org.protelis.lang.interpreter.impl.NBRCall Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of protelis-interpreter Show documentation
Show all versions of protelis-interpreter Show documentation
The Protelis language interpreter
/*
* Copyright (C) 2021, Danilo Pianini and contributors listed in the project's build.gradle.kts or pom.xml file.
*
* This file is part of Protelis, and is distributed under the terms of the GNU General Public License,
* with a linking exception, as described in the file LICENSE.txt in this project's top directory.
*/
package org.protelis.lang.interpreter.impl;
import java.util.function.Function;
import org.protelis.lang.datatype.Field;
import org.protelis.lang.interpreter.ProtelisAST;
import org.protelis.lang.interpreter.util.Bytecode;
import org.protelis.lang.loading.Metadata;
import org.protelis.vm.ExecutionContext;
/**
* Implementation of 'nbr' operator.
*
* @param field type
*/
public final class NBRCall extends AbstractProtelisAST> {
private static final long serialVersionUID = 5255917527687990281L;
/**
* @param metadata
* A {@link Metadata} object containing information about the code that generated this AST node.
* @param body
* body of nbr
*/
public NBRCall(final Metadata metadata, final ProtelisAST body) {
super(metadata, body);
}
@SuppressWarnings("unchecked")
@Override
public Field evaluate(final ExecutionContext context) {
return context.buildField(Function.identity(), (T) getBranch(0).eval(context));
}
@Override
public Bytecode getBytecode() {
return Bytecode.NBR;
}
@Override
public String getName() {
return "nbr";
}
}