зеркало из 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", },
|
||||
{ -1, "Juxtapose", },
|
||||
{ -1, "NamedArgument", },
|
||||
{ -1, "Use", },
|
||||
{ -1, "Use", },
|
||||
{ 0, "UseOnceOp", },
|
||||
|
||||
};
|
||||
|
||||
|
@ -1389,13 +1390,30 @@ bool ByteCodeGen::genCodeForStatement(StmtNode *p, ByteCodeGen *static_cg, uint3
|
|||
|
||||
}
|
||||
break;
|
||||
case StmtNode::Package:
|
||||
case StmtNode::Import:
|
||||
case StmtNode::Namespace:
|
||||
{
|
||||
// do anything at bytecodegen?
|
||||
}
|
||||
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:
|
||||
NOT_REACHED("Not Implemented Yet");
|
||||
}
|
||||
|
@ -2063,14 +2081,15 @@ BinaryOpEquals:
|
|||
delete ref;
|
||||
return Object_Type;
|
||||
}
|
||||
case ExprNode::identifier:
|
||||
{
|
||||
Reference *ref = genReference(p, Read);
|
||||
ref->emitCodeSequence(this);
|
||||
JSType *type = ref->mType;
|
||||
delete ref;
|
||||
return type;
|
||||
}
|
||||
case ExprNode::qualify:
|
||||
case ExprNode::identifier:
|
||||
{
|
||||
Reference *ref = genReference(p, Read);
|
||||
ref->emitCodeSequence(this);
|
||||
JSType *type = ref->mType;
|
||||
delete ref;
|
||||
return type;
|
||||
}
|
||||
case ExprNode::This:
|
||||
{
|
||||
JSFunction *f = mScopeChain->getContainerFunction();
|
||||
|
|
|
@ -157,7 +157,7 @@ typedef enum {
|
|||
JuxtaposeOp, // <attribute> <attribute> --> <attribute>
|
||||
NamedArgOp, // <object> <string> --> <named arg object>
|
||||
UseOp, // <object> -->
|
||||
UseOnceOp, // <object> -->
|
||||
UseOnceOp, // <pool ref>
|
||||
|
||||
OpCodeCount
|
||||
|
||||
|
|
|
@ -1246,33 +1246,44 @@ void ScopeChain::collectNames(StmtNode *p)
|
|||
break;
|
||||
case StmtNode::Import:
|
||||
{
|
||||
// if loaded already - just skip.
|
||||
ImportStmtNode *i = checked_cast<ImportStmtNode *>(p);
|
||||
String packagePath;
|
||||
if (i->packageIdList) {
|
||||
packagePath = getPackageName(i->packageIdList);
|
||||
if (!m_cx->checkForPackage(packagePath)) {
|
||||
m_cx->loadPackage(packagePath, packagePath + ".js");
|
||||
String packageName;
|
||||
if (i->packageIdList)
|
||||
packageName = getPackageName(i->packageIdList);
|
||||
else
|
||||
packageName = *i->packageString;
|
||||
|
||||
JSValue packageValue = getCompileTimeValue(packagePath, NULL);
|
||||
ASSERT(packageValue.isObject() && (packageValue.object->mType == Package_Type));
|
||||
Package *package = checked_cast<Package *>(packageValue.object);
|
||||
|
||||
for (PropertyIterator it = package->mProperties.begin(), end = package->mProperties.end();
|
||||
(it != end); it++) {
|
||||
|
||||
ASSERT(PROPERTY_KIND(it) == ValuePointer);
|
||||
defineAlias(m_cx, PROPERTY_NAME(it), PROPERTY_NAMESPACELIST(it), PROPERTY_ATTR(it), PROPERTY_TYPE(it), PROPERTY_VALUEPOINTER(it));
|
||||
if (!m_cx->checkForPackage(packageName))
|
||||
m_cx->loadPackage(packageName, packageName + ".js");
|
||||
|
||||
JSValue packageValue = getCompileTimeValue(packageName, NULL);
|
||||
ASSERT(packageValue.isObject() && (packageValue.object->mType == Package_Type));
|
||||
Package *package = checked_cast<Package *>(packageValue.object);
|
||||
|
||||
if (i->varName)
|
||||
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;
|
||||
case StmtNode::Namespace:
|
||||
|
@ -1289,7 +1300,7 @@ void ScopeChain::collectNames(StmtNode *p)
|
|||
String packageName = getPackageName(ps->packageIdList);
|
||||
Package *package = new Package(packageName);
|
||||
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);
|
||||
|
||||
addScope(ps->scope);
|
||||
|
|
Загрузка…
Ссылка в новой задаче