~james/remy

3
31d281ada88d2822fbbece49ea5e511b0ad3ada3
main
remy/cli/driver.ML -rw-r--r--2.0 KiB ViewLogBlameView rawPermalink 31d281ada8 feat(checker): validate native stack and register effects 23 days ago
1val root = valOf (OS.Process.getEnv "REMY_ROOT");
2val _ = use (root ^ "/.build/Remy.Export/code/remy.ML");
3
4fun chars s = map (Remy.ascii o IntInf.fromInt o Char.ord) (String.explode s);
5fun text cs = String.implode (map (Char.chr o IntInf.toInt o Remy.ordinal) cs);
6
7fun read path =
8 let
9 val stream = TextIO.openIn path
10 val input = TextIO.inputN (stream, 65537)
11 handle exn => (TextIO.closeIn stream; raise exn)
12 val _ = TextIO.closeIn stream
13 in
14 if size input > 65536 then raise Fail "source exceeds 64 KiB" else chars input
15 end;
16
17fun write path bytes =
18 let
19 val stream = BinIO.openOut path
20 in
21 (BinIO.output (stream, Byte.stringToBytes (text bytes)); BinIO.closeOut stream)
22 handle exn => ((BinIO.closeOut stream handle _ => ()); raise exn)
23 end;
24
25fun output (ok, message) =
26 (TextIO.output (if ok then TextIO.stdOut else TextIO.stdErr, text message);
27 if ok then () else OS.Process.exit OS.Process.failure);
28
29fun emit destination ((ok, bytes), report) =
30 if ok then (write destination bytes; output (true,report)) else output (false,report);
31
32fun main () =
33 (case CommandLine.arguments () of
34 ["vectors", source, destination] =>
35 (case Remy.vectors (read source) of (true, bytes) => write destination bytes | result => output result)
36 | ["eval", source, x, y, t] => output (Remy.reference (read source) (chars x) (chars y) (chars t))
37 | ["limits", depth, nodes, stack, source, destination] =>
38 emit destination (Remy.configured (chars depth) (chars nodes) (chars stack) (read source))
39 | ["check", binary] => output (Remy.validate (read binary))
40 | ["disassemble", binary] => output (Remy.disassemble (read binary))
41 | [source, destination] => emit destination (Remy.artifact (read source))
42 | _ => raise Fail "usage: remy check binary | remy disassemble binary | remy limits depth nodes stack source binary | remy source binary | remy vectors source data | remy eval source x y t")
43 handle exn =>
44 (TextIO.output (TextIO.stdErr, "remy: " ^ General.exnMessage exn ^ "\n");
45 OS.Process.exit OS.Process.failure);