X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fexpressions%2FExpression.java;h=e01098c12df762eb3e32c43caaff6baaee3f36c6;hp=83d7ec4e7bb5290a407df6dc3d79dff8b7fed328;hb=f8576d4d2b3b30d76db552d624fc9f087b8940bd;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java index 83d7ec4e7..e01098c12 100755 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java @@ -1,13 +1,11 @@ package org.simantics.scl.compiler.elaboration.expressions; -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.common.precedence.Precedence; +import org.simantics.scl.compiler.constants.NoRepConstant; +import org.simantics.scl.compiler.elaboration.contexts.EnvironmentalContext; import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; @@ -36,6 +34,10 @@ import org.simantics.scl.compiler.types.exceptions.MatchException; import org.simantics.scl.compiler.types.kinds.Kinds; import org.simantics.scl.compiler.types.util.Typed; +import gnu.trove.map.hash.TObjectIntHashMap; +import gnu.trove.set.hash.THashSet; +import gnu.trove.set.hash.TIntHashSet; + public abstract class Expression extends Symbol implements Typed { public static final Expression[] EMPTY_ARRAY = new Expression[0]; @@ -77,10 +79,30 @@ public abstract class Expression extends Symbol implements Typed { public Expression inferType(TypingContext context) { return checkBasicType(context, Types.metaVar(Kinds.STAR)); } - - public Expression checkBasicType(TypingContext context, Type requiredType) { - return context.subsume(inferType(context), requiredType); - } + + public Expression checkBasicType(TypingContext context, Type requiredType) { + return context.subsume(inferType(context), requiredType); + } + + protected Expression applyPUnit(EnvironmentalContext context) { + Type type = Types.canonical(getType()); + if(type instanceof TFun) { + TFun fun = (TFun)type; + if(fun.getCanonicalDomain() == Types.PUNIT) { + EApply result = new EApply(location, this, new ELiteral(NoRepConstant.PUNIT)); + result.effect = fun.getCanonicalEffect(); + return result; + } + } + return this; + } + + public Expression checkIgnoredType(TypingContext context) { + Expression expression = inferType(context); + if(Types.canonical(expression.getType()) != Types.UNIT) + expression = new ESimpleLet(location, null, expression, new ELiteral(NoRepConstant.PUNIT)); + return expression; + } /** * Checks the type of the expression against the given type. Adds type @@ -89,7 +111,7 @@ public abstract class Expression extends Symbol implements Typed { public final Expression checkType(TypingContext context, Type requiredType) { //System.out.println("checkType: " + this + " :: " + requiredType); if(!context.isInPattern()) { - requiredType = Types.weakCanonical(requiredType); + requiredType = Types.canonical(requiredType); if(requiredType instanceof TForAll) { TForAll forAll = (TForAll)requiredType; TVar var = forAll.var; @@ -185,8 +207,6 @@ public abstract class Expression extends Symbol implements Typed { public abstract void collectFreeVariables(THashSet vars); public Expression simplify(SimplificationContext context) { - System.out.println("#############################"); - System.out.println(this); throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support simplify method."); }