From a0ef3365458bdd8e99d0d4bb05c6de9f13527ad6 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Mon, 5 Oct 2026 12:31:30 -0700 Subject: The "evoke" executable now accepts command-line parameters. They can be regular words, and integer literals. In the near future perhaps source files will also be acceptable, but there's other work to do first. Force-Push Change-Id: Ib97db00126139aefdcdc725f9ccf6b045ceb3d2d --- language/dynamic/command-line.e | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 language/dynamic/command-line.e (limited to 'language/dynamic') diff --git a/language/dynamic/command-line.e b/language/dynamic/command-line.e new file mode 100644 index 0000000..8e2d812 --- /dev/null +++ b/language/dynamic/command-line.e @@ -0,0 +1,61 @@ +8 2 * allocate s" argument-scan-state" variable +: argument-scan-state-next-argument-handle ; +: argument-scan-state-n-remaining-arguments 8 + ; + +~ (next argument handle, n remaining arguments --) +: save-argument-scan-state + argument-scan-state argument-scan-state-n-remaining-arguments ! + argument-scan-state argument-scan-state-next-argument-handle ! ; +~ (-- next argument handle, n remaining arguments) +: restore-argument-scan-state + argument-scan-state argument-scan-state-next-argument-handle @ + argument-scan-state argument-scan-state-n-remaining-arguments @ ; + +~ (argument pointer -- *) +: process-command-line-argument + dup find dup { + ~ (argument pointer, entry pointer) + swap drop + interpreter-flags @ 0x01 & { + dup entry-flags@ 1 & + swap entry-to-execution-token swap + { execute } { , } if-else + } { entry-to-execution-token execute } if-else + } { + drop + ~ (argument pointer) + dup read-integer 0 = { + ~ (argument pointer, integer value) + interpreter-flags @ 0x01 & { + x' lit , , + drop + } { + swap drop + } if-else + } { + ~ (argument pointer) + ." No such word: " emitstring newline + } if-else + } if-else ; + +: process-command-line-arguments + s0 @ + dup @ + swap 8 + + swap + ~ (next argument handle, n remaining arguments) + dup { + ~ Skip the executable name. + 1- swap 8 + swap + + { dup } { + over @ + 3unroll save-argument-scan-state + + process-command-line-argument + + restore-argument-scan-state + 1- swap 8 + swap + } while + } if 2drop ; + -- cgit 1.4.1