X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FJS.java;h=0290e46c363a86653358c275ef8097e80bc1ac56;hp=de60d0c2797777f81e285441567522256c1fa949;hb=592fa04faf2d7c5bbf5fceae5a81da13f4791261;hpb=9d4e2434725c2ee15785e27d662bb9465cb767f2 diff --git a/src/org/ibex/js/JS.java b/src/org/ibex/js/JS.java index de60d0c..0290e46 100644 --- a/src/org/ibex/js/JS.java +++ b/src/org/ibex/js/JS.java @@ -2,7 +2,6 @@ package org.ibex.js; import org.ibex.util.*; -import org.ibex.*; import java.io.*; import java.util.*; @@ -11,30 +10,32 @@ public class JS extends org.ibex.util.BalancedTree { public static boolean checkAssertions = false; - public static final Object METHOD = new Object(); + public static final Object METHOD = new Object() { public String toString() { return "JS.METHOD"; } }; public final JS unclone() { return _unclone(); } + public final JS jsclone() throws JSExn { return new Clone(this); } public Enumeration keys() throws JSExn { return entries == null ? emptyEnumeration : entries.keys(); } public Object get(Object key) throws JSExn { return entries == null ? null : entries.get(key, null); } public void put(Object key, Object val) throws JSExn { (entries==null?entries=new Hash():entries).put(key,null,val); } public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn { - throw new JSExn("attempted to call the null value (method "+method+")"); + throw new JSExn("you cannot call this object (class=" + this.getClass().getName() +")"); } + // FIXME: JSArgs objects, pointers into stack frame public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn { throw new JSExn("you cannot call this object (class=" + this.getClass().getName() +")"); } JS _unclone() { return this; } - public static class Cloneable extends JS { - public Object jsclone() throws JSExn { - return new Clone(this); - } - } - - public static class Clone extends JS.Cloneable { - protected JS.Cloneable clonee = null; + + public interface Cloneable { } + + public static class Clone extends JS implements Cloneable { + protected JS clonee; JS _unclone() { return clonee.unclone(); } - public JS.Cloneable getClonee() { return clonee; } - public Clone(JS.Cloneable clonee) { this.clonee = clonee; } + public JS getClonee() { return clonee; } + public Clone(JS clonee) throws JSExn { + if(!(clonee instanceof Cloneable)) throw new JSExn("this object isn't cloneable"); + this.clonee = clonee; + } public boolean equals(Object o) { if (!(o instanceof JS)) return false; return unclone() == ((JS)o).unclone(); @@ -69,7 +70,7 @@ public class JS extends org.ibex.util.BalancedTree { return new JS.UnpauseCallback(i); } - public static class UnpauseCallback implements Scheduler.Task { + public static class UnpauseCallback implements Task { Interpreter i; UnpauseCallback(Interpreter i) { this.i = i; } public void perform() throws JSExn { unpause(null); } @@ -132,9 +133,14 @@ public class JS extends org.ibex.util.BalancedTree { if((int)d == d) return Integer.toString((int)d); return o.toString(); } + if (o instanceof JS) return ((JS)o).coerceToString(); // HACK for now, this will probably go away throw new RuntimeException("can't coerce "+o+" [" + o.getClass().getName() + "] to type String."); } + public String coerceToString() { + throw new RuntimeException("can't coerce "+this+" [" + getClass().getName() + "] to type String."); + } + // Instance Methods //////////////////////////////////////////////////////////////////// public static final Integer ZERO = new Integer(0);