The ezr² Project 0.1.1
The codebase for the ezr² programming language.
Loading...
Searching...
No Matches
EzrSquared.Runtime.Context Class Reference

Stores all user defined variables/constant references, called symbols. More...

Public Types

enum  GetStatus {
  Ok , UndefinedSymbolAccessNotAllowed , AccessToPrivateSymbolNotAllowed , StaticAccessWithoutDefinedContextNotAllowed ,
  InvalidGlobalPrivateAccessNotAllowed
}
 Represents the status of a Get(Context?, string, out Reference, AccessMod, bool) call. More...
 
enum  SetStatus {
  Ok , ConstantAssignmentNotAllowed , PrivateSymbolAssignmentNotAllowed , SymbolAccessibilityChangeInParentNotAllowed ,
  PrivateSymbolAssignmentInChildNotAllowed , UnregisteredSymbolScopeOrVariabilityChangeNotAllowed , StaticAssignmentWithoutDefinedContextNotAllowed , InvalidGlobalPrivateAssignmentNotAllowed
}
 Represents the status of a set call. More...
 

Public Member Functions

 Context (string name, bool isStatic, Position startPosition, Context? parent=null, Context? staticContext=null, int linkedContexts=0)
 Creates a new Context.
 
void SetNewLinkedContexts (int contexts)
 Clears the existing LinkedContexts and creates a new empty Array of Contexts.
 
void UpdateStaticContext (Context? newStaticContext)
 Updates the StaticContext to a new one.
 
void UpdateParent (Context newParent)
 Updates the parent of this Context/.
 
void UpdatePosition (Position startPosition)
 Updates the starting Position of this Context/.
 
GetStatus Get (Context? callingContext, string symbol, out Reference objectReference, AccessMod accessibilityModifiers=AccessMod.None, bool ignoreLinkedContexts=false)
 Retrieves the Reference of the requested symbol.
 
Reference Set (Context? callingContext,(IEzrObject Object, string Name) newObject, Reference oldReference, AccessMod accessibilityModifiers=AccessMod.None)
 
SetStatus Set (Context? callingContext, string symbol, Reference objectReference)
 Sets the Reference to a new symbol.
 
bool IsDefined (string name)
 Checks if a symbol has been defined in this Context/.
 
ContextDeepCopy (RuntimeResult result, IEzrObject[] excludedSymbols)
 Creates a deep copy of the context.
 
void Release ()
 Releases all references in the context and clears the symbols dictionary.
 

Public Attributes

readonly string Name
 The name of the Context.
 
readonly long Id
 The unique identifier of the Context.
 
readonly bool IsStatic
 Is this a static Context?
 

Static Public Attributes

static readonly Context Empty = new(string.Empty, false, Position.None)
 An empty context.
 

Properties

int Count [get]
 The number of symbols in the context.
 
Position StartPosition [get, private set]
 The starting Position of the Context.
 
Context[] LinkedContexts [get, private set]
 Other Contexts which are linked to this.
 
ContextParent [get, private set]
 The parent of this Context. May be null.
 
ContextStaticContext [get, private set]
 The static Context in relation to this Context. May be null.
 

Private Member Functions

bool IsContextParent (Context context)
 Checks if the given Context is a parent of this Context.
 
 ~Context ()
 Destructor.
 

Private Attributes

Dictionary< string, Reference > _symbols
 The symbols of this Context.
 

Detailed Description

Stores all user defined variables/constant references, called symbols.

Member Enumeration Documentation

◆ GetStatus

Represents the status of a Get(Context?, string, out Reference, AccessMod, bool) call.

Enumerator
Ok 

The operation was successful.

UndefinedSymbolAccessNotAllowed 

The requested symbol was not found.

AccessToPrivateSymbolNotAllowed 

Accessing privates symbols from Contexts without permission is not allowed.

StaticAccessWithoutDefinedContextNotAllowed 

Cannot access static symbols without a known static Context.

InvalidGlobalPrivateAccessNotAllowed 

Cannot access symbols with both AccessMod.Global and AccessMod.Private accessibility modifiers.

◆ SetStatus

Represents the status of a set call.

Sets a new IEzrObject to an existing Reference.

This includes both Set(Context?, string, Reference) and Set(Context?, ValueTuple<IEzrObject, string>, Reference, AccessMod).

If oldReference is Reference.Empty, the operation is passed onto Set(Context?, string, Reference).

Parameters
callingContextThe Context from which the operation is being called.
newObjectThe new IEzrObject to be assigned and the name of the symbol, in the format (IEzrObject Object, string Name).
oldReferenceThe old reference to assign to.
accessibilityModifiersAccessibility modifiers of the operation, AccessMod.None by default.
Returns
The SetStatus, representing the result of the operation.
Enumerator
Ok 

The operation was successful.

ConstantAssignmentNotAllowed 

Assigning new values to a constant reference is not allowed.

PrivateSymbolAssignmentNotAllowed 

Assigning privates symbols from Contexts without permission is not allowed.

SymbolAccessibilityChangeInParentNotAllowed 

Changing the accessibility of an existing symbol in a parent Context is not allowed.

PrivateSymbolAssignmentInChildNotAllowed 

Assigning a private symbol to a child Context is not allowed.

UnregisteredSymbolScopeOrVariabilityChangeNotAllowed 

Changing the accessibility of a symbol which has not been assigned to a Context is not allowed.

StaticAssignmentWithoutDefinedContextNotAllowed 

Assigning static symbols without a known static Context is not allowed.

InvalidGlobalPrivateAssignmentNotAllowed 

Cannot assign symbols with both AccessMod.Global and AccessMod.Private accessibility modifiers.

Constructor & Destructor Documentation

◆ Context()

EzrSquared.Runtime.Context.Context ( string name,
bool isStatic,
Position startPosition,
Context? parent = null,
Context? staticContext = null,
int linkedContexts = 0 )

Creates a new Context.

Parameters
nameThe name of the Context.
isStaticIs this a static Context?
startPositionThe starting Position of the Context.
parentThe parent of this Context. Can be null.
staticContextThe static Context in relation to this Context. Can be null.
linkedContextsThe number of other Contexts which are linked to this. See
See also
LinkedContexts
.
Exceptions
ArgumentExceptionRaised if isStatic is true and a static Context as staticContext was provided at the same time. This is invalid as a Context can either be static or have a static Context related to it, but not both.

Member Function Documentation

◆ DeepCopy()

Context? EzrSquared.Runtime.Context.DeepCopy ( RuntimeResult result,
IEzrObject[] excludedSymbols )

Creates a deep copy of the context.

It is the caller's responsibility to handle linked contexts.

Parameters
resultRuntime result for raising errors/
excludedSymbolsSymbols to exclude when copying.
Returns
The copy, or, null if failed.

◆ Get()

GetStatus EzrSquared.Runtime.Context.Get ( Context? callingContext,
string symbol,
out Reference objectReference,
AccessMod accessibilityModifiers = AccessMod::None,
bool ignoreLinkedContexts = false )

Retrieves the Reference of the requested symbol.

Parameters
callingContextThe Context from which the operation is being called.
symbolThe symbol to retrieve.
objectReferenceThe resulting Reference.
accessibilityModifiersAccessibility modifiers of the operation, AccessMod.None by default.
ignoreLinkedContextsShould the Context ignore its linked contexts? (Used mainly for retrieving a reference before symbol assignment)
Returns
The GetStatus, representing the result of the operation.

◆ IsContextParent()

bool EzrSquared.Runtime.Context.IsContextParent ( Context context)
private

Checks if the given Context is a parent of this Context.

Parameters
contextThe Context to check.
Returns
true if it is, false otherwise.

◆ IsDefined()

bool EzrSquared.Runtime.Context.IsDefined ( string name)

Checks if a symbol has been defined in this Context/.

Parameters
nameThe name of the symbol to check.
Returns
true if it is, false otherwise.

◆ Set()

SetStatus EzrSquared.Runtime.Context.Set ( Context? callingContext,
string symbol,
Reference objectReference )

Sets the Reference to a new symbol.

Parameters
callingContextThe Context from which the operation is being called.
symbolThe symbol to assign.
objectReferenceThe reference to assign to the symbol.
Returns
The SetStatus, representing the result of the operation.

◆ SetNewLinkedContexts()

void EzrSquared.Runtime.Context.SetNewLinkedContexts ( int contexts)

Clears the existing LinkedContexts and creates a new empty Array of Contexts.

Parameters
contextsThe number of Contexts to allocate the Array for.

◆ UpdateParent()

void EzrSquared.Runtime.Context.UpdateParent ( Context newParent)

Updates the parent of this Context/.

Parameters
newParentThe new parent Context.

◆ UpdatePosition()

void EzrSquared.Runtime.Context.UpdatePosition ( Position startPosition)

Updates the starting Position of this Context/.

Parameters
startPositionThe new starting Position.

◆ UpdateStaticContext()

void EzrSquared.Runtime.Context.UpdateStaticContext ( Context? newStaticContext)

Updates the StaticContext to a new one.

Parameters
newStaticContextThe new static Context.

Property Documentation

◆ LinkedContexts

Context [] EzrSquared.Runtime.Context.LinkedContexts
getprivate set

Other Contexts which are linked to this.

This allowed the Interpreter to access variables from multiple Contexts while in a local scope.


The documentation for this class was generated from the following file: