Changed Cast to take a JSValue containing a type instead of type directly.

Added LoadType to help support that. Also added LoadNull.
This commit is contained in:
rogerl%netscape.com 2001-02-01 00:59:21 +00:00
Родитель a4db62ff77
Коммит 80fd524b82
12 изменённых файлов: 142 добавлений и 2208 удалений

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -225,6 +225,21 @@ TypedRegister ICodeGenerator::loadBoolean(bool value)
return dest;
}
TypedRegister ICodeGenerator::loadNull()
{
TypedRegister dest(getTempRegister(), &Any_Type);
iCode->push_back(new LoadNull(dest));
return dest;
}
TypedRegister ICodeGenerator::loadType(JSType *type)
{
TypedRegister dest(getTempRegister(), type);
iCode->push_back(new LoadType(dest, type));
return dest;
}
TypedRegister ICodeGenerator::newObject(TypedRegister constructor)
{
TypedRegister dest(getTempRegister(), &Any_Type);
@ -535,7 +550,7 @@ TypedRegister ICodeGenerator::super()
TypedRegister ICodeGenerator::cast(TypedRegister arg, JSType *toType)
{
TypedRegister dest(getTempRegister(), toType);
Cast *instr = new Cast(dest, arg, toType);
Cast *instr = new Cast(dest, arg, loadType(toType));
iCode->push_back(instr);
return dest;
}
@ -1249,6 +1264,9 @@ TypedRegister ICodeGenerator::genExpr(ExprNode *p,
else
ret = loadBoolean(false);
break;
case ExprNode::Null:
ret = loadNull();
break;
case ExprNode::parentheses:
{
UnaryExprNode *u = static_cast<UnaryExprNode *>(p);

Просмотреть файл

@ -378,6 +378,8 @@ namespace ICG {
TypedRegister loadImmediate(double value);
TypedRegister loadString(const String &value);
TypedRegister loadString(const StringAtom &name);
TypedRegister loadNull();
TypedRegister loadType(JSType *toType);
TypedRegister newObject(TypedRegister constructor);
TypedRegister newArray();

Просмотреть файл

@ -1,389 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the JavaScript 2 Prototype.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
/***** THIS FILE IS AUTO GENERATED! DO NOT EDIT THIS FILE! *****
* make changes to js2/tools/genmap.pl and regenerate this file *
***** THIS FILE IS AUTO GENERATED! DO NOT EDIT THIS FILE! *****/
#ifndef __icodemap_h
#define __icodemap_h
#include "systemtypes.h"
#include "icodeasm.h"
namespace JavaScript {
namespace ICodeASM {
static uint icodemap_size = 78;
static struct {
char *name;
OperandType otype[4];
} icodemap [] = {
{"ADD", {otRegister, otRegister, otRegister}},
{"AND", {otRegister, otRegister, otRegister}},
{"BIND_THIS", {otRegister, otRegister, otRegister}},
{"BITNOT", {otRegister, otRegister}},
{"BRANCH", {otLabel}},
{"BRANCH_FALSE", {otLabel, otRegister}},
{"BRANCH_INITIALIZED", {otLabel, otRegister}},
{"BRANCH_TRUE", {otLabel, otRegister}},
{"CALL", {otRegister, otRegister, otArgumentList}},
{"CAST", {otRegister, otRegister, otJSType}},
{"CLASS", {otRegister, otRegister}},
{"COMPARE_EQ", {otRegister, otRegister, otRegister}},
{"COMPARE_GE", {otRegister, otRegister, otRegister}},
{"COMPARE_GT", {otRegister, otRegister, otRegister}},
{"COMPARE_IN", {otRegister, otRegister, otRegister}},
{"COMPARE_LE", {otRegister, otRegister, otRegister}},
{"COMPARE_LT", {otRegister, otRegister, otRegister}},
{"COMPARE_NE", {otRegister, otRegister, otRegister}},
{"DEBUGGER", {otNone}},
{"DELETE_PROP", {otRegister, otRegister, otStringAtom}},
{"DIRECT_CALL", {otRegister, otJSFunction, otArgumentList}},
{"DIVIDE", {otRegister, otRegister, otRegister}},
{"ELEM_XCR", {otRegister, otRegister, otRegister, otDouble}},
{"GENERIC_BINARY_OP", {otRegister, otExprNodeKind, otRegister, otRegister}},
{"GET_CLOSURE", {otRegister, otUInt32}},
{"GET_ELEMENT", {otRegister, otRegister, otRegister}},
{"GET_METHOD", {otRegister, otRegister, otUInt32}},
{"GET_PROP", {otRegister, otRegister, otStringAtom}},
{"GET_SLOT", {otRegister, otRegister, otUInt32}},
{"GET_STATIC", {otRegister, otJSClass, otUInt32}},
{"INSTANCEOF", {otRegister, otRegister, otRegister}},
{"JSR", {otLabel}},
{"LOAD_FALSE", {otRegister}},
{"LOAD_IMMEDIATE", {otRegister, otDouble}},
{"LOAD_NAME", {otRegister, otStringAtom}},
{"LOAD_NULL", {otRegister}},
{"LOAD_STRING", {otRegister, otJSString}},
{"LOAD_TRUE", {otRegister}},
{"MOVE", {otRegister, otRegister}},
{"MULTIPLY", {otRegister, otRegister, otRegister}},
{"NAME_XCR", {otRegister, otStringAtom, otDouble}},
{"NEGATE", {otRegister, otRegister}},
{"NEW_ARRAY", {otRegister}},
{"NEW_CLASS", {otRegister, otJSClass}},
{"NEW_CLOSURE", {otRegister, otICodeModule}},
{"NEW_FUNCTION", {otRegister, otICodeModule}},
{"NEW_OBJECT", {otRegister, otRegister}},
{"NOP", {otNone}},
{"NOT", {otRegister, otRegister}},
{"OR", {otRegister, otRegister, otRegister}},
{"POSATE", {otRegister, otRegister}},
{"PROP_XCR", {otRegister, otRegister, otStringAtom, otDouble}},
{"REMAINDER", {otRegister, otRegister, otRegister}},
{"RETURN", {otRegister}},
{"RETURN_VOID", {otNone}},
{"RTS", {otNone}},
{"SAVE_NAME", {otStringAtom, otRegister}},
{"SET_ELEMENT", {otRegister, otRegister, otRegister}},
{"SET_PROP", {otRegister, otStringAtom, otRegister}},
{"SET_SLOT", {otRegister, otUInt32, otRegister}},
{"SET_STATIC", {otJSClass, otUInt32, otRegister}},
{"SHIFTLEFT", {otRegister, otRegister, otRegister}},
{"SHIFTRIGHT", {otRegister, otRegister, otRegister}},
{"SLOT_XCR", {otRegister, otRegister, otUInt32, otDouble}},
{"STATIC_XCR", {otRegister, otJSClass, otUInt32, otDouble}},
{"STRICT_EQ", {otRegister, otRegister, otRegister}},
{"STRICT_NE", {otRegister, otRegister, otRegister}},
{"SUBTRACT", {otRegister, otRegister, otRegister}},
{"SUPER", {otRegister}},
{"TEST", {otRegister, otRegister}},
{"THROW", {otRegister}},
{"TRYIN", {otLabel, otLabel}},
{"TRYOUT", {otNone}},
{"USHIFTRIGHT", {otRegister, otRegister, otRegister}},
{"VAR_XCR", {otRegister, otRegister, otDouble}},
{"WITHIN", {otRegister}},
{"WITHOUT", {otNone}},
{"XOR", {otRegister, otRegister, otRegister}},
};
VM::Instruction *InstructionFromNode (StatementNode *node)
{
using namespace VM;
using namespace JSTypes;
Instruction *i;
switch (node->icodeID)
{
case 0:
i = new Add (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 1:
i = new And (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 2:
i = new BindThis (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 3:
i = new Bitnot (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 4:
i = new Branch (reinterpret_cast<Label*>(node->operand[0].data));
break;
case 5:
i = new BranchFalse (reinterpret_cast<Label*>(node->operand[0].data), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 6:
i = new BranchInitialized (reinterpret_cast<Label*>(node->operand[0].data), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 7:
i = new BranchTrue (reinterpret_cast<Label*>(node->operand[0].data), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 8:
i = new Call (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), reinterpret_cast<ArgumentList*>(node->operand[2].data));
break;
case 9:
i = new Cast (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), reinterpret_cast<JSType*>(node->operand[2].data));
break;
case 10:
i = new Class (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 11:
i = new CompareEQ (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 12:
i = new CompareGE (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 13:
i = new CompareGT (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 14:
i = new CompareIN (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 15:
i = new CompareLE (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 16:
i = new CompareLT (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 17:
i = new CompareNE (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 18:
i = new Debugger ();
break;
case 19:
i = new DeleteProp (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), reinterpret_cast<const StringAtom*>(node->operand[2].data));
break;
case 20:
i = new DirectCall (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<JSFunction*>(node->operand[1].data), reinterpret_cast<ArgumentList*>(node->operand[2].data));
break;
case 21:
i = new Divide (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 22:
i = new ElemXcr (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0), static_cast<double>(node->operand[3].data));
break;
case 23:
i = new GenericBinaryOP (TypedRegister(static_cast<Register>(node->operand[0].data), 0), static_cast<ExprNode::Kind>(node->operand[1].data), TypedRegister(static_cast<Register>(node->operand[2].data), 0), TypedRegister(static_cast<Register>(node->operand[3].data), 0));
break;
case 24:
i = new GetClosure (TypedRegister(static_cast<Register>(node->operand[0].data), 0), static_cast<uint32>(node->operand[1].data));
break;
case 25:
i = new GetElement (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 26:
i = new GetMethod (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), static_cast<uint32>(node->operand[2].data));
break;
case 27:
i = new GetProp (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), reinterpret_cast<const StringAtom*>(node->operand[2].data));
break;
case 28:
i = new GetSlot (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), static_cast<uint32>(node->operand[2].data));
break;
case 29:
i = new GetStatic (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<JSClass*>(node->operand[1].data), static_cast<uint32>(node->operand[2].data));
break;
case 30:
i = new Instanceof (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 31:
i = new Jsr (reinterpret_cast<Label*>(node->operand[0].data));
break;
case 32:
i = new LoadFalse (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
break;
case 33:
i = new LoadImmediate (TypedRegister(static_cast<Register>(node->operand[0].data), 0), static_cast<double>(node->operand[1].data));
break;
case 34:
i = new LoadName (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<const StringAtom*>(node->operand[1].data));
break;
case 35:
i = new LoadNull (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
break;
case 36:
i = new LoadString (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<JSString*>(node->operand[1].data));
break;
case 37:
i = new LoadTrue (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
break;
case 38:
i = new Move (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 39:
i = new Multiply (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 40:
i = new NameXcr (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<const StringAtom*>(node->operand[1].data), static_cast<double>(node->operand[2].data));
break;
case 41:
i = new Negate (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 42:
i = new NewArray (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
break;
case 43:
i = new NewClass (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<JSClass*>(node->operand[1].data));
break;
case 44:
i = new NewClosure (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<ICodeModule*>(node->operand[1].data));
break;
case 45:
i = new NewFunction (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<ICodeModule*>(node->operand[1].data));
break;
case 46:
i = new NewObject (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 47:
i = new Nop ();
break;
case 48:
i = new Not (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 49:
i = new Or (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 50:
i = new Posate (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 51:
i = new PropXcr (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), reinterpret_cast<const StringAtom*>(node->operand[2].data), static_cast<double>(node->operand[3].data));
break;
case 52:
i = new Remainder (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 53:
i = new Return (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
break;
case 54:
i = new ReturnVoid ();
break;
case 55:
i = new Rts ();
break;
case 56:
i = new SaveName (reinterpret_cast<const StringAtom*>(node->operand[0].data), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 57:
i = new SetElement (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 58:
i = new SetProp (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<const StringAtom*>(node->operand[1].data), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 59:
i = new SetSlot (TypedRegister(static_cast<Register>(node->operand[0].data), 0), static_cast<uint32>(node->operand[1].data), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 60:
i = new SetStatic (reinterpret_cast<JSClass*>(node->operand[0].data), static_cast<uint32>(node->operand[1].data), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 61:
i = new Shiftleft (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 62:
i = new Shiftright (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 63:
i = new SlotXcr (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), static_cast<uint32>(node->operand[2].data), static_cast<double>(node->operand[3].data));
break;
case 64:
i = new StaticXcr (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<JSClass*>(node->operand[1].data), static_cast<uint32>(node->operand[2].data), static_cast<double>(node->operand[3].data));
break;
case 65:
i = new StrictEQ (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 66:
i = new StrictNE (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 67:
i = new Subtract (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 68:
i = new Super (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
break;
case 69:
i = new Test (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 70:
i = new Throw (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
break;
case 71:
i = new Tryin (reinterpret_cast<Label*>(node->operand[0].data), reinterpret_cast<Label*>(node->operand[1].data));
break;
case 72:
i = new Tryout ();
break;
case 73:
i = new Ushiftright (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 74:
i = new VarXcr (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), static_cast<double>(node->operand[2].data));
break;
case 75:
i = new Within (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
break;
case 76:
i = new Without ();
break;
case 77:
i = new Xor (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
default:
NOT_REACHED("Unknown icodeID");
}
return i;
}
}
}
#endif /* #ifdef __icodemap_h */

Просмотреть файл

@ -108,12 +108,6 @@ JSValue Context::readEvalFile(FILE* in, const String& fileName)
JSValues emptyArgs;
JSValue result;
// save off important member variables, to enable recursive call to interpret.
// this is a little stinky, but should be exception-safe.
autosaver<Activation*> activation(mActivation, 0);
autosaver<Linkage*> linkage(mLinkage, 0);
autosaver<InstructionIterator> pc(mPC);
try {
Arena a;
Parser p(getWorld(), a, buffer, fileName);
@ -133,11 +127,12 @@ JSValue Context::readEvalFile(FILE* in, const String& fileName)
stdOut << '\n';
/*******/
// Generate code for parsedStatements, which is a linked
// Generate code for parsedStatements, which is a linked
// list of zero or more statements
ICodeModule* icm = genCode(parsedStatements, fileName);
if (icm) {
result = interpret(icm, emptyArgs);
Context cx(getWorld(), getGlobalObject());
result = cx.interpret(icm, emptyArgs);
delete icm;
}
} catch (Exception &e) {
@ -538,8 +533,15 @@ JSValue Context::interpret(ICodeModule* iCode, const JSValues& args)
case CAST:
{
Cast* c = static_cast<Cast*>(instruction);
JSType *toType = op3(c);
(*registers)[dst(c).first] = (*registers)[src1(c).first].convert(toType);
JSValue toTypeValue = (*registers)[op3(c).first];
ASSERT(toTypeValue.isType());
(*registers)[dst(c).first] = (*registers)[src1(c).first].convert(toTypeValue.type);
}
break;
case LOAD_TYPE:
{
LoadType *lt = static_cast<LoadType*>(instruction);
(*registers)[dst(lt).first] = src1(lt);
}
break;
case CLASS:

Просмотреть файл

@ -1,438 +0,0 @@
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is JavaScript Core Tests.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1997-1999 Netscape Communications Corporation. All
# Rights Reserved.
#
# Alternatively, the contents of this file may be used under the
# terms of the GNU Public License (the "GPL"), in which case the
# provisions of the GPL are applicable instead of those above.
# If you wish to allow use of your version of this file only
# under the terms of the GPL and not to allow others to use your
# version of this file under the NPL, indicate your decision by
# deleting the provisions above and replace them with the notice
# and other provisions required by the GPL. If you do not delete
# the provisions above, a recipient may use your version of this
# file under either the NPL or the GPL.
#
# Contributers:
#
package jsicodes;
use strict;
use vars qw(%ops @ISA);
require Exporter;
@ISA = qw(Exporter);
sub get_classname {
# munge an OPCODE_MNEMONIC into a ClassName
my ($enum_name) = @_;
my @words = split ("_", $enum_name);
my $cname = "";
my $i = 0;
my $word;
for $word (@words) {
if ((length($word) == 2) && ($i != 0)) {
$cname .= uc($word);
} else {
$cname .= uc(substr($word, 0, 1)) . lc(substr($word, 1));
}
$i++;
}
return $cname;
}
#
# fields are:
#
# * super: Class to inherit from, if super is Instruction_(1|2|3), the script
# will automatically append the correct template info based on
# |params|
# * super_has_print: Set to 1 if you want to inherit the print() and
# print_args() methods from the superclass, set to 0
# (or just don't set) to generate print methods.
#
# * rem: Remark you want to show up after the enum def, and inside the class.
# * params: The parameter list expected by the constructor, you can specify a
# default value, using the syntax, [ ("Type = default") ].
#
# class names will be generated based on the opcode mnemonic. See the
# subroutine get_classname for the implementation. Basically underscores will
# be removes and the class name will be WordCapped, using the positions where
# the underscores were as word boundries. The only exception occurs when a
# word is two characters, in which case both characters will be capped,
# as in BRANCH_GT -> BranchGT.
#
#
# template definitions for compare, arithmetic, and conditional branch ops
#
my $binary_op =
{
super => "Instruction_3",
# super_has_print => 1,
rem => "dest, source1, source2",
params => [ ("TypedRegister", "TypedRegister", "TypedRegister") ]
};
my $math_op =
{
super => "Arithmetic",
super_has_print => 1,
rem => "dest, source1, source2",
params => [ ("TypedRegister", "TypedRegister", "TypedRegister") ]
};
my $cbranch_op =
{
super => "GenericBranch",
super_has_print => 1,
rem => "target label, condition",
params => [ ("Label*", "TypedRegister") ]
};
my $unary_op =
{
super => "Instruction_2",
rem => "dest, source",
params => [ ("TypedRegister", "TypedRegister") ]
};
#
# op defititions
#
$ops{"NOP"} =
{
super => "Instruction",
rem => "do nothing and like it",
};
$ops{"DEBUGGER"} =
{
super => "Instruction",
rem => "drop to the debugger",
};
$ops{"GENERIC_BINARY_OP"} =
{
super => "Instruction_4",
rem => "dest, op, source1, source2",
params => [ ("TypedRegister", "ExprNode::Kind", "TypedRegister", "TypedRegister") ]
};
$ops{"MOVE"} =
{
super => "Instruction_2",
rem => "dest, source",
params => [ ("TypedRegister", "TypedRegister") ]
};
$ops{"LOAD_IMMEDIATE"} =
{
super => "Instruction_2",
rem => "dest, immediate value (double)",
params => [ ("TypedRegister", "double" ) ]
};
$ops{"LOAD_NULL"} =
{
super => "Instruction_1",
rem => "dest",
params => [ ("TypedRegister") ]
};
$ops{"LOAD_TRUE"} =
{
super => "Instruction_1",
rem => "dest",
params => [ ("TypedRegister" ) ]
};
$ops{"LOAD_FALSE"} =
{
super => "Instruction_1",
rem => "dest",
params => [ ("TypedRegister" ) ]
};
$ops{"LOAD_STRING"} =
{
super => "Instruction_2",
rem => "dest, immediate value (string)",
params => [ ("TypedRegister", "JSString*" ) ]
};
$ops{"LOAD_NAME"} =
{
super => "Instruction_2",
rem => "dest, name",
params => [ ("TypedRegister", "const StringAtom*" ) ]
};
$ops{"SUPER"} =
{
super => "Instruction_1",
rem => "dest",
params => [ ("TypedRegister" ) ]
};
$ops{"SAVE_NAME"} =
{
super => "Instruction_2",
rem => "name, source",
params => [ ("const StringAtom*", "TypedRegister") ]
};
$ops{"NEW_OBJECT"} =
{
super => "Instruction_2",
rem => "dest, constructor",
params => [ ("TypedRegister", "TypedRegister") ]
};
$ops{"NEW_CLASS"} =
{
super => "Instruction_2",
rem => "dest, class",
params => [ ("TypedRegister", "JSClass*") ]
};
$ops{"NEW_FUNCTION"} =
{
super => "Instruction_2",
rem => "dest, ICodeModule",
params => [ ("TypedRegister", "ICodeModule*") ]
};
$ops{"NEW_ARRAY"} =
{
super => "Instruction_1",
rem => "dest",
params => [ ("TypedRegister") ]
};
$ops{"DELETE_PROP"} =
{
super => "Instruction_3",
rem => "dest, object, prop name",
params => [ ("TypedRegister", "TypedRegister", "const StringAtom*") ]
};
$ops{"GET_PROP"} =
{
super => "Instruction_3",
rem => "dest, object, prop name",
params => [ ("TypedRegister", "TypedRegister", "const StringAtom*") ]
};
$ops{"SET_PROP"} =
{
super => "Instruction_3",
rem => "object, name, source",
params => [ ("TypedRegister", "const StringAtom*", "TypedRegister") ]
};
$ops{"GET_SLOT"} =
{
super => "Instruction_3",
rem => "dest, object, slot number",
params => [ ("TypedRegister", "TypedRegister", "uint32") ]
};
$ops{"SET_SLOT"} =
{
super => "Instruction_3",
rem => "object, slot number, source",
params => [ ("TypedRegister", "uint32", "TypedRegister") ]
};
$ops{"GET_STATIC"} =
{
super => "Instruction_3",
rem => "dest, class, index",
params => [ ("TypedRegister", "JSClass*", "uint32") ]
};
$ops{"SET_STATIC"} =
{
super => "Instruction_3",
rem => "class, index, source",
params => [ ("JSClass*", "uint32", "TypedRegister") ]
};
$ops{"STATIC_XCR"} =
{
super => "Instruction_4",
rem => "dest, class, index, value",
params => [ ("TypedRegister", "JSClass*", "uint32", "double") ]
};
$ops{"SLOT_XCR"} =
{
super => "Instruction_4",
rem => "dest, source, slot number, value",
params => [ ("TypedRegister", "TypedRegister", "uint32", "double") ]
};
$ops{"PROP_XCR"} =
{
super => "Instruction_4",
rem => "dest, source, name, value",
params => [ ("TypedRegister", "TypedRegister", "const StringAtom*", "double") ]
};
$ops{"ELEM_XCR"} =
{
super => "Instruction_4",
rem => "dest, base, index, value",
params => [ ("TypedRegister", "TypedRegister", "TypedRegister", "double") ]
};
$ops{"NAME_XCR"} =
{
super => "Instruction_3",
rem => "dest, name, value",
params => [ ("TypedRegister", "const StringAtom*", "double") ]
};
$ops{"VAR_XCR"} =
{
super => "Instruction_3",
rem => "dest, source, value",
params => [ ("TypedRegister", "TypedRegister", "double") ]
};
$ops{"GET_ELEMENT"} =
{
super => "Instruction_3",
rem => "dest, base, index",
params => [ ("TypedRegister", "TypedRegister", "TypedRegister") ]
};
$ops{"SET_ELEMENT"} =
{
super => "Instruction_3",
rem => "base, index, value",
params => [ ("TypedRegister", "TypedRegister", "TypedRegister") ]
};
$ops{"NEW_CLOSURE"} =
{
super => "Instruction_2",
rem => "dest, ICodeModule",
params => [ ("TypedRegister", "ICodeModule*") ]
};
$ops{"GET_CLOSURE"} =
{
super => "Instruction_2",
rem => "dest, closure depth",
params => [ ("TypedRegister", "uint32") ]
};
$ops{"ADD"} = $math_op;
$ops{"SUBTRACT"} = $math_op;
$ops{"MULTIPLY"} = $math_op;
$ops{"DIVIDE"} = $math_op;
$ops{"REMAINDER"} = $math_op;
$ops{"SHIFTLEFT"} = $math_op;
$ops{"SHIFTRIGHT"} = $math_op;
$ops{"USHIFTRIGHT"}= $math_op;
$ops{"AND"} = $math_op;
$ops{"OR"} = $math_op;
$ops{"XOR"} = $math_op;
$ops{"COMPARE_LT"} = $binary_op;
$ops{"COMPARE_LE"} = $binary_op;
$ops{"COMPARE_EQ"} = $binary_op;
$ops{"COMPARE_NE"} = $binary_op;
$ops{"COMPARE_GE"} = $binary_op;
$ops{"COMPARE_GT"} = $binary_op;
$ops{"COMPARE_IN"} = $binary_op;
$ops{"STRICT_EQ"} = $binary_op;
$ops{"STRICT_NE"} = $binary_op;
$ops{"INSTANCEOF"} = $binary_op;
$ops{"BITNOT"} = $unary_op;
$ops{"NOT"} = $unary_op;
$ops{"TEST"} = $unary_op;
$ops{"NEGATE"} = $unary_op;
$ops{"POSATE"} = $unary_op;
$ops{"BRANCH"} =
{
super => "GenericBranch",
rem => "target label",
params => [ ("Label*") ]
};
$ops{"BRANCH_TRUE"} = $cbranch_op;
$ops{"BRANCH_FALSE"} = $cbranch_op;
$ops{"BRANCH_INITIALIZED"} = $cbranch_op;
$ops{"RETURN"} =
{
super => "Instruction_1",
rem => "return value",
params => [ ("TypedRegister") ]
};
$ops{"RETURN_VOID"} =
{
super => "Instruction",
rem => "Return without a value"
};
$ops{"CALL"} =
{
super => "Instruction_3",
rem => "result, target, args",
params => [ ("TypedRegister", "TypedRegister", "ArgumentList*") ]
};
$ops{"DIRECT_CALL"} =
{
super => "Instruction_3",
rem => "result, target, args",
params => [ ("TypedRegister", "JSFunction*", "ArgumentList*") ]
};
$ops{"BIND_THIS"} =
{
super => "Instruction_3",
rem => "result, this, target",
params => [ ("TypedRegister", "TypedRegister", "TypedRegister") ]
};
$ops{"GET_METHOD"} =
{
super => "Instruction_3",
rem => "result, target base, index",
params => [ ("TypedRegister", "TypedRegister", "uint32") ]
};
$ops{"THROW"} =
{
super => "Instruction_1",
rem => "exception value",
params => [ ("TypedRegister") ]
};
$ops{"TRYIN"} =
{
super => "Instruction_2",
rem => "catch target, finally target",
params => [ ("Label*", "Label*") ]
};
$ops{"TRYOUT"} =
{
super => "Instruction",
rem => "mmm, there is no try, only do",
};
$ops{"JSR"} =
{
super => "GenericBranch",
rem => "target",
params => [ ("Label*") ]
};
$ops{"RTS"} =
{
super => "Instruction",
rem => "Return to sender",
};
$ops{"WITHIN"} =
{
super => "Instruction_1",
rem => "within this object",
params => [ ("TypedRegister") ]
};
$ops{"WITHOUT"} =
{
super => "Instruction",
rem => "without this object",
};
$ops{"CAST"} =
{
super => "Instruction_3",
rem => "dest, rvalue, toType",
params => [ ("TypedRegister", "TypedRegister", "JSType*") ]
};
$ops{"CLASS"} =
{
super => "Instruction_2",
rem => "dest, obj",
params => [ ("TypedRegister", "TypedRegister") ]
};
1;

Просмотреть файл

@ -41,6 +41,7 @@
LOAD_NULL, /* dest */
LOAD_STRING, /* dest, immediate value (string) */
LOAD_TRUE, /* dest */
LOAD_TYPE, /* dest, type */
MOVE, /* dest, source */
MULTIPLY, /* dest, source1, source2 */
NAME_XCR, /* dest, name, value */
@ -191,18 +192,18 @@
}
};
class Cast : public Instruction_3<TypedRegister, TypedRegister, JSType*> {
class Cast : public Instruction_3<TypedRegister, TypedRegister, TypedRegister> {
public:
/* dest, rvalue, toType */
Cast (TypedRegister aOp1, TypedRegister aOp2, JSType* aOp3) :
Instruction_3<TypedRegister, TypedRegister, JSType*>
Cast (TypedRegister aOp1, TypedRegister aOp2, TypedRegister aOp3) :
Instruction_3<TypedRegister, TypedRegister, TypedRegister>
(CAST, aOp1, aOp2, aOp3) {};
virtual Formatter& print(Formatter& f) {
f << opcodeNames[CAST] << "\t" << mOp1 << ", " << mOp2 << ", " << "'" << mOp3->getName() << "'";
f << opcodeNames[CAST] << "\t" << mOp1 << ", " << mOp2 << ", " << mOp3;
return f;
}
virtual Formatter& printOperands(Formatter& f, const JSValues& registers) {
f << getRegisterValue(registers, mOp1.first) << ", " << getRegisterValue(registers, mOp2.first);
f << getRegisterValue(registers, mOp1.first) << ", " << getRegisterValue(registers, mOp2.first) << ", " << getRegisterValue(registers, mOp3.first);
return f;
}
};
@ -646,6 +647,22 @@
}
};
class LoadType : public Instruction_2<TypedRegister, JSType*> {
public:
/* dest, type */
LoadType (TypedRegister aOp1, JSType* aOp2) :
Instruction_2<TypedRegister, JSType*>
(LOAD_TYPE, aOp1, aOp2) {};
virtual Formatter& print(Formatter& f) {
f << opcodeNames[LOAD_TYPE] << "\t" << mOp1 << ", " << "'" << mOp2->getName() << "'";
return f;
}
virtual Formatter& printOperands(Formatter& f, const JSValues& registers) {
f << getRegisterValue(registers, mOp1.first);
return f;
}
};
class Move : public Instruction_2<TypedRegister, TypedRegister> {
public:
/* dest, source */
@ -1265,6 +1282,7 @@
"LOAD_NULL ",
"LOAD_STRING ",
"LOAD_TRUE ",
"LOAD_TYPE ",
"MOVE ",
"MULTIPLY ",
"NAME_XCR ",

Просмотреть файл

@ -225,6 +225,21 @@ TypedRegister ICodeGenerator::loadBoolean(bool value)
return dest;
}
TypedRegister ICodeGenerator::loadNull()
{
TypedRegister dest(getTempRegister(), &Any_Type);
iCode->push_back(new LoadNull(dest));
return dest;
}
TypedRegister ICodeGenerator::loadType(JSType *type)
{
TypedRegister dest(getTempRegister(), type);
iCode->push_back(new LoadType(dest, type));
return dest;
}
TypedRegister ICodeGenerator::newObject(TypedRegister constructor)
{
TypedRegister dest(getTempRegister(), &Any_Type);
@ -535,7 +550,7 @@ TypedRegister ICodeGenerator::super()
TypedRegister ICodeGenerator::cast(TypedRegister arg, JSType *toType)
{
TypedRegister dest(getTempRegister(), toType);
Cast *instr = new Cast(dest, arg, toType);
Cast *instr = new Cast(dest, arg, loadType(toType));
iCode->push_back(instr);
return dest;
}
@ -1249,6 +1264,9 @@ TypedRegister ICodeGenerator::genExpr(ExprNode *p,
else
ret = loadBoolean(false);
break;
case ExprNode::Null:
ret = loadNull();
break;
case ExprNode::parentheses:
{
UnaryExprNode *u = static_cast<UnaryExprNode *>(p);

Просмотреть файл

@ -378,6 +378,8 @@ namespace ICG {
TypedRegister loadImmediate(double value);
TypedRegister loadString(const String &value);
TypedRegister loadString(const StringAtom &name);
TypedRegister loadNull();
TypedRegister loadType(JSType *toType);
TypedRegister newObject(TypedRegister constructor);
TypedRegister newArray();

Просмотреть файл

@ -45,7 +45,7 @@
namespace JavaScript {
namespace ICodeASM {
static uint icodemap_size = 78;
static uint icodemap_size = 79;
static struct {
char *name;
@ -60,7 +60,7 @@ namespace ICodeASM {
{"BRANCH_INITIALIZED", {otLabel, otRegister}},
{"BRANCH_TRUE", {otLabel, otRegister}},
{"CALL", {otRegister, otRegister, otArgumentList}},
{"CAST", {otRegister, otRegister, otJSType}},
{"CAST", {otRegister, otRegister, otRegister}},
{"CLASS", {otRegister, otRegister}},
{"COMPARE_EQ", {otRegister, otRegister, otRegister}},
{"COMPARE_GE", {otRegister, otRegister, otRegister}},
@ -89,6 +89,7 @@ namespace ICodeASM {
{"LOAD_NULL", {otRegister}},
{"LOAD_STRING", {otRegister, otJSString}},
{"LOAD_TRUE", {otRegister}},
{"LOAD_TYPE", {otRegister, otJSType}},
{"MOVE", {otRegister, otRegister}},
{"MULTIPLY", {otRegister, otRegister, otRegister}},
{"NAME_XCR", {otRegister, otStringAtom, otDouble}},
@ -167,7 +168,7 @@ namespace ICodeASM {
i = new Call (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), reinterpret_cast<ArgumentList*>(node->operand[2].data));
break;
case 9:
i = new Cast (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), reinterpret_cast<JSType*>(node->operand[2].data));
i = new Cast (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 10:
i = new Class (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
@ -254,123 +255,126 @@ namespace ICodeASM {
i = new LoadTrue (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
break;
case 38:
i = new Move (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
i = new LoadType (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<JSType*>(node->operand[1].data));
break;
case 39:
i = new Multiply (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
i = new Move (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 40:
i = new NameXcr (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<const StringAtom*>(node->operand[1].data), static_cast<double>(node->operand[2].data));
i = new Multiply (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 41:
i = new Negate (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
i = new NameXcr (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<const StringAtom*>(node->operand[1].data), static_cast<double>(node->operand[2].data));
break;
case 42:
i = new NewArray (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
i = new Negate (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 43:
i = new NewClass (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<JSClass*>(node->operand[1].data));
i = new NewArray (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
break;
case 44:
i = new NewClosure (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<ICodeModule*>(node->operand[1].data));
i = new NewClass (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<JSClass*>(node->operand[1].data));
break;
case 45:
i = new NewFunction (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<ICodeModule*>(node->operand[1].data));
i = new NewClosure (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<ICodeModule*>(node->operand[1].data));
break;
case 46:
i = new NewObject (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
i = new NewFunction (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<ICodeModule*>(node->operand[1].data));
break;
case 47:
i = new Nop ();
i = new NewObject (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 48:
i = new Not (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
i = new Nop ();
break;
case 49:
i = new Or (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
i = new Not (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 50:
i = new Posate (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
i = new Or (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 51:
i = new PropXcr (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), reinterpret_cast<const StringAtom*>(node->operand[2].data), static_cast<double>(node->operand[3].data));
i = new Posate (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 52:
i = new Remainder (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
i = new PropXcr (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), reinterpret_cast<const StringAtom*>(node->operand[2].data), static_cast<double>(node->operand[3].data));
break;
case 53:
i = new Return (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
i = new Remainder (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 54:
i = new ReturnVoid ();
i = new Return (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
break;
case 55:
i = new Rts ();
i = new ReturnVoid ();
break;
case 56:
i = new SaveName (reinterpret_cast<const StringAtom*>(node->operand[0].data), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
i = new Rts ();
break;
case 57:
i = new SetElement (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
i = new SaveName (reinterpret_cast<const StringAtom*>(node->operand[0].data), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 58:
i = new SetProp (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<const StringAtom*>(node->operand[1].data), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
i = new SetElement (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 59:
i = new SetSlot (TypedRegister(static_cast<Register>(node->operand[0].data), 0), static_cast<uint32>(node->operand[1].data), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
i = new SetProp (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<const StringAtom*>(node->operand[1].data), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 60:
i = new SetStatic (reinterpret_cast<JSClass*>(node->operand[0].data), static_cast<uint32>(node->operand[1].data), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
i = new SetSlot (TypedRegister(static_cast<Register>(node->operand[0].data), 0), static_cast<uint32>(node->operand[1].data), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 61:
i = new Shiftleft (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
i = new SetStatic (reinterpret_cast<JSClass*>(node->operand[0].data), static_cast<uint32>(node->operand[1].data), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 62:
i = new Shiftright (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
i = new Shiftleft (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 63:
i = new SlotXcr (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), static_cast<uint32>(node->operand[2].data), static_cast<double>(node->operand[3].data));
i = new Shiftright (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 64:
i = new StaticXcr (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<JSClass*>(node->operand[1].data), static_cast<uint32>(node->operand[2].data), static_cast<double>(node->operand[3].data));
i = new SlotXcr (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), static_cast<uint32>(node->operand[2].data), static_cast<double>(node->operand[3].data));
break;
case 65:
i = new StrictEQ (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
i = new StaticXcr (TypedRegister(static_cast<Register>(node->operand[0].data), 0), reinterpret_cast<JSClass*>(node->operand[1].data), static_cast<uint32>(node->operand[2].data), static_cast<double>(node->operand[3].data));
break;
case 66:
i = new StrictNE (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
i = new StrictEQ (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 67:
i = new Subtract (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
i = new StrictNE (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 68:
i = new Super (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
i = new Subtract (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 69:
i = new Test (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
i = new Super (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
break;
case 70:
i = new Throw (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
i = new Test (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0));
break;
case 71:
i = new Tryin (reinterpret_cast<Label*>(node->operand[0].data), reinterpret_cast<Label*>(node->operand[1].data));
i = new Throw (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
break;
case 72:
i = new Tryout ();
i = new Tryin (reinterpret_cast<Label*>(node->operand[0].data), reinterpret_cast<Label*>(node->operand[1].data));
break;
case 73:
i = new Ushiftright (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
i = new Tryout ();
break;
case 74:
i = new VarXcr (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), static_cast<double>(node->operand[2].data));
i = new Ushiftright (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;
case 75:
i = new Within (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
i = new VarXcr (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), static_cast<double>(node->operand[2].data));
break;
case 76:
i = new Without ();
i = new Within (TypedRegister(static_cast<Register>(node->operand[0].data), 0));
break;
case 77:
i = new Without ();
break;
case 78:
i = new Xor (TypedRegister(static_cast<Register>(node->operand[0].data), 0), TypedRegister(static_cast<Register>(node->operand[1].data), 0), TypedRegister(static_cast<Register>(node->operand[2].data), 0));
break;

Просмотреть файл

@ -108,12 +108,6 @@ JSValue Context::readEvalFile(FILE* in, const String& fileName)
JSValues emptyArgs;
JSValue result;
// save off important member variables, to enable recursive call to interpret.
// this is a little stinky, but should be exception-safe.
autosaver<Activation*> activation(mActivation, 0);
autosaver<Linkage*> linkage(mLinkage, 0);
autosaver<InstructionIterator> pc(mPC);
try {
Arena a;
Parser p(getWorld(), a, buffer, fileName);
@ -133,11 +127,12 @@ JSValue Context::readEvalFile(FILE* in, const String& fileName)
stdOut << '\n';
/*******/
// Generate code for parsedStatements, which is a linked
// Generate code for parsedStatements, which is a linked
// list of zero or more statements
ICodeModule* icm = genCode(parsedStatements, fileName);
if (icm) {
result = interpret(icm, emptyArgs);
Context cx(getWorld(), getGlobalObject());
result = cx.interpret(icm, emptyArgs);
delete icm;
}
} catch (Exception &e) {
@ -538,8 +533,15 @@ JSValue Context::interpret(ICodeModule* iCode, const JSValues& args)
case CAST:
{
Cast* c = static_cast<Cast*>(instruction);
JSType *toType = op3(c);
(*registers)[dst(c).first] = (*registers)[src1(c).first].convert(toType);
JSValue toTypeValue = (*registers)[op3(c).first];
ASSERT(toTypeValue.isType());
(*registers)[dst(c).first] = (*registers)[src1(c).first].convert(toTypeValue.type);
}
break;
case LOAD_TYPE:
{
LoadType *lt = static_cast<LoadType*>(instruction);
(*registers)[dst(lt).first] = src1(lt);
}
break;
case CLASS:

Просмотреть файл

@ -175,6 +175,12 @@ $ops{"LOAD_NAME"} =
rem => "dest, name",
params => [ ("TypedRegister", "const StringAtom*" ) ]
};
$ops{"LOAD_TYPE"} =
{
super => "Instruction_2",
rem => "dest, type",
params => [ ("TypedRegister", "JSType*" ) ]
};
$ops{"SUPER"} =
{
super => "Instruction_1",
@ -426,7 +432,7 @@ $ops{"CAST"} =
{
super => "Instruction_3",
rem => "dest, rvalue, toType",
params => [ ("TypedRegister", "TypedRegister", "JSType*") ]
params => [ ("TypedRegister", "TypedRegister", "TypedRegister") ]
};
$ops{"CLASS"} =
{