Can now define an initial file to run.
authorTim Vaughan <tgvaughan@gmail.com>
Sat, 15 Oct 2016 00:42:41 +0000 (13:42 +1300)
committerTim Vaughan <tgvaughan@gmail.com>
Sat, 15 Oct 2016 00:42:41 +0000 (13:42 +1300)
src/forth.jl
src/lib.4th

index 877c2d2..02f74af 100644 (file)
@@ -1229,6 +1229,20 @@ INCLUDE_CFA = defWord("INCLUDE", [LIT_CFA, 32, WORD_CFA,
     SWAP_CFA, FETCH_CFA,
     INCLUDED_CFA, EXIT_CFA]);
 
+ABORT_CFA = defWord("ABORT",
+    [CLOSE_FILES_CFA, DROP_CFA, PSP0_CFA, PSPSTORE_CFA, QUIT_CFA])
+
+BYE_CFA = defPrimWord("BYE", () -> begin
+    println("\nBye!")
+    return 0
+end)
+
+EOF_CFA = defPrimWord("\x04", () -> begin
+    return 0
+end)
+
+### Library loading ###
+
 oldCWD = ""
 SETLIBCWD_CFA = defPrimWord("SETLIBCWD", () -> begin
     global oldCWD = pwd()
@@ -1251,37 +1265,38 @@ INCLUDE_LIB_CFA = defWord("INCLUDE-LIB", [LIT_CFA, 32, WORD_CFA,
     SWAP_CFA, FETCH_CFA,
     INCLUDED_LIB_CFA, EXIT_CFA]);
 
-ABORT_CFA = defWord("ABORT",
-    [CLOSE_FILES_CFA, DROP_CFA, PSP0_CFA, PSPSTORE_CFA, QUIT_CFA])
-
-BYE_CFA = defPrimWord("BYE", () -> begin
-    println("\nBye!")
-    return 0
-end)
-
-EOF_CFA = defPrimWord("\x04", () -> begin
-    return 0
-end)
+SKIP_WELCOME, SKIP_WELCOME_CFA = defNewVar("SKIP-WELCOME", 0)
 
 #### VM loop ####
 
 initialized = false
-initFileName = "lib.4th"
+libFileName = "lib.4th"
 
-function run(;initialize=true)
+function run(fileName=nothing; initialize=true)
 
     # Start with IP pointing to first instruction of outer interpreter
     pushRS(QUIT_CFA+1)
 
+    # Include optional file
+    if fileName != nothing
+        putString(fileName, mem[H])
+        pushPS(mem[H])
+        mem[H] += length(fileName)
+        pushPS(length(fileName))
+        pushRS(INCLUDED_CFA+1)
+
+        mem[SKIP_WELCOME] = -1
+    end
+
     # Load library files
-    global initialized, initFileName
+    global initialized, libFileName
     if !initialized && initialize
-        if initFileName != nothing
-            print("Including definitions from $initFileName...")
+        if libFileName != nothing
+            #print("Including definitions from $libFileName...")
 
-            putString(initFileName, mem[H])
+            putString(libFileName, mem[H])
             pushPS(mem[H])
-            pushPS(length(initFileName))
+            pushPS(length(libFileName))
             pushRS(INCLUDED_LIB_CFA+1)
 
             initialized = true
index fef3b42..d8d819b 100644 (file)
@@ -17,4 +17,9 @@ include lib_9_decompiler.4th
 include lib_10_misc.4th
 include lib_11_extensions.4th
 
-.(  done.) cr
+: WELCOME
+    SKIP-WELCOME @ INVERT IF
+        ." Welcome to forth.jl!" CR CR
+    THEN
+;
+welcome