(refs #7508) Edo and modified mdo under edo feature 93/1093/2
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Tue, 10 Oct 2017 14:56:31 +0000 (17:56 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Tue, 10 Oct 2017 15:37:34 +0000 (18:37 +0300)
Change-Id: I37c9a0e09ef436f29a5fcd92d7f10f14671059c0

bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBind.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/header/ModuleHeader.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/parser/SCLLexer.flex
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/parser/SCLLexer.java
bundles/org.simantics.scl.db/scl/Simantics/GShow.scl
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/MonadSyntax3.scl
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/MonadSyntax4.scl
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/MonadSyntax5.scl [new file with mode: 0644]

index 5664db7bfdd768f17dbbda87c45a5c6abb8ae995..84cc220c1a0222e75def8781fe657eaff1a88aa3 100644 (file)
@@ -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,13 @@ 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();
+        else
+            effect = Types.NO_EFFECTS;
         Type inType = in.getType();
         setType(inType);
         return this;
index 0ab17f83478313ee3f5df5209850ce3178b198ef..7362b38ee1c81db4da85d7261640b273800e27fb 100644 (file)
@@ -8,6 +8,7 @@ import org.simantics.scl.compiler.elaboration.expressions.records.FieldAssignmen
 import org.simantics.scl.compiler.errors.ErrorLog;
 
 public class ModuleHeader {
+    public String deprecated;
     public String classLoader;
     public long classLoaderLocation;
     public String defaultLocalName;
@@ -16,6 +17,7 @@ public class ModuleHeader {
     // Features
     public boolean chr;
     public boolean fields;
+    public boolean edo;
     
     private void read(ErrorLog errorLog, FieldAssignment[] fields) {
         for(FieldAssignment assignment : fields)
@@ -60,6 +62,15 @@ public class ModuleHeader {
                         errorLog.log(assignment.value.location, "Expected string here.");
                 }
                 break;
+            case "deprecated":
+                if(assignment.value == null)
+                    deprecated = "";
+                else {
+                    deprecated = AnnotationUtils.extractString(assignment.value);
+                    if(deprecated == null)
+                        errorLog.log(assignment.value.location, "Expected string here.");
+                }
+                break;
             default:
                 errorLog.logWarning(assignment.location, "Unknown module header field was skipped.");
             }
@@ -69,6 +80,7 @@ public class ModuleHeader {
         switch(feature.name) {
         case "chr": chr = true; break;
         case "fields": fields = true; break;
+        case "edo": edo = true; break;
         default:
             errorLog.log(feature.location, "Unknown feature " + feature.name + ".");
         }
index 0aafe287261101a5ac1d099ae9b3c988e223a40b..595c082ca4c70151f946cf37a63353d4a078bd2e 100644 (file)
@@ -42,6 +42,9 @@ import gnu.trove.list.array.TIntArrayList;
     public boolean supportCHR() {
         return context.header == null ? false : context.header.chr;
     }
+    public boolean supportEDO() {
+        return context.header == null ? false : context.header.edo;
+    }
 %}
 
 letter          = [a-zA-Z_]
@@ -105,7 +108,7 @@ char_literal    = "'" ([^'\\\ufffd] | "\\" [^\ufffd]) "'"
   do              { return sym(SCLTerminals.DO); }
   eq              { return sym(options.supportEq ? SCLTerminals.EQ : SCLTerminals.ID); }
   mdo             { return sym(SCLTerminals.MDO); }
-  edo             { return sym(SCLTerminals.EDO); }
+  edo             { return sym(supportEDO() ? SCLTerminals.EDO : SCLTerminals.ID); }
   class           { return sym(SCLTerminals.CLASS); }
   effect          { return sym(SCLTerminals.EFFECT); }
   match           { return sym(SCLTerminals.MATCH); }
index fb9eb54d518293a91d5f3baab61b931a130c1e23..0caade6bf77160202c519831b25f30bd2365b5e9 100644 (file)
@@ -12,7 +12,7 @@ import gnu.trove.list.array.TIntArrayList;
 /**
  * This class is a scanner generated by 
  * <a href="http://www.jflex.de/">JFlex</a> 1.6.1
- * from the specification file <tt>C:/GamsGui/git/platform/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/parser/SCLLexer.flex</tt>
+ * from the specification file <tt>C:/Simugawa.git/git/platform/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/parser/SCLLexer.flex</tt>
  */
 public class SCLLexer {
 
@@ -607,6 +607,9 @@ public class SCLLexer {
     public boolean supportCHR() {
         return context.header == null ? false : context.header.chr;
     }
+    public boolean supportEDO() {
+        return context.header == null ? false : context.header.edo;
+    }
 
 
   /**
@@ -1194,7 +1197,7 @@ public class SCLLexer {
             }
           case 155: break;
           case 60: 
-            { return sym(SCLTerminals.EDO);
+            { return sym(supportEDO() ? SCLTerminals.EDO : SCLTerminals.ID);
             }
           case 156: break;
           case 61: 
index 693e3e31f4565fcba87d3ab494070fe878e22457..c3e899a8c06ff2b83956144f359f17e7a2cb3ae1 100644 (file)
@@ -1,3 +1,7 @@
+module {
+    features = [edo]
+}
+
 include "Simantics/DB" hiding (resourceId)
 import "http://www.simantics.org/Layer0-1.1" as L0
 import "http://www.simantics.org/Modeling-1.2" as MOD
index a61dc965d43b26806e4595c0f5ce2d88dbb7d289..f67b7c8b59fee99cb705a504ad3dcdd57cc44c93 100644 (file)
@@ -183,6 +183,7 @@ public class ModuleRegressionTests extends TestBase {
     @Test public void MonadSyntax1() { test(); }    
     @Test public void MonadSyntax3() { test(); }    
     @Test public void MonadSyntax4() { test(); }
+    @Test public void MonadSyntax5() { test(); }
     @Test public void NoDefinitionErrorMessage() { test(); }
     @Test public void NoInstance() { test(); }
     @Test public void NoInstance2() { test(); }
diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/MonadSyntax5.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/MonadSyntax5.scl
new file mode 100644 (file)
index 0000000..35327aa
--- /dev/null
@@ -0,0 +1,22 @@
+// Old mdo
+import "Prelude"
+
+main = mdo 
+  x <- [1,2]
+  return $ print "\(x :: Integer)"
+--
+1
+2
+[(), ()]
+--
+// New mdo
+module {
+    features = [edo]
+}
+import "Prelude"
+
+main = mdo 
+  x <- [1,2]
+  return $ print "\(x :: Integer)"
+--
+9:12-9:35: No side-effects allowed here.
\ No newline at end of file