Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-08 04:20:06 +01:00
Renamed Assignable to LValue and Invokable to RValue
Dieser Commit ist enthalten in:
Ursprung
0ba3da2641
Commit
93f073f264
@ -29,13 +29,13 @@ import com.sk89q.worldedit.expression.parser.Parser;
|
||||
import com.sk89q.worldedit.expression.parser.ParserException;
|
||||
import com.sk89q.worldedit.expression.runtime.Constant;
|
||||
import com.sk89q.worldedit.expression.runtime.EvaluationException;
|
||||
import com.sk89q.worldedit.expression.runtime.Invokable;
|
||||
import com.sk89q.worldedit.expression.runtime.RValue;
|
||||
import com.sk89q.worldedit.expression.runtime.Variable;
|
||||
|
||||
public class Expression {
|
||||
private final Map<String, Invokable> variables = new HashMap<String, Invokable>();
|
||||
private final Map<String, RValue> variables = new HashMap<String, RValue>();
|
||||
private final String[] variableNames;
|
||||
private Invokable root;
|
||||
private RValue root;
|
||||
|
||||
public static Expression compile(String expression, String... variableNames) throws ExpressionException {
|
||||
return new Expression(expression, variableNames);
|
||||
@ -59,7 +59,7 @@ public class Expression {
|
||||
public double evaluate(double... values) throws EvaluationException {
|
||||
for (int i = 0; i < values.length; ++i) {
|
||||
final String variableName = variableNames[i];
|
||||
final Invokable invokable = variables.get(variableName);
|
||||
final RValue invokable = variables.get(variableName);
|
||||
if (!(invokable instanceof Variable)) {
|
||||
throw new EvaluationException(invokable.getPosition(), "Tried to assign constant " + variableName + ".");
|
||||
}
|
||||
@ -79,7 +79,7 @@ public class Expression {
|
||||
return root.toString();
|
||||
}
|
||||
|
||||
public Invokable getVariable(String name) {
|
||||
public RValue getVariable(String name) {
|
||||
return variables.get(name);
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import com.sk89q.worldedit.expression.lexer.tokens.OperatorToken;
|
||||
import com.sk89q.worldedit.expression.lexer.tokens.Token;
|
||||
import com.sk89q.worldedit.expression.runtime.Constant;
|
||||
import com.sk89q.worldedit.expression.runtime.Functions;
|
||||
import com.sk89q.worldedit.expression.runtime.Invokable;
|
||||
import com.sk89q.worldedit.expression.runtime.RValue;
|
||||
|
||||
public class Parser {
|
||||
private final class NullToken extends Token {
|
||||
@ -51,19 +51,19 @@ public class Parser {
|
||||
|
||||
private final List<Token> tokens;
|
||||
private int position = 0;
|
||||
private Map<String, Invokable> variables;
|
||||
private Map<String, RValue> variables;
|
||||
|
||||
private Parser(List<Token> tokens, Map<String, Invokable> variables) {
|
||||
private Parser(List<Token> tokens, Map<String, RValue> variables) {
|
||||
this.tokens = tokens;
|
||||
this.variables = variables;
|
||||
}
|
||||
|
||||
public static final Invokable parse(List<Token> tokens, Map<String, Invokable> variables) throws ParserException {
|
||||
public static final RValue parse(List<Token> tokens, Map<String, RValue> variables) throws ParserException {
|
||||
return new Parser(tokens, variables).parse();
|
||||
}
|
||||
|
||||
private Invokable parse() throws ParserException {
|
||||
final Invokable ret = parseInternal(true);
|
||||
private RValue parse() throws ParserException {
|
||||
final RValue ret = parseInternal(true);
|
||||
if (position < tokens.size()) {
|
||||
final Token token = peek();
|
||||
throw new ParserException(token.getPosition(), "Extra token at the end of the input: " + token);
|
||||
@ -71,7 +71,7 @@ public class Parser {
|
||||
return ret;
|
||||
}
|
||||
|
||||
private final Invokable parseInternal(boolean isStatement) throws ParserException {
|
||||
private final RValue parseInternal(boolean isStatement) throws ParserException {
|
||||
LinkedList<Identifiable> halfProcessed = new LinkedList<Identifiable>();
|
||||
|
||||
// process brackets, numbers, functions, variables and detect prefix operators
|
||||
@ -95,7 +95,7 @@ public class Parser {
|
||||
halfProcessed.add(parseFunctionCall(identifierToken));
|
||||
}
|
||||
else {
|
||||
Invokable variable = variables.get(identifierToken.value);
|
||||
RValue variable = variables.get(identifierToken.value);
|
||||
if (variable == null) {
|
||||
throw new ParserException(current.getPosition(), "Variable '" + identifierToken.value + "' not found");
|
||||
}
|
||||
@ -167,7 +167,7 @@ public class Parser {
|
||||
return Functions.getFunction(identifierToken.getPosition(), identifierToken.value);
|
||||
}
|
||||
|
||||
List<Invokable> args = new ArrayList<Invokable>();
|
||||
List<RValue> args = new ArrayList<RValue>();
|
||||
|
||||
loop: while (true) {
|
||||
args.add(parseInternal(false));
|
||||
@ -187,20 +187,20 @@ public class Parser {
|
||||
}
|
||||
}
|
||||
|
||||
return Functions.getFunction(identifierToken.getPosition(), identifierToken.value, args.toArray(new Invokable[args.size()]));
|
||||
return Functions.getFunction(identifierToken.getPosition(), identifierToken.value, args.toArray(new RValue[args.size()]));
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
throw new ParserException(identifierToken.getPosition(), "Function not found", e);
|
||||
}
|
||||
}
|
||||
|
||||
private final Invokable parseBracket() throws ParserException {
|
||||
private final RValue parseBracket() throws ParserException {
|
||||
if (peek().id() != '(') {
|
||||
throw new ParserException(peek().getPosition(), "Unexpected character in parseBracket");
|
||||
}
|
||||
++position;
|
||||
|
||||
final Invokable ret = parseInternal(false);
|
||||
final RValue ret = parseInternal(false);
|
||||
|
||||
if (peek().id() != ')') {
|
||||
throw new ParserException(peek().getPosition(), "Unmatched opening bracket");
|
||||
@ -210,13 +210,13 @@ public class Parser {
|
||||
return ret;
|
||||
}
|
||||
|
||||
private final Invokable parseBlock() throws ParserException {
|
||||
private final RValue parseBlock() throws ParserException {
|
||||
if (peek().id() != '{') {
|
||||
throw new ParserException(peek().getPosition(), "Unexpected character in parseBlock");
|
||||
}
|
||||
++position;
|
||||
|
||||
final Invokable ret = parseInternal(true);
|
||||
final RValue ret = parseInternal(true);
|
||||
|
||||
if (peek().id() != '}') {
|
||||
throw new ParserException(peek().getPosition(), "Unmatched opening brace");
|
||||
|
@ -9,7 +9,7 @@ import java.util.Map;
|
||||
import com.sk89q.worldedit.expression.Identifiable;
|
||||
import com.sk89q.worldedit.expression.lexer.tokens.OperatorToken;
|
||||
import com.sk89q.worldedit.expression.lexer.tokens.Token;
|
||||
import com.sk89q.worldedit.expression.runtime.Invokable;
|
||||
import com.sk89q.worldedit.expression.runtime.RValue;
|
||||
import com.sk89q.worldedit.expression.runtime.Operators;
|
||||
import com.sk89q.worldedit.expression.runtime.Sequence;
|
||||
|
||||
@ -121,7 +121,7 @@ public final class ParserProcessors {
|
||||
}
|
||||
}
|
||||
|
||||
static Invokable processStatement(LinkedList<Identifiable> input) throws ParserException {
|
||||
static RValue processStatement(LinkedList<Identifiable> input) throws ParserException {
|
||||
LinkedList<Identifiable> lhs = new LinkedList<Identifiable>();
|
||||
LinkedList<Identifiable> rhs = new LinkedList<Identifiable>();
|
||||
boolean semicolonFound = false;
|
||||
@ -153,18 +153,18 @@ public final class ParserProcessors {
|
||||
else {
|
||||
assert(semicolonFound);
|
||||
|
||||
Invokable lhsInvokable = processExpression(lhs);
|
||||
Invokable rhsInvokable = processStatement(rhs);
|
||||
RValue lhsInvokable = processExpression(lhs);
|
||||
RValue rhsInvokable = processStatement(rhs);
|
||||
|
||||
return new Sequence(lhsInvokable.getPosition(), lhsInvokable, rhsInvokable);
|
||||
}
|
||||
}
|
||||
|
||||
static Invokable processExpression(LinkedList<Identifiable> input) throws ParserException {
|
||||
static RValue processExpression(LinkedList<Identifiable> input) throws ParserException {
|
||||
return processBinaryOpsRA(input, binaryOpMapsRA.length - 1);
|
||||
}
|
||||
|
||||
private static Invokable processBinaryOpsLA(LinkedList<Identifiable> input, int level) throws ParserException {
|
||||
private static RValue processBinaryOpsLA(LinkedList<Identifiable> input, int level) throws ParserException {
|
||||
if (level < 0) {
|
||||
return processUnaryOps(input);
|
||||
}
|
||||
@ -194,10 +194,10 @@ public final class ParserProcessors {
|
||||
}
|
||||
}
|
||||
|
||||
Invokable rhsInvokable = processBinaryOpsLA(rhs, level - 1);
|
||||
RValue rhsInvokable = processBinaryOpsLA(rhs, level - 1);
|
||||
if (operator == null) return rhsInvokable;
|
||||
|
||||
Invokable lhsInvokable = processBinaryOpsLA(lhs, level);
|
||||
RValue lhsInvokable = processBinaryOpsLA(lhs, level);
|
||||
|
||||
try {
|
||||
return Operators.getOperator(input.get(0).getPosition(), operator, lhsInvokable, rhsInvokable);
|
||||
@ -208,7 +208,7 @@ public final class ParserProcessors {
|
||||
}
|
||||
}
|
||||
|
||||
private static Invokable processBinaryOpsRA(LinkedList<Identifiable> input, int level) throws ParserException {
|
||||
private static RValue processBinaryOpsRA(LinkedList<Identifiable> input, int level) throws ParserException {
|
||||
if (level < 0) {
|
||||
return processTernaryOps(input);
|
||||
}
|
||||
@ -237,10 +237,10 @@ public final class ParserProcessors {
|
||||
}
|
||||
}
|
||||
|
||||
Invokable lhsInvokable = processBinaryOpsRA(lhs, level - 1);
|
||||
RValue lhsInvokable = processBinaryOpsRA(lhs, level - 1);
|
||||
if (operator == null) return lhsInvokable;
|
||||
|
||||
Invokable rhsInvokable = processBinaryOpsRA(rhs, level);
|
||||
RValue rhsInvokable = processBinaryOpsRA(rhs, level);
|
||||
|
||||
try {
|
||||
return Operators.getOperator(input.get(0).getPosition(), operator, lhsInvokable, rhsInvokable);
|
||||
@ -251,16 +251,16 @@ public final class ParserProcessors {
|
||||
}
|
||||
}
|
||||
|
||||
private static Invokable processTernaryOps(LinkedList<Identifiable> input) throws ParserException {
|
||||
private static RValue processTernaryOps(LinkedList<Identifiable> input) throws ParserException {
|
||||
return processBinaryOpsLA(input, binaryOpMapsLA.length - 1);
|
||||
}
|
||||
|
||||
private static Invokable processUnaryOps(LinkedList<Identifiable> input) throws ParserException {
|
||||
private static RValue processUnaryOps(LinkedList<Identifiable> input) throws ParserException {
|
||||
if (input.isEmpty()) {
|
||||
throw new ParserException(-1, "Expression missing.");
|
||||
}
|
||||
|
||||
Invokable ret = (Invokable) input.removeLast();
|
||||
RValue ret = (RValue) input.removeLast();
|
||||
while (!input.isEmpty()) {
|
||||
final Identifiable last = input.removeLast();
|
||||
final int lastPosition = last.getPosition();
|
||||
@ -284,7 +284,7 @@ public final class ParserProcessors {
|
||||
if (last instanceof Token) {
|
||||
throw new ParserException(lastPosition, "Extra token found in expression: " + last);
|
||||
}
|
||||
else if (last instanceof Invokable) {
|
||||
else if (last instanceof RValue) {
|
||||
throw new ParserException(lastPosition, "Extra expression found: " + last);
|
||||
}
|
||||
else {
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.expression.runtime;
|
||||
|
||||
public final class Constant extends Invokable {
|
||||
public final class Constant extends RValue {
|
||||
private final double value;
|
||||
|
||||
public Constant(int position, double value) {
|
||||
|
@ -24,14 +24,14 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class Function extends Invokable {
|
||||
public class Function extends RValue {
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Dynamic { }
|
||||
|
||||
final Method method;
|
||||
final Invokable[] args;
|
||||
final RValue[] args;
|
||||
|
||||
Function(int position, Method method, Invokable... args) {
|
||||
Function(int position, Method method, RValue... args) {
|
||||
super(position);
|
||||
this.method = method;
|
||||
this.args = args;
|
||||
@ -73,12 +73,12 @@ public class Function extends Invokable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Invokable optimize() throws EvaluationException {
|
||||
final Invokable[] optimizedArgs = new Invokable[args.length];
|
||||
public RValue optimize() throws EvaluationException {
|
||||
final RValue[] optimizedArgs = new RValue[args.length];
|
||||
boolean optimizable = !method.isAnnotationPresent(Dynamic.class);
|
||||
int position = getPosition();
|
||||
for (int i = 0; i < args.length; ++i) {
|
||||
final Invokable optimized = optimizedArgs[i] = args[i].optimize();
|
||||
final RValue optimized = optimizedArgs[i] = args[i].optimize();
|
||||
|
||||
if (!(optimized instanceof Constant)) {
|
||||
optimizable = false;
|
||||
|
@ -22,116 +22,116 @@ package com.sk89q.worldedit.expression.runtime;
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class Functions {
|
||||
public static final Function getFunction(int position, String name, Invokable... args) throws NoSuchMethodException {
|
||||
public static final Function getFunction(int position, String name, RValue... args) throws NoSuchMethodException {
|
||||
final Class<?>[] parameterTypes = (Class<?>[]) new Class[args.length];
|
||||
Arrays.fill(parameterTypes, Invokable.class);
|
||||
Arrays.fill(parameterTypes, RValue.class);
|
||||
return new Function(position, Functions.class.getMethod(name, parameterTypes), args);
|
||||
}
|
||||
|
||||
|
||||
public static final double sin(Invokable x) throws Exception {
|
||||
public static final double sin(RValue x) throws Exception {
|
||||
return Math.sin(x.invoke());
|
||||
}
|
||||
|
||||
public static final double cos(Invokable x) throws Exception {
|
||||
public static final double cos(RValue x) throws Exception {
|
||||
return Math.cos(x.invoke());
|
||||
}
|
||||
|
||||
public static final double tan(Invokable x) throws Exception {
|
||||
public static final double tan(RValue x) throws Exception {
|
||||
return Math.tan(x.invoke());
|
||||
}
|
||||
|
||||
|
||||
public static final double asin(Invokable x) throws Exception {
|
||||
public static final double asin(RValue x) throws Exception {
|
||||
return Math.asin(x.invoke());
|
||||
}
|
||||
|
||||
public static final double acos(Invokable x) throws Exception {
|
||||
public static final double acos(RValue x) throws Exception {
|
||||
return Math.acos(x.invoke());
|
||||
}
|
||||
|
||||
public static final double atan(Invokable x) throws Exception {
|
||||
public static final double atan(RValue x) throws Exception {
|
||||
return Math.atan(x.invoke());
|
||||
}
|
||||
|
||||
public static final double atan2(Invokable y, Invokable x) throws Exception {
|
||||
public static final double atan2(RValue y, RValue x) throws Exception {
|
||||
return Math.atan2(y.invoke(), x.invoke());
|
||||
}
|
||||
|
||||
|
||||
public static final double sinh(Invokable x) throws Exception {
|
||||
public static final double sinh(RValue x) throws Exception {
|
||||
return Math.sinh(x.invoke());
|
||||
}
|
||||
|
||||
public static final double cosh(Invokable x) throws Exception {
|
||||
public static final double cosh(RValue x) throws Exception {
|
||||
return Math.cosh(x.invoke());
|
||||
}
|
||||
|
||||
public static final double tanh(Invokable x) throws Exception {
|
||||
public static final double tanh(RValue x) throws Exception {
|
||||
return Math.tanh(x.invoke());
|
||||
}
|
||||
|
||||
|
||||
public static final double sqrt(Invokable x) throws Exception {
|
||||
public static final double sqrt(RValue x) throws Exception {
|
||||
return Math.sqrt(x.invoke());
|
||||
}
|
||||
|
||||
public static final double cbrt(Invokable x) throws Exception {
|
||||
public static final double cbrt(RValue x) throws Exception {
|
||||
return Math.cbrt(x.invoke());
|
||||
}
|
||||
|
||||
|
||||
public static final double abs(Invokable x) throws Exception {
|
||||
public static final double abs(RValue x) throws Exception {
|
||||
return Math.abs(x.invoke());
|
||||
}
|
||||
|
||||
public static final double min(Invokable a, Invokable b) throws Exception {
|
||||
public static final double min(RValue a, RValue b) throws Exception {
|
||||
return Math.min(a.invoke(), b.invoke());
|
||||
}
|
||||
|
||||
public static final double min(Invokable a, Invokable b, Invokable c) throws Exception {
|
||||
public static final double min(RValue a, RValue b, RValue c) throws Exception {
|
||||
return Math.min(a.invoke(), Math.min(b.invoke(), c.invoke()));
|
||||
}
|
||||
|
||||
public static final double max(Invokable a, Invokable b) throws Exception {
|
||||
public static final double max(RValue a, RValue b) throws Exception {
|
||||
return Math.max(a.invoke(), b.invoke());
|
||||
}
|
||||
|
||||
public static final double max(Invokable a, Invokable b, Invokable c) throws Exception {
|
||||
public static final double max(RValue a, RValue b, RValue c) throws Exception {
|
||||
return Math.max(a.invoke(), Math.max(b.invoke(), c.invoke()));
|
||||
}
|
||||
|
||||
|
||||
public static final double ceil(Invokable x) throws Exception {
|
||||
public static final double ceil(RValue x) throws Exception {
|
||||
return Math.ceil(x.invoke());
|
||||
}
|
||||
|
||||
public static final double floor(Invokable x) throws Exception {
|
||||
public static final double floor(RValue x) throws Exception {
|
||||
return Math.floor(x.invoke());
|
||||
}
|
||||
|
||||
public static final double rint(Invokable x) throws Exception {
|
||||
public static final double rint(RValue x) throws Exception {
|
||||
return Math.rint(x.invoke());
|
||||
}
|
||||
|
||||
public static final double round(Invokable x) throws Exception {
|
||||
public static final double round(RValue x) throws Exception {
|
||||
return Math.round(x.invoke());
|
||||
}
|
||||
|
||||
|
||||
public static final double exp(Invokable x) throws Exception {
|
||||
public static final double exp(RValue x) throws Exception {
|
||||
return Math.exp(x.invoke());
|
||||
}
|
||||
|
||||
public static final double ln(Invokable x) throws Exception {
|
||||
public static final double ln(RValue x) throws Exception {
|
||||
return Math.log(x.invoke());
|
||||
}
|
||||
|
||||
public static final double log(Invokable x) throws Exception {
|
||||
public static final double log(RValue x) throws Exception {
|
||||
return Math.log(x.invoke());
|
||||
}
|
||||
|
||||
public static final double log10(Invokable x) throws Exception {
|
||||
public static final double log10(RValue x) throws Exception {
|
||||
return Math.log10(x.invoke());
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit.expression.runtime;
|
||||
|
||||
public abstract class Assignable extends Invokable {
|
||||
public Assignable(int position) {
|
||||
public abstract class LValue extends RValue {
|
||||
public LValue(int position) {
|
||||
super(position);
|
||||
}
|
||||
|
@ -20,147 +20,147 @@
|
||||
package com.sk89q.worldedit.expression.runtime;
|
||||
|
||||
public final class Operators {
|
||||
public static final Function getOperator(int position, String name, Invokable lhs, Invokable rhs) throws NoSuchMethodException {
|
||||
if (lhs instanceof Assignable) {
|
||||
public static final Function getOperator(int position, String name, RValue lhs, RValue rhs) throws NoSuchMethodException {
|
||||
if (lhs instanceof LValue) {
|
||||
try {
|
||||
return new Function(position, Operators.class.getMethod(name, Assignable.class, Invokable.class), lhs, rhs);
|
||||
return new Function(position, Operators.class.getMethod(name, LValue.class, RValue.class), lhs, rhs);
|
||||
}
|
||||
catch (NoSuchMethodException e) {}
|
||||
}
|
||||
return new Function(position, Operators.class.getMethod(name, Invokable.class, Invokable.class), lhs, rhs);
|
||||
return new Function(position, Operators.class.getMethod(name, RValue.class, RValue.class), lhs, rhs);
|
||||
}
|
||||
|
||||
public static final Function getOperator(int position, String name, Invokable argument) throws NoSuchMethodException {
|
||||
if (argument instanceof Assignable) {
|
||||
public static final Function getOperator(int position, String name, RValue argument) throws NoSuchMethodException {
|
||||
if (argument instanceof LValue) {
|
||||
try {
|
||||
return new Function(position, Operators.class.getMethod(name, Assignable.class), argument);
|
||||
return new Function(position, Operators.class.getMethod(name, LValue.class), argument);
|
||||
}
|
||||
catch (NoSuchMethodException e) {}
|
||||
}
|
||||
return new Function(position, Operators.class.getMethod(name, Invokable.class), argument);
|
||||
return new Function(position, Operators.class.getMethod(name, RValue.class), argument);
|
||||
}
|
||||
|
||||
|
||||
public static final double add(Invokable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double add(RValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.invoke() + rhs.invoke();
|
||||
}
|
||||
|
||||
public static final double sub(Invokable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double sub(RValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.invoke() - rhs.invoke();
|
||||
}
|
||||
|
||||
public static final double mul(Invokable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double mul(RValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.invoke() * rhs.invoke();
|
||||
}
|
||||
|
||||
public static final double div(Invokable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double div(RValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.invoke() / rhs.invoke();
|
||||
}
|
||||
|
||||
public static final double mod(Invokable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double mod(RValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.invoke() % rhs.invoke();
|
||||
}
|
||||
|
||||
public static final double pow(Invokable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double pow(RValue lhs, RValue rhs) throws EvaluationException {
|
||||
return Math.pow(lhs.invoke(), rhs.invoke());
|
||||
}
|
||||
|
||||
|
||||
public static final double neg(Invokable x) throws EvaluationException {
|
||||
public static final double neg(RValue x) throws EvaluationException {
|
||||
return -x.invoke();
|
||||
}
|
||||
|
||||
public static final double not(Invokable x) throws EvaluationException {
|
||||
public static final double not(RValue x) throws EvaluationException {
|
||||
return x.invoke() > 0.0 ? 0.0 : 1.0;
|
||||
}
|
||||
|
||||
public static final double inv(Invokable x) throws EvaluationException {
|
||||
public static final double inv(RValue x) throws EvaluationException {
|
||||
return ~(long) x.invoke();
|
||||
}
|
||||
|
||||
|
||||
public static final double lth(Invokable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double lth(RValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.invoke() < rhs.invoke() ? 1.0 : 0.0;
|
||||
}
|
||||
|
||||
public static final double gth(Invokable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double gth(RValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.invoke() > rhs.invoke() ? 1.0 : 0.0;
|
||||
}
|
||||
|
||||
public static final double leq(Invokable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double leq(RValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.invoke() <= rhs.invoke() ? 1.0 : 0.0;
|
||||
}
|
||||
|
||||
public static final double geq(Invokable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double geq(RValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.invoke() >= rhs.invoke() ? 1.0 : 0.0;
|
||||
}
|
||||
|
||||
|
||||
public static final double equ(Invokable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double equ(RValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.invoke() == rhs.invoke() ? 1.0 : 0.0;
|
||||
}
|
||||
|
||||
public static final double neq(Invokable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double neq(RValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.invoke() != rhs.invoke() ? 1.0 : 0.0;
|
||||
}
|
||||
|
||||
public static final double near(Invokable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double near(RValue lhs, RValue rhs) throws EvaluationException {
|
||||
return almostEqual2sComplement(lhs.invoke(), rhs.invoke(), 450359963L) ? 1.0 : 0.0;
|
||||
//return Math.abs(lhs.invoke() - rhs.invoke()) < 1e-7 ? 1.0 : 0.0;
|
||||
}
|
||||
|
||||
|
||||
public static final double or(Invokable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double or(RValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.invoke() > 0.0 || rhs.invoke() > 0.0 ? 1.0 : 0.0;
|
||||
}
|
||||
|
||||
public static final double and(Invokable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double and(RValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.invoke() > 0.0 && rhs.invoke() > 0.0 ? 1.0 : 0.0;
|
||||
}
|
||||
|
||||
|
||||
public static final double shl(Invokable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double shl(RValue lhs, RValue rhs) throws EvaluationException {
|
||||
return (long) lhs.invoke() << (long) rhs.invoke();
|
||||
}
|
||||
|
||||
public static final double shr(Invokable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double shr(RValue lhs, RValue rhs) throws EvaluationException {
|
||||
return (long) lhs.invoke() >> (long) rhs.invoke();
|
||||
}
|
||||
|
||||
|
||||
public static final double ass(Assignable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double ass(LValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.assign(rhs.invoke());
|
||||
}
|
||||
|
||||
public static final double aadd(Assignable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double aadd(LValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.assign(lhs.invoke() + rhs.invoke());
|
||||
}
|
||||
|
||||
public static final double asub(Assignable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double asub(LValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.assign(lhs.invoke() - rhs.invoke());
|
||||
}
|
||||
|
||||
public static final double amul(Assignable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double amul(LValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.assign(lhs.invoke() * rhs.invoke());
|
||||
}
|
||||
|
||||
public static final double adiv(Assignable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double adiv(LValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.assign(lhs.invoke() / rhs.invoke());
|
||||
}
|
||||
|
||||
public static final double amod(Assignable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double amod(LValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.assign(lhs.invoke() % rhs.invoke());
|
||||
}
|
||||
|
||||
public static final double aexp(Assignable lhs, Invokable rhs) throws EvaluationException {
|
||||
public static final double aexp(LValue lhs, RValue rhs) throws EvaluationException {
|
||||
return lhs.assign(Math.pow(lhs.invoke(), rhs.invoke()));
|
||||
}
|
||||
|
||||
public static final double inc(Assignable x) throws EvaluationException {
|
||||
public static final double inc(LValue x) throws EvaluationException {
|
||||
return x.assign(x.invoke() + 1);
|
||||
}
|
||||
|
||||
public static final double dec(Assignable x) throws EvaluationException {
|
||||
public static final double dec(LValue x) throws EvaluationException {
|
||||
return x.assign(x.invoke() - 1);
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,10 @@ package com.sk89q.worldedit.expression.runtime;
|
||||
|
||||
import com.sk89q.worldedit.expression.Identifiable;
|
||||
|
||||
public abstract class Invokable implements Identifiable {
|
||||
public abstract class RValue implements Identifiable {
|
||||
private final int position;
|
||||
|
||||
public Invokable(int position) {
|
||||
public RValue(int position) {
|
||||
super();
|
||||
this.position = position;
|
||||
}
|
||||
@ -34,7 +34,7 @@ public abstract class Invokable implements Identifiable {
|
||||
@Override
|
||||
public abstract String toString();
|
||||
|
||||
public Invokable optimize() throws EvaluationException {
|
||||
public RValue optimize() throws EvaluationException {
|
||||
return this;
|
||||
}
|
||||
|
@ -22,10 +22,10 @@ package com.sk89q.worldedit.expression.runtime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Sequence extends Invokable {
|
||||
private final Invokable[] sequence;
|
||||
public class Sequence extends RValue {
|
||||
private final RValue[] sequence;
|
||||
|
||||
public Sequence(int position, Invokable... sequence) {
|
||||
public Sequence(int position, RValue... sequence) {
|
||||
super(position);
|
||||
|
||||
this.sequence = sequence;
|
||||
@ -40,7 +40,7 @@ public class Sequence extends Invokable {
|
||||
@Override
|
||||
public double invoke() throws EvaluationException {
|
||||
double ret = 0;
|
||||
for (Invokable invokable : sequence) {
|
||||
for (RValue invokable : sequence) {
|
||||
ret = invokable.invoke();
|
||||
}
|
||||
return ret;
|
||||
@ -50,7 +50,7 @@ public class Sequence extends Invokable {
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("seq(");
|
||||
boolean first = true;
|
||||
for (Invokable invokable : sequence) {
|
||||
for (RValue invokable : sequence) {
|
||||
if (!first) {
|
||||
sb.append(", ");
|
||||
}
|
||||
@ -62,13 +62,13 @@ public class Sequence extends Invokable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Invokable optimize() throws EvaluationException {
|
||||
List<Invokable> newSequence = new ArrayList<Invokable>();
|
||||
public RValue optimize() throws EvaluationException {
|
||||
List<RValue> newSequence = new ArrayList<RValue>();
|
||||
|
||||
for (Invokable invokable : sequence) {
|
||||
for (RValue invokable : sequence) {
|
||||
invokable = invokable.optimize();
|
||||
if (invokable instanceof Sequence) {
|
||||
for (Invokable subInvokable : ((Sequence) invokable).sequence) {
|
||||
for (RValue subInvokable : ((Sequence) invokable).sequence) {
|
||||
newSequence.add(subInvokable);
|
||||
}
|
||||
}
|
||||
@ -77,6 +77,6 @@ public class Sequence extends Invokable {
|
||||
}
|
||||
}
|
||||
|
||||
return new Sequence(getPosition(), newSequence.toArray(new Invokable[newSequence.size()]));
|
||||
return new Sequence(getPosition(), newSequence.toArray(new RValue[newSequence.size()]));
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.expression.runtime;
|
||||
|
||||
public final class Variable extends Assignable {
|
||||
public final class Variable extends LValue {
|
||||
public double value;
|
||||
|
||||
public Variable(double value) {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren