More namespaces and use statement. Fixed retval behaviour

This commit is contained in:
rogerl%netscape.com 2002-08-29 16:14:40 +00:00
parent bf7c000c87
commit 7df2968246
4 changed files with 24 additions and 15 deletions

View File

@ -125,13 +125,16 @@ float64 *JS2Engine::newDoubleValue(float64 x)
// if the argument can be stored as an integer value, do so // if the argument can be stored as an integer value, do so
// otherwise get a double value // otherwise get a double value
void JS2Engine::pushNumber(float64 x) js2val JS2Engine::pushNumber(float64 x)
{ {
uint32 i; uint32 i;
js2val retval;
if (JSDOUBLE_IS_INT(x, i) && INT_FITS_IN_JS2VAL(i)) if (JSDOUBLE_IS_INT(x, i) && INT_FITS_IN_JS2VAL(i))
push(INT_TO_JS2VAL(i)); retval = INT_TO_JS2VAL(i);
else else
push(DOUBLE_TO_JS2VAL(newDoubleValue(x))); retval = DOUBLE_TO_JS2VAL(newDoubleValue(x));
push(retval);
return retval;
} }
// Convert an integer to a string // Convert an integer to a string

View File

@ -82,7 +82,7 @@ public:
size_t errorPos(); size_t errorPos();
void pushNumber(float64 x); js2val pushNumber(float64 x);
#define MAX_EXEC_STACK (20) #define MAX_EXEC_STACK (20)

View File

@ -178,6 +178,18 @@ namespace MetaData {
break; break;
case StmtNode::Use: case StmtNode::Use:
{ {
UseStmtNode *u = checked_cast<UseStmtNode *>(p);
ExprList *eList = u->namespaces;
while (eList) {
js2val av = EvalExpression(env, CompilePhase, eList->expr);
if (JS2VAL_IS_NULL(av) || !JS2VAL_IS_OBJECT(av))
reportError(Exception::badValueError, "Namespace expected in use directive", p->pos);
JS2Object *obj = JS2VAL_TO_OBJECT(av);
if ((obj->kind != AttributeObjectKind) || (checked_cast<Attribute *>(obj)->attrKind != Attribute::NamespaceAttr))
reportError(Exception::badValueError, "Namespace expected in use directive", p->pos);
cxt->openNamespaces.push_back(checked_cast<Namespace *>(obj));
eList = eList->next;
}
} }
break; break;
} // switch (p->getKind()) } // switch (p->getKind())
@ -253,14 +265,6 @@ namespace MetaData {
break; break;
case StmtNode::Use: case StmtNode::Use:
{ {
UseStmtNode *u = checked_cast<UseStmtNode *>(p);
ExprList *eList = u->namespaces;
while (eList) {
Reference *r = EvalExprNode(env, phase, eList->expr);
if (r) r->emitReadBytecode(bCon, p->pos);
bCon->emitOp(eUse, p->pos);
eList = eList->next;
}
} }
break; break;
default: default:
@ -585,8 +589,8 @@ namespace MetaData {
{ {
BinaryExprNode *b = checked_cast<BinaryExprNode *>(p); BinaryExprNode *b = checked_cast<BinaryExprNode *>(p);
Reference *lVal = EvalExprNode(env, phase, b->op1); Reference *lVal = EvalExprNode(env, phase, b->op1);
Reference *rVal = EvalExprNode(env, phase, b->op2);
if (lVal) lVal->emitReadBytecode(bCon, p->pos); if (lVal) lVal->emitReadBytecode(bCon, p->pos);
Reference *rVal = EvalExprNode(env, phase, b->op2);
if (rVal) rVal->emitReadBytecode(bCon, p->pos); if (rVal) rVal->emitReadBytecode(bCon, p->pos);
bCon->emitOp(ePlus, p->pos); bCon->emitOp(ePlus, p->pos);
} }
@ -628,6 +632,7 @@ namespace MetaData {
{ {
IdentifierExprNode *i = checked_cast<IdentifierExprNode *>(p); IdentifierExprNode *i = checked_cast<IdentifierExprNode *>(p);
returnRef = new LexicalReference(i->name, cxt.strict); returnRef = new LexicalReference(i->name, cxt.strict);
((LexicalReference *)returnRef)->variableMultiname->addNamespace(cxt);
((LexicalReference *)returnRef)->emitBindBytecode(bCon, p->pos); ((LexicalReference *)returnRef)->emitBindBytecode(bCon, p->pos);
} }
break; break;

View File

@ -44,12 +44,13 @@
String *bstr = toString(b); String *bstr = toString(b);
String *c = new String(*astr); String *c = new String(*astr);
*c += *bstr; *c += *bstr;
push(STRING_TO_JS2VAL(c)); retval = STRING_TO_JS2VAL(c);
push(retval);
} }
else { else {
float64 anum = toNumber(a); float64 anum = toNumber(a);
float64 bnum = toNumber(b); float64 bnum = toNumber(b);
pushNumber(anum + bnum); retval = pushNumber(anum + bnum);
} }
} }
break; break;