use of com.github.anba.es6draft.runtime.modules.ExportEntry in project es6draft by anba.
the class ModuleDeclarationInstantiationGenerator method generate.
private void generate(Module module, SourceTextModuleRecord moduleRecord, ModuleDeclInitVisitor mv) {
Variable<ExecutionContext> context = mv.getExecutionContext();
Variable<SourceTextModuleRecord> moduleRec = mv.getModule();
Variable<LexicalEnvironment<ModuleEnvironmentRecord>> env = mv.getModuleEnvironment();
Variable<ModuleEnvironmentRecord> envRec = mv.newVariable("envRec", ModuleEnvironmentRecord.class);
getEnvironmentRecord(env, envRec, mv);
Variable<ResolvedBinding> resolved = mv.newVariable("resolved", ResolvedBinding.class);
Variable<ScriptObject> namespace = null;
Variable<FunctionObject> fo = null;
Variable<Undefined> undef = mv.newVariable("undef", Undefined.class);
mv.loadUndefined();
mv.store(undef);
/* step 1 */
for (ExportEntry exportEntry : moduleRecord.getIndirectExportEntries()) {
mv.lineInfo(exportEntry.getLine());
mv.load(moduleRec);
mv.aconst(exportEntry.getExportName());
mv.invoke(Methods.ModuleOperations_resolveExportOrThrow);
}
/* step 8 */
for (ImportEntry importEntry : moduleRecord.getImportEntries()) {
mv.lineInfo(importEntry.getLine());
if (importEntry.isStarImport()) {
Name localName = new Name(importEntry.getLocalName());
BindingOp<ModuleEnvironmentRecord> op = BindingOp.of(envRec, localName);
op.createImmutableBinding(envRec, localName, true, mv);
mv.load(context);
mv.load(moduleRec);
mv.aconst(importEntry.getModuleRequest());
mv.invoke(Methods.ModuleOperations_getModuleNamespace);
if (namespace == null) {
namespace = mv.newVariable("namespace", ScriptObject.class);
}
mv.store(namespace);
op.initializeBinding(envRec, localName, namespace, mv);
} else {
mv.load(moduleRec);
mv.aconst(importEntry.getModuleRequest());
mv.aconst(importEntry.getImportName());
mv.invoke(Methods.ModuleOperations_resolveImportOrThrow);
mv.store(resolved);
/* step 8.d.iii */
createImportBinding(context, envRec, importEntry.getLocalName(), resolved, mv);
}
}
/* step 9 (not applicable) */
/* step 10 */
List<StatementListItem> varDeclarations = VarScopedDeclarations(module);
/* step 11 */
HashSet<Name> declaredVarNames = new HashSet<>();
/* step 12 */
for (StatementListItem d : varDeclarations) {
assert d instanceof VariableStatement;
for (Name dn : BoundNames((VariableStatement) d)) {
if (declaredVarNames.add(dn)) {
BindingOp<ModuleEnvironmentRecord> op = BindingOp.of(envRec, dn);
op.createMutableBinding(envRec, dn, false, mv);
op.initializeBinding(envRec, dn, undef, mv);
}
}
}
/* step 13 */
List<Declaration> lexDeclarations = LexicallyScopedDeclarations(module);
/* step 14 */
for (Declaration d : lexDeclarations) {
for (Name dn : BoundNames(d)) {
BindingOp<ModuleEnvironmentRecord> op = BindingOp.of(envRec, dn);
if (d.isConstDeclaration()) {
op.createImmutableBinding(envRec, dn, true, mv);
} else {
op.createMutableBinding(envRec, dn, false, mv);
}
if (d instanceof HoistableDeclaration) {
InstantiateFunctionObject(context, env, d, mv);
if (fo == null) {
fo = mv.newVariable("fo", FunctionObject.class);
}
mv.store(fo);
op.initializeBinding(envRec, dn, fo, mv);
}
}
}
mv._return();
}
use of com.github.anba.es6draft.runtime.modules.ExportEntry in project es6draft by anba.
the class ModuleDeclarationInstantiationGenerator method generate.
private void generate(Module module, SourceTextModuleRecord moduleRecord, InstructionVisitor mv) {
Variable<ExecutionContext> context = mv.getParameter(EXECUTION_CONTEXT, ExecutionContext.class);
Variable<SourceTextModuleRecord> moduleRec = mv.getParameter(MODULE, SourceTextModuleRecord.class);
Variable<LexicalEnvironment<ModuleEnvironmentRecord>> env = mv.getParameter(MODULE_ENV, LexicalEnvironment.class).uncheckedCast();
Variable<ModuleEnvironmentRecord> envRec = mv.newVariable("envRec", ModuleEnvironmentRecord.class);
getEnvironmentRecord(env, envRec, mv);
Variable<ModuleExport> resolved = mv.newVariable("resolved", ModuleExport.class);
Variable<ScriptObject> namespace = null;
Variable<FunctionObject> fo = null;
Variable<Undefined> undef = mv.newVariable("undef", Undefined.class);
mv.loadUndefined();
mv.store(undef);
/* step 9 */
for (ExportEntry exportEntry : moduleRecord.getIndirectExportEntries()) {
mv.lineInfo(exportEntry.getLine());
mv.load(moduleRec);
mv.aconst(exportEntry.getExportName());
mv.invoke(Methods.ScriptRuntime_resolveExportOrThrow);
}
/* step 12 */
for (ImportEntry importEntry : moduleRecord.getImportEntries()) {
mv.lineInfo(importEntry.getLine());
if (importEntry.isStarImport()) {
Name localName = new Name(importEntry.getLocalName());
BindingOp<ModuleEnvironmentRecord> op = BindingOp.of(envRec, localName);
op.createImmutableBinding(envRec, localName, true, mv);
mv.load(context);
mv.load(moduleRec);
mv.aconst(importEntry.getModuleRequest());
mv.invoke(Methods.ScriptRuntime_getModuleNamespace);
if (namespace == null) {
namespace = mv.newVariable("namespace", ScriptObject.class);
}
mv.store(namespace);
op.initializeBinding(envRec, localName, namespace, mv);
} else {
mv.load(moduleRec);
mv.aconst(importEntry.getModuleRequest());
mv.aconst(importEntry.getImportName());
mv.invoke(Methods.ScriptRuntime_resolveImportOrThrow);
mv.store(resolved);
createImportBinding(context, envRec, importEntry.getLocalName(), resolved, mv);
}
}
/* step 13 */
List<StatementListItem> varDeclarations = VarScopedDeclarations(module);
HashSet<Name> declaredVarNames = new HashSet<>();
/* step 14 */
for (StatementListItem d : varDeclarations) {
assert d instanceof VariableStatement;
for (Name dn : BoundNames((VariableStatement) d)) {
if (declaredVarNames.add(dn)) {
BindingOp<ModuleEnvironmentRecord> op = BindingOp.of(envRec, dn);
op.createMutableBinding(envRec, dn, false, mv);
op.initializeBinding(envRec, dn, undef, mv);
}
}
}
/* step 15 */
List<Declaration> lexDeclarations = LexicallyScopedDeclarations(module);
/* step 16 */
for (Declaration d : lexDeclarations) {
for (Name dn : BoundNames(d)) {
BindingOp<ModuleEnvironmentRecord> op = BindingOp.of(envRec, dn);
if (d.isConstDeclaration()) {
op.createImmutableBinding(envRec, dn, true, mv);
} else {
op.createMutableBinding(envRec, dn, false, mv);
}
if (d instanceof HoistableDeclaration) {
InstantiateFunctionObject(context, env, d, mv);
if (fo == null) {
fo = mv.newVariable("fo", FunctionObject.class);
}
mv.store(fo);
op.initializeBinding(envRec, dn, fo, mv);
}
}
}
/* step 17 */
mv._return();
}
use of com.github.anba.es6draft.runtime.modules.ExportEntry in project es6draft by anba.
the class StaticSemantics method ExportEntries.
/**
* 15.2.1.7 Static Semantics: ExportEntries<br>
* 15.2.3.5 Static Semantics: ExportEntries
*
* @param node
* the module node
* @return the list of export entries
*/
public static List<ExportEntry> ExportEntries(Module node) {
ArrayList<ExportEntry> entries = new ArrayList<>();
for (ModuleItem item : node.getStatements()) {
if (item instanceof ExportDeclaration) {
ExportDeclaration exportDecl = (ExportDeclaration) item;
switch(exportDecl.getType()) {
case All:
{
String module = exportDecl.getModuleSpecifier();
entries.add(new ExportEntry(item, module, "*", null, null));
break;
}
case External:
{
String module = exportDecl.getModuleSpecifier();
ExportEntriesForModule(exportDecl.getExportClause(), module, entries);
break;
}
case Local:
ExportEntriesForModule(exportDecl.getExportClause(), null, entries);
break;
case Variable:
for (Name name : BoundNames(exportDecl.getVariableStatement())) {
String id = name.getIdentifier();
entries.add(new ExportEntry(item, null, null, id, id));
}
break;
case Declaration:
for (Name name : BoundNames(exportDecl.getDeclaration())) {
String id = name.getIdentifier();
entries.add(new ExportEntry(item, null, null, id, id));
}
break;
case DefaultHoistableDeclaration:
{
Name localName = BoundName(exportDecl.getHoistableDeclaration());
entries.add(new ExportEntry(item, null, null, localName.getIdentifier(), "default"));
break;
}
case DefaultClassDeclaration:
{
Name localName = BoundName(exportDecl.getClassDeclaration());
entries.add(new ExportEntry(item, null, null, localName.getIdentifier(), "default"));
break;
}
case DefaultExpression:
{
Name localName = BoundName(exportDecl.getExpression().getBinding());
entries.add(new ExportEntry(item, null, null, localName.getIdentifier(), "default"));
break;
}
default:
throw new AssertionError();
}
}
}
return entries;
}
use of com.github.anba.es6draft.runtime.modules.ExportEntry in project es6draft by anba.
the class StaticSemantics method ExportEntriesForModule.
/**
* 15.2.3.6 Static Semantics: ExportEntriesForModule
*
* @param node
* the exports clause node
* @param module
* the module name
* @param entries
* the list of export entries
*/
private static void ExportEntriesForModule(ExportClause node, String module, List<ExportEntry> entries) {
if (module == null) {
assert node.getDefaultEntry() == null;
assert node.getNameSpace() == null;
for (ExportSpecifier specifier : node.getExports()) {
String localName = specifier.getSourceName();
String importName = null;
String exportName = specifier.getExportName();
entries.add(new ExportEntry(specifier, module, importName, localName, exportName));
}
} else {
IdentifierName defaultEntry = node.getDefaultEntry();
if (defaultEntry != null) {
String exportName = defaultEntry.getName();
entries.add(new ExportEntry(defaultEntry, module, "default", null, exportName));
}
IdentifierName nameSpace = node.getNameSpace();
if (nameSpace != null) {
String exportName = nameSpace.getName();
entries.add(new ExportEntry(nameSpace, module, "*", null, exportName));
}
for (ExportSpecifier specifier : node.getExports()) {
String localName = null;
String importName = specifier.getSourceName();
String exportName = specifier.getExportName();
entries.add(new ExportEntry(specifier, module, importName, localName, exportName));
}
}
}
Aggregations