add int into value type in IR
This commit is contained in:
parent
8eea4a7d15
commit
b4f384ea76
3 changed files with 8 additions and 4 deletions
3
ast.ml
3
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
|
||||
|
|
|
@ -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 = [] }
|
||||
|
|
|
@ -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_
|
||||
|
|
Reference in a new issue