about summary refs log tree commit diff
path: root/language/dynamic
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-10-05 20:58:52 -0700
committerIrene Knapp <ireneista@irenes.space>2026-10-05 20:58:52 -0700
commit2b601cdda09dc566c011efd1c5f72c30b196e1d3 (patch)
tree9a9d6854311488e56b63563c581d4a91104c9260 /language/dynamic
parent39304d51c4a6d057e6515a9f75db2086940f6877 (diff)
yessssssssssss, nice clean invocation now
Force-Push: yes
Change-Id: Id3bfde4a2053c9f07fd596def8381afc505949eb
Diffstat (limited to 'language/dynamic')
-rw-r--r--language/dynamic/command-line.e53
1 files changed, 52 insertions, 1 deletions
diff --git a/language/dynamic/command-line.e b/language/dynamic/command-line.e
index 8e2d812..4b3ab6d 100644
--- a/language/dynamic/command-line.e
+++ b/language/dynamic/command-line.e
@@ -1,3 +1,28 @@
+~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+~ ~~ Command-line parameter semantics ~~
+~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+~
+~   The Evocation executable runs as a command-line tool. As part of that, it
+~ accepts command-line parameters via the POSIX argc/argv interface. The code
+~ in this file implements the semantics of those parameters.
+~
+~   The rule is quite simple: Each parameter is treated as a single word, and
+~ run as if by "interpret". When a parameter is neither a regular word nor an
+~ integer literal, if it looks like it could be a source code filename, the
+~ file it names is read as if by "include", except that the success flag is
+~ discarded.
+~
+~   Nothing special is done to make command-line parameters appear as if
+~ they're an input stream; they're not. They're special words that are invoked
+~ before standard input is touched. Anything words run as command-line
+~ parameters try to do to standard input will draw on standard input as usual,
+~ despite that not being where they themselves come from, which will likely
+~ cause unwanted behavior. See language/boot-source-footer.e for the exact
+~ sequence of events during startup.
+~
+~   In particular, this means that words such as s" and ', which try to read
+~ input, are unlikely to do what you want as command-line parameters.
+
 8 2 * allocate s" argument-scan-state" variable
 : argument-scan-state-next-argument-handle ;
 : argument-scan-state-n-remaining-arguments 8 + ;
@@ -11,6 +36,28 @@
   argument-scan-state argument-scan-state-next-argument-handle @
   argument-scan-state argument-scan-state-n-remaining-arguments @ ;
 
+
+~   This tests whether a string looks like it could be an Evocation
+~ source-code filename.
+~
+~   Specifically, it looks for an extension of *.e. Also, it disallows ".e" by
+~ itself as a filename, requiring the length to be at least three characters.
+~
+~   This comparison is done case-sensitively. This means that, even on a
+~ case-insensitive filesystem, from Evocation's perspective we always require
+~ the extension to be treated as lowercase.
+~
+~ (string pointer -- boolean)
+: is-possible-source-filename
+  dup stringlen
+  ~ (string pointer, length)
+  dup 2 < {
+    2 - + s" .e" stringcmp 0 =
+  } {
+    2drop 0
+  } if-else ;
+
+
 ~ (argument pointer -- *)
 : process-command-line-argument
   dup find dup {
@@ -34,7 +81,11 @@
       } if-else
     } {
       ~ (argument pointer)
-      ." No such word: " emitstring newline
+      dup is-possible-source-filename {
+        include drop
+      } {
+        ." No such word: " emitstring newline
+      } if-else
     } if-else
   } if-else ;