зеркало из https://github.com/mozilla/gecko-dev.git
This commit is contained in:
Родитель
0248fef529
Коммит
a254fc512f
|
@ -0,0 +1,34 @@
|
|||
class BitwiseNode extends BinaryNode {
|
||||
|
||||
BitwiseNode(String aOp, ExpressionNode aLeft, ExpressionNode aRight)
|
||||
{
|
||||
super(aOp, aLeft, aRight);
|
||||
}
|
||||
|
||||
void eval(Environment theEnv)
|
||||
{
|
||||
super.eval(theEnv);
|
||||
int iR = (int)(theEnv.theStack.pop().d);
|
||||
int iL = (int)(theEnv.theStack.pop().d);
|
||||
if (op == "&")
|
||||
theEnv.theStack.push(new StackValue(iL & iR));
|
||||
else
|
||||
if (op == "|")
|
||||
theEnv.theStack.push(new StackValue(iL | iR));
|
||||
else
|
||||
if (op == "^")
|
||||
theEnv.theStack.push(new StackValue(iL ^ iR));
|
||||
else
|
||||
if (op == "<<")
|
||||
theEnv.theStack.push(new StackValue(iL << iR));
|
||||
else
|
||||
if (op == ">>")
|
||||
theEnv.theStack.push(new StackValue(iL >> iR));
|
||||
else
|
||||
if (op == ">>>")
|
||||
theEnv.theStack.push(new StackValue(iL >>> iR));
|
||||
else
|
||||
System.out.println("missing bitwise op " + op);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
class JSBoolean extends JSValue {
|
||||
|
||||
JSBoolean(String s)
|
||||
{
|
||||
if (s.equals("true"))
|
||||
b = true;
|
||||
else
|
||||
if (s.equals("false"))
|
||||
b = false;
|
||||
else
|
||||
throw new RuntimeException("Bad string for JSBoolean constructor : " + s);
|
||||
}
|
||||
|
||||
void eval(Environment theEnv)
|
||||
{
|
||||
theEnv.theStack.push(new StackValue(b ? 1 : 0));
|
||||
}
|
||||
|
||||
boolean b;
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
class JSDouble extends JSNumber {
|
||||
|
||||
JSDouble(String s)
|
||||
{
|
||||
d = new Double(s).doubleValue();
|
||||
}
|
||||
|
||||
String print(String indent)
|
||||
{
|
||||
return indent + "JSDouble " + d + "\n";
|
||||
}
|
||||
|
||||
void eval(Environment theEnv)
|
||||
{
|
||||
theEnv.theStack.push(new StackValue(d));
|
||||
}
|
||||
|
||||
double d;
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
class JSInteger extends JSNumber {
|
||||
|
||||
JSInteger(String s)
|
||||
{
|
||||
i = new Integer(s).intValue();
|
||||
}
|
||||
|
||||
void eval(Environment theEnv)
|
||||
{
|
||||
theEnv.theStack.push(new StackValue(i));
|
||||
}
|
||||
|
||||
int i;
|
||||
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
class JSNumber extends JSValue {
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
class JSObject extends JSValue {
|
||||
|
||||
JSObject(String aType, String aValue)
|
||||
{
|
||||
type = aType;
|
||||
value = aValue;
|
||||
}
|
||||
|
||||
String print(String indent)
|
||||
{
|
||||
return indent + "JSObject " + type + " : " + value + "\n";
|
||||
}
|
||||
|
||||
void evalLHS(Environment theEnv)
|
||||
{
|
||||
if (type == "object") {
|
||||
theEnv.theStack.push(new StackValue(value));
|
||||
}
|
||||
else {
|
||||
System.out.println("EvalLHS on non-object");
|
||||
}
|
||||
}
|
||||
|
||||
void eval(Environment theEnv)
|
||||
{
|
||||
if (type.equals("object")) {
|
||||
Double d = (Double)(theEnv.theGlobals.get(value));
|
||||
if (d == null) {
|
||||
System.out.println("Accessed undefined : " + value);
|
||||
theEnv.theStack.push(new StackValue(0.0));
|
||||
}
|
||||
else
|
||||
theEnv.theStack.push(new StackValue(d.doubleValue()));
|
||||
}
|
||||
}
|
||||
|
||||
String type;
|
||||
String value;
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
class JSString extends JSValue {
|
||||
|
||||
JSString(String p)
|
||||
{
|
||||
s = p;
|
||||
}
|
||||
|
||||
void eval(Environment theEnv)
|
||||
{
|
||||
theEnv.theStack.push(new StackValue(s));
|
||||
}
|
||||
|
||||
|
||||
String s;
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
class LogicalNode extends BinaryNode {
|
||||
|
||||
LogicalNode(String aOp, ExpressionNode aLeft, ExpressionNode aRight)
|
||||
{
|
||||
super(aOp, aLeft, aRight);
|
||||
}
|
||||
|
||||
void eval(Environment theEnv)
|
||||
{
|
||||
left.eval(theEnv);
|
||||
double d = theEnv.theStack.pop().d;
|
||||
if (op == "&&") {
|
||||
if (d == 0.0)
|
||||
theEnv.theStack.push(new StackValue(0));
|
||||
else {
|
||||
right.eval(theEnv);
|
||||
d = theEnv.theStack.pop().d;
|
||||
if (d == 0.0)
|
||||
theEnv.theStack.push(new StackValue(0));
|
||||
else
|
||||
theEnv.theStack.push(new StackValue(1));
|
||||
}
|
||||
}
|
||||
if (op == "||") {
|
||||
if (d != 0.0)
|
||||
theEnv.theStack.push(new StackValue(1));
|
||||
else {
|
||||
right.eval(theEnv);
|
||||
d = theEnv.theStack.pop().d;
|
||||
if (d != 0.0)
|
||||
theEnv.theStack.push(new StackValue(1));
|
||||
else
|
||||
theEnv.theStack.push(new StackValue(0));
|
||||
}
|
||||
}
|
||||
else
|
||||
System.out.println("missing logical op " + op);
|
||||
}
|
||||
|
||||
}
|
Загрузка…
Ссылка в новой задаче