add extends native

This commit is contained in:
Daniella 2022-05-18 00:56:49 +02:00
parent 9fac0ebaa6
commit 73d7323f8c
2 changed files with 26 additions and 0 deletions

View file

@ -573,6 +573,18 @@ public class ISBPL {
stack.push(new ISBPLObject(types.get(((int) i.object)), o.object));
};
break;
case "extends":
func = (stack) -> {
ISBPLObject b = stack.pop();
ISBPLObject a = stack.pop();
if(a.type.extendsOther(getType("int")) && b.type.extendsOther(getType("int"))) {
stack.push(new ISBPLObject(getType("int"), types.get((int) a.object).extendsOther(types.get((int) b.object)) ? 1 : 0));
}
else {
stack.push(new ISBPLObject(getType("int"), a.type.extendsOther(b.type) ? 1 : 0));
}
};
break;
case "throw":
func = (Stack<ISBPLObject> stack) -> {
ISBPLObject message = stack.pop();
@ -1835,6 +1847,18 @@ class ISBPLType {
", superTypes=" + superTypes +
'}';
}
public boolean extendsOther(ISBPLType other) {
Queue<ISBPLType> q = new LinkedList<>();
q.add(this);
while(!q.isEmpty()) {
ISBPLType t = q.poll();
q.addAll(t.superTypes);
if(other.equals(t))
return true;
}
return false;
}
}
class ISBPLObject {

View file

@ -48,6 +48,8 @@ native typename
native typeid
native gettype
native settype
"a b extends => a.extends(b) | b.isSuperOf(a) | a == b" #
native extends
"try and do are keywords, not functions" #
native throw
native exit