diff --git a/src/WattleScript.Interpreter/Execution/DynamicExpression.cs b/src/WattleScript.Interpreter/Execution/DynamicExpression.cs index 7fa0314f..5ef08b4a 100644 --- a/src/WattleScript.Interpreter/Execution/DynamicExpression.cs +++ b/src/WattleScript.Interpreter/Execution/DynamicExpression.cs @@ -34,16 +34,16 @@ internal DynamicExpression(Script S, string strExpr, DynValue constant) /// /// The context. /// - public DynValue Evaluate(ScriptExecutionContext context = null) + public DynValue Evaluate(ScriptExecutionContext? context = null) { - context = context ?? OwnerScript.CreateDynamicExecutionContext(); + var ctx = context ?? OwnerScript.CreateDynamicExecutionContext(); - this.CheckScriptOwnership(context.GetScript()); + this.CheckScriptOwnership(ctx.GetScript()); if (!m_Constant.IsNil()) return m_Constant; - return m_Exp.Eval(context); + return m_Exp.Eval(ctx); } /// diff --git a/src/WattleScript.Interpreter/Execution/ScriptExecutionContext.cs b/src/WattleScript.Interpreter/Execution/ScriptExecutionContext.cs index a9e8f1ca..e0ef852b 100644 --- a/src/WattleScript.Interpreter/Execution/ScriptExecutionContext.cs +++ b/src/WattleScript.Interpreter/Execution/ScriptExecutionContext.cs @@ -8,19 +8,34 @@ namespace WattleScript.Interpreter /// /// Class giving access to details of the environment where the script is executing /// - public class ScriptExecutionContext : IScriptPrivateResource + public struct ScriptExecutionContext : IScriptPrivateResource { Processor m_Processor; CallbackFunction m_Callback; - - internal bool CanAwait { get; set; } + private SourceRef m_CallingLocation; + private int m_Flags; + + private const int FLAG_ISDYNAMIC = (1 << 0); + private const int FLAG_CANAWAIT = (1 << 1); + + internal bool CanAwait + { + get => (m_Flags & FLAG_CANAWAIT) != 0; + set + { + if (value) + m_Flags |= FLAG_CANAWAIT; + else + m_Flags &= ~FLAG_CANAWAIT; + } + } internal ScriptExecutionContext(Processor p, CallbackFunction callBackFunction, SourceRef sourceRef, bool isDynamic = false) { - IsDynamicExecution = isDynamic; + m_Flags = isDynamic ? FLAG_ISDYNAMIC : 0; m_Processor = p; m_Callback = callBackFunction; - CallingLocation = sourceRef; + m_CallingLocation = sourceRef; } /// @@ -28,20 +43,12 @@ internal ScriptExecutionContext(Processor p, CallbackFunction callBackFunction, /// Under a dynamic execution, most methods of ScriptExecutionContext are not reliable as the /// processing engine of the script is not "really" running or is not available. /// - public bool IsDynamicExecution - { - get; - private set; - } + public bool IsDynamicExecution => (m_Flags & FLAG_ISDYNAMIC) != 0; /// /// Gets the location of the code calling back /// - public SourceRef CallingLocation - { - get; - private set; - } + public SourceRef CallingLocation => m_CallingLocation; /// /// Gets or sets the additional data associated to this CLR function call.