From: Tim Vaughan Date: Tue, 24 May 2016 09:47:53 +0000 (+1200) Subject: Working on CREATE/DOES> X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=2268c3eaeb5a3a885ee4d63d64ef454549039a22;p=forth.jl.git Working on CREATE/DOES> --- diff --git a/src/forth.jl b/src/forth.jl index 0194736..0835e4b 100644 --- a/src/forth.jl +++ b/src/forth.jl @@ -912,6 +912,37 @@ HEADER = defPrimWord("HEADER", () -> begin return NEXT end) +CREATE = defWord("CREATE", + [LIT, 32, WORD, HEADER, + LIT, DOVAR, COMMA, + EXIT]); + +DODOES = defPrim(() -> begin + pushRS(reg.IP) + reg.IP = popPS() + return NEXT +end, name="DODOES") + +BDOES = defPrimWord("(DOES>)", () -> begin + pushPS(mem[LATEST]) + callPrim(mem[TOCFA]) + cfa = popPS() + println(cfa) + + mem[cfa] = defPrim(eval(:(() -> begin + pushPS($(mem[H])) + return DODOES + end)), name="doesPrim") + + mem[mem[H]] = LIT; mem[H] += 1 + mem[mem[H]] = cfa+1; mem[H] += 1 + + return NEXT +end, flags=F_IMMED) + +DOES = defWord("DOES>", + [BDOES, EXIT]) + LBRAC = defPrimWord("[", () -> begin mem[STATE] = 0 return NEXT