package org.shedlang.compiler.shid.instructions; import org.pcollections.PVector; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.sources.Sources; import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.util.P; import java.util.List; /** * Push a native function value onto the temporary value stack with the given * declaration. */ public record ShidDeclareNativeFunction( NamespaceName namespaceName, String name, List positionalParams, List namedParams, Source source ) implements ShidInstruction { @Override public boolean isBlockTerminator() { return false; } public static Builder builder() { return new Builder( NamespaceName.of(), "f", P.vector(), P.vector() ); } public record Builder( NamespaceName namespaceName, String name, PVector positionalParams, PVector namedParams ) { public ShidDeclareNativeFunction build() { return new ShidDeclareNativeFunction( this.namespaceName, this.name, this.positionalParams, this.namedParams, Sources.NULL ); } public Builder withNamespaceName(NamespaceName namespaceName) { return new Builder( namespaceName, this.name, this.positionalParams, this.namedParams ); } public Builder withName(String name) { return new Builder( this.namespaceName, name, this.positionalParams, this.namedParams ); } public Builder addPositionalParam(String name) { return new Builder( this.namespaceName, this.name, this.positionalParams.plus(new ShidParam(name, Sources.NULL)), this.namedParams ); } public Builder addNamedParam(String name) { return new Builder( this.namespaceName, this.name, this.positionalParams, this.namedParams.plus(new ShidParam(name, Sources.NULL)) ); } } }