Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/isa/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ macro_rules! instr {
$crate::_reg_idx16!($offset_idx),
))
};
(put s16[$idx:literal], $val:literal) => {{
Instr::Bytes(BytesOp::Put(RegS::from($idx), Box::new(ByteStr::with($val)), false))
(put $val:literal,s16[$idx:literal]) => {{
Instr::Bytes(BytesOp::Put(Box::new(ByteStr::with(&$val)), RegS::from($idx), false))
}};
(put $val:literal, $reg:ident[$idx:literal]) => {{
let s = stringify!($val);
Expand Down Expand Up @@ -464,7 +464,7 @@ macro_rules! instr {
$crate::_reg_idx!($idx2),
))
}};
(cmp s16[$idx1:literal],s16[$idx2:literal]) => {{
(eq s16[$idx1:literal],s16[$idx2:literal]) => {{
Instr::Bytes(BytesOp::Eq(RegS::from($idx1), RegS::from($idx2)))
}};
(ifn $reg:ident[$idx:literal]) => {
Expand Down
4 changes: 2 additions & 2 deletions src/isa/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ impl Bytecode for BytesOp {
W: Write,
{
match self {
BytesOp::Put(reg, bytes, _) => {
BytesOp::Put(bytes, reg, _) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid changing in BytesOp::Put argument order is a breaking change which makes this PR impossible to release without a major version bump (while it will be nice to have it as a fix instead).

writer.write_u8(reg)?;
writer.write_data(bytes.as_ref())?;
}
Expand Down Expand Up @@ -1189,7 +1189,7 @@ impl Bytecode for BytesOp {
INSTR_PUT => {
let index = reader.read_u8()?;
let (data, st0) = reader.read_data()?;
Self::Put(index.into(), Box::new(ByteStr::with(data)), st0)
Self::Put(Box::new(ByteStr::with(data)), index.into(), st0)
}
INSTR_MVS => Self::Mov(reader.read_u4()?.into(), reader.read_u4()?.into()),
INSTR_SWP => Self::Swp(reader.read_u4()?.into(), reader.read_u4()?.into()),
Expand Down
14 changes: 7 additions & 7 deletions src/isa/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ impl InstructionSet for BytesOp {
#[allow(warnings)]
fn exec(&self, regs: &mut CoreRegs, _site: LibSite, _: &()) -> ExecStep {
match self {
BytesOp::Put(reg, bytes, st0) => {
BytesOp::Put(bytes, reg, st0) => {
regs.s16[reg.as_usize()] = Some(*bytes.clone());
if *st0 {
regs.st0 = false
Expand Down Expand Up @@ -1066,12 +1066,12 @@ mod tests {
let lib_site = LibSite::default();
let s1 = "apple_banana_kiwi".as_bytes();
let s2 = "apple@banana@kiwi".as_bytes();
BytesOp::Put(1.into(), Box::new(ByteStr::with(s1)), false).exec(
BytesOp::Put(Box::new(ByteStr::with(s1)), 1.into(), false).exec(
&mut register,
lib_site,
&(),
);
BytesOp::Put(2.into(), Box::new(ByteStr::with(s2)), false).exec(
BytesOp::Put(Box::new(ByteStr::with(s2)), 2.into(), false).exec(
&mut register,
lib_site,
&(),
Expand Down Expand Up @@ -1135,12 +1135,12 @@ mod tests {

let s1 = "aaa".as_bytes();
let s2 = "bbb".as_bytes();
BytesOp::Put(1.into(), Box::new(ByteStr::with(s1)), false).exec(
BytesOp::Put(Box::new(ByteStr::with(s1)), 1.into(), false).exec(
&mut register,
lib_site,
&(),
);
BytesOp::Put(2.into(), Box::new(ByteStr::with(s2)), false).exec(
BytesOp::Put(Box::new(ByteStr::with(s2)), 2.into(), false).exec(
&mut register,
lib_site,
&(),
Expand All @@ -1162,12 +1162,12 @@ mod tests {

let s1 = [0u8; u16::MAX as usize];
let s2 = [0u8; u16::MAX as usize];
BytesOp::Put(1.into(), Box::new(ByteStr::with(s1)), false).exec(
BytesOp::Put(Box::new(ByteStr::with(s1)), 1.into(), false).exec(
&mut register,
lib_site,
&(),
);
BytesOp::Put(2.into(), Box::new(ByteStr::with(s2)), false).exec(
BytesOp::Put(Box::new(ByteStr::with(s2)), 2.into(), false).exec(
&mut register,
lib_site,
&(),
Expand Down
4 changes: 2 additions & 2 deletions src/isa/instr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,8 @@ pub enum BytesOp {
/// sets `st0` to `false`. Otherwise, `st0` is unaffected.
#[display("put {0},{1}")]
Put(
/** Destination `s` register index */ RegS,
Box<ByteStr>,
/** Destination `s` register index */ RegS,
/** Indicates that the operation must set `st0` to false; i.e. string data are not
* completely read from the data segment */
bool,
Expand Down Expand Up @@ -665,7 +665,7 @@ pub enum BytesOp {
/// Check equality of two strings, putting result into `st0`.
///
/// If both of strings are uninitialized, `st0` assigned `true` value.
#[display("cmp {0},{1}")]
#[display("eq {0},{1}")]
Eq(RegS, RegS),

/// Compute offset and length of the `n`th fragment shared between two strings ("conjoint
Expand Down
6 changes: 6 additions & 0 deletions src/reg/core_regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,12 @@ impl Debug for CoreRegs {
}
}

write!(f, "\n{}S-REG:{}\t", sect, reset)?;
for i in 0..16 {
if let Some(ref v) = self.s16[i] {
write!(f, "{}s16{}[{}{:02}{}]={}{}{}\n\t", reg, eq, reset, i, eq, val, v, reset)?;
}
}
Comment on lines +696 to +701
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put   100,r8192[1];
put   2,r8192[2];
put   18,a16[1];
put   2,a16[2];
put   "aaa",s16[1];
put   "aaa",s16[2];

would be displayed as

CTRL:   st0=true cy0=0 ca0=8 cl0=~ cp0=0 
                cs0=0 @ alien_vista_plaza_11111111111111111111111111111111
                   
A-REG:  a16[01]=0012h   a16[02]=0002h   
                
F-REG:  
R-REG:  r8192[01]=64h
                
S-REG:  s16[01]="aaa"
        s16[02]="aaa"

Ok(())
}
}
34 changes: 17 additions & 17 deletions tests/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,16 @@ fn float() {
#[test]
fn bytes_put() {
let code = aluasm! {
put s16[1],"aaa";
put s16[2],"aaa";
cmp s16[1],s16[2];
put "aaa",s16[1];
put "aaa",s16[2];
eq s16[1],s16[2];
ret;
};
run(code, true);
let code = aluasm! {
put s16[1],"aaa";
put s16[2],"bbb";
cmp s16[1],s16[2];
put "aaa",s16[1];
put "bbb",s16[2];
eq s16[1],s16[2];
ret;
};
run(code, false);
Expand All @@ -215,7 +215,7 @@ fn bytes_put() {
#[test]
fn bytes_extr() {
let code = aluasm! {
put s16[0],"################@@@@@@";
put "################@@@@@@",s16[0];
put 0,a16[0];
extr s16[0],r128[0],a16[0];
put 0x23232323232323232323232323232323,r128[1];
Expand All @@ -224,7 +224,7 @@ fn bytes_extr() {
};
run(code, true);
let code = aluasm! {
put s16[0],"################@@@@@@";
put "################@@@@@@",s16[0];
put 3,a16[0];
extr s16[0],r128[0],a16[0];
put 0x40404023232323232323232323232323,r128[1];
Expand All @@ -237,35 +237,35 @@ fn bytes_extr() {
#[test]
fn bytes_extr_offset_exceed() {
let code = aluasm! {
put s16[0],"123456788901234567";
put "123456788901234567",s16[0];
put 0,a16[0];
extr s16[0],r128[0],a16[0];
ret;
};
run(code, true);
let code = aluasm! {
put s16[0],"123456788901234567";
put "123456788901234567",s16[0];
put 1,a16[0];
extr s16[0],r128[0],a16[0];
ret;
};
run(code, true);
let code = aluasm! {
put s16[0],"123456788901234567";
put "123456788901234567",s16[0];
put 2,a16[0];
extr s16[0],r128[0],a16[0];
ret;
};
run(code, false);
let code = aluasm! {
put s16[0],"123456788901234567";
put "123456788901234567",s16[0];
put 2,a16[0];
extr s16[0],r128[0],a16[0];
ret;
};
run(code, false);
let code = aluasm! {
put s16[0],"################@";
put "################@",s16[0];
put 1,a16[0];
extr s16[0],r128[0],a16[0];
put 0x40232323232323232323232323232323,r128[1];
Expand All @@ -274,14 +274,14 @@ fn bytes_extr_offset_exceed() {
};
run(code, true);
let code = aluasm! {
put s16[0],"123456788901234567";
put "123456788901234567",s16[0];
put 100,a16[0];
extr s16[0],r128[0],a16[0];
ret;
};
run(code, false);
let code = aluasm! {
put s16[0],"123";
put "123",s16[0];
put 0,a16[0];
extr s16[0],r128[0],a16[0];
ret;
Expand All @@ -292,13 +292,13 @@ fn bytes_extr_offset_exceed() {
#[test]
fn bytes_extr_uninitialized_offset() {
let code = aluasm! {
put s16[0],"12345678890123456";
put "12345678890123456",s16[0];
extr s16[0],r128[0],a16[0];
ret;
};
run(code, false);
let code = aluasm! {
put s16[0],"12345678890123456";
put "12345678890123456",s16[0];
extr s16[0],r128[0],a16[0];
eq.e r128[0],r128[1];
ret;
Expand Down