return NEXT
end, flags=F_IMMED)
-CODE_CFA = defPrimWord("CODE", () -> begin
- pushPS(32)
- callPrim(mem[WORD_CFA])
- callPrim(mem[HEADER_CFA])
-
- exprString = "() -> begin\n"
- while true
- if mem[TOIN] >= mem[NUMTIB]
- exprString = string(exprString, "\n")
- if currentSource() == STDIN
- println()
- end
-
- pushPS(TIB)
- pushPS(160)
- callPrim(mem[EXPECT_CFA])
- mem[NUMTIB] = mem[SPAN]
- mem[TOIN] = 0
- end
-
- pushPS(32)
- callPrim(mem[WORD_CFA])
- cAddr = popPS()
- thisWord = getString(cAddr+1, mem[cAddr])
-
- if uppercase(thisWord) == "END-CODE"
- break
- end
-
- exprString = string(exprString, " ", thisWord)
- end
- exprString = string(exprString, "\nreturn NEXT\nend")
-
- func = eval(parse(exprString))
- dictWrite(defPrim(func))
+# ( addr n -- primAddr )
+CREATE_PRIM_CFA = defPrimWord("CREATE-PRIM", () -> begin
+ len = popPS()
+ addr = popPS()
+
+ exprString = string("() -> begin\n",
+ getString(addr, len), "\n",
+ "return NEXT\n",
+ "end")
+ func = eval(parse(expString))
+ pushPS(defPrim(func))
return NEXT
end)
: COUNT ( addr1 -- addr2 n )
DUP 1+ SWAP @ ;
+( Compares two strings, returns 0 if identical. )
+: COMPARE ( addr1 n1 addr2 n2 -- res )
+ rot 2dup <> if
+ 2drop 2drop 1 exit
+ then
+
+ drop
+
+ 0 do
+ 2dup i + @ swap i + @ <> if
+ unloop 2drop 1 exit
+ then
+ loop
+
+ 2drop 0
+;
+
+( Converts a string to lower case. )
+: TOLOWER ( addr n -- )
+ 0 do
+ dup i + @ dup dup ( addr char char char )
+ [char] A >=
+ swap [char] Z <= and if
+ [char] A - [char] a +
+ over i + !
+ else
+ drop
+ then
+ loop
+
+ drop
+;
+
( Abort if flag is true. )
: ABORT" IMMEDIATE ( flag -- )
[COMPILE] S"