From 14346e112835db44d5eba27da0ca97089f621a91 Mon Sep 17 00:00:00 2001 From: james Date: Mon, 26 Oct 2026 12:00:00 +0000 Subject: [PATCH] feat(cli): accept source input from standard input --- cli/driver.ML | 9 +++++---- tests/cli.py | 8 ++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cli/driver.ML b/cli/driver.ML index 2d7eca380e4e15f56fed67212f32b59f59ad8bb2..493b9abaad5bab3d5ecaf8c97eb661d5bb1e25b8 100644 --- a/cli/driver.ML +++ b/cli/driver.ML @@ -6,10 +6,11 @@ fun text cs = String.implode (map (Char.chr o IntInf.toInt o Remy.ordinal) cs); fun read path = let - val stream = TextIO.openIn path + val stream = if path = "-" then TextIO.stdIn else TextIO.openIn path + fun close () = if path = "-" then () else TextIO.closeIn stream val input = TextIO.inputN (stream, 65537) - handle exn => (TextIO.closeIn stream; raise exn) - val _ = TextIO.closeIn stream + handle exn => (close (); raise exn) + val _ = close () in if size input > 65536 then raise Fail "source exceeds 64 KiB" else chars input end; @@ -71,7 +72,7 @@ fun main () = | ["check", binary] => output (Remy.validate (read binary)) | ["disassemble", binary] => output (Remy.disassemble (read binary)) | [source, destination] => emit destination (Remy.artifact (read source)) - | _ => 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") + | _ => 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 (source - reads standard input)") handle exn => (TextIO.output (TextIO.stdErr, "remy: " ^ General.exnMessage exn ^ "\n"); OS.Process.exit OS.Process.failure); diff --git a/tests/cli.py b/tests/cli.py index ab846e9556a9eb4997ccbc711f49d9e4670aae02..61e8d8eb7986efb37d5e43ff6c31dc4443398264 100644 --- a/tests/cli.py +++ b/tests/cli.py @@ -86,6 +86,14 @@ def main(): source.write_text('(+ x y)') invoke(source,source) assert source.read_bytes().endswith(bytes([195])) + invoke('-',binary,data='(+ x y)') + assert int(invoke('eval','-',3,4,0,data='(+ x y)')) == 7 + invoke('vectors','-',binary,data='(+ x y)') + assert binary.stat().st_size == 16384 + for data in ['(+ x)', ' ' * 65537]: + binary.write_bytes(b'preserve') + invoke('-',binary,data=data,ok=False) + assert binary.read_bytes() == b'preserve' source.write_text('é') assert 'ASCII' in invoke(source,binary,ok=False) for text in ['0x','0x10000000000000000','0xfg','0xffextra','-0x1']: