зеркало из https://github.com/mozilla/pjs.git
Incremental fixes for Packages/Import/Use etc.
This commit is contained in:
Родитель
18d34111dd
Коммит
036d2c9f30
|
@ -367,7 +367,8 @@ ByteCodeData gByteCodeData[OpCodeCount] = {
|
||||||
{ 0, "NewClosure", },
|
{ 0, "NewClosure", },
|
||||||
{ -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,14 +2081,15 @@ BinaryOpEquals:
|
||||||
delete ref;
|
delete ref;
|
||||||
return Object_Type;
|
return Object_Type;
|
||||||
}
|
}
|
||||||
case ExprNode::identifier:
|
case ExprNode::qualify:
|
||||||
{
|
case ExprNode::identifier:
|
||||||
Reference *ref = genReference(p, Read);
|
{
|
||||||
ref->emitCodeSequence(this);
|
Reference *ref = genReference(p, Read);
|
||||||
JSType *type = ref->mType;
|
ref->emitCodeSequence(this);
|
||||||
delete ref;
|
JSType *type = ref->mType;
|
||||||
return type;
|
delete ref;
|
||||||
}
|
return type;
|
||||||
|
}
|
||||||
case ExprNode::This:
|
case ExprNode::This:
|
||||||
{
|
{
|
||||||
JSFunction *f = mScopeChain->getContainerFunction();
|
JSFunction *f = mScopeChain->getContainerFunction();
|
||||||
|
|
|
@ -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))
|
||||||
ASSERT(packageValue.isObject() && (packageValue.object->mType == Package_Type));
|
m_cx->loadPackage(packageName, packageName + ".js");
|
||||||
Package *package = checked_cast<Package *>(packageValue.object);
|
|
||||||
|
JSValue packageValue = getCompileTimeValue(packageName, NULL);
|
||||||
for (PropertyIterator it = package->mProperties.begin(), end = package->mProperties.end();
|
ASSERT(packageValue.isObject() && (packageValue.object->mType == Package_Type));
|
||||||
(it != end); it++) {
|
Package *package = checked_cast<Package *>(packageValue.object);
|
||||||
|
|
||||||
ASSERT(PROPERTY_KIND(it) == ValuePointer);
|
if (i->varName)
|
||||||
defineAlias(m_cx, PROPERTY_NAME(it), PROPERTY_NAMESPACELIST(it), PROPERTY_ATTR(it), PROPERTY_TYPE(it), PROPERTY_VALUEPOINTER(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);
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
packagePath = *i->packageString + ".js";
|
|
||||||
if (!m_cx->checkForPackage(*i->packageString)) {
|
|
||||||
m_cx->loadPackage(*i->packageString, packagePath);
|
|
||||||
}
|
}
|
||||||
|
if (makeAlias)
|
||||||
|
defineAlias(m_cx, PROPERTY_NAME(it), PROPERTY_NAMESPACELIST(it), PROPERTY_ATTR(it), PROPERTY_TYPE(it), PROPERTY_VALUEPOINTER(it));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче