Skip to content

Commit

Permalink
fix: minor correction in Deref bytecode
Browse files Browse the repository at this point in the history
  • Loading branch information
jac3km4 committed May 25, 2024
1 parent f0926a1 commit f12f7ab
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,8 @@ impl<'a> Assembler<'a> {
self.emit(Instr::AsRef(get_arg_type(0)?));
}
IntrinsicOp::Deref => {
self.emit(Instr::Deref(get_arg_type(0)?));
let type_idx = scope.get_type_index(return_type, pool).with_span(span)?;
self.emit(Instr::Deref(type_idx));
}
IntrinsicOp::RefToWeakRef => {
self.emit(Instr::RefToWeakRef);
Expand Down
28 changes: 28 additions & 0 deletions compiler/tests/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,34 @@ fn compile_string_literals() {
TestContext::compiled(vec![sources]).unwrap().run("Testing", check);
}

#[test]
fn compile_deref_asref() {
let sources = r#"
func Testing(str: String) {
let a = ToString(str);
let b = AsRef(str);
let c = Deref(b);
}
"#;

let check = check_code![
pat!(Assign),
mem!(Local(a)),
mem!(ToString(str_type)),
mem!(Param(str)),
pat!(Assign),
mem!(Local(b)),
mem!(AsRef(str_type)),
mem!(Param(str)),
pat!(Assign),
mem!(Local(c)),
mem!(Deref(str_type)),
mem!(Local(b)),
pat!(Nop)
];
TestContext::compiled(vec![sources]).unwrap().run("Testing", check);
}

#[test]
fn compile_is_defined() {
let sources = "
Expand Down

0 comments on commit f12f7ab

Please sign in to comment.