if (parent != null) {\r
_additions.add(new Object[] { ss.getRandomAccessId(parent), ss.getRandomAccessId(entry.component), name, types, id != null ? id.indexString() : "" });\r
} else {\r
- System.err.println("resource " + entry.component + ": no parent for entry " + name + " " + types);\r
+ //System.err.println("resource " + entry.component + ": no parent for entry " + name + " " + types);\r
}\r
} else {\r
- System.err.println("resource " + entry.component + ": " + name + " " + types);\r
+ //System.err.println("resource " + entry.component + ": " + name + " " + types);\r
}\r
} else if(_entry instanceof ComponentModification) {\r
ComponentModification entry = (ComponentModification)_entry;\r
package org.cojen.classfile;
-import java.io.Serializable;
import java.io.Externalizable;
-import java.io.ObjectOutput;
-import java.io.ObjectInput;
import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.io.ObjectStreamException;
+import java.io.Serializable;
import java.lang.reflect.Method;
-import java.util.List;
import java.util.ArrayList;
+import java.util.List;
import org.cojen.util.WeakCanonicalSet;
package org.cojen.classfile;
import java.io.Serializable;
-import java.io.Externalizable;
-import java.io.ObjectOutput;
-import java.io.ObjectInput;
-import java.io.IOException;
-import java.io.ObjectStreamException;
import java.lang.ref.SoftReference;
import java.lang.reflect.Array;
import java.util.Collections;
return false;
}
- Object writeReplace() throws ObjectStreamException {
- return new External(mDescriptor);
- }
-
private static class PrimitiveType extends TypeDesc {
private transient final int mCode;
private transient TypeDesc mArrayType;
}
}
}
-
- private static class External implements Externalizable {
- private String mDescriptor;
-
- public External() {
- }
-
- public External(String desc) {
- mDescriptor = desc;
- }
-
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeUTF(mDescriptor);
- }
-
- public void readExternal(ObjectInput in) throws IOException {
- mDescriptor = in.readUTF();
- }
-
- public Object readResolve() throws ObjectStreamException {
- return forDescriptor(mDescriptor);
- }
- }
}
package org.simantics.scl.compiler.commands;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.procedure.TObjectProcedure;
-import gnu.trove.set.hash.THashSet;
-
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import org.simantics.scl.runtime.reporting.SCLReportingHandler;
import org.simantics.scl.runtime.tuple.Tuple0;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.procedure.TObjectProcedure;
+import gnu.trove.set.hash.THashSet;
+
public class CommandSession {
package org.simantics.scl.compiler.commands;
-import gnu.trove.map.hash.THashMap;
-
import org.simantics.scl.compiler.runtime.RuntimeEnvironment;
import org.simantics.scl.compiler.top.ExpressionEvaluator;
import org.simantics.scl.compiler.top.SCLExpressionCompilationException;
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.runtime.function.Function1;
+import gnu.trove.map.hash.THashMap;
+
public class ValueToStringConverter {
final RuntimeEnvironment environment;
final THashMap<Type, Function1> showInstances = new THashMap<Type, Function1>();
package org.simantics.scl.compiler.compilation;\r
\r
-import gnu.trove.map.hash.TObjectLongHashMap;\r
-\r
import java.util.ArrayList;\r
\r
+import gnu.trove.map.hash.TObjectLongHashMap;\r
+\r
public class CompilationTimer {\r
private long initialTime, previousTime;\r
private ArrayList<TimerEntry> entries = new ArrayList<TimerEntry>();\r
package org.simantics.scl.compiler.compilation;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import org.simantics.scl.compiler.elaboration.modules.SCLValue;
import org.simantics.scl.compiler.module.ConcreteModule;
import org.simantics.scl.compiler.types.TCon;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
+
public class DocumentationGeneration {
THashMap<String, DDocumentationAst> valueDocumentation;
THashMap<String, DDocumentationAst> typeDocumentation;
package org.simantics.scl.compiler.compilation;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.simantics.scl.compiler.environment.AmbiguousNameException;\r
import org.simantics.scl.compiler.environment.Environment;\r
import org.simantics.scl.compiler.errors.ErrorLog;\r
+import org.simantics.scl.compiler.top.SCLCompilerConfiguration;\r
\r
public class NameExistenceChecks {\r
public static void checkIfValueExists(ErrorLog errorLog, long location,\r
Environment environment, String name) {\r
- try {\r
- SCLValue value = environment.getLocalNamespace().getValue(name);\r
- if(value != null)\r
+ if(SCLCompilerConfiguration.ALLOW_OVERLOADING)\r
+ return;\r
+ else {\r
+ try {\r
+ SCLValue value = environment.getLocalNamespace().getValue(name);\r
+ if(value != null)\r
+ errorLog.log(location,\r
+ "Value " + name + " is already defined in the module " + \r
+ value.getName().module + \r
+ " that is imported to the default namespace.");\r
+ } catch(AmbiguousNameException e) {\r
errorLog.log(location,\r
- "Value " + name + " is already defined in the module " + \r
- value.getName().module + \r
- " that is imported to the default namespace.");\r
- } catch(AmbiguousNameException e) {\r
- errorLog.log(location,\r
- "Value " + name + " is already defined in the modules " + \r
- e.conflictingModules[0] + " and " + e.conflictingModules[1] + \r
- " that are imported to the default namespace.");\r
+ "Value " + name + " is already defined in the modules " + \r
+ e.conflictingModules[0] + " and " + e.conflictingModules[1] + \r
+ " that are imported to the default namespace.");\r
+ }\r
}\r
}\r
\r
package org.simantics.scl.compiler.compilation;
-import gnu.trove.procedure.TObjectProcedure;
-
+import java.util.Arrays;
import java.util.function.Consumer;
import org.simantics.scl.compiler.elaboration.modules.SCLValue;
import org.simantics.scl.compiler.environment.filter.NamespaceFilter;
import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor;
import org.simantics.scl.compiler.module.Module;
+import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
import org.simantics.scl.compiler.types.TCon;
+import gnu.trove.procedure.TObjectProcedure;
+
public class NamespaceOfModule implements Namespace {
private final Namespace base;
private final Module module;
@Override
public SCLValue getValue(String name) throws AmbiguousNameException {
SCLValue value = module.getValue(name);
+ if(SCLCompilerConfiguration.ALLOW_OVERLOADING) {
+ SCLValue value2;
+ try {
+ value2 = base.getValue(name);
+ } catch(AmbiguousNameException e) {
+ if(value != null) {
+ String[] conflictingModules = Arrays.copyOf(e.conflictingModules, e.conflictingModules.length+1);
+ conflictingModules[e.conflictingModules.length] = module.getName();
+ throw new AmbiguousNameException(Arrays.asList(conflictingModules), e.name);
+ }
+ else
+ throw e;
+ }
+ if(value == null)
+ return value2;
+ if(value2 == null)
+ return value;
+ throw new AmbiguousNameException(Arrays.asList(value.getName().module, value2.getName().module), value.getName().name);
+ }
+ else {
if(value != null)
return value;
return base.getValue(name);
+ }
}
@Override
import static org.simantics.scl.compiler.elaboration.expressions.Expressions.lambda;
import static org.simantics.scl.compiler.elaboration.expressions.Expressions.loc;
import static org.simantics.scl.compiler.elaboration.expressions.Expressions.vars;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-import gnu.trove.set.hash.TIntHashSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
+import org.simantics.scl.compiler.elaboration.expressions.EAmbiguous;
import org.simantics.scl.compiler.elaboration.expressions.EPlaceholder;
import org.simantics.scl.compiler.elaboration.expressions.ETransformation;
import org.simantics.scl.compiler.elaboration.expressions.EVariable;
import org.simantics.scl.compiler.types.kinds.Kinds;
import org.simantics.scl.compiler.types.util.Polarity;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.THashSet;
+import gnu.trove.set.hash.TIntHashSet;
+
public class TypeChecking {
final ErrorLog errorLog;
final Environment environment;
context.pushEffectUpperBound(expression.location, Types.PROC);
expression = expression.checkType(context, value.getType());
context.popEffectUpperBound();
+ for(EAmbiguous overloaded : context.overloadedExpressions)
+ overloaded.assertResolved(errorLog);
value.setExpression(expression);
ArrayList<EVariable> constraintDemand = context.getConstraintDemand();
@Override
public void run() {
Type type = value.getType();
+
Expression expression = value.getExpression();
try {
context.pushEffectUpperBound(expression.location, Types.PROC);
expression = expression.checkType(context, type);
context.popEffectUpperBound();
+ for(EAmbiguous overloaded : context.overloadedExpressions)
+ overloaded.assertResolved(errorLog);
expression.getType().addPolarity(Polarity.POSITIVE);
context.solveSubsumptions(expression.getLocation());
ArrayList<EVariable> demands = context.getConstraintDemand();
+++ /dev/null
-package org.simantics.scl.compiler.compilation;
-
-import static org.simantics.scl.compiler.elaboration.expressions.Expressions.apply;
-import static org.simantics.scl.compiler.elaboration.expressions.Expressions.applyTypes;
-import static org.simantics.scl.compiler.elaboration.expressions.Expressions.lambda;
-import static org.simantics.scl.compiler.elaboration.expressions.Expressions.loc;
-import static org.simantics.scl.compiler.elaboration.expressions.Expressions.vars;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-import gnu.trove.set.hash.TIntHashSet;
-
-import java.util.ArrayList;
-
-import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
-import org.simantics.scl.compiler.elaboration.expressions.EPlaceholder;
-import org.simantics.scl.compiler.elaboration.expressions.EVariable;
-import org.simantics.scl.compiler.elaboration.expressions.Expression;
-import org.simantics.scl.compiler.elaboration.expressions.Variable;
-import org.simantics.scl.compiler.elaboration.modules.SCLValue;
-import org.simantics.scl.compiler.elaboration.rules.MappingRelation;
-import org.simantics.scl.compiler.elaboration.rules.TransformationRule;
-import org.simantics.scl.compiler.environment.Environment;
-import org.simantics.scl.compiler.errors.ErrorLog;
-import org.simantics.scl.compiler.errors.Locations;
-import org.simantics.scl.compiler.internal.elaboration.constraints.Constraint;
-import org.simantics.scl.compiler.internal.elaboration.constraints.ConstraintEnvironment;
-import org.simantics.scl.compiler.internal.elaboration.constraints.ConstraintSolver;
-import org.simantics.scl.compiler.internal.elaboration.constraints.ExpressionAugmentation;
-import org.simantics.scl.compiler.internal.elaboration.constraints.ReducedConstraints;
-import org.simantics.scl.compiler.internal.elaboration.utils.StronglyConnectedComponents;
-import org.simantics.scl.compiler.module.ConcreteModule;
-import org.simantics.scl.compiler.types.TPred;
-import org.simantics.scl.compiler.types.TVar;
-import org.simantics.scl.compiler.types.Type;
-import org.simantics.scl.compiler.types.Types;
-import org.simantics.scl.compiler.types.kinds.Kinds;
-import org.simantics.scl.compiler.types.util.Polarity;
-
-public class TypeCheckingOld {
- public static final boolean PRINT_VALUES = false;
-
- ErrorLog errorLog;
- Environment environment;
- ConcreteModule module;
-
- ConstraintEnvironment ce;
- ArrayList<SCLValue[]> valuesWithoutTypeAnnotation = new ArrayList<SCLValue[]>();
- ArrayList<SCLValue> valuesWithTypeAnnotation = new ArrayList<SCLValue>();
-
- public TypeCheckingOld(ErrorLog errorLog, Environment environment,
- ConcreteModule module) {
- this.errorLog = errorLog;
- this.environment = environment;
- this.module = module;
- }
-
- public void typeCheck() {
- ce = new ConstraintEnvironment(environment);
- groupValueDefinitionsByDependency();
- typeCheckValuesWithoutTypeAnnotations();
- typeCheckValuesWithTypeAnnotations();
- typeCheckRules();
- }
-
- private void groupValueDefinitionsByDependency() {
- // Collect all untyped names
- final ArrayList<SCLValue> values = new ArrayList<SCLValue>();
- for(SCLValue value : module.getValues()) {
- if(value.getExpression() != null) {
- if(value.getType() == null)
- values.add(value);
- else
- valuesWithTypeAnnotation.add(value);
- }
- }
-
- // Create inverse
- final TObjectIntHashMap<Object> allRefs =
- new TObjectIntHashMap<Object>(values.size()*2, 0.5f, -1);
- for(int i=0;i<values.size();++i)
- allRefs.put(values.get(i), i);
-
- // Create groups
- new StronglyConnectedComponents(values.size()) {
-
- TIntHashSet set = new TIntHashSet();
-
- @Override
- protected void reportComponent(int[] component) {
- SCLValue[] valueComponent = new SCLValue[component.length];
- for(int i=0;i<component.length;++i)
- valueComponent[i] = values.get(component[i]);
- valuesWithoutTypeAnnotation.add(valueComponent);
- }
-
- @Override
- protected int[] findDependencies(int u) {
- Expression expression = values.get(u).getExpression();
- expression.collectRefs(allRefs, set);
-
- int[] result = set.toArray();
- set.clear();
-
- return result;
- }
-
- }.findComponents();
- }
-
- private void typeCheckValuesWithoutTypeAnnotations() {
- for(SCLValue[] group : valuesWithoutTypeAnnotation) {
- if(PRINT_VALUES) {
- System.out.println("---------------------------------------------");
- System.out.print("---");
- for(SCLValue value : group)
- System.out.print(" " + value.getName());
- System.out.println();
- }
-
- for(int i=0;i<group.length;++i)
- group[i].setType(Types.metaVar(Kinds.STAR));
-
- TypingContext context = new TypingContext(errorLog, environment);
- context.recursiveValues = new THashSet<SCLValue>();
- for(SCLValue value : group)
- context.recursiveValues.add(value);
-
- @SuppressWarnings("unchecked")
- ArrayList<EVariable>[] constraintDemands = new ArrayList[group.length];
-
- @SuppressWarnings("unchecked")
- ArrayList<EPlaceholder>[] recursiveReferences = new ArrayList[group.length];
- for(int i=0;i<group.length;++i) {
- context.recursiveReferences = new ArrayList<EPlaceholder>();
-
- SCLValue value = group[i];
- Expression expression = value.getExpression();
- expression = expression.checkType(context, value.getType());
- value.setExpression(expression);
-
- ArrayList<EVariable> constraintDemand = context.getConstraintDemand();
- if(!constraintDemand.isEmpty()) {
- constraintDemands[i] = constraintDemand;
- context.resetConstraintDemand();
- }
-
- recursiveReferences[i] = context.recursiveReferences;
- }
-
- for(Type type : Types.getTypes(group))
- type.addPolarity(Polarity.POSITIVE);
- context.solveSubsumptions(group[0].getExpression().getLocation());
- ArrayList<Constraint> allUnsolvedConstraints = new ArrayList<Constraint>();
-
- @SuppressWarnings("unchecked")
- ArrayList<Variable>[] freeEvidence = new ArrayList[group.length];
- for(int i=0;i<group.length;++i) {
- if(constraintDemands[i] != null) {
- SCLValue value = group[i];
- Expression expression = value.getExpression();
-
- ReducedConstraints red = ConstraintSolver.solve(
- ce, new ArrayList<TPred>(0), constraintDemands[i],
- true /*!Types.isFunction(expression.getType())*/);
-
- expression = ExpressionAugmentation.augmentSolved(
- red.solvedConstraints,
- expression);
- value.setExpression(expression);
- value.setType(expression.getType());
-
- for(Constraint c : red.unsolvedConstraints)
- if(c.constraint.isGround()) {
- errorLog.log(c.getDemandLocation(), "There is no instance for <"+c.constraint+">.");
- }
-
- ArrayList<Variable> fe = new ArrayList<Variable>(red.unsolvedConstraints.size());
- for(Constraint c : red.unsolvedConstraints) {
- allUnsolvedConstraints.add(c);
- fe.add(c.evidence);
- }
- freeEvidence[i] = fe;
- }
- else {
- group[i].setExpression(group[i].getExpression().decomposeMatching());
- freeEvidence[i] = new ArrayList<Variable>(0);
- }
- }
-
- THashSet<TVar> varSet = new THashSet<TVar>();
- for(int i=0;i<group.length;++i) {
- SCLValue value = group[i];
- Type type = value.getType();
- type = type.convertMetaVarsToVars();
- value.setType(type);
- varSet.addAll(Types.freeVars(type));
- }
-
- TVar[] vars = varSet.toArray(new TVar[varSet.size()]);
-
- // Collect all constraints needed in the group
- THashSet<TPred> constraintSet = new THashSet<TPred>();
- for(int i=0;i<group.length;++i) {
- for(Variable evidence : freeEvidence[i]) {
- constraintSet.add((TPred)evidence.getType());
- }
- }
- TPred[] constraints = constraintSet.toArray(new TPred[constraintSet.size()]);
- for(TPred constraint : constraints)
- if(constraint.containsMetaVars()) {
- for(Constraint c : allUnsolvedConstraints) {
- if(Types.equals(c.constraint, constraint)) {
- errorLog.log(c.getDemandLocation(),
- "Constrain " + constraint +
- " contains free variables not mentioned in the type of the value.");
- break;
- }
- }
- }
-
-
- // TODO copy to TypeChecking2 from this onwards
- for(int i=0;i<group.length;++i) {
- // Create evidence array of every value in the group that has the variables
- // in the same array as in the shared array
- ArrayList<Variable> fe = freeEvidence[i];
- THashMap<TPred, Variable> indexedEvidence = new THashMap<TPred, Variable>(fe.size());
- for(Variable v : fe)
- indexedEvidence.put((TPred)v.getType(), v);
- fe.clear();
- for(TPred c : constraints) {
- Variable var = indexedEvidence.get(c);
- if(var == null) {
- // These are variables that are not directly needed in
- // this definition but in the definitions that are
- // recursively called
- var = new Variable("evX");
- var.setType(c);
- fe.add(var);
- }
- fe.add(var);
- }
-
- // Add evidence parameters to the functions
- SCLValue value = group[i];
- value.setExpression(lambda(Types.NO_EFFECTS, fe, value.getExpression())
- .closure(vars));
- value.setType(Types.forAll(vars,
- Types.constrained(constraints, value.getType())));
-
- // Add evidence parameters to recursive calls
- for(EPlaceholder ref : recursiveReferences[i]) {
- ref.expression = loc(ref.expression.location, apply(
- Types.NO_EFFECTS,
- applyTypes(ref.expression, vars),
- vars(fe)));
- }
- }
- }
- }
-
- private void typeCheckValuesWithTypeAnnotations() {
- ArrayList<TPred> givenConstraints = new ArrayList<TPred>();
- for(SCLValue value : valuesWithTypeAnnotation) {
- Type type = value.getType();
- if(type != null) {
- if(PRINT_VALUES) {
- System.out.println("---------------------------------------------");
- System.out.println("--- " + value.getName() + " :: " + type);
- }
- Expression expression = value.getExpression();
- ArrayList<TVar> vars = new ArrayList<TVar>();
- type = Types.removeForAll(type, vars);
- type = Types.removePred(type, givenConstraints);
-
- /*System.out.println("---------------------------------------------");
- TypeUnparsingContext tuc = new TypeUnparsingContext();
- System.out.println("--- " + value.getName() + " :: " + type.toString(tuc));
- for(TPred t : givenConstraints)
- System.out.println(">>> " + t.toString(tuc));
- */
- TypingContext context = new TypingContext(errorLog, environment);
- //System.out.println(expression);
- expression = expression.checkType(context, type);
- //System.out.println(expression);
- expression.getType().addPolarity(Polarity.POSITIVE);
- context.solveSubsumptions(expression.getLocation());
- ArrayList<EVariable> demands = context.getConstraintDemand();
- if(!demands.isEmpty() || !givenConstraints.isEmpty()) {
- ReducedConstraints red =
- ConstraintSolver.solve(ce, givenConstraints, demands, true);
- givenConstraints.clear();
- for(Constraint c : red.unsolvedConstraints) {
- errorLog.log(c.getDemandLocation(),
- "Constraint <"+c.constraint+"> is not given and cannot be derived.");
- }
- if(errorLog.isEmpty()) { // To prevent exceptions
- expression = ExpressionAugmentation.augmentSolved(
- red.solvedConstraints,
- expression);
- expression = ExpressionAugmentation.augmentUnsolved(
- red.givenConstraints,
- expression);
- }
- }
- else {
- if(errorLog.isEmpty()) // To prevent exceptions
- expression = expression.decomposeMatching();
- }
- expression = expression.closure(vars.toArray(new TVar[vars.size()]));
- value.setExpression(expression);
- }
- }
- }
-
- public void typeCheckRules() {
- TypingContext context = new TypingContext(errorLog, environment);
- for(TransformationRule rule : module.getRules()) {
- context.pushEffectUpperBound(rule.location, Types.metaVar(Kinds.EFFECT));
- rule.checkType(context);
- rule.setEffect(Types.canonical(context.popEffectUpperBound()));
- }
- context.solveSubsumptions(Locations.NO_LOCATION);
-
- ArrayList<EVariable> demands = context.getConstraintDemand();
- if(!demands.isEmpty()) {
- ReducedConstraints red =
- ConstraintSolver.solve(ce, new ArrayList<TPred>(), demands, true);
- for(Constraint c : red.unsolvedConstraints) {
- errorLog.log(c.getDemandLocation(),
- "Constraint <"+c.constraint+"> is not given and cannot be derived.");
- }
- }
-
- for(MappingRelation mappingRelation : module.getMappingRelations())
- for(Type parameterType : mappingRelation.parameterTypes)
- if(!parameterType.isGround()) {
- errorLog.log(mappingRelation.location, "Parameter types of the mapping relation are not completely determined.");
- break;
- }
-
- /*for(Rule rule : module.getRules()) {
- System.out.println(rule.name);
- for(Variable variable : rule.variables)
- System.out.println(" " + variable.getName() + " :: " + variable.getType());
- }*/
- }
-}
package org.simantics.scl.compiler.compilation;
-import gnu.trove.impl.Constants;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-import gnu.trove.set.hash.TIntHashSet;
-
import java.util.ArrayList;
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
import org.simantics.scl.compiler.types.TPred;
import org.simantics.scl.compiler.types.TVar;
+import gnu.trove.impl.Constants;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.THashSet;
+import gnu.trove.set.hash.TIntHashSet;
+
/**
* Schedules the order of type checking.
*
package org.simantics.scl.compiler.compilation;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-import gnu.trove.set.hash.TIntHashSet;
-
import java.util.ArrayList;
import java.util.Collection;
import org.simantics.scl.compiler.types.TPred;
import org.simantics.scl.compiler.types.TVar;
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.THashSet;
+import gnu.trove.set.hash.TIntHashSet;
+
public interface TypeInferableDefinition {
long getLocation();
Collection<Object> getDefinedObjects();
package org.simantics.scl.compiler.constants;
-import org.simantics.scl.compiler.internal.codegen.utils.LocalVariable;
import org.cojen.classfile.TypeDesc;
+import org.simantics.scl.compiler.internal.codegen.utils.LocalVariable;
import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
import org.simantics.scl.compiler.internal.codegen.utils.TransientClassBuilder;
import org.simantics.scl.compiler.types.Type;
package org.simantics.scl.compiler.constants;
-import org.simantics.scl.compiler.internal.codegen.utils.LocalVariable;
import org.cojen.classfile.TypeDesc;
+import org.simantics.scl.compiler.internal.codegen.utils.LocalVariable;
import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
import org.simantics.scl.compiler.internal.codegen.utils.TransientClassBuilder;
import org.simantics.scl.compiler.types.Type;
package org.simantics.scl.compiler.constants.generic;
-import gnu.trove.map.hash.THashMap;
-
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.simantics.scl.compiler.constants.generic.MethodRef.StaticMethodRef;
import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilderBase;
+import gnu.trove.map.hash.THashMap;
+
/**
* This class is a reference to a Java class that contains a map of MethodRef for each
* method declared by the referenced class.
package org.simantics.scl.compiler.elaboration.contexts;
-import gnu.trove.list.array.TLongArrayList;
-import gnu.trove.map.hash.THashMap;
-
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.common.names.Name;
import org.simantics.scl.compiler.constants.Constant;
import org.simantics.scl.compiler.types.exceptions.MatchException;
import org.simantics.scl.compiler.types.util.MultiFunction;
+import gnu.trove.list.array.TLongArrayList;
+import gnu.trove.map.hash.THashMap;
+
public class SimplificationContext implements EnvironmentalContext {
Environment environment;
ErrorLog errorLog;
package org.simantics.scl.compiler.elaboration.contexts;
-import gnu.trove.list.array.TIntArrayList;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.procedure.TObjectProcedure;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import java.util.Arrays;
import org.simantics.scl.compiler.common.precedence.Associativity;
import org.simantics.scl.compiler.common.precedence.Precedence;
import org.simantics.scl.compiler.elaboration.expressions.Case;
+import org.simantics.scl.compiler.elaboration.expressions.EAmbiguous;
import org.simantics.scl.compiler.elaboration.expressions.EConstant;
import org.simantics.scl.compiler.elaboration.expressions.EEntityTypeAnnotation;
import org.simantics.scl.compiler.elaboration.expressions.EError;
import org.simantics.scl.compiler.errors.ErrorLog;
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.internal.parsing.declarations.DValueAst;
+import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
+import org.simantics.scl.compiler.types.Type;
+
+import gnu.trove.list.array.TIntArrayList;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.procedure.TObjectProcedure;
+import gnu.trove.set.hash.THashSet;
public class TranslationContext extends TypeTranslationContext implements EnvironmentalContext {
}
private Expression resolveIn(long location, Namespace namespace, String name) {
- SCLValue value = resolveValueIn(location, namespace, name);
+ SCLValue value;
+ try {
+ value = resolveValueIn(location, namespace, name);
+ } catch (AmbiguousNameException e) {
+ if(SCLCompilerConfiguration.ALLOW_OVERLOADING) {
+ EAmbiguous.Alternative[] alternatives = new EAmbiguous.Alternative[e.conflictingModules.length];
+ //System.out.println("Overloading:");
+ for(int i=0;i<e.conflictingModules.length;++i) {
+ Name altName = Name.create(e.conflictingModules[i], e.name);
+ //System.out.println(" " + altName);
+ SCLValue altValue = environment.getValue(altName);
+ alternatives[i] = new EAmbiguous.Alternative() {
+ @Override
+ public Type getType() {
+ return altValue.getType();
+ }
+
+ @Override
+ public Expression realize() {
+ EConstant expression = new EConstant(altValue);
+ expression.location = location;
+ return expression;
+ }
+
+ @Override
+ public String toString() {
+ return altValue.getName().toString().replace('/', '.');
+ }
+ };
+ }
+ EAmbiguous expression = new EAmbiguous(alternatives);
+ expression.location = location;
+ return expression;
+ }
+ else {
+ errorLog.log(location, e.getMessage());
+ value = null;
+ }
+ }
if(value == null)
return new EError(location);
return new EConstant(location, value);
return prec;
}
- private SCLValue resolveValueIn(long location, Namespace namespace, final String name) {
- try {
+ private SCLValue resolveValueIn(long location, Namespace namespace, final String name) throws AmbiguousNameException {
SCLValue value = namespace.getValue(name);
if(value == null) {
StringBuilder message = new StringBuilder();
return null;
}
return value;
- } catch (AmbiguousNameException e) {
- errorLog.log(location, e.getMessage());
- return null;
- }
}
public Case translateCase(Expression lhs, Expression rhs) {
package org.simantics.scl.compiler.elaboration.contexts;
-import gnu.trove.map.hash.THashMap;
-
import org.simantics.scl.compiler.environment.Environment;
import org.simantics.scl.compiler.errors.ErrorLog;
import org.simantics.scl.compiler.internal.parsing.exceptions.SCLSyntaxErrorException;
import org.simantics.scl.compiler.types.kinds.Kind;
import org.simantics.scl.compiler.types.kinds.Kinds;
+import gnu.trove.map.hash.THashMap;
+
public class TypeTranslationContext {
Environment environment;
package org.simantics.scl.compiler.elaboration.contexts;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.common.names.Name;
import org.simantics.scl.compiler.constants.NoRepConstant;
+import org.simantics.scl.compiler.elaboration.expressions.EAmbiguous;
import org.simantics.scl.compiler.elaboration.expressions.EApply;
import org.simantics.scl.compiler.elaboration.expressions.EConstant;
import org.simantics.scl.compiler.elaboration.expressions.EError;
import org.simantics.scl.compiler.types.kinds.Kinds;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
+
public class TypingContext implements EnvironmentalContext {
private ErrorLog errorLog;
public THashSet<SCLValue> recursiveValues;
public ArrayList<EPlaceholder> recursiveReferences;
+ // Overloading
+ public ArrayList<EAmbiguous> overloadedExpressions = new ArrayList<EAmbiguous>();
+
//TypeUnparsingContext tuc = new TypeUnparsingContext();
Environment environment;
* Instantiates type abstractions and constraints from the value.
*/
public Expression instantiate(Expression expr) {
- Type type = Types.weakCanonical(expr.getType());
+ Type type = Types.canonical(expr.getType());
while(type instanceof TForAll) {
TForAll forAll = (TForAll)type;
TVar var = forAll.var;
* type applications, lambdas and effect subsumptions.
*/
public Expression subsume(Expression expr, Type b) {
- b = Types.weakCanonical(b);
+ b = Types.canonical(b);
/*if(b instanceof TForAll) {
TForAll forAll = (TForAll)b;
TVar var = forAll.var;
\r
@Override\r
public void checkType(TypingContext context) {\r
- guard = guard.inferType(context);\r
+ guard = guard.checkIgnoredType(context);\r
}\r
\r
@Override\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;\r
import org.simantics.scl.compiler.types.Type;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public abstract class ASTExpression extends SimplifiableExpression {\r
public ASTExpression() {\r
}\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.internal.parsing.Symbol;\r
import org.simantics.scl.compiler.types.Type;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class Case extends Symbol {\r
public Expression[] patterns;\r
public Expression value;\r
patterns[i] = patterns[i].checkTypeAsPattern(context, parameterTypes[i]);\r
value = value.checkType(context, requiredType);\r
}\r
+ \r
+ public void checkIgnoredType(TypingContext context, Type[] parameterTypes) {\r
+ if(patterns.length != parameterTypes.length) {\r
+ context.getErrorLog().log(location, "This case has different arity ("+patterns.length+\r
+ ") than than the first case (+"+parameterTypes.length+"+).");\r
+ return;\r
+ }\r
+ for(int i=0;i<patterns.length;++i)\r
+ patterns[i] = patterns[i].checkTypeAsPattern(context, parameterTypes[i]);\r
+ value = value.checkIgnoredType(context);\r
+ }\r
\r
public void decorate(ExpressionDecorator decorator) {\r
for(int i=0;i<patterns.length;++i)\r
expression = expression.checkBasicType(context, requiredType);
return this;
}
+
+ @Override
+ public Expression checkIgnoredType(TypingContext context) {
+ expression = expression.checkIgnoredType(context);
+ return this;
+ }
}
--- /dev/null
+package org.simantics.scl.compiler.elaboration.expressions;
+
+import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
+import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
+import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
+import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
+import org.simantics.scl.compiler.errors.ErrorLog;
+import org.simantics.scl.compiler.errors.Locations;
+import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
+import org.simantics.scl.compiler.types.Skeletons;
+import org.simantics.scl.compiler.types.TMetaVar;
+import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.Types;
+import org.simantics.scl.compiler.types.exceptions.MatchException;
+import org.simantics.scl.compiler.types.exceptions.UnificationException;
+import org.simantics.scl.compiler.types.util.TypeListener;
+import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.THashSet;
+import gnu.trove.set.hash.TIntHashSet;
+
+public class EAmbiguous extends SimplifiableExpression {
+ public static final boolean DEBUG = false;
+
+ Alternative[] alternatives;
+ boolean[] active;
+ int activeCount;
+ transient TypingContext context;
+ Expression resolvedExpression;
+
+ public abstract static class Alternative {
+ public abstract Type getType();
+ public abstract Expression realize();
+ }
+
+ public EAmbiguous(Alternative[] alternatives) {
+ this.alternatives = alternatives;
+ this.active = new boolean[alternatives.length];
+ for(int i=0;i<alternatives.length;++i)
+ this.active[i] = true;
+ this.activeCount = alternatives.length;
+ }
+
+ @Override
+ public void collectRefs(TObjectIntHashMap<Object> allRefs,
+ TIntHashSet refs) {
+ }
+
+ @Override
+ public void collectVars(TObjectIntHashMap<Variable> allVars,
+ TIntHashSet vars) {
+ }
+
+ @Override
+ public void forVariables(VariableProcedure procedure) {
+ }
+
+ @Override
+ protected void updateType() throws MatchException {
+ throw new InternalCompilerError();
+ }
+
+ private Type getCommonSkeleton() {
+ Type[] types = new Type[activeCount];
+ for(int i=0,j=0;i<alternatives.length;++i)
+ if(active[i])
+ types[j++] = Types.instantiateAndStrip(alternatives[i].getType());
+ return Skeletons.commonSkeleton(context.getEnvironment(), types);
+ }
+
+ private void filterActive() {
+ THashMap<TMetaVar,Type> unifications = new THashMap<TMetaVar,Type>();
+ Type requiredType = getType();
+ if(DEBUG)
+ System.out.println("EAmbigious.filterActive with " + requiredType);
+ for(int i=0;i<alternatives.length;++i)
+ if(active[i]) {
+ unifications.clear();
+ Type alternativeType = Types.instantiateAndStrip(alternatives[i].getType());
+ if(DEBUG)
+ System.out.println(" " + alternativeType);
+ if(!Skeletons.areSkeletonsCompatible(unifications, alternativeType, requiredType)) {
+ active[i] = false;
+ --activeCount;
+ }
+ }
+ if(DEBUG)
+ System.out.println(" activeCount = " + activeCount);
+ }
+
+ private String getNoMatchDescription(Type requiredType) {
+ StringBuilder b = new StringBuilder();
+ b.append("Expected <");
+ requiredType.toString(new TypeUnparsingContext(), b);
+ b.append(">, but no alteratives match the type: ");
+ for(int i=0;i<alternatives.length;++i) {
+ b.append("\n ");
+ b.append(alternatives[i]);
+ b.append(" :: ");
+ alternatives[i].getType().toString(new TypeUnparsingContext(), b);
+ }
+ b.append('.');
+ return b.toString();
+ }
+
+ private String getAmbiguousDescription(Type requiredType) {
+ StringBuilder b = new StringBuilder();
+ b.append("Expected <");
+ requiredType.toString(new TypeUnparsingContext(), b);
+ b.append(">, but multiple values match the type: ");
+ for(int i=0;i<alternatives.length;++i) {
+ b.append("\n ");
+ b.append(alternatives[i]);
+ b.append(" :: ");
+ alternatives[i].getType().toString(new TypeUnparsingContext(), b);
+ }
+ b.append('.');
+ return b.toString();
+ }
+
+
+ private void resolveTo(int i) {
+ if(DEBUG)
+ System.out.println("EAmbigious.resolve to " + alternatives[i]);
+ resolvedExpression = context.instantiate(alternatives[i].realize());
+ Type requiredType = getType();
+ try {
+ Types.unify(resolvedExpression.getType(), requiredType);
+ } catch (UnificationException e) {
+ context.getErrorLog().log(location, getNoMatchDescription(requiredType));
+ }
+ }
+
+ private void listenType() {
+ if(DEBUG)
+ System.out.println("EAmbigious.listenType " + getType());
+ new TypeListener() {
+ @Override
+ public void notifyAboutChange() {
+ if(DEBUG)
+ System.out.println("EAmbigious.notifyAboutChange " + getType());
+ Type requiredType = getType();
+ filterActive();
+ if(activeCount == 0) {
+ context.getErrorLog().log(location, getNoMatchDescription(requiredType));
+ return;
+ }
+ else if(activeCount == 1) {
+ for(int i=0;i<alternatives.length;++i)
+ if(active[i]) {
+ resolveTo(i);
+ return;
+ }
+ }
+ Type commonType = getCommonSkeleton();
+ try {
+ Skeletons.unifySkeletons(requiredType, commonType);
+ listenType();
+ } catch (UnificationException e) {
+ context.getErrorLog().log(location, getNoMatchDescription(requiredType));
+ }
+ }
+ }.listenSkeleton(getType());
+ }
+
+ @Override
+ public Expression inferType(TypingContext context) {
+ this.context = context;
+ context.overloadedExpressions.add(this);
+ setType(getCommonSkeleton());
+ listenType();
+ return this;
+ }
+
+ @Override
+ public void collectFreeVariables(THashSet<Variable> vars) {
+ }
+
+ @Override
+ public Expression resolve(TranslationContext context) {
+ throw new InternalCompilerError("EAmbiguousConstant should not exist in resolve phase.");
+ }
+
+ @Override
+ public void setLocationDeep(long loc) {
+ if(location == Locations.NO_LOCATION)
+ location = loc;
+ }
+
+ @Override
+ public Expression decorate(ExpressionDecorator decorator) {
+ return this;
+ }
+
+ @Override
+ public void collectEffects(THashSet<Type> effects) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void accept(ExpressionVisitor visitor) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public Expression simplify(SimplificationContext context) {
+ if(resolvedExpression != null)
+ return resolvedExpression;
+ else {
+ context.getErrorLog().log(location, getAmbiguousDescription(getType()));
+ return this;
+ }
+ }
+
+ public void assertResolved(ErrorLog errorLog) {
+ if(resolvedExpression == null)
+ errorLog.log(location, getAmbiguousDescription(getType()));
+ }
+
+ @Override
+ public Expression accept(ExpressionTransformer transformer) {
+ return transformer.transform(this);
+ }
+
+}
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import java.util.ArrayList;\r
\r
import org.simantics.scl.compiler.common.names.Name;\r
+import org.simantics.scl.compiler.constants.NoRepConstant;\r
import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.internal.interpreted.IExpression;\r
import org.simantics.scl.compiler.internal.interpreted.IListLiteral;\r
import org.simantics.scl.compiler.top.ExpressionInterpretationContext;\r
+import org.simantics.scl.compiler.types.Skeletons;\r
+import org.simantics.scl.compiler.types.TFun;\r
import org.simantics.scl.compiler.types.Type;\r
import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
import org.simantics.scl.compiler.types.kinds.Kinds;\r
import org.simantics.scl.compiler.types.util.MultiFunction;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class EApply extends Expression {\r
Expression function;\r
Expression[] parameters;\r
return new IApply(function.toIExpression(target), parametersI);\r
}\r
\r
- @Override\r
- public Expression inferType(TypingContext context) {\r
+ private void inferType(TypingContext context, boolean ignoreResult) {\r
function = function.inferType(context);\r
function = context.instantiate(function);\r
MultiFunction mfun;\r
setType(Types.metaVar(Kinds.STAR));\r
for(int i=0;i<parameters.length;++i)\r
parameters[i] = parameters[i].inferType(context);\r
- return this;\r
+ return;\r
+ }\r
+ if((ignoreResult && Skeletons.canonicalSkeleton(mfun.returnType) instanceof TFun &&\r
+ Types.canonical(mfun.effect) == Types.NO_EFFECTS) ||\r
+ (context.isInPattern() && Skeletons.canonicalSkeleton(mfun.returnType) instanceof TFun)) {\r
+ context.getErrorLog().log(location, "The function is applied with too few parameters.");\r
}\r
\r
// Check parameter types\r
\r
context.declareEffect(location, mfun.effect);\r
setType(mfun.returnType);\r
-\r
+ }\r
+ \r
+ @Override\r
+ public Expression inferType(TypingContext context) {\r
+ inferType(context, false);\r
+ return this;\r
+ }\r
+ \r
+ @Override\r
+ public Expression checkIgnoredType(TypingContext context) {\r
+ inferType(context, true);\r
+ if(Types.canonical(getType()) != Types.UNIT)\r
+ return new ESimpleLet(location, null, this, new ELiteral(NoRepConstant.PUNIT));\r
return this;\r
}\r
\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class EApplyType extends Expression { \r
Expression expression;\r
Type parameter;\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.types.Type;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class EAsPattern extends Expression {\r
\r
Variable var;\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.types.exceptions.UnificationException;\r
import org.simantics.scl.compiler.types.kinds.Kinds;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class EBind extends SimplifiableExpression {\r
public Expression pattern;\r
public Expression value;\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import java.util.ArrayList;\r
\r
import org.simantics.scl.compiler.common.names.Name;\r
import org.simantics.scl.compiler.types.util.MultiFunction;\r
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class EConstant extends Expression {\r
SCLValue value;\r
Type[] typeParameters;\r
return this;\r
}\r
else\r
- return this;\r
+ return applyPUnit(context);\r
}\r
\r
@Override\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class EEnforce extends SimplifiableExpression {\r
\r
Query query;\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import static org.simantics.scl.compiler.elaboration.expressions.Expressions.*;\r
-import gnu.trove.map.hash.THashMap;\r
+import static org.simantics.scl.compiler.elaboration.expressions.Expressions.loc;\r
\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.elaboration.java.EqRelation;\r
import org.simantics.scl.compiler.errors.Locations;\r
import org.simantics.scl.compiler.internal.parsing.Token;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+\r
public class EEntityTypeAnnotation extends ASTExpression {\r
\r
Expression expression;\r
return this;\r
}\r
\r
+ @Override\r
+ public Expression checkIgnoredType(TypingContext context) {\r
+ return inferType(context);\r
+ }\r
+\r
@Override\r
public Expression simplify(SimplificationContext context) {\r
context.getErrorLog().log(location, "Equations should be transformed into other expressions before simplification phase.");\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
import org.simantics.scl.compiler.types.kinds.Kinds;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class EError extends Expression {\r
\r
public EError(long loc, Type type) {\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import java.util.ArrayList;\r
\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class EExternalConstant extends Expression {\r
Object value;\r
\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.common.names.Name;\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class EFieldAccess extends SimplifiableExpression {\r
\r
private static final Type VARIABLE = Types.con("Simantics/Variables", "Variable");\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;\r
import org.simantics.scl.compiler.types.Type;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class EGetConstraint extends SimplifiableExpression {\r
TPred constraint;\r
EVariable evidence;\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class EIf extends Expression {\r
public Expression condition;\r
public Expression then_;\r
return this;\r
}\r
\r
+ @Override\r
+ public Expression checkIgnoredType(TypingContext context) {\r
+ condition = condition.checkType(context, Types.BOOLEAN);\r
+ then_ = then_.checkIgnoredType(context);\r
+ else_ = else_.checkIgnoredType(context);\r
+ return this;\r
+ }\r
+ \r
@Override\r
public Expression decorate(ExpressionDecorator decorator) {\r
condition = condition.decorate(decorator);\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.constants.DoubleConstant;\r
import org.simantics.scl.compiler.constants.FloatConstant;\r
import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class EIntegerLiteral extends SimplifiableExpression {\r
public String value;\r
EVariable constraint;\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.types.kinds.Kinds;\r
import org.simantics.scl.compiler.types.util.MultiFunction;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class ELambda extends SimplifiableExpression {\r
public Case[] cases;\r
Type effect = Types.NO_EFFECTS;\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class ELambdaType extends Expression {\r
public TVar[] parameters;\r
public Expression value;\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import java.util.ArrayList;\r
\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
import org.simantics.scl.compiler.types.kinds.Kinds;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class ELet extends Expression {\r
public Assignment[] assignments;\r
public Expression in;\r
in = in.checkType(context, requiredType);\r
return this;\r
}\r
+ \r
+ @Override\r
+ public Expression checkIgnoredType(TypingContext context) {\r
+ checkAssignments(context);\r
+ in = in.checkIgnoredType(context);\r
+ return this;\r
+ }\r
\r
@Override\r
public Expression decorate(ExpressionDecorator decorator) {\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;\r
import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class EListComprehension extends SimplifiableExpression {\r
\r
public Expression head;\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class EListLiteral extends SimplifiableExpression {\r
\r
Expression[] components;\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import java.util.ArrayList;\r
\r
import org.simantics.scl.compiler.constants.Constant;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class ELiteral extends Expression {\r
Constant value;\r
\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import java.util.ArrayList;\r
\r
import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;\r
import org.simantics.scl.compiler.environment.Environment;\r
import org.simantics.scl.compiler.errors.Locations;\r
import org.simantics.scl.compiler.internal.codegen.references.IVal;\r
+import org.simantics.scl.compiler.internal.codegen.ssa.exits.Throw;\r
import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;\r
import org.simantics.scl.compiler.internal.elaboration.matching.PatternMatchingCompiler;\r
import org.simantics.scl.compiler.internal.elaboration.matching.Row;\r
import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.kinds.Kinds;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class EMatch extends Expression {\r
\r
public Expression[] scrutinee;\r
CodeWriter joinPoint = w.createBlock(getType());\r
CodeWriter failurePoint = w.createBlock(); // TODO generate only one failurePoint per function\r
PatternMatchingCompiler.split(w, env, scrutineeVals, joinPoint.getContinuation(), failurePoint.getContinuation(), rows);\r
- failurePoint.throw_(location, "Matching failure at: " + toString());\r
+ failurePoint.throw_(location, Throw.MatchingException, "Matching failure at: " + toString());\r
w.continueAs(joinPoint);\r
return w.getParameters()[0];\r
}\r
setType(requiredType);\r
return this;\r
}\r
+ \r
+ @Override\r
+ public Expression checkIgnoredType(TypingContext context) {\r
+ Type[] scrutineeTypes = new Type[scrutinee.length];\r
+ for(int i=0;i<scrutinee.length;++i) {\r
+ scrutinee[i] = scrutinee[i].checkType(context, Types.metaVar(Kinds.STAR));\r
+ scrutineeTypes[i] = scrutinee[i].getType();\r
+ }\r
+ for(Case case_ : cases)\r
+ case_.checkIgnoredType(context, scrutineeTypes);\r
+ setType(Types.UNIT);\r
+ return this;\r
+ }\r
\r
@Override\r
public Expression decorate(ExpressionDecorator decorator) {\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-import gnu.trove.procedure.TObjectObjectProcedure;\r
-\r
import java.util.ArrayList;\r
import java.util.List;\r
\r
import org.simantics.scl.compiler.elaboration.expressions.lhstype.LhsType;\r
import org.simantics.scl.compiler.errors.Locations;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+import gnu.trove.procedure.TObjectObjectProcedure;\r
+\r
public class EPreLet extends ASTExpression {\r
\r
List<LetStatement> assignments;\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.elaboration.expressions.ERuleset.DatalogRule;\r
import org.simantics.scl.compiler.elaboration.expressions.block.RuleStatement;\r
import org.simantics.scl.compiler.elaboration.relations.LocalRelation;\r
import org.simantics.scl.compiler.errors.Locations;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+\r
public class EPreRuleset extends ASTExpression {\r
\r
RuleStatement[] statements;\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.constants.DoubleConstant;\r
import org.simantics.scl.compiler.constants.FloatConstant;\r
import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class ERealLiteral extends SimplifiableExpression {\r
public String value;\r
EVariable constraint;\r
return new EError(constructor.location);
}
THashMap<String,FieldAssignment> recordMap = new THashMap<String,FieldAssignment>(fields.length);
- for(FieldAssignment field : fields)
- recordMap.put(field.name, field);
+ for(FieldAssignment field : fields) {
+ if(field.value == null) {
+ String bestMatch = null;
+ int bestMatchLength = 0;
+ for(int i=0;i<fieldNames.length;++i) {
+ String fieldName = fieldNames[i];
+ if(field.name.startsWith(fieldName) && fieldName.length() > bestMatchLength) {
+ bestMatch = fieldName;
+ bestMatchLength = fieldName.length();
+ }
+ }
+ if(bestMatch == null) {
+ context.getErrorLog().log(field.location, "Invalid shorthand field " + field.name + " is defined twice.");
+ return new EError(location);
+ }
+ field.value = new EVar(field.location, field.name);
+ field.name = bestMatch;
+ }
+ if(recordMap.put(field.name, field) != null) {
+ context.getErrorLog().log(field.location, "Field " + field.name + " is defined more than once.");
+ return new EError(location);
+ }
+ }
Expression[] parameters = new Expression[fieldNames.length];
boolean error = false;
for(int i=0;i<fieldNames.length;++i) {
if(location == Locations.NO_LOCATION) {
location = loc;
for(FieldAssignment field : fields)
- field.value.setLocationDeep(loc);
+ if(field.value != null)
+ field.value.setLocationDeep(loc);
}
}
return compile(context);\r
}\r
\r
+ @Override\r
+ public Expression checkIgnoredType(TypingContext context) {\r
+ checkRuleTypes(context);\r
+ in = in.checkIgnoredType(context);\r
+ return compile(context);\r
+ }\r
+ \r
@Override\r
public void collectFreeVariables(THashSet<Variable> vars) {\r
for(DatalogRule rule : rules) {\r
import static org.simantics.scl.compiler.elaboration.expressions.Expressions.seq;\r
import static org.simantics.scl.compiler.elaboration.expressions.Expressions.tuple;\r
import static org.simantics.scl.compiler.elaboration.expressions.Expressions.var;\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.common.names.Name;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
import org.simantics.scl.compiler.types.kinds.Kinds;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class ESelect extends SimplifiableExpression {\r
\r
private final Type ARRAY_LIST = Types.con("ArrayList", "T"); \r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import java.util.ArrayList;\r
\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.types.kinds.Kinds;\r
import org.simantics.scl.compiler.types.util.MultiFunction;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class ESimpleLambda extends Expression {\r
public Variable parameter;\r
public Expression value;\r
\r
private void checkBinding(TypingContext context) {\r
if(variable == null)\r
- value = value.inferType(context);\r
+ value = value.checkIgnoredType(context);\r
else if(variable.getType() == null) {\r
value = value.inferType(context);\r
variable.setType(value.getType());\r
in = in.checkType(context, requiredType);\r
return this;\r
}\r
+ \r
+ @Override\r
+ public Expression checkIgnoredType(TypingContext context) {\r
+ checkBinding(context);\r
+ in = in.checkIgnoredType(context);\r
+ return this;\r
+ }\r
\r
@Override\r
public Expression decorate(ExpressionDecorator decorator) {\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import java.util.ArrayList;\r
import java.util.Collections;\r
import java.util.Comparator;\r
import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class ETransformation extends SimplifiableExpression {\r
public static final Object TRANSFORMATION_RULES_TYPECHECKED = new Object();\r
\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;\r
import org.simantics.scl.compiler.types.Type;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class ETypeAnnotation extends SimplifiableExpression {\r
Expression value;\r
Type type;\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import java.util.ArrayList;\r
\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.types.kinds.Kinds;\r
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class EVariable extends Expression {\r
public static final EVariable[] EMPTY_ARRAY = new EVariable[0];\r
\r
\r
@Override\r
public Expression inferType(TypingContext context) {\r
- if(context.isInPattern())\r
+ if(context.isInPattern()) {\r
variable.setType(Types.metaVar(Kinds.STAR));\r
- return this;\r
+ return this;\r
+ }\r
+ else\r
+ return applyPUnit(context);\r
}\r
\r
@Override\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.types.exceptions.UnificationException;\r
import org.simantics.scl.compiler.types.kinds.Kinds;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class EWhen extends SimplifiableExpression {\r
\r
public Query query;\r
for(Variable variable : variables)\r
variable.setType(Types.metaVar(Kinds.STAR));\r
query.checkType(context);\r
- action.checkType(context, Types.UNIT);\r
+ action.checkIgnoredType(context);\r
\r
// Compile query\r
return compile(context);\r
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import java.util.ArrayList;\r
\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.common.precedence.Precedence;\r
+import org.simantics.scl.compiler.constants.NoRepConstant;\r
+import org.simantics.scl.compiler.elaboration.contexts.EnvironmentalContext;\r
import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.types.kinds.Kinds;\r
import org.simantics.scl.compiler.types.util.Typed;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public abstract class Expression extends Symbol implements Typed {\r
public static final Expression[] EMPTY_ARRAY = new Expression[0];\r
\r
public Expression inferType(TypingContext context) {\r
return checkBasicType(context, Types.metaVar(Kinds.STAR));\r
}\r
- \r
- public Expression checkBasicType(TypingContext context, Type requiredType) {\r
- return context.subsume(inferType(context), requiredType);\r
- }\r
+\r
+ public Expression checkBasicType(TypingContext context, Type requiredType) {\r
+ return context.subsume(inferType(context), requiredType);\r
+ }\r
+ \r
+ protected Expression applyPUnit(EnvironmentalContext context) {\r
+ Type type = Types.canonical(getType());\r
+ if(type instanceof TFun) {\r
+ TFun fun = (TFun)type;\r
+ if(fun.getCanonicalDomain() == Types.PUNIT) {\r
+ EApply result = new EApply(location, this, new ELiteral(NoRepConstant.PUNIT));\r
+ result.effect = fun.getCanonicalEffect();\r
+ return result;\r
+ }\r
+ }\r
+ return this;\r
+ }\r
+\r
+ public Expression checkIgnoredType(TypingContext context) {\r
+ Expression expression = inferType(context);\r
+ if(Types.canonical(expression.getType()) != Types.UNIT)\r
+ expression = new ESimpleLet(location, null, expression, new ELiteral(NoRepConstant.PUNIT));\r
+ return expression;\r
+ }\r
\r
/**\r
* Checks the type of the expression against the given type. Adds type\r
public final Expression checkType(TypingContext context, Type requiredType) {\r
//System.out.println("checkType: " + this + " :: " + requiredType);\r
if(!context.isInPattern()) {\r
- requiredType = Types.weakCanonical(requiredType);\r
+ requiredType = Types.canonical(requiredType);\r
if(requiredType instanceof TForAll) {\r
TForAll forAll = (TForAll)requiredType;\r
TVar var = forAll.var;\r
public interface ExpressionTransformer {
+ Expression transform(EAmbiguous expression);
Expression transform(EApply expression);
Expression transform(EApplyType expression);
Expression transform(EAsPattern expression);
package org.simantics.scl.compiler.elaboration.expressions;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
-import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.errors.Locations;\r
import org.simantics.scl.compiler.internal.codegen.continuations.ICont;\r
import org.simantics.scl.compiler.internal.codegen.references.IVal;\r
+import org.simantics.scl.compiler.internal.codegen.ssa.exits.Throw;\r
import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;\r
import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;\r
import org.simantics.scl.compiler.types.Type;\r
import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class GuardedExpressionGroup extends Expression {\r
public GuardedExpression[] expressions;\r
\r
CodeWriter failure = w.createBlock();\r
compile(env, w, success.getContinuation(), failure.getContinuation());\r
w.continueAs(success);\r
- failure.throw_(location, "Matching failure at: " + toString());\r
+ failure.throw_(location, Throw.MatchingException, "Matching failure at: " + toString());\r
return result;\r
//throw new InternalCompilerError("GuardedExpressionGroup should be handled in match compilation.");\r
}\r
ExpressionTransformer, QueryTransformer, ListQualifierTransformer, StatementVisitor,
EquationVisitor {
+ @Override
+ public Expression transform(EAmbiguous expression) {
+ return expression;
+ }
+
@Override
public Expression transform(EApply expression) {
expression.function = expression.function.accept(this);
package org.simantics.scl.compiler.elaboration.expressions.accessor;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;\r
import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;\r
import org.simantics.scl.compiler.types.Types;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class ExpressionAccessor extends FieldAccessor {\r
public Expression fieldName;\r
\r
package org.simantics.scl.compiler.elaboration.expressions.accessor;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;\r
import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;\r
import org.simantics.scl.compiler.internal.parsing.Symbol;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public abstract class FieldAccessor extends Symbol {\r
public char accessSeparator;\r
\r
\r
@Override\r
public Expression toExpression(EnvironmentalContext context, boolean monadic, Expression in) {\r
- Variable var = new Variable("_");\r
- if(monadic)\r
+ if(monadic) {\r
+ Variable var = new Variable("_");\r
return new EBind(location, new EVariable(location, var), value, in);\r
+ }\r
else\r
- return new ESimpleLet(location, var, value, in);\r
+ return new ESimpleLet(location, null, value, in);\r
}\r
\r
@Override\r
package org.simantics.scl.compiler.elaboration.expressions.list;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;\r
import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;\r
import org.simantics.scl.compiler.types.Type;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class ListAssignment extends ListQualifier {\r
public Expression pattern;\r
public Expression value;\r
package org.simantics.scl.compiler.elaboration.expressions.list;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;\r
import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.kinds.Kinds;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class ListGenerator extends ListQualifier {\r
public Expression pattern;\r
public Expression value;\r
package org.simantics.scl.compiler.elaboration.expressions.list;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;\r
import org.simantics.scl.compiler.types.Type;\r
import org.simantics.scl.compiler.types.Types;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class ListGuard extends ListQualifier {\r
public Expression condition;\r
\r
package org.simantics.scl.compiler.elaboration.expressions.list;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;\r
import org.simantics.scl.compiler.internal.parsing.Symbol;\r
import org.simantics.scl.compiler.types.Type;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public abstract class ListQualifier extends Symbol {\r
\r
public abstract void checkType(TypingContext context);\r
package org.simantics.scl.compiler.elaboration.expressions.list;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;\r
import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;\r
import org.simantics.scl.compiler.types.Type;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class ListSeq extends ListQualifier {\r
public ListQualifier a;\r
public ListQualifier b;\r
package org.simantics.scl.compiler.elaboration.expressions.list;\r
\r
-import gnu.trove.map.hash.TObjectIntHashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;\r
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;\r
import org.simantics.scl.compiler.types.exceptions.UnificationException;\r
import org.simantics.scl.compiler.types.kinds.Kinds;\r
\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class ListThen extends ListQualifier {\r
public ListQualifier left;\r
public Expression transformer;\r
import org.simantics.scl.compiler.elaboration.expressions.EAsPattern;\r
import org.simantics.scl.compiler.elaboration.expressions.EBind;\r
import org.simantics.scl.compiler.elaboration.expressions.EConstant;\r
+import org.simantics.scl.compiler.elaboration.expressions.ECoveringBranchPoint;\r
import org.simantics.scl.compiler.elaboration.expressions.EEnforce;\r
import org.simantics.scl.compiler.elaboration.expressions.EEquations;\r
import org.simantics.scl.compiler.elaboration.expressions.EError;\r
import org.simantics.scl.compiler.elaboration.expressions.ELiteral;\r
import org.simantics.scl.compiler.elaboration.expressions.EMatch;\r
import org.simantics.scl.compiler.elaboration.expressions.EPlaceholder;\r
-import org.simantics.scl.compiler.elaboration.expressions.ECoveringBranchPoint;\r
import org.simantics.scl.compiler.elaboration.expressions.ERealLiteral;\r
import org.simantics.scl.compiler.elaboration.expressions.ERuleset;\r
import org.simantics.scl.compiler.elaboration.expressions.ESelect;\r
ESimpleLet let = (ESimpleLet)expression;\r
Variable variable = let.getVariable();\r
Expression value = let.getValue();\r
- if("_".equals(variable.getName()))\r
+ if(variable == null || "_".equals(variable.getName()))\r
printAsDo(value);\r
else {\r
newLine();\r
package org.simantics.scl.compiler.elaboration.java;
-import static org.simantics.scl.compiler.elaboration.expressions.Expressions.*;
+import static org.simantics.scl.compiler.elaboration.expressions.Expressions.apply;
+import static org.simantics.scl.compiler.elaboration.expressions.Expressions.constant;
+import static org.simantics.scl.compiler.elaboration.expressions.Expressions.string;
+import static org.simantics.scl.compiler.elaboration.expressions.Expressions.var;
import org.cojen.classfile.TypeDesc;
import org.simantics.scl.compiler.constants.generic.CallJava;
package org.simantics.scl.compiler.elaboration.macros;
-import gnu.trove.map.hash.THashMap;
-
import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
import org.simantics.scl.compiler.elaboration.expressions.EApply;
import org.simantics.scl.compiler.types.TVar;
import org.simantics.scl.compiler.types.Type;
+import gnu.trove.map.hash.THashMap;
+
/**
* This is a macro rule that replaces an application with
* the definition of the function.
package org.simantics.scl.compiler.elaboration.modules;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-\r
import java.util.ArrayList;\r
\r
import org.cojen.classfile.TypeDesc;\r
import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.kinds.Kinds;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+\r
public class TypeClass extends TypeConstructor {\r
public final TPred[] context;\r
public final TCon name;\r
package org.simantics.scl.compiler.elaboration.modules;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-\r
import org.simantics.scl.compiler.constants.Constant;\r
import org.simantics.scl.compiler.elaboration.errors.ElabNode;\r
import org.simantics.scl.compiler.types.TPred;\r
import org.simantics.scl.compiler.types.TVar;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+\r
public class TypeClassInstance extends ElabNode {\r
public final TypeClass typeClass;\r
public final TPred[] context; \r
package org.simantics.scl.compiler.elaboration.query;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-import gnu.trove.set.hash.TIntHashSet;
-
import java.util.Arrays;
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
import org.simantics.scl.compiler.elaboration.query.pre.QPreExists;
import org.simantics.scl.compiler.elaboration.query.pre.QPreGuard;
import org.simantics.scl.compiler.errors.Locations;
-import org.simantics.scl.compiler.types.Type;
+
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.THashSet;
+import gnu.trove.set.hash.TIntHashSet;
public abstract class QAbstractCombiner extends Query {
public Query[] queries;
package org.simantics.scl.compiler.elaboration.query;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-import gnu.trove.set.hash.TIntHashSet;
-
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
import org.simantics.scl.compiler.elaboration.expressions.Variable;
import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure;
import org.simantics.scl.compiler.errors.Locations;
-import org.simantics.scl.compiler.types.Type;
+
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.THashSet;
+import gnu.trove.set.hash.TIntHashSet;
public abstract class QAbstractModifier extends Query {
public Query query;
package org.simantics.scl.compiler.elaboration.query;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.map.hash.TIntObjectHashMap;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-import gnu.trove.set.hash.TIntHashSet;
-
import java.util.ArrayList;
import java.util.Set;
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.Types;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.map.hash.TIntObjectHashMap;
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.THashSet;
+import gnu.trove.set.hash.TIntHashSet;
+
public class QAtom extends Query {
public SCLRelation relation;
public Type[] typeParameters;
public Expression[] parameters;
-
+
public QAtom(SCLRelation relation, Expression ... parameters) {
this.relation = relation;
this.parameters = parameters;
}
-
+
public QAtom(SCLRelation relation, Type[] typeParameters, Expression ... parameters) {
this.relation = relation;
this.typeParameters = typeParameters;
for(Expression parameter : parameters)
parameter.collectFreeVariables(vars);
}
-
+
@Override
public void checkType(TypingContext context) {
// Type parameters
typeParameters = new Type[typeVariables.length];
for(int i=0;i<typeVariables.length;++i)
typeParameters[i] = Types.metaVar(typeVariables[i].getKind());
-
+
// Check parameter types
Type[] parameterTypes = relation.getParameterTypes();
if(parameterTypes.length != parameters.length)
parameters[i] = parameters[i]
.checkType(context, parameterTypes[i].replace(typeVariables, typeParameters));
}
-
+
public Expression generateEnforce(EnforcingContext context) {
Variable[] variables = new Variable[parameters.length];
for(int i=0;i<variables.length;++i)
private static class VariableMaskProcedure implements VariableProcedure {
ConstraintCollectionContext context;
long requiredVariablesMask = 0L;
-
+
public VariableMaskProcedure(ConstraintCollectionContext context) {
this.context = context;
}
requiredVariablesMask |= 1L << id;
}
}
-
+
@Override
public void collectConstraints(ConstraintCollectionContext context) {
try {
}
}
}
-
+
// Combine required and optional variables
TIntHashSet allVariablesSet = new TIntHashSet();
for(int v : optionalVariableByParameter)
if(v >= 0)
allVariablesSet.add(v);
-
+
context.addConstraint(new RelationConstraint(allVariablesSet.toArray(), varParameters, this,
optionalVariableByParameter, procedure.requiredVariablesMask));
} catch(Exception e) {
context.getQueryCompilationContext().getTypingContext().getErrorLog().log(location, e);
}
}
-
+
private static void collectRefs(SCLRelation relation, TObjectIntHashMap<Object> allRefs,
TIntHashSet refs) {
if(relation instanceof CompositeRelation) {
for(Expression parameter : parameters)
parameter.collectRefs(allRefs, refs);
}
-
+
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
return new Diff[] { new Diff(diffable.id, new QConjunction(eqs)) };
}
}
-
+
private static boolean containsReferenceTo(
CompositeRelation relation,
THashMap<SCLRelation, Diffable> diffables) {
else
return this;
}
-
+
@Override
public void setLocationDeep(long loc) {
if(location == Locations.NO_LOCATION) {
parameter.setLocationDeep(loc);
}
}
-
+
@Override
public void accept(QueryVisitor visitor) {
visitor.visit(this);
}
list.add(this);
}
-
+
@Override
public Query accept(QueryTransformer transformer) {
return transformer.transform(this);
package org.simantics.scl.compiler.elaboration.query;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.map.hash.TIntObjectHashMap;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
import org.simantics.scl.compiler.types.Types;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.map.hash.TIntObjectHashMap;
+
public class QConjunction extends QAbstractCombiner {
package org.simantics.scl.compiler.elaboration.query;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.map.hash.TLongObjectHashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
import java.util.ArrayList;
import java.util.Set;
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.types.Types;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.map.hash.TLongObjectHashMap;
+import gnu.trove.set.hash.TIntHashSet;
+
public class QDisjunction extends QAbstractCombiner {
package org.simantics.scl.compiler.elaboration.query;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.Collection;
import java.util.Set;
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.kinds.Kinds;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
+
public class QExists extends QAbstractModifier {
Variable[] variables;
package org.simantics.scl.compiler.elaboration.query;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-import gnu.trove.set.hash.TIntHashSet;
-
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.types.Type;
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.THashSet;
+import gnu.trove.set.hash.TIntHashSet;
+
public class QMapping extends Query {
public final MappingRelation mappingRelation;
public final Expression[] parameters;
package org.simantics.scl.compiler.elaboration.query;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.TIntHashSet;
-
import org.simantics.scl.compiler.common.names.Name;
import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
import org.simantics.scl.compiler.elaboration.expressions.EApply;
import org.simantics.scl.compiler.elaboration.relations.LocalRelation;
import org.simantics.scl.compiler.types.Type;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.TIntHashSet;
+
public class QNegation extends QAbstractModifier {
package org.simantics.scl.compiler.elaboration.query;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.map.hash.TIntObjectHashMap;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-import gnu.trove.set.hash.TIntHashSet;
-
import java.util.ArrayList;
import java.util.Set;
import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
import org.simantics.scl.compiler.internal.parsing.Symbol;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.map.hash.TIntObjectHashMap;
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.THashSet;
+import gnu.trove.set.hash.TIntHashSet;
+
public abstract class Query extends Symbol {
public static final Query[] EMPTY_ARRAY = new Query[0];
package org.simantics.scl.compiler.elaboration.query.compilation;
-import gnu.trove.impl.Constants;
-import gnu.trove.map.hash.TObjectIntHashMap;
-
import java.util.ArrayList;
import org.simantics.scl.compiler.elaboration.expressions.Variable;
+import gnu.trove.impl.Constants;
+import gnu.trove.map.hash.TObjectIntHashMap;
+
public class ConstraintCollectionContext {
QueryCompilationContext context;
ArrayList<Variable> variables = new ArrayList<Variable>();
package org.simantics.scl.compiler.elaboration.query.compilation;
-import gnu.trove.map.hash.TLongObjectHashMap;
-import gnu.trove.procedure.TLongObjectProcedure;
-
import java.util.ArrayList;
import java.util.Collections;
+import gnu.trove.map.hash.TLongObjectHashMap;
+import gnu.trove.procedure.TLongObjectProcedure;
+
public class DynamicProgrammingOrdering {
final ConstraintCollectionContext collectionContext;
int variableCount;
package org.simantics.scl.compiler.elaboration.query.compilation;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-import gnu.trove.procedure.TObjectObjectProcedure;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
import java.util.ArrayList;\r
\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.types.TVar;\r
import org.simantics.scl.compiler.types.Type;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+import gnu.trove.procedure.TObjectObjectProcedure;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
public class ExpressionConstraint extends QueryConstraint {\r
Variable variable;\r
Expression expression;\r
package org.simantics.scl.compiler.elaboration.query.pre;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-import gnu.trove.set.hash.TIntHashSet;
-
import java.util.ArrayList;
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.elaboration.query.Query;
import org.simantics.scl.compiler.elaboration.query.QueryVisitor;
import org.simantics.scl.compiler.elaboration.query.compilation.ConstraintCollectionContext;
-import org.simantics.scl.compiler.types.Type;
+
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.THashSet;
+import gnu.trove.set.hash.TIntHashSet;
/**
* Query classes that may exist before resolving
package org.simantics.scl.compiler.elaboration.relations;
-import static org.simantics.scl.compiler.elaboration.expressions.Expressions.*;
+import static org.simantics.scl.compiler.elaboration.expressions.Expressions.apply;
+import static org.simantics.scl.compiler.elaboration.expressions.Expressions.newVar;
+import static org.simantics.scl.compiler.elaboration.expressions.Expressions.tuple;
+import static org.simantics.scl.compiler.elaboration.expressions.Expressions.var;
+import static org.simantics.scl.compiler.elaboration.expressions.Expressions.vars;
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.common.names.Name;
import org.simantics.scl.compiler.elaboration.expressions.Variable;
import org.simantics.scl.compiler.elaboration.query.compilation.EnforcingContext;
import org.simantics.scl.compiler.elaboration.query.compilation.QueryCompilationContext;
-import org.simantics.scl.compiler.types.TPred;
import org.simantics.scl.compiler.types.TVar;
import org.simantics.scl.compiler.types.Type;
import static org.simantics.scl.compiler.elaboration.expressions.Expressions.var;
import org.simantics.scl.compiler.common.names.Name;
-import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
import org.simantics.scl.compiler.elaboration.expressions.EApply;
import org.simantics.scl.compiler.elaboration.expressions.EVariable;
import org.simantics.scl.compiler.elaboration.expressions.Expression;
import org.simantics.scl.compiler.elaboration.expressions.Variable;
import org.simantics.scl.compiler.elaboration.query.compilation.QueryCompilationContext;
-import org.simantics.scl.compiler.errors.Locations;
-import org.simantics.scl.compiler.types.TPred;
import org.simantics.scl.compiler.types.TVar;
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.Types;
package org.simantics.scl.compiler.elaboration.rules;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.procedure.TObjectObjectProcedure;
-import gnu.trove.procedure.TObjectProcedure;
-import gnu.trove.set.hash.THashSet;
-
import org.simantics.scl.compiler.common.names.Name;
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
import org.simantics.scl.compiler.elaboration.expressions.Variable;
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.kinds.Kinds;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.procedure.TObjectObjectProcedure;
+import gnu.trove.procedure.TObjectProcedure;
+import gnu.trove.set.hash.THashSet;
+
public class TransformationRule extends Symbol {
public static final TransformationRule[] EMPTY_ARRAY = new TransformationRule[0];
package org.simantics.scl.compiler.environment;\r
\r
-import gnu.trove.procedure.TObjectProcedure;\r
-\r
import org.simantics.scl.compiler.elaboration.expressions.ESimpleLambda;\r
import org.simantics.scl.compiler.elaboration.expressions.Expression;\r
import org.simantics.scl.compiler.elaboration.expressions.Variable;\r
import org.simantics.scl.compiler.types.Type;\r
-import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.util.ProcedureType;\r
\r
+import gnu.trove.procedure.TObjectProcedure;\r
+\r
public abstract class AbstractLocalEnvironment implements LocalEnvironment {\r
\r
@Override\r
package org.simantics.scl.compiler.environment;
-import gnu.trove.map.hash.THashMap;
-
import java.util.Collection;
import org.simantics.scl.compiler.elaboration.rules.TransformationRule;
import org.simantics.scl.compiler.module.Module;
+import gnu.trove.map.hash.THashMap;
+
public class ConcreteEnvironment extends AbstractEnvironment {
private final THashMap<String, Module> moduleMap;
package org.simantics.scl.compiler.environment;
-import gnu.trove.procedure.TObjectProcedure;
-
import java.util.function.Consumer;
import org.simantics.scl.compiler.elaboration.modules.SCLValue;
import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor;
import org.simantics.scl.compiler.types.TCon;
+import gnu.trove.procedure.TObjectProcedure;
+
public enum EmptyNamespace implements Namespace {
INSTANCE;
package org.simantics.scl.compiler.environment;
-import gnu.trove.procedure.TObjectProcedure;
-
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import org.simantics.scl.compiler.types.TCon;
import org.simantics.scl.compiler.types.Type;
+import gnu.trove.procedure.TObjectProcedure;
+
public class Environments {
/**
* Get the SCLValue object representing an SCL value defined in a given environment.
package org.simantics.scl.compiler.environment;\r
\r
-import gnu.trove.procedure.TObjectProcedure;\r
-\r
import org.simantics.scl.compiler.elaboration.expressions.Expression;\r
import org.simantics.scl.compiler.types.Type;\r
import org.simantics.scl.compiler.types.util.ProcedureType;\r
\r
+import gnu.trove.procedure.TObjectProcedure;\r
+\r
/**\r
* Provides local variable names for expressions\r
* that do not need to defined in any module.\r
package org.simantics.scl.compiler.environment;
-import gnu.trove.procedure.TObjectProcedure;
-
import java.util.function.Consumer;
import org.simantics.scl.compiler.elaboration.modules.SCLValue;
import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor;
import org.simantics.scl.compiler.types.TCon;
+import gnu.trove.procedure.TObjectProcedure;
+
public interface Namespace {
/**
* Find a sub-namespace with a given name
package org.simantics.scl.compiler.environment;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.procedure.TObjectProcedure;
-
import java.util.ArrayList;
import java.util.function.Consumer;
import org.simantics.scl.compiler.module.Module;
import org.simantics.scl.compiler.types.TCon;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.procedure.TObjectProcedure;
+
public class NamespaceImpl implements Namespace {
private final THashMap<String, Namespace> namespaceMap;
package org.simantics.scl.compiler.environment;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-\r
import java.util.Map;\r
\r
import org.simantics.scl.compiler.environment.NamespaceImpl.ModuleImport;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+\r
public class NamespaceSpec {\r
public final THashMap<String, NamespaceSpec> namespaceMap = new THashMap<String, NamespaceSpec>();\r
public final THashMap<String, ModuleImport> moduleMap = new THashMap<String, ModuleImport>();\r
package org.simantics.scl.compiler.environment.filter;\r
\r
-import gnu.trove.set.hash.THashSet;\r
-\r
import org.simantics.scl.compiler.elaboration.expressions.EVar;\r
import org.simantics.scl.compiler.module.ImportDeclaration.ImportSpec;\r
\r
+import gnu.trove.set.hash.THashSet;\r
+\r
public class NamespaceFilters {\r
public static NamespaceFilter createFromSpec(ImportSpec spec) {\r
if(spec.hiding) {\r
package org.simantics.scl.compiler.errors;
-import gnu.trove.list.array.TIntArrayList;
-
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
+import gnu.trove.list.array.TIntArrayList;
+
public class CompilationErrorFormatter {
public static int[] rows(Reader reader) throws IOException {
package org.simantics.scl.compiler.internal.codegen.analysis;\r
\r
-import gnu.trove.set.hash.THashSet;\r
-\r
import org.simantics.scl.compiler.common.names.Name;\r
import org.simantics.scl.compiler.constants.SCLConstant;\r
import org.simantics.scl.compiler.internal.codegen.references.Val;\r
import org.simantics.scl.compiler.internal.codegen.ssa.binders.ValRefBinder;\r
import org.simantics.scl.compiler.internal.codegen.ssa.statements.LetApply;\r
\r
+import gnu.trove.set.hash.THashSet;\r
+\r
public class LoopAnalysis {\r
\r
/**\r
package org.simantics.scl.compiler.internal.codegen.analysis;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.common.names.Name;\r
import org.simantics.scl.compiler.constants.SCLConstant;\r
import org.simantics.scl.compiler.internal.codegen.ssa.binders.ValRefBinder;\r
import org.simantics.scl.compiler.internal.codegen.ssa.statements.LetApply;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+\r
public abstract class StatementBrowser {\r
\r
THashSet<SSABlock> visited;\r
package org.simantics.scl.compiler.internal.codegen.optimization;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-\r
import org.simantics.scl.compiler.common.names.Name;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+\r
public class OptimizationMap {\r
\r
public static final THashMap<Name, Optimization> OPTIMIZATIONS = new THashMap<Name, Optimization>();\r
package org.simantics.scl.compiler.internal.codegen.references;
-import gnu.trove.map.hash.THashMap;
-
import org.cojen.classfile.TypeDesc;
import org.simantics.scl.compiler.internal.codegen.ssa.SSAFunction;
import org.simantics.scl.compiler.internal.codegen.ssa.binders.BoundVarBinder;
import org.simantics.scl.compiler.types.TVar;
import org.simantics.scl.compiler.types.Type;
+import gnu.trove.map.hash.THashMap;
+
public final class BoundVar extends Val {
public BoundVarBinder parent;
Type type;
package org.simantics.scl.compiler.internal.codegen.references;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.internal.codegen.types.BTypes;\r
import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;\r
import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+\r
\r
public abstract class Val implements IVal {\r
\r
import org.simantics.scl.compiler.internal.codegen.ssa.SSABlock;
import org.simantics.scl.compiler.internal.codegen.ssa.SSAExit;
import org.simantics.scl.compiler.internal.codegen.ssa.SSAFunction;
+import org.simantics.scl.compiler.internal.codegen.utils.Constants;
import org.simantics.scl.compiler.internal.codegen.utils.CopyContext;
import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
import org.simantics.scl.compiler.internal.codegen.utils.PrintingContext;
import org.simantics.scl.compiler.internal.codegen.utils.SSAValidationContext;
import org.simantics.scl.compiler.types.TVar;
import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.runtime.exceptions.MatchingException;
public class Throw extends SSAExit {
- private static final TypeDesc RuntimeException =
+ public static final TypeDesc RuntimeException =
TypeDesc.forClass(RuntimeException.class);
+ public static final TypeDesc MatchingException =
+ TypeDesc.forClass(MatchingException.class);
+ TypeDesc exceptionClass;
String description;
- public Throw(String description) {
+ public Throw(TypeDesc exceptionClass, String description) {
+ this.exceptionClass = exceptionClass;
this.description = description;
}
public void generateCode(MethodBuilder mb) {
//mb.push(exception.getBinding());
//cb.mapLineNumber(location);
- mb.newObject(RuntimeException);
+ mb.newObject(exceptionClass);
mb.dup();
- mb.loadConstant(description);
- mb.invokeConstructor(RuntimeException, new TypeDesc[] {TypeDesc.STRING});
+ if(description == null)
+ mb.invokeConstructor(exceptionClass, Constants.EMPTY_TYPEDESC_ARRAY);
+ else {
+ mb.loadConstant(description);
+ mb.invokeConstructor(exceptionClass, new TypeDesc[] {TypeDesc.STRING});
+ }
mb.throwObject();
}
@Override
public SSAExit copy(CopyContext context) {
- return new Throw(description);
+ return new Throw(exceptionClass, description);
}
@Override
import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.exceptions.MatchException;\r
import org.simantics.scl.compiler.types.util.MultiFunction;\r
-import org.simantics.scl.compiler.types.util.TypeUnparsingContext;\r
\r
public class LetApply extends LetStatement implements ValRefBinder {\r
private ValRef function;\r
package org.simantics.scl.compiler.internal.codegen.ssa.statements;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-\r
import java.util.ArrayList;\r
\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.types.TVar;\r
import org.simantics.scl.compiler.types.Type;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+\r
public class LetFunctions extends SSAStatement implements FunctionBinder {\r
long recursiveGroupLocation;\r
SSAFunction firstFunction;\r
return new MethodBuilder(this, moduleBuilder, (access&Opcodes.ACC_STATIC) != 0, methodVisitor, params);
}
- private MethodVisitor augmentMethodVisitor(String methodName, MethodVisitor methodVisitor) {
+ private MethodVisitor augmentMethodVisitor(final String methodName, MethodVisitor methodVisitor) {
if(SCLCompilerConfiguration.TRACE_MAX_METHOD_SIZE && moduleBuilder != null) {
methodVisitor = new CodeSizeEvaluator(methodVisitor) {
@Override
package org.simantics.scl.compiler.internal.codegen.utils;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-\r
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
import org.simantics.scl.compiler.internal.codegen.continuations.Cont;\r
import org.simantics.scl.compiler.internal.codegen.continuations.ContRef;\r
import org.simantics.scl.compiler.types.Type;\r
import org.simantics.scl.compiler.types.Types;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+\r
public class CopyContext {\r
\r
THashMap<Val, Val> valMap = new THashMap<Val, Val>();\r
package org.simantics.scl.compiler.internal.codegen.utils;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-\r
import java.util.ArrayDeque;\r
import java.util.ArrayList;\r
\r
import org.simantics.scl.compiler.types.Type;\r
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+\r
public class PrintingContext {\r
\r
THashMap<Object, String> names = new THashMap<Object, String>(); \r
package org.simantics.scl.compiler.internal.codegen.utils;
-import org.simantics.scl.compiler.internal.codegen.utils.LocalVariable;
import org.cojen.classfile.TypeDesc;
import org.simantics.scl.runtime.SCLContext;
package org.simantics.scl.compiler.internal.codegen.utils;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.procedure.TObjectIntProcedure;
-import gnu.trove.set.hash.THashSet;
-
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.constants.Constant;
import org.simantics.scl.compiler.constants.SCLConstant;
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.procedure.TObjectIntProcedure;
+import gnu.trove.set.hash.THashSet;
+
public class SSAValidationContext {
public THashSet<BoundVar> validBoundVariables = new THashSet<BoundVar>();
-package org.simantics.scl.compiler.internal.codegen.writer;\r
-\r
-import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;\r
-import org.simantics.scl.compiler.internal.codegen.continuations.Branch;\r
-import org.simantics.scl.compiler.internal.codegen.continuations.BranchRef;\r
-import org.simantics.scl.compiler.internal.codegen.continuations.ICont;\r
-import org.simantics.scl.compiler.internal.codegen.references.BoundVar;\r
-import org.simantics.scl.compiler.internal.codegen.references.IVal;\r
-import org.simantics.scl.compiler.internal.codegen.references.ValRef;\r
-import org.simantics.scl.compiler.internal.codegen.ssa.SSABlock;\r
-import org.simantics.scl.compiler.internal.codegen.ssa.SSAFunction;\r
-import org.simantics.scl.compiler.internal.codegen.ssa.exits.If;\r
-import org.simantics.scl.compiler.internal.codegen.ssa.exits.Jump;\r
-import org.simantics.scl.compiler.internal.codegen.ssa.exits.Switch;\r
-import org.simantics.scl.compiler.internal.codegen.ssa.exits.Throw;\r
-import org.simantics.scl.compiler.internal.codegen.ssa.statements.LetApply;\r
-import org.simantics.scl.compiler.internal.codegen.ssa.statements.LetFunctions;\r
-import org.simantics.scl.compiler.top.SCLCompilerConfiguration;\r
-import org.simantics.scl.compiler.types.TVar;\r
-import org.simantics.scl.compiler.types.Type;\r
-import org.simantics.scl.compiler.types.Types;\r
-import org.simantics.scl.compiler.types.exceptions.MatchException;\r
-import org.simantics.scl.compiler.types.util.MultiFunction;\r
-\r
-public class CodeWriter {\r
-\r
- ModuleWriter moduleWriter;\r
- SSABlock block;\r
- \r
- CodeWriter(ModuleWriter moduleWriter, SSABlock block) {\r
- this.moduleWriter = moduleWriter;\r
- this.block = block;\r
- }\r
-\r
- public IVal apply(int lineNumber, IVal function, IVal ... parameters) {\r
- try {\r
- MultiFunction mfun = Types.matchFunction(function.getType(), parameters.length);\r
- return applyWithEffect(lineNumber,\r
- mfun.effect,\r
- mfun.returnType,\r
- function, parameters);\r
- } catch (MatchException e) {\r
- throw new InternalCompilerError(e);\r
- }\r
- }\r
- \r
- public IVal applyWithEffectChecked(int lineNumber, Type effect, Type returnType, IVal function, IVal ... parameters) {\r
- try {\r
- MultiFunction mfun = Types.matchFunction(function.getType(), parameters.length);\r
- if(!Types.equals(effect, mfun.effect))\r
- throw new InternalCompilerError();\r
- if(!Types.equals(returnType, mfun.returnType))\r
- throw new InternalCompilerError();\r
- } catch (MatchException e) {\r
- throw new InternalCompilerError(e);\r
- } \r
- return applyWithEffect(lineNumber, effect, returnType, function, parameters);\r
- }\r
- \r
- public IVal applyWithEffect(long location, Type effect, Type returnType, IVal function, IVal ... parameters) {\r
- BoundVar var = new BoundVar(returnType);\r
- LetApply apply = new LetApply(var,\r
- effect,\r
- function.createOccurrence(), \r
- ValRef.createOccurrences(parameters));\r
- apply.location = location;\r
- block.addStatement(apply);\r
- return var;\r
- }\r
- \r
- public CodeWriter createBlock(Type ... parameterTypes) {\r
- SSABlock newBlock = new SSABlock(parameterTypes);\r
- block.getParent().addBlock(newBlock);\r
- return new CodeWriter(moduleWriter, newBlock);\r
- }\r
- \r
- public CodeWriter createFunction(TVar[] typeParameters, Type effect, Type returnType, Type[] parameterTypes) {\r
- if(SCLCompilerConfiguration.DEBUG)\r
- if(effect == null)\r
- throw new InternalCompilerError();\r
- SSAFunction function = new SSAFunction(typeParameters, effect, returnType);\r
- SSABlock block = new SSABlock(parameterTypes);\r
- function.addBlock(block);\r
- BoundVar target = new BoundVar(function.getType());\r
- function.setTarget(target);\r
- \r
- this.block.addStatement(new LetFunctions(function));\r
- return new CodeWriter(moduleWriter, block);\r
- }\r
- \r
- public RecursiveDefinitionWriter createRecursiveDefinition() {\r
- LetFunctions let = new LetFunctions();\r
- block.addStatement(let);\r
- return new RecursiveDefinitionWriter(moduleWriter, let);\r
- }\r
- \r
- public void continueAs(CodeWriter codeWriter) {\r
- this.block = codeWriter.block;\r
- codeWriter.block = null;\r
- }\r
- \r
- public IVal[] getParameters() {\r
- return block.getParameters();\r
- }\r
- \r
- public ICont getContinuation() {\r
- return block;\r
- }\r
- \r
- public void jump(ICont cont, IVal ... parameters) {\r
- block.setExit(new Jump(cont.createOccurrence(), \r
- ValRef.createOccurrences(parameters)));\r
- block = null;\r
- }\r
- \r
- public void if_(IVal condition, ICont thenTarget, ICont elseTarget) {\r
- block.setExit(new If(condition.createOccurrence(), \r
- thenTarget.createOccurrence(), \r
- elseTarget.createOccurrence()));\r
- block = null;\r
- }\r
-\r
- public void return_(IVal val) {\r
- jump(block.getParent().getReturnCont(), val);\r
- }\r
-\r
- public void switch_(IVal val, Branch[] branches) {\r
- block.setExit(new Switch(val.createOccurrence(), BranchRef.toBranchRefs(branches)));\r
- block = null;\r
- }\r
-\r
- public void throw_(long location, String description) {\r
- Throw exit = new Throw(description);\r
- exit.location = location;\r
- block.setExit(exit);\r
- block = null;\r
- }\r
- \r
- public ModuleWriter getModuleWriter() {\r
- return moduleWriter;\r
- }\r
-\r
- public SSAFunction getFunction() {\r
- return block.getParent();\r
- } \r
-}\r
+package org.simantics.scl.compiler.internal.codegen.writer;
+
+import org.cojen.classfile.TypeDesc;
+import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
+import org.simantics.scl.compiler.internal.codegen.continuations.Branch;
+import org.simantics.scl.compiler.internal.codegen.continuations.BranchRef;
+import org.simantics.scl.compiler.internal.codegen.continuations.ICont;
+import org.simantics.scl.compiler.internal.codegen.references.BoundVar;
+import org.simantics.scl.compiler.internal.codegen.references.IVal;
+import org.simantics.scl.compiler.internal.codegen.references.ValRef;
+import org.simantics.scl.compiler.internal.codegen.ssa.SSABlock;
+import org.simantics.scl.compiler.internal.codegen.ssa.SSAFunction;
+import org.simantics.scl.compiler.internal.codegen.ssa.exits.If;
+import org.simantics.scl.compiler.internal.codegen.ssa.exits.Jump;
+import org.simantics.scl.compiler.internal.codegen.ssa.exits.Switch;
+import org.simantics.scl.compiler.internal.codegen.ssa.exits.Throw;
+import org.simantics.scl.compiler.internal.codegen.ssa.statements.LetApply;
+import org.simantics.scl.compiler.internal.codegen.ssa.statements.LetFunctions;
+import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
+import org.simantics.scl.compiler.types.TVar;
+import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.Types;
+import org.simantics.scl.compiler.types.exceptions.MatchException;
+import org.simantics.scl.compiler.types.util.MultiFunction;
+
+public class CodeWriter {
+
+ ModuleWriter moduleWriter;
+ SSABlock block;
+
+ CodeWriter(ModuleWriter moduleWriter, SSABlock block) {
+ this.moduleWriter = moduleWriter;
+ this.block = block;
+ }
+
+ public IVal apply(int lineNumber, IVal function, IVal ... parameters) {
+ try {
+ MultiFunction mfun = Types.matchFunction(function.getType(), parameters.length);
+ return applyWithEffect(lineNumber,
+ mfun.effect,
+ mfun.returnType,
+ function, parameters);
+ } catch (MatchException e) {
+ throw new InternalCompilerError(e);
+ }
+ }
+
+ public IVal applyWithEffectChecked(int lineNumber, Type effect, Type returnType, IVal function, IVal ... parameters) {
+ try {
+ MultiFunction mfun = Types.matchFunction(function.getType(), parameters.length);
+ if(!Types.equals(effect, mfun.effect))
+ throw new InternalCompilerError();
+ if(!Types.equals(returnType, mfun.returnType))
+ throw new InternalCompilerError();
+ } catch (MatchException e) {
+ throw new InternalCompilerError(e);
+ }
+ return applyWithEffect(lineNumber, effect, returnType, function, parameters);
+ }
+
+ public IVal applyWithEffect(long location, Type effect, Type returnType, IVal function, IVal ... parameters) {
+ BoundVar var = new BoundVar(returnType);
+ LetApply apply = new LetApply(var,
+ effect,
+ function.createOccurrence(),
+ ValRef.createOccurrences(parameters));
+ apply.location = location;
+ block.addStatement(apply);
+ return var;
+ }
+
+ public CodeWriter createBlock(Type ... parameterTypes) {
+ SSABlock newBlock = new SSABlock(parameterTypes);
+ block.getParent().addBlock(newBlock);
+ return new CodeWriter(moduleWriter, newBlock);
+ }
+
+ public CodeWriter createFunction(TVar[] typeParameters, Type effect, Type returnType, Type[] parameterTypes) {
+ if(SCLCompilerConfiguration.DEBUG)
+ if(effect == null)
+ throw new InternalCompilerError();
+ SSAFunction function = new SSAFunction(typeParameters, effect, returnType);
+ SSABlock block = new SSABlock(parameterTypes);
+ function.addBlock(block);
+ BoundVar target = new BoundVar(function.getType());
+ function.setTarget(target);
+
+ this.block.addStatement(new LetFunctions(function));
+ return new CodeWriter(moduleWriter, block);
+ }
+
+ public RecursiveDefinitionWriter createRecursiveDefinition() {
+ LetFunctions let = new LetFunctions();
+ block.addStatement(let);
+ return new RecursiveDefinitionWriter(moduleWriter, let);
+ }
+
+ public void continueAs(CodeWriter codeWriter) {
+ this.block = codeWriter.block;
+ codeWriter.block = null;
+ }
+
+ public IVal[] getParameters() {
+ return block.getParameters();
+ }
+
+ public ICont getContinuation() {
+ return block;
+ }
+
+ public void jump(ICont cont, IVal ... parameters) {
+ block.setExit(new Jump(cont.createOccurrence(),
+ ValRef.createOccurrences(parameters)));
+ block = null;
+ }
+
+ public void if_(IVal condition, ICont thenTarget, ICont elseTarget) {
+ block.setExit(new If(condition.createOccurrence(),
+ thenTarget.createOccurrence(),
+ elseTarget.createOccurrence()));
+ block = null;
+ }
+
+ public void return_(IVal val) {
+ jump(block.getParent().getReturnCont(), val);
+ }
+
+ public void switch_(IVal val, Branch[] branches) {
+ block.setExit(new Switch(val.createOccurrence(), BranchRef.toBranchRefs(branches)));
+ block = null;
+ }
+
+ public void throw_(long location, TypeDesc exceptionClass, String description) {
+ Throw exit = new Throw(exceptionClass, description);
+ exit.location = location;
+ block.setExit(exit);
+ block = null;
+ }
+
+ public ModuleWriter getModuleWriter() {
+ return moduleWriter;
+ }
+
+ public SSAFunction getFunction() {
+ return block.getParent();
+ }
+}
package org.simantics.scl.compiler.internal.codegen.writer;
-import gnu.trove.map.hash.THashMap;
-
import java.util.Map;
import org.simantics.scl.compiler.common.names.Name;
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.runtime.tuple.Tuple2;
+import gnu.trove.map.hash.THashMap;
+
public class ModuleWriter {
SSAModule module;
package org.simantics.scl.compiler.internal.deriving;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-\r
import org.simantics.scl.compiler.types.TCon;\r
import org.simantics.scl.compiler.types.Types;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+\r
public class InstanceDerivers {\r
private static final THashMap<TCon, InstanceDeriver> MAP = \r
new THashMap<TCon, InstanceDeriver>();\r
package org.simantics.scl.compiler.internal.elaboration.constraints;
-import gnu.trove.map.hash.THashMap;
-
import org.cojen.classfile.TypeDesc;
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.constants.ClassConstant;
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.Types;
+import gnu.trove.map.hash.THashMap;
+
public class ConstraintEnvironment {
Environment environment;
package org.simantics.scl.compiler.internal.elaboration.constraints;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import org.simantics.scl.compiler.elaboration.expressions.ELiteral;
import org.simantics.scl.compiler.types.TPred;
import org.simantics.scl.compiler.types.Types;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
+
class ConstraintSet {
private static int id = 0;
package org.simantics.scl.compiler.internal.elaboration.constraints;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-\r
import java.util.ArrayList;\r
import java.util.Arrays;\r
import java.util.Collections;\r
import org.simantics.scl.compiler.types.util.TConComparator;\r
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+\r
public class ConstraintSolver {\r
\r
public static THashSet<TCon> DEFAULTS_IGNORE = new THashSet<TCon>(); \r
package org.simantics.scl.compiler.internal.elaboration.constraints;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-import gnu.trove.procedure.TObjectObjectProcedure;\r
-\r
import java.util.ArrayList;\r
\r
import org.simantics.scl.compiler.types.TApply;\r
import org.simantics.scl.compiler.types.Types;\r
import org.simantics.scl.compiler.types.util.MultiApply;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+import gnu.trove.procedure.TObjectObjectProcedure;\r
+\r
public class InstanceTree<T> {\r
\r
Node<T> root;\r
package org.simantics.scl.compiler.internal.elaboration.constraints2;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.procedure.TObjectObjectProcedure;
-
import org.simantics.scl.compiler.environment.Environment;
import org.simantics.scl.compiler.types.TCon;
import org.simantics.scl.compiler.types.TPred;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.procedure.TObjectObjectProcedure;
+
public class ConstraintSolver {
final Environment environment;
private final THashMap<TCon, ConstraintStore> constraintStores =
package org.simantics.scl.compiler.internal.elaboration.constraints2;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.procedure.TObjectProcedure;
-
import java.util.ArrayList;
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.procedure.TObjectProcedure;
+
class ConstraintStore {
private final ConstraintSolver solver;
package org.simantics.scl.compiler.internal.elaboration.matching;
-import gnu.trove.map.hash.THashMap;
-
import java.util.ArrayList;
import java.util.List;
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
+import gnu.trove.map.hash.THashMap;
+
public class PatternMatchingCompiler {
private static class ExpressionMatrix {
import java.util.ArrayList;
import org.simantics.scl.compiler.elaboration.expressions.Case;
+import org.simantics.scl.compiler.elaboration.expressions.EAmbiguous;
import org.simantics.scl.compiler.elaboration.expressions.EApply;
import org.simantics.scl.compiler.elaboration.expressions.EApplyType;
import org.simantics.scl.compiler.elaboration.expressions.EAsPattern;
return expression;
}
+ @Override
+ public Expression transform(EAmbiguous expression) {
+ ++codeCounter;
+ return super.transform(expression);
+ }
+
@Override
public Expression transform(EApply expression) {
++codeCounter;
package org.simantics.scl.compiler.internal.elaboration.subsumption;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-import gnu.trove.set.hash.THashSet;\r
-\r
import java.util.ArrayDeque;\r
import java.util.ArrayList;\r
\r
import org.simantics.scl.compiler.types.util.Polarity;\r
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+import gnu.trove.set.hash.THashSet;\r
+\r
public class SubSolver {\r
\r
public static final boolean DEBUG = false;\r
package org.simantics.scl.compiler.internal.elaboration.transformations;
-import gnu.trove.procedure.TObjectObjectProcedure;
-
import java.util.ArrayList;
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
import org.simantics.scl.compiler.elaboration.rules.SectionName;
import org.simantics.scl.compiler.elaboration.rules.TransformationRule;
+import gnu.trove.procedure.TObjectObjectProcedure;
+
public class DecomposedRule {
final TransformationRule rule;
final ArrayList<Query> sourceQueries = new ArrayList<Query>();
package org.simantics.scl.compiler.internal.elaboration.transformations;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.map.hash.TIntObjectHashMap;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.simantics.scl.compiler.internal.codegen.references.IVal;
import org.simantics.scl.compiler.internal.elaboration.utils.ForcedClosure;
import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
-import org.simantics.scl.compiler.top.SCLExpressionCompilationException;
import org.simantics.scl.compiler.types.TCon;
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.Types;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.map.hash.TIntObjectHashMap;
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.THashSet;
+
public class TransformationBuilder {
private static final TCon UMap = Types.con("Unification", "UMap");
private static final Name createUMap = Name.create("Unification", "createUMap");
package org.simantics.scl.compiler.internal.elaboration.transformations;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.elaboration.modules.SCLValue;
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.internal.codegen.references.IVal;
-import org.simantics.scl.compiler.internal.types.TypeHashCodeContext;
+import org.simantics.scl.compiler.internal.types.HashCodeUtils;
import org.simantics.scl.compiler.types.TCon;
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.util.MultiApply;
import org.simantics.scl.compiler.types.util.MultiFunction;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
+
public class UnifiableFactory {
private static final TCon Unifiable = Types.con("Unification", "Unifiable");
private static final Name uVar = Name.create("Unification", "uVar");
@Override
public int hashCode() {
if(hashCode == 0) {
- TypeHashCodeContext hcContext = new TypeHashCodeContext();
- hcContext.append(function.hashCode());
+ int hash = HashCodeUtils.SEED;
+ hash = HashCodeUtils.update(hash, function.hashCode());
for(Type typeParameter : typeParameters)
- typeParameter.updateHashCode(hcContext);
- hashCode = hcContext.getResult();
+ hash = typeParameter.hashCode(hash);
+ hashCode = hash;
}
return hashCode;
}
package org.simantics.scl.compiler.internal.parsing.declarations;
-import gnu.trove.map.hash.THashMap;
-
import java.util.ArrayList;
import org.simantics.scl.compiler.elaboration.query.Query;
+import gnu.trove.map.hash.THashMap;
+
public class DRuleAst extends DeclarationAst {
public final boolean isAbstract;
public final String name;
package org.simantics.scl.compiler.internal.parsing.translation;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-\r
import java.util.ArrayList;\r
import java.util.Collection;\r
\r
import org.simantics.scl.compiler.internal.parsing.declarations.DAnnotationAst;\r
import org.simantics.scl.compiler.internal.parsing.declarations.DRelationAst;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+\r
public class RelationRepository {\r
THashMap<String, ArrayList<DRelationAst>> relations = \r
new THashMap<String, ArrayList<DRelationAst>>();\r
package org.simantics.scl.compiler.internal.types;
-import gnu.trove.map.hash.THashMap;
-
import org.simantics.scl.compiler.types.TVar;
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.kinds.Kinds;
import org.simantics.scl.compiler.types.util.ITypeEnvironment;
+import gnu.trove.map.hash.THashMap;
+
public class TypeElaborationContext {
THashMap<String, TVar> vars;
package org.simantics.scl.compiler.internal.types;
-import gnu.trove.map.hash.TObjectIntHashMap;
-
import org.simantics.scl.compiler.types.TVar;
+import gnu.trove.map.hash.TObjectIntHashMap;
+
public class TypeHashCodeContext {
public static final int APPLY = 0x12345678;
package org.simantics.scl.compiler.internal.types.effects;
-import gnu.trove.map.hash.TObjectIntHashMap;
-
import java.util.ArrayList;
import java.util.Collection;
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.Types;
+import gnu.trove.map.hash.TObjectIntHashMap;
+
public class EffectIdMap {
public static final int MIN = 0;
package org.simantics.scl.compiler.markdown.html;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-import gnu.trove.procedure.TObjectProcedure;\r
-import gnu.trove.set.hash.THashSet;\r
-\r
import java.util.ArrayList;\r
import java.util.Collections;\r
import java.util.List;\r
\r
import org.simantics.scl.compiler.source.repository.ModuleSourceRepository;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+import gnu.trove.procedure.TObjectProcedure;\r
+import gnu.trove.set.hash.THashSet;\r
+\r
public class HierarchicalDocumentationRef implements Comparable<HierarchicalDocumentationRef> {\r
final String name;\r
final ArrayList<HierarchicalDocumentationRef> children = new ArrayList<HierarchicalDocumentationRef>();\r
package org.simantics.scl.compiler.markdown.html;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.procedure.TObjectProcedure;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import java.util.Collections;
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.procedure.TObjectProcedure;
+import gnu.trove.set.hash.THashSet;
+
public class SCLDocumentationExtensionNodeHandler implements ExtensionNodeHandler {
final ModuleRepository moduleRepository;
package org.simantics.scl.compiler.markdown.inlines;
-import gnu.trove.map.hash.THashMap;
-
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
+import gnu.trove.map.hash.THashMap;
+
public class Entities {
public static final THashMap<String, String> ENTITY_MAP = new THashMap<String, String>();
public static int MAX_ENTITY_LENGTH;
package org.simantics.scl.compiler.markdown.inlines;
-import gnu.trove.map.hash.THashMap;
-
import org.simantics.scl.compiler.markdown.internal.Scanner;
import org.simantics.scl.compiler.markdown.nodes.AutolinkNode;
import org.simantics.scl.compiler.markdown.nodes.CodeNode;
import org.simantics.scl.compiler.markdown.nodes.Reference;
import org.simantics.scl.compiler.markdown.nodes.TextNode;
+import gnu.trove.map.hash.THashMap;
+
public class Subject {
THashMap<String, Reference> referenceMap;
StringBuilder input;
package org.simantics.scl.compiler.markdown.internal;
-import gnu.trove.map.hash.TCharObjectHashMap;
-
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
+import gnu.trove.map.hash.TCharObjectHashMap;
+
public class HtmlEscape {
private static final Charset UTF8 = Charset.forName("UTF-8");
package org.simantics.scl.compiler.markdown.internal;
-import gnu.trove.map.hash.THashMap;
-
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import org.simantics.scl.compiler.markdown.nodes.ParagraphNode;
import org.simantics.scl.compiler.markdown.nodes.Reference;
+import gnu.trove.map.hash.THashMap;
+
public class MarkdownParser {
public static final boolean DEBUG = false;
public static final int CODE_INDENT = 4;
package org.simantics.scl.compiler.markdown.internal;
-import gnu.trove.set.hash.THashSet;
-
import org.simantics.scl.compiler.markdown.inlines.Subject;
+import gnu.trove.set.hash.THashSet;
+
public class Scanner {
public int level;
package org.simantics.scl.compiler.module;
-import gnu.trove.map.hash.THashMap;
-
import java.util.Collection;
import java.util.Collections;
import org.simantics.scl.compiler.types.TCon;
import org.simantics.scl.runtime.profiling.BranchPoint;
+import gnu.trove.map.hash.THashMap;
+
public abstract class LazyModule implements Module {
String moduleName;
package org.simantics.scl.compiler.module.repository;\r
\r
-import gnu.trove.procedure.TObjectProcedure;\r
-\r
import java.util.ArrayList;\r
import java.util.List;\r
import java.util.regex.Pattern;\r
import org.simantics.scl.compiler.errors.Failable;\r
import org.simantics.scl.compiler.module.Module;\r
\r
+import gnu.trove.procedure.TObjectProcedure;\r
+\r
public class ModuleRepositories {\r
public static List<SCLValue> allValuesMatching(final ModuleRepository repository, String pattern) {\r
final Pattern compiledPattern = pattern == null ? null \r
package org.simantics.scl.compiler.runtime;
-import gnu.trove.map.hash.THashMap;
-
import java.util.Map;
import org.simantics.scl.compiler.constants.Constant;
+import gnu.trove.map.hash.THashMap;
+
public class ExpressionClassLoader extends ClassLoader implements MutableClassLoader {
public static final boolean VALIDATE_CLASS_NAMES = true;
public static final boolean TRACE_CLASS_CREATION = false;
package org.simantics.scl.compiler.runtime;
-import gnu.trove.map.hash.THashMap;
-
import java.util.Map;
import org.simantics.scl.compiler.constants.Constant;
+import gnu.trove.map.hash.THashMap;
+
public interface MutableClassLoader {
public static final String SCL_PACKAGE_PREFIX = "scl.";
package org.simantics.scl.compiler.runtime;
-import gnu.trove.map.hash.THashMap;
-
import org.simantics.scl.compiler.environment.Environment;
+import gnu.trove.map.hash.THashMap;
+
public class RuntimeEnvironmentImpl implements RuntimeEnvironment {
private final Environment environment;
package org.simantics.scl.compiler.runtime;\r
\r
-import gnu.trove.map.hash.THashMap;\r
-\r
import java.util.Collection;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+\r
public class RuntimeModuleMap {\r
THashMap<String, RuntimeModule> moduleMap = new THashMap<String, RuntimeModule>(); \r
\r
import java.io.IOException;
import java.io.InputStream;
-import java.nio.charset.Charset;
import org.simantics.scl.compiler.internal.codegen.types.JavaReferenceValidator;
import org.simantics.scl.compiler.internal.codegen.types.RuntimeJavaReferenceValidator;
package org.simantics.scl.compiler.source.repository;
-import gnu.trove.procedure.TObjectProcedure;
-import gnu.trove.set.hash.THashSet;
-
import java.io.IOException;
import java.net.URL;
import org.simantics.scl.compiler.source.ClassModuleSource;
import org.simantics.scl.compiler.source.ModuleSource;
+import gnu.trove.procedure.TObjectProcedure;
+import gnu.trove.set.hash.THashSet;
+
public class ClassModuleSourceRepository extends AbstractModuleSourceRepository {
private final Class<?> clazz;
package org.simantics.scl.compiler.source.repository;
-import gnu.trove.procedure.TObjectProcedure;
-
import org.simantics.scl.compiler.module.repository.UpdateListener;
import org.simantics.scl.compiler.source.ModuleSource;
+import gnu.trove.procedure.TObjectProcedure;
+
public class CompositeModuleSourceRepository implements ModuleSourceRepository {
public final ModuleSourceRepository[] children;
package org.simantics.scl.compiler.source.repository;
-import gnu.trove.procedure.TObjectProcedure;
-import gnu.trove.set.hash.THashSet;
-
import java.io.File;
import java.io.IOException;
import org.simantics.scl.compiler.source.FileModuleSource;
import org.simantics.scl.compiler.source.ModuleSource;
+import gnu.trove.procedure.TObjectProcedure;
+import gnu.trove.set.hash.THashSet;
+
public class FileModuleSourceRepository extends AbstractModuleSourceRepository {
private final File path;
package org.simantics.scl.compiler.source.repository;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.procedure.TObjectProcedure;
-
import org.simantics.scl.compiler.module.Module;
import org.simantics.scl.compiler.module.repository.UpdateListener;
import org.simantics.scl.compiler.source.ModuleSource;
import org.simantics.scl.compiler.source.PrecompiledModuleSource;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.procedure.TObjectProcedure;
+
/**
* An implementation of {@link ModuleSourceRepository} as a finite map.
* This implementation does not support listening module changes,
package org.simantics.scl.compiler.source.repository;
-import gnu.trove.procedure.TObjectProcedure;
-
import org.simantics.scl.compiler.module.repository.ModuleRepository;
import org.simantics.scl.compiler.module.repository.UpdateListener;
import org.simantics.scl.compiler.source.ModuleSource;
+import gnu.trove.procedure.TObjectProcedure;
+
/**
* An interface for locating modules descriptors and listening if they change.
* An instance of this interface is used to create a {@link ModuleRepository}.
package org.simantics.scl.compiler.top;
-import gnu.trove.set.hash.THashSet;
-
import java.io.StringReader;
import java.lang.reflect.Method;
import java.util.ArrayList;
import org.simantics.scl.runtime.function.FunctionImpl1;
import org.simantics.scl.runtime.tuple.Tuple0;
+import gnu.trove.set.hash.THashSet;
+
public class ExpressionEvaluator {
public static final boolean TRACE_INTERPRETATION_VS_COMPILATION = false;
package org.simantics.scl.compiler.top;
-import gnu.trove.impl.Constants;
-import gnu.trove.map.hash.TObjectIntHashMap;
-
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.elaboration.expressions.Variable;
import org.simantics.scl.compiler.internal.codegen.utils.TransientClassBuilder;
import org.simantics.scl.compiler.runtime.RuntimeEnvironment;
+import gnu.trove.impl.Constants;
+import gnu.trove.map.hash.TObjectIntHashMap;
+
public class ExpressionInterpretationContext {
public static final boolean EVERY_RULE_ENFORCEMENT_IN_SEPARATE_METHOD = true;
public static final boolean EVERY_DATALOG_STRATUM_IN_SEPARATE_METHOD = true;
+ public static final boolean ALLOW_OVERLOADING = false;
+
}
--- /dev/null
+package org.simantics.scl.compiler.types;
+
+import org.simantics.scl.compiler.environment.Environment;
+import org.simantics.scl.compiler.internal.types.HashCodeUtils;
+import org.simantics.scl.compiler.types.exceptions.KindUnificationException;
+import org.simantics.scl.compiler.types.exceptions.UnificationException;
+import org.simantics.scl.compiler.types.kinds.Kinds;
+
+import gnu.trove.map.hash.THashMap;
+
+public class Skeletons {
+
+ public static Type canonicalSkeleton(Type type) {
+ while(type instanceof TMetaVar) {
+ TMetaVar metaVar = (TMetaVar)type;
+ if(metaVar.ref != null)
+ type = metaVar.ref;
+ else if(metaVar.skeletonRef != null)
+ type = metaVar.skeletonRef;
+ else
+ return metaVar;
+ }
+ return type;
+ }
+
+ public static Type canonicalSkeleton(THashMap<TMetaVar,Type> unifications, Type type) {
+ while(type instanceof TMetaVar) {
+ TMetaVar metaVar = (TMetaVar)type;
+ if(metaVar.ref != null)
+ type = metaVar.ref;
+ else if(metaVar.skeletonRef != null)
+ type = metaVar.skeletonRef;
+ else {
+ Type temp = unifications.get(metaVar);
+ if(temp == null)
+ return metaVar;
+ else
+ type = temp;
+ }
+ }
+ return type;
+ }
+
+ public static boolean doesSkeletonContain(THashMap<TMetaVar,Type> unifications, Type type, TMetaVar metaVar) {
+ type = canonicalSkeleton(unifications, type);
+ if(type == metaVar)
+ return true;
+ if(type instanceof TFun) {
+ TFun fun = (TFun)type;
+ return doesSkeletonContain(unifications, fun.domain, metaVar)
+ || doesSkeletonContain(unifications, fun.range, metaVar);
+ }
+ if(type instanceof TApply) {
+ TApply apply = (TApply)type;
+ return doesSkeletonContain(unifications, apply.function, metaVar)
+ || doesSkeletonContain(unifications, apply.parameter, metaVar);
+ }
+ if(type instanceof TForAll) {
+ TForAll forAll = (TForAll)type;
+ return doesSkeletonContain(unifications, forAll.type, metaVar);
+ }
+ if(type instanceof TPred) {
+ TPred pred = (TPred)type;
+ for(Type param : pred.parameters)
+ if(doesSkeletonContain(unifications, param, metaVar))
+ return true;
+ return false;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Returns true, if unification of the skeletons of the types would succeed.
+ */
+ public static boolean areSkeletonsCompatible(THashMap<TMetaVar,Type> unifications, Type a, Type b) {
+ a = canonicalSkeleton(unifications, a);
+ b = canonicalSkeleton(unifications, b);
+ if(a == b)
+ return true;
+ Class<?> ca = a.getClass();
+ Class<?> cb = b.getClass();
+
+ if(ca == TMetaVar.class) {
+ TMetaVar ma = (TMetaVar)a;
+ if(doesSkeletonContain(unifications, b, ma))
+ return false;
+ unifications.put(ma, b);
+ return true;
+ }
+ if(cb == TMetaVar.class) {
+ TMetaVar mb = (TMetaVar)b;
+ if(doesSkeletonContain(unifications, a, mb))
+ return false;
+ unifications.put(mb, a);
+ return true;
+ }
+ if(ca != cb)
+ return false;
+ if(ca == TFun.class) {
+ TFun funA = (TFun)a;
+ TFun funB = (TFun)b;
+ return areSkeletonsCompatible(unifications, funA.domain, funB.domain)
+ && areSkeletonsCompatible(unifications, funA.range, funB.range);
+ }
+ if(ca == TApply.class) {
+ TApply applyA = (TApply)a;
+ TApply applyB = (TApply)b;
+ return areSkeletonsCompatible(unifications, applyA.function, applyB.function)
+ && areSkeletonsCompatible(unifications, applyA.parameter, applyB.parameter);
+ }
+ if(ca == TPred.class) {
+ TPred predA = (TPred)a;
+ TPred predB = (TPred)b;
+ if(predA.typeClass != predB.typeClass)
+ return false;
+ for(int i=0;i<predA.parameters.length;++i)
+ if(!areSkeletonsCompatible(unifications, predA.parameters[i], predB.parameters[i]))
+ return false;
+ return true;
+ }
+ if(ca == TForAll.class) {
+ TForAll forAllA = (TForAll)a;
+ TForAll forAllB = (TForAll)b;
+ TVar temp = Types.var(forAllA.var.getKind());
+ return areSkeletonsCompatible(unifications,
+ forAllA.type.replace(forAllA.var, temp),
+ forAllB.type.replace(forAllB.var, temp));
+ }
+ return false;
+ }
+
+ public static void unifySkeletons(Type a, Type b) throws UnificationException {
+ a = canonicalSkeleton(a);
+ b = canonicalSkeleton(b);
+
+ if(a == b)
+ return;
+ if(a instanceof TMetaVar) {
+ ((TMetaVar) a).setSkeletonRef(b);
+ return;
+ }
+ if(b instanceof TMetaVar) {
+ ((TMetaVar) b).setSkeletonRef(a);
+ return;
+ }
+
+ Class<?> ca = a.getClass();
+ Class<?> cb = b.getClass();
+ if(ca != cb) {
+ throw new UnificationException(a, b);
+ }
+ if(ca == TApply.class)
+ //unifySkeletons((TApply)a, (TApply)b);
+ Types.unify(a, b);
+ else if(ca == TFun.class)
+ unifySkeletons((TFun)a, (TFun)b);
+ else if(ca == TForAll.class)
+ unifySkeletons((TForAll)a, (TForAll)b);
+ else if(ca == TPred.class)
+ //unifySkeletons((TPred)a, (TPred)b);
+ Types.unify(a, b);
+ else if(ca == TUnion.class)
+ unifySkeletons((TUnion)a, (TUnion)b);
+ else // ca == TCon.class || ca = TVar.class
+ throw new UnificationException(a, b);
+ }
+
+ public static void unifySkeletons(TFun a, TFun b) throws UnificationException {
+ unifySkeletons(a.domain, b.domain);
+ unifySkeletons(a.range, b.range);
+ }
+
+ public static void unifySkeletons(TApply a, TApply b) throws UnificationException {
+ unifySkeletons(a.function, b.function);
+ unifySkeletons(a.parameter, b.parameter);
+ }
+
+ public static void unifySkeletons(TForAll a, TForAll b) throws UnificationException {
+ try {
+ Kinds.unify(a.var.getKind(), b.var.getKind());
+ } catch (KindUnificationException e) {
+ throw new UnificationException(a, b);
+ }
+ TVar newVar = Types.var(a.var.getKind());
+ unifySkeletons(a.type.replace(a.var, newVar), b.type.replace(b.var, newVar));
+ }
+
+ public static void unifySkeletons(TPred a, TPred b) throws UnificationException {
+ if(a.typeClass != b.typeClass
+ || a.parameters.length != b.parameters.length)
+ throw new UnificationException(a, b);
+ for(int i=0;i<a.parameters.length;++i)
+ unifySkeletons(a.parameters[i], b.parameters[i]);
+ }
+
+ public static void unifySkeletons(TUnion a, TUnion b) throws UnificationException {
+ // Nothing to do
+ }
+
+ public static Type commonSkeleton(Environment context, Type[] types) {
+ THashMap<Type[], TMetaVar> metaVarMap = new THashMap<Type[], TMetaVar>() {
+ @Override
+ protected boolean equals(Object a, Object b) {
+ return Types.equals((Type[])a, (Type[])b);
+ }
+ @Override
+ protected int hash(Object a) {
+ Type[] types = (Type[])a;
+ int hash = HashCodeUtils.SEED;
+ for(Type type : types)
+ hash = type.hashCode(hash);
+ return hash;
+ }
+ };
+ return commonSkeleton(context, metaVarMap, types);
+ }
+
+ private static TMetaVar metaVarFor(Environment context, THashMap<Type[], TMetaVar> metaVarMap, Type[] types) {
+ TMetaVar result = metaVarMap.get(types);
+ if(result == null) {
+ try {
+ result = Types.metaVar(types[0].inferKind(context));
+ } catch (KindUnificationException e) {
+ result = Types.metaVar(Kinds.STAR);
+ }
+ metaVarMap.put(types, result);
+ }
+ return result;
+ }
+
+ /**
+ * Finds the most specific type that can be unified with the all the types
+ * given as a parameter.
+ */
+ private static Type commonSkeleton(Environment context, THashMap<Type[], TMetaVar> metaVarMap, Type[] types) {
+ for(int i=0;i<types.length;++i)
+ types[i] = canonicalSkeleton(types[i]);
+
+ Type first = types[0];
+ Class<?> clazz = first.getClass();
+ for(int i=1;i<types.length;++i)
+ if(types[i].getClass() != clazz)
+ return metaVarFor(context, metaVarMap, types);
+
+ if(clazz == TCon.class) {
+ for(int i=1;i<types.length;++i)
+ if(types[i] != first)
+ return metaVarFor(context, metaVarMap, types);
+ return first;
+ }
+ else if(clazz == TApply.class) {
+ Type[] functions = new Type[types.length];
+ Type[] parameters = new Type[types.length];
+ for(int i=0;i<types.length;++i) {
+ TApply apply = (TApply)types[i];
+ functions[i] = apply.function;
+ parameters[i] = apply.parameter;
+ }
+ return Types.apply(
+ commonSkeleton(context, metaVarMap, functions),
+ commonSkeleton(context, metaVarMap, parameters));
+ }
+ else if(clazz == TFun.class) {
+ Type[] domains = new Type[types.length];
+ Type[] effects = new Type[types.length];
+ Type[] ranges = new Type[types.length];
+ for(int i=0;i<types.length;++i) {
+ TFun fun = (TFun)types[i];
+ if(fun.domain instanceof TPred)
+ return metaVarFor(context, metaVarMap, types);
+ domains[i] = fun.domain;
+ effects[i] = fun.effect;
+ ranges[i] = fun.range;
+ }
+ return Types.functionE(
+ commonSkeleton(context, metaVarMap, domains),
+ commonEffect(effects),
+ commonSkeleton(context, metaVarMap, ranges));
+ }
+ else
+ return metaVarFor(context, metaVarMap, types);
+ }
+
+ private static Type commonEffect(Type[] effects) {
+ Type first = effects[0];
+ for(int i=1;i<effects.length;++i)
+ if(!Types.equals(first, effects[i]))
+ return Types.metaVar(Kinds.EFFECT);
+ return first;
+ }
+}
package org.simantics.scl.compiler.types;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import java.util.List;
import org.simantics.scl.compiler.environment.Environment;
+import org.simantics.scl.compiler.internal.types.HashCodeUtils;
import org.simantics.scl.compiler.internal.types.TypeHashCodeContext;
import org.simantics.scl.compiler.internal.types.ast.TApplyAst;
import org.simantics.scl.compiler.internal.types.ast.TListAst;
import org.simantics.scl.compiler.types.util.TMultiApply;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
+
/**
* @author Hannu Niemistö
*/
public class TApply extends Type {
- public final Type function;
- public final Type parameter;
+ public Type function;
+ public Type parameter;
public TApply(Type function, Type parameter) {
if(NULL_CHECKS) {
Kind parameterKind = parameter.inferKind(context);
Kinds.unify(functionKind, Kinds.arrow(parameterKind, requiredKind));
}
+
+ @Override
+ public Kind getKind(Environment context) {
+ Kind functionKind = function.getKind(context);
+ return Kinds.rangeOfArrow(functionKind);
+ }
@Override
public boolean containsMetaVars() {
else
return new TApply(newFunction, newParameter);
}
+
+ @Override
+ public int hashCode(int hash) {
+ hash = HashCodeUtils.updateWithPreprocessedValue(hash, APPLY_HASH);
+ hash = function.hashCode(hash);
+ hash = parameter.hashCode(hash);
+ return hash;
+ }
+
+ @Override
+ public int hashCode(int hash, TVar[] boundVars) {
+ hash = HashCodeUtils.updateWithPreprocessedValue(hash, APPLY_HASH);
+ hash = function.hashCode(hash, boundVars);
+ hash = parameter.hashCode(hash, boundVars);
+ return hash;
+ }
+
+ public Type getCanonicalFunction() {
+ if(function instanceof TMetaVar)
+ function = function.canonical();
+ return function;
+ }
+
+ public Type getCanonicalParameter() {
+ if(parameter instanceof TMetaVar)
+ parameter = parameter.canonical();
+ return parameter;
+ }
+
+ @Override
+ public boolean equalsCanonical(Type other) {
+ if(this == other)
+ return true;
+ if(!other.getClass().equals(TApply.class))
+ return false;
+ TApply apply = (TApply)other;
+ return getCanonicalFunction().equalsCanonical(apply.getCanonicalFunction())
+ && getCanonicalParameter().equalsCanonical(apply.getCanonicalParameter());
+ }
}
package org.simantics.scl.compiler.types;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import org.simantics.scl.compiler.environment.Environment;
import org.simantics.scl.compiler.internal.codegen.utils.NameMangling;
+import org.simantics.scl.compiler.internal.types.HashCodeUtils;
import org.simantics.scl.compiler.internal.types.TypeHashCodeContext;
import org.simantics.scl.compiler.internal.types.ast.TConAst;
import org.simantics.scl.compiler.internal.types.ast.TypeAst;
import org.simantics.scl.compiler.types.util.Polarity;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
+
/**
* This class represents an SCL type constant with a name given in a module.
*/
-public class TCon extends Type {
+public final class TCon extends Type {
public final String module;
public final String name;
public Kind inferKind(Environment context) throws KindUnificationException {
return context.getTypeConstructor(this).kind;
}
+
+ public Kind getKind(Environment context) {
+ return context.getTypeConstructor(this).kind;
+ }
@Override
public boolean containsMetaVars() {
public Type copySkeleton(THashMap<TMetaVar, TMetaVar> metaVarMap) {
return this;
}
+
+ @Override
+ public int hashCode(int hash) {
+ return HashCodeUtils.update(hash, System.identityHashCode(this));
+ }
+
+ @Override
+ public int hashCode(int hash, TVar[] boundVars) {
+ return HashCodeUtils.update(hash, System.identityHashCode(this));
+ }
+
+ @Override
+ public boolean equalsCanonical(Type other) {
+ return this == other;
+ }
}
package org.simantics.scl.compiler.types;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
+import java.util.Arrays;
import org.simantics.scl.compiler.environment.Environment;
+import org.simantics.scl.compiler.internal.types.HashCodeUtils;
import org.simantics.scl.compiler.internal.types.TypeHashCodeContext;
import org.simantics.scl.compiler.internal.types.ast.TForAllAst;
import org.simantics.scl.compiler.internal.types.ast.TypeAst;
import org.simantics.scl.compiler.types.util.Polarity;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.THashSet;
+
public class TForAll extends Type {
public final TVar var;
- public final Type type;
+ public Type type;
TForAll(TVar var, Type type) {
if(NULL_CHECKS) {
// Should never get here
return new TMetaVar(Kinds.STAR);
}
+
+ @Override
+ public int hashCode(int hash) {
+ int count=1;
+ {
+ Type t = Types.canonical(type);
+ while(t instanceof TForAll) {
+ t = Types.canonical( ((TForAll)t).type );
+ ++count;
+ }
+ }
+ TVar[] boundVars = new TVar[count];
+ boundVars[0] = var;
+ TForAll t = this;
+ {
+ for(int i=1;i<count;++i) {
+ t = (TForAll)Types.canonical(t.type);
+ boundVars[i] = t.var;
+ }
+ }
+
+ for(int i=0;i<count;++i)
+ hash = HashCodeUtils.updateWithPreprocessedValue(hash, FORALL_HASH);
+ return t.type.hashCode(hash, boundVars);
+ }
+
+ @Override
+ public int hashCode(int hash, TVar[] oldBoundVars) {
+ int count=1;
+ {
+ Type t = Types.canonical(type);
+ while(t instanceof TForAll) {
+ t = Types.canonical( ((TForAll)t).type );
+ ++count;
+ }
+ }
+ TVar[] boundVars = Arrays.copyOf(oldBoundVars, oldBoundVars.length + count);
+ boundVars[oldBoundVars.length] = var;
+ TForAll t = this;
+ {
+ for(int i=1;i<count;++i) {
+ t = (TForAll)Types.canonical(t.type);
+ boundVars[oldBoundVars.length + i] = t.var;
+ }
+ }
+
+ for(int i=0;i<count;++i)
+ hash = HashCodeUtils.updateWithPreprocessedValue(hash, FORALL_HASH);
+ return t.type.hashCode(hash, boundVars);
+ }
+
+ public Type getCanonicalType() {
+ if(type instanceof TMetaVar)
+ type = type.canonical();
+ return type;
+ }
+
+ @Override
+ public boolean equalsCanonical(Type other) {
+ if(this == other)
+ return true;
+ if(!other.getClass().equals(TForAll.class))
+ return false;
+ TForAll forAll = (TForAll)other;
+ return getCanonicalType().equalsCanonical(forAll.getCanonicalType().replace(forAll.var, var));
+ }
+
+ @Override
+ public Kind getKind(Environment context) {
+ return Kinds.STAR;
+ }
+
}
package org.simantics.scl.compiler.types;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import org.simantics.scl.compiler.environment.Environment;
+import org.simantics.scl.compiler.internal.types.HashCodeUtils;
import org.simantics.scl.compiler.internal.types.TypeHashCodeContext;
import org.simantics.scl.compiler.internal.types.ast.TEffectAst;
import org.simantics.scl.compiler.internal.types.ast.TFunctionAst;
import org.simantics.scl.compiler.types.util.Polarity;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
+
public class TFun extends Type {
- public final Type domain;
- public final Type effect;
- public final Type range;
+ public Type domain;
+ public Type effect;
+ public Type range;
TFun(Type domain, Type effect, Type range) {
if(domain == null)
Type newRange = range.copySkeleton(metaVarMap);
return new TFun(newDomain, newEffect, newRange);
}
+
+ @Override
+ public int hashCode(int hash) {
+ hash = HashCodeUtils.updateWithPreprocessedValue(hash, FUN_HASH);
+ hash = domain.hashCode(hash);
+ hash = effect.hashCode(hash);
+ hash = range.hashCode(hash);
+ return hash;
+ }
+
+ @Override
+ public int hashCode(int hash, TVar[] boundVars) {
+ hash = HashCodeUtils.updateWithPreprocessedValue(hash, FUN_HASH);
+ hash = domain.hashCode(hash, boundVars);
+ hash = effect.hashCode(hash, boundVars);
+ hash = range.hashCode(hash, boundVars);
+ return hash;
+ }
+
+ public Type getCanonicalDomain() {
+ if(domain instanceof TMetaVar)
+ domain = domain.canonical();
+ return domain;
+ }
+
+ public Type getCanonicalEffect() {
+ if(effect instanceof TMetaVar)
+ effect = effect.canonical();
+ return effect;
+ }
+
+ public Type getCanonicalRange() {
+ if(range instanceof TMetaVar)
+ range = range.canonical();
+ return range;
+ }
+
+ @Override
+ public boolean equalsCanonical(Type other) {
+ if(this == other)
+ return true;
+ if(!other.getClass().equals(TFun.class))
+ return false;
+ TFun fun = (TFun)other;
+ return getCanonicalDomain().equalsCanonical(fun.getCanonicalDomain())
+ && getCanonicalEffect().equalsCanonical(fun.getCanonicalEffect())
+ && getCanonicalRange().equalsCanonical(fun.getCanonicalRange());
+ }
+
+ @Override
+ public Kind getKind(Environment context) {
+ return Kinds.STAR;
+ }
}
package org.simantics.scl.compiler.types;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
+import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.environment.Environment;
+import org.simantics.scl.compiler.internal.types.HashCodeUtils;
import org.simantics.scl.compiler.internal.types.TypeHashCodeContext;
import org.simantics.scl.compiler.internal.types.ast.TVarAst;
import org.simantics.scl.compiler.internal.types.ast.TypeAst;
import org.simantics.scl.compiler.types.util.Polarity;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
+
/**
*/
public class TMetaVar extends Type {
public static final TMetaVar[] EMPTY_ARRAY = new TMetaVar[0];
+ public static final boolean DEBUG = false;
Type ref = null;
+ Type skeletonRef = null;
Polarity polarity = Polarity.NO_POLARITY;
private Kind kind;
+ private TMetaVarListener listener;
+
+ public static abstract class TMetaVarListener {
+ private Object prev; // TMetaVarListener or TMetaVar
+ private TMetaVarListener next;
+
+ public abstract void notifyAboutChange();
+
+ public void remove() {
+ if(prev == null)
+ return; // Not added or not anymore listening TMetaVar
+ if(prev instanceof TMetaVar)
+ ((TMetaVar)prev).listener = next;
+ else
+ ((TMetaVarListener)prev).next = next;
+ if(next != null) {
+ next.prev = prev;
+ next = null;
+ }
+ prev = null;
+ }
+ }
TMetaVar(Kind kind) {
this.kind = kind;
ref.collectEffectMetaVars(vars);
}
- public void setRef(Type a) throws UnificationException {
- a = Types.weakCanonical(a);
- if(a.contains(this))
- throw new UnificationException(this, a);
- ref = a;
+ public void setRef(Type type) throws UnificationException {
+ if(DEBUG)
+ System.out.println("setRef " + System.identityHashCode(this) + " -> " + type);
+ if(ref != null)
+ throw new InternalCompilerError("Method setRef should be called only for unbound meta variables.");
+ if(type.contains(this))
+ throw new UnificationException(this, type);
+ ref = type;
if(polarity != Polarity.NO_POLARITY)
- a.addPolarity(polarity);
+ type.addPolarity(polarity);
+ if(skeletonRef != null) {
+ Type skeleton = skeletonRef;
+ skeletonRef = null;
+ Skeletons.unifySkeletons(skeleton, type);
+ }
+ fireNotifyAboutChange();
}
public Type getRef() {
@Override
public boolean contains(TMetaVar other) {
- if(ref == null)
- return this == other;
- else
+ if(ref != null)
return ref.contains(other);
+ else if(skeletonRef != null)
+ return skeletonRef.contains(other);
+ else
+ return this == other;
}
@Override
return result;
}
}
+
+ public void setSkeletonRef(Type type) throws UnificationException {
+ if(DEBUG)
+ System.out.println("setSkeletonRef " + System.identityHashCode(this) + " -> " + type);
+ if(ref != null || skeletonRef != null)
+ throw new InternalCompilerError("Method setRef should be called only for unbound meta variables.");
+ if(type.contains(this))
+ throw new UnificationException(this, type);
+ this.skeletonRef = type;
+ fireNotifyAboutChange();
+ }
+
+ @Override
+ public int hashCode(int hash) {
+ if(ref == null)
+ return HashCodeUtils.update(hash, System.identityHashCode(this));
+ else
+ return ref.hashCode(hash);
+ }
+
+ @Override
+ public int hashCode(int hash, TVar[] boundVars) {
+ if(ref == null)
+ return HashCodeUtils.update(hash, System.identityHashCode(this));
+ else
+ return ref.hashCode(hash, boundVars);
+ }
+
+ @Override
+ public boolean equalsCanonical(Type other) {
+ return this == other;
+ }
+
+ @Override
+ public Type canonical() {
+ if(ref == null)
+ return this;
+ else
+ return ref = ref.canonical();
+ }
+
+ public void addListener(TMetaVarListener newListener) {
+ if(DEBUG)
+ System.out.println("addListener " + System.identityHashCode(this));
+ newListener.next = listener;
+ newListener.prev = this;
+ if(listener != null)
+ listener.prev = newListener;
+ listener = newListener;
+ }
+
+ private void fireNotifyAboutChange() {
+ if(DEBUG)
+ System.out.println("fireNotifyAboutChange " + System.identityHashCode(this) + " " + ref);
+ TMetaVarListener cur = listener;
+ listener = null;
+ while(cur != null) {
+ if(DEBUG)
+ System.out.println(" call listener");
+ cur.prev = null; // This prevents TMetaVarListener.remove from doing anything
+ cur.notifyAboutChange();
+ TMetaVarListener next = cur.next;
+ cur.next = null;
+ cur = next;
+ }
+ }
+
+ public TMetaVarListener getLatestListener() {
+ return listener;
+ }
+
+ @Override
+ public Kind getKind(Environment context) {
+ return kind;
+ }
}
package org.simantics.scl.compiler.types;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import org.simantics.scl.compiler.environment.Environment;
+import org.simantics.scl.compiler.internal.types.HashCodeUtils;
import org.simantics.scl.compiler.internal.types.TypeHashCodeContext;
import org.simantics.scl.compiler.internal.types.ast.TApplyAst;
import org.simantics.scl.compiler.internal.types.ast.TypeAst;
import org.simantics.scl.compiler.types.util.Polarity;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
+
public class TPred extends Type {
newParameters[i] = parameters[i].copySkeleton(metaVarMap);
return new TPred(typeClass, parameters);
}
+
+ @Override
+ public int hashCode(int hash) {
+ hash = HashCodeUtils.updateWithPreprocessedValue(hash, PRED_HASH);
+ hash = typeClass.hashCode(hash);
+ for(Type parameter : parameters)
+ hash = parameter.hashCode(hash);
+ return hash;
+ }
+
+ @Override
+ public int hashCode(int hash, TVar[] boundVars) {
+ hash = HashCodeUtils.updateWithPreprocessedValue(hash, PRED_HASH);
+ hash = typeClass.hashCode(hash, boundVars);
+ for(Type parameter : parameters)
+ hash = parameter.hashCode(hash, boundVars);
+ return hash;
+ }
+
+ @Override
+ public boolean equalsCanonical(Type other) {
+ if(this == other)
+ return true;
+ if(!other.getClass().equals(TPred.class))
+ return false;
+ TPred pred = (TPred)other;
+ if(typeClass != pred.typeClass || parameters.length != pred.parameters.length)
+ return false;
+ for(int i=0;i<parameters.length;++i)
+ if(!Types.canonical(parameters[i]).equalsCanonical(Types.canonical(pred.parameters[i])))
+ return false;
+ return true;
+ }
+
+ @Override
+ public Kind getKind(Environment context) {
+ return Kinds.STAR;
+ }
}
package org.simantics.scl.compiler.types;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
+import org.simantics.scl.compiler.environment.Environment;
+import org.simantics.scl.compiler.internal.types.HashCodeUtils;
import org.simantics.scl.compiler.internal.types.TypeHashCodeContext;
import org.simantics.scl.compiler.internal.types.ast.TConAst;
import org.simantics.scl.compiler.internal.types.ast.TypeAst;
+import org.simantics.scl.compiler.types.kinds.Kind;
+import org.simantics.scl.compiler.types.kinds.Kinds;
import org.simantics.scl.compiler.types.util.Polarity;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
+
public class TUnion extends Type {
public final Type[] effects;
public Type copySkeleton(THashMap<TMetaVar, TMetaVar> metaVarMap) {
return Types.NO_EFFECTS;
}
+
+ @Override
+ public int hashCode(int hash) {
+ int sum = UNION_HASH;
+ for(Type effect : effects)
+ sum += effect.hashCode(HashCodeUtils.SEED);
+ return HashCodeUtils.updateWithPreprocessedValue(hash, sum);
+ }
+
+ @Override
+ public int hashCode(int hash, TVar[] boundVars) {
+ int sum = UNION_HASH;
+ for(Type effect : effects)
+ sum += effect.hashCode(HashCodeUtils.SEED, boundVars);
+ return HashCodeUtils.updateWithPreprocessedValue(hash, sum);
+ }
+
+ @Override
+ public boolean equalsCanonical(Type other) {
+ if(this == other)
+ return true;
+ if(!other.getClass().equals(TUnion.class))
+ return false;
+ TUnion union = (TUnion)other;
+ int length = effects.length;
+ if(length != union.effects.length)
+ return false;
+ if(length == 0)
+ return true;
+ for(int i=0;i<length;++i) {
+ effects[i] = effects[i].canonical();
+ union.effects[i] = union.effects[i].canonical();
+ }
+ if(length == 2) {
+ if(effects[0].equalsCanonical(union.effects[0]))
+ return effects[1].equalsCanonical(union.effects[1]);
+ else
+ return effects[0].equalsCanonical(union.effects[1]) &&
+ effects[1].equalsCanonical(union.effects[0]);
+ }
+ loop: for(int i=0;i<length;++i) {
+ Type effect = effects[i];
+ for(int j=i;j<length;++j)
+ if(effect.equalsCanonical(union.effects[j])) {
+ if(j > i) {
+ effect = union.effects[i];
+ union.effects[i] = union.effects[j];
+ union.effects[j] = effect;
+ }
+ continue loop;
+ }
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public Kind getKind(Environment context) {
+ return Kinds.EFFECT;
+ }
}
package org.simantics.scl.compiler.types;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import org.simantics.scl.compiler.environment.Environment;
+import org.simantics.scl.compiler.internal.types.HashCodeUtils;
import org.simantics.scl.compiler.internal.types.TypeHashCodeContext;
import org.simantics.scl.compiler.internal.types.ast.TVarAst;
import org.simantics.scl.compiler.internal.types.ast.TypeAst;
import org.simantics.scl.compiler.types.util.Polarity;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.THashSet;
+
-public class TVar extends Type {
+public final class TVar extends Type {
public static final TVar[] EMPTY_ARRAY = new TVar[0];
private Kind kind;
public Type copySkeleton(THashMap<TMetaVar, TMetaVar> metaVarMap) {
return this;
}
+
+ @Override
+ public int hashCode(int hash) {
+ return HashCodeUtils.update(hash, System.identityHashCode(this));
+ }
+
+ @Override
+ public int hashCode(int hash, TVar[] boundVars) {
+ for(int i=0;i<boundVars.length;++i)
+ if(boundVars[i] == this) {
+ hash = HashCodeUtils.updateWithPreprocessedValue(hash, BOUND_VAR_HASH);
+ return HashCodeUtils.update(hash, i);
+ }
+ return HashCodeUtils.update(hash, System.identityHashCode(this));
+ }
+
+ @Override
+ public boolean equalsCanonical(Type other) {
+ return this == other;
+ }
+
+ @Override
+ public Kind getKind(Environment context) {
+ return kind;
+ }
}
package org.simantics.scl.compiler.types;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import java.util.Map;
import org.simantics.scl.compiler.environment.Environment;
+import org.simantics.scl.compiler.internal.types.HashCodeUtils;
import org.simantics.scl.compiler.internal.types.TypeHashCodeContext;
import org.simantics.scl.compiler.internal.types.ast.TypeAst;
import org.simantics.scl.compiler.types.exceptions.KindUnificationException;
import org.simantics.scl.compiler.types.util.Polarity;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
+
/**
public static final int METAVAR_ID = 5;
public static final int VAR_ID = 6;
public static final int UNION_ID = 7;
- public static final int ALIAS_ID = 8;
+ protected static final int APPLY_HASH = HashCodeUtils.preprocessValue(0);
+ protected static final int FORALL_HASH = HashCodeUtils.preprocessValue(1);
+ protected static final int FUN_HASH = HashCodeUtils.preprocessValue(2);
+ protected static final int PRED_HASH = HashCodeUtils.preprocessValue(3);
+ protected static final int UNION_HASH = HashCodeUtils.preprocessValue(4);
+ protected static final int BOUND_VAR_HASH = HashCodeUtils.preprocessValue(5);
/*
* This class is not meant to be extended outside of this package.
@Override
public int hashCode() {
- TypeHashCodeContext context = new TypeHashCodeContext();
- updateHashCode(context);
- return context.getResult();
+ return hashCode(HashCodeUtils.SEED);
}
public abstract void updateHashCode(TypeHashCodeContext context);
+ public abstract int hashCode(int hash);
+ public abstract int hashCode(int hash, TVar[] boundVars);
public abstract void collectFreeVars(ArrayList<TVar> vars);
* Creates an independent copy of the type, but replaces all effects by metavars
*/
public abstract Type copySkeleton(THashMap<TMetaVar,TMetaVar> metaVarMap);
+
+ public abstract boolean equalsCanonical(Type other);
+
+ public Type canonical() {
+ return this;
+ }
+
+ public abstract Kind getKind(Environment context);
}
\ No newline at end of file
function = apply(function, parameter);
return function;
}
-
- /**
- * Get the concrete type or alias type pointed to by a chain of type meta-variables,
- * or the last metavariable in the link, if it is not linked to an actual type.
- * Unlike {@link #canonical(Type)}, this method does not resolve type aliases.
- */
- public static Type weakCanonical(Type type) {
- while(true) {
- if(type instanceof TMetaVar) {
- TMetaVar metaVar = (TMetaVar)type;
- if(metaVar.ref == null)
- return type;
- else
- type = metaVar.ref;
- }
- else
- return type;
- }
- }
/**
- * Get the concrete type pointed to by a chain of type meta-variables. Unlike {@link #weakCanonical(Type)}
- * this method also resolves type aliases.
+ * Get the concrete type pointed to by a chain of type meta-variables.
*/
public static Type canonical(Type type) {
while(type instanceof TMetaVar) {
}
public static void unify(Type a, Type b) throws UnificationException {
- a = weakCanonical(a);
- b = weakCanonical(b);
+ a = canonical(a);
+ b = canonical(b);
if(a == b)
return;
if(a instanceof TMetaVar) {
e.getMessage()));
}
}
+
+ public static Type instantiateAndStrip(Type type) {
+ while(true) {
+ if(type instanceof TForAll) {
+ TForAll forAll = (TForAll)type;
+ type = forAll.type.replace(forAll.var, metaVar(forAll.var.getKind()));
+ }
+ else if(type instanceof TFun) {
+ TFun fun = (TFun)type;
+ if(fun.domain instanceof TPred || fun.domain == Types.PUNIT)
+ type = fun.range;
+ else
+ return type;
+ }
+ else if(type instanceof TMetaVar) {
+ TMetaVar metaVar = (TMetaVar)type;
+ if(metaVar.ref == null)
+ return type;
+ else
+ type = metaVar.ref;
+ }
+ else
+ return type;
+ }
+ }
+
}
package org.simantics.scl.compiler.types.kinds;
+import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.types.exceptions.KindUnificationException;
public class Kinds {
public static boolean equals(Kind a, Kind b) {
return equalsCanonical(canonical(a), canonical(b));
+ }
+
+ public static Kind rangeOfArrow(Kind kind) {
+ kind = canonical(kind);
+ if(kind instanceof KArrow)
+ return ((KArrow)kind).range;
+ else if(kind instanceof KMetaVar) {
+ Kind domain = Kinds.metaVar();
+ Kind range = Kinds.metaVar();
+ try {
+ ((KMetaVar)kind).setRef(arrow(domain, range));
+ } catch (KindUnificationException e) {
+ // Should not fail because kind is canonical
+ e.printStackTrace();
+ }
+ return range;
+ }
+ else
+ throw new InternalCompilerError("Assumed arrow kind but encountered " + kind + ".");
}
}
--- /dev/null
+package org.simantics.scl.compiler.types.util;
+
+import java.util.ArrayList;
+
+import org.simantics.scl.compiler.types.Skeletons;
+import org.simantics.scl.compiler.types.TApply;
+import org.simantics.scl.compiler.types.TForAll;
+import org.simantics.scl.compiler.types.TFun;
+import org.simantics.scl.compiler.types.TMetaVar;
+import org.simantics.scl.compiler.types.TMetaVar.TMetaVarListener;
+import org.simantics.scl.compiler.types.TPred;
+import org.simantics.scl.compiler.types.Type;
+
+public abstract class TypeListener {
+ private ArrayList<TMetaVarListener> metaVarListeners = new ArrayList<TMetaVarListener>(2);
+ public abstract void notifyAboutChange();
+
+ private static class SubListener extends TMetaVarListener {
+ private final TypeListener parent;
+ public SubListener(TypeListener parent) {
+ this.parent = parent;
+ } @Override
+ public void notifyAboutChange() {
+ for(TMetaVarListener otherListeners : parent.metaVarListeners)
+ otherListeners.remove();
+ parent.notifyAboutChange();
+ }
+ };
+
+ public void listenSkeleton(Type type) {
+ type = Skeletons.canonicalSkeleton(type);
+ if(type instanceof TMetaVar) {
+ TMetaVar metaVar = (TMetaVar)type;
+ TMetaVarListener latestListener = metaVar.getLatestListener();
+ if(latestListener instanceof SubListener &&
+ ((SubListener)latestListener).parent == this)
+ return;
+
+ SubListener subListener = new SubListener(this);
+ metaVarListeners.add(subListener);
+ metaVar.addListener(subListener);
+ }
+ else if(type instanceof TApply) {
+ TApply apply = (TApply)type;
+ listenSkeleton(apply.function);
+ listenSkeleton(apply.parameter);
+ }
+ else if(type instanceof TFun) {
+ TFun fun = (TFun)type;
+ listenSkeleton(fun.domain);
+ listenSkeleton(fun.range);
+ }
+ else if(type instanceof TForAll) {
+ TForAll forAll = (TForAll)type;
+ listenSkeleton(forAll.type);
+ }
+ else if(type instanceof TPred) {
+ TPred pred = (TPred)type;
+ for(Type parameter : pred.parameters)
+ listenSkeleton(parameter);
+ }
+ }
+}
--- /dev/null
+package org.simantics.scl.compiler.types.util;\r
+\r
+import org.simantics.scl.compiler.types.Skeletons;\r
+import org.simantics.scl.compiler.types.TMetaVar;\r
+import org.simantics.scl.compiler.types.Type;\r
+\r
+public class TypeTree<T> {\r
+ \r
+ public static class Case<T> {\r
+ public Type[] types;\r
+ public T result;\r
+ }\r
+ \r
+ private static class Node<T> {\r
+ Case<T>[] cases;\r
+ Branch<T>[] branches;\r
+\r
+ public Node(Case<T>[] cases) {\r
+ this.cases = cases;\r
+ this.branches = new Branch[cases[0].types.length];\r
+ }\r
+ \r
+ Branch<T> getBranch(int i) {\r
+ // TODO\r
+ return null;\r
+ }\r
+ }\r
+ \r
+ private static class Branch<T> {\r
+\r
+ public void improve(Iterator<T> iterator) {\r
+ // TODO Auto-generated method stub\r
+ \r
+ }\r
+ \r
+ }\r
+ \r
+ public static class Iterator<T> {\r
+ Node<T> node;\r
+ Type[] scrutinee;\r
+ \r
+ public Iterator(Node<T> node, Type[] scrutinee) {\r
+ this.node = node;\r
+ this.scrutinee = scrutinee;\r
+ }\r
+ \r
+ public void improve() {\r
+ for(int i=0;i<scrutinee.length;++i) {\r
+ Type type = scrutinee[i] = Skeletons.canonicalSkeleton(scrutinee[i]);\r
+ if(!(type instanceof TMetaVar)) {\r
+ Branch<T> branch = node.getBranch(i);\r
+ if(branch != null) {\r
+ branch.improve(this);\r
+ --i;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
+ Node<T> root;\r
+ \r
+ public TypeTree(Case<T>[] cases) {\r
+ this.root = new Node<T>(cases);\r
+ }\r
+ \r
+ public Iterator<T> iterator(Type ... scrutinee) {\r
+ return new Iterator<T>(root, scrutinee);\r
+ }\r
+}\r
public ActiveTests() { super("scl"); }
@Test public void Equations1() { test(); }
- @Test public void Equality() { test(); }
- @Test public void ModuleInitialization() { test(); }
-
- @Test public void ImportJavaConstructor() { test(); }
- @Test public void MarketModel() { test(); }
@Test public void MarketModel2() { test(); }
- @Ignore
+ @Test public void Overloading2() { test(); }
+ @Test public void Overloading3() { test(); }
+ //@Ignore
@Test public void PatternError() { test(); }
- @Test public void TypeAliasRefsToTypeAlias() { test(); }
+ @Test public void Serialization() { test(); }
@Ignore
@Test public void TypeClass2() { test(); }
@Test public void TypeClassBug2() { test(); }
--- /dev/null
+package org.simantics.scl.compiler.tests;\r
+\r
+import java.lang.reflect.Method;\r
+\r
+import org.objectweb.asm.ClassWriter;\r
+import org.objectweb.asm.MethodVisitor;\r
+import org.objectweb.asm.Opcodes;\r
+\r
+public class FindAllowedChars {\r
+ public static class MyClassLoader extends ClassLoader {\r
+ final String className;\r
+ final byte[] classBytes;\r
+ \r
+ public MyClassLoader(ClassLoader parent, String className, byte[] classBytes) {\r
+ super(parent);\r
+ this.className = className;\r
+ this.classBytes = classBytes;\r
+ }\r
+ \r
+ public MyClassLoader(String className, byte[] classBytes) {\r
+ this.className = className;\r
+ this.classBytes = classBytes;\r
+ }\r
+\r
+ @Override\r
+ protected Class<?> findClass(String name) throws ClassNotFoundException {\r
+ if(name.equals(name))\r
+ return defineClass(name, classBytes, 0, classBytes.length);\r
+ else\r
+ return super.findClass(name);\r
+ }\r
+ }\r
+ \r
+ public static void test(String className, String methodName) throws Exception {\r
+ ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);\r
+ classWriter.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, className, null, "java/lang/Object", null);\r
+ \r
+ MethodVisitor methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, methodName, "()V", null, null);\r
+ /*methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");\r
+ methodVisitor.visitLdcInsn("Hello world!");\r
+ methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);*/\r
+ methodVisitor.visitInsn(Opcodes.RETURN);\r
+ methodVisitor.visitMaxs(0, 0);\r
+ methodVisitor.visitEnd();\r
+ classWriter.visitEnd();\r
+ \r
+ ClassLoader loader = new MyClassLoader(className, classWriter.toByteArray());\r
+ Class<?> clazz = loader.loadClass(className);\r
+ Method method = clazz.getMethod(methodName);\r
+ method.invoke(null);\r
+ }\r
+ \r
+ public static void main(String[] args) throws Exception {\r
+ for(int a=Character.MIN_VALUE;a<Character.MAX_VALUE;++a) {\r
+ //for(char b=0;b<256;++b) {\r
+ String name = new String(new char[] {(char)a});\r
+ try {\r
+ test(name, "test");\r
+ } catch(Throwable e) {\r
+ System.out.println(name + " (" + a + ")");\r
+ }\r
+ //} \r
+ }\r
+ System.out.println((int)Character.MAX_VALUE);\r
+ }\r
+}\r
+++ /dev/null
-package org.simantics.scl.compiler.tests;
-
-import org.junit.Test;
-
-public class FutureTests extends TestBase {
-
- public FutureTests() { super("scl"); }
-
- @Test public void BigInstances() { test(); }
- @Test public void Matching3() { test(); }
- @Test public void Seq() { test(); }
-
-}
package org.simantics.scl.compiler.tests;
+import org.junit.AfterClass;
import org.junit.Test;
+import org.simantics.scl.compiler.errors.Failable;
+import org.simantics.scl.compiler.module.Module;
+import org.simantics.scl.compiler.module.coverage.CoverageUtils;
+import org.simantics.scl.compiler.module.coverage.ModuleCoverage;
import org.simantics.scl.compiler.top.ValueNotFound;
+import org.simantics.scl.runtime.profiling.BranchPoint;
-public class RegressionTestsWithoutPrelude extends TestBase {
-
- public RegressionTestsWithoutPrelude() { super("scl"); }
+public class ModuleRegressionTests extends TestBase {
+
+ public ModuleRegressionTests() { super("scl"); }
@Test public void AmbiguousType() { test(); }
@Test public void ApplicationOfNunfunction() { test(); }
@Test public void Arity1() { test(); }
@Test public void AsPattern() { test(); }
+ @Test public void BigContext() { test(); }
+ @Test public void BigFunction() { test(); }
+ @Test public void BinaryOperators1() { test(); }
@Test public void BooleanId() { test(); }
+ @Test public void Bug4450() { test(); }
+ @Test public void Character1() { test(); }
@Test public void ClashingClass() { test(); }
@Test public void ClashingData() { test(); }
@Test public void ClashingInstance() { test(); }
@Test public void ClashingValueType() { test(); }
+ @Test public void Collaz() { test(); }
@Test public void Compose() { test(); }
@Test public void Composition() { test(); }
@Test public void ConjunctionMacro() { test(); }
@Test public void Constant() { test(); }
@Test public void ConstructorNameClash() { test(); }
@Test public void DefaultMethods1() { test(); }
+ @Test public void Deriving3() { test(); }
+ @Test public void Deriving4() { test(); }
+ @Test public void DifferentBranchTypes() { test(); }
+ @Test public void Div() { test(); }
+ @Test public void DoubleConversion() { test(); }
@Test public void DoubleEffect() { test(); }
@Test public void Effects1() { test(); }
@Test public void Effects2() { test(); }
@Test public void Effects6() { test(); }
@Test(expected=ValueNotFound.class)
public void EmptyModule() throws ValueNotFound {
- test("EmptyModule", "");
+ test(new String[]{"EmptyModule"}, new String[]{""});
}
+ @Test public void Equality() { test(); }
@Test public void ExistentialData() { test(); }
@Test public void ExistentialData2() { test(); }
+ @Test public void ExpressionParsing() { test(); }
@Test public void FaultyRecursion() { test(); }
@Test public void Fibonacci() { test(); }
+ @Test public void Fibonacci2() { test(); }
@Test public void Fibonacci3() { test(); }
@Test public void FingerTree() { test(); }
+ @Test public void FoldMissingInitialValue() { test(); }
+ @Test public void FoldlBuild1() { test(); }
+ @Test public void FoldlBuild2() { test(); }
@Test public void Forall1() { test(); }
@Test public void Forall2() { test(); }
@Test public void Forall3() { test(); }
+ @Test public void Formula() { test(); }
+ @Test public void FromDynamic() { test(); }
+ @Test public void FromDynamic2() { test(); }
+ @Test public void FromDynamic3() { test(); }
+ @Test public void FromDynamic4() { test(); }
+ @Test public void FromDynamic5() { test(); }
+ @Test public void FunctionFunctor() { test(); }
@Test public void Functor() { test(); }
+ @Test public void FunctorM1() { test(); }
@Test public void Generalization() { test(); }
+ @Test public void GenericMutualRecursion() { test(); }
+ @Test public void GlobalVariables() { test(); }
@Test public void GuardedExpressionBug() { test(); }
+ @Test public void Guards1() { test(); }
+ @Test public void Guards2() { test(); }
@Test public void IdAsOperator() { test(); }
@Test public void IllegalChar() { test(); }
+ @Test public void ImportJavaConstructor() { test(); }
@Test public void ImportRef() { test(); }
@Test public void InconsistentArity() { test(); }
@Test public void InconsistentIndentation() { test(); }
@Test public void IndentationAndParenthesis() { test(); }
+ @Test public void Index() { test(); }
@Test public void Inline1() { test(); }
+ @Test public void InstanceHierarchy() { test(); }
@Test public void InstanceIsTypoedAsClass() { test(); }
@Test public void InvalidClass1() { test(); }
@Test public void InvalidEncoding() { test(); }
@Test public void InvalidKinds2() { test(); }
@Test public void InvalidKinds3() { test(); }
@Test public void InvalidLambda() { test(); }
+ @Test public void InvalidModule() { test(); }
@Test public void InvalidPattern1() { test(); }
@Test public void InvalidPattern2() { test(); }
@Test public void InvalidPattern3() { test(); }
@Test public void JavaTypes() { test(); }
@Test public void Kinds1() { test(); }
@Test public void Lambda() { test(); }
+ @Test public void Layout1() { test(); }
@Test public void List() { test(); }
@Test public void ListError1() { test(); }
@Test public void ListError2() { test(); }
+ @Test public void ListSyntax() { test(); }
+ @Test public void ListSyntax10() { test(); }
+ @Test public void ListSyntax11() { test(); }
+ @Test public void ListSyntax12() { test(); }
+ @Test public void ListSyntax2() { test(); }
+ @Test public void ListSyntax3() { test(); }
+ @Test public void ListSyntax4() { test(); }
+ @Test public void ListSyntax5() { test(); }
+ @Test public void ListSyntax6() { test(); }
+ @Test public void ListSyntax7() { test(); }
+ @Test public void ListSyntax8() { test(); }
+ @Test public void ListSyntax9() { test(); }
@Test public void ListSyntaxWithoutPrelude() { test(); }
@Test public void LocalDefinitions() { test(); }
@Test public void LocalDefinitions2() { test(); }
@Test public void LocalDefinitions3() { test(); }
@Test public void LocalDefinitions4() { test(); }
+ @Test public void LocalDefinitions5() { test(); }
@Test public void Macros1() { test(); }
@Test public void Macros2() { test(); }
@Test public void Macros4() { test(); }
@Test public void Map1() { test(); }
+ @Test public void MarketModel() { test(); }
@Test public void Matching() { test(); }
@Test public void Matching2() { test(); }
- @Test public void Matching5() { test(); }
+ @Test public void Matching4() { test(); }
+ @Test public void Matching5() { test(); }
+ @Test public void MatchingWithMissingParameter() { test(); }
@Test public void MatchingWithoutTypeAnnotations() { test(); }
+ @Test public void MaximumBy() { test(); }
@Test public void Maybe1() { test(); }
@Test public void Maybe2() { test(); }
@Test public void Maybe3() { test(); }
+ @Test public void Maybe4() { test(); }
+ @Test public void MissingEffect() { test(); }
@Test public void MissingMethod() { test(); }
+ @Test public void ModuleInitialization() { test(); }
@Test public void MonadBug1() { test(); }
+ @Test public void MonadSyntax1() { test(); }
+ @Test public void Monads1() { test(); }
@Test public void NoDefinitionErrorMessage() { test(); }
@Test public void NoInstance() { test(); }
@Test public void NoInstance2() { test(); }
@Test public void NonassociativeOperator() { test(); }
+ @Test public void NonexistentTypeClassInAnnotation() { test(); }
@Test public void NonexistingEffect() { test(); }
@Test public void OneLineMatch() { test(); }
@Test public void OpenString1() { test(); }
@Test public void OverloadedArithmetic1() { test(); }
@Test public void OverloadedArithmetic2() { test(); }
@Test public void OverloadedArithmetic3() { test(); }
+ @Test public void OverloadedLiterals2() { test(); }
+ @Test public void Overloading1() { test(); }
+ @Test public void Parsing() { test(); }
@Test public void PolymorphicRecursion() { test(); }
@Test public void PolymorphicRecursion2() { test(); }
+ @Test public void Polynomials() { test(); }
@Test public void PrecedenceOfNonoperators() { test(); }
@Test public void Primes() { test(); }
+ @Test public void Proc1() { test(); }
+ @Test public void Proc2() { test(); }
+ @Test public void Proc3() { test(); }
@Test public void Pythagoras() { test(); }
+ @Test public void Random1() { test(); }
+ @Test public void RangeSyntax() { test(); }
+ @Test public void Record1() { test(); }
+ @Test public void RecordShorthand() { test(); }
@Test public void RecursiveContext() { test(); }
@Test public void RecursiveValues2() { test(); }
@Test public void RecursiveValues3() { test(); }
@Test public void RecursiveValues4() { test(); }
+ @Test public void RedBlackTrees() { test(); }
+ @Test public void Relations1() { test(); }
+ @Test public void Relations2() { test(); }
@Test public void RepeatedVariableInPattern() { test(); }
+ @Test public void SSATypingBug() { test(); }
+ @Test public void Scanl() { test(); }
+ @Test public void Search() { test(); }
+ @Test public void Sections() { test(); }
+ @Test public void Select1() { test(); }
+ @Test public void Select2() { test(); }
+ @Test public void Select3() { test(); }
+ @Test public void Select4() { test(); }
+ @Test public void Select5() { test(); }
+ @Test public void Select6() { test(); }
+ @Test public void Select7() { test(); }
+ @Test public void Select8() { test(); }
+ @Test public void Select9() { test(); }
@Test public void SelfReferringContextInTypeClass() { test(); }
+ @Test public void Serialization2() { test(); }
+ @Test public void Serialization3() { test(); }
@Test public void SharedTypeVariable() { test(); }
@Test public void ShortcutFusion() { test(); }
+ @Test public void Show1() { test(); }
+ @Test public void SinConst1() { test(); }
+ @Test public void Sort() { test(); }
@Test public void Sort2() { test(); }
@Test public void StreamFusion() { test(); }
+ @Test public void StringEscape() { test(); }
+ @Test public void StringInterpolation1() { test(); }
@Test public void StringMatching1() { test(); }
+ @Test public void SumOfInverses2() { test(); }
+ @Test public void TooManyParametersToSin() { test(); }
+ @Test public void Transformation1() { test(); }
+ @Test public void Transformation2() { test(); }
+ @Test public void Transformation3() { test(); }
+ @Test public void Transformation4() { test(); }
+ @Test public void Transformation5() { test(); }
+ @Test public void Transformation6() { test(); }
+ @Test public void Transformation7() { test(); }
+ @Test public void TransformationOrder() { test(); }
@Test public void Tuples() { test(); }
@Test public void Tuples2() { test(); }
@Test public void TypeAlias1() { test(); }
@Test public void TypeAlias2() { test(); }
@Test public void TypeAlias3() { test(); }
+ @Test public void TypeAliasRefsToTypeAlias() { test(); }
@Test public void TypeAnnotation1() { test(); }
@Test public void TypeAnnotation2() { test(); }
@Test public void TypeClass() { test(); }
@Test public void TypeClassBug1() { test(); }
+ @Test(timeout=1000L) public void TypeInferenceBug2() { test(); }
+ @Test public void TypeOf1() { test(); }
@Test public void TypingBug1() { test(); }
@Test public void TypingError1() { test(); }
@Test public void TypingError2() { test(); }
+ @Test public void UnaryMinus() { test(); }
@Test public void UndefinedValue() { test(); }
@Test public void UnexpectedToken() { test(); }
+ @Test public void Unification1() { test(); }
@Test public void UnknownAnnotation() { test(); }
@Test public void UnresolvedClass() { test(); }
@Test public void UnresolvedTypeInAnnotation() { test(); }
@Test public void UnresolvedVariable() { test(); }
@Test public void UnresolvedVariable2() { test(); }
@Test public void ValueAsOperator() { test(); }
+ @Test public void ValueConversion() { test(); }
+ @Test public void Vector1() { test(); }
+ @Test public void Vector2() { test(); }
@Test public void Void1() { test(); }
@Test public void Void2() { test(); }
@Test public void Void3() { test(); }
@Test public void While() { test(); }
+ @Test public void While2() { test(); }
+ @Test public void While3() { test(); }
@Test public void WrongDefaultMethod() { test(); }
@Test public void WrongInstanceMethod() { test(); }
-
+
+ @AfterClass
+ public static void checkCoverage() {
+ Failable<Module> maybeModule = PRELUDE_MODULE_REPOSITORY.getModule("Prelude");
+ if(!maybeModule.didSucceed())
+ return;
+ Module module = maybeModule.getResult();
+ ModuleCoverage coverage = CoverageUtils.getCoverage(module);
+ if(coverage == null)
+ return;
+ coverage.print(System.out);
+ printCoverageTree(module.getBranchPoints().get("lookup"), 0);
+ }
+
+ private static void printCoverageTree(BranchPoint[] branchPoints, int ind) {
+ for(BranchPoint bp : branchPoints) {
+ for(int i=0;i<ind;++i)
+ System.out.print(" ");
+ System.out.println(bp.codeSize);
+ printCoverageTree(bp.children, ind+1);
+ }
+ }
+
}
@RunWith(Suite.class)
@SuiteClasses({
- RegressionTestsWithoutPrelude.class,
- RegressionTestsWithPrelude.class,
+ ModuleRegressionTests.class,
TestExpressionEvaluator.class,
TestCommandSession.class
})
+++ /dev/null
-package org.simantics.scl.compiler.tests;
-
-import org.junit.Test;
-
-public class RegressionTestsWithPrelude extends TestBase {
-
- public RegressionTestsWithPrelude() { super("scl"); }
-
- @Test public void BigContext() { test(); }
- @Test public void BigFunction() { test(); }
- @Test public void BinaryOperators1() { test(); }
- @Test public void Bug4450() { test(); }
- @Test public void Character1() { test(); }
- @Test public void Collaz() { test(); }
- @Test public void Deriving1() { test(); }
- @Test public void Deriving3() { test(); }
- @Test public void Deriving4() { test(); }
- @Test public void Div() { test(); }
- @Test public void DoubleConversion() { test(); }
- @Test public void ExpressionParsing() { test(); }
- @Test public void Fibonacci2() { test(); }
- @Test public void FoldlBuild1() { test(); }
- @Test public void FoldlBuild2() { test(); }
- @Test public void FoldMissingInitialValue() { test(); }
- @Test public void FromDynamic() { test(); }
- @Test public void FromDynamic2() { test(); }
- @Test public void FromDynamic3() { test(); }
- @Test public void FromDynamic4() { test(); }
- @Test public void FromDynamic5() { test(); }
- @Test public void FunctionFunctor() { test(); }
- @Test public void FunctorM1() { test(); }
- @Test public void GenericMutualRecursion() { test(); }
- @Test public void GlobalVariables() { test(); }
- @Test public void Guards1() { test(); }
- @Test public void Guards2() { test(); }
- @Test public void Hashable1() { test(); }
- @Test public void Hashable2() { test(); }
- @Test public void Index() { test(); }
- @Test public void InstanceHierarchy() { test(); }
- @Test public void InvalidModule() { test(); }
- @Test public void Layout1() { test(); }
- @Test public void ListSyntax() { test(); }
- @Test public void ListSyntax2() { test(); }
- @Test public void ListSyntax3() { test(); }
- @Test public void ListSyntax4() { test(); }
- @Test public void ListSyntax5() { test(); }
- @Test public void ListSyntax6() { test(); }
- @Test public void ListSyntax7() { test(); }
- @Test public void ListSyntax8() { test(); }
- @Test public void ListSyntax9() { test(); }
- @Test public void ListSyntax10() { test(); }
- @Test public void ListSyntax11() { test(); }
- @Test public void ListSyntax12() { test(); }
- @Test public void LocalDefinitions5() { test(); }
- @Test public void Matching4() { test(); }
- @Test public void MaximumBy() { test(); }
- @Test public void Maybe4() { test(); }
- @Test public void MissingEffect() { test(); }
- @Test public void Monads1() { test(); }
- @Test public void MonadSyntax1() { test(); }
- @Test public void NonexistentTypeClassInAnnotation() { test(); }
- @Test public void OverloadedLiterals2() { test(); }
- @Test public void Parsing() { test(); }
- @Test public void Polynomials() { test(); }
- @Test public void Proc1() { test(); }
- @Test public void Proc2() { test(); }
- @Test public void Proc3() { test(); }
- @Test public void Random1() { test(); }
- @Test public void RangeSyntax() { test(); }
- @Test public void Record1() { test(); }
- @Test public void RedBlackTrees() { test(); }
- @Test public void Relations1() { test(); }
- @Test public void Relations2() { test(); }
- @Test public void Scanl() { test(); }
- @Test public void Search() { test(); }
- @Test public void Sections() { test(); }
- @Test public void Select1() { test(); }
- @Test public void Select2() { test(); }
- @Test public void Select3() { test(); }
- @Test public void Select4() { test(); }
- @Test public void Select5() { test(); }
- @Test public void Select6() { test(); }
- @Test public void Select7() { test(); }
- @Test public void Select8() { test(); }
- @Test public void Select9() { test(); }
- @Test public void Serialization() { test(); }
- @Test public void Serialization2() { test(); }
- @Test public void Serialization3() { test(); }
- @Test public void Show1() { test(); }
- @Test public void SinConst1() { test(); }
- @Test public void Sort() { test(); }
- @Test public void SSATypingBug() { test(); }
- @Test public void StringInterpolation1() { test(); }
- @Test public void SumOfInverses2() { test(); }
- @Test public void TooManyParametersToSin() { test(); }
- @Test public void Transformation1() { test(); }
- @Test public void Transformation2() { test(); }
- @Test public void Transformation3() { test(); }
- @Test public void Transformation4() { test(); }
- @Test public void Transformation5() { test(); }
- @Test public void Transformation6() { test(); }
- @Test public void Transformation7() { test(); }
- @Test public void TransformationOrder() { test(); }
- @Test(timeout=1000L) public void TypeInferenceBug2() { test(); }
- @Test public void TypeOf1() { test(); }
- @Test public void UnaryMinus() { test(); }
- @Test public void Unification1() { test(); }
- @Test public void ValueConversion() { test(); }
- @Test public void Vector1() { test(); }
- @Test public void Vector2() { test(); }
- @Test public void While2() { test(); }
- @Test public void While3() { test(); }
-
-}
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.regex.Pattern;
import org.simantics.scl.compiler.module.Module;
import org.simantics.scl.compiler.module.repository.ModuleRepository;
import org.simantics.scl.compiler.module.repository.UpdateListener;
+import org.simantics.scl.compiler.source.ModuleSource;
import org.simantics.scl.compiler.source.StringModuleSource;
import org.simantics.scl.compiler.source.repository.CompositeModuleSourceRepository;
import org.simantics.scl.compiler.source.repository.MapModuleSourceRepository;
SourceRepositories.BUILTIN_SOURCE_REPOSITORY,
SourceRepositories.PRELUDE_SOURCE_REPOSITORY
));
- private static final Pattern TEST_SEPARATOR = Pattern.compile("^-- *$", Pattern.MULTILINE);
+ private static final Pattern TEST_SEPARATOR = Pattern.compile("^--+ *$", Pattern.MULTILINE);
private static final Charset UTF8 = Charset.forName("UTF-8");
String path;
this.path = path;
}
-
protected void test() {
String testModuleName = Thread.currentThread().getStackTrace()[2].getMethodName();
String testPath = path + "/" + testModuleName + ".scl";
try {
String[] testParts = readTestParts(testPath);
- for(int i=0;i<testParts.length;i+=2) {
- String input = testParts[i];
- String expectedOutput = testParts[i+1];
- String actualOutput = test(testModuleName, input);
+
+ int j=0;
+ ArrayList<String> auxModuleNameList = new ArrayList<String>();
+ while(j < testParts.length) {
+ String part = testParts[j];
+ if(part.startsWith("// module "))
+ auxModuleNameList.add(part.substring(10).split("\\n", 2)[0].trim());
+ else
+ break;
+ ++j;
+ }
+ int mainId = j;
+ String[] moduleNames = new String[mainId+1];
+ String[] moduleTexts = new String[mainId+1];
+ for(int i=0;i<mainId;++i) {
+ moduleNames[i] = auxModuleNameList.get(i);
+ moduleTexts[i] = testParts[i];
+ }
+ moduleNames[mainId] = testModuleName;
+
+ for(;j<testParts.length;j+=2) {
+ moduleTexts[mainId] = testParts[j];
+ String expectedOutput = j+1<testParts.length ? testParts[j+1] : "";
+ String actualOutput = test(moduleNames, moduleTexts);
Assert.assertEquals(
canonicalizeOutput(expectedOutput),
canonicalizeOutput(actualOutput));
return text.trim().replace("\r\n", "\n");
}
- protected String test(String testModuleName, String input) throws ValueNotFound {
+ protected String test(String[] moduleNames, String[] moduleTexts) throws ValueNotFound {
+ if(moduleNames.length != moduleTexts.length)
+ throw new IllegalArgumentException();
+ /*for(int i=0;i<moduleNames.length;++i) {
+ System.out.println("-- " + moduleNames[i] + " --");
+ System.out.println(moduleTexts[i]);
+ }*/
+
+ ModuleSource[] moduleSources = new ModuleSource[moduleNames.length];
+ for(int i=0;i<moduleNames.length;++i)
+ moduleSources[i] = new StringModuleSource(
+ moduleNames[i], getClass().getClassLoader(), moduleTexts[i]) {
+ @Override
+ protected ImportDeclaration[] getBuiltinImports(UpdateListener listener) {
+ return ImportDeclaration.ONLY_BUILTINS;
+ }
+ };
ModuleRepository testEnvironment = new ModuleRepository(
PRELUDE_MODULE_REPOSITORY,
- new MapModuleSourceRepository(new StringModuleSource(
- testModuleName, getClass().getClassLoader(), input) {
- @Override
- protected ImportDeclaration[] getBuiltinImports(UpdateListener listener) {
- return ImportDeclaration.ONLY_BUILTINS;
- }
- }
- ));
- Failable<Module> result = testEnvironment.getModule(testModuleName);
+ new MapModuleSourceRepository(moduleSources));
+ int lastId = moduleNames.length-1;
+ Failable<Module> result = testEnvironment.getModule(moduleNames[lastId]);
if(!result.didSucceed())
- return ((Failure)result).toString(input);
+ return ((Failure)result).toString(moduleTexts[lastId]);
else {
- Object main = testEnvironment.getRuntimeModule(testModuleName).getResult().getValue("main");
+ Object main = testEnvironment.getRuntimeModule(moduleNames[lastId]).getResult().getValue("main");
return String.valueOf(main);
}
}
}
String text = new String(buffer, 0, pos, UTF8);
String[] result = TEST_SEPARATOR.split(text);
- if(result.length % 2 == 1) {
- result = Arrays.copyOf(result, result.length+2);
- result[result.length-1] = "";
+ for(int i=1;i<result.length;++i) {
+ if(result[i].startsWith("\r\n"))
+ result[i] = result[i].substring(2);
+ if(result[i].startsWith("\n") || result[i].startsWith("\r"))
+ result[i] = result[i].substring(1);
}
return result;
} finally {
package org.simantics.scl.compiler.tests;\r
\r
-import junit.framework.Assert;\r
-\r
import org.junit.Test;\r
import org.simantics.scl.compiler.elaboration.java.Builtins;\r
import org.simantics.scl.compiler.environment.specification.EnvironmentSpecification;\r
import org.simantics.scl.compiler.source.repository.ModuleSourceRepository;\r
import org.simantics.scl.compiler.top.ExpressionEvaluator;\r
\r
+import junit.framework.Assert;\r
+\r
public class TestClassNaming {\r
\r
private static class SimpleModuleSource extends StringModuleSource {\r
import java.util.Arrays;
-import junit.framework.Assert;
-
import org.junit.Before;
import org.junit.Test;
import org.simantics.scl.compiler.elaboration.expressions.EVariable;
import org.simantics.scl.runtime.function.Function;
import org.simantics.scl.runtime.tuple.Tuple0;
+import junit.framework.Assert;
+
public class TestExpressionEvaluator {
public static final boolean TIMING = false;
Assert.assertEquals(sum, result);
}
}
-
- @Test
- public void testSeq() throws Exception {
- String expressionText = "Sequences.runSequence mdo\n" +
- " repeatForever mdo\n" +
- " Sequences.wait 2\n" +
- " Sequences.stop";
-
- try {
- Object result = new ExpressionEvaluator(runtimeEnvironment, expressionText)
- .parseAsBlock(true)
- .eval();
- } catch(SCLExpressionCompilationException e) {
- System.out.println(CompilationErrorFormatter.toString(expressionText, e.getErrors()));
- throw e;
- }
- }
}
--- /dev/null
+package org.simantics.scl.compiler.tests;
+
+import org.cojen.classfile.TypeDesc;
+
+public class TestTypeDesc {
+ public static void main(String[] args) {
+ System.out.println(TypeDesc.forClass(String.class).getFullName());
+ System.out.println(TypeDesc.forClass(String.class).getDescriptor());
+ System.out.println(TypeDesc.forClass(String.class).getRootName());
+
+ }
+}
public UnimplementedTests() { super("scl"); }
+ @Test public void BigInstances() { test(); }
@Test public void BlankExpression() { test(); }
@Test public void ClashingValueDefinition() { test(); }
@Test public void FunctionalDependencies1() { test(); }
+++ /dev/null
-import "Prelude"\r
-\r
-data Vec2 = Vec2 Double Double\r
-\r
-deriving instance Eq Vec2\r
-\r
-main = Vec2 1 1 == Vec2 1 1\r
---\r
-true
\ No newline at end of file
--- /dev/null
+import "Prelude"
+
+foo n = n
+ where
+ if n > 0
+ then 1
+ else "asd"
+
+bar n = n
+ where
+ do
+ c = n+1
+ if c > 0
+ then 1
+ else "asd"
+
+main = foo 3 + bar 3
+--
+6
\ No newline at end of file
--- /dev/null
+import "Prelude"
+
+data Formula a = TrueF
+ | FalseF
+ | XorF (Formula a) (Formula a)
+ | AndF (Formula a) (Formula a)
+ | ConditionF a
+ | NextF (Formula a)
+ | UntilF (Formula a) (Formula a)
+
+deriving instance (Ord a) => Ord (Formula a)
+
+instance (Show a) => Show (Formula a) where
+ sb <+ TrueF = sb << "true"
+ sb <+ FalseF = sb << "false"
+ sb <+ XorF a b = sb << "(" <+ a << " `XorF` " <+ b << ")"
+ sb <+ AndF a b = sb << "(" <+ a << " &&& " <+ b << ")"
+ sb <+ ConditionF c = sb <+ c
+ sb <+ NextF a = sb << "(next " <+ a << ")"
+ sb <+ UntilF a b = sb << "(" <+ a << " `UntilF` " <+ b << ")"
+
+xorF FalseF f2 = f2
+xorF f1 FalseF = f1
+xorF f1@(XorF h1 t1) f2@(XorF h2 t2) =
+ let cmp = compare h1 h2
+ in if cmp < 0
+ then XorF h1 (xorF t1 f2)
+ else if cmp > 0
+ then XorF h2 (xorF f1 t2)
+ else xorF t1 t2
+xorF f1@(XorF h1 t1) f2 =
+ let cmp = compare h1 f2
+ in if cmp < 0
+ then XorF h1 (xorF t1 f2)
+ else if cmp > 0
+ then XorF f2 f1
+ else t1
+xorF f1 f2@(XorF h2 t2) =
+ let cmp = compare f1 h2
+ in if cmp < 0
+ then XorF f1 f2
+ else if cmp > 0
+ then XorF h2 (xorF f1 t2)
+ else t2
+xorF f1 f2 =
+ let cmp = compare f1 f2
+ in if cmp < 0
+ then XorF f1 f2
+ else if cmp > 0
+ then XorF f2 f1
+ else TrueF
+
+notF f = xorF TrueF f
+
+TrueF &&& f2 = f2
+f1 &&& TrueF = f1
+FalseF &&& _ = FalseF
+_ &&& FalseF = FalseF
+XorF h1 t1 &&& f2 = xorF (h1 &&& f2) (t1 &&& f2)
+f1 &&& XorF h2 t2 = xorF (f1 &&& h2) (f1 &&& t2)
+f1@(AndF h1 t1) &&& f2@(AndF h2 t2) =
+ let cmp = compare h1 h2
+ in if cmp < 0
+ then AndF h1 (t1 &&& f2)
+ else if cmp > 0
+ then AndF h2 (f1 &&& t2)
+ else AndF h1 (t1 &&& t2)
+f1@(AndF h1 t1) &&& f2 =
+ let cmp = compare h1 f2
+ in if cmp < 0
+ then AndF h1 (t1 &&& f2)
+ else if cmp > 0
+ then AndF f2 f1
+ else f1
+f1 &&& f2@(AndF h2 t2) =
+ let cmp = compare f1 h2
+ in if cmp < 0
+ then AndF f1 f2
+ else if cmp > 0
+ then AndF h2 (f1 &&& t2)
+ else f2
+f1 &&& f2 =
+ let cmp = compare f1 f2
+ in if cmp < 0
+ then AndF f1 f2
+ else if cmp > 0
+ then AndF f2 f1
+ else f1
+
+f1 ||| f2 = xorF (xorF f1 f2) (f1 &&& f2)
+
+eval :: Ord a => (a -> <e> Boolean) -> Formula a -> <e> Formula a
+eval s TrueF = TrueF
+eval s FalseF = FalseF
+eval s (XorF f1 f2) = xorF (eval s f1) (eval s f2)
+eval s (AndF f1 f2) = eval s f1 &&& eval s f2
+eval s (ConditionF c) = if s c then TrueF else FalseF
+eval s (NextF f) = f
+eval s (UntilF f1 f2) = eval s f2 ||| (eval s f1 &&& UntilF f1 f2)
+
+// Concrete conditions
+
+data V = V String (Ref Boolean)
+
+instance Ord V where
+ compare (V a _) (V b _) = compare a b
+instance Show V where
+ sb <+ V a _ = sb <+ a
+
+cond :: String -> Ref Boolean -> Formula V
+cond name ref = ConditionF (V name ref)
+
+// Testing
+
+x = ref True
+y = ref False
+
+f = cond "x" x `UntilF` cond "y" y
+
+evalV = eval (\(V _ c) -> getRef c)
+
+main = do
+ print (evalV f)
+ x := False
+ print (evalV f)
+ y = ref True
+ print (evalV f)
+ x := True
+ print (evalV f)
+--
+()
\ No newline at end of file
+++ /dev/null
-import "Prelude"\r
-\r
-l :: [Integer]\r
-l = [1,2,3,4,5]\r
-main = hash l - foldl (\c x -> 31*c + x) 0 l\r
---\r
--1625180697
\ No newline at end of file
+++ /dev/null
-import "Prelude"\r
-\r
-l :: [Double]\r
-l = [1,2,3,4,5]\r
-main = hash l\r
---\r
-849277455
\ No newline at end of file
main = \ /* no parameters */ -> 3
--
-2:30-2:32: Unexpected token '->' (ARROW). Expected one of ATTACHED_HASH, BEGIN_STRING, BLANK, CHAR, DO, ENFORCE, ESCAPED_SYMBOL, FLOAT, ID, IF, INTEGER, LAMBDA, LBRACKET, LET, LPAREN, MATCH, MDO, SELECT, SELECT_DISTINCT, SELECT_FIRST, TRANSFORMATION, WHEN.
+2:30-2:32: Unexpected token '->' (ARROW). Expected one of ATTACHED_HASH, BEGIN_STRING, BLANK, CHAR, DO, ENFORCE, EQ, ESCAPED_SYMBOL, FLOAT, ID, IF, INTEGER, LAMBDA, LBRACKET, LET, LPAREN, MATCH, MDO, SELECT, SELECT_DISTINCT, SELECT_FIRST, TRANSFORMATION, WHEN.
--- /dev/null
+import "StandardLibrary"
+
+foo 1 = "one"
+foo 2 = "two"
+
+main = if True then foo (2 :: Long) else foo (1 :: Integer)
+--
+two
\ No newline at end of file
--- /dev/null
+data Foo = Foo Integer Integer
+ | Bar
+
+isFoo (Foo _) = True
+isFoo _ = False
+
+main = "Hello world!"
+--
+4:7-4:14: The function is applied with too few parameters.
+
--- /dev/null
+// module Foo1
+import "Prelude"
+
+foo :: Integer -> Boolean
+foo i = i == 5
+--
+// module Foo2
+import "Prelude"
+
+foo :: Integer -> Integer -> Boolean
+foo i j = i == j
+--
+import "Prelude"
+import "Foo1"
+import "Foo2"
+
+main = foo 5 && foo 5 4
+--
+false
\ No newline at end of file
--- /dev/null
+// module Max1
+import "Prelude"
+
+myMax :: Ord a => a -> a -> a
+myMax = max
+--
+// module Max2
+import "Prelude"
+
+myMax :: Ord a => a -> a -> a -> a
+myMax a b c = max a (max b c)
+--
+import "Prelude"
+import "Max1"
+import "Max2"
+
+main = myMax (1 :: Integer) 2 3 + myMax (3 :: Integer) 2 1 + myMax 4 2 :: Integer
+--
+10
+
--- /dev/null
+// module M1
+import "Prelude"
+
+foo :: Ring a => Boolean -> a -> a
+foo True v = v+1
+foo False v = v+1
+--
+// module M2
+import "Prelude"
+
+foo :: Ring a => String -> a -> a
+foo cond v = if cond=="true"
+ then v+1
+ else v-1
+--
+import "Prelude"
+import "M1"
+import "M2"
+
+main = foo False (foo "True" 10) :: Integer
+--
+10
+
--- /dev/null
+import "Prelude"
+
+data Vec = Vec { x :: Double, y :: Double }
+deriving instance Show Vec
+
+createVec x y = Vec {x, y}
+sumVec Vec { x1, y1 } Vec { x2, y2 } = Vec { x = x1+x2, y = y1 + y2 }
+
+main = sumVec (createVec 1 2) (createVec 3 4)
+--
+(Vec 4.0 6.0)
\ No newline at end of file
+++ /dev/null
-import "Prelude"\r
-import "JavaBuiltin" as Java\r
-\r
-class Seq seq el where\r
- myLength :: seq -> Integer\r
- myGet :: seq -> Integer -> el\r
-\r
-instance (b ~ Character) => Seq String b where\r
- myLength = Java.method "length"\r
- myGet = Java.method "charAt"\r
- \r
-instance (b ~ a) => Seq [a] b where\r
- myLength = Java.method "size"\r
- myGet = Java.method "get"\r
-\r
-//main :: (Character, String)\r
-main = (myGet "abc" 1, myGet ["a", "b", "c"] 1)\r
---\r
-(b,b)
\ No newline at end of file
--- /dev/null
+main = "a\nb\"c\'d"\r
+--\r
+a\r
+b"c'd\r
+--\r
+main = "a\u0053"\r
+--\r
+aS\r
+--\r
+main = "a\xb"\r
+--\r
+1:8-1:10: Illegal string escape character.\r
-a = =\r
-b = 4\r
---\r
-1:5-1:6: Unexpected token '=' (EQUALS). Expected one of ATTACHED_HASH, BEGIN_STRING, BLANK, CHAR, DO, ENFORCE, ESCAPED_SYMBOL, FLOAT, ID, IF, INTEGER, LAMBDA, LBRACKET, LET, LPAREN, MATCH, MDO, MINUS, SELECT, SELECT_DISTINCT, SELECT_FIRST, TRANSFORMATION, WHEN.\r
+a = =
+b = 4
+--
+1:5-1:6: Unexpected token '=' (EQUALS). Expected one of ATTACHED_HASH, BEGIN_STRING, BLANK, CHAR, DO, ENFORCE, EQ, ESCAPED_SYMBOL, FLOAT, ID, IF, INTEGER, LAMBDA, LBRACKET, LET, LPAREN, MATCH, MDO, MINUS, SELECT, SELECT_DISTINCT, SELECT_FIRST, TRANSFORMATION, WHEN.
\ No newline at end of file
package org.simantics.scl.compiler.tests.unit;\r
\r
-import gnu.trove.set.hash.THashSet;\r
-\r
import java.util.Collection;\r
\r
-import junit.framework.Assert;\r
-\r
import org.junit.Test;\r
import org.simantics.scl.compiler.environment.filter.AcceptAllNamespaceFilter;\r
import org.simantics.scl.compiler.environment.filter.NamespaceFilter;\r
import org.simantics.scl.compiler.environment.filter.NegativeNamespaceFilter;\r
import org.simantics.scl.compiler.environment.filter.PositiveNamespaceFilter;\r
\r
+import gnu.trove.set.hash.THashSet;\r
+import junit.framework.Assert;\r
+\r
public class TestNamespaceFilter {\r
\r
private void testBooleanOperations(Collection<String> all, NamespaceFilter a, NamespaceFilter b) {\r
}\r
\r
public void checkUpdates() {\r
- System.out.println(url + " checkUpdates");\r
if(digest != null && listeners != null) {\r
byte[] newDigest = computeDigest();\r
if(!Arrays.equals(digest, newDigest)) {\r
\r
@Override\r
public void update(String newSourceText) {\r
- System.out.println(url + " update");\r
try {\r
Path path = getPath();\r
Files.write(path, newSourceText.getBytes(Charset.forName("UTF-8")));\r
try {
CommandSession session = new CommandSession(SCLOsgi.MODULE_REPOSITORY, handler);
new TestScriptExecutor(session, reader, handler).execute();
- } catch(Throwable e) {
- CommandSession.formatException(handler, e);
- throw e;
} finally {
reader.close();
}
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.simantics.scl.runtime,
org.simantics.scl.runtime.collection,
- org.simantics.scl.runtime.equations,
+ org.simantics.scl.runtime.exceptions,
org.simantics.scl.runtime.function,
org.simantics.scl.runtime.io,
org.simantics.scl.runtime.lazy,
package org.simantics.scl.runtime;
-import gnu.trove.map.hash.TCustomHashMap;
-import gnu.trove.set.hash.THashSet;
-import gnu.trove.strategy.HashingStrategy;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import org.simantics.scl.runtime.function.FunctionImpl2;
import org.simantics.scl.runtime.tuple.Tuple2;
+import gnu.trove.map.hash.TCustomHashMap;
+import gnu.trove.set.hash.THashSet;
+import gnu.trove.strategy.HashingStrategy;
+
@SuppressWarnings({"rawtypes", "unchecked"})
public class Lists {
\r
import gnu.trove.map.hash.THashMap;\r
\r
-import java.util.Map;\r
-\r
public class SCLContext extends THashMap<String,Object> {\r
private static ThreadLocal<SCLContext> CONTEXT = new ThreadLocal<SCLContext>();\r
private static ThreadLocal<OldContextNode> OLD_CONTEXT = new ThreadLocal<OldContextNode>();\r
\r
import java.util.ArrayList;\r
import java.util.Collections;\r
-import java.util.Comparator;\r
import java.util.List;\r
\r
import org.simantics.scl.runtime.SCLContext;\r
--- /dev/null
+package org.simantics.scl.runtime.exceptions;\r
+\r
+public class MatchingException extends RuntimeException {\r
+ private static final long serialVersionUID = -3364111368224089448L;\r
+\r
+ public MatchingException() {\r
+ super();\r
+ }\r
+ \r
+ public MatchingException(String message) {\r
+ super(message);\r
+ }\r
+}\r
package org.simantics.scl.runtime.io;\r
\r
-import gnu.trove.list.array.TByteArrayList;\r
-\r
import java.io.EOFException;\r
import java.io.IOException;\r
import java.io.InputStream;\r
import java.io.OutputStream;\r
import java.nio.charset.Charset;\r
\r
+import gnu.trove.list.array.TByteArrayList;\r
+\r
public class SclIO {\r
\r
private static final Charset UTF8 = Charset.forName("UTF-8");\r
package org.simantics.scl.runtime.minigraph;
-import gnu.trove.impl.Constants;
-import gnu.trove.map.hash.TIntObjectHashMap;
-import gnu.trove.map.hash.TLongObjectHashMap;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.procedure.TIntProcedure;
-import gnu.trove.set.hash.TIntHashSet;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.simantics.scl.runtime.function.Function;
import org.simantics.scl.runtime.tuple.Tuple0;
+import gnu.trove.impl.Constants;
+import gnu.trove.map.hash.TIntObjectHashMap;
+import gnu.trove.map.hash.TLongObjectHashMap;
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.procedure.TIntProcedure;
+import gnu.trove.set.hash.TIntHashSet;
+
public class Minigraph {
private static final int[] EMPTY_INT_ARRAY = new int[0];
package org.simantics.scl.runtime.unification;
-import gnu.trove.map.hash.THashMap;
-
import java.util.Map;
import org.simantics.scl.runtime.function.Function;
import org.simantics.scl.runtime.tuple.Tuple0;
+import gnu.trove.map.hash.THashMap;
+
public class UMapUtils {
public static void put(Map<Object,Object> map, Object key, Object value) {
if(map.containsKey(key))
<arguments>
</arguments>
</buildCommand>
- <buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
</buildSpec>
<natures>
- <nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>