all repos — xyw @ a9215ea544b6ef9fbced607b89569ae8a887357e

A minimal virtual machine and assembler for terminals.

Improved cmdexec example
h3rald h3rald@h3rald.com
Fri, 07 Aug 2026 12:58:59 +0000
commit

a9215ea544b6ef9fbced607b89569ae8a887357e

parent

24fc8cfd45178b30d9c8e2bae216a4b2789bae27

2 files changed, 42 insertions(+), 14 deletions(-)

jump to
M examples/cmdexec.xywexamples/cmdexec.xyw

@@ -7,22 +7,50 @@ output file.read STW

$0100 file.length STW ; Execute command file.op.exec file.operation STB -; Print captured output -output-prefix puts JSRw -output puts JSRw -; Print: Result: <code>\n -result-prefix puts JSRw -file.result LDW putdw JSRw NL +; Print OS based on output +output linux contains JSRw print-linux JCNw +output bsd contains JSRw print-bsd JCNw +output darwin contains JSRw print-macos JCNw +output mingw contains JSRw print-windows JCNw +output windows contains JSRw print-windows JCNw +unknown puts JSRw NL +.label halt HLT -.include "lib/putdw.xyw" +.label print-windows + windows puts JSRw NL + halt JMPw + +.label print-linux + linux puts JSRw NL + halt JMPw + +.label print-bsd + bsd puts JSRw NL + halt JMPw + +.label print-macos + macos puts JSRw NL + halt JMPw + .include "lib/puts.xyw" +.include "lib/contains.xyw" .label output .reserve $0100 -.label output-prefix -.string "Output: " -.label result-prefix -.string "Result: " .label cmd -.string "uname -s"+.string "uname -s" +.label linux +.string "Linux" +.label bsd +.string "BSD" +.label darwin +.string "Darwin" +.label mingw +.string "MinGW" +.label windows +.string "Windows" +.label macos +.string "macOS" +.label unknown +.string "Unknown"
M test.shtest.sh

@@ -14,7 +14,7 @@ run_test fileops.xyw -- assert_output_equals $'This is a test file.\nIt has multiple lines.\n'

# Cleanup test file rm -f "$EXAMPLES_DIR/test.txt" run_test launcher.xyw -- assert_output_equals $'Executing: print-args.xim hello world\nprint-args.xim, hello, world\nExecuting: helloworld.xim\nHello, World!\nDone!\n' - run_test cmdexec.xyw -- assert_output_matches $'MINGW|Linux|BSD|Darwin' + run_test cmdexec.xyw -- assert_output_matches $'Windows|Linux|BSD|macOS' } ### Helper functions

@@ -350,4 +350,4 @@

echo -e "\n=> All tests passed." } -main "$@"+main "$@"