X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Forg%2Fxwt%2Fjs%2FInterpreter.java;h=101b0af81079ef8278dd3d4da89a1424e5a27031;hb=d4d39728dfff9918ac8ab5e054524585cac77ac0;hp=df802e274fb8f50678e4d50ce9ac4fdcd997469f;hpb=f955f7381d5ce44b7dc1fd2e2e00210bc25cdbb7;p=org.ibex.core.git diff --git a/src/org/xwt/js/Interpreter.java b/src/org/xwt/js/Interpreter.java index df802e2..101b0af 100644 --- a/src/org/xwt/js/Interpreter.java +++ b/src/org/xwt/js/Interpreter.java @@ -160,7 +160,7 @@ class Interpreter implements ByteCodes, Tokens { pc = ((TryMarker)o).finallyLoc - 1; continue OUTER; } else if (o instanceof CallMarker) { - if (scope instanceof Trap.TrapScope) { + if (scope instanceof Trap.TrapScope) { // handles return component of a read trap Trap.TrapScope ts = (Trap.TrapScope)scope; if (!ts.cascadeHappened) { ts.cascadeHappened = true; @@ -177,7 +177,7 @@ class Interpreter implements ByteCodes, Tokens { f = t.f; scope = new Trap.TrapScope(f.parentScope, t, ts.val); pc = -1; - break; + continue OUTER; } } } @@ -201,22 +201,36 @@ class Interpreter implements ByteCodes, Tokens { throw je("tried to put a value to the " + key + " property on a " + target.getClass().getName()); if (key == null) throw je("tried to assign \"" + (val==null?"(null)":val.toString()) + "\" to the null key"); + Trap t = null; - if (target instanceof JS) { - t = ((JS)target).getTrap(key); - while (t != null && t.f.numFormalArgs == 0) t = t.next; - } else if (target instanceof Trap.TrapScope && key.equals("cascade")) { + if (target instanceof Trap.TrapScope && key.equals("cascade")) { Trap.TrapScope ts = (Trap.TrapScope)target; t = ts.t.next; ts.cascadeHappened = true; while (t != null && t.f.numFormalArgs == 0) t = t.next; - if (t == null) target = ts.t.trapee; + if (t == null) { target = ts.t.trapee; key = ts.t.name; } + + } else if (target instanceof Trap.TrapScope && key.equals(((Trap.TrapScope)target).t.name)) { + throw je("tried to put to " + key + " inside a trap it owns; use cascade instead"); + + } else if (target instanceof JS) { + if (target instanceof JSScope) { + JSScope p = (JSScope)target; // search the scope-path for the trap + t = p.getTrap(key); + while (t == null && p.getParentScope() != null) { p = p.getParentScope(); t = p.getTrap(key); } + } else { + t = ((JS)target).getTrap(key); + } + + while (t != null && t.f.numFormalArgs == 0) t = t.next; // find the first write trap + if (t != null) { + stack.push(new CallMarker(this)); + JSArray args = new JSArray(); + args.addElement(val); + stack.push(args); + } } if (t != null) { - stack.push(new CallMarker(this)); - JSArray args = new JSArray(); - args.addElement(val); - stack.push(args); f = t.f; scope = new Trap.TrapScope(f.parentScope, t, val); pc = -1; @@ -248,18 +262,28 @@ class Interpreter implements ByteCodes, Tokens { break; } else if (o instanceof JS) { Trap t = null; - if (o instanceof JS) { - t = ((JS)o).getTrap(v); - while (t != null && t.f.numFormalArgs != 0) t = t.next; - } else if (o instanceof Trap.TrapScope && v.equals("cascade")) { + if (o instanceof Trap.TrapScope && v.equals("cascade")) { t = ((Trap.TrapScope)o).t.next; while (t != null && t.f.numFormalArgs != 0) t = t.next; - if (t == null) o = ((Trap.TrapScope)o).t.trapee; + if (t == null) { v = ((Trap.TrapScope)o).t.name; o = ((Trap.TrapScope)o).t.trapee; } + + } else if (o instanceof JS) { + if (o instanceof JSScope) { + JSScope p = (JSScope)o; // search the scope-path for the trap + t = p.getTrap(v); + while (t == null && p.getParentScope() != null) { p = p.getParentScope(); t = p.getTrap(v); } + } else { + t = ((JS)o).getTrap(v); + } + + while (t != null && t.f.numFormalArgs != 0) t = t.next; // get first read trap + if (t != null) { + stack.push(new CallMarker(this)); + JSArray args = new JSArray(); + stack.push(args); + } } if (t != null) { - stack.push(new CallMarker(this)); - JSArray args = new JSArray(); - stack.push(args); f = t.f; scope = new Trap.TrapScope(f.parentScope, t, null); ((Trap.TrapScope)scope).cascadeHappened = true;