Fixes for InstanceMethod dispatch and InstanceVariable references.

This commit is contained in:
rogerl%netscape.com 2003-04-21 06:16:38 +00:00
parent a06072c2a3
commit 301a40424c
3 changed files with 67 additions and 2 deletions

View File

@ -255,6 +255,32 @@ void printLocalBindings(LocalBindingMap *lMap)
}
}
void printInstanceVariables(JS2Class *c, Slot *slots)
{
if (c->super)
printInstanceVariables(c->super, slots);
for (InstanceBindingIterator rib = c->instanceBindings.begin(), riend = c->instanceBindings.end(); (rib != riend); rib++) {
InstanceBindingEntry *ibe = *rib;
for (InstanceBindingEntry::NS_Iterator i = ibe->begin(), end = ibe->end(); (i != end); i++) {
InstanceBindingEntry::NamespaceBinding ns = *i;
if (ns.second->content->memberKind == Member::InstanceVariableMember) {
stdOut << "\t" << *(ns.first->name) << "::" << ibe->name;
if (ns.second->accesses & ReadAccess)
if (ns.second->accesses & WriteAccess)
stdOut << " [read/write] ";
else
stdOut << " [read-only] ";
else
stdOut << " [write-only] ";
InstanceVariable *iv = checked_cast<InstanceVariable *>(ns.second->content);
stdOut << *metadata->toString(slots[iv->slotIndex].value);
}
}
}
stdOut << "\n";
}
js2val dump(JS2Metadata *meta, const js2val /* thisValue */, js2val argv[], uint32 argc)
{
if (argc) {
@ -278,6 +304,8 @@ js2val dump(JS2Metadata *meta, const js2val /* thisValue */, js2val argv[], uint
stdOut << ((s->sealed) ? "sealed " : "not-sealed ") << '\n';
stdOut << "type = " << *s->type->getName() << '\n';
printLocalBindings(&s->localBindings);
stdOut << " Instance Bindings:\n";
printInstanceVariables(s->type, s->slots);
if (meta->objectType(argv[0]) == meta->functionClass) {
FunctionWrapper *fWrap;
fWrap = (checked_cast<SimpleInstance *>(fObj))->fWrap;
@ -335,6 +363,8 @@ js2val dump(JS2Metadata *meta, const js2val /* thisValue */, js2val argv[], uint
break;
}
}
else
stdOut << *metadata->toString(argv[0]);
}
return JS2VAL_UNDEFINED;
}

View File

@ -1206,6 +1206,12 @@ namespace MetaData {
t = objectClass;
}
v->type = t;
if (vb->initializer) {
js2val newValue = EvalExpression(env, CompilePhase, vb->initializer);
v->defaultValue = t->implicitCoerce(this, newValue);
}
else
v->defaultValue = t->defaultValue;
}
}
else { // HoistedVariable
@ -3779,6 +3785,14 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now...
*rval = s->value;
return true;
}
case Member::InstanceMethodMember:
{
InstanceMethod *im = checked_cast<InstanceMethod *>(m);
if (phase == CompilePhase)
reportError(Exception::compileExpressionError, "Inappropriate compile time expression", engine->errorPos());
*rval = OBJECT_TO_JS2VAL(new MethodClosure(containerVal, im));
return true;
}
default:
ASSERT(false);
}
@ -4260,6 +4274,23 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now...
************************************************************************************/
void SimpleInstance::initializeSlots(JS2Class *type)
{
if (type->super)
initializeSlots(type->super);
for (InstanceBindingIterator rib = type->instanceBindings.begin(), riend = type->instanceBindings.end(); (rib != riend); rib++) {
InstanceBindingEntry *ibe = *rib;
for (InstanceBindingEntry::NS_Iterator i = ibe->begin(), end = ibe->end(); (i != end); i++) {
InstanceBindingEntry::NamespaceBinding ns = *i;
InstanceMember *im = ns.second->content;
if (im->memberKind == Member::InstanceVariableMember) {
InstanceVariable *iv = checked_cast<InstanceVariable *>(im);
slots[iv->slotIndex].value = iv->defaultValue;
}
}
}
}
// Construct a Simple instance of a class. Set the
// initial value of all slots to uninitialized.
SimpleInstance::SimpleInstance(JS2Metadata *meta, js2val parent, JS2Class *type)
@ -4273,6 +4304,7 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now...
for (uint32 i = 0; i < type->slotCount; i++) {
slots[i].value = JS2VAL_UNINITIALIZED;
}
initializeSlots(type);
}
// gc-mark all contained JS2Objects and visit contained structures to do likewise

View File

@ -536,9 +536,10 @@ public:
class InstanceVariable : public InstanceMember {
public:
InstanceVariable(Multiname *multiname, JS2Class *type, bool immutable, bool final, bool enumerable, uint32 slotIndex)
: InstanceMember(InstanceVariableMember, multiname, final, enumerable), type(type), immutable(immutable), slotIndex(slotIndex) { }
Invokable *evalInitialValue; // A function that computes this variable's initial value
: InstanceMember(InstanceVariableMember, multiname, final, enumerable),
type(type), defaultValue(JS2VAL_UNDEFINED), immutable(immutable), slotIndex(slotIndex) { }
JS2Class *type; // Type of values that may be stored in this variable
js2val defaultValue; // This variable's default value, if provided
bool immutable; // true if this variable's value may not be changed once set
uint32 slotIndex; // The index into an instance's slot array in which this variable is stored
@ -819,6 +820,8 @@ public:
FunctionWrapper *fWrap;
void initializeSlots(JS2Class *type);
virtual void markChildren();
virtual ~SimpleInstance();
};