From 774d01063550b3c14baa692281094927ca88f195 Mon Sep 17 00:00:00 2001 From: "rogerl%netscape.com" Date: Tue, 11 Jul 2000 20:54:06 +0000 Subject: [PATCH] More on @ operator. Fixed R 4billion print bug. --- js/js2/icode.h | 78 ++++++++++++++++++------------------- js/js2/interpreter.cpp | 7 ++-- js/js2/js2.cpp | 11 ++++-- js/js2/jstypes.cpp | 28 +++++++++++-- js/js2/jstypes.h | 2 +- js/js2/tools/gencode.pl | 8 +++- js/js2/vmtypes.cpp | 9 +++++ js/js2/vmtypes.h | 1 + js2/src/icode.h | 78 ++++++++++++++++++------------------- js2/src/interpreter.cpp | 7 ++-- js2/src/jstypes.cpp | 28 +++++++++++-- js2/src/jstypes.h | 2 +- js2/src/vmtypes.cpp | 9 +++++ js2/src/vmtypes.h | 1 + js2/tests/cpp/js2_shell.cpp | 11 ++++-- js2/tools/gencode.pl | 8 +++- 16 files changed, 182 insertions(+), 106 deletions(-) diff --git a/js/js2/icode.h b/js/js2/icode.h index 6c9d7ecdbc75..d689203d3df0 100644 --- a/js/js2/icode.h +++ b/js/js2/icode.h @@ -101,7 +101,7 @@ Instruction_2 (BITNOT, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[BITNOT] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first; + f << opcodeNames[BITNOT] << "\t" << mOp1 << ", " << mOp2; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -150,7 +150,7 @@ Instruction_4 (CALL, aOp1, aOp2, aOp3, aOp4) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[CALL] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << "'" << *mOp3 << "'" << ", " << mOp4; + f << opcodeNames[CALL] << "\t" << mOp1 << ", " << mOp2 << ", " << "'" << *mOp3 << "'" << ", " << mOp4; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -166,7 +166,7 @@ Instruction_3 (CAST, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[CAST] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << "'" << *mOp3 << "'"; + f << opcodeNames[CAST] << "\t" << mOp1 << ", " << mOp2 << ", " << "'" << mOp3->getName() << "'"; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -245,7 +245,7 @@ Instruction_4 (CONSTRUCTOR_CALL, aOp1, aOp2, aOp3, aOp4) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[CONSTRUCTOR_CALL] << "\t" << mOp1->getName() << ", " << mOp2 << ", " << "R" << mOp3.first << ", " << mOp4; + f << opcodeNames[CONSTRUCTOR_CALL] << "\t" << mOp1->getName() << ", " << mOp2 << ", " << mOp3 << ", " << mOp4; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -276,7 +276,7 @@ Instruction_3 (DELETE_PROP, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[DELETE_PROP] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << "'" << *mOp3 << "'"; + f << opcodeNames[DELETE_PROP] << "\t" << mOp1 << ", " << mOp2 << ", " << "'" << *mOp3 << "'"; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -301,7 +301,7 @@ Instruction_4 (ELEM_XCR, aOp1, aOp2, aOp3, aOp4) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[ELEM_XCR] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << "R" << mOp3.first << ", " << mOp4; + f << opcodeNames[ELEM_XCR] << "\t" << mOp1 << ", " << mOp2 << ", " << mOp3 << ", " << mOp4; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -317,7 +317,7 @@ Instruction_3 (GET_ELEMENT, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[GET_ELEMENT] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << "R" << mOp3.first; + f << opcodeNames[GET_ELEMENT] << "\t" << mOp1 << ", " << mOp2 << ", " << mOp3; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -333,7 +333,7 @@ Instruction_3 (GET_PROP, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[GET_PROP] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << "'" << *mOp3 << "'"; + f << opcodeNames[GET_PROP] << "\t" << mOp1 << ", " << mOp2 << ", " << "'" << *mOp3 << "'"; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -349,7 +349,7 @@ Instruction_3 (GET_SLOT, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[GET_SLOT] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << mOp3; + f << opcodeNames[GET_SLOT] << "\t" << mOp1 << ", " << mOp2 << ", " << mOp3; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -365,7 +365,7 @@ Instruction_3 (GET_STATIC, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[GET_STATIC] << "\t" << "R" << mOp1.first << ", " << mOp2->getName() << ", " << mOp3; + f << opcodeNames[GET_STATIC] << "\t" << mOp1 << ", " << mOp2->getName() << ", " << mOp3; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -405,7 +405,7 @@ Instruction_2 (LOAD_BOOLEAN, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[LOAD_BOOLEAN] << "\t" << "R" << mOp1.first << ", " << "'" << ((mOp2) ? "true" : "false") << "'"; + f << opcodeNames[LOAD_BOOLEAN] << "\t" << mOp1 << ", " << "'" << ((mOp2) ? "true" : "false") << "'"; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -421,7 +421,7 @@ Instruction_2 (LOAD_IMMEDIATE, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[LOAD_IMMEDIATE] << "\t" << "R" << mOp1.first << ", " << mOp2; + f << opcodeNames[LOAD_IMMEDIATE] << "\t" << mOp1 << ", " << mOp2; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -437,7 +437,7 @@ Instruction_2 (LOAD_NAME, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[LOAD_NAME] << "\t" << "R" << mOp1.first << ", " << "'" << *mOp2 << "'"; + f << opcodeNames[LOAD_NAME] << "\t" << mOp1 << ", " << "'" << *mOp2 << "'"; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -453,7 +453,7 @@ Instruction_2 (LOAD_STRING, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[LOAD_STRING] << "\t" << "R" << mOp1.first << ", " << "'" << *mOp2 << "'"; + f << opcodeNames[LOAD_STRING] << "\t" << mOp1 << ", " << "'" << *mOp2 << "'"; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -469,7 +469,7 @@ Instruction_4 (METHOD_CALL, aOp1, aOp2, aOp3, aOp4) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[METHOD_CALL] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << "R" << mOp3.first << ", " << mOp4; + f << opcodeNames[METHOD_CALL] << "\t" << mOp1 << ", " << mOp2 << ", " << mOp3 << ", " << mOp4; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -485,7 +485,7 @@ Instruction_2 (MOVE, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[MOVE] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first; + f << opcodeNames[MOVE] << "\t" << mOp1 << ", " << mOp2; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -510,7 +510,7 @@ Instruction_3 (NAME_XCR, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[NAME_XCR] << "\t" << "R" << mOp1.first << ", " << "'" << *mOp2 << "'" << ", " << mOp3; + f << opcodeNames[NAME_XCR] << "\t" << mOp1 << ", " << "'" << *mOp2 << "'" << ", " << mOp3; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -526,7 +526,7 @@ Instruction_2 (NEGATE, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[NEGATE] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first; + f << opcodeNames[NEGATE] << "\t" << mOp1 << ", " << mOp2; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -542,7 +542,7 @@ Instruction_1 (NEW_ARRAY, aOp1) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[NEW_ARRAY] << "\t" << "R" << mOp1.first; + f << opcodeNames[NEW_ARRAY] << "\t" << mOp1; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -558,7 +558,7 @@ Instruction_2 (NEW_CLASS, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[NEW_CLASS] << "\t" << "R" << mOp1.first << ", " << mOp2->getName(); + f << opcodeNames[NEW_CLASS] << "\t" << mOp1 << ", " << mOp2->getName(); return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -574,7 +574,7 @@ Instruction_2 (NEW_FUNCTION, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[NEW_FUNCTION] << "\t" << "R" << mOp1.first << ", " << "ICodeModule"; + f << opcodeNames[NEW_FUNCTION] << "\t" << mOp1 << ", " << "ICodeModule"; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -590,7 +590,7 @@ Instruction_1 (NEW_OBJECT, aOp1) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[NEW_OBJECT] << "\t" << "R" << mOp1.first; + f << opcodeNames[NEW_OBJECT] << "\t" << mOp1; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -621,7 +621,7 @@ Instruction_2 (NOT, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[NOT] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first; + f << opcodeNames[NOT] << "\t" << mOp1 << ", " << mOp2; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -646,7 +646,7 @@ Instruction_2 (POSATE, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[POSATE] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first; + f << opcodeNames[POSATE] << "\t" << mOp1 << ", " << mOp2; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -662,7 +662,7 @@ Instruction_4 (PROP_XCR, aOp1, aOp2, aOp3, aOp4) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[PROP_XCR] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << "'" << *mOp3 << "'" << ", " << mOp4; + f << opcodeNames[PROP_XCR] << "\t" << mOp1 << ", " << mOp2 << ", " << "'" << *mOp3 << "'" << ", " << mOp4; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -687,7 +687,7 @@ Instruction_1 (RETURN, aOp1) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[RETURN] << "\t" << "R" << mOp1.first; + f << opcodeNames[RETURN] << "\t" << mOp1; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -733,7 +733,7 @@ Instruction_2 (SAVE_NAME, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[SAVE_NAME] << "\t" << "'" << *mOp1 << "'" << ", " << "R" << mOp2.first; + f << opcodeNames[SAVE_NAME] << "\t" << "'" << *mOp1 << "'" << ", " << mOp2; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -749,7 +749,7 @@ Instruction_3 (SET_ELEMENT, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[SET_ELEMENT] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << "R" << mOp3.first; + f << opcodeNames[SET_ELEMENT] << "\t" << mOp1 << ", " << mOp2 << ", " << mOp3; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -765,7 +765,7 @@ Instruction_3 (SET_PROP, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[SET_PROP] << "\t" << "R" << mOp1.first << ", " << "'" << *mOp2 << "'" << ", " << "R" << mOp3.first; + f << opcodeNames[SET_PROP] << "\t" << mOp1 << ", " << "'" << *mOp2 << "'" << ", " << mOp3; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -781,7 +781,7 @@ Instruction_3 (SET_SLOT, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[SET_SLOT] << "\t" << "R" << mOp1.first << ", " << mOp2 << ", " << "R" << mOp3.first; + f << opcodeNames[SET_SLOT] << "\t" << mOp1 << ", " << mOp2 << ", " << mOp3; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -797,7 +797,7 @@ Instruction_3 (SET_STATIC, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[SET_STATIC] << "\t" << mOp1->getName() << ", " << mOp2 << ", " << "R" << mOp3.first; + f << opcodeNames[SET_STATIC] << "\t" << mOp1->getName() << ", " << mOp2 << ", " << mOp3; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -831,7 +831,7 @@ Instruction_4 (SLOT_XCR, aOp1, aOp2, aOp3, aOp4) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[SLOT_XCR] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << mOp3 << ", " << mOp4; + f << opcodeNames[SLOT_XCR] << "\t" << mOp1 << ", " << mOp2 << ", " << mOp3 << ", " << mOp4; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -847,7 +847,7 @@ Instruction_4 (STATIC_CALL, aOp1, aOp2, aOp3, aOp4) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[STATIC_CALL] << "\t" << "R" << mOp1.first << ", " << mOp2->getName() << ", " << mOp3 << ", " << mOp4; + f << opcodeNames[STATIC_CALL] << "\t" << mOp1 << ", " << mOp2->getName() << ", " << mOp3 << ", " << mOp4; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -863,7 +863,7 @@ Instruction_4 (STATIC_XCR, aOp1, aOp2, aOp3, aOp4) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[STATIC_XCR] << "\t" << "R" << mOp1.first << ", " << mOp2->getName() << ", " << mOp3 << ", " << mOp4; + f << opcodeNames[STATIC_XCR] << "\t" << mOp1 << ", " << mOp2->getName() << ", " << mOp3 << ", " << mOp4; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -906,7 +906,7 @@ Instruction_1 (SUPER, aOp1) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[SUPER] << "\t" << "R" << mOp1.first; + f << opcodeNames[SUPER] << "\t" << mOp1; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -922,7 +922,7 @@ Instruction_2 (TEST, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[TEST] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first; + f << opcodeNames[TEST] << "\t" << mOp1 << ", " << mOp2; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -938,7 +938,7 @@ Instruction_1 (THROW, aOp1) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[THROW] << "\t" << "R" << mOp1.first; + f << opcodeNames[THROW] << "\t" << mOp1; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -993,7 +993,7 @@ Instruction_3 (VAR_XCR, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[VAR_XCR] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << mOp3; + f << opcodeNames[VAR_XCR] << "\t" << mOp1 << ", " << mOp2 << ", " << mOp3; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -1009,7 +1009,7 @@ Instruction_1 (WITHIN, aOp1) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[WITHIN] << "\t" << "R" << mOp1.first; + f << opcodeNames[WITHIN] << "\t" << mOp1; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { diff --git a/js/js2/interpreter.cpp b/js/js2/interpreter.cpp index bb6338de0f0e..88b31aa62052 100644 --- a/js/js2/interpreter.cpp +++ b/js/js2/interpreter.cpp @@ -485,7 +485,7 @@ JSValue Context::interpret(ICodeModule* iCode, const JSValues& args) { Cast* c = static_cast(instruction); JSType *toType = op3(c); - (*registers)[dst(c).first] = (*registers)[src1(c).first]; + (*registers)[dst(c).first] = (*registers)[src1(c).first].convert(toType); } break; case SUPER: @@ -1095,7 +1095,7 @@ using JSString throughout. // increment the program counter. ++mPC; } - catch (JSException x) { + catch (JSException *x) { if (mLinkage) { if (mActivation->catchStack.empty()) { Linkage *pLinkage = mLinkage; @@ -1130,7 +1130,8 @@ using JSString throughout. continue; } } - rv = x.value; + rv = x->value; + break; } } diff --git a/js/js2/js2.cpp b/js/js2/js2.cpp index bd2c6275b5ec..d6413ff4a491 100644 --- a/js/js2/js2.cpp +++ b/js/js2/js2.cpp @@ -157,7 +157,7 @@ static ICodeModule* genCode(Context &cx, StmtNode *p, const String &fileName) return icm; } -static void readEvalFile(FILE* in, const String& fileName) +static JSValue readEvalFile(FILE* in, const String& fileName) { Context cx(world, &global); @@ -165,6 +165,7 @@ static void readEvalFile(FILE* in, const String& fileName) string line; LineReader inReader(in); JSValues emptyArgs; + JSValue result; while (inReader.readLine(line) != 0) { appendChars(buffer, line.data(), line.size()); @@ -189,7 +190,7 @@ static void readEvalFile(FILE* in, const String& fileName) // list of zero or more statements ICodeModule* icm = genCode(cx, parsedStatements, fileName); if (icm) { - cx.interpret(icm, emptyArgs); + result = cx.interpret(icm, emptyArgs); delete icm; } @@ -206,12 +207,14 @@ static void readEvalFile(FILE* in, const String& fileName) } } } + return result; } inline char narrow(char16 ch) { return char(ch); } static JSValue load(const JSValues &argv) { + JSValue result; size_t n = argv.size(); if (n > 1) { // the 'this' parameter is un-interesting for (size_t i = 1; i < n; ++i) { @@ -222,13 +225,13 @@ static JSValue load(const JSValues &argv) std::transform(fileName.begin(), fileName.end(), str.begin(), narrow); FILE* f = fopen(str.c_str(), "r"); if (f) { - readEvalFile(f, fileName); + result = readEvalFile(f, fileName); fclose(f); } } } } - return kUndefinedValue; + return result; } static void readEvalPrint(FILE *in, World &world) diff --git a/js/js2/jstypes.cpp b/js/js2/jstypes.cpp index 19fe99b997b7..73807666933b 100644 --- a/js/js2/jstypes.cpp +++ b/js/js2/jstypes.cpp @@ -39,6 +39,8 @@ namespace JavaScript { namespace JSTypes { +using namespace JSClasses; + // using JavaScript::StringAtom; // the canonical undefined value, etc. @@ -452,7 +454,7 @@ JSValue JSValue::valueToUInt32(const JSValue& value) } -JSValue JSValue::convert(const JSType *toType) +JSValue JSValue::convert(JSType *toType) { if (toType == &Any_Type) // yuck, something wrong with this // maybe the base types should be @@ -461,9 +463,27 @@ JSValue JSValue::convert(const JSType *toType) return *this; else if (toType == &Integer_Type) return valueToInteger(*this); - else - // etc... - return kUndefinedValue; + else { + JSClass *toClass = dynamic_cast(toType); + if (toClass) { + if (tag == object_tag) { + JSClass *fromClass = dynamic_cast(object->getType()); + if (fromClass) { + while (fromClass != toClass) { + fromClass = fromClass->getSuperClass(); + if (fromClass == NULL) + throw new JSException("Can't cast to unrelated class"); + } + return *this; + } + else + throw new JSException("Can't cast a generic object to a class"); + } + else + throw new JSException("Can't cast a non-object to a class"); + } + } + return kUndefinedValue; } diff --git a/js/js2/jstypes.h b/js/js2/jstypes.h index 8f69c10a1e4d..db40c3ec525e 100644 --- a/js/js2/jstypes.h +++ b/js/js2/jstypes.h @@ -142,7 +142,7 @@ namespace JSTypes { JSValue toPrimitive(ECMA_type hint = NoHint) const; - JSValue convert(const JSType *toType); + JSValue convert(JSType *toType); static JSValue valueToString(const JSValue& value); diff --git a/js/js2/tools/gencode.pl b/js/js2/tools/gencode.pl index c61cdef431a4..33ed4aabe030 100644 --- a/js/js2/tools/gencode.pl +++ b/js/js2/tools/gencode.pl @@ -540,13 +540,17 @@ sub get_print_body { for $type (@types) { if ($type eq "TypedRegister") { - push (@oplist, "\"R\" << mOp$op.first"); + + push (@oplist, "mOp$op" ); + + # push (@oplist, "\"R\" << ((mOp$op.first == NotARegister) ? -1 : mOp$op.first)"); + } elsif ($type eq "Label*") { push (@oplist, "\"Offset \" << ((mOp$op) ? mOp$op->mOffset : NotAnOffset)") } elsif ($type =~ /String/) { push (@oplist, "\"'\" << *mOp$op << \"'\""); } elsif ($type =~ /JSType\*/) { - push (@oplist, "\"'\" << *mOp$op << \"'\""); + push (@oplist, "\"'\" << mOp$op->getName() << \"'\""); } elsif ($type =~ /bool/) { push (@oplist, "\"'\" << ((mOp$op) ? \"true\" : \"false\") << \"'\""); } elsif ($type =~ /ICodeModule/) { diff --git a/js/js2/vmtypes.cpp b/js/js2/vmtypes.cpp index 516d4d80196a..f153170d0aec 100644 --- a/js/js2/vmtypes.cpp +++ b/js/js2/vmtypes.cpp @@ -81,6 +81,15 @@ Formatter& operator<< (Formatter& f, const ArgList& al) return f; } +Formatter& operator<< (Formatter& f, TypedRegister& r) +{ + if (r.first == NotARegister) + f << ""; + else + f << "R" << r.first; + return f; +} + Formatter& operator<< (Formatter &f, InstructionStream &is) { diff --git a/js/js2/vmtypes.h b/js/js2/vmtypes.h index 2a1419ff59c9..c5dc086ed3a6 100644 --- a/js/js2/vmtypes.h +++ b/js/js2/vmtypes.h @@ -109,6 +109,7 @@ namespace VM { Formatter& operator<< (Formatter& f, RegisterList& rl); Formatter& operator<< (Formatter& f, const ArgList& al); Formatter& operator<< (Formatter& f, InstructionStream& is); + Formatter& operator<< (Formatter& f, TypedRegister& r); /********************************************************************/ diff --git a/js2/src/icode.h b/js2/src/icode.h index 6c9d7ecdbc75..d689203d3df0 100644 --- a/js2/src/icode.h +++ b/js2/src/icode.h @@ -101,7 +101,7 @@ Instruction_2 (BITNOT, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[BITNOT] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first; + f << opcodeNames[BITNOT] << "\t" << mOp1 << ", " << mOp2; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -150,7 +150,7 @@ Instruction_4 (CALL, aOp1, aOp2, aOp3, aOp4) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[CALL] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << "'" << *mOp3 << "'" << ", " << mOp4; + f << opcodeNames[CALL] << "\t" << mOp1 << ", " << mOp2 << ", " << "'" << *mOp3 << "'" << ", " << mOp4; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -166,7 +166,7 @@ Instruction_3 (CAST, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[CAST] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << "'" << *mOp3 << "'"; + f << opcodeNames[CAST] << "\t" << mOp1 << ", " << mOp2 << ", " << "'" << mOp3->getName() << "'"; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -245,7 +245,7 @@ Instruction_4 (CONSTRUCTOR_CALL, aOp1, aOp2, aOp3, aOp4) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[CONSTRUCTOR_CALL] << "\t" << mOp1->getName() << ", " << mOp2 << ", " << "R" << mOp3.first << ", " << mOp4; + f << opcodeNames[CONSTRUCTOR_CALL] << "\t" << mOp1->getName() << ", " << mOp2 << ", " << mOp3 << ", " << mOp4; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -276,7 +276,7 @@ Instruction_3 (DELETE_PROP, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[DELETE_PROP] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << "'" << *mOp3 << "'"; + f << opcodeNames[DELETE_PROP] << "\t" << mOp1 << ", " << mOp2 << ", " << "'" << *mOp3 << "'"; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -301,7 +301,7 @@ Instruction_4 (ELEM_XCR, aOp1, aOp2, aOp3, aOp4) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[ELEM_XCR] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << "R" << mOp3.first << ", " << mOp4; + f << opcodeNames[ELEM_XCR] << "\t" << mOp1 << ", " << mOp2 << ", " << mOp3 << ", " << mOp4; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -317,7 +317,7 @@ Instruction_3 (GET_ELEMENT, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[GET_ELEMENT] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << "R" << mOp3.first; + f << opcodeNames[GET_ELEMENT] << "\t" << mOp1 << ", " << mOp2 << ", " << mOp3; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -333,7 +333,7 @@ Instruction_3 (GET_PROP, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[GET_PROP] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << "'" << *mOp3 << "'"; + f << opcodeNames[GET_PROP] << "\t" << mOp1 << ", " << mOp2 << ", " << "'" << *mOp3 << "'"; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -349,7 +349,7 @@ Instruction_3 (GET_SLOT, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[GET_SLOT] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << mOp3; + f << opcodeNames[GET_SLOT] << "\t" << mOp1 << ", " << mOp2 << ", " << mOp3; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -365,7 +365,7 @@ Instruction_3 (GET_STATIC, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[GET_STATIC] << "\t" << "R" << mOp1.first << ", " << mOp2->getName() << ", " << mOp3; + f << opcodeNames[GET_STATIC] << "\t" << mOp1 << ", " << mOp2->getName() << ", " << mOp3; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -405,7 +405,7 @@ Instruction_2 (LOAD_BOOLEAN, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[LOAD_BOOLEAN] << "\t" << "R" << mOp1.first << ", " << "'" << ((mOp2) ? "true" : "false") << "'"; + f << opcodeNames[LOAD_BOOLEAN] << "\t" << mOp1 << ", " << "'" << ((mOp2) ? "true" : "false") << "'"; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -421,7 +421,7 @@ Instruction_2 (LOAD_IMMEDIATE, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[LOAD_IMMEDIATE] << "\t" << "R" << mOp1.first << ", " << mOp2; + f << opcodeNames[LOAD_IMMEDIATE] << "\t" << mOp1 << ", " << mOp2; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -437,7 +437,7 @@ Instruction_2 (LOAD_NAME, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[LOAD_NAME] << "\t" << "R" << mOp1.first << ", " << "'" << *mOp2 << "'"; + f << opcodeNames[LOAD_NAME] << "\t" << mOp1 << ", " << "'" << *mOp2 << "'"; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -453,7 +453,7 @@ Instruction_2 (LOAD_STRING, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[LOAD_STRING] << "\t" << "R" << mOp1.first << ", " << "'" << *mOp2 << "'"; + f << opcodeNames[LOAD_STRING] << "\t" << mOp1 << ", " << "'" << *mOp2 << "'"; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -469,7 +469,7 @@ Instruction_4 (METHOD_CALL, aOp1, aOp2, aOp3, aOp4) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[METHOD_CALL] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << "R" << mOp3.first << ", " << mOp4; + f << opcodeNames[METHOD_CALL] << "\t" << mOp1 << ", " << mOp2 << ", " << mOp3 << ", " << mOp4; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -485,7 +485,7 @@ Instruction_2 (MOVE, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[MOVE] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first; + f << opcodeNames[MOVE] << "\t" << mOp1 << ", " << mOp2; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -510,7 +510,7 @@ Instruction_3 (NAME_XCR, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[NAME_XCR] << "\t" << "R" << mOp1.first << ", " << "'" << *mOp2 << "'" << ", " << mOp3; + f << opcodeNames[NAME_XCR] << "\t" << mOp1 << ", " << "'" << *mOp2 << "'" << ", " << mOp3; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -526,7 +526,7 @@ Instruction_2 (NEGATE, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[NEGATE] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first; + f << opcodeNames[NEGATE] << "\t" << mOp1 << ", " << mOp2; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -542,7 +542,7 @@ Instruction_1 (NEW_ARRAY, aOp1) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[NEW_ARRAY] << "\t" << "R" << mOp1.first; + f << opcodeNames[NEW_ARRAY] << "\t" << mOp1; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -558,7 +558,7 @@ Instruction_2 (NEW_CLASS, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[NEW_CLASS] << "\t" << "R" << mOp1.first << ", " << mOp2->getName(); + f << opcodeNames[NEW_CLASS] << "\t" << mOp1 << ", " << mOp2->getName(); return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -574,7 +574,7 @@ Instruction_2 (NEW_FUNCTION, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[NEW_FUNCTION] << "\t" << "R" << mOp1.first << ", " << "ICodeModule"; + f << opcodeNames[NEW_FUNCTION] << "\t" << mOp1 << ", " << "ICodeModule"; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -590,7 +590,7 @@ Instruction_1 (NEW_OBJECT, aOp1) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[NEW_OBJECT] << "\t" << "R" << mOp1.first; + f << opcodeNames[NEW_OBJECT] << "\t" << mOp1; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -621,7 +621,7 @@ Instruction_2 (NOT, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[NOT] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first; + f << opcodeNames[NOT] << "\t" << mOp1 << ", " << mOp2; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -646,7 +646,7 @@ Instruction_2 (POSATE, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[POSATE] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first; + f << opcodeNames[POSATE] << "\t" << mOp1 << ", " << mOp2; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -662,7 +662,7 @@ Instruction_4 (PROP_XCR, aOp1, aOp2, aOp3, aOp4) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[PROP_XCR] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << "'" << *mOp3 << "'" << ", " << mOp4; + f << opcodeNames[PROP_XCR] << "\t" << mOp1 << ", " << mOp2 << ", " << "'" << *mOp3 << "'" << ", " << mOp4; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -687,7 +687,7 @@ Instruction_1 (RETURN, aOp1) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[RETURN] << "\t" << "R" << mOp1.first; + f << opcodeNames[RETURN] << "\t" << mOp1; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -733,7 +733,7 @@ Instruction_2 (SAVE_NAME, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[SAVE_NAME] << "\t" << "'" << *mOp1 << "'" << ", " << "R" << mOp2.first; + f << opcodeNames[SAVE_NAME] << "\t" << "'" << *mOp1 << "'" << ", " << mOp2; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -749,7 +749,7 @@ Instruction_3 (SET_ELEMENT, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[SET_ELEMENT] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << "R" << mOp3.first; + f << opcodeNames[SET_ELEMENT] << "\t" << mOp1 << ", " << mOp2 << ", " << mOp3; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -765,7 +765,7 @@ Instruction_3 (SET_PROP, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[SET_PROP] << "\t" << "R" << mOp1.first << ", " << "'" << *mOp2 << "'" << ", " << "R" << mOp3.first; + f << opcodeNames[SET_PROP] << "\t" << mOp1 << ", " << "'" << *mOp2 << "'" << ", " << mOp3; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -781,7 +781,7 @@ Instruction_3 (SET_SLOT, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[SET_SLOT] << "\t" << "R" << mOp1.first << ", " << mOp2 << ", " << "R" << mOp3.first; + f << opcodeNames[SET_SLOT] << "\t" << mOp1 << ", " << mOp2 << ", " << mOp3; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -797,7 +797,7 @@ Instruction_3 (SET_STATIC, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[SET_STATIC] << "\t" << mOp1->getName() << ", " << mOp2 << ", " << "R" << mOp3.first; + f << opcodeNames[SET_STATIC] << "\t" << mOp1->getName() << ", " << mOp2 << ", " << mOp3; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -831,7 +831,7 @@ Instruction_4 (SLOT_XCR, aOp1, aOp2, aOp3, aOp4) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[SLOT_XCR] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << mOp3 << ", " << mOp4; + f << opcodeNames[SLOT_XCR] << "\t" << mOp1 << ", " << mOp2 << ", " << mOp3 << ", " << mOp4; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -847,7 +847,7 @@ Instruction_4 (STATIC_CALL, aOp1, aOp2, aOp3, aOp4) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[STATIC_CALL] << "\t" << "R" << mOp1.first << ", " << mOp2->getName() << ", " << mOp3 << ", " << mOp4; + f << opcodeNames[STATIC_CALL] << "\t" << mOp1 << ", " << mOp2->getName() << ", " << mOp3 << ", " << mOp4; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -863,7 +863,7 @@ Instruction_4 (STATIC_XCR, aOp1, aOp2, aOp3, aOp4) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[STATIC_XCR] << "\t" << "R" << mOp1.first << ", " << mOp2->getName() << ", " << mOp3 << ", " << mOp4; + f << opcodeNames[STATIC_XCR] << "\t" << mOp1 << ", " << mOp2->getName() << ", " << mOp3 << ", " << mOp4; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -906,7 +906,7 @@ Instruction_1 (SUPER, aOp1) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[SUPER] << "\t" << "R" << mOp1.first; + f << opcodeNames[SUPER] << "\t" << mOp1; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -922,7 +922,7 @@ Instruction_2 (TEST, aOp1, aOp2) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[TEST] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first; + f << opcodeNames[TEST] << "\t" << mOp1 << ", " << mOp2; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -938,7 +938,7 @@ Instruction_1 (THROW, aOp1) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[THROW] << "\t" << "R" << mOp1.first; + f << opcodeNames[THROW] << "\t" << mOp1; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -993,7 +993,7 @@ Instruction_3 (VAR_XCR, aOp1, aOp2, aOp3) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[VAR_XCR] << "\t" << "R" << mOp1.first << ", " << "R" << mOp2.first << ", " << mOp3; + f << opcodeNames[VAR_XCR] << "\t" << mOp1 << ", " << mOp2 << ", " << mOp3; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { @@ -1009,7 +1009,7 @@ Instruction_1 (WITHIN, aOp1) {}; virtual Formatter& print(Formatter& f) { - f << opcodeNames[WITHIN] << "\t" << "R" << mOp1.first; + f << opcodeNames[WITHIN] << "\t" << mOp1; return f; } virtual Formatter& printOperands(Formatter& f, const JSValues& registers) { diff --git a/js2/src/interpreter.cpp b/js2/src/interpreter.cpp index bb6338de0f0e..88b31aa62052 100644 --- a/js2/src/interpreter.cpp +++ b/js2/src/interpreter.cpp @@ -485,7 +485,7 @@ JSValue Context::interpret(ICodeModule* iCode, const JSValues& args) { Cast* c = static_cast(instruction); JSType *toType = op3(c); - (*registers)[dst(c).first] = (*registers)[src1(c).first]; + (*registers)[dst(c).first] = (*registers)[src1(c).first].convert(toType); } break; case SUPER: @@ -1095,7 +1095,7 @@ using JSString throughout. // increment the program counter. ++mPC; } - catch (JSException x) { + catch (JSException *x) { if (mLinkage) { if (mActivation->catchStack.empty()) { Linkage *pLinkage = mLinkage; @@ -1130,7 +1130,8 @@ using JSString throughout. continue; } } - rv = x.value; + rv = x->value; + break; } } diff --git a/js2/src/jstypes.cpp b/js2/src/jstypes.cpp index 19fe99b997b7..73807666933b 100644 --- a/js2/src/jstypes.cpp +++ b/js2/src/jstypes.cpp @@ -39,6 +39,8 @@ namespace JavaScript { namespace JSTypes { +using namespace JSClasses; + // using JavaScript::StringAtom; // the canonical undefined value, etc. @@ -452,7 +454,7 @@ JSValue JSValue::valueToUInt32(const JSValue& value) } -JSValue JSValue::convert(const JSType *toType) +JSValue JSValue::convert(JSType *toType) { if (toType == &Any_Type) // yuck, something wrong with this // maybe the base types should be @@ -461,9 +463,27 @@ JSValue JSValue::convert(const JSType *toType) return *this; else if (toType == &Integer_Type) return valueToInteger(*this); - else - // etc... - return kUndefinedValue; + else { + JSClass *toClass = dynamic_cast(toType); + if (toClass) { + if (tag == object_tag) { + JSClass *fromClass = dynamic_cast(object->getType()); + if (fromClass) { + while (fromClass != toClass) { + fromClass = fromClass->getSuperClass(); + if (fromClass == NULL) + throw new JSException("Can't cast to unrelated class"); + } + return *this; + } + else + throw new JSException("Can't cast a generic object to a class"); + } + else + throw new JSException("Can't cast a non-object to a class"); + } + } + return kUndefinedValue; } diff --git a/js2/src/jstypes.h b/js2/src/jstypes.h index 8f69c10a1e4d..db40c3ec525e 100644 --- a/js2/src/jstypes.h +++ b/js2/src/jstypes.h @@ -142,7 +142,7 @@ namespace JSTypes { JSValue toPrimitive(ECMA_type hint = NoHint) const; - JSValue convert(const JSType *toType); + JSValue convert(JSType *toType); static JSValue valueToString(const JSValue& value); diff --git a/js2/src/vmtypes.cpp b/js2/src/vmtypes.cpp index 516d4d80196a..f153170d0aec 100644 --- a/js2/src/vmtypes.cpp +++ b/js2/src/vmtypes.cpp @@ -81,6 +81,15 @@ Formatter& operator<< (Formatter& f, const ArgList& al) return f; } +Formatter& operator<< (Formatter& f, TypedRegister& r) +{ + if (r.first == NotARegister) + f << ""; + else + f << "R" << r.first; + return f; +} + Formatter& operator<< (Formatter &f, InstructionStream &is) { diff --git a/js2/src/vmtypes.h b/js2/src/vmtypes.h index 2a1419ff59c9..c5dc086ed3a6 100644 --- a/js2/src/vmtypes.h +++ b/js2/src/vmtypes.h @@ -109,6 +109,7 @@ namespace VM { Formatter& operator<< (Formatter& f, RegisterList& rl); Formatter& operator<< (Formatter& f, const ArgList& al); Formatter& operator<< (Formatter& f, InstructionStream& is); + Formatter& operator<< (Formatter& f, TypedRegister& r); /********************************************************************/ diff --git a/js2/tests/cpp/js2_shell.cpp b/js2/tests/cpp/js2_shell.cpp index bd2c6275b5ec..d6413ff4a491 100644 --- a/js2/tests/cpp/js2_shell.cpp +++ b/js2/tests/cpp/js2_shell.cpp @@ -157,7 +157,7 @@ static ICodeModule* genCode(Context &cx, StmtNode *p, const String &fileName) return icm; } -static void readEvalFile(FILE* in, const String& fileName) +static JSValue readEvalFile(FILE* in, const String& fileName) { Context cx(world, &global); @@ -165,6 +165,7 @@ static void readEvalFile(FILE* in, const String& fileName) string line; LineReader inReader(in); JSValues emptyArgs; + JSValue result; while (inReader.readLine(line) != 0) { appendChars(buffer, line.data(), line.size()); @@ -189,7 +190,7 @@ static void readEvalFile(FILE* in, const String& fileName) // list of zero or more statements ICodeModule* icm = genCode(cx, parsedStatements, fileName); if (icm) { - cx.interpret(icm, emptyArgs); + result = cx.interpret(icm, emptyArgs); delete icm; } @@ -206,12 +207,14 @@ static void readEvalFile(FILE* in, const String& fileName) } } } + return result; } inline char narrow(char16 ch) { return char(ch); } static JSValue load(const JSValues &argv) { + JSValue result; size_t n = argv.size(); if (n > 1) { // the 'this' parameter is un-interesting for (size_t i = 1; i < n; ++i) { @@ -222,13 +225,13 @@ static JSValue load(const JSValues &argv) std::transform(fileName.begin(), fileName.end(), str.begin(), narrow); FILE* f = fopen(str.c_str(), "r"); if (f) { - readEvalFile(f, fileName); + result = readEvalFile(f, fileName); fclose(f); } } } } - return kUndefinedValue; + return result; } static void readEvalPrint(FILE *in, World &world) diff --git a/js2/tools/gencode.pl b/js2/tools/gencode.pl index c61cdef431a4..33ed4aabe030 100644 --- a/js2/tools/gencode.pl +++ b/js2/tools/gencode.pl @@ -540,13 +540,17 @@ sub get_print_body { for $type (@types) { if ($type eq "TypedRegister") { - push (@oplist, "\"R\" << mOp$op.first"); + + push (@oplist, "mOp$op" ); + + # push (@oplist, "\"R\" << ((mOp$op.first == NotARegister) ? -1 : mOp$op.first)"); + } elsif ($type eq "Label*") { push (@oplist, "\"Offset \" << ((mOp$op) ? mOp$op->mOffset : NotAnOffset)") } elsif ($type =~ /String/) { push (@oplist, "\"'\" << *mOp$op << \"'\""); } elsif ($type =~ /JSType\*/) { - push (@oplist, "\"'\" << *mOp$op << \"'\""); + push (@oplist, "\"'\" << mOp$op->getName() << \"'\""); } elsif ($type =~ /bool/) { push (@oplist, "\"'\" << ((mOp$op) ? \"true\" : \"false\") << \"'\""); } elsif ($type =~ /ICodeModule/) {