add compiler

This commit is contained in:
2020-05-10 01:39:48 +08:00
parent fe196b6507
commit bdc9eb543a
5 changed files with 120 additions and 3 deletions

View File

@@ -19,8 +19,8 @@ impl Instruction {
let a = context.pop();
let b = context.pop();
if let (Some(a), Some(b)) = (a, b) {
context.push(b);
context.push(a);
context.push(b);
} else {
return Err(RuntimeError::ErrorVmState(format!("Stack is not enough when call swap!")));
}
@@ -85,7 +85,7 @@ impl Instruction {
let addr = context.pop();
if let Some(addr) = addr {
match context.get_mem(addr) {
Some(val) => { context.put_mem(addr, val); },
Some(val) => { context.push(val); },
None => return Err(RuntimeError::ErrorVmState(format!("Memory addr not found: {}!", addr))),
}
} else {
@@ -165,6 +165,7 @@ impl Vm {
if context.is_debug() {
let is_define_label = if let Instruction::DefineLabel(_) = ins { true } else { false };
if !is_define_label {
println!("[DEBUG] Context: {:?}", context);
println!("[DEBUG] Execute instruction: {:?}", ins);
}
}