fix binop codegen
This commit is contained in:
parent
1aa704fa49
commit
10f5a5a6e2
|
@ -5,7 +5,7 @@ let () =
|
||||||
Logs.set_level (Some Logs.Debug);
|
Logs.set_level (Some Logs.Debug);
|
||||||
|
|
||||||
try
|
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);
|
Logs.debug (fun m -> m "%a" Ast.pp_modl ast);
|
||||||
let prog = compile ast in
|
let prog = compile ast in
|
||||||
Logs.debug (fun m -> m "%a" Code.pp_program prog);
|
Logs.debug (fun m -> m "%a" Code.pp_program prog);
|
||||||
|
|
|
@ -51,8 +51,8 @@ let compile modl lib =
|
||||||
compile_exp env r2 e2;
|
compile_exp env r2 e2;
|
||||||
begin match op with
|
begin match op with
|
||||||
| Ast.Add -> emit (ADD (rd, r1, r2))
|
| Ast.Add -> emit (ADD (rd, r1, r2))
|
||||||
| Ast.Sub -> emit (ADD (rd, r1, r2))
|
| Ast.Sub -> emit (SUB (rd, r1, r2))
|
||||||
| Ast.Mul -> emit (ADD (rd, r1, r2))
|
| Ast.Mul -> emit (MUL (rd, r1, r2))
|
||||||
| Ast.Div | Ast.Mod -> failwith "Bcc.compile_exp: TODO(Div,Mod)"
|
| Ast.Div | Ast.Mod -> failwith "Bcc.compile_exp: TODO(Div,Mod)"
|
||||||
| Ast.Eql -> emit (EQL (rd, r1, r2))
|
| Ast.Eql -> emit (EQL (rd, r1, r2))
|
||||||
| Ast.Grt -> emit (GRT (rd, r1, r2))
|
| Ast.Grt -> emit (GRT (rd, r1, r2))
|
||||||
|
@ -76,9 +76,9 @@ let compile modl lib =
|
||||||
|
|
||||||
| Ast.If (e0, e1, e2) ->
|
| Ast.If (e0, e1, e2) ->
|
||||||
let r0 = rd in
|
let r0 = rd in
|
||||||
compile_exp env r0 e0;
|
|
||||||
let b1 = Code.make_block () in
|
let b1 = Code.make_block () in
|
||||||
let b2 = Code.make_block () in
|
let b2 = Code.make_block () in
|
||||||
|
compile_exp env r0 e0;
|
||||||
emit (CBR (r0, b1, b2));
|
emit (CBR (r0, b1, b2));
|
||||||
let jp = Code.make_block () in
|
let jp = Code.make_block () in
|
||||||
enter b1; compile_exp env rd e1; emit (JMP jp);
|
enter b1; compile_exp env rd e1; emit (JMP jp);
|
||||||
|
|
Loading…
Reference in New Issue