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