import org.simantics.scl.compiler.internal.codegen.writer.ExternalConstant;
import org.simantics.scl.compiler.internal.codegen.writer.ModuleWriter;
import org.simantics.scl.compiler.internal.elaboration.decomposed.DecomposedExpression;
-import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
import org.simantics.scl.compiler.internal.interpreted.IExpression;
import org.simantics.scl.compiler.internal.parsing.exceptions.SCLSyntaxErrorException;
import org.simantics.scl.compiler.internal.parsing.parser.SCLBlockParser;
import org.simantics.scl.compiler.internal.parsing.parser.SCLParserImpl;
import org.simantics.scl.compiler.internal.parsing.parser.SCLParserOptions;
+import org.simantics.scl.compiler.internal.parsing.utils.LineLocators;
import org.simantics.scl.compiler.runtime.MutableClassLoader;
import org.simantics.scl.compiler.runtime.RuntimeEnvironment;
import org.simantics.scl.compiler.types.TVar;
// Parse expression
if(expressionText != null) {
+ compilationContext.lineLocator = LineLocators.createLineLocator(expressionText);
try {
switch(parseMode) {
case BLOCK: {
throw new SCLExpressionCompilationException(errorLog.getErrors());
}
}
+ else
+ compilationContext.lineLocator = LineLocators.DUMMY_LOCATOR;
// Store local variables
ArrayList<Type> lvTypes = new ArrayList<Type>();
// Elaboration
{
- TranslationContext context = new TranslationContext(compilationContext, localEnvironment);
+ TranslationContext context = new TranslationContext(compilationContext, localEnvironment, "expression");
expression = expression.resolve(context);
if(!errorLog.hasNoErrors())
throw new SCLExpressionCompilationException(errorLog.getErrors());
if(!errorLog.hasNoErrors())
throw new SCLExpressionCompilationException(errorLog.getErrors());
if(decorateExpression && Types.canonical(expectedEffect) != Types.NO_EFFECTS) {
- ExpressionDecorator decorator =
+ ToplevelEffectDecorator decorator =
new ToplevelEffectDecorator(errorLog, environment);
- expression = expression.decorate(decorator);
+ expression = expression.accept(decorator);
}
expression = context.solveConstraints(environment, expression);
expressionType = expression.getType();
}
// Convert to SSA
- ModuleWriter mw = new ModuleWriter(namingPolicy.getModuleClassName());
+ ModuleWriter mw = new ModuleWriter(namingPolicy.getModuleClassName(), compilationContext.lineLocator);
DecomposedExpression decomposed =
- DecomposedExpression.decompose(expression);
+ DecomposedExpression.decompose(errorLog, expression);
SCLConstant constant = new SCLConstant(
Name.create(moduleName, COMPUTATION_METHOD_NAME),
IVal[] parameterVals = w.getParameters();
for(int i=0;i<decomposed.parameters.length;++i)
decomposed.parameters[i].setVal(parameterVals[i]);
- w.return_(decomposed.body.toVal(environment, w));
+ w.return_(decomposed.body.location, decomposed.body.toVal(compilationContext, w));
} catch(RuntimeException e) {
errorLog.setExceptionPosition(expression.location);
+ errorLog.log(e);
throw new SCLExpressionCompilationException(errorLog.getErrors());
}
throw new SCLExpressionCompilationException(errorLog.getErrors());
}
Map<String, byte[]> classes = moduleBuilder.getClasses();
+ ssaModule.cleanup();
// Load generated code and execute
try {