Skip to content

Commit

Permalink
fix(compiler): tests of br_if
Browse files Browse the repository at this point in the history
  • Loading branch information
clearloop committed Oct 9, 2024
1 parent cb6900c commit 5565b0b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
1 change: 0 additions & 1 deletion codegen/src/visitor/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ impl Function {
}

// TODO: support same pc different jumps. (#160)
// TODO: store the params in memory
self.table.call(self.masm.pc_offset(), index);

// jump to the callee function
Expand Down
22 changes: 13 additions & 9 deletions compiler/filetests/wat/br_if/as_block_last.wat
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
;;! target = "evm"
(module
(func (export "as-block-last") (param i32)
(block
(call $dummy)
(call $dummy)
(br_if 0 (local.get 0))
)
)
(func $dummy)
)
(func (export "as-block-last") (param i32)
(local.get 0)
(call $internal)
)
(func $internal (param i32)
(block
(call $dummy)
(call $dummy)
(br_if 0 (local.get 0))
)
)
(func $dummy)
)
5 changes: 3 additions & 2 deletions tests/br_if.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
//! br_if tests for the zink compiler.
use anyhow::Result;
use filetests::Test;
use zint::{Contract, HaltReason, OutOfGasError};
use zint::Contract;

#[test]
fn as_block_last() -> Result<()> {
let mut contract = Contract::from(Test::BR_IF_AS_BLOCK_LAST).pure().compile()?;

let info = contract.execute(&[0])?;
assert!(info.halt.is_none());
assert!(info.ret.is_empty());

let info = contract.execute(&[42])?;
assert_eq!(info.halt, Some(HaltReason::OutOfGas(OutOfGasError::Basic)));
assert!(info.halt.is_none());
assert!(info.ret.is_empty());

Ok(())
Expand Down

0 comments on commit 5565b0b

Please sign in to comment.