package org.metaborg.meta.lang.dynsem.interpreter.nodes.matching.lists;

import org.metaborg.meta.lang.dynsem.interpreter.nodes.matching.MatchPattern;
import org.metaborg.meta.lang.dynsem.interpreter.terms.IListTerm;

import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;

public abstract class ListLengthFixedMatch extends MatchPattern {

	protected final int expectedLength;

	public ListLengthFixedMatch(SourceSection source, int expectedLength) {
		super(source);
		this.expectedLength = expectedLength;
	}

	@Specialization(guards = { "list == cachedL" })
	public boolean executeCachedList(VirtualFrame frame, IListTerm<?> list, @Cached("list") IListTerm<?> cachedL,
			@Cached("cachedL.size() == expectedLength") boolean eqLength) {
		return eqLength;
	}

	@Specialization(replaces = "executeCachedList")
	public boolean executeList(VirtualFrame frame, IListTerm<?> list,
			@Cached("createBinaryProfile()") ConditionProfile profile) {
		return profile.profile(list.size() == expectedLength);
	}

	public int getExpectedLength() {
		return expectedLength;
	}

}

@@ -307,115 +307,8 @@
 on;%0A
-import com.oracle.truffle.api.frame.VirtualFrame;%0Aimport com.oracle.truffle.api.profiles.ConditionProfile;%0A
 impo
@@ -678,36 +678,16 @@
 hedList(
-VirtualFrame frame, 
 IListTer
@@ -906,136 +906,38 @@
 ist(
-VirtualFrame frame, IListTerm%3C?%3E list,%0A%09%09%09@Cached(%22createBinaryProfile()%22) ConditionProfile profile) %7B%0A%09%09return profile.profile(
+IListTerm%3C?%3E list) %7B%0A%09%09return 
 list
@@ -961,17 +961,16 @@
 edLength
-)
 ;%0A%09%7D%0A%0A%09p
@@ -975,16 +975,22 @@
 %09public 
+final 
 int getE

Drop virtual frame