diff --git a/src/WattleScript.Interpreter/Debugging/SourceRef.cs b/src/WattleScript.Interpreter/Debugging/SourceRef.cs
index 289998cc..ddebd96f 100755
--- a/src/WattleScript.Interpreter/Debugging/SourceRef.cs
+++ b/src/WattleScript.Interpreter/Debugging/SourceRef.cs
@@ -8,10 +8,43 @@ namespace WattleScript.Interpreter.Debugging
///
public class SourceRef
{
+ private int Flags = 0;
+ private const int FLAG_CLRLOCATION = (1 << 0);
+ private const int FLAG_BREAKPOINT = (1 << 1);
+ private const int FLAG_CANNOT_BREAKPOINT = (1 << 2);
+ private const int FLAG_STEPSTOP = (1 << 3);
+ //Flags accessors
+
+
///
/// Gets a value indicating whether this location is inside CLR .
///
- public bool IsClrLocation { get; private set; }
+ public bool IsClrLocation => (Flags & FLAG_CLRLOCATION) != 0;
+
+ ///
+ /// Gets a value indicating whether this instance is a stop "step" in source mode
+ ///
+ public bool IsStepStop => (Flags & FLAG_STEPSTOP) != 0;
+
+ ///
+ /// Gets a value indicating whether this instance is a breakpoint
+ ///
+ public bool Breakpoint
+ {
+ get => (Flags & FLAG_BREAKPOINT) != 0;
+ set
+ {
+ if (value)
+ Flags |= FLAG_BREAKPOINT;
+ else
+ Flags &= ~FLAG_BREAKPOINT;
+ }
+ }
+
+ ///
+ /// Gets a value indicating whether this instance cannot be set as a breakpoint
+ ///
+ public bool CannotBreakpoint => (Flags & FLAG_CANNOT_BREAKPOINT) != 0;
///
/// Gets the index of the source.
@@ -33,19 +66,7 @@ public class SourceRef
/// Gets to which line the source code ref ends
///
public int ToLine { get; }
- ///
- /// Gets a value indicating whether this instance is a stop "step" in source mode
- ///
- public bool IsStepStop { get; }
-
- ///
- /// Gets a value indicating whether this instance is a breakpoint
- ///
- public bool Breakpoint;
- ///
- /// Gets a value indicating whether this instance cannot be set as a breakpoint
- ///
- public bool CannotBreakpoint { get; private set; }
+
///
/// Gets character index the source ref starts at
///
@@ -57,7 +78,7 @@ public class SourceRef
internal static SourceRef GetClrLocation()
{
- return new SourceRef(0, 0, 0, 0, 0, false, 0, 0) { IsClrLocation = true };
+ return new SourceRef(0, 0, 0, 0, 0, false, 0, 0) { Flags = FLAG_CLRLOCATION };
}
public SourceRef(SourceRef src, bool isStepStop)
@@ -67,7 +88,7 @@ public SourceRef(SourceRef src, bool isStepStop)
ToChar = src.ToChar;
FromLine = src.FromLine;
ToLine = src.ToLine;
- IsStepStop = isStepStop;
+ Flags = isStepStop ? FLAG_STEPSTOP : 0;
ToCharIndex = src.ToCharIndex;
FromCharIndex = src.FromCharIndex;
}
@@ -81,17 +102,14 @@ public override bool Equals(object obj)
return false;
}
- protected bool Equals(SourceRef other)
+ public bool Equals(SourceRef other)
{
- return Breakpoint == other.Breakpoint &&
- IsClrLocation == other.IsClrLocation &&
+ return Flags == other.Flags &&
SourceIdx == other.SourceIdx &&
FromChar == other.FromChar &&
ToChar == other.ToChar &&
FromLine == other.FromLine &&
ToLine == other.ToLine &&
- IsStepStop == other.IsStepStop &&
- CannotBreakpoint == other.CannotBreakpoint &&
ToCharIndex == other.ToCharIndex &&
FromCharIndex == other.FromCharIndex;
}
@@ -100,17 +118,14 @@ public override int GetHashCode()
{
unchecked
{
- var hashCode = Breakpoint.GetHashCode();
- hashCode = (hashCode * 397) ^ IsClrLocation.GetHashCode();
+ var hashCode = Flags.GetHashCode();
hashCode = (hashCode * 397) ^ SourceIdx;
hashCode = (hashCode * 397) ^ FromChar;
hashCode = (hashCode * 397) ^ ToChar;
hashCode = (hashCode * 397) ^ FromLine;
hashCode = (hashCode * 397) ^ ToLine;
- hashCode = (hashCode * 397) ^ IsStepStop.GetHashCode();
hashCode = (hashCode * 397) ^ FromCharIndex;
hashCode = (hashCode * 397) ^ ToCharIndex;
- hashCode = (hashCode * 397) ^ CannotBreakpoint.GetHashCode();
return hashCode;
}
}
@@ -128,6 +143,7 @@ public override int GetHashCode()
public SourceRef(int sourceIdx)
{
SourceIdx = sourceIdx;
+
}
public SourceRef(int sourceIdx, int from, int to, int fromline, int toline, bool isStepStop, int charIndexFrom, int charIndexTo)
@@ -137,7 +153,7 @@ public SourceRef(int sourceIdx, int from, int to, int fromline, int toline, bool
ToChar = to;
FromLine = fromline;
ToLine = toline;
- IsStepStop = isStepStop;
+ Flags = isStepStop ? FLAG_STEPSTOP : 0;
ToCharIndex = charIndexTo;
FromCharIndex = charIndexFrom;
}
@@ -228,7 +244,7 @@ public bool IncludesLocation(int sourceIdx, int line, int col)
///
public SourceRef SetNoBreakPoint()
{
- CannotBreakpoint = true;
+ Flags |= FLAG_CANNOT_BREAKPOINT;
return this;
}
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.