diff --git a/ast.ml b/ast.ml index 727a62d..f6cd2bf 100644 --- a/ast.ml +++ b/ast.ml @@ -7,5 +7,6 @@ module Syntax = struct end module IR = struct - type expr = Int of int + type value = Int of int + type expr = Val of value end diff --git a/compiler.ml b/compiler.ml index c2cdffe..bf86436 100644 --- a/compiler.ml +++ b/compiler.ml @@ -2,9 +2,12 @@ open Ast.IR open Mips module Env = Map.Make (String) -let rec compile_expr e = - match e with +let compile_value = function | Int n -> [ Li (V0, n) ] ;; +let compile_expr = function + | Val v -> compile_value v +;; + let compile ir = { text = Baselib.builtins @ compile_expr ir; data = [] } diff --git a/semantics.ml b/semantics.ml index 9461a9e..90f7432 100644 --- a/semantics.ml +++ b/semantics.ml @@ -6,7 +6,7 @@ exception Error of string * Lexing.position let rec analyze_expr expr env = match expr with - | Syntax.Int n -> Int n.value + | Syntax.Int n -> Val (Int n.value) ;; let analyze parsed = analyze_expr parsed Baselib._types_