X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FTrap.java;h=f2200fb32b6aabca99503b95e03cf832721481fb;hb=73131826a18c93af4fb04672bc3ec820e1197ad1;hp=77476f6f688b9d0711c54b550b5d508014e26084;hpb=b1fa73c17b31f268fca5695d0876d7314fbacce3;p=org.ibex.js.git diff --git a/src/org/ibex/js/Trap.java b/src/org/ibex/js/Trap.java index 77476f6..f2200fb 100644 --- a/src/org/ibex/js/Trap.java +++ b/src/org/ibex/js/Trap.java @@ -1,4 +1,7 @@ -// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL] +// Copyright 2000-2005 the Contributors, as shown in the revision logs. +// Licensed under the Apache Public Source License 2.0 ("the License"). +// You may not use this file except in compliance with the License. + package org.ibex.js; /** @@ -7,55 +10,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 - Object 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, String n, JSFunction f, Trap nx) { - trapee = b; name = 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); + Trap(JS b, JS n, JSFunction f, Trap nx) { + target = b; key = n; this.f = f; this.next = nx; } - void invoke(Object value) throws JSExn { - Interpreter i = new Interpreter(putInvoker, false, null); - i.stack.push(trapee); - i.stack.push(name); - i.stack.push(value); - i.resume(); - } - - Object invoke() throws JSExn { - Interpreter i = new Interpreter(getInvoker, false, null); - i.stack.push(trapee); - i.stack.push(name); - return i.resume(); - } - - // FIXME: review; is necessary? - static class TrapScope extends JSScope { - Trap t; - Object val = null; - boolean cascadeHappened = false; - public TrapScope(JSScope parent, Trap t, Object val) { super(parent); this.t = t; this.val = val; } - public Object get(Object key) throws JSExn { - if (key.equals("trapee")) return t.trapee; - if (key.equals("callee")) return t.f; - if (key.equals("trapname")) return t.name; - return super.get(key); - } - } + 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(); } } -