QuakeC (QuakeC v0.2.2)

Copy Markdown View Source

A QuakeC program's memory: its globals, and every entity's fields laid end to end, as the program addresses them.

Values are floats, integers (entity numbers, function indices, string offsets, field offsets and pointers), or binaries for strings made while running. A slot never written is 0.

A pointer is a byte address: global slot n is at 4 * n, field slot f of entity e at field_base() + 4 * (e * entity_fields + f), and memory from alloc/2 at heap_base() and up. load/2 and store/3 read and write through one.

Writes take effect in place (QuakeC.Memory): every copy of the struct sees them. copy/1 gives memory written apart from the original. The memory belongs to the process that made it (new/1), works from any process while that process lives, and release/1 frees it sooner.

qc = QuakeC.new(progs)
QuakeC.put_global(qc, "time", 1.5)
QuakeC.field(qc, 1, "origin")

Summary

Functions

bytes of fresh zeroed memory, rounded up to whole words: the memory and its address.

Every field of entity set back to zero.

Memory holding the same values as qc, written apart from it.

Field name of entity; 0 when the program has no such field.

The address of field slot offset of entity.

The address of field slot 0 of entity 0.

The offset of field name, or nil when the program has none.

Field slot offset of entity.

The type of field name, or nil.

Vector field name of entity.

Write integer or float value into words words from address address.

A value as a float.

Give back memory alloc/2 handed out at address; any other address is left alone.

The global named name.

Whether the program has a global name.

The vector global named name.

The address of the first word alloc/2 hands out.

The value at address address; an address outside every space reads 0.

Copy words words from address from to address to, as they stood before the copy; the ranges may overlap. Words from below address 0 read 0; a copy to an address outside every space raises.

Fresh memory for progs: its initial globals, every entity field zero.

Set the global named name when the program declares one; otherwise leave the memory as it is.

Set field name of entity; a vector sets three slots. A field the program lacks is left alone.

Set field slot offset of entity.

Set the global named name; a vector sets three slots.

Set global slot offset.

Set the three slots from offset.

Free qc's memory (QuakeC.Memory.delete/1); neither it nor any copy may be used after.

The global slot offset.

The three slots from offset as a vector.

Write value at address address.

A string value as text: an offset into the program's strings, or a made string.

Set global slot offset: :ok when only the memory's words changed, or the memory to use from then on (QuakeC.Memory.put/3).

Types

t()

@type t() :: %QuakeC{
  blocks: term(),
  field_offsets: term(),
  fields: term(),
  global_offsets: term(),
  globals: term(),
  heap: term(),
  heap_top: term(),
  progs: term(),
  size: term(),
  spare: term()
}

value()

@type value() :: number() | binary()

vector()

@type vector() :: {float(), float(), float()}

Functions

alloc(qc, bytes)

@spec alloc(t(), non_neg_integer()) :: {t(), pos_integer()}

bytes of fresh zeroed memory, rounded up to whole words: the memory and its address.

clear_entity(qc, entity)

@spec clear_entity(t(), non_neg_integer()) :: t()

Every field of entity set back to zero.

copy(qc)

@spec copy(t()) :: t()

Memory holding the same values as qc, written apart from it.

field(qc, entity, name)

@spec field(t(), non_neg_integer(), String.t()) :: value()

Field name of entity; 0 when the program has no such field.

field_address(quake_c, entity, offset)

@spec field_address(t(), non_neg_integer(), non_neg_integer()) :: pos_integer()

The address of field slot offset of entity.

field_base()

@spec field_base() :: pos_integer()

The address of field slot 0 of entity 0.

field_offset(quake_c, name)

@spec field_offset(t(), String.t()) :: non_neg_integer() | nil

The offset of field name, or nil when the program has none.

field_slot(quake_c, entity, offset)

@spec field_slot(t(), non_neg_integer(), non_neg_integer()) :: value()

Field slot offset of entity.

field_type(quake_c, name)

@spec field_type(t(), String.t()) :: atom() | nil

The type of field name, or nil.

field_vector(qc, entity, name)

@spec field_vector(t(), non_neg_integer(), String.t()) :: vector()

Vector field name of entity.

fill(qc, address, words, value)

@spec fill(t(), integer(), non_neg_integer(), number()) :: t()

Write integer or float value into words words from address address.

float(value)

@spec float(value()) :: float()

A value as a float.

free(qc, address)

@spec free(t(), integer()) :: t()

Give back memory alloc/2 handed out at address; any other address is left alone.

global(qc, name)

@spec global(t(), String.t()) :: value()

The global named name.

global?(quake_c, name)

@spec global?(t(), String.t()) :: boolean()

Whether the program has a global name.

global_vector(qc, name)

@spec global_vector(t(), String.t()) :: vector()

The vector global named name.

heap_base()

@spec heap_base() :: pos_integer()

The address of the first word alloc/2 hands out.

load(qc, address)

@spec load(t(), integer()) :: value()

The value at address address; an address outside every space reads 0.

move(qc, from, to, words)

@spec move(t(), integer(), integer(), non_neg_integer()) :: t()

Copy words words from address from to address to, as they stood before the copy; the ranges may overlap. Words from below address 0 read 0; a copy to an address outside every space raises.

new(progs)

@spec new(QuakeC.Progs.t()) :: t()

Fresh memory for progs: its initial globals, every entity field zero.

put_declared(qc, name, value)

@spec put_declared(t(), String.t(), value() | vector()) :: t()

Set the global named name when the program declares one; otherwise leave the memory as it is.

put_field(qc, entity, name, value)

@spec put_field(t(), non_neg_integer(), String.t(), value() | vector()) :: t()

Set field name of entity; a vector sets three slots. A field the program lacks is left alone.

put_field_slot(qc, entity, offset, value)

@spec put_field_slot(t(), non_neg_integer(), non_neg_integer(), value()) :: t()

Set field slot offset of entity.

put_global(qc, name, vector)

@spec put_global(t(), String.t(), value() | vector()) :: t()

Set the global named name; a vector sets three slots.

put_slot(qc, offset, value)

@spec put_slot(t(), non_neg_integer(), value()) :: t()

Set global slot offset.

put_slot_vector(qc, offset, arg)

@spec put_slot_vector(t(), non_neg_integer(), vector()) :: t()

Set the three slots from offset.

release(qc)

@spec release(t()) :: :ok

Free qc's memory (QuakeC.Memory.delete/1); neither it nor any copy may be used after.

slot(quake_c, offset)

@spec slot(t(), non_neg_integer()) :: value()

The global slot offset.

slot_vector(quake_c, offset)

@spec slot_vector(t(), non_neg_integer()) :: vector()

The three slots from offset as a vector.

store(qc, address, value)

@spec store(t(), integer(), value()) :: t()

Write value at address address.

string(arg1, value)

@spec string(t(), value()) :: String.t()

A string value as text: an offset into the program's strings, or a made string.

update_slot(qc, offset, value)

@spec update_slot(t(), non_neg_integer(), value()) :: :ok | t()

Set global slot offset: :ok when only the memory's words changed, or the memory to use from then on (QuakeC.Memory.put/3).