fix binop codegen

This commit is contained in:
tali 2023-12-07 12:34:50 -05:00
parent 1aa704fa49
commit 10f5a5a6e2
2 changed files with 4 additions and 4 deletions

View File

@ -5,7 +5,7 @@ let () =
Logs.set_level (Some Logs.Debug);
try
let ast = parse "fun f() g() + 1 fun g() 5 println(f())" in
let ast = parse "val x = 1 fun f() g() + x fun g() 5 println(f())" in
Logs.debug (fun m -> m "%a" Ast.pp_modl ast);
let prog = compile ast in
Logs.debug (fun m -> m "%a" Code.pp_program prog);

View File

@ -51,8 +51,8 @@ let compile modl lib =
compile_exp env r2 e2;
begin match op with
| Ast.Add -> emit (ADD (rd, r1, r2))
| Ast.Sub -> emit (ADD (rd, r1, r2))
| Ast.Mul -> emit (ADD (rd, r1, r2))
| Ast.Sub -> emit (SUB (rd, r1, r2))
| Ast.Mul -> emit (MUL (rd, r1, r2))
| Ast.Div | Ast.Mod -> failwith "Bcc.compile_exp: TODO(Div,Mod)"
| Ast.Eql -> emit (EQL (rd, r1, r2))
| Ast.Grt -> emit (GRT (rd, r1, r2))
@ -76,9 +76,9 @@ let compile modl lib =
| Ast.If (e0, e1, e2) ->
let r0 = rd in
compile_exp env r0 e0;
let b1 = Code.make_block () in
let b2 = Code.make_block () in
compile_exp env r0 e0;
emit (CBR (r0, b1, b2));
let jp = Code.make_block () in
enter b1; compile_exp env rd e1; emit (JMP jp);