fix stream.isbpl

This commit is contained in:
Daniella / Tove 2022-04-18 21:36:53 +02:00
parent 288370d093
commit cdaf6edffa
2 changed files with 16 additions and 6 deletions

View file

@ -36,10 +36,6 @@ public class ISBPL {
ArrayList<String> included = new ArrayList<>();
HashMap<String, ISBPLCallable> 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());

View file

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