~james/remy

feat(cli): accept source input from standard input

commit
14346e112835db44d5eba27da0ca97089f621a91 browse tree
parent
d3257a26ac346abdf0585b20fadc11e2ca5812bd
author
james <j@cpl0.zip>
signature
Verified ~james signed with a key registered by ~james
date
2026-10-26 12:00 UTC

2 files changed, +13 −4

cli/driver.ML modified

@@ -6,10 +6,11 @@ fun text cs = String.implode (map (Char.chr o IntInf.toInt o Remy.ordinal) cs);
66
77 fun read path =
88 let
9- val stream = TextIO.openIn path
9+ val stream = if path = "-" then TextIO.stdIn else TextIO.openIn path
10+ fun close () = if path = "-" then () else TextIO.closeIn stream
1011 val input = TextIO.inputN (stream, 65537)
11- handle exn => (TextIO.closeIn stream; raise exn)
12- val _ = TextIO.closeIn stream
12+ handle exn => (close (); raise exn)
13+ val _ = close ()
1314 in
1415 if size input > 65536 then raise Fail "source exceeds 64 KiB" else chars input
1516 end;
@@ -71,7 +72,7 @@ fun main () =
7172 | ["check", binary] => output (Remy.validate (read binary))
7273 | ["disassemble", binary] => output (Remy.disassemble (read binary))
7374 | [source, destination] => emit destination (Remy.artifact (read source))
74- | _ => 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")
75+ | _ => 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)")
7576 handle exn =>
7677 (TextIO.output (TextIO.stdErr, "remy: " ^ General.exnMessage exn ^ "\n");
7778 OS.Process.exit OS.Process.failure);

tests/cli.py modified

@@ -86,6 +86,14 @@ def main():
8686 source.write_text('(+ x y)')
8787 invoke(source,source)
8888 assert source.read_bytes().endswith(bytes([195]))
89+ invoke('-',binary,data='(+ x y)')
90+ assert int(invoke('eval','-',3,4,0,data='(+ x y)')) == 7
91+ invoke('vectors','-',binary,data='(+ x y)')
92+ assert binary.stat().st_size == 16384
93+ for data in ['(+ x)', ' ' * 65537]:
94+ binary.write_bytes(b'preserve')
95+ invoke('-',binary,data=data,ok=False)
96+ assert binary.read_bytes() == b'preserve'
8997 source.write_text('é')
9098 assert 'ASCII' in invoke(source,binary,ok=False)
9199 for text in ['0x','0x10000000000000000','0xfg','0xffextra','-0x1']: