fix bug in binop code gen

This commit is contained in:
tali 2023-11-29 23:04:45 -05:00
parent 3d88cbe319
commit fca1c8f557
1 changed files with 3 additions and 3 deletions

View File

@ -14,7 +14,7 @@ let compile modl =
let bb = ref ep in
let emit is = Code.add_ins !bb is in
let emit_mov l r = if r <> Code.Reg l then emit (MOV (l, r)) in
let emit_mov lhs rhs = if rhs <> Code.Reg lhs then emit (MOV (lhs, rhs)) in
let rec compile_exp env = function
| Ast.Literal Nil -> Code.Cst_nil
@ -33,9 +33,9 @@ let compile modl =
| Ast.Binop (op, lhs, rhs) ->
let ret = !sp in
let lhs = compile_exp env lhs in
let rhs = compile_exp env rhs in
sp := ret + 1;
emit_mov ret lhs;
sp := ret + 1;
let rhs = compile_exp env rhs in
(match op with
| Ast.Add -> emit (ADD (ret, rhs))
| Ast.Sub -> emit (SUB (ret, rhs))