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
|
end
|
||||||
|
|
||||||
module IR = struct
|
module IR = struct
|
||||||
type expr = Int of int
|
type value = Int of int
|
||||||
|
type expr = Val of value
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,9 +2,12 @@ open Ast.IR
|
||||||
open Mips
|
open Mips
|
||||||
module Env = Map.Make (String)
|
module Env = Map.Make (String)
|
||||||
|
|
||||||
let rec compile_expr e =
|
let compile_value = function
|
||||||
match e with
|
|
||||||
| Int n -> [ Li (V0, n) ]
|
| Int n -> [ Li (V0, n) ]
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
let compile_expr = function
|
||||||
|
| Val v -> compile_value v
|
||||||
|
;;
|
||||||
|
|
||||||
let compile ir = { text = Baselib.builtins @ compile_expr ir; data = [] }
|
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 =
|
let rec analyze_expr expr env =
|
||||||
match expr with
|
match expr with
|
||||||
| Syntax.Int n -> Int n.value
|
| Syntax.Int n -> Val (Int n.value)
|
||||||
;;
|
;;
|
||||||
|
|
||||||
let analyze parsed = analyze_expr parsed Baselib._types_
|
let analyze parsed = analyze_expr parsed Baselib._types_
|
||||||
|
|
Reference in a new issue