diff --git a/ISBPL.java b/ISBPL.java index 80ee03e..2eda61f 100644 --- a/ISBPL.java +++ b/ISBPL.java @@ -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 stack) -> { ISBPLObject message = stack.pop(); @@ -1835,6 +1847,18 @@ class ISBPLType { ", superTypes=" + superTypes + '}'; } + + public boolean extendsOther(ISBPLType other) { + Queue 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 { diff --git a/std.isbpl b/std.isbpl index 885c8c8..0ae8eb4 100644 --- a/std.isbpl +++ b/std.isbpl @@ -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