From: Tim Vaughan Date: Wed, 12 Oct 2016 09:12:05 +0000 (+1300) Subject: CODE now a library word. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=b5c0bc63b635d113a5fafacbf5c0c7634a9a3012;p=forth.jl.git CODE now a library word. --- diff --git a/src/forth.jl b/src/forth.jl index 9939c9c..877c2d2 100644 --- a/src/forth.jl +++ b/src/forth.jl @@ -1143,7 +1143,7 @@ CREATE_PRIM_CFA = defPrimWord("CREATE-PRIM", () -> begin getString(addr, len), "\n", "return NEXT\n", "end") - func = eval(parse(expString)) + func = eval(parse(exprString)) pushPS(defPrim(func)) return NEXT diff --git a/src/lib.4th b/src/lib.4th index 86731cf..fef3b42 100644 --- a/src/lib.4th +++ b/src/lib.4th @@ -15,5 +15,6 @@ include lib_7_variables.4th include lib_8_vocab.4th include lib_9_decompiler.4th include lib_10_misc.4th +include lib_11_extensions.4th .( done.) cr diff --git a/src/lib_11_extensions.4th b/src/lib_11_extensions.4th new file mode 100644 index 0000000..1e28933 --- /dev/null +++ b/src/lib_11_extensions.4th @@ -0,0 +1,41 @@ +\ Non-core extension words + +CREATE CODEBUFFER 1000 CELLS ALLOT +VARIABLE >CB +0 >CB ! + +: PARSE-CODE + 0 >CB ! + + BEGIN + >IN @ #IB @ >= IF \ End of IB? + '\n' CODEBUFFER >CB @ + ! + 1 >CB +! + SOURCE-ID 0= IF CR THEN + QUERY-INPUT \ Get next line + ELSE + BL CODEBUFFER >CB @ + ! + 1 >CB +! + THEN + + BL WORD COUNT + 2DUP ( addr n addr n) + PAD SWAP CMOVE + + PAD OVER TOLOWER + PAD OVER s" end-code" COMPARE + 0= IF + 2DROP EXIT + THEN + + dup -rot ( n addr n ) + CODEBUFFER >CB @ + SWAP CMOVE + >CB +! + AGAIN +; + +: CODE + BL WORD HEADER + PARSE-CODE + CODEBUFFER >CB @ CREATE-PRIM , +;