From: Tim Vaughan Date: Fri, 22 Apr 2016 03:21:16 +0000 (+1200) Subject: Added TICK, BRANCH, 0BRANCH X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=cf53a68bcea007d723e2037fb94577700532b00e;p=forth.jl.git Added TICK, BRANCH, 0BRANCH --- diff --git a/src/forth.jl b/src/forth.jl index 8c5c3de..101cca8 100644 --- a/src/forth.jl +++ b/src/forth.jl @@ -726,9 +726,30 @@ IMMEDIATE = defPrim("IMMEDIATE", () -> begin return mem[NEXT] end, flags=F_IMMEDIATE) +TICK = defWord("'", [WORD, FIND, TOCFA, EXIT]) + +# Branching + +BRANCH = defPrim("BRANCH", () -> begin + reg.IP += mem[reg.IP] + return mem[NEXT] +end) + +ZBRANCH = defPrim("0BRANCH", () -> begin + if (popPS() == 0) + reg.IP += mem[reg.IP] + else + reg.IP += 1 + end + + return mem[NEXT] +end) + +# Strings + #### VM loop #### function runVM() - jmp = NEXT + jmp = mem[NEXT] while (jmp = callPrim(jmp)) != 0 end end