-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmicroc.fs
32 lines (24 loc) · 922 Bytes
/
microc.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
let fromFile = Parse.fromFile
let compileToFile = Comp.compileToFile
let argv = System.Environment.GetCommandLineArgs()
let args = Array.filter ((<>) "-g") argv
let _ = printfn "Micro-C Stack VM compiler v 1.2.0 of 2021-5-12"
let _ =
if args.Length > 1 then
let source = args.[1]
let stem =
if source.EndsWith(".c") then
source.Substring(0, source.Length - 2)
else
source
let target = stem + ".out"
printfn "Compiling %s ......\n" source
try
(let instrs = compileToFile (fromFile source) stem
// printf "StackVM code:\n%A\n" instrs;
printfn "Numeric code saved in file:\n\t%s\nPlease run with VM." target)
with
| Failure msg -> printfn "ERROR: %s" msg
| exn -> printfn "ERROR: %s" exn.Message
else
printfn "Usage: microc.exe <source file>"