1 (* Scheme
-> C Compiler
*)
3 datatype SchemeToken
= LparenToken
10 | StringToken
of string
11 | SymbolToken
of string
16 | Pair
of Sexpr
* Sexpr
17 |
Vector of Sexpr list
24 datatype Expr
= Const
of Sexpr
26 | VarFree
of string (* free variable
*)
27 | VarParam
of string * int (* parameter variable
*)
28 | VarBound
of string * int * int (* bound variable
*)
29 | If
of Expr
* Expr
* Expr
30 | Abs
of (string list
) * Expr
31 | AbsOpt
of (string list
) * string * Expr
32 | AbsVar
of string * Expr
33 | App
of Expr
* (Expr list
)
34 | AppTP
of Expr
* (Expr list
) (* in tail position
*)
40 use
"./src/sml/utils.sml"; (* Utility functions
*)
41 use
"./src/sml/scanner.sml"; (* Scanner
*)
42 use
"./src/sml/reader.sml"; (* Reader
*)
43 use
"./src/sml/tag-parser.sml"; (* Tag Parser
*)
44 use
"./src/sml/sa.sml"; (* Semantic Analysis
*)
45 use
"./src/sml/cg.sml"; (* Code Generation
*)
49 val cg
: Expr
-> string;
50 val compileSchemeFile
: string * string -> unit
;
53 fun stringToFile (filename
: string, str
: string) =
55 val f
= TextIO.openOut filename
57 ( TextIO.output(f
, str
);
61 fun fileToString (filename
: string) =
63 val f
= TextIO.openIn filename
65 (case TextIO.input1 f
of
67 | SOME c
=> loop (c
:: s
))
68 val result
= String.implode (rev (loop
[]))
74 structure CodeGen
: CODE_GEN
=
77 fun cg (e
: Expr
) : string =
80 Program
.emit (8,1024*10))
84 ;map (fn expr
=> (Program
.gen (SemanticAnalysis
.semanticAnalysis expr
) 0))
85 (TagParser
.stringToPEs str
)
86 ;Program
.emit (8,1024*10)
89 fun compileSchemeFile (infile
:string, outfile
:string) : unit
=
92 (compile ((* (fileToString
"./src/scm/support-code.scm")^
*)
93 (fileToString infile
))));
95 end; (* of struct CodeGen
*)