add int into value type in IR

This commit is contained in:
Mylloon 2022-12-08 14:04:46 +01:00
parent 8eea4a7d15
commit b4f384ea76
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 8 additions and 4 deletions

3
ast.ml
View file

@ -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

View file

@ -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 = [] }

View file

@ -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_