diff --git a/mozilla/js/js2/java/AssignmentNode.java b/mozilla/js/js2/java/AssignmentNode.java new file mode 100644 index 00000000000..1df0a4160d4 --- /dev/null +++ b/mozilla/js/js2/java/AssignmentNode.java @@ -0,0 +1,21 @@ +class AssignmentNode extends BinaryNode { + + AssignmentNode(String aOp, ExpressionNode aLeft, ExpressionNode aRight) + { + super(aOp, aLeft, aRight); + } + + void eval(Environment theEnv) + { + left.evalLHS(theEnv); + right.eval(theEnv); + + double dValue = theEnv.theStack.pop().d; + String id = theEnv.theStack.pop().id; + + theEnv.theGlobals.put(id, new Double(dValue)); + + + } + +} \ No newline at end of file diff --git a/mozilla/js/js2/java/ConditionalNode.java b/mozilla/js/js2/java/ConditionalNode.java new file mode 100644 index 00000000000..fef953f3fd5 --- /dev/null +++ b/mozilla/js/js2/java/ConditionalNode.java @@ -0,0 +1,49 @@ +class ConditionalNode extends ControlNode { + + ConditionalNode(ExpressionNode aCondition, ControlNode aTrueCode) + { + super(aCondition); + trueCode = aTrueCode; + } + + ConditionalNode(ExpressionNode aCondition, ControlNode aTrueCode, ControlNode aFalseCode) + { + super(aCondition); + trueCode = aTrueCode; + setNext(aFalseCode); + } + + ControlNode eval(Environment theEnv) + { + ControlNode n = super.eval(theEnv); + double d = theEnv.theStack.pop().d; + if (d != 0.0) + return trueCode; + else + return n; + } + + String print() + { + StringBuffer result = new StringBuffer("ConditionalNode "); + result.append(index); + result.append("\nexpr:\n"); + if (expr == null) + result.append("expr = null\n"); + else + result.append(expr.print("")); + result.append("true branch:\n"); + if (trueCode == null) + result.append("true branch = null\n"); + else + result.append("true branch->" + trueCode.index + "\n"); + result.append("false branch:\n"); + if (next == null) + result.append("false branch = null\n"); + else + result.append("false branch->" + next.index + "\n"); + return result.toString(); + } + + protected ControlNode trueCode; +} diff --git a/mozilla/js/js2/java/ControlNode.java b/mozilla/js/js2/java/ControlNode.java new file mode 100644 index 00000000000..8f2f9988d67 --- /dev/null +++ b/mozilla/js/js2/java/ControlNode.java @@ -0,0 +1,61 @@ + +import java.util.Vector; + +class ControlNode { + + private static Vector gList = new Vector(); + + static String printAll() + { + StringBuffer result = new StringBuffer(); + for (int i = 0; i < gList.size(); i++) { + result.append(((ControlNode)(gList.elementAt(i))).print()); + } + return result.toString(); + } + + ControlNode(ExpressionNode anExpr) + { + expr = anExpr; + index = gList.size(); + gList.addElement(this); + } + + void setNext(ControlNode aNext) + { + next = aNext; + } + + ControlNode eval(Environment theEnv) + { + expr.eval(theEnv); + return next; + } + + String print() + { + StringBuffer result = new StringBuffer("ControlNode "); + result.append(index); + result.append("\nexpr:\n"); + if (expr == null) + result.append("expr = null\n"); + else + result.append(expr.print("")); + result.append("next:\n"); + if (next == null) + result.append("next = null\n"); + else + result.append("next->" + next.index + "\n"); + return result.toString(); + } + + protected ExpressionNode expr; + protected ControlNode next; + protected int index; + +} + + + + + diff --git a/mozilla/js/js2/java/ControlNodeGroup.java b/mozilla/js/js2/java/ControlNodeGroup.java new file mode 100644 index 00000000000..6a73a2e9502 --- /dev/null +++ b/mozilla/js/js2/java/ControlNodeGroup.java @@ -0,0 +1,57 @@ + +import java.util.Vector; + +class ControlNodeGroup { + + ControlNodeGroup(ControlNode aHead) + { + head = aHead; + tails = new Vector(); + } + + void fixTails(ControlNode butt) + { + int count = tails.size(); + for (int i = 0; i < count; i++) + { + ControlNode aNode = (ControlNode)(tails.elementAt(i)); + aNode.setNext(butt); + } + tails.removeAllElements(); + } + + void setHead(ControlNode aHead) + { + head = aHead; + } + + ControlNode getHead() + { + return head; + } + + void addTail(ControlNode aTail) + { + tails.addElement(aTail); + } + + void removeTail(ControlNode aTail) + { + tails.removeElement(aTail); + } + + void addTails(ControlNodeGroup aGroup) + { + int count = aGroup.tails.size(); + for (int i = 0; i < count; i++) + { + tails.addElement(aGroup.tails.elementAt(i)); + } + aGroup.tails.removeAllElements(); + } + + + ControlNode head; + Vector tails; + +} \ No newline at end of file diff --git a/mozilla/js/js2/java/Environment.java b/mozilla/js/js2/java/Environment.java new file mode 100644 index 00000000000..a1e02b274f9 --- /dev/null +++ b/mozilla/js/js2/java/Environment.java @@ -0,0 +1,18 @@ + +import java.util.Hashtable; + +class Environment { + + JSStack theStack = new JSStack(); + Hashtable theGlobals = new Hashtable(); + + String print() + { + StringBuffer result = new StringBuffer("Globals contents :\n"); + result.append(theGlobals.toString()); + result.append("\nStack Top = " + theStack.size()); + return result.toString(); + } + + +} \ No newline at end of file diff --git a/mozilla/js/js2/java/StackValue.java b/mozilla/js/js2/java/StackValue.java new file mode 100644 index 00000000000..06cf334066a --- /dev/null +++ b/mozilla/js/js2/java/StackValue.java @@ -0,0 +1,16 @@ +class StackValue { + + StackValue(double x) + { + d = x; + } + + StackValue(String x) + { + id = x; + } + + double d; + String id; + +} \ No newline at end of file