From cdaf6edffa661deb7dca6b7ed8b7d64980d590d2 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Mon, 18 Apr 2022 21:36:53 +0200 Subject: [PATCH] fix stream.isbpl --- bootstrap/ISBPL.java | 20 +++++++++++++++----- stream.isbpl | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/bootstrap/ISBPL.java b/bootstrap/ISBPL.java index 6efdfe8..bcfe244 100644 --- a/bootstrap/ISBPL.java +++ b/bootstrap/ISBPL.java @@ -36,10 +36,6 @@ public class ISBPL { ArrayList included = new ArrayList<>(); HashMap natives = new HashMap<>(); - public ISBPL() { - functionStack.get().push(new HashMap<>()); - } - private ISBPLKeyword getKeyword(String word) { switch (word) { case "native": @@ -55,6 +51,7 @@ public class ISBPL { idx++; Object var = new Object(); ISBPLCallable c; + vars.put(var, new ISBPLObject(getType("null"), 0)); addFunction(words[idx], c = ((stack1) -> stack1.push(vars.get(var)))); addFunction("=" + words[idx], (stack1) -> vars.put(var, stack1.pop())); varLinks.put(c, var); @@ -886,7 +883,7 @@ public class ISBPL { ISBPLType t = types.get((int) type.object); String s = toJavaString(str); Object var = new Object(); - addFunction(t, s, (stack1) -> stack1.push(t.varget(stack1.pop()).get(var))); + addFunction(t, s, (stack1) -> stack1.push(t.varget(stack1.pop()).getOrDefault(var, getNullObject()))); addFunction(t, "=" + s, (stack1) -> t.varget(stack1.pop()).put(var, stack1.pop())); }; break; @@ -933,12 +930,25 @@ public class ISBPL { stack.push(new ISBPLObject(getType("null"), 0)); }; break; + case "delete": + func = (stack) -> { + ISBPLObject o = stack.pop(); + o.type.vars.remove(o); + }; + break; default: func = natives.get(name); break; } addFunction(name, func); } + + ISBPLObject nullObj = null; + public ISBPLObject getNullObject() { + if(nullObj == null) + nullObj = new ISBPLObject(getType("null"), 0); + return nullObj; + } public ISBPLObject toISBPL(Class clazz) { ISBPLType type = getType(clazz.getName()); diff --git a/stream.isbpl b/stream.isbpl index 66cba06..a7779a9 100644 --- a/stream.isbpl +++ b/stream.isbpl @@ -35,7 +35,7 @@ func stream.readline { array _string 2 stop } - array ( ( array alen 1 - anew ) dup =tmparray 0 0 ) ( tmparray alen ) acopy _string + array _string } func stream.write {