fix bug in binop code gen
This commit is contained in:
parent
3d88cbe319
commit
fca1c8f557
|
@ -14,7 +14,7 @@ let compile modl =
|
||||||
let bb = ref ep in
|
let bb = ref ep in
|
||||||
|
|
||||||
let emit is = Code.add_ins !bb is 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
|
let rec compile_exp env = function
|
||||||
| Ast.Literal Nil -> Code.Cst_nil
|
| Ast.Literal Nil -> Code.Cst_nil
|
||||||
|
@ -33,9 +33,9 @@ let compile modl =
|
||||||
| Ast.Binop (op, lhs, rhs) ->
|
| Ast.Binop (op, lhs, rhs) ->
|
||||||
let ret = !sp in
|
let ret = !sp in
|
||||||
let lhs = compile_exp env lhs in
|
let lhs = compile_exp env lhs in
|
||||||
let rhs = compile_exp env rhs in
|
|
||||||
sp := ret + 1;
|
|
||||||
emit_mov ret lhs;
|
emit_mov ret lhs;
|
||||||
|
sp := ret + 1;
|
||||||
|
let rhs = compile_exp env rhs in
|
||||||
(match op with
|
(match op with
|
||||||
| Ast.Add -> emit (ADD (ret, rhs))
|
| Ast.Add -> emit (ADD (ret, rhs))
|
||||||
| Ast.Sub -> emit (SUB (ret, rhs))
|
| Ast.Sub -> emit (SUB (ret, rhs))
|
||||||
|
|
Loading…
Reference in New Issue