diff options
-rw-r--r-- | source/mod_student/translator.ml | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/source/mod_student/translator.ml b/source/mod_student/translator.ml index 163d312..898ab5b 100644 --- a/source/mod_student/translator.ml +++ b/source/mod_student/translator.ml @@ -132,10 +132,9 @@ module Make() = struct current_bb, E_Int (int32_of_bool value) | Ast.EXPR_String {value;_} -> let reg =allocate_register() in - append_instruction current_bb @@ I_NewArray ( reg,E_Int (Int32.of_int @@ (1+String.length value))); + append_instruction current_bb @@ I_NewArray ( reg,E_Int (Int32.of_int @@ String.length value)); String.iteri (fun i c -> append_instruction current_bb @@ I_StoreArray (E_Reg reg, E_Int (Int32.of_int i), E_Int (Int32.of_int @@ Char.code c))) value; - append_instruction current_bb @@ I_StoreArray ( E_Reg reg, E_Int (Int32.of_int (String.length value)), E_Int (Int32.of_int 0) ); current_bb, E_Reg reg | Ast.EXPR_Binop {lhs;rhs;op=Ast.BINOP_Add;tag;_} -> @@ -262,9 +261,9 @@ module Make() = struct end | STMT_Assign {lhs=Ast.LVALUE_Id{id;_};rhs;_} -> let current_bb, reg = translate_expression env current_bb rhs in - let my_reg = allocate_register() in + let my_reg = (Environment.lookup_var id env) in append_instruction current_bb @@ I_Move (my_reg, reg); - current_bb, (Environment.add_var id my_reg env) + current_bb, env | STMT_VarDecl {var=VarDecl{id;_};init=None;_} -> let my_reg = allocate_register() in current_bb,(Environment.add_var id my_reg env) |