Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/org/rascalmpl/repl/rascal/RascalInterpreterREPL.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public ICommandOutput handleInput(String command) throws InterruptedException, P
changes.addAll(dirtyModules);
if (!changes.isEmpty()) {
dirtyModules.removeAll(changes);
eval.reloadModules(eval.getMonitor(), changes, URIUtil.rootLocation("reloader"));
eval.reloadModules(eval.getMonitor(), changes, URIUtil.rootLocation("prompt"));
}
return printer.outputResult(eval.eval(eval.getMonitor(), command, PROMPT_LOCATION));
}
Expand Down
27 changes: 17 additions & 10 deletions src/org/rascalmpl/semantics/dynamic/Import.java
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ public static ITree parseModuleAndFragments(char[] data, ISourceLocation locatio
ISet extend = Modules.getExtends(top);
eval.getMonitor().jobTodo(jobName, extend.size());
for (IValue mod : extend) {
evalImport(eval, (IConstructor) mod);
evalImport(eval, env, (IConstructor) mod);
eval.getMonitor().jobStep(jobName, "extending for " + name, 1);
if (eval.isInterrupted()) {
throw new InterruptException(eval.getStackTrace(), eval.getCurrentAST().getLocation());
Expand All @@ -503,7 +503,7 @@ public static ITree parseModuleAndFragments(char[] data, ISourceLocation locatio
ISet imports = Modules.getImports(top);
eval.getMonitor().jobTodo(jobName, imports.size());
for (IValue mod : imports) {
evalImport(eval, (IConstructor) mod);
evalImport(eval, env, (IConstructor) mod);
eval.getMonitor().jobStep(jobName, "importing for " + name, 1);
if (eval.isInterrupted()) {
throw new InterruptException(eval.getStackTrace(), eval.getCurrentAST().getLocation());
Expand All @@ -515,7 +515,7 @@ public static ITree parseModuleAndFragments(char[] data, ISourceLocation locatio
ISet externals = Modules.getExternals(top);
eval.getMonitor().jobTodo(jobName, externals.size());
for (IValue mod : externals) {
evalImport(eval, (IConstructor) mod);
evalImport(eval, env, (IConstructor) mod);
eval.getMonitor().jobStep(jobName, "external importing for " + name, 1);
if (eval.isInterrupted()) {
throw new InterruptException(eval.getStackTrace(), eval.getCurrentAST().getLocation());
Expand Down Expand Up @@ -575,28 +575,35 @@ private static void declareTypesWhichDoNotNeedImportedModulesAlready(IEvaluator<
eval.__getTypeDeclarator().evaluateDeclarations(decls, eval.getCurrentEnvt(), true);
}

public static void evalImport(IEvaluator<Result<IValue>> eval, IConstructor mod) {
/**
* Evaluate an import/extend statement in the current module environment, effectively implementing the semantics of import and extend,
* and handle any errors that may occur.
*
* NB. all errors that flow up to here are reported with the importing module because they make the import/extend unavailable here.
* Errors inside of those modules that do not impact this module directly, should have been reported earlier with the module in question, during {@link #loadModule()}.
* It is possible that the ModuleEnvironment for the imported/extended module does not even exist here anymore.
*/
public static void evalImport(IEvaluator<Result<IValue>> eval, ModuleEnvironment importer, IConstructor mod) {
org.rascalmpl.ast.Import imp = (org.rascalmpl.ast.Import) getBuilder().buildValue(mod);
String name = Names.fullName(imp.getModule().getName());

try {
imp.interpret(eval);
}
catch (Throw rascalException) {
catch (Throw rascalException) {
// when a global initializer throws a runtime exception
handleLoadError(eval.getHeap().getModule(name), rascalException.getMessage(), rascalException.getLocation(), rascalException.getTrace().toString());
handleLoadError(importer, rascalException.getMessage(), rascalException.getLocation(), rascalException.getTrace().toString());
}
catch (CyclicExtend | CyclicImportExtend e) {
// when we end up in a cycle which we can't implement
handleLoadError(eval.getHeap().getModule(name), e.getMessage(), e.getLocation(), "");
handleLoadError(importer, e.getMessage(), e.getLocation(), "");
}
catch (StaticError e) {
// all other static errors
handleLoadError(eval.getHeap().getModule(name), e.getMessage(), e.getLocation(), "");
handleLoadError(importer, e.getMessage(), e.getLocation(), "");
}
catch (Throwable e) {
// all internal implementation errors that mess up a module's loading
handleLoadError(eval.getHeap().getModule(name), e.getMessage(), imp.getLocation(),
handleLoadError(importer, e.getMessage(), imp.getLocation(),
Arrays.stream(e.getStackTrace())
.map(Object::toString)
.collect(Collectors.joining("\n")));
Expand Down
Loading