From: Tim Vaughan Date: Tue, 24 May 2016 11:36:48 +0000 (+1200) Subject: CREATE/DOES> working. Closes #2. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=d75b27e59e0ea50e52018239a74e1edc831219f7;p=forth.jl.git CREATE/DOES> working. Closes #2. --- diff --git a/src/forth.jl b/src/forth.jl index 0835e4b..80f6b76 100644 --- a/src/forth.jl +++ b/src/forth.jl @@ -902,6 +902,9 @@ end) # Compilation +HERE = defWord("HERE", + [H_CFA, FETCH, EXIT]) + HEADER = defPrimWord("HEADER", () -> begin wordAddr = popPS()+1 wordLen = mem[wordAddr-1] @@ -915,33 +918,35 @@ end) CREATE = defWord("CREATE", [LIT, 32, WORD, HEADER, LIT, DOVAR, COMMA, - EXIT]); + EXIT]) DODOES = defPrim(() -> begin pushRS(reg.IP) reg.IP = popPS() + pushPS(reg.W + 1) return NEXT end, name="DODOES") -BDOES = defPrimWord("(DOES>)", () -> begin +DOES_HELPER = defPrimWord("(DOES>)", () -> begin + pushPS(mem[LATEST]) callPrim(mem[TOCFA]) cfa = popPS() - println(cfa) + + runtimeAddr = popPS() mem[cfa] = defPrim(eval(:(() -> begin - pushPS($(mem[H])) + pushPS($(runtimeAddr)) 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]) + [BTICK, LIT, COMMA, HERE, LIT, 3, ADD, COMMA, + BTICK, DOES_HELPER, COMMA, BTICK, EXIT, COMMA, EXIT], + flags=F_IMMED) LBRAC = defPrimWord("[", () -> begin mem[STATE] = 0 diff --git a/src/lib.4th b/src/lib.4th index f8eb737..647b499 100644 --- a/src/lib.4th +++ b/src/lib.4th @@ -27,8 +27,6 @@ : DEPTH PSP@ PSP0 - ; -: HERE H @ ; - : '\n' 10 ; : BL 32 ;