From b4f384ea7642754e84d07b016189dada91955729 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 8 Dec 2022 14:04:46 +0100 Subject: [PATCH] add int into value type in IR --- ast.ml | 3 ++- compiler.ml | 7 +++++-- semantics.ml | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) 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_