C# Класс kOS.Safe.Execution.CPU

Наследование: ICpu
Показать файл Открыть проект

Открытые методы

Метод Описание
AddTrigger ( int triggerFunctionPointer ) : void
AddVariable ( kOS.Safe.Execution.Variable variable, string identifier, bool local, bool overwrite = false ) : void

Make a new variable at either the local depth or the global depth depending. throws exception if it already exists as a boundvariable at the desired scope level, unless overwrite = true.

AssertValidDelegateCall ( IUserDelegate userDelegate ) : void

Throw exception if the user delegate is not one the CPU can call right now.

Boot ( ) : void
BreakExecution ( bool manual ) : void
BuiltInExists ( string functionName ) : bool
CPU ( SafeSharedObjects shared ) : System
CallBuiltinFunction ( string functionName ) : void
Dispose ( ) : void
DumpStack ( ) : string
DumpVariables ( ) : string
GetCallTrace ( ) : List

Return the subroutine call trace of how the code got to where it is right now.

GetCodeFragment ( int contextLines ) : List
GetCurrentClosure ( ) : List

Build a clone of the current state of the scope stack, for the sake of capturing a closure.

GetCurrentOpcode ( ) : Opcode
GetInterpreterContext ( ) : IProgramContext
GetOpcodeAt ( int instructionPtr ) : Opcode
GetStackSize ( ) : int
GetStructureEncapsulated ( Structure testValue, bool barewordOkay = false ) : Structure

Identical to GetValue(), except that it guarantees the return value is either already a Structure, or it converts it into a Structure if it's a primitive. It bombs out with an exception if it can't be converted thusly.
Use this in places where the stack value *must* come out as an encapsulated value and something has gone seriously wrong if it can't. This applies to cases where you are attempting to store its value inside another user's variable, mostly.
Hypothetically this should never really be required, as the value is coming FROM a user varible in the first place.

GetValue ( object testValue, bool barewordOkay = false ) : object

Given a value which may or may not be a variable name, return the value back. If it's not a variable, return it as-is. If it's a variable, look it up and return that.

IdentifierExistsInScope ( string identifier ) : bool

Test if an identifier is a variable you can get the value of at the moment (var name exists and is in scope). Return true if you can, false if you can't.

KOSFixedUpdate ( double deltaTime ) : void
MakeUserDelegate ( int entryPoint, bool withClosure ) : IUserDelegate

Build a delegate call for the given function entry point, in which it will capture a closure of the current runtime scoping state to be used when that function gets called later by OpcodeCall:

MoveStackPointer ( int delta ) : void
PeekRaw ( int digDepth, bool &checkOkay ) : object

Peek at a value atop the stack without popping it, and without evaluating it to get the variable's value. (i.e. if the thing in the stack is $foo, and the variable foo has value 5, you'll get the string "$foo" returned, not the integer 5).

PeekStructureEncapsulated ( int digDepth, bool barewordOkay = false ) : Structure

Identical to PeekValue(), except that it guarantees the return value is either already a Structure, or it converts it into a Structure if it's a primitive. It bombs out with an exception if it can't be converted thusly.
Use this in places where the stack value *must* come out as an encapsulated value and something has gone seriously wrong if it can't. This applies to cases where you are attempting to store its value inside a user's variable, mostly.

PeekValue ( int digDepth, bool barewordOkay = false ) : object

Peek at a value atop the stack without popping it, and if it's a variable name then get its value, else just return it as it is.

NOTE: Evaluating variables when you don't really need to is pointlessly expensive, as it needs to walk the scoping stack to exhaust a search. If you don't need to evaluate variables, then consider using PeekRaw() instead.

PeekValueEncapsulated ( int digDepth, bool barewordOkay = false ) : object

Identical to PeekStructureEncapsulated(), except that it doesn't complain if the result can't be converted to a Structure. It's acceptable for it to not be a Structure, in which case the original object is returned as-is.
Use this in places where the stack value *should* come out as an encapsulated value if it can, but there are some valid cases where it might not be.

PopAboveStack ( int howMany ) : object

Pop one or more things from the secret "over" stack, only returning the finalmost thing popped. (i.e if you pop 3 things then you get: pop once and throw away, pop again and throw away, pop again and return the popped thing.)

PopStack ( ) : object
PopStructureEncapsulated ( bool barewordOkay = false ) : Structure

Identical to PopValue(), except that it guarantees the return value is either already a Structure, or it converts it into a Structure if it's a primitive. It bombs out with an exception if it can't be converted thusly.
Use this in places where the stack value *must* come out as an encapsulated value and something has gone seriously wrong if it can't. This applies to cases where you are attempting to store its value inside a user's variable, mostly.

PopValue ( bool barewordOkay = false ) : object

Pop a value off the stack, and if it's a variable name then get its value, else just return it as it is.

PopValueEncapsulated ( bool barewordOkay = false ) : object

Identical to PopStructureEncapsulated(), except that it doesn't complain if the result can't be converted to a Structure. It's acceptable for it to not be a Structure, in which case the original object is returned as-is.
Use this in places where the stack value *should* come out as an encapsulated value if it can, but there are some valid cases where it might not be.

PushAboveStack ( object thing ) : void

Push a single thing onto the secret "over" stack.

PushStack ( object item ) : void
RemoveTrigger ( int triggerFunctionPointer ) : void
RemoveVariable ( string identifier ) : void

Removes a variable, following current scoping rules, removing the innermost scope of the variable that is found.

If the variable cannot be found, it fails silently without complaint.

ResetStatistics ( ) : void
RunProgram ( List program ) : void
RunProgram ( List program, bool silent ) : void
SelectAutopilotMode ( string autopilotMode ) : void
SetGlobal ( string identifier, object value ) : void

Make a new global variable at the localmost scoping level and give it a starting value, or overwrite an existing variable at the localmost level with a starting value.

This does NOT scan up the scoping stack like SetValue() does. It operates at the global level only.

SetNewLocal ( string identifier, object value ) : void

Try to make a new local variable at the localmost scoping level and give it a starting value. It errors out of there is already one there by the same name.

This does NOT scan up the scoping stack like SetValue() does. It operates at the local level only.

This is the normal way to make a new local variable. You cannot make a local variable without attempting to give it a value.

SetValue ( string identifier, object value ) : void

Try to set the value of the identifier at the localmost level possible, by scanning up the scope stack to find the local-most level at which the identifier is a variable, and assigning it the value there.

If no such value is found, all the way up to the global level, then it resorts to making a global variable with the name and using that.

This is the normal way to make a new global variable. You cannot make a global variable without attempting to give it a value.

SetValueExists ( string identifier, object value ) : void

Try to set the value of the identifier at the localmost level possible, by scanning up the scope stack to find the local-most level at which the identifier is a variable, and assigning it the value there.

If no such value is found, an error is thrown. It only stores into variables that already exist, refusing to create new variables.

StartCompileStopwatch ( ) : void
StatisticsDump ( bool doProfiling ) : string
StopCompileStopwatch ( ) : void
SwitchToProgramContext ( ) : IProgramContext
ToggleFlyByWire ( string paramName, bool enabled ) : void
VariableIsRemovable ( Variable variable ) : bool
YieldProgram ( YieldFinishedDetector yieldTracker ) : void

Call when you want to suspend execution of the Opcodes until some future condition becomes true. The CPU will call yieldTracker.Begin() right away, and then after that call yieldTracker.IsFinished() again and again until it returns true. Until IsFinished() returns true, the CPU will not advance any further into the program in its current "mode". Note that the CPU will track "trigger" and "mainline" code separately for this purpose. Waiting in mainline code will still allow triggers to run.

Приватные методы

Метод Описание
AbortAllYields ( ) : void
CalculateProfileResult ( ) : void
ContinueExecution ( bool doProfiling ) : void
ExecuteInstruction ( IProgramContext context, bool doProfiling ) : bool
GetNestedDictionary ( int peekDepth ) : VariableScope

Gets the dictionary N levels of nesting down the dictionary stack, where zero is the current localmost level. Never errors out or fails. If N is too large you just end up with the global scope dictionary. Does not allow the walk to go past the start of the current function scope.

GetNestedDictionary ( string identifier, List searchReport = null ) : VariableScope

Gets the dictionary that contains the given identifier, starting the search at the local level and scanning the scopes upward all the way to the global dictionary.
Does not allow the walk to use scope frames that were not directly in this scope's lexical chain. It skips over scope frames from other branches of the parse tree. (i.e. if a function calls a function elsewhere).
Returns null when no hit was found.

GetOrCreateVariable ( string identifier ) : Variable

Get the value of a variable or create it at global scope if not found.

GetVariable ( string identifier, bool barewordOkay = false, bool failOkay = false ) : Variable

Get the variable's contents, performing a lookup through all nesting levels up to global.

IsYielding ( ) : bool
PopContext ( ) : void
PopFirstContext ( ) : void
PostUpdateBindings ( ) : void
PreUpdateBindings ( ) : void
PrintStatistics ( ) : void
ProcessTriggers ( ) : void
PushContext ( ProgramContext context ) : void
PushInterpreterContext ( ) : void
RestorePointers ( ) : void
SaveAndClearPointers ( ) : void
SkipCurrentInstructionId ( ) : void

Описание методов

AddTrigger() публичный Метод

public AddTrigger ( int triggerFunctionPointer ) : void
triggerFunctionPointer int
Результат void

AddVariable() публичный Метод

Make a new variable at either the local depth or the global depth depending. throws exception if it already exists as a boundvariable at the desired scope level, unless overwrite = true.
public AddVariable ( kOS.Safe.Execution.Variable variable, string identifier, bool local, bool overwrite = false ) : void
variable kOS.Safe.Execution.Variable variable to add
identifier string name of variable to add
local bool true if you want to make it at local depth
overwrite bool true if it's okay to overwrite an existing variable
Результат void

AssertValidDelegateCall() публичный Метод

Throw exception if the user delegate is not one the CPU can call right now.
thrown if the cpu is in a state where it can't call this delegate.
public AssertValidDelegateCall ( IUserDelegate userDelegate ) : void
userDelegate IUserDelegate The userdelegate being checked
Результат void

Boot() публичный Метод

public Boot ( ) : void
Результат void

BreakExecution() публичный Метод

public BreakExecution ( bool manual ) : void
manual bool
Результат void

BuiltInExists() публичный Метод

public BuiltInExists ( string functionName ) : bool
functionName string
Результат bool

CPU() публичный Метод

public CPU ( SafeSharedObjects shared ) : System
shared SafeSharedObjects
Результат System

CallBuiltinFunction() публичный Метод

public CallBuiltinFunction ( string functionName ) : void
functionName string
Результат void

Dispose() публичный Метод

public Dispose ( ) : void
Результат void

DumpStack() публичный Метод

public DumpStack ( ) : string
Результат string

DumpVariables() публичный Метод

public DumpVariables ( ) : string
Результат string

GetCallTrace() публичный Метод

Return the subroutine call trace of how the code got to where it is right now.
public GetCallTrace ( ) : List
Результат List

GetCodeFragment() публичный Метод

public GetCodeFragment ( int contextLines ) : List
contextLines int
Результат List

GetCurrentClosure() публичный Метод

Build a clone of the current state of the scope stack, for the sake of capturing a closure.
public GetCurrentClosure ( ) : List
Результат List

GetCurrentOpcode() публичный Метод

public GetCurrentOpcode ( ) : Opcode
Результат kOS.Safe.Compilation.Opcode

GetInterpreterContext() публичный Метод

public GetInterpreterContext ( ) : IProgramContext
Результат IProgramContext

GetOpcodeAt() публичный Метод

public GetOpcodeAt ( int instructionPtr ) : Opcode
instructionPtr int
Результат Opcode

GetStackSize() публичный Метод

public GetStackSize ( ) : int
Результат int

GetStructureEncapsulated() публичный Метод

Identical to GetValue(), except that it guarantees the return value is either already a Structure, or it converts it into a Structure if it's a primitive. It bombs out with an exception if it can't be converted thusly.
Use this in places where the stack value *must* come out as an encapsulated value and something has gone seriously wrong if it can't. This applies to cases where you are attempting to store its value inside another user's variable, mostly.
Hypothetically this should never really be required, as the value is coming FROM a user varible in the first place.
public GetStructureEncapsulated ( Structure testValue, bool barewordOkay = false ) : Structure
testValue Structure the object which might be a variable name
barewordOkay bool /// Is this a case in which it's acceptable for the /// variable not to exist, and if it doesn't exist then the variable name itself /// is the value? ///
Результат Structure

GetValue() публичный Метод

Given a value which may or may not be a variable name, return the value back. If it's not a variable, return it as-is. If it's a variable, look it up and return that.
public GetValue ( object testValue, bool barewordOkay = false ) : object
testValue object the object which might be a variable name
barewordOkay bool /// Is this a case in which it's acceptable for the /// variable not to exist, and if it doesn't exist then the variable name itself /// is the value? ///
Результат object

IdentifierExistsInScope() публичный Метод

Test if an identifier is a variable you can get the value of at the moment (var name exists and is in scope). Return true if you can, false if you can't.
public IdentifierExistsInScope ( string identifier ) : bool
identifier string
Результат bool

KOSFixedUpdate() публичный Метод

public KOSFixedUpdate ( double deltaTime ) : void
deltaTime double
Результат void

MakeUserDelegate() публичный Метод

Build a delegate call for the given function entry point, in which it will capture a closure of the current runtime scoping state to be used when that function gets called later by OpcodeCall:
public MakeUserDelegate ( int entryPoint, bool withClosure ) : IUserDelegate
entryPoint int Integer location in memory to jump to to start the call
withClosure bool Should the closure be captured for this delegate or ignored
Результат IUserDelegate

MoveStackPointer() публичный Метод

public MoveStackPointer ( int delta ) : void
delta int
Результат void

PeekRaw() публичный Метод

Peek at a value atop the stack without popping it, and without evaluating it to get the variable's value. (i.e. if the thing in the stack is $foo, and the variable foo has value 5, you'll get the string "$foo" returned, not the integer 5).
public PeekRaw ( int digDepth, bool &checkOkay ) : object
digDepth int Peek at the element this far down the stack (0 means top, 1 means just under the top, etc)
checkOkay bool Tells you whether or not the stack was exhausted. If it's false, then the peek went too deep.
Результат object

PeekStructureEncapsulated() публичный Метод

Identical to PeekValue(), except that it guarantees the return value is either already a Structure, or it converts it into a Structure if it's a primitive. It bombs out with an exception if it can't be converted thusly.
Use this in places where the stack value *must* come out as an encapsulated value and something has gone seriously wrong if it can't. This applies to cases where you are attempting to store its value inside a user's variable, mostly.
public PeekStructureEncapsulated ( int digDepth, bool barewordOkay = false ) : Structure
digDepth int Peek at the element this far down the stack (0 means top, 1 means just under the top, etc)
barewordOkay bool Is this a context in which it's acceptable for /// a variable not existing error to occur (in which case the identifier itself /// should therefore become a string object returned)?
Результат Structure

PeekValue() публичный Метод

Peek at a value atop the stack without popping it, and if it's a variable name then get its value, else just return it as it is.

NOTE: Evaluating variables when you don't really need to is pointlessly expensive, as it needs to walk the scoping stack to exhaust a search. If you don't need to evaluate variables, then consider using PeekRaw() instead.
public PeekValue ( int digDepth, bool barewordOkay = false ) : object
digDepth int Peek at the element this far down the stack (0 means top, 1 means just under the top, etc)
barewordOkay bool Is this a context in which it's acceptable for /// a variable not existing error to occur (in which case the identifier itself /// should therefore become a string object returned)?
Результат object

PeekValueEncapsulated() публичный Метод

Identical to PeekStructureEncapsulated(), except that it doesn't complain if the result can't be converted to a Structure. It's acceptable for it to not be a Structure, in which case the original object is returned as-is.
Use this in places where the stack value *should* come out as an encapsulated value if it can, but there are some valid cases where it might not be.
public PeekValueEncapsulated ( int digDepth, bool barewordOkay = false ) : object
digDepth int Peek at the element this far down the stack (0 means top, 1 means just under the top, etc)
barewordOkay bool Is this a context in which it's acceptable for /// a variable not existing error to occur (in which case the identifier itself /// should therefore become a string object returned)?
Результат object

PopAboveStack() публичный Метод

Pop one or more things from the secret "over" stack, only returning the finalmost thing popped. (i.e if you pop 3 things then you get: pop once and throw away, pop again and throw away, pop again and return the popped thing.)
public PopAboveStack ( int howMany ) : object
howMany int
Результат object

PopStack() публичный Метод

public PopStack ( ) : object
Результат object

PopStructureEncapsulated() публичный Метод

Identical to PopValue(), except that it guarantees the return value is either already a Structure, or it converts it into a Structure if it's a primitive. It bombs out with an exception if it can't be converted thusly.
Use this in places where the stack value *must* come out as an encapsulated value and something has gone seriously wrong if it can't. This applies to cases where you are attempting to store its value inside a user's variable, mostly.
public PopStructureEncapsulated ( bool barewordOkay = false ) : Structure
barewordOkay bool Is this a context in which it's acceptable for /// a variable not existing error to occur (in which case the identifier itself /// should therefore become a string object returned)?
Результат Structure

PopValue() публичный Метод

Pop a value off the stack, and if it's a variable name then get its value, else just return it as it is.
public PopValue ( bool barewordOkay = false ) : object
barewordOkay bool Is this a context in which it's acceptable for /// a variable not existing error to occur (in which case the identifier itself /// should therefore become a string object returned)?
Результат object

PopValueEncapsulated() публичный Метод

Identical to PopStructureEncapsulated(), except that it doesn't complain if the result can't be converted to a Structure. It's acceptable for it to not be a Structure, in which case the original object is returned as-is.
Use this in places where the stack value *should* come out as an encapsulated value if it can, but there are some valid cases where it might not be.
public PopValueEncapsulated ( bool barewordOkay = false ) : object
barewordOkay bool Is this a context in which it's acceptable for /// a variable not existing error to occur (in which case the identifier itself /// should therefore become a string object returned)?
Результат object

PushAboveStack() публичный Метод

Push a single thing onto the secret "over" stack.
public PushAboveStack ( object thing ) : void
thing object
Результат void

PushStack() публичный Метод

public PushStack ( object item ) : void
item object
Результат void

RemoveTrigger() публичный Метод

public RemoveTrigger ( int triggerFunctionPointer ) : void
triggerFunctionPointer int
Результат void

RemoveVariable() публичный Метод

Removes a variable, following current scoping rules, removing the innermost scope of the variable that is found.

If the variable cannot be found, it fails silently without complaint.
public RemoveVariable ( string identifier ) : void
identifier string varible to remove.
Результат void

ResetStatistics() публичный Метод

public ResetStatistics ( ) : void
Результат void

RunProgram() публичный Метод

public RunProgram ( List program ) : void
program List
Результат void

RunProgram() публичный Метод

public RunProgram ( List program, bool silent ) : void
program List
silent bool
Результат void

SelectAutopilotMode() публичный Метод

public SelectAutopilotMode ( string autopilotMode ) : void
autopilotMode string
Результат void

SetGlobal() публичный Метод

Make a new global variable at the localmost scoping level and give it a starting value, or overwrite an existing variable at the localmost level with a starting value.

This does NOT scan up the scoping stack like SetValue() does. It operates at the global level only.
public SetGlobal ( string identifier, object value ) : void
identifier string variable name to attempt to store into
value object value to put into it
Результат void

SetNewLocal() публичный Метод

Try to make a new local variable at the localmost scoping level and give it a starting value. It errors out of there is already one there by the same name.

This does NOT scan up the scoping stack like SetValue() does. It operates at the local level only.

This is the normal way to make a new local variable. You cannot make a local variable without attempting to give it a value.
public SetNewLocal ( string identifier, object value ) : void
identifier string variable name to attempt to store into
value object value to put into it
Результат void

SetValue() публичный Метод

Try to set the value of the identifier at the localmost level possible, by scanning up the scope stack to find the local-most level at which the identifier is a variable, and assigning it the value there.

If no such value is found, all the way up to the global level, then it resorts to making a global variable with the name and using that.

This is the normal way to make a new global variable. You cannot make a global variable without attempting to give it a value.
public SetValue ( string identifier, object value ) : void
identifier string variable name to attempt to store into
value object value to put into it
Результат void

SetValueExists() публичный Метод

Try to set the value of the identifier at the localmost level possible, by scanning up the scope stack to find the local-most level at which the identifier is a variable, and assigning it the value there.

If no such value is found, an error is thrown. It only stores into variables that already exist, refusing to create new variables.

public SetValueExists ( string identifier, object value ) : void
identifier string variable name to attempt to store into
value object value to put into it
Результат void

StartCompileStopwatch() публичный Метод

public StartCompileStopwatch ( ) : void
Результат void

StatisticsDump() публичный Метод

public StatisticsDump ( bool doProfiling ) : string
doProfiling bool
Результат string

StopCompileStopwatch() публичный Метод

public StopCompileStopwatch ( ) : void
Результат void

SwitchToProgramContext() публичный Метод

public SwitchToProgramContext ( ) : IProgramContext
Результат IProgramContext

ToggleFlyByWire() публичный Метод

public ToggleFlyByWire ( string paramName, bool enabled ) : void
paramName string
enabled bool
Результат void

VariableIsRemovable() публичный Метод

public VariableIsRemovable ( Variable variable ) : bool
variable Variable
Результат bool

YieldProgram() публичный Метод

Call when you want to suspend execution of the Opcodes until some future condition becomes true. The CPU will call yieldTracker.Begin() right away, and then after that call yieldTracker.IsFinished() again and again until it returns true. Until IsFinished() returns true, the CPU will not advance any further into the program in its current "mode". Note that the CPU will track "trigger" and "mainline" code separately for this purpose. Waiting in mainline code will still allow triggers to run.
public YieldProgram ( YieldFinishedDetector yieldTracker ) : void
yieldTracker YieldFinishedDetector
Результат void