this.cases = cases;
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+ @Override
+ public void collectVars(TObjectIntHashMap<Variable> allVars,
+ TIntHashSet vars) {
for(Expression s : scrutinee)
- s.collectRefs(allRefs, refs);
- for(Case case_ : cases)
- case_.collectRefs(allRefs, refs);
- }
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- for(Expression s : scrutinee)
s.collectVars(allVars, vars);
- for(Case case_ : cases)
+ for(Case case_ : cases)
case_.collectVars(allVars, vars);
- }
-
- @Override
- protected void updateType() {
- setType(cases[0].value.getType());
- }
+ }
+
+ @Override
+ protected void updateType() {
+ setType(cases[0].value.getType());
+ }
+
+ @Override
+ public IVal toVal(CompilationContext context, CodeWriter w) {
+ ArrayList<Row> rows = new ArrayList<Row>(cases.length);
+ for(Case case_ : cases)
+ rows.add(new Row(case_.patterns, case_.value));
- @Override
- public IVal toVal(CompilationContext context, CodeWriter w) {
- ArrayList<Row> rows = new ArrayList<Row>(cases.length);
- for(Case case_ : cases)
- rows.add(new Row(case_.patterns, case_.value));
-
- IVal[] scrutineeVals = new IVal[scrutinee.length];
- for(int i=0;i<scrutinee.length;++i)
- scrutineeVals[i] = scrutinee[i].toVal(context, w);
-
- CodeWriter joinPoint = w.createBlock(getType());
- CodeWriter failurePoint = w.createBlock(); // TODO generate only one failurePoint per function
- PatternMatchingCompiler.split(w, context, scrutineeVals, joinPoint.getContinuation(), failurePoint.getContinuation(), rows);
- failurePoint.throw_(location, Throw.MatchingException, "Matching failure at: " + toString());
- w.continueAs(joinPoint);
- return w.getParameters()[0];
+ IVal[] scrutineeVals = new IVal[scrutinee.length];
+ for(int i=0;i<scrutinee.length;++i)
+ scrutineeVals[i] = scrutinee[i].toVal(context, w);
+
+ CodeWriter joinPoint = w.createBlock(getType());
+ CodeWriter failurePoint = w.createBlock(); // TODO generate only one failurePoint per function
+ PatternMatchingCompiler.split(w, context, scrutineeVals, joinPoint.getContinuation(), failurePoint.getContinuation(), rows);
+ failurePoint.throw_(location, Throw.MatchingException, "Matching failure at: " + toString());
+ w.continueAs(joinPoint);
+ return w.getParameters()[0];
}
@Override
setType(Types.UNIT);
return this;
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- for(Expression s : scrutinee)
- s.collectEffects(effects);
- for(Case case_ : cases) {
- for(Expression pattern : case_.patterns)
- pattern.collectEffects(effects);
- case_.value.collectEffects(effects);
- }
- }
@Override
public void accept(ExpressionVisitor visitor) {