class Ven::Machine

Included Modules

Defined in:

ven/machine.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

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

Makes a Machine that will run chunks, an array of stitched chunks.

context is the context that the Machine will run in. origin is the first chunk that will be evaluated (the main chunk).


[View source]

Class Method Detail

def self.run(chunks, context = Context::Machine.new, origin = 0, &) #

Makes a Machine, runs chunks and disposes the Machine.

context is the context that the Machine will run in. origin is the first chunk that will be evaluated (the main chunk).

Before running, yields the Machine to the block.

Returns the result that was produced by the Machine, or nil if nothing was produced.


[View source]
def self.run(chunks, context = Context::Machine.new, origin = 0, legate = Legate.new) #

Makes a Machine, runs chunks and disposes the Machine.

context is the context that the Machine will run in. origin is the first chunk that will be evaluated (the main chunk).

Returns the result that was produced by the Machine, or nil if nothing was produced.


[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 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 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]