eval word

This commit is contained in:
zeroflag 2021-06-28 16:06:17 +02:00
parent 89e6a64c1d
commit 386d25482a
2 changed files with 7 additions and 0 deletions

View file

@ -368,6 +368,7 @@ public class Fcl {
addPrimitive("var:", () -> { String name = word(); dict.add(new Var(dp, name)); dp++; });
addPrimitive("val:", () -> { String name = word(); dict.add(new Val(name, stack.pop())); });
addPrimitive("abort", () -> { throw new Aborted(stack.pop().asStr().value()); });
addPrimitive("eval", () -> eval(stack.pop().asStr().value()));
addPrimitive("words", () -> {
List<String> words = new ArrayList(wordList());
Collections.sort(words);

View file

@ -1133,6 +1133,12 @@ public class FclTest {
assertEquals("#[ ]#", evalPop("12 hist").toString());
}
@Test
public void testEval() {
assertEquals(3, evalPop(" '1 2 +' eval").intValue());
assertEquals(42, evalPop(" ': tst 42 ; tst' eval").intValue());
}
private String transcript() {
return transcript.content();
}