
org.snapscript.tree.function.FunctionReference Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap Show documentation
Show all versions of snap Show documentation
Dynamic scripting for the JVM
package org.snapscript.tree.function;
import org.snapscript.core.Evaluation;
import org.snapscript.core.Module;
import org.snapscript.core.Scope;
import org.snapscript.core.Value;
import org.snapscript.core.function.Function;
import org.snapscript.tree.NameReference;
public class FunctionReference extends Evaluation {
private final FunctionReferenceBuilder builder;
private final NameReference reference;
private final Evaluation variable;
public FunctionReference(Evaluation variable, Evaluation method) {
this.builder = new FunctionReferenceBuilder();
this.reference = new NameReference(method);
this.variable = variable;
}
@Override
public void compile(Scope scope) throws Exception {
variable.compile(scope);
}
@Override
public Value evaluate(Scope scope, Object left) throws Exception {
Value value = variable.evaluate(scope, left);
String match = reference.getName(scope);
Module module = scope.getModule(); // is this the correct module?
Object object = value.getValue();
Function function = builder.create(module, object, match);
return Value.getTransient(function);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy