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%2Finternal%2Felaboration%2Fmatching2%2FPatternMatchingCompiler2.java;h=bd904cf28ef52bbc5e7ddc058a1a9fe28978a672;hp=7849300deb594b23dc3834af60a1393490656ff7;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/matching2/PatternMatchingCompiler2.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/matching2/PatternMatchingCompiler2.java index 7849300de..bd904cf28 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/matching2/PatternMatchingCompiler2.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/matching2/PatternMatchingCompiler2.java @@ -1,264 +1,264 @@ -package org.simantics.scl.compiler.internal.elaboration.matching2; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; -import org.simantics.scl.compiler.constants.Constant; -import org.simantics.scl.compiler.elaboration.expressions.EApply; -import org.simantics.scl.compiler.elaboration.expressions.EApplyType; -import org.simantics.scl.compiler.elaboration.expressions.EAsPattern; -import org.simantics.scl.compiler.elaboration.expressions.EConstant; -import org.simantics.scl.compiler.elaboration.expressions.EExternalConstant; -import org.simantics.scl.compiler.elaboration.expressions.ELiteral; -import org.simantics.scl.compiler.elaboration.expressions.EVariable; -import org.simantics.scl.compiler.elaboration.expressions.EViewPattern; -import org.simantics.scl.compiler.elaboration.expressions.Expression; -import org.simantics.scl.compiler.elaboration.modules.SCLValue; -import org.simantics.scl.compiler.elaboration.modules.TypeConstructor; -import org.simantics.scl.compiler.environment.Environment; -import org.simantics.scl.compiler.internal.codegen.continuations.Branch; -import org.simantics.scl.compiler.internal.codegen.continuations.ICont; -import org.simantics.scl.compiler.internal.codegen.references.IVal; -import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; -import org.simantics.scl.compiler.types.TCon; -import org.simantics.scl.compiler.types.Types; -import org.simantics.scl.compiler.types.exceptions.MatchException; - -import gnu.trove.map.hash.THashMap; - -public class PatternMatchingCompiler2 { - - private static class ExpressionMatrix { - final CodeWriter w; - final IVal[] scrutinee; - final List rows = new ArrayList(); - - public ExpressionMatrix(CodeWriter w, IVal[] scrutinee) { - this.w = w; - this.scrutinee = scrutinee; - } - } - - public static IVal[] replace(IVal[] vals, int columnToReplace, IVal ... substitution) { - IVal[] newVals = new IVal[vals.length-1+substitution.length]; - int j=0; - for(int i=0;i rows, int columnId) { - THashMap matrixMap = new THashMap(); - ArrayList branches = new ArrayList(); - ArrayList matrices = new ArrayList(); - - /*System.out.println("---"); - for(Row row : rows) { - for(Expression e : row.patterns) - System.out.print(e + " "); - System.out.println(); - }*/ - - int i; - for(i=0;i rows, int viewPatternColumn) { - Row2 firstRow = rows.get(0); - EViewPattern firstViewPattern = (EViewPattern)firstRow.patterns[viewPatternColumn]; - firstRow.patterns[viewPatternColumn] = firstViewPattern.pattern; - int i; - for(i=1;i rows) { - Row2 firstRow = rows.get(0); - Expression[] patterns = firstRow.patterns; - if(scrutinee.length != patterns.length) - throw new InternalCompilerError("Scrutinee and patterns have a different length"); - - // Find a non-variable pattern and split by it - int viewPatternColumn = -1; - for(int i=0;i= 0) { - splitByViewPattern(w, env, scrutinee, failure, rows, viewPatternColumn); - return; - } - - // The first row has only variable patterns: no matching needed - for(int i=0;i rows = new ArrayList(); + + public ExpressionMatrix(CodeWriter w, IVal[] scrutinee) { + this.w = w; + this.scrutinee = scrutinee; + } + } + + public static IVal[] replace(IVal[] vals, int columnToReplace, IVal ... substitution) { + IVal[] newVals = new IVal[vals.length-1+substitution.length]; + int j=0; + for(int i=0;i rows, int columnId) { + THashMap matrixMap = new THashMap(); + ArrayList branches = new ArrayList(); + ArrayList matrices = new ArrayList(); + + /*System.out.println("---"); + for(Row row : rows) { + for(Expression e : row.patterns) + System.out.print(e + " "); + System.out.println(); + }*/ + + int i; + for(i=0;i rows, int viewPatternColumn) { + Row2 firstRow = rows.get(0); + EViewPattern firstViewPattern = (EViewPattern)firstRow.patterns[viewPatternColumn]; + firstRow.patterns[viewPatternColumn] = firstViewPattern.pattern; + int i; + for(i=1;i rows) { + Row2 firstRow = rows.get(0); + Expression[] patterns = firstRow.patterns; + if(scrutinee.length != patterns.length) + throw new InternalCompilerError("Scrutinee and patterns have a different length"); + + // Find a non-variable pattern and split by it + int viewPatternColumn = -1; + for(int i=0;i= 0) { + splitByViewPattern(w, env, scrutinee, failure, rows, viewPatternColumn); + return; + } + + // The first row has only variable patterns: no matching needed + for(int i=0;i