Got newClass working, added printProperties for instances, some slot

stuff is happening.
This commit is contained in:
rogerl%netscape.com 2000-06-24 00:50:59 +00:00
Родитель 1af2ca85a9
Коммит ac7b311416
14 изменённых файлов: 154 добавлений и 18 удалений

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

@ -197,6 +197,14 @@ TypedRegister ICodeGenerator::newObject()
return dest; return dest;
} }
TypedRegister ICodeGenerator::newClass(const StringAtom &name)
{
TypedRegister dest(getRegister(), &Any_Type);
NewClass *instr = new NewClass(dest, &name);
iCode->push_back(instr);
return dest;
}
TypedRegister ICodeGenerator::newFunction(ICodeModule *icm) TypedRegister ICodeGenerator::newFunction(ICodeModule *icm)
{ {
TypedRegister dest(getRegister(), &Function_Type); TypedRegister dest(getRegister(), &Function_Type);
@ -632,8 +640,12 @@ TypedRegister ICodeGenerator::genExpr(ExprNode *p,
break; break;
case ExprNode::New: case ExprNode::New:
{ {
// FIXME - handle args, etc... InvokeExprNode *i = static_cast<InvokeExprNode *>(p);
ret = newObject(); if (i->op->getKind() == ExprNode::identifier) {
ret = newClass(static_cast<IdentifierExprNode *>(i->op)->name);
}
else
ret = newObject(); // XXX more
} }
break; break;
case ExprNode::call : case ExprNode::call :
@ -934,7 +946,7 @@ TypedRegister ICodeGenerator::genExpr(ExprNode *p,
if (b->op1->getKind() == ExprNode::dot) { if (b->op1->getKind() == ExprNode::dot) {
BinaryExprNode *lb = static_cast<BinaryExprNode *>(b->op1); BinaryExprNode *lb = static_cast<BinaryExprNode *>(b->op1);
TypedRegister base = genExpr(lb->op1); TypedRegister base = genExpr(lb->op1);
const StringAtom &name = static_cast<IdentifierExprNode *>(b->op2)->name; const StringAtom &name = static_cast<IdentifierExprNode *>(lb->op2)->name;
uint32 slotIndex; uint32 slotIndex;
if (isSlotName(base.second, name, slotIndex)) if (isSlotName(base.second, name, slotIndex))
setSlot(base, slotIndex, ret); setSlot(base, slotIndex, ret);

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

@ -238,6 +238,7 @@ namespace ICG {
TypedRegister newObject(); TypedRegister newObject();
TypedRegister newArray(); TypedRegister newArray();
TypedRegister newFunction(ICodeModule *icm); TypedRegister newFunction(ICodeModule *icm);
TypedRegister newClass(const StringAtom &name);
TypedRegister loadName(const StringAtom &name); TypedRegister loadName(const StringAtom &name);
void saveName(const StringAtom &name, TypedRegister value); void saveName(const StringAtom &name, TypedRegister value);

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

@ -56,6 +56,7 @@ namespace Interpreter {
using namespace ICG; using namespace ICG;
using namespace JSTypes; using namespace JSTypes;
using namespace JSClasses;
// These classes are private to the JS interpreter. // These classes are private to the JS interpreter.
@ -709,6 +710,28 @@ using JSString throughout.
} }
break; break;
case GET_SLOT:
{
GetSlot* gs = static_cast<GetSlot*>(instruction);
JSValue& value = (*registers)[src1(gs).first];
if (value.isObject()) {
JSInstance* inst = static_cast<JSInstance *>(value.object);
(*registers)[dst(gs).first] = (*inst)[src2(gs)];
}
// XXX runtime error
}
break;
case SET_SLOT:
{
SetSlot* ss = static_cast<SetSlot*>(instruction);
JSValue& value = (*registers)[dst(ss).first];
if (value.isObject()) {
JSInstance* inst = static_cast<JSInstance *>(value.object);
(*inst)[src1(ss)] = (*registers)[src2(ss).first];
}
}
break;
case LOAD_IMMEDIATE: case LOAD_IMMEDIATE:
{ {
LoadImmediate* li = static_cast<LoadImmediate*>(instruction); LoadImmediate* li = static_cast<LoadImmediate*>(instruction);
@ -822,6 +845,19 @@ using JSString throughout.
} }
break; break;
case SLOT_XCR:
{
SlotXcr *sx = static_cast<SlotXcr*>(instruction);
JSValue& dest = (*registers)[dst(sx).first];
JSValue& base = (*registers)[src1(sx).first];
JSInstance *inst = static_cast<JSInstance*>(base.object);
JSValue r = (*inst)[src2(sx)].toNumber();
dest = r;
r.f64 += val4(sx);
(*inst)[src2(sx)] = r;
}
break;
case NAME_XCR: case NAME_XCR:
{ {
NameXcr *nx = static_cast<NameXcr*>(instruction); NameXcr *nx = static_cast<NameXcr*>(instruction);

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

@ -22,8 +22,8 @@
// JS2 shell. // JS2 shell.
// //
#if 0 #if 1
#define DEBUGGER_FOO //#define DEBUGGER_FOO
#define INTERPRET_INPUT #define INTERPRET_INPUT
#else #else
#undef DEBUGGER_FOO #undef DEBUGGER_FOO

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

@ -104,6 +104,11 @@ namespace JSClasses {
return mSlots[name]; return mSlots[name];
} }
JSSlots& getSlots()
{
return mSlots;
}
bool hasSlot(const String& name) bool hasSlot(const String& name)
{ {
return (mSlots.count(name) != 0); return (mSlots.count(name) != 0);
@ -142,6 +147,18 @@ namespace JSClasses {
{ {
return mSlots[index]; return mSlots[index];
} }
virtual void printProperties(Formatter& f)
{
JSObject::printProperties(f);
JSClass *thisClass = getClass();
JSSlots &slots = thisClass->getSlots();
f << "Slots:\n";
for (JSSlots::iterator i = slots.begin(), end = slots.end(); i != end; ++i) {
f << i->first << " : " << mSlots[i->second.mIndex] << "\n";
}
}
}; };
} /* namespace JSClasses */ } /* namespace JSClasses */

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

@ -32,6 +32,7 @@
*/ */
#include "jstypes.h" #include "jstypes.h"
#include "jsclasses.h"
#include "numerics.h" #include "numerics.h"
#include "icodegenerator.h" #include "icodegenerator.h"
@ -155,13 +156,13 @@ int JSValue::operator==(const JSValue& value) const
return 0; return 0;
} }
Formatter& operator<<(Formatter& f, const JSObject& obj) Formatter& operator<<(Formatter& f, JSObject& obj)
{ {
obj.printProperties(f); obj.printProperties(f);
return f; return f;
} }
void JSObject::printProperties(Formatter& f) const void JSObject::printProperties(Formatter& f)
{ {
for (JSProperties::const_iterator i = mProperties.begin(); i != mProperties.end(); i++) { for (JSProperties::const_iterator i = mProperties.begin(); i != mProperties.end(); i++) {
f << (*i).first << " : " << (*i).second; f << (*i).first << " : " << (*i).second;
@ -184,6 +185,7 @@ Formatter& operator<<(Formatter& f, const JSValue& value)
break; break;
case JSValue::object_tag: case JSValue::object_tag:
{ {
printFormat(f, "Object @ 0x%08X\n", value.object); printFormat(f, "Object @ 0x%08X\n", value.object);
f << *value.object; f << *value.object;
} }

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

@ -253,10 +253,10 @@ namespace JSTypes {
return mPrototype; return mPrototype;
} }
void printProperties(Formatter& f) const; virtual void printProperties(Formatter& f);
}; };
Formatter& operator<<(Formatter& f, const JSObject& obj); Formatter& operator<<(Formatter& f, JSObject& obj);
/** /**
* Private representation of a JavaScript array. * Private representation of a JavaScript array.

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

@ -197,6 +197,14 @@ TypedRegister ICodeGenerator::newObject()
return dest; return dest;
} }
TypedRegister ICodeGenerator::newClass(const StringAtom &name)
{
TypedRegister dest(getRegister(), &Any_Type);
NewClass *instr = new NewClass(dest, &name);
iCode->push_back(instr);
return dest;
}
TypedRegister ICodeGenerator::newFunction(ICodeModule *icm) TypedRegister ICodeGenerator::newFunction(ICodeModule *icm)
{ {
TypedRegister dest(getRegister(), &Function_Type); TypedRegister dest(getRegister(), &Function_Type);
@ -632,8 +640,12 @@ TypedRegister ICodeGenerator::genExpr(ExprNode *p,
break; break;
case ExprNode::New: case ExprNode::New:
{ {
// FIXME - handle args, etc... InvokeExprNode *i = static_cast<InvokeExprNode *>(p);
ret = newObject(); if (i->op->getKind() == ExprNode::identifier) {
ret = newClass(static_cast<IdentifierExprNode *>(i->op)->name);
}
else
ret = newObject(); // XXX more
} }
break; break;
case ExprNode::call : case ExprNode::call :
@ -934,7 +946,7 @@ TypedRegister ICodeGenerator::genExpr(ExprNode *p,
if (b->op1->getKind() == ExprNode::dot) { if (b->op1->getKind() == ExprNode::dot) {
BinaryExprNode *lb = static_cast<BinaryExprNode *>(b->op1); BinaryExprNode *lb = static_cast<BinaryExprNode *>(b->op1);
TypedRegister base = genExpr(lb->op1); TypedRegister base = genExpr(lb->op1);
const StringAtom &name = static_cast<IdentifierExprNode *>(b->op2)->name; const StringAtom &name = static_cast<IdentifierExprNode *>(lb->op2)->name;
uint32 slotIndex; uint32 slotIndex;
if (isSlotName(base.second, name, slotIndex)) if (isSlotName(base.second, name, slotIndex))
setSlot(base, slotIndex, ret); setSlot(base, slotIndex, ret);

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

@ -238,6 +238,7 @@ namespace ICG {
TypedRegister newObject(); TypedRegister newObject();
TypedRegister newArray(); TypedRegister newArray();
TypedRegister newFunction(ICodeModule *icm); TypedRegister newFunction(ICodeModule *icm);
TypedRegister newClass(const StringAtom &name);
TypedRegister loadName(const StringAtom &name); TypedRegister loadName(const StringAtom &name);
void saveName(const StringAtom &name, TypedRegister value); void saveName(const StringAtom &name, TypedRegister value);

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

@ -56,6 +56,7 @@ namespace Interpreter {
using namespace ICG; using namespace ICG;
using namespace JSTypes; using namespace JSTypes;
using namespace JSClasses;
// These classes are private to the JS interpreter. // These classes are private to the JS interpreter.
@ -709,6 +710,28 @@ using JSString throughout.
} }
break; break;
case GET_SLOT:
{
GetSlot* gs = static_cast<GetSlot*>(instruction);
JSValue& value = (*registers)[src1(gs).first];
if (value.isObject()) {
JSInstance* inst = static_cast<JSInstance *>(value.object);
(*registers)[dst(gs).first] = (*inst)[src2(gs)];
}
// XXX runtime error
}
break;
case SET_SLOT:
{
SetSlot* ss = static_cast<SetSlot*>(instruction);
JSValue& value = (*registers)[dst(ss).first];
if (value.isObject()) {
JSInstance* inst = static_cast<JSInstance *>(value.object);
(*inst)[src1(ss)] = (*registers)[src2(ss).first];
}
}
break;
case LOAD_IMMEDIATE: case LOAD_IMMEDIATE:
{ {
LoadImmediate* li = static_cast<LoadImmediate*>(instruction); LoadImmediate* li = static_cast<LoadImmediate*>(instruction);
@ -822,6 +845,19 @@ using JSString throughout.
} }
break; break;
case SLOT_XCR:
{
SlotXcr *sx = static_cast<SlotXcr*>(instruction);
JSValue& dest = (*registers)[dst(sx).first];
JSValue& base = (*registers)[src1(sx).first];
JSInstance *inst = static_cast<JSInstance*>(base.object);
JSValue r = (*inst)[src2(sx)].toNumber();
dest = r;
r.f64 += val4(sx);
(*inst)[src2(sx)] = r;
}
break;
case NAME_XCR: case NAME_XCR:
{ {
NameXcr *nx = static_cast<NameXcr*>(instruction); NameXcr *nx = static_cast<NameXcr*>(instruction);

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

@ -104,6 +104,11 @@ namespace JSClasses {
return mSlots[name]; return mSlots[name];
} }
JSSlots& getSlots()
{
return mSlots;
}
bool hasSlot(const String& name) bool hasSlot(const String& name)
{ {
return (mSlots.count(name) != 0); return (mSlots.count(name) != 0);
@ -142,6 +147,18 @@ namespace JSClasses {
{ {
return mSlots[index]; return mSlots[index];
} }
virtual void printProperties(Formatter& f)
{
JSObject::printProperties(f);
JSClass *thisClass = getClass();
JSSlots &slots = thisClass->getSlots();
f << "Slots:\n";
for (JSSlots::iterator i = slots.begin(), end = slots.end(); i != end; ++i) {
f << i->first << " : " << mSlots[i->second.mIndex] << "\n";
}
}
}; };
} /* namespace JSClasses */ } /* namespace JSClasses */

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

@ -32,6 +32,7 @@
*/ */
#include "jstypes.h" #include "jstypes.h"
#include "jsclasses.h"
#include "numerics.h" #include "numerics.h"
#include "icodegenerator.h" #include "icodegenerator.h"
@ -155,13 +156,13 @@ int JSValue::operator==(const JSValue& value) const
return 0; return 0;
} }
Formatter& operator<<(Formatter& f, const JSObject& obj) Formatter& operator<<(Formatter& f, JSObject& obj)
{ {
obj.printProperties(f); obj.printProperties(f);
return f; return f;
} }
void JSObject::printProperties(Formatter& f) const void JSObject::printProperties(Formatter& f)
{ {
for (JSProperties::const_iterator i = mProperties.begin(); i != mProperties.end(); i++) { for (JSProperties::const_iterator i = mProperties.begin(); i != mProperties.end(); i++) {
f << (*i).first << " : " << (*i).second; f << (*i).first << " : " << (*i).second;
@ -184,6 +185,7 @@ Formatter& operator<<(Formatter& f, const JSValue& value)
break; break;
case JSValue::object_tag: case JSValue::object_tag:
{ {
printFormat(f, "Object @ 0x%08X\n", value.object); printFormat(f, "Object @ 0x%08X\n", value.object);
f << *value.object; f << *value.object;
} }

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

@ -253,10 +253,10 @@ namespace JSTypes {
return mPrototype; return mPrototype;
} }
void printProperties(Formatter& f) const; virtual void printProperties(Formatter& f);
}; };
Formatter& operator<<(Formatter& f, const JSObject& obj); Formatter& operator<<(Formatter& f, JSObject& obj);
/** /**
* Private representation of a JavaScript array. * Private representation of a JavaScript array.

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

@ -22,8 +22,8 @@
// JS2 shell. // JS2 shell.
// //
#if 0 #if 1
#define DEBUGGER_FOO //#define DEBUGGER_FOO
#define INTERPRET_INPUT #define INTERPRET_INPUT
#else #else
#undef DEBUGGER_FOO #undef DEBUGGER_FOO