QuakeC.Exec (QuakeC v0.2.2)

Copy Markdown View Source

Runs QuakeC functions, compiled to Elixir (QuakeC.Compiler) the first time a program runs on this node.

The host is any map with the program memory under :qc; builtins are called as builtins.call(host, builtin, argument_count) and return the host, builtin being the builtin's number, or its name for a function the program declares as builtin #0 (bound by name). A builtin may run QuakeC itself (a touch during a move, say) by calling call/4 again, or stop every running function with abort/1.

host = QuakeC.Exec.call(host, function_index, MyGame.Builtins)
host = QuakeC.Exec.call(host, function_index, MyGame.Builtins, budget: 10_000_000)

Options

  • :budget — how many statements one call may run before it is taken for a runaway loop, default 100 000
  • :trace — a function given the name of every QuakeC function entered, default none
  • :before — a function of the host returning the host, run before each call starts (nested calls from builtins included), default none

A program that runs past its budget, calls a null function or an unknown builtin, or uses an instruction this machine lacks raises QuakeC.Exec.Error.

Summary

Functions

Stop every QuakeC function running in this process, as FTE's AbortStack: the outermost call/4 returns host as it stands. Called from a builtin.

Run function index to its end and return the host.

Run function name; a name the program lacks does nothing.

Functions

abort(host)

@spec abort(map()) :: no_return()

Stop every QuakeC function running in this process, as FTE's AbortStack: the outermost call/4 returns host as it stands. Called from a builtin.

call(host, index, builtins, opts \\ [])

@spec call(map(), non_neg_integer(), module(), keyword()) :: map()

Run function index to its end and return the host.

call_named(host, name, builtins, opts \\ [])

@spec call_named(map(), String.t(), module(), keyword()) :: map()

Run function name; a name the program lacks does nothing.