From 6e9c9dd78efbc4412861bac523fe1a3a7382d780 Mon Sep 17 00:00:00 2001 From: fxmorin <28154542+fxmorin@users.noreply.github.com> Date: Thu, 21 Dec 2023 20:48:53 -0500 Subject: [PATCH] Add `evaluate` to Evaluatable --- src/main/java/com/eliotlash/molang/ast/Evaluatable.java | 2 ++ src/main/java/com/eliotlash/molang/ast/EvaluatableExpr.java | 3 +++ src/main/java/com/eliotlash/molang/ast/EvaluatableStmt.java | 1 + 3 files changed, 6 insertions(+) diff --git a/src/main/java/com/eliotlash/molang/ast/Evaluatable.java b/src/main/java/com/eliotlash/molang/ast/Evaluatable.java index 1e9a865..dcf0f5f 100644 --- a/src/main/java/com/eliotlash/molang/ast/Evaluatable.java +++ b/src/main/java/com/eliotlash/molang/ast/Evaluatable.java @@ -4,6 +4,8 @@ public interface Evaluatable { + double evaluate(Evaluator evaluator); + default boolean isConstant() { return false; } diff --git a/src/main/java/com/eliotlash/molang/ast/EvaluatableExpr.java b/src/main/java/com/eliotlash/molang/ast/EvaluatableExpr.java index 6094337..00ef688 100644 --- a/src/main/java/com/eliotlash/molang/ast/EvaluatableExpr.java +++ b/src/main/java/com/eliotlash/molang/ast/EvaluatableExpr.java @@ -12,15 +12,18 @@ public EvaluatableExpr(Expr expr) { this.constant = expr instanceof Expr.Constant; } + @Override public double evaluate(Evaluator evaluator) { Double result = evaluator.evaluate(this.expr); return result == null ? 0 : result; } + @Override public boolean isConstant() { return this.constant; } + @Override public double getConstant() { if(!isConstant()) { return 0.0; diff --git a/src/main/java/com/eliotlash/molang/ast/EvaluatableStmt.java b/src/main/java/com/eliotlash/molang/ast/EvaluatableStmt.java index dea235b..ba39071 100644 --- a/src/main/java/com/eliotlash/molang/ast/EvaluatableStmt.java +++ b/src/main/java/com/eliotlash/molang/ast/EvaluatableStmt.java @@ -11,6 +11,7 @@ public EvaluatableStmt(List stmts) { this.stmts = Objects.requireNonNull(stmts); } + @Override public double evaluate(Evaluator evaluator) { return evaluator.evaluate(this.stmts); }