fixed the "!" operation
This commit is contained in:
parent
0c60e98d9f
commit
e9d1f9bbd6
3 changed files with 34 additions and 18 deletions
|
@ -222,6 +222,11 @@ fn do_ast_op(ast_op: ASTPart, op_count: &mut usize, ops: &mut Vec<Operation>, va
|
||||||
">=" => 21,
|
">=" => 21,
|
||||||
"<" => 22,
|
"<" => 22,
|
||||||
"<=" => 23,
|
"<=" => 23,
|
||||||
|
"!" => {
|
||||||
|
ops.push(Operation { opcode: 24, arg1: Some(left_reg), arg2: Some(reg.register as i64), arg3: None });
|
||||||
|
set_register(registers, RegisterState { id: reg.register, used: true, variable: 0, last_used: *op_count });
|
||||||
|
return reg.register;
|
||||||
|
},
|
||||||
_ => panic!("Unknown operator {}", op.operator),
|
_ => panic!("Unknown operator {}", op.operator),
|
||||||
};
|
};
|
||||||
ops.push(Operation { opcode, arg1: Some(left_reg), arg2: Some(right_reg as i64), arg3: Some(reg.register) });
|
ops.push(Operation { opcode, arg1: Some(left_reg), arg2: Some(right_reg as i64), arg3: Some(reg.register) });
|
||||||
|
|
|
@ -228,6 +228,20 @@ fn shunt(input: Vec<ASTPart>) -> ASTPart {
|
||||||
i += 1;
|
i += 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if op.operator == "!" {
|
||||||
|
println!("{:?}", output);
|
||||||
|
if i < 1 {
|
||||||
|
panic!("Unexpected operation at {}", op.pos);
|
||||||
|
}
|
||||||
|
let left = output[i-1].clone();
|
||||||
|
output[i] = ASTPart::Operation(AstOperation {
|
||||||
|
operator: op.operator.clone(),
|
||||||
|
left: Box::new(left),
|
||||||
|
right: Box::new(ASTPart::NOOP),
|
||||||
|
pos: op.pos,
|
||||||
|
});
|
||||||
|
output.remove(i-1);
|
||||||
|
} else {
|
||||||
if i < 2 {
|
if i < 2 {
|
||||||
panic!("Unexpected operation at {}", op.pos);
|
panic!("Unexpected operation at {}", op.pos);
|
||||||
}
|
}
|
||||||
|
@ -243,6 +257,7 @@ fn shunt(input: Vec<ASTPart>) -> ASTPart {
|
||||||
output.remove(i-2);
|
output.remove(i-2);
|
||||||
i -= 1;
|
i -= 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
6
test.as
6
test.as
|
@ -1,5 +1 @@
|
||||||
gethelj a = 1
|
gethelj a = !piszv
|
||||||
ha geny (1==1) {
|
|
||||||
gethelj b = 2
|
|
||||||
}
|
|
||||||
gethelj c = 3
|
|
Loading…
Add table
Add a link
Reference in a new issue