Skip to content

Commit

Permalink
fixed binary op send2 + tests for send BC
Browse files Browse the repository at this point in the history
  • Loading branch information
OctaveLarose authored and Hirevo committed Feb 16, 2024
1 parent f6f246e commit 44522ff
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
20 changes: 9 additions & 11 deletions som-interpreter-bc/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,14 @@ impl MethodCodegen for ast::Expression {
ctxt.push_instr(Bytecode::PushArgument(up_idx, idx))
}
Some(FoundVar::Field(idx)) => ctxt.push_instr(Bytecode::PushField(idx)),
None => {
match name.as_str() {
"nil" => ctxt.push_instr(Bytecode::PushNil),
_ => {
let name = ctxt.intern_symbol(name);
let idx = ctxt.push_literal(Literal::Symbol(name));
ctxt.push_instr(Bytecode::PushGlobal(idx as u8));
}
None => match name.as_str() {
"nil" => ctxt.push_instr(Bytecode::PushNil),
_ => {
let name = ctxt.intern_symbol(name);
let idx = ctxt.push_literal(Literal::Symbol(name));
ctxt.push_instr(Bytecode::PushGlobal(idx as u8));
}
}
},
}
Some(())
}
Expand Down Expand Up @@ -344,9 +342,9 @@ impl MethodCodegen for ast::Expression {
let sym = ctxt.intern_symbol(message.op.as_str());
let idx = ctxt.push_literal(Literal::Symbol(sym));
if super_send {
ctxt.push_instr(Bytecode::SuperSendN(idx as u8));
ctxt.push_instr(Bytecode::SuperSend2(idx as u8));
} else {
ctxt.push_instr(Bytecode::SendN(idx as u8));
ctxt.push_instr(Bytecode::Send2(idx as u8));
}
Some(())
}
Expand Down
33 changes: 33 additions & 0 deletions som-interpreter-bc/tests/specialized_bc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,36 @@ fn push_constant_bytecodes() {
],
);
}

#[test]
fn send_bytecodes() {
let class_txt = "Foo = (
send: a three: b = (
^ false
)
send: a with: b four: c = (
^ false
)
run = (
1 abs.
1 + 1.
self send: 1 three: 1.
self send: 1 with: 1 four: 1.
)
)
";

let bytecodes = get_bytecodes_from_method(class_txt, "run");
expect_bytecode_sequence(&bytecodes, &[Push1, Send1(0)]);

expect_bytecode_sequence(&bytecodes, &[Push1, Push1, Send2(1)]);

expect_bytecode_sequence(&bytecodes, &[PushArgument(0, 0), Push1, Push1, Send3(2)]);

expect_bytecode_sequence(
&bytecodes,
&[PushArgument(0, 0), Push1, Push1, Push1, SendN(3)],
);
}

0 comments on commit 44522ff

Please sign in to comment.