diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-10-05 12:31:30 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-10-05 12:31:30 -0700 |
| commit | a0ef3365458bdd8e99d0d4bb05c6de9f13527ad6 (patch) | |
| tree | 8382a512d364cded0eb8fa0ea748f5f626f5a9fb /language/dynamic/command-line.e | |
| parent | 85afda64df4290527157f50646a09c32491f16d4 (diff) | |
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
Diffstat (limited to 'language/dynamic/command-line.e')
| -rw-r--r-- | language/dynamic/command-line.e | 61 |
1 files changed, 61 insertions, 0 deletions
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 ; + |