X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fexpressions%2FEBind.java;h=af31cf9c200c5286f8c0737991807c5dfa0344d3;hb=131be5c413e1f9dc652b6b46c763625b30ad8350;hp=c72776b35829ea91b6aa90037b4920bf35c39458;hpb=82a87b8535628d47d9c381e1a3a2296fb67c7fd0;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBind.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBind.java index c72776b35..af31cf9c2 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBind.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBind.java @@ -11,6 +11,7 @@ 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.codegen.writer.CodeWriter; +import org.simantics.scl.compiler.internal.header.ModuleHeader; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; import org.simantics.scl.compiler.types.exceptions.MatchException; @@ -52,7 +53,11 @@ public class EBind extends SimplifiableExpression { @Override public Expression checkBasicType(TypingContext context, Type requiredType) { + ModuleHeader header = context.getCompilationContext().header; + boolean edo = header != null && header.edo; + monadType = Types.metaVar(Kinds.STAR_TO_STAR); + inContentType = Types.metaVar(Kinds.STAR); Type monadContent = Types.apply(monadType, inContentType); try { @@ -71,9 +76,15 @@ public class EBind extends SimplifiableExpression { pattern = pattern.checkTypeAsPattern(context, Types.metaVar(Kinds.STAR)); valueContentType = pattern.getType(); value = value.checkType(context, Types.apply(monadType, valueContentType)); - context.pushEffectUpperBound(location, blockType == BlockType.Monad ? Types.NO_EFFECTS : Types.metaVar(Kinds.EFFECT)); + if(edo) + context.pushEffectUpperBound(location, blockType == BlockType.Monad ? Types.NO_EFFECTS : Types.metaVar(Kinds.EFFECT)); in = in.checkType(context, requiredType); - effect = context.popEffectUpperBound(); + if(edo) { + effect = context.popEffectUpperBound(); + context.declareEffect(location, effect); + } + else + effect = Types.NO_EFFECTS; Type inType = in.getType(); setType(inType); return this; @@ -89,10 +100,6 @@ public class EBind extends SimplifiableExpression { */ @Override public Expression simplify(SimplificationContext context) { - value = value.simplify(context); - in = in.simplify(context); - pattern = pattern.simplify(context); - long loc = getLocation(); monadType = Types.canonical(monadType); valueContentType = Types.canonical(valueContentType); @@ -101,11 +108,11 @@ public class EBind extends SimplifiableExpression { Type[] types = blockType == BlockType.MonadE ? new Type[] {monadType, valueContentType, effect, inContentType} : new Type[] {monadType, valueContentType, inContentType}; - Expression simplified = new EApply(loc, + Expression simplified = new EApply(loc, effect, new EConstant(loc, context.getValue(blockType == BlockType.MonadE ? Names.Prelude_bindE : Names.Prelude_bind), types), monadEvidence, value, - new ELambda(loc, new Case[] { + new ELambda(loc, effect, new Case[] { new Case(new Expression[] { pattern }, in) })); simplified.setType(getType());