diff --git a/src/main/java/me/blvckbytes/gpeee/GPEEE.java b/src/main/java/me/blvckbytes/gpeee/GPEEE.java index bfc844a..5124373 100644 --- a/src/main/java/me/blvckbytes/gpeee/GPEEE.java +++ b/src/main/java/me/blvckbytes/gpeee/GPEEE.java @@ -91,6 +91,13 @@ public Object evaluateExpression(AExpression expression, IEvaluationEnvironment return interpreter.evaluateExpression(expression, environment); } + @Override + public EvaluationEnvironmentBuilder getBaseEnvironment() { + if (this.baseEnvironment == null) + return new EvaluationEnvironmentBuilder(); + return this.baseEnvironment.duplicate(); + } + @Override public void register(String name, AStandardFunction function) { this.standardFunctions.put(name, function); diff --git a/src/main/java/me/blvckbytes/gpeee/IExpressionEvaluator.java b/src/main/java/me/blvckbytes/gpeee/IExpressionEvaluator.java index a4a074b..c1be3be 100644 --- a/src/main/java/me/blvckbytes/gpeee/IExpressionEvaluator.java +++ b/src/main/java/me/blvckbytes/gpeee/IExpressionEvaluator.java @@ -25,6 +25,7 @@ package me.blvckbytes.gpeee; import me.blvckbytes.gpeee.error.AEvaluatorError; +import me.blvckbytes.gpeee.interpreter.EvaluationEnvironmentBuilder; import me.blvckbytes.gpeee.interpreter.IEvaluationEnvironment; import me.blvckbytes.gpeee.parser.expression.AExpression; @@ -56,4 +57,9 @@ public interface IExpressionEvaluator { */ Object evaluateExpression(AExpression expression, IEvaluationEnvironment environment) throws AEvaluatorError; + /** + * Get a copy of the evaluator's base environment to be safely modified and built by the caller + */ + EvaluationEnvironmentBuilder getBaseEnvironment(); + }