mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-05 07:16:10 +00:00
use applyDouble and applyBoolean in applicable ops
This commit is contained in:
@@ -341,11 +341,11 @@ public class Parser {
|
||||
|
||||
String id = identifier.getContent();
|
||||
|
||||
return switch(type.getType()) {
|
||||
return switch(value.returnType()) {
|
||||
case NUMBER -> new NumAssignmentNode((Returnable<Number>) value, identifier.getPosition(), scopeBuilder.num(id));
|
||||
case STRING -> new StrAssignmentNode((Returnable<String>) value, identifier.getPosition(), scopeBuilder.str(id));
|
||||
case BOOLEAN -> new BoolAssignmentNode((Returnable<Boolean>) value, identifier.getPosition(), scopeBuilder.bool(id));
|
||||
default -> throw new ParseException("Illegal type for variable assignment: " + type, value.getPosition());
|
||||
default -> throw new ParseException("Illegal type for variable declaration: " + type, value.getPosition());
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,21 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.constants;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
|
||||
public class BooleanConstant extends ConstantExpression<Boolean> {
|
||||
private final boolean constant;
|
||||
public BooleanConstant(Boolean constant, Position position) {
|
||||
super(constant, position);
|
||||
this.constant = constant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return constant;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,13 +7,22 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.constants;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
|
||||
public class NumericConstant extends ConstantExpression<Number> {
|
||||
private final double constant;
|
||||
public NumericConstant(Number constant, Position position) {
|
||||
super(constant, position);
|
||||
this.constant = constant.doubleValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double applyDouble(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return constant;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,6 +14,16 @@ import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
|
||||
public interface Function<T> extends Returnable<T> {
|
||||
@Override
|
||||
default double applyDouble(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return (Double) apply(implementationArguments, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return (Boolean) apply(implementationArguments, scope);
|
||||
}
|
||||
|
||||
Function<?> NULL = new Function<>() {
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
|
||||
@@ -16,8 +16,8 @@ import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
|
||||
public abstract class BinaryOperation<I, O> implements Returnable<O> {
|
||||
private final Returnable<I> left;
|
||||
private final Returnable<I> right;
|
||||
protected final Returnable<I> left;
|
||||
protected final Returnable<I> right;
|
||||
private final Position start;
|
||||
|
||||
public BinaryOperation(Returnable<I> left, Returnable<I> right, Position start) {
|
||||
@@ -26,13 +26,6 @@ public abstract class BinaryOperation<I, O> implements Returnable<O> {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public abstract O apply(Supplier<I> left, Supplier<I> right);
|
||||
|
||||
@Override
|
||||
public O apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return apply(() -> left.apply(implementationArguments, scope), () -> right.apply(implementationArguments, scope));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return start;
|
||||
|
||||
@@ -9,7 +9,9 @@ package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
|
||||
@@ -18,13 +20,18 @@ public class BooleanAndOperation extends BinaryOperation<Boolean, Boolean> {
|
||||
super(left, right, start);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean apply(Supplier<Boolean> left, Supplier<Boolean> right) {
|
||||
return left.get() && right.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.BOOLEAN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return applyBoolean(implementationArguments, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyBoolean(implementationArguments, scope) && right.applyBoolean(implementationArguments, scope);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
|
||||
@@ -17,8 +19,13 @@ public class BooleanNotOperation extends UnaryOperation<Boolean> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean apply(Boolean input) {
|
||||
return !input;
|
||||
public Boolean apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return applyBoolean(implementationArguments, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return !input.applyBoolean(implementationArguments, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,7 +9,9 @@ package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
|
||||
@@ -19,10 +21,14 @@ public class BooleanOrOperation extends BinaryOperation<Boolean, Boolean> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean apply(Supplier<Boolean> left, Supplier<Boolean> right) {
|
||||
return left.get() || right.get();
|
||||
public Boolean apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return applyBoolean(implementationArguments, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyBoolean(implementationArguments, scope) || right.applyBoolean(implementationArguments, scope);
|
||||
}
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.BOOLEAN;
|
||||
|
||||
@@ -9,7 +9,9 @@ package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
|
||||
@@ -18,13 +20,13 @@ public class ConcatenationOperation extends BinaryOperation<Object, Object> {
|
||||
super(left, right, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apply(Supplier<Object> left, Supplier<Object> right) {
|
||||
return left.get().toString() + right.get().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType returnType() {
|
||||
return Returnable.ReturnType.STRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.apply(implementationArguments, scope).toString() + right.apply(implementationArguments, scope).toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
|
||||
@@ -18,13 +20,18 @@ public class DivisionOperation extends BinaryOperation<Number, Number> {
|
||||
super(left, right, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number apply(Supplier<Number> left, Supplier<Number> right) {
|
||||
return left.get().doubleValue() / right.get().doubleValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType returnType() {
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double applyDouble(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) / right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
|
||||
@@ -19,10 +21,14 @@ public class ModuloOperation extends BinaryOperation<Number, Number> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number apply(Supplier<Number> left, Supplier<Number> right) {
|
||||
return left.get().doubleValue() % right.get().doubleValue();
|
||||
public Number apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double applyDouble(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) % right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
|
||||
@@ -9,7 +9,9 @@ package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
|
||||
@@ -19,10 +21,14 @@ public class MultiplicationOperation extends BinaryOperation<Number, Number> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number apply(Supplier<Number> left, Supplier<Number> right) {
|
||||
return left.get().doubleValue() * right.get().doubleValue();
|
||||
public Number apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double applyDouble(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) * right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
|
||||
@@ -16,13 +18,18 @@ public class NegationOperation extends UnaryOperation<Number> {
|
||||
super(input, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number apply(Number input) {
|
||||
return -input.doubleValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double applyDouble(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return -input.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
|
||||
@@ -19,10 +21,14 @@ public class NumberAdditionOperation extends BinaryOperation<Number, Number> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number apply(Supplier<Number> left, Supplier<Number> right) {
|
||||
return left.get().doubleValue() + right.get().doubleValue();
|
||||
public Number apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double applyDouble(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) + right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
|
||||
@@ -9,7 +9,9 @@ package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
|
||||
@@ -19,10 +21,14 @@ public class SubtractionOperation extends BinaryOperation<Number, Number> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number apply(Supplier<Number> left, Supplier<Number> right) {
|
||||
return left.get().doubleValue() - right.get().doubleValue();
|
||||
public Number apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double applyDouble(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) - right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
|
||||
@@ -14,7 +14,7 @@ import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
|
||||
public abstract class UnaryOperation<T> implements Returnable<T> {
|
||||
private final Returnable<T> input;
|
||||
protected final Returnable<T> input;
|
||||
private final Position position;
|
||||
|
||||
public UnaryOperation(Returnable<T> input, Position position) {
|
||||
@@ -22,13 +22,6 @@ public abstract class UnaryOperation<T> implements Returnable<T> {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public abstract T apply(T input);
|
||||
|
||||
@Override
|
||||
public T apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return apply(input.apply(implementationArguments, scope));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
@@ -24,20 +27,25 @@ public class EqualsStatement extends BinaryOperation<Object, Boolean> {
|
||||
super(left, right, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean apply(Supplier<Object> left, Supplier<Object> right) {
|
||||
Object leftUnwrapped = left.get();
|
||||
Object rightUnwrapped = right.get();
|
||||
if(leftUnwrapped instanceof Number l && rightUnwrapped instanceof Number r) {
|
||||
return FastMath.abs(l.doubleValue() - r.doubleValue()) <= EPSILON;
|
||||
}
|
||||
|
||||
return leftUnwrapped.equals(rightUnwrapped);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType returnType() {
|
||||
return Returnable.ReturnType.BOOLEAN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return applyBoolean(implementationArguments, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
Object leftValue = left.apply(implementationArguments, scope);
|
||||
Object rightValue = right.apply(implementationArguments, scope);
|
||||
if(leftValue instanceof Number l && rightValue instanceof Number r) {
|
||||
return FastMath.abs(l.doubleValue() - r.doubleValue()) <= EPSILON;
|
||||
}
|
||||
|
||||
return leftValue.equals(rightValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
@@ -19,14 +21,18 @@ public class GreaterOrEqualsThanStatement extends BinaryOperation<Number, Boolea
|
||||
super(left, right, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean apply(Supplier<Number> left, Supplier<Number> right) {
|
||||
return left.get().doubleValue() >= right.get().doubleValue();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType returnType() {
|
||||
return Returnable.ReturnType.BOOLEAN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return applyBoolean(implementationArguments, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) >= right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
@@ -19,11 +21,16 @@ public class GreaterThanStatement extends BinaryOperation<Number, Boolean> {
|
||||
super(left, right, position);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Boolean apply(Supplier<Number> left, Supplier<Number> right) {
|
||||
return left.get().doubleValue() > right.get().doubleValue();
|
||||
public Boolean apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return applyBoolean(implementationArguments, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) > right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType returnType() {
|
||||
|
||||
@@ -9,7 +9,9 @@ package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
@@ -19,12 +21,16 @@ public class LessThanOrEqualsStatement extends BinaryOperation<Number, Boolean>
|
||||
super(left, right, position);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Boolean apply(Supplier<Number> left, Supplier<Number> right) {
|
||||
return left.get().doubleValue() <= right.get().doubleValue();
|
||||
public Boolean apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return applyBoolean(implementationArguments, scope);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) <= right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
@Override
|
||||
public Returnable.ReturnType returnType() {
|
||||
return Returnable.ReturnType.BOOLEAN;
|
||||
|
||||
@@ -9,7 +9,9 @@ package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
@@ -19,12 +21,16 @@ public class LessThanStatement extends BinaryOperation<Number, Boolean> {
|
||||
super(left, right, position);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Boolean apply(Supplier<Number> left, Supplier<Number> right) {
|
||||
return left.get().doubleValue() < right.get().doubleValue();
|
||||
public Boolean apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return applyBoolean(implementationArguments, scope);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) < right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
@Override
|
||||
public Returnable.ReturnType returnType() {
|
||||
return Returnable.ReturnType.BOOLEAN;
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
@@ -24,16 +27,20 @@ public class NotEqualsStatement extends BinaryOperation<Object, Boolean> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean apply(Supplier<Object> left, Supplier<Object> right) {
|
||||
Object leftUnwrapped = left.get();
|
||||
Object rightUnwrapped = right.get();
|
||||
if(leftUnwrapped instanceof Number l && rightUnwrapped instanceof Number r) {
|
||||
return FastMath.abs(l.doubleValue() - r.doubleValue()) > EPSILON;
|
||||
}
|
||||
|
||||
return !leftUnwrapped.equals(rightUnwrapped);
|
||||
public Boolean apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return applyBoolean(implementationArguments, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
Object leftValue = left.apply(implementationArguments, scope);
|
||||
Object rightValue = right.apply(implementationArguments, scope);
|
||||
if(leftValue instanceof Number l && rightValue instanceof Number r) {
|
||||
return FastMath.abs(l.doubleValue() - r.doubleValue()) > EPSILON;
|
||||
}
|
||||
|
||||
return !leftValue.equals(rightValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType returnType() {
|
||||
|
||||
Reference in New Issue
Block a user