Skip to content

Commit 0db56c1

Browse files
committed
Add missing instructions to assembler
1 parent 2be57d2 commit 0db56c1

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

vm/src/asm.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,22 @@ impl Assembler
957957
self.code.push_u8(idx);
958958
}
959959

960+
"get_argc" => {
961+
self.code.push_op(Op::get_argc);
962+
}
963+
964+
"thread_get" => {
965+
let idx: u8 = self.parse_int_arg(input)?;
966+
self.code.push_op(Op::thread_get);
967+
self.code.push_u8(idx);
968+
}
969+
970+
"thread_set" => {
971+
let idx: u8 = self.parse_int_arg(input)?;
972+
self.code.push_op(Op::thread_set);
973+
self.code.push_u8(idx);
974+
}
975+
960976
"push_0" => {
961977
self.code.push_op(Op::push_0);
962978
}
@@ -1274,6 +1290,13 @@ mod tests
12741290
parse_ok(".code;\npush_u32 0xFFFFFFFF;");
12751291
parse_ok(".code; push_u32 1_000_000;");
12761292
parse_ok(".code; push_i8 55; push_i8 -1;");
1293+
1294+
// Frame argument count and thread-local variable access
1295+
parse_ok(".code; get_argc;");
1296+
parse_ok(".code; thread_get 0;");
1297+
parse_ok(".code; push_i8 7; thread_set 3;");
1298+
parse_fails(".code; thread_get;");
1299+
parse_fails(".code; thread_set;");
12771300
}
12781301

12791302
#[test]

vm/src/vm.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,11 @@ impl Thread
838838
self.push(b);
839839
}
840840

841+
Op::get_argc => {
842+
let argc = self.frames[self.frames.len() - 1].argc;
843+
self.push(Value::from(argc as u64));
844+
}
845+
841846
Op::get_arg => {
842847
let idx = self.code.read_pc::<u8>(&mut pc) as usize;
843848

@@ -1928,6 +1933,17 @@ mod tests
19281933
eval_i64(".code; push 0; push 77; set_local 0; get_local 0; ret;", 77);
19291934
}
19301935

1936+
#[test]
1937+
fn test_get_argc()
1938+
{
1939+
// The top-level frame is entered with no arguments
1940+
eval_i64("get_argc; ret;", 0);
1941+
1942+
// get_argc reports the argument count of the current frame
1943+
eval_i64("push 42; call FN, 1; ret; FN: get_argc; ret;", 1);
1944+
eval_i64("push 10; push 20; push 30; call FN, 3; ret; FN: get_argc; ret;", 3);
1945+
}
1946+
19311947
#[test]
19321948
fn test_floats()
19331949
{

0 commit comments

Comments
 (0)