defer: + is:

This commit is contained in:
zeroflag 2021-06-30 14:51:29 +02:00
parent 5105ab2351
commit 62be7a78f1
2 changed files with 38 additions and 1 deletions

View file

@ -53,3 +53,13 @@
var: exit.prim ( primitive exit - in case some word needs to override )
` exit exit.prim !
: nop ;
: defer:
word create
['] lit ,
['] nop ,
['] exec ,
['] exit , ;
: is: ( xt -- ) ` 'longValue' jvm-call-method 1+ ! ;

View file

@ -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(