mirror of
https://github.com/zeroflag/fcl.git
synced 2025-01-11 20:01:10 +01:00
eval word
This commit is contained in:
parent
89e6a64c1d
commit
386d25482a
2 changed files with 7 additions and 0 deletions
|
@ -368,6 +368,7 @@ public class Fcl {
|
||||||
addPrimitive("var:", () -> { String name = word(); dict.add(new Var(dp, name)); dp++; });
|
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("val:", () -> { String name = word(); dict.add(new Val(name, stack.pop())); });
|
||||||
addPrimitive("abort", () -> { throw new Aborted(stack.pop().asStr().value()); });
|
addPrimitive("abort", () -> { throw new Aborted(stack.pop().asStr().value()); });
|
||||||
|
addPrimitive("eval", () -> eval(stack.pop().asStr().value()));
|
||||||
addPrimitive("words", () -> {
|
addPrimitive("words", () -> {
|
||||||
List<String> words = new ArrayList(wordList());
|
List<String> words = new ArrayList(wordList());
|
||||||
Collections.sort(words);
|
Collections.sort(words);
|
||||||
|
|
|
@ -1133,6 +1133,12 @@ public class FclTest {
|
||||||
assertEquals("#[ ]#", evalPop("12 hist").toString());
|
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() {
|
private String transcript() {
|
||||||
return transcript.content();
|
return transcript.content();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue