~james/remy

4
3e3f52cd4b5a7e127a8a6834b895a5537dcf5b47
main
remy/cli/driver.ML -rw-r--r--1.6 KiB ViewLogBlameView rawPermalink 3ac5bae085 feat(compiler): add verified pixel compiler and templeos runner 2 months 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 main () =
30 (case CommandLine.arguments () of
31 ["vectors", source, destination] =>
32 (case Remy.vectors (read source) of (true, bytes) => write destination bytes | result => output result)
33 | ["eval", source, x, y, t] => output (Remy.reference (read source) (chars x) (chars y) (chars t))
34 | [source, destination] =>
35 let val ((ok, bytes), report) = Remy.artifact (read source)
36 in if ok then (write destination bytes; output (true,report)) else output (false,report) end
37 | _ => raise Fail "usage: remy source binary | remy vectors source data | remy eval source x y t")
38 handle exn =>
39 (TextIO.output (TextIO.stdErr, "remy: " ^ General.exnMessage exn ^ "\n");
40 OS.Process.exit OS.Process.failure);