From 30a093845e2d1097242e948bb577fb71f73bc860 Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Tue, 11 Oct 2016 21:37:54 +1300 Subject: [PATCH] Moved some input stream words to library. --- src/forth.jl | 44 +++++++------------ src/lib.4th | 15 ++++--- src/{lib_9_misc.4th => lib_10_misc.4th} | 0 src/lib_3_input.4th | 12 +++++ ...{lib_3_comments.4th => lib_4_comments.4th} | 0 ...{lib_4_printnum.4th => lib_5_printnum.4th} | 0 src/{lib_5_strings.4th => lib_6_strings.4th} | 0 ...ib_6_variables.4th => lib_7_variables.4th} | 0 src/{lib_7_vocab.4th => lib_8_vocab.4th} | 0 ..._8_decompiler.4th => lib_9_decompiler.4th} | 0 10 files changed, 36 insertions(+), 35 deletions(-) rename src/{lib_9_misc.4th => lib_10_misc.4th} (100%) create mode 100644 src/lib_3_input.4th rename src/{lib_3_comments.4th => lib_4_comments.4th} (100%) rename src/{lib_4_printnum.4th => lib_5_printnum.4th} (100%) rename src/{lib_5_strings.4th => lib_6_strings.4th} (100%) rename src/{lib_6_variables.4th => lib_7_variables.4th} (100%) rename src/{lib_7_vocab.4th => lib_8_vocab.4th} (100%) rename src/{lib_8_decompiler.4th => lib_9_decompiler.4th} (100%) diff --git a/src/forth.jl b/src/forth.jl index c540313..6afe492 100644 --- a/src/forth.jl +++ b/src/forth.jl @@ -969,29 +969,18 @@ FIB_CFA = defConst("FIB", FIB) NUMFIB, NUMFIB_CFA = defNewVar("#FIB", 0) IB_CFA = defPrimWord("IB", () -> begin - pushPS(mem[SOURCE_ID] == 0 ? TIB : FIB) + pushPS(mem[SOURCE_ID_VAR] == 0 ? TIB : FIB) return NEXT end) NUMIB_CFA = defPrimWord("#IB", () -> begin - pushPS(mem[SOURCE_ID] == 0 ? NUMTIB : NUMFIB) + pushPS(mem[SOURCE_ID_VAR] == 0 ? NUMTIB : NUMFIB) return NEXT end) TOIN, TOIN_CFA = defNewVar(">IN", 0) -SOURCE_ID, SOURCE_ID_CFA = defNewVar("SOURCE-ID", 0) - -SOURCE_CFA = defPrimWord("SOURCE", () -> begin - if mem[SOURCE_ID] == 0 - pushPS(TIB) - pushPS(NUMTIB) - else - pushPS(FIB) - pushPS(NUMFIB) - end - return NEXT -end) +SOURCE_ID_VAR, SOURCE_ID_VAR_CFA = defNewVar("SOURCE-ID-VAR", 0) QUERY_CFA = defWord("QUERY", [TIB_CFA, LIT_CFA, 160, EXPECT_CFA, @@ -1010,17 +999,16 @@ QUERY_FILE_CFA = defWord("QUERY-FILE", LIT_CFA, 0, TOIN_CFA, STORE_CFA, EXIT_CFA]) -QUERY_INPUT_CFA = defWord("QUERY-INPUT", - [SOURCE_ID_CFA, FETCH_CFA, QDUP_CFA, ZBRANCH_CFA, 3, - QUERY_FILE_CFA, EXIT_CFA, - QUERY_CFA, EXIT_CFA]) - WORD_CFA = defPrimWord("WORD", () -> begin delim = popPS() - callPrim(mem[SOURCE_CFA]) - sizeAddr = popPS() - bufferAddr = popPS() + if mem[SOURCE_ID_VAR] == 0 + bufferAddr = TIB + sizeAddr = NUMTIB + else + bufferAddr = FIB + sizeAddr = NUMFIB + end # Chew up initial occurrences of delim while (mem[TOIN]