summaryrefslogtreecommitdiffstats
path: root/compiler.sml
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2023-02-12 15:37:25 -0800
committerRose Hogenson <rhogenson@posteo.net>2023-02-12 15:37:25 -0800
commitd940187fd8720e0ab3c00e5a6a7ae8f181c7752d (patch)
tree69df829ae1e7fb9454008920b49db08489d939a6 /compiler.sml
parentChange how slices work. (diff)
downloadsml-d940187fd8720e0ab3c00e5a6a7ae8f181c7752d.tar.zst
Add lambda functions.
Diffstat (limited to 'compiler.sml')
-rw-r--r--compiler.sml17
1 files changed, 10 insertions, 7 deletions
diff --git a/compiler.sml b/compiler.sml
index 599d85a..4c5e238 100644
--- a/compiler.sml
+++ b/compiler.sml
@@ -2,25 +2,28 @@ structure Compiler =
struct
fun compile (prog : Syntax.expr) : Word8Vector.vector =
let
+ val _ = print ("ast:\n" ^ Syntax.exprToString prog ^ "\n")
val elab = Elab.elaborate prog
+ val _ = print ("lambda lang:\n" ^ Syntax.lexpToString elab ^ "\n")
val cps =
- CPS.convertClosures
- (CPS.toCPS elab
- (fn _ => Syntax.CPrimop (Syntax.PExit, [Syntax.VInt 0], [], [])))
- val _ = print ("cps:\n" ^ Syntax.cexpToString cps ^ "\n")
- val asm = CodeGen.toASM cps
+ CPS.toCPS elab
+ (fn _ => Syntax.CPrimop (Syntax.PExit, [Syntax.VInt 0], [], []))
+ val _ = print ("cps1:\n" ^ Syntax.cexpToString cps ^ "\n")
+ val cps' = CPS.convertClosures cps
+ val _ = print ("cps:\n" ^ Syntax.cexpToString cps' ^ "\n")
+ val asm = CodeGen.toASM cps'
val _ = print ("bytecode:\n" ^ String.concatWith "\n" (map Syntax.opcodeToString asm) ^ "\n")
in
Linker.link asm
end
- fun main () =
+ fun main (args : string list) : unit =
let
val opts = { o = ref "a.out" }
val flags =
[ ("o", Opts.StringOpt (fn arg => #o opts := arg)) ]
val filename =
- case Opts.getOpt flags of
+ case Opts.getOpt flags args of
[arg] => arg
| _ => raise Fail "usage: sml [-o <outfile>] <filename>"
val ast =