From: Tim Vaughan Date: Sat, 15 Oct 2016 00:42:41 +0000 (+1300) Subject: Can now define an initial file to run. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=74030e7ce7cbe674ac71767cff6e9c3f3564c3b0;p=forth.jl.git Can now define an initial file to run. --- diff --git a/src/forth.jl b/src/forth.jl index 877c2d2..02f74af 100644 --- a/src/forth.jl +++ b/src/forth.jl @@ -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 diff --git a/src/lib.4th b/src/lib.4th index fef3b42..d8d819b 100644 --- a/src/lib.4th +++ b/src/lib.4th @@ -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