]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/matching2/PatternMatchingCompiler2.java
SCL compiler generates line numbers to bytecode
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / elaboration / matching2 / PatternMatchingCompiler2.java
index 24a3bfb2edcc2e8208aefa4435974fec8b31af47..41882f57a5d86448a98ec049cd2783d6cf4ed58b 100644 (file)
@@ -54,7 +54,7 @@ public class PatternMatchingCompiler2 {
         return newVals;
     }
 
-    private static void splitByConstructors(CodeWriter w, final CompilationContext context, IVal[] scrutinee, ICont failure, List<Row2> rows, int columnId) {
+    private static void splitByConstructors(long location, CodeWriter w, final CompilationContext context, IVal[] scrutinee, ICont failure, List<Row2> rows, int columnId) {
         THashMap<Object, ExpressionMatrix> matrixMap = new THashMap<Object, ExpressionMatrix>();
         ArrayList<Branch> branches = new ArrayList<Branch>();
         ArrayList<ExpressionMatrix> matrices = new ArrayList<ExpressionMatrix>();
@@ -167,7 +167,7 @@ public class PatternMatchingCompiler2 {
             CodeWriter newW = w.createBlock();
             ICont cont = newW.getContinuation();
             branches.add(new Branch(null, cont));
-            split(newW, context, scrutinee, failure, rows.subList(i, rows.size()));
+            split(location, newW, context, scrutinee, failure, rows.subList(i, rows.size()));
             failure = cont;
         }
         else {
@@ -185,11 +185,11 @@ public class PatternMatchingCompiler2 {
         }
 
         for(ExpressionMatrix mx : matrices)
-            split(mx.w, context, mx.scrutinee, failure, mx.rows);
-        w.switch_(scrutinee[columnId], branches.toArray(new Branch[branches.size()]));
+            split(location, mx.w, context, mx.scrutinee, failure, mx.rows);
+        w.switch_(location, scrutinee[columnId], branches.toArray(new Branch[branches.size()]));
     }
 
-    private static void splitByViewPattern(CodeWriter w, CompilationContext context, IVal[] scrutinee, ICont failure, List<Row2> rows, int viewPatternColumn) {
+    private static void splitByViewPattern(long location, CodeWriter w, CompilationContext context, IVal[] scrutinee, ICont failure, List<Row2> rows, int viewPatternColumn) {
         Row2 firstRow = rows.get(0);
         EViewPattern firstViewPattern = (EViewPattern)firstRow.patterns[viewPatternColumn];
         firstRow.patterns[viewPatternColumn] = firstViewPattern.pattern;
@@ -223,16 +223,16 @@ public class PatternMatchingCompiler2 {
                         firstViewPattern.expression.toVal(context, w),
                         scrutinee[viewPatternColumn]);
         if(i == rows.size()) {
-            split(w, context, newScrutinee, failure, rows);
+            split(location, w, context, newScrutinee, failure, rows);
         }
         else {
             CodeWriter cont = w.createBlock();
-            split(w, context, newScrutinee, cont.getContinuation(), rows.subList(0, i));
-            split(cont, context, scrutinee, failure, rows.subList(i, rows.size()));
+            split(location, w, context, newScrutinee, cont.getContinuation(), rows.subList(0, i));
+            split(location, cont, context, scrutinee, failure, rows.subList(i, rows.size()));
         }
     }
 
-    public static void split(CodeWriter w, CompilationContext context, IVal[] scrutinee, ICont failure, List<Row2> rows) {
+    public static void split(long location, CodeWriter w, CompilationContext context, IVal[] scrutinee, ICont failure, List<Row2> rows) {
         Row2 firstRow = rows.get(0);
         Expression[] patterns = firstRow.patterns;
         if(scrutinee.length != patterns.length)
@@ -247,19 +247,19 @@ public class PatternMatchingCompiler2 {
                     viewPatternColumn = i;
             }
             else if(!(pattern instanceof EVariable)) {
-                splitByConstructors(w, context, scrutinee, failure, rows, i);
+                splitByConstructors(location, w, context, scrutinee, failure, rows, i);
                 return;
             }
         }
         
         if(viewPatternColumn >= 0) {
-            splitByViewPattern(w, context, scrutinee, failure, rows, viewPatternColumn);
+            splitByViewPattern(location, w, context, scrutinee, failure, rows, viewPatternColumn);
             return;
         }
 
         // The first row has only variable patterns: no matching needed
         for(int i=0;i<patterns.length;++i)
             ((EVariable)patterns[i]).getVariable().setVal(scrutinee[i]);
-        w.jump(firstRow.continuation);
+        w.jump(location, firstRow.continuation);
     }
 }