use of buildcraft.lib.expression.api.IExpressionNode in project BuildCraft by BuildCraft.
the class InternalCompiler method compileFunction.
public static INodeFunc compileFunction(String expression, FunctionContext context, Argument... args) throws InvalidExpressionException {
FunctionContext ctxReal = new FunctionContext(context);
IVariableNode[] nodes = new IVariableNode[args.length];
Class<?>[] types = new Class[args.length];
for (int i = 0; i < nodes.length; i++) {
types[i] = args[i].type;
nodes[i] = ctxReal.putVariable(args[i].name, args[i].type);
}
IExpressionNode node = compileExpression(expression, ctxReal);
if (node instanceof INodeLong) {
return new NodeFuncGenericToLong((INodeLong) node, types, nodes);
} else if (node instanceof INodeDouble) {
return new NodeFuncGenericToDouble((INodeDouble) node, types, nodes);
} else if (node instanceof INodeBoolean) {
return new NodeFuncGenericToBoolean((INodeBoolean) node, types, nodes);
} else if (node instanceof INodeObject<?>) {
return new NodeFuncGenericToObject<>((INodeObject<?>) node, types, nodes);
} else {
ExpressionDebugManager.debugNodeClass(node.getClass());
throw new IllegalStateException("Unknown node " + node.getClass());
}
}
use of buildcraft.lib.expression.api.IExpressionNode in project BuildCraft by BuildCraft.
the class InternalCompiler method pushConditional.
private static void pushConditional(NodeStack stack) throws InvalidExpressionException {
IExpressionNode right = stack.pop();
IExpressionNode left = stack.pop();
IExpressionNode conditional = stack.pop();
right = convertBinary(right, left);
left = convertBinary(left, right);
if (conditional instanceof INodeBoolean) {
INodeBoolean condition = (INodeBoolean) conditional;
if (right instanceof INodeBoolean) {
stack.push(new NodeConditionalBoolean(condition, (INodeBoolean) left, (INodeBoolean) right));
} else if (right instanceof INodeDouble) {
stack.push(new NodeConditionalDouble(condition, (INodeDouble) left, (INodeDouble) right));
} else if (right instanceof INodeObject) {
stack.push(new NodeConditionalObject(condition, (INodeObject) left, (INodeObject) right));
} else if (right instanceof INodeLong) {
stack.push(new NodeConditionalLong(condition, (INodeLong) left, (INodeLong) right));
} else {
throw new InvalidExpressionException("Unknown node " + left);
}
} else {
throw new InvalidExpressionException("Required a boolean node, but got '" + conditional + "' of " + conditional.getClass());
}
}
use of buildcraft.lib.expression.api.IExpressionNode in project BuildCraft by BuildCraft.
the class NodeStack method popObject.
@Override
public <T> INodeObject<T> popObject(Class<T> type) throws InvalidExpressionException {
checkTypeMatch(type);
IExpressionNode node = pop();
if (node instanceof INodeObject) {
INodeObject<?> nodeObj = (INodeObject<?>) node;
if (nodeObj.getType() == type) {
return (INodeObject<T>) nodeObj;
} else {
throw new InvalidExpressionException("Cannot cast " + nodeObj.getType().getSimpleName() + " to " + type.getSimpleName() + "!");
}
} else {
throw new InvalidExpressionException("Cannot cast " + node + " to " + type.getSimpleName() + "!");
}
}
use of buildcraft.lib.expression.api.IExpressionNode in project BuildCraft by BuildCraft.
the class NodeStack method pop.
public IExpressionNode pop() throws InvalidExpressionException {
if (stack.isEmpty()) {
throw new InvalidExpressionException("No more nodes to pop!");
} else {
IExpressionNode node = stack.remove(stack.size() - 1);
ExpressionDebugManager.debugPrintln("Popped " + node);
return node;
}
}
use of buildcraft.lib.expression.api.IExpressionNode in project BuildCraft by BuildCraft.
the class NodeStack method popBoolean.
@Override
public INodeBoolean popBoolean() throws InvalidExpressionException {
checkTypeMatch(boolean.class);
IExpressionNode node = pop();
if (node instanceof INodeBoolean) {
return (INodeBoolean) node;
} else {
throw new InvalidExpressionException("Cannot cast " + node + " to a boolean!");
}
}
Aggregations