Commit 555dc5dd authored by Ticxo's avatar Ticxo
Browse files

Directly move everything to this repo

parent 2ff9eb39
package com.bedrockk.molang.ast;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.MoValue;
import lombok.Value;
@Value
public class ReturnExpression implements Expression {
Expression expression;
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
MoValue eval = expression.evaluate(scope, environment);
scope.setReturnValue(eval);
return eval;
}
}
package com.bedrockk.molang.ast;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue;
import com.bedrockk.molang.runtime.value.MoValue;
import lombok.Value;
@Value
public class StatementExpression implements Expression {
Expression[] expressions;
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
for (Expression expression : expressions) {
expression.evaluate(scope, environment);
if (scope.getReturnValue() != null) {
return scope.getReturnValue();
} else if (scope.isBreak() || scope.isContinue()) {
break;
}
}
return DoubleValue.ZERO;
}
}
package com.bedrockk.molang.ast;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.MoValue;
import com.bedrockk.molang.runtime.value.StringValue;
import lombok.Value;
@Value
public class StringExpression implements Expression {
String string;
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
return new StringValue(string);
}
}
package com.bedrockk.molang.ast;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue;
import com.bedrockk.molang.runtime.value.MoValue;
import lombok.Value;
@Value
public class TernaryExpression implements Expression {
Expression condition;
Expression thenExpr;
Expression elseExpr;
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
if (condition.evaluate(scope, environment).equals(DoubleValue.ONE)) {
return thenExpr == null ? condition.evaluate(scope, environment) : thenExpr.evaluate(scope, environment);
} else if (elseExpr != null) {
return elseExpr.evaluate(scope, environment);
}
return DoubleValue.ZERO;
}
}
package com.bedrockk.molang.ast;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.MoValue;
import lombok.Value;
@Value
public class ThisExpression implements Expression {
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
return environment;
}
}
package com.bedrockk.molang.ast;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue;
import com.bedrockk.molang.runtime.value.MoValue;
import lombok.Value;
@Value
public class UnaryMinusExpression implements Expression {
Expression expression;
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
return new DoubleValue(-expression.evaluate(scope, environment).asDouble());
}
}
package com.bedrockk.molang.ast;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue;
import com.bedrockk.molang.runtime.value.MoValue;
import lombok.Value;
@Value
public class UnaryPlusExpression implements Expression {
Expression expression;
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
return new DoubleValue(+expression.evaluate(scope, environment).asDouble());
}
}
package com.bedrockk.molang.ast.binaryop;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.ast.BinaryOpExpression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.MoValue;
public class ArrowExpression extends BinaryOpExpression {
public ArrowExpression(Expression left, Expression right) {
super(left, right);
}
@Override
public String getSigil() {
return "->";
}
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
Object leftEnv = left.evaluate(scope, environment);
if (leftEnv instanceof MoLangEnvironment) {
return right.evaluate(scope, (MoLangEnvironment) leftEnv);
}
return null;
}
}
package com.bedrockk.molang.ast.binaryop;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.ast.BinaryOpExpression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue;
import com.bedrockk.molang.runtime.value.MoValue;
public class BooleanAndExpression extends BinaryOpExpression {
public BooleanAndExpression(Expression left, Expression right) {
super(left, right);
}
@Override
public String getSigil() {
return "&&";
}
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
return new DoubleValue(!left.evaluate(scope, environment).equals(DoubleValue.ZERO) && !right.evaluate(scope, environment).equals(DoubleValue.ZERO));
}
}
package com.bedrockk.molang.ast.binaryop;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.ast.BinaryOpExpression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue;
import com.bedrockk.molang.runtime.value.MoValue;
public class BooleanOrExpression extends BinaryOpExpression {
public BooleanOrExpression(Expression left, Expression right) {
super(left, right);
}
@Override
public String getSigil() {
return "||";
}
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
return new DoubleValue(!left.evaluate(scope, environment).equals(DoubleValue.ZERO) || !right.evaluate(scope, environment).equals(DoubleValue.ZERO));
}
}
package com.bedrockk.molang.ast.binaryop;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.ast.BinaryOpExpression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue;
import com.bedrockk.molang.runtime.value.MoValue;
public class CoalesceExpression extends BinaryOpExpression {
public CoalesceExpression(Expression left, Expression right) {
super(left, right);
}
@Override
public String getSigil() {
return "??";
}
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
MoValue evalLeft = left.evaluate(scope, environment);
MoValue value = environment.getValue(evalLeft.asString());
if (value == null || value.equals(DoubleValue.ZERO)) {
return right.evaluate(scope, environment);
} else {
return evalLeft;
}
}
}
package com.bedrockk.molang.ast.binaryop;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.ast.BinaryOpExpression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue;
import com.bedrockk.molang.runtime.value.MoValue;
public class DivideExpression extends BinaryOpExpression {
public DivideExpression(Expression left, Expression right) {
super(left, right);
}
@Override
public String getSigil() {
return "/";
}
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
return new DoubleValue(left.evaluate(scope, environment).asDouble() / right.evaluate(scope, environment).asDouble());
}
}
package com.bedrockk.molang.ast.binaryop;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.ast.BinaryOpExpression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue;
import com.bedrockk.molang.runtime.value.MoValue;
public class EqualExpression extends BinaryOpExpression {
public EqualExpression(Expression left, Expression right) {
super(left, right);
}
@Override
public String getSigil() {
return "==";
}
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
return new DoubleValue(left.evaluate(scope, environment).equals(right.evaluate(scope, environment)));
}
}
package com.bedrockk.molang.ast.binaryop;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.ast.BinaryOpExpression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue;
import com.bedrockk.molang.runtime.value.MoValue;
public class GreaterExpression extends BinaryOpExpression {
public GreaterExpression(Expression left, Expression right) {
super(left, right);
}
@Override
public String getSigil() {
return ">";
}
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
return new DoubleValue(left.evaluate(scope, environment).asDouble() > right.evaluate(scope, environment).asDouble());
}
}
package com.bedrockk.molang.ast.binaryop;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.ast.BinaryOpExpression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue;
import com.bedrockk.molang.runtime.value.MoValue;
public class GreaterOrEqualExpression extends BinaryOpExpression {
public GreaterOrEqualExpression(Expression left, Expression right) {
super(left, right);
}
@Override
public String getSigil() {
return ">=";
}
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
return new DoubleValue(left.evaluate(scope, environment).asDouble() >= right.evaluate(scope, environment).asDouble());
}
}
package com.bedrockk.molang.ast.binaryop;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.ast.BinaryOpExpression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue;
import com.bedrockk.molang.runtime.value.MoValue;
public class MinusExpression extends BinaryOpExpression {
public MinusExpression(Expression left, Expression right) {
super(left, right);
}
@Override
public String getSigil() {
return "-";
}
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
return new DoubleValue(left.evaluate(scope, environment).asDouble() - right.evaluate(scope, environment).asDouble());
}
}
package com.bedrockk.molang.ast.binaryop;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.ast.BinaryOpExpression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue;
import com.bedrockk.molang.runtime.value.MoValue;
public class NotEqualExpression extends BinaryOpExpression {
public NotEqualExpression(Expression left, Expression right) {
super(left, right);
}
@Override
public String getSigil() {
return "!=";
}
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
return new DoubleValue(!left.evaluate(scope, environment).equals(right.evaluate(scope, environment)));
}
}
package com.bedrockk.molang.ast.binaryop;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.ast.BinaryOpExpression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue;
import com.bedrockk.molang.runtime.value.MoValue;
public class PlusExpression extends BinaryOpExpression {
public PlusExpression(Expression left, Expression right) {
super(left, right);
}
@Override
public String getSigil() {
return "+";
}
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
return new DoubleValue(left.evaluate(scope, environment).asDouble() + right.evaluate(scope, environment).asDouble());
}
}
package com.bedrockk.molang.ast.binaryop;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.ast.BinaryOpExpression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue;
import com.bedrockk.molang.runtime.value.MoValue;
public class PowExpression extends BinaryOpExpression {
public PowExpression(Expression left, Expression right) {
super(left, right);
}
@Override
public String getSigil() {
return "*";
}
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
return new DoubleValue(left.evaluate(scope, environment).asDouble() * right.evaluate(scope, environment).asDouble());
}
}
package com.bedrockk.molang.ast.binaryop;
import com.bedrockk.molang.Expression;
import com.bedrockk.molang.ast.BinaryOpExpression;
import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue;
import com.bedrockk.molang.runtime.value.MoValue;
public class SmallerExpression extends BinaryOpExpression {
public SmallerExpression(Expression left, Expression right) {
super(left, right);
}
@Override
public String getSigil() {
return "<";
}
@Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
return new DoubleValue(left.evaluate(scope, environment).asDouble() < right.evaluate(scope, environment).asDouble());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment