X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FTrap.java;h=580ed692fc111f4c3bb3ab88d447fa6e33406766;hb=a19b897271a8ab6b25aba63e4b30223c2477c28d;hp=67d02386b74f31ff951dc238383e3be41d3d997b;hpb=4c96b0f7e40e4689434c46e4300cc9bef9d0fab9;p=org.ibex.core.git diff --git a/src/org/ibex/js/Trap.java b/src/org/ibex/js/Trap.java index 67d0238..580ed69 100644 --- a/src/org/ibex/js/Trap.java +++ b/src/org/ibex/js/Trap.java @@ -7,43 +7,22 @@ package org.ibex.js; * linked list stack, with the most recently placed trap at the head * of the list. */ -class Trap { +final class Trap { - JS trapee = null; ///< the box on which this trap was placed - JS name = null; ///< the property that the trap was placed on + final JS target; ///< the box on which this trap was placed + final JS key; ///< the property that the trap was placed on - JSFunction f = null; ///< the function for this trap - Trap next = null; ///< the next trap down the trap stack + final JSFunction f; ///< the function for this trap + Trap next; ///< the next trap down the trap stack Trap(JS b, JS n, JSFunction f, Trap nx) { - trapee = b; name = n; this.f = f; this.next = nx; + target = b; key = n; this.f = f; this.next = nx; } - - static final JSFunction putInvoker = new JSFunction("putInvoker", 0, null); - static final JSFunction getInvoker = new JSFunction("getInvoker", 0, null); - - static { - putInvoker.add(1, ByteCodes.PUT, null); - putInvoker.add(2, Tokens.RETURN, null); - getInvoker.add(1, ByteCodes.GET, null); - getInvoker.add(2, Tokens.RETURN, null); - } - - boolean readTrap() { return f.numFormalArgs == 0; } - boolean writeTrap() { return f.numFormalArgs != 0; } - void invoke(JS value) throws JSExn { - Interpreter i = new Interpreter(putInvoker, false, null); - i.stack.push(trapee); - i.stack.push(name); - i.stack.push(value); - i.resume(); - } - - JS invoke() throws JSExn { - Interpreter i = new Interpreter(getInvoker, false, null); - i.stack.push(trapee); - i.stack.push(name); - return i.resume(); - } + boolean isReadTrap() { return f.numFormalArgs == 0; } + boolean isWriteTrap() { return f.numFormalArgs != 0; } + Trap readTrap() { Trap t = this; while(t!=null && t.isWriteTrap()) t = t.next; return t; } + Trap writeTrap() { Trap t = this; while(t!=null && t.isReadTrap()) t = t.next; return t; } + Trap nextReadTrap() { return next == null ? null : next.readTrap(); } + Trap nextWriteTrap() { return next == null ? null : next.writeTrap(); } }