add extends native
This commit is contained in:
parent
9fac0ebaa6
commit
73d7323f8c
2 changed files with 26 additions and 0 deletions
24
ISBPL.java
24
ISBPL.java
|
@ -573,6 +573,18 @@ public class ISBPL {
|
||||||
stack.push(new ISBPLObject(types.get(((int) i.object)), o.object));
|
stack.push(new ISBPLObject(types.get(((int) i.object)), o.object));
|
||||||
};
|
};
|
||||||
break;
|
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":
|
case "throw":
|
||||||
func = (Stack<ISBPLObject> stack) -> {
|
func = (Stack<ISBPLObject> stack) -> {
|
||||||
ISBPLObject message = stack.pop();
|
ISBPLObject message = stack.pop();
|
||||||
|
@ -1835,6 +1847,18 @@ class ISBPLType {
|
||||||
", superTypes=" + superTypes +
|
", 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 {
|
class ISBPLObject {
|
||||||
|
|
|
@ -48,6 +48,8 @@ native typename
|
||||||
native typeid
|
native typeid
|
||||||
native gettype
|
native gettype
|
||||||
native settype
|
native settype
|
||||||
|
"a b extends => a.extends(b) | b.isSuperOf(a) | a == b" #
|
||||||
|
native extends
|
||||||
"try and do are keywords, not functions" #
|
"try and do are keywords, not functions" #
|
||||||
native throw
|
native throw
|
||||||
native exit
|
native exit
|
||||||
|
|
Loading…
Reference in a new issue