зеркало из https://github.com/mozilla/pjs.git
Incremental fixes for Packages/Import/Use etc.
This commit is contained in:
Родитель
18d34111dd
Коммит
036d2c9f30
|
@ -368,6 +368,7 @@ ByteCodeData gByteCodeData[OpCodeCount] = {
|
||||||
{ -1, "Juxtapose", },
|
{ -1, "Juxtapose", },
|
||||||
{ -1, "NamedArgument", },
|
{ -1, "NamedArgument", },
|
||||||
{ -1, "Use", },
|
{ -1, "Use", },
|
||||||
|
{ 0, "UseOnceOp", },
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1389,13 +1390,30 @@ bool ByteCodeGen::genCodeForStatement(StmtNode *p, ByteCodeGen *static_cg, uint3
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case StmtNode::Package:
|
|
||||||
case StmtNode::Import:
|
|
||||||
case StmtNode::Namespace:
|
case StmtNode::Namespace:
|
||||||
{
|
{
|
||||||
// do anything at bytecodegen?
|
// do anything at bytecodegen?
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case StmtNode::Package:
|
||||||
|
{
|
||||||
|
PackageStmtNode *ps = checked_cast<PackageStmtNode *>(p);
|
||||||
|
mScopeChain->addScope(ps->scope);
|
||||||
|
genCodeForStatement(ps->body, static_cg, finallyLabel);
|
||||||
|
mScopeChain->popScope();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case StmtNode::Import:
|
||||||
|
{
|
||||||
|
ImportStmtNode *i = checked_cast<ImportStmtNode *>(p);
|
||||||
|
ExprList *namespaces = i->namespaces;
|
||||||
|
while (namespaces) {
|
||||||
|
genExpr(namespaces->expr);
|
||||||
|
addOp(UseOp);
|
||||||
|
namespaces = namespaces->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
NOT_REACHED("Not Implemented Yet");
|
NOT_REACHED("Not Implemented Yet");
|
||||||
}
|
}
|
||||||
|
@ -2063,6 +2081,7 @@ BinaryOpEquals:
|
||||||
delete ref;
|
delete ref;
|
||||||
return Object_Type;
|
return Object_Type;
|
||||||
}
|
}
|
||||||
|
case ExprNode::qualify:
|
||||||
case ExprNode::identifier:
|
case ExprNode::identifier:
|
||||||
{
|
{
|
||||||
Reference *ref = genReference(p, Read);
|
Reference *ref = genReference(p, Read);
|
||||||
|
|
|
@ -157,7 +157,7 @@ typedef enum {
|
||||||
JuxtaposeOp, // <attribute> <attribute> --> <attribute>
|
JuxtaposeOp, // <attribute> <attribute> --> <attribute>
|
||||||
NamedArgOp, // <object> <string> --> <named arg object>
|
NamedArgOp, // <object> <string> --> <named arg object>
|
||||||
UseOp, // <object> -->
|
UseOp, // <object> -->
|
||||||
UseOnceOp, // <object> -->
|
UseOnceOp, // <pool ref>
|
||||||
|
|
||||||
OpCodeCount
|
OpCodeCount
|
||||||
|
|
||||||
|
|
|
@ -1246,33 +1246,44 @@ void ScopeChain::collectNames(StmtNode *p)
|
||||||
break;
|
break;
|
||||||
case StmtNode::Import:
|
case StmtNode::Import:
|
||||||
{
|
{
|
||||||
// if loaded already - just skip.
|
|
||||||
ImportStmtNode *i = checked_cast<ImportStmtNode *>(p);
|
ImportStmtNode *i = checked_cast<ImportStmtNode *>(p);
|
||||||
String packagePath;
|
String packageName;
|
||||||
if (i->packageIdList) {
|
if (i->packageIdList)
|
||||||
packagePath = getPackageName(i->packageIdList);
|
packageName = getPackageName(i->packageIdList);
|
||||||
if (!m_cx->checkForPackage(packagePath)) {
|
else
|
||||||
m_cx->loadPackage(packagePath, packagePath + ".js");
|
packageName = *i->packageString;
|
||||||
|
|
||||||
JSValue packageValue = getCompileTimeValue(packagePath, NULL);
|
if (!m_cx->checkForPackage(packageName))
|
||||||
|
m_cx->loadPackage(packageName, packageName + ".js");
|
||||||
|
|
||||||
|
JSValue packageValue = getCompileTimeValue(packageName, NULL);
|
||||||
ASSERT(packageValue.isObject() && (packageValue.object->mType == Package_Type));
|
ASSERT(packageValue.isObject() && (packageValue.object->mType == Package_Type));
|
||||||
Package *package = checked_cast<Package *>(packageValue.object);
|
Package *package = checked_cast<Package *>(packageValue.object);
|
||||||
|
|
||||||
for (PropertyIterator it = package->mProperties.begin(), end = package->mProperties.end();
|
if (i->varName)
|
||||||
(it != end); it++) {
|
defineVariable(m_cx, *i->varName, NULL, Package_Type, JSValue(package));
|
||||||
|
|
||||||
|
for (PropertyIterator it = package->mProperties.begin(), end = package->mProperties.end();
|
||||||
|
(it != end); it++)
|
||||||
|
{
|
||||||
ASSERT(PROPERTY_KIND(it) == ValuePointer);
|
ASSERT(PROPERTY_KIND(it) == ValuePointer);
|
||||||
|
bool makeAlias = true;
|
||||||
|
if (i->includeExclude) {
|
||||||
|
makeAlias = !i->exclude;
|
||||||
|
IdentifierList *idList = i->includeExclude;
|
||||||
|
while (idList) {
|
||||||
|
if (idList->name.compare(PROPERTY_NAME(it)) == 0) {
|
||||||
|
makeAlias = !makeAlias;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
idList = idList->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (makeAlias)
|
||||||
defineAlias(m_cx, PROPERTY_NAME(it), PROPERTY_NAMESPACELIST(it), PROPERTY_ATTR(it), PROPERTY_TYPE(it), PROPERTY_VALUEPOINTER(it));
|
defineAlias(m_cx, PROPERTY_NAME(it), PROPERTY_NAMESPACELIST(it), PROPERTY_ATTR(it), PROPERTY_TYPE(it), PROPERTY_VALUEPOINTER(it));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
packagePath = *i->packageString + ".js";
|
|
||||||
if (!m_cx->checkForPackage(*i->packageString)) {
|
|
||||||
m_cx->loadPackage(*i->packageString, packagePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case StmtNode::Namespace:
|
case StmtNode::Namespace:
|
||||||
|
@ -1289,7 +1300,7 @@ void ScopeChain::collectNames(StmtNode *p)
|
||||||
String packageName = getPackageName(ps->packageIdList);
|
String packageName = getPackageName(ps->packageIdList);
|
||||||
Package *package = new Package(packageName);
|
Package *package = new Package(packageName);
|
||||||
ps->scope = package;
|
ps->scope = package;
|
||||||
m_cx->getGlobalObject()->defineVariable(m_cx, packageName, (NamespaceList *)(NULL), Property::NoAttribute, Package_Type, JSValue(package));
|
defineVariable(m_cx, packageName, NULL, Package_Type, JSValue(package));
|
||||||
m_cx->mPackages.push_back(package);
|
m_cx->mPackages.push_back(package);
|
||||||
|
|
||||||
addScope(ps->scope);
|
addScope(ps->scope);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче