37 private readonly Stack<BadRuntimeVirtualStackFrame>
m_ContextStack =
new Stack<BadRuntimeVirtualStackFrame>();
100 "Lock object must be of type Array, Object or Class",
115 List<BadObject> arr =
new List<BadObject>();
117 for (
int i = 0; i < length; i++)
129 Dictionary<string, BadObject> arr =
new Dictionary<string, BadObject>();
131 for (
int i = 0; i < length; i++)
140 arr.Add(s.Value, val);
175 for (
int i = argCount - 1; i >= 0; i--)
187 ReturnPointer = m_InstructionPointer
216 for (
int i = argCount - 1; i >= 0; i--)
257 "Lock object must be of type Array, Object or Class",
269 string name = (string)instr.
Arguments[0];
270 bool isReadOnly = (bool)instr.
Arguments[1];
279 string name = (string)instr.
Arguments[0];
280 bool isReadOnly = (bool)instr.
Arguments[1];
293 if (instr.
Arguments.Length > 1 && instr.
Arguments[1] is
int genericArgCount && genericArgCount != 0)
301 for (
int i = genericArgCount - 1; i >= 0; i--)
316 if (instr.
Arguments.Length > 1 && instr.
Arguments[1] is
int genericArgCount && genericArgCount != 0)
329 for (
int i = genericArgCount - 1; i >= 0; i--)
349 string name = (string)instr.
Arguments[0];
353 if (instr.
Arguments.Length > 1 && instr.
Arguments[1] is
int genericArgCount && genericArgCount != 0)
364 for (
int i = genericArgCount - 1; i >= 0; i--)
391 for (
int i = argCount - 1; i >= 0; i--)
409 case BadOpCode.LoadArrayAccessNullChecked:
416 for (
int i = 0; i < argCount; i++)
429 for (
int i = argCount - 1; i >= 0; i--)
454 for (
int i = argCount - 1; i >= 0; i--)
472 case BadOpCode.LoadArrayAccessReverseNullChecked:
487 for (
int i = argCount - 1; i >= 0; i--)
529 string format = (string)instr.
Arguments[0];
533 for (
int i = argCount - 1; i >= 0; i--)
538 m_ArgumentStack.Push(
string.Format(format, args.Cast<
object?>().ToArray()));
815 string name = (string)instr.
Arguments[0];
816 bool? useVisibility =
null;
820 useVisibility = (bool)instr.
Arguments[1];
880 "Cannot check if an object is an instance of a non-class object.",
898 string name = (string)instr.
Arguments[0];
907 string name = (string)instr.
Arguments[0];
908 string path = (string)instr.
Arguments[1];
921 "Cannot delete a non-reference object.",
1409 bool isRefReturn = (bool)instr.
Arguments[0];
1413 ret = ret.Dereference();
1488 throw new ArgumentOutOfRangeException();
1592 if (!enumerator.MoveNext())
Public Debugger Interface.
static void Step(BadDebuggerStep stepInfo)
Sends a step event to the debugger.
static bool IsAttached
True if a debugger is attached.
Implements the Array Access to set or get properties from an object. LEFT[RIGHT].
static IEnumerable< BadObject > Access(BadExecutionContext? context, BadObject left, IEnumerable< BadObject > args, BadSourcePosition position)
Executes the Array Access Expression.
Implements the Reverse Array Access to set or get properties from an object. LEFT[^RIGHT].
static IEnumerable< BadObject > Access(BadExecutionContext context, BadObject left, IEnumerable< BadObject > args, BadSourcePosition position)
Executes the Array Access Expression.
Base Implementation for all Expressions used inside the Script.
Implements the binary ... operator. This operator is used to unpack the right side into the left side...
static BadTable Unpack(BadObject left, BadObject right, BadSourcePosition position)
Executes the binary ... operator.
Implements the 'in' operator. The 'in' operator is used to check if a key is present in an instance o...
static IEnumerable< BadObject > InWithOverride(BadExecutionContext context, BadObject left, BadObject right, BadSourcePosition position)
Implements the logic of the 'in' operator but checks for an operator override first.
static BadObject In(BadExecutionContext ctx, BadObject left, BadObject right)
Implements the logic of the 'in' operator.
Implements the Range Expression START..END.
static IEnumerable< BadObject > Range(decimal from, decimal to)
Returns a range of numbers.
Implements the unary ... operator. This operator is used to unpack a table into the current execution...
static void Unpack(BadTable table, BadObject right, BadSourcePosition position)
Implements the logic of the unary ... operator.
Implements the Equality Expression LEFT == RIGHT.
static BadObject Equal(BadObject left, BadObject right)
Returns true if the left side is equal to the right side.
static IEnumerable< BadObject > EqualWithOverride(BadExecutionContext? caller, BadObject left, BadObject right, BadSourcePosition position)
Executes the operator override for the given operator name.
Implements the Greater or Equal Expression LEFT >= RIGHT.
static IEnumerable< BadObject > GreaterOrEqualWithOverride(BadExecutionContext? context, BadObject left, BadObject right, BadSourcePosition position)
Executes the expression.
static BadObject GreaterOrEqual(BadObject left, BadObject right, BadSourcePosition pos)
Returns true if the left side is greater or equal to the right side.
Implements the Greater Than Expression.
static BadObject GreaterThan(BadObject left, BadObject right, BadSourcePosition pos)
Returns true if the left side is greater than the right side.
static IEnumerable< BadObject > GreaterThanWithOverride(BadExecutionContext? context, BadObject left, BadObject right, BadSourcePosition position)
Executes the expression.
Implements the Inequality Expression.
static BadObject NotEqual(BadObject left, BadObject right)
Returns True if the two Objects are not equal.
static IEnumerable< BadObject > NotEqualWithOverride(BadExecutionContext? caller, BadObject left, BadObject right, BadSourcePosition position)
Executes the expression.
Implements the Less or Equal Expression LEFT <= RIGHT.
static BadObject LessOrEqual(BadObject left, BadObject right, BadSourcePosition pos)
Returns true if the left side is less or equal to the right side.
static IEnumerable< BadObject > LessOrEqualWithOverride(BadExecutionContext? context, BadObject left, BadObject right, BadSourcePosition position)
Executes the expression.
Implements the Less Than Expression.
static BadObject LessThan(BadObject left, BadObject right, BadSourcePosition pos)
Returns true if the left side is less than the right side.
static IEnumerable< BadObject > LessThanWithOverride(BadExecutionContext? context, BadObject left, BadObject right, BadSourcePosition position)
Executes the expression.
Implements the Logic And Expression.
static BadObject And(BadObject left, BadObject right, BadSourcePosition pos)
Returns true if left and right are true.
Implements the Logic Not Exression.
static IEnumerable< BadObject > NotWithOverride(BadExecutionContext? context, BadObject left, BadSourcePosition position)
Executes the expression.
static BadObject Not(BadObject left, BadSourcePosition pos)
Returns true if the Input is false Returns false if the Input is true.
Implements the Logic Exclusive Or Expression.
static BadObject XOr(BadObject left, BadObject right, BadSourcePosition pos)
Returns true if left or right are true. False if both are true.
Implements the Add Assignment Expression.
static IEnumerable< BadObject > AddWithOverride(BadExecutionContext? context, BadObjectReference leftRef, BadObject right, BadSourcePosition position, string symbol)
Executes the Operator with operator override.
static BadObject Add(BadObjectReference leftRef, BadObject left, BadObject right, BadSourcePosition position, string symbol)
Executes the Add Assignment Operator.
Implements the Divide Assignment Expression.
static IEnumerable< BadObject > DivideWithOverride(BadExecutionContext? context, BadObjectReference leftRef, BadObject right, BadSourcePosition position, string symbol)
Executes the Operator with operator override.
static BadObject Divide(BadObjectReference leftRef, BadObject left, BadObject right, BadSourcePosition position, string symbol)
Executes the Operator.
Implements the Exponentiation Assign Expression.
static BadObject Exp(BadObjectReference leftRef, BadObject left, BadObject right, BadSourcePosition position, string symbol)
Implements the logic of the Exponentiation Operator.
static IEnumerable< BadObject > ExpWithOverride(BadExecutionContext? context, BadObjectReference leftRef, BadObject right, BadSourcePosition position, string symbol)
Runs the Exponentiation Operator on the given objects.
Implements the Modulus Assign Expression.
static BadObject Modulus(BadObjectReference leftRef, BadObject left, BadObject right, BadSourcePosition position, string symbol)
Executes the Operator.
static IEnumerable< BadObject > ModulusWithOverride(BadExecutionContext? context, BadObjectReference leftRef, BadObject right, BadSourcePosition position, string symbol)
Executes the Operator with operator override.
Implements the Multiply Assignment Expression.
static IEnumerable< BadObject > MultiplyWithOverride(BadExecutionContext? context, BadObjectReference leftRef, BadObject right, BadSourcePosition position, string symbol)
Executes the Operator with operator override.
static BadObject Multiply(BadObjectReference leftRef, BadObject left, BadObject right, BadSourcePosition position, string symbol)
Executes the Operator.
Implements the Subtract Assign Expression.
static BadObject Subtract(BadObjectReference leftRef, BadObject left, BadObject right, BadSourcePosition position, string symbol)
Executes the Operator.
static IEnumerable< BadObject > SubtractWithOverride(BadExecutionContext? context, BadObjectReference leftRef, BadObject right, BadSourcePosition position, string symbol)
Executes the Operator with operator override.
Implements the Post Decrement Expression.
static BadObject Decrement(BadObjectReference reference, BadSourcePosition position)
Executes the Operator.
static IEnumerable< BadObject > DecrementWithOverride(BadExecutionContext? context, BadObjectReference leftRef, BadSourcePosition position)
Executes the Operator.
Implements the Post Increment Expression.
static IEnumerable< BadObject > IncrementWithOverride(BadExecutionContext? context, BadObjectReference leftRef, BadSourcePosition position)
Executes the Operator.
static BadObject Increment(BadObjectReference reference, BadSourcePosition position)
Executes the Operator.
Implements the Pre Decrement Expression.
static BadObject Decrement(BadObjectReference reference, BadSourcePosition position)
Executes the Operator.
static IEnumerable< BadObject > DecrementWithOverride(BadExecutionContext? context, BadObjectReference leftRef, BadSourcePosition position)
Executes the Operator.
Implements the Pre Increment Expression.
static BadObject Increment(BadObjectReference reference, BadSourcePosition position)
Executes the Operator.
static IEnumerable< BadObject > IncrementWithOverride(BadExecutionContext? context, BadObjectReference leftRef, BadSourcePosition position)
Executes the Operator.
Implements the Add Expression.
static BadObject Add(BadObject left, BadObject right, BadSourcePosition pos)
Adds left and right together.
static IEnumerable< BadObject > AddWithOverride(BadExecutionContext? context, BadObject leftRef, BadObject right, BadSourcePosition position)
Executes the Operator with operator overrides.
Implements the Divide Expression.
static IEnumerable< BadObject > DivWithOverride(BadExecutionContext? context, BadObject left, BadObject right, BadSourcePosition position)
Executes the Operator with operator overrides.
static BadObject Div(BadObject left, BadObject right, BadSourcePosition pos)
Divides left by right.
Implements the Exponentiation Expression.
static BadObject Exp(BadObject left, BadObject right, BadSourcePosition position)
Implements the logic of the Exponentiation Operator.
static IEnumerable< BadObject > ExpWithOverride(BadExecutionContext? context, BadObject left, BadObject right, BadSourcePosition position)
Runs the Exponentiation Operator on the given objects.
Implements the Modulus Expression.
static BadObject Mod(BadObject left, BadObject right, BadSourcePosition pos)
Performs the Modulus Operation on left and right.
static IEnumerable< BadObject > ModWithOverride(BadExecutionContext? context, BadObject left, BadObject right, BadSourcePosition position)
Executes the Operator with operator overrides.
Implements the Multiply Expression.
static IEnumerable< BadObject > MulWithOverride(BadExecutionContext? context, BadObject left, BadObject right, BadSourcePosition position)
Executes the Operator with operator overrides.
static BadObject Mul(BadObject left, BadObject right, BadSourcePosition pos)
Performs the Multiplication Operation on left and right.
Implements the Negation Expression.
static IEnumerable< BadObject > NegateWithOverride(BadExecutionContext? context, BadObject left, BadSourcePosition position)
Executes the Operator.
static BadObject Negate(BadObject obj, BadSourcePosition pos)
Executes the Operator.
Implements the Subtract Expression.
static BadObject Sub(BadObject left, BadObject right, BadSourcePosition pos)
Performs the Subtraction Operation on left and right.
static IEnumerable< BadObject > SubWithOverride(BadExecutionContext? context, BadObject left, BadObject right, BadSourcePosition position)
Executes the Operator with operator overrides.
Implements the Using Block Expression.
static void Finalize(BadExecutionContext usingContext, string name, BadSourcePosition position)
The Finalizer method of the Using Expression.
The Lock List that is used to store all locks.
static readonly BadLockList Instance
Instance of the Lock List.
bool TryAquire(BadObject lockObj)
Tries to aquire a lock on the given object.
void Release(BadObject lockObj)
Releases the lock on the given object.
Implements the Invocation Expression.
static IEnumerable< BadObject > Invoke(BadObject left, IEnumerable< BadObject > args, BadSourcePosition position, BadExecutionContext context)
Invokes a function.
A Import Expression that is used to import a module from a specified path.
static IEnumerable< BadObject > Import(BadExecutionContext ctx, string name, string path)
Imports a module from the specified path and assigns it to the specified name.
Implements the New Expression.
static IEnumerable< BadObject > CreateObject(BadClassPrototype proto, BadExecutionContext context, BadObject[] args, BadSourcePosition pos)
Creates an Instance of the Specified Class prototype.
The Execution Context. Every execution of a script needs a context the script is running in....
IEnumerable< BadObject > Execute(IEnumerable< BadExpression > expressions)
Executes an enumeration of expressions.
BadScope Scope
The Root Scope of the Context.
void Dispose()
Disposes the context.
BadScope CreateChild(string name, BadScope? caller, bool? useVisibility, BadScopeFlags flags=BadScopeFlags.RootScope)
Creates a subscope of the current scope.
BadScopeFlags Flags
The Scope Flags.
bool IsContinue
Is true if the Continue Keyword was set.
BadObjectReference GetVariable(string name, BadScope caller)
Returns the variable reference of the specified variable.
BadTable GetTable()
Returns the Variable Table of the current scope.
void SetContinue()
Sets the continue keyword inside this scope.
bool IsBreak
Is true if the Break Keyword was set.
string GetStackTrace()
Returns the Stack Trace of the Current scope.
void SetExports(BadExecutionContext ctx, BadObject exports)
void AddExport(string key, BadObject value)
Sets an exported key value pair in the scope.
BadObject? ReturnValue
The Return value of the scope.
void SetReturnValue(BadObject? value)
Sets the Return value of this scope.
void SetBreak()
Sets the break keyword inside this scope.
void AddFinalizer(Action finalizer)
Adds a Finalizer to the Scope.
void DefineVariable(string name, BadObject value, BadScope? caller=null, BadPropertyInfo? info=null, BadObject[]? attributes=null)
Defines a new Variable in the current scope.
BadFunction? FunctionObject
The Function Object of the Scope.
Gets thrown if the runtime encounters an error.
Implements the Error Object Type.
static BadRuntimeError FromException(Exception e, string? scriptStackTrace=null)
Creates a BadRuntimeError from an Exception.
Gets thrown by the runtime.
static BadRuntimeException Create(BadScope? scope, string message)
Creates a new BadScriptException.
Implements a simple wrapper for C# IEnumerators to be used in BS2.
Implements a Dynamic List/Array for the BadScript Language.
The Base Class for all BadScript Objects.
virtual BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.
BadClassPrototype GetPrototype()
Returns the Prototype of this Object.
virtual bool HasProperty(string propName, BadScope? caller=null)
Returns true if the object contains a given property or there exists an extension for the current Ins...
static readonly BadObject Null
The Null Value for the BadScript Language.
Implements the base functionality for a BadScript Reference.
void Set(BadObject obj, BadPropertyInfo? info=null, bool noChangeEvent=false)
Sets the Referenced Object to a new Value.
Stores Meta Information about a Property.
Implements a Table Structure for the BadScript Language.
The Any Prototype, Base type for all types.
static readonly BadAnyPrototype Instance
The Instance of the BadAnyPrototype.
Implements a Type Instance in the BadScript Language.
Implements a Class Prototype for the BadScript Language.
The Void Prototype, can be assigned to nothing, can not be inherited from, can not be instantiated....
static BadVoidPrototype Instance
The Instance of the BadVoidPrototype.
Implements a Compiled Function.
BadExecutionContext CreateExecutionContext(BadExecutionContext caller, BadObject[] args)
Implements a Virtual Machine for the BadScript Language.
readonly Stack< BadObject > m_ArgumentStack
The Argument Stack.
readonly bool m_UseOverrides
Indicates if the Virtual Machine should use Operator Overrides.
readonly BadInstruction[] m_Instructions
The Instructions.
readonly BadCompiledFunction m_Function
The Function that is executed by this Virtual Machine.
readonly Stack< BadRuntimeVirtualStackFrame > m_ContextStack
The Context Stack.
IEnumerable< BadObject > ExecuteStep(BadExecutionContext ctx)
IEnumerable< BadObject > Execute()
Executes the Virtual Machine.
IEnumerable< BadObject > Execute(BadExecutionContext ctx)
Executes the virtual machine with the given context.
BadRuntimeVirtualMachine(BadCompiledFunction function, BadInstruction[] instructions, bool useOverrides=true)
Creates a new BadRuntimeVirtualMachine instance.
int m_InstructionPointer
The Current Instruction Pointer.
Stores the current execution state of the Virtual Machine.
int ThrowPointer
The current throw instruction pointer.
int BreakPointer
The current break instruction pointer.
readonly BadExecutionContext Context
The current execution context.
int ContinuePointer
The current continue instruction pointer.
int ReturnPointer
The Return Pointer.
Implements the Interface for Native Boolean.
new bool Value
The Boolean Value.
Implements the Interface for Native Numbers.
Implements the Interface for Native Strings.
Represents a Generic Object.
Contains the debugging abstractions for the BadScript2 Runtime.
Contains the Access Expressions for the BadScript2 Language.
Contains the Comparison Expressions for the BadScript2 Language.
Contains the Logic Expressions for the BadScript2 Language.
Contains the Self-Assigning Math Expressions for the BadScript2 Language.
Contains the Atomic Math Expressions for the BadScript2 Language.
Contains the Math Expressions for the BadScript2 Language.
Contains the Binary Expressions for the BadScript2 Language.
Contains the Locking Expressions for the BadScript2 Language.
Contains the Block Expressions for the BadScript2 Language.
Contains the Function Expressions for the BadScript2 Language.
Contains the Type Expressions for the BadScript2 Language.
Contains the Expressions for the BadScript2 Language.
Contains the Error Objects for the BadScript2 Language.
Contains the Interop Abstractions and Implementations for the BadScript2 Language.
Contains the Native Runtime Objects.
Contains Runtime Interface Objects.
Contains Runtime Type Objects.
Contains the Runtime Objects.
Contains the Virtual Machine Implementation.
BadOpCode
Defines the Operations that the BadVirtualMachine can execute.
BadScopeFlags
Defines Different Behaviours for the Current Scope.
Represents a Debugging Step.
Implements a single instruction for the BadVirtualMachine.
readonly object[] Arguments
The arguments of this Instruction.
readonly BadSourcePosition Position
The position of this Instruction in the source code.
readonly BadOpCode OpCode
The OpCode of this Instruction.