summaryrefslogtreecommitdiffstats
path: root/syntax.sml
diff options
context:
space:
mode:
Diffstat (limited to 'syntax.sml')
-rw-r--r--syntax.sml18
1 files changed, 11 insertions, 7 deletions
diff --git a/syntax.sml b/syntax.sml
index aa94b09..5672a5b 100644
--- a/syntax.sml
+++ b/syntax.sml
@@ -32,6 +32,7 @@ struct
and dec =
DVal of pat * expr
| DValRec of pat * expr
+ | DFun of string * (pat list * expr) list
| DDatatype of string * (string * etype option) list
(* Lambda language *)
@@ -145,6 +146,7 @@ struct
case x of
DVal (p, e) => "DVal (" ^ patToString p ^ ", " ^ exprToStringI indent e ^ ")"
| DValRec (p, e) => "DValRec (" ^ patToString p ^ ", " ^ exprToStringI indent e ^ ")"
+ | DFun (name, cases) => "DFun (" ^ quote name ^ ", " ^ multilineListToString (fn indent => fn (ps, b) => "(" ^ listToString patToString ps ^ ", " ^ exprToStringI indent b ^ ")") indent cases ^ ")"
| DDatatype (name, arms) => "DDatatype (" ^ quote name ^ ", " ^ listToString (fn (con, v) => "(" ^ quote con ^ ", " ^ optionToString etypeToString v ^ ")") arms ^ ")"
val exprToString : expr -> string = exprToStringI ""
@@ -162,18 +164,20 @@ struct
| PEq => "PEq"
| PIf => "PIf"
- fun lexpToString (x : lexp) : string =
+ fun lexpToStringI (indent : string) (x : lexp) : string =
case x of
LVar v => "LVar " ^ Int.toString v
- | LFn (arg, expr) => "LFun (" ^ Int.toString arg ^ ", " ^ lexpToString expr ^ ")"
- | LFix (decls, body) => "LFix (" ^ listToString (fn (arg, var, expr) => "(" ^ Int.toString arg ^ ", " ^ Int.toString var ^ ", " ^ lexpToString expr ^ ")") decls ^ ", " ^ lexpToString body ^ ")"
- | LApp (a, b) => "LApp (" ^ lexpToString a ^ ", " ^ lexpToString b ^ ")"
+ | LFn (arg, expr) => "LFun (" ^ Int.toString arg ^ ",\n" ^ indent ^ "\t" ^ lexpToStringI (indent ^ "\t") expr ^ ")"
+ | LFix (decls, body) => "LFix (" ^ multilineListToString (fn indent => fn (arg, var, expr) => "(" ^ Int.toString arg ^ ", " ^ Int.toString var ^ ", " ^ lexpToStringI indent expr ^ ")") indent decls ^ ",\n" ^ indent ^ lexpToStringI indent body ^ ")"
+ | LApp (a, b) => "LApp (" ^ lexpToStringI indent a ^ ",\n" ^ indent ^ "\t" ^ lexpToStringI (indent ^ "\t") b ^ ")"
| LInt i => "LInt " ^ Int.toString i
| LString s => "LString " ^ quote s
- | LRecord l => "LRecord " ^ listToString lexpToString l
- | LSelect (i, r) => "LSelect (" ^ Int.toString i ^ ", " ^ lexpToString r ^ ")"
+ | LRecord l => "LRecord " ^ listToString (lexpToStringI indent) l
+ | LSelect (i, r) => "LSelect (" ^ Int.toString i ^ ", " ^ lexpToStringI indent r ^ ")"
| LPrim p => "LPrim " ^ primopToString p
- | LSwitch (e, arms, otherwise) => "LSwitch (" ^ lexpToString e ^ ", " ^ listToString (fn (x, e) => "(" ^ Int.toString x ^ ", " ^ lexpToString e ^ ")") arms ^ ", " ^ optionToString lexpToString otherwise ^ ")"
+ | LSwitch (e, arms, otherwise) => "LSwitch (" ^ lexpToStringI indent e ^ ",\n" ^ indent ^ "\t" ^ multilineListToString (fn indent => fn (x, e) => "(" ^ Int.toString x ^ ", " ^ lexpToStringI indent e ^ ")") (indent ^ "\t") arms ^ ",\n" ^ indent ^ "\t" ^ optionToString (lexpToStringI (indent ^ "\t")) otherwise ^ ")"
+
+ fun lexpToString (x : lexp) : string = lexpToStringI "" x
fun valueToString (x : value) : string =
case x of