}
public void typeCheck() {
- ce = new ConstraintEnvironment(environment);
+ ce = new ConstraintEnvironment(compilationContext);
scheduler = new TypeCheckingScheduler(compilationContext);
typeCheckValues();
public Expression solveConstraints(Environment environment, Expression expression) {
ArrayList<EVariable> constraintDemand = getConstraintDemand();
if(!constraintDemand.isEmpty()) {
- ConstraintEnvironment ce = new ConstraintEnvironment(environment);
+ ConstraintEnvironment ce = new ConstraintEnvironment(compilationContext);
ReducedConstraints red = ConstraintSolver.solve(
ce, new ArrayList<TPred>(0), constraintDemand,
true);
// Try to find constant evidence and prefer that
// to subclass
{
- Reduction reduction = environment.reduce(constraint);
+ Reduction reduction = environment.reduce(demandLocation, constraint);
if(reduction != null && reduction.demands.length == 0) {
generator = reduction.generator;
generatorParameters = reduction.parameters;
import java.util.ArrayList;
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
+import org.simantics.scl.compiler.compilation.CompilationContext;
import org.simantics.scl.compiler.constants.ClassConstant;
import org.simantics.scl.compiler.constants.StringConstant;
import org.simantics.scl.compiler.elaboration.expressions.EApply;
import gnu.trove.map.hash.THashMap;
public class ConstraintEnvironment {
+ CompilationContext compilationContext;
Environment environment;
- public ConstraintEnvironment(Environment environment) {
- this.environment = environment;
+ public ConstraintEnvironment(CompilationContext compilationContext) {
+ this.compilationContext = compilationContext;
+ this.environment = compilationContext.environment;
}
public Superconstraint[] getSuperconstraints(TPred constraint) {
return result;
}
- public Reduction reduce(TPred constraint) {
+ public Reduction reduce(long location, TPred constraint) {
// VecComp
if(constraint.typeClass == Types.VEC_COMP) {
Type parameter = Types.canonical(constraint.parameters[0]);
if(reductions.size() == 1)
return reductions.get(0);
else if(reductions.size() > 1) {
- throw new InternalCompilerError("Found more than one matching instances for " + constraint.typeClass + ".");
+ StringBuilder b = new StringBuilder();
+ b.append("Found more than one matching instances for ").append(constraint.typeClass).append(": ");
+ boolean first = true;
+ for(Reduction reduction : reductions) {
+ if(first)
+ first = false;
+ else
+ b.append(", ");
+ b.append(reduction.generator);
+ }
+ compilationContext.errorLog.log(location, b.toString());
}
return null;
}
unsolved = new THashSet<Constraint>();
for(Constraint c : temp) {
if(c.state == Constraint.STATE_UNSOLVED) {
- Reduction reduction = environment.reduce(c.constraint);
+ Reduction reduction = environment.reduce(c.demandLocation, c.constraint);
if(reduction != null) {
TPred[] demands = reduction.demands;
if(demands.length == 0)
throw new InternalCompilerError();
}
for(Constraint constraint : group) {
- Reduction reduction = environment.reduce(constraint.constraint);
+ Reduction reduction = environment.reduce(constraint.demandLocation, constraint.constraint);
if(reduction.demands.length > 0)
throw new InternalCompilerError();
constraint.setGenerator(Constraint.STATE_HAS_INSTANCE,
type DoubleArray = Vector Double
importJava "java.util.Arrays" where
- @private
- @JavaName toString
- showDoubleArray :: DoubleArray -> String
-
"Converts an array to a list."
@JavaName asList
arrayToList :: Array a -> [a]
@JavaName toArray
listToArray :: [a] -> Array a
-instance Show DoubleArray where
- show = showDoubleArray
-
importJava "org.simantics.scl.runtime.Coercion" where
"Converts a list of doubles to a double array."
toDoubleArray :: [Double] -> DoubleArray