diff --git a/src/main/res/raw/core.forth b/src/main/res/raw/core.forth index e1b9f82..61adcd1 100644 --- a/src/main/res/raw/core.forth +++ b/src/main/res/raw/core.forth @@ -52,4 +52,14 @@ : endcase ( #branches #branchesi*a -- ) immediate 0 do resolve loop ; var: exit.prim ( primitive exit - in case some word needs to override ) -` exit exit.prim ! \ No newline at end of file +` exit exit.prim ! + +: nop ; +: defer: + word create + ['] lit , + ['] nop , + ['] exec , + ['] exit , ; + +: is: ( xt -- ) ` 'longValue' jvm-call-method 1+ ! ; \ No newline at end of file diff --git a/src/test/java/com/vectron/fcl/FclTest.java b/src/test/java/com/vectron/fcl/FclTest.java index 3e7462c..4e461da 100644 --- a/src/test/java/com/vectron/fcl/FclTest.java +++ b/src/test/java/com/vectron/fcl/FclTest.java @@ -1139,6 +1139,33 @@ public class FclTest { assertEquals(42, evalPop(" ': tst 42 ; tst' eval").intValue()); } + @Test + public void testUnsetDefer() { + eval("defer: xx"); + eval("xx"); + assertEquals(0, fcl.stackSize()); + eval(": tst xx ;"); + assertEquals(0, fcl.stackSize()); + } + + @Test + public void testDefer() { // only works for colon defs and not for primitives + eval("defer: d1"); + eval("defer: d2"); + eval(": tst d1 d2 + ;"); + eval(": i1 11 ;"); + eval(": i2 22 ;"); + eval(": i3 42 ;"); + eval("` i1 is: d1"); + eval("` i2 is: d2"); + assertEquals(11, evalPop("d1").intValue()); + assertEquals(22, evalPop("d2").intValue()); + assertEquals(33, evalPop("tst").intValue()); + eval("` i3 is: d1"); + assertEquals(42, evalPop("d1").intValue()); + assertEquals(42+22, evalPop("tst").intValue()); + } + @Test public void testHttpHeaders() { assertEquals(