astra.core.Fragment Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of astra-interpreter Show documentation
Show all versions of astra-interpreter Show documentation
Core interpreter artifact for the ASTRA Language
package astra.core;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import astra.formula.Formula;
import astra.term.Primitive;
import astra.term.Term;
public class Fragment {
private Map modules = new HashMap();
ASTRAClass clazz;
Fragment next;
List linearization;
public Fragment(ASTRAClass clazz) throws ASTRAClassNotFoundException {
this.clazz = clazz;
linearization = clazz.getLinearization();
}
public List getLinearization() {
return linearization;
}
public void addModule(String name, Class> cls, Agent agent) {
try {
Module module = (Module) cls.getDeclaredConstructor(new Class[0]).newInstance(new Object[0]);
module.setAgent(agent);
modules.put(name, module);
} catch (Exception e) {
e.printStackTrace();
return;
}
}
public void addModule(String name, Class> cls, Term[] params, Agent agent) {
Object[] values = getValues(params);
try {
Module module = (Module) cls.getDeclaredConstructor(getTypes(values)).newInstance(values);
module.setAgent(agent);
modules.put(name, module);
} catch (Exception e) {
e.printStackTrace();
return;
}
}
private Object[] getValues(Term[] params) {
Object[] values = new Object[params.length];
for (int i=0; i) params[i]).value();
} else {
throw new RuntimeException("Invalid type in module constructor: " + params[i]);
}
}
return values;
}
private Class>[] getTypes(Object[] values) {
Class>[] classes = new Class[values.length];
for (int i=0; i getMatchingFormulae(Formula predicate) {
return null;
}
}