about summary refs log tree commit diff
path: root/language
diff options
context:
space:
mode:
Diffstat (limited to 'language')
-rw-r--r--language/boot-source-footer.e2
-rw-r--r--language/dynamic/command-line.e61
2 files changed, 63 insertions, 0 deletions
diff --git a/language/boot-source-footer.e b/language/boot-source-footer.e
index 97a8c5b..e95fc0e 100644
--- a/language/boot-source-footer.e
+++ b/language/boot-source-footer.e
@@ -2,5 +2,7 @@
 ~ last thing in the boot-source. It has the responsibility of switching from
 ~ processing boot-source into the regular interaction mode.
 
+process-command-line-arguments
+
 relink-main-input-buffer-to-stdin
 
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 ;
+