summaryrefslogtreecommitdiffstats
path: root/syntax.sml
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2024-04-28 15:06:43 -0700
committerRose Hogenson <rosehogenson@posteo.net>2024-04-28 15:06:43 -0700
commit5737e8430d43b3b5bd448f761cd2f3c35707a174 (patch)
treeb24f44ea5245a56b2f712c2eef6a3897f53bd098 /syntax.sml
parent9f5889c1263d63b953b3a324da07321deef5ca58 (diff)
downloadsml-5737e8430d43b3b5bd448f761cd2f3c35707a174.tar.zst
Add case over int.
Diffstat (limited to 'syntax.sml')
-rw-r--r--syntax.sml16
1 files changed, 16 insertions, 0 deletions
diff --git a/syntax.sml b/syntax.sml
index b91e0a2..f85e6f2 100644
--- a/syntax.sml
+++ b/syntax.sml
@@ -10,6 +10,7 @@ struct
datatype pat =
PWild
| PVar of string
+ | PInt of int
datatype expr =
EIdent of string list
@@ -37,6 +38,9 @@ struct
| PSub
| PMul
| PDiv
+ | PLess
+ | PEq
+ | PIf
datatype lexp =
LVar of var
@@ -47,6 +51,7 @@ struct
| LString of string
| LRecord of lexp list
| LPrim of primop
+ | LSwitch of lexp * (int * lexp) list * lexp
(* CPS *)
datatype value =
@@ -73,6 +78,9 @@ struct
| OSub of var * value * value
| OMul of var * value * value
| ODiv of var * value * value
+ | OLess of var * value * value
+ | OEq of var * value * value
+ | OIf of value * var
| OLabel of var
fun listToString (show : 'a -> string) (l : 'a list) =
@@ -100,6 +108,7 @@ struct
case p of
PWild => "PWild"
| PVar v => "PVar " ^ quote v
+ | PInt i => "PInt " ^ Int.toString i
fun exprToStringI (indent : string) (x : expr) : string =
let val self = exprToStringI indent
@@ -134,6 +143,9 @@ struct
| PSub => "PSub"
| PMul => "PMul"
| PDiv => "PDiv"
+ | PLess => "PLess"
+ | PEq => "PEq"
+ | PIf => "PIf"
fun lexpToString (x : lexp) : string =
case x of
@@ -145,6 +157,7 @@ struct
| LString s => "LString " ^ quote s
| LRecord l => "LRecord " ^ listToString lexpToString l
| LPrim p => "LPrim " ^ primopToString p
+ | LSwitch (e, arms, otherwise) => "LSwitch (" ^ lexpToString e ^ ", " ^ listToString (fn (x, e) => "(" ^ Int.toString x ^ ", " ^ lexpToString e ^ ")") arms ^ ", " ^ lexpToString otherwise ^ ")"
fun valueToString (x : value) : string =
case x of
@@ -179,5 +192,8 @@ struct
| OSub (r, v1, v2) => "Var " ^ Int.toString r ^ " = OSub (" ^ valueToString v1 ^ ", " ^ valueToString v2 ^ ")"
| OMul (r, v1, v2) => "Var " ^ Int.toString r ^ " = OMul (" ^ valueToString v1 ^ ", " ^ valueToString v2 ^ ")"
| ODiv (r, v1, v2) => "Var " ^ Int.toString r ^ " = ODiv (" ^ valueToString v1 ^ ", " ^ valueToString v2 ^ ")"
+ | OLess (r, v1, v2) => "Var " ^ Int.toString r ^ " = OLess (" ^ valueToString v1 ^ ", " ^ valueToString v2 ^ ")"
+ | OEq (r, v1, v2) => "Var " ^ Int.toString r ^ " = OEq (" ^ valueToString v1 ^ ", " ^ valueToString v2 ^ ")"
+ | OIf (condition, target) => "OIf (" ^ valueToString condition ^ ") goto " ^ Int.toString target
| OLabel l => "OLabel " ^ Int.toString l
end