add more arithmetic instructions
This commit is contained in:
parent
ed5e3453b0
commit
09cd134406
2 changed files with 115 additions and 15 deletions
src
18
src/test.rs
18
src/test.rs
|
@ -16,17 +16,17 @@ fn test_vm() {
|
|||
.inst( crate::VM_Instruction::Store )
|
||||
.build());
|
||||
|
||||
linker.add_procedure("i+",
|
||||
linker.add_procedure("int-add",
|
||||
crate::Assembler::new()
|
||||
.inst( crate::VM_Instruction::Add )
|
||||
.inst( crate::VM_Instruction::IntAdd )
|
||||
.build());
|
||||
|
||||
linker.add_procedure("i-",
|
||||
|
||||
linker.add_procedure("int-sub",
|
||||
crate::Assembler::new()
|
||||
.inst( crate::VM_Instruction::BitwiseNot )
|
||||
.inst( crate::VM_Instruction::BitNeg )
|
||||
.lit(1)
|
||||
.inst( crate::VM_Instruction::Add )
|
||||
.inst( crate::VM_Instruction::Add )
|
||||
.inst( crate::VM_Instruction::IntAdd )
|
||||
.inst( crate::VM_Instruction::IntAdd )
|
||||
.build());
|
||||
|
||||
// declare variable 'x' at address 0x86
|
||||
|
@ -50,13 +50,13 @@ fn test_vm() {
|
|||
linker.add_procedure("main",
|
||||
crate::Assembler::new()
|
||||
// x = 123
|
||||
.lit(100).lit(23).call("i+")
|
||||
.lit(100).lit(23).call("int-add")
|
||||
.call("x").call("!")
|
||||
|
||||
// if ( 123 - x ) { emit '*' } else { emit '+' }
|
||||
.lit(123)
|
||||
.call("x").call("@")
|
||||
.call("i-")
|
||||
.call("int-sub")
|
||||
.branch(
|
||||
crate::Assembler::new()
|
||||
.lit(42).inst(crate::VM_Instruction::Emit)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue