Table of Contents

Class Context

Namespace
EzrSquared.Runtime
Assembly
ezrSquared-lib.dll

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

public class Context
Inheritance
object
Context

Constructors

Context(string, bool, Position, Context?, Context?, int)

Creates a new Context.

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

Parameters

name string

The name of the Context.

isStatic bool

Is this a static Context?

startPosition Position

The starting Position of the Context.

parent Context

The parent of this Context. Can be null.

staticContext Context

The static Context in relation to this Context. Can be null.

linkedContexts int

The number of other Contexts which are linked to this. See LinkedContexts.

Exceptions

ArgumentException

Raised 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.

Fields

Empty

An empty context.

public static readonly Context Empty

Field Value

Context

Id

The unique identifier of the Context.

public readonly long Id

Field Value

long

IsStatic

Is this a static Context?

public readonly bool IsStatic

Field Value

bool

Name

The name of the Context.

public readonly string Name

Field Value

string

_symbols

The symbols of this Context.

private Dictionary<string, Reference> _symbols

Field Value

Dictionary<string, Reference>

Properties

Count

The number of symbols in the context.

public int Count { get; }

Property Value

int

LinkedContexts

Other Contexts which are linked to this.

public Context[] LinkedContexts { get; private set; }

Property Value

Context[]

Remarks

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

Parent

The parent of this Context. May be null.

public Context? Parent { get; private set; }

Property Value

Context

StartPosition

The starting Position of the Context.

public Position StartPosition { get; private set; }

Property Value

Position

StaticContext

The static Context in relation to this Context. May be null.

public Context? StaticContext { get; private set; }

Property Value

Context

Methods

DeepCopy(RuntimeResult, IEzrObject[])

Creates a deep copy of the context.

public Context? DeepCopy(RuntimeResult result, IEzrObject[] excludedSymbols)

Parameters

result RuntimeResult

Runtime result for raising errors/

excludedSymbols IEzrObject[]

Symbols to exclude when copying.

Returns

Context

The copy, or, null if failed.

Remarks

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

~Context()

Destructor.

protected ~Context()

Get(Context?, string, out Reference, AccessMod, bool)

Retrieves the Reference of the requested symbol.

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

Parameters

callingContext Context

The Context from which the operation is being called.

symbol string

The symbol to retrieve.

objectReference Reference

The resulting Reference.

accessibilityModifiers AccessMod

Accessibility modifiers of the operation, None by default.

ignoreLinkedContexts bool

Should the Context ignore its linked contexts? (Used mainly for retrieving a reference before symbol assignment)

Returns

Context.GetStatus

The Context.GetStatus, representing the result of the operation.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<KeyValuePair<string, Reference>> GetEnumerator()

Returns

IEnumerator<KeyValuePair<string, Reference>>

An enumerator that can be used to iterate through the collection.

IsContextParent(Context)

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

private bool IsContextParent(Context context)

Parameters

context Context

The Context to check.

Returns

bool

true if it is, false otherwise.

IsDefined(string)

Checks if a symbol has been defined in this Context/

public bool IsDefined(string name)

Parameters

name string

The name of the symbol to check.

Returns

bool

true if it is, false otherwise.

Release()

Releases all references in the context and clears the symbols dictionary.

public void Release()

Set(Context?, string, Reference)

Sets the Reference to a new symbol.

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

Parameters

callingContext Context

The Context from which the operation is being called.

symbol string

The symbol to assign.

objectReference Reference

The reference to assign to the symbol.

Returns

Context.SetStatus

The Context.SetStatus, representing the result of the operation.

Set(Context?, (IEzrObject Object, string Name), Reference, AccessMod)

Sets a new IEzrObject to an existing Reference.

public (Context.SetStatus, Reference) Set(Context? callingContext, (IEzrObject Object, string Name) newObject, Reference oldReference, AccessMod accessibilityModifiers = AccessMod.None)

Parameters

callingContext Context

The Context from which the operation is being called.

newObject (IEzrObject Object, string Name)

The new IEzrObject to be assigned and the name of the symbol, in the format (IEzrObject Object, string Name).

oldReference Reference

The old reference to assign to.

accessibilityModifiers AccessMod

Accessibility modifiers of the operation, None by default.

Returns

(Context.SetStatus, Reference)

The Context.SetStatus, representing the result of the operation, and the reference to the set symbol.

Remarks

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

SetNewLinkedContexts(int)

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

public void SetNewLinkedContexts(int contexts)

Parameters

contexts int

The number of Contexts to allocate the System.Array for.

UpdateParent(Context)

Updates the parent of this Context/

public void UpdateParent(Context newParent)

Parameters

newParent Context

The new parent Context.

UpdatePosition(Position)

Updates the starting Position of this Context/

public void UpdatePosition(Position startPosition)

Parameters

startPosition Position

The new starting Position.

UpdateStaticContext(Context?)

Updates the StaticContext to a new one.

public void UpdateStaticContext(Context? newStaticContext)

Parameters

newStaticContext Context

The new static Context.