X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fjs%2FCompiledFunctionImpl.java;h=f118b76a16efcfcc0db22d069ec0416b920db305;hb=8235361e8601ae7b36ab707058de3b52225d15a2;hp=5771060705a7f3eb4c7a55a9dcbc73f989d4cfef;hpb=7aff6dbf6c8af7212fe187c404d3118626af8278;p=org.ibex.core.git diff --git a/src/org/xwt/js/CompiledFunctionImpl.java b/src/org/xwt/js/CompiledFunctionImpl.java index 5771060..f118b76 100644 --- a/src/org/xwt/js/CompiledFunctionImpl.java +++ b/src/org/xwt/js/CompiledFunctionImpl.java @@ -4,12 +4,14 @@ package org.xwt.js; import org.xwt.util.*; import java.io.*; -// FIXME: could use some cleaning up /** a JavaScript function, compiled into bytecode */ -class CompiledFunctionImpl extends JSCallable implements ByteCodes, Tokens { +class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Tokens { // Fields and Accessors /////////////////////////////////////////////// + /** the number of formal arguments */ + int numFormalArgs = 0; + /** the source code file that this block was drawn from */ private String sourceName; public String getSourceName() throws JS.Exn { return sourceName; } @@ -74,7 +76,8 @@ class CompiledFunctionImpl extends JSCallable implements ByteCodes, Tokens { Object ret = cx.stack.pop(); if (cx.stack.size() > size) // this should never happen - throw new Error("ERROR: stack grew by " + (cx.stack.size() - size) + " elements during call at " + sourceName + ":" + firstLine); + throw new Error("ERROR: stack grew by " + (cx.stack.size() - size) + + " elements during call at " + sourceName + ":" + firstLine); return ret; } catch(Error e) { // Unwind the stack @@ -323,7 +326,34 @@ class CompiledFunctionImpl extends JSCallable implements ByteCodes, Tokens { break; } - + case ASSIGN_SUB: case ASSIGN_ADD: { + Object val = t.pop(); + Object old = t.pop(); + Object key = t.pop(); + Object obj = t.peek(); + if (val instanceof CompiledFunction) { + if (obj instanceof JS.Scope) { + JS.Scope parent = (JS.Scope)obj; + while(parent.getParentScope() != null) parent = parent.getParentScope(); + if (parent instanceof org.xwt.Box) { + if (curOP == ASSIGN_ADD) { + ((org.xwt.Box)parent).addTrap(key, val); + } else { + ((org.xwt.Box)parent).delTrap(key, val); + } + // skip over the "normal" implementation of +=/-= + pc += ((Integer)arg[pc]).intValue() - 1; + break; + } + } + } + // use the "normal" implementation + t.push(key); + t.push(old); + t.push(arg); + break; + } + case ADD: { int count = ((Number)arg[pc]).intValue(); if(count < 2) throw new Error("this should never happen"); @@ -333,31 +363,31 @@ class CompiledFunctionImpl extends JSCallable implements ByteCodes, Tokens { Object left = t.pop(); if(left instanceof String || right instanceof String) t.push(JS.toString(left).concat(JS.toString(right))); else t.push(new Double(JS.toDouble(left) + JS.toDouble(right))); - break; - } - Object[] args = new Object[count]; - while(--count >= 0) args[count] = t.pop(); - if(args[0] instanceof String) { - StringBuffer sb = new StringBuffer(64); - for(int i=0;i= 0) args[count] = t.pop(); + if(args[0] instanceof String) { StringBuffer sb = new StringBuffer(64); - sb.append(JS.toString(new Double(d))); - while(i < args.length) sb.append(JS.toString(args[i++])); + for(int i=0;i