class Ven::Machine

Included Modules

Defined in:

ven/machine.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(context : Ven::Suite::Context::Machine, chunks : Chunks, cp = 0) #

Initializes a Machine given some chunks, a context and a chunk pointer cp: in chunks, the chunk at cp will be the first to be executed.

Remember: per each frame there should always be a scope; if you push a frame, that is, you have to push a scope as well. This has to be done so the frames and the context scopes are in sync.


[View source]

Class Method Detail

def self.start(context, chunks, offset, &) #

Makes an instance of Machine given context, chunks and offset (see Machine). Yields this instance to the block.

After the block was executed, starts the Machine and returns the resulting value.


[View source]

Instance Method Detail

def binary(operator : String, left : Model, right : Model) #

Performs a binary operation on left, right.

Tries to normalize if left, right cannot be used with the operator.


[View source]
def context : Context::Machine #

[View source]
def defun(informer : VFunction, given : Models) #

Properly defines a function based off an informer and some given values.


[View source]
def die(message : String) #

Dies of runtime error with message, which should explain why the error happened.


[View source]
def field(head : Vec, field) #

If head, a vector, has a field field, returns the value of that field.

Otherwise, spreads the field access on the items of head. E.g., [1, 2, 3].a is [1.a, 2.a, 3.a]


[View source]
def field(head : Model, field : Model) #

Same as #field?, but dies if found no working field resolution.


[View source]
def field?(head : Model, field : Str) #

Resolves a field access.

Provides the 'callable?' field for any head, which calls Model.callable?.

If head has a field named field, returns the value of that field.

Otherwise, tries to construct a partial from a function called field, if it exists.

Returns nil if found no valid field resolution.


[View source]
def field?(head : Vec, field : MFunction) #

Resolves a field access.

Provides the 'callable?' field for any head, which calls Model.callable?.

If head has a field named field, returns the value of that field.

Otherwise, tries to construct a partial from a function called field, if it exists.

Returns nil if found no valid field resolution.


[View source]
def field?(head, field : MFunction) #

Resolves a field access.

Provides the 'callable?' field for any head, which calls Model.callable?.

If head has a field named field, returns the value of that field.

Otherwise, tries to construct a partial from a function called field, if it exists.

Returns nil if found no valid field resolution.


[View source]
def field?(head, field) #

Resolves a field access.

Provides the 'callable?' field for any head, which calls Model.callable?.

If head has a field named field, returns the value of that field.

Otherwise, tries to construct a partial from a function called field, if it exists.

Returns nil if found no valid field resolution.


[View source]
def inspect : Bool #

Whether to run the inspector.


[View source]
def inspect=(inspect : Bool) #

Whether to run the inspector.


[View source]
def inspector #

Starts a primitive state inspector prompt.

Returns false if the user wanted to terminate inspector functionality, or true if the user requested the next instruction.


[View source]
def measure : Bool #

Whether to measure instruction evaluation time.


[View source]
def measure=(measure : Bool) #

Whether to measure instruction evaluation time.


[View source]
def normalize(operator, left, right) #

Normalizes a binary operation (i.e., converts it to its normal form).

Dies if found no matching conversion.


[View source]
def normalize?(operator : String, left : Model, right : Model) #

Normalizes a binary operation (i.e., converts it to its normal form).

Returns nil if found no matching conversion.


[View source]
def record!(instruction, duration, cp, ip) #

Updates the timetable entry for an instruction given duration - the time it took to execute.

cp is a chunk pointer to the chunk where the instruction is found.

ip is an instruction pointer to the instruction.


[View source]
def reduce(operator : String, operand : Vec) #

Reduces vector operand using a binary operator.

Note:

  • If operand is empty, returns it back.
  • If operand has one item, returns that one item.

[View source]
def reduce(operator, operand : MRange) #

Reduces range operand using a binary operator.


[View source]
def reduce(operator, operand) #

Fallback reduce (converts operand to vec).


[View source]
def return! #

Cleans up and returns the last value on the operand stack, if any.


[View source]
def start #

Starts the evaluation loop, which begins to fetch the instructions from the current chunk and execute them, until there aren't any left.


[View source]
def timetable : Timetable #

[View source]