Defines | |
#define | ur_ctxCell(c, n) ((c)->ptr.cell + n) |
Get pointer of UCell in context by index. | |
Functions | |
UIndex | ur_makeContext (UThread *ut, int size) |
Generate and initialize a single context. | |
UBuffer * | ur_makeContextCell (UThread *ut, int size, UCell *cell) |
Generate a single context and set cell to reference it. | |
void | ur_ctxReserve (UBuffer *buf, int size) |
Allocates enough memory to hold size words. | |
UBuffer * | ur_ctxClone (UThread *ut, const UBuffer *src, UCell *cell) |
Clone a new context and set cell to reference it. | |
UBuffer * | ur_ctxMirror (UThread *ut, const UBuffer *src, UCell *cell) |
Create a shallow copy of a context and set cell to reference the new context. | |
void | ur_ctxSetWords (UBuffer *ctx, const UCell *it, const UCell *end) |
Add the set-word! values in a series of cells to the words in a context. | |
void | ur_ctxInit (UBuffer *buf, int size) |
Initialize context buffer. | |
void | ur_ctxFree (UBuffer *buf) |
Free context data. | |
int | ur_atomsSearch (const UAtomEntry *entries, int count, UAtom atom) |
Find an atom in a UAtomEntry table using a binary search. | |
int | ur_ctxLookupNoSort (const UBuffer *ctx, UAtom atom) |
Find word in context by atom. | |
int | ur_ctxAppendWord (UBuffer *ctx, UAtom atom) |
Append word to context. | |
int | ur_ctxAddWordI (UBuffer *ctx, UAtom atom) |
Add word to context if it does not already exist. | |
UCell * | ur_ctxAddWord (UBuffer *ctx, UAtom atom) |
Similar to ur_ctxAddWordI(), but safely returns the cell pointer. | |
void | ur_atomsSort (UAtomEntry *entries, int low, int high) |
Perform quicksort on UAtomEntry table. | |
UBuffer * | ur_ctxSort (UBuffer *ctx) |
Sort the internal context search table so ur_ctxLookup() can be used. | |
const UBuffer * | ur_sortedContext (UThread *ut, const UCell *cell) |
Get context and make sure it is ready for ur_ctxLookup(). | |
int | ur_ctxLookup (const UBuffer *ctx, UAtom atom) |
Find word in context by atom. | |
void | ur_bindCells (UThread *ut, UCell *it, UCell *end, const UBindTarget *bt) |
Bind an array of cells to a target. | |
void | ur_bind (UThread *ut, UBuffer *blk, const UBuffer *ctx, int bindType) |
Bind block to context. | |
void | ur_infuse (UThread *ut, UCell *it, UCell *end, const UBuffer *ctx) |
Replace words in cells with their values from a context. |
int ur_atomsSearch | ( | const UAtomEntry * | entries, | |
int | count, | |||
UAtom | atom | |||
) |
Find an atom in a UAtomEntry table using a binary search.
The table must have been previously sorted with ur_atomsSort().
void ur_atomsSort | ( | UAtomEntry * | entries, | |
int | low, | |||
int | high | |||
) |
Perform quicksort on UAtomEntry table.
Pass low of 0 and high of (count - 1) to sort the entire table.
entries | Array of initialized UAtomEntry structs. | |
low | First entry in sort partition. | |
high | Last entry in sort partition. |
Bind block to context.
This recursively binds all sub-blocks.
blk | Block to bind. | |
ctx | Context. This may be a stand-alone context outside of any dataStore. | |
bindType | UR_BIND_THREAD, UR_BIND_ENV, etc. |
void ur_bindCells | ( | UThread * | ut, | |
UCell * | it, | |||
UCell * | end, | |||
const UBindTarget * | bt | |||
) |
Bind an array of cells to a target.
This recursively binds all blocks in the range of cells.
it | First cell. | |
end | End of cell array. | |
bt | Bind target. |
Similar to ur_ctxAddWordI(), but safely returns the cell pointer.
int ur_ctxAddWordI | ( | UBuffer * | ctx, | |
UAtom | atom | |||
) |
Add word to context if it does not already exist.
If added, the word is initialized as unset.
Note that the ctx->ptr may be changed by this function.
int ur_ctxAppendWord | ( | UBuffer * | ctx, | |
UAtom | atom | |||
) |
Append word to context.
This should only be called if the word is known to not already exist in the context.
The new word is initialized as unset.
Clone a new context and set cell to reference it.
src | Context to copy. | |
cell | Cell to initialize. |
void ur_ctxFree | ( | UBuffer * | buf | ) |
Free context data.
buf->ptr and buf->used are set to zero.
void ur_ctxInit | ( | UBuffer * | buf, | |
int | size | |||
) |
Initialize context buffer.
size | Number of words to reserve. |
int ur_ctxLookup | ( | const UBuffer * | ctx, | |
UAtom | atom | |||
) |
Find word in context by atom.
The internal context search table must sorted with ur_ctxSort() or ur_sortedContext() before ur_ctxLookup is called.
ctx | Initialized and sorted context buffer. | |
atom | Atom of word to find. |
int ur_ctxLookupNoSort | ( | const UBuffer * | ctx, | |
UAtom | atom | |||
) |
Find word in context by atom.
If the context is not sorted then a linear search will be done.
cxt | Initialized context which has at least one word. | |
atom | Atom of word to find. |
Create a shallow copy of a context and set cell to reference the new context.
No binding is done, so any blocks remain bound to the source context.
src | Context to copy. | |
cell | Cell to initialize. |
void ur_ctxReserve | ( | UBuffer * | buf, | |
int | size | |||
) |
Allocates enough memory to hold size words.
buf->used is not changed.
buf | Initialized context buffer. | |
size | Number of words to reserve. |
Add the set-word! values in a series of cells to the words in a context.
ctx | Destination context. | |
it | Start of cells. | |
end | End of cells. |
Sort the internal context search table so ur_ctxLookup() can be used.
If the context is already sorted then nothing is done. Each time new words are appended to the context it will become un-sorted.
ctx | Initialized context buffer. |
Replace words in cells with their values from a context.
This recursively infuses all sub-blocks.
Unlike bind, this only modifies UT_WORD cells in UT_BLOCK or UT_PAREN slices.
bi | Cells to infuse. | |
ctx | Context. |
UIndex ur_makeContext | ( | UThread * | ut, | |
int | size | |||
) |
Generate and initialize a single context.
If you need multiple buffers then ur_genBuffers() should be used.
size | Number of words to reserve. |
Generate a single context and set cell to reference it.
If you need multiple buffers then ur_genBuffers() should be used.
size | Number of words to reserve. | |
cell | Cell to initialize. |
Get context and make sure it is ready for ur_ctxLookup().
If the context is shared and has not been sorted, then an error is generated with ur_error() and zero is returned.
cell | Valid context cell. |