![]() |
Boron 2.1.0
|
The Urlan programmer interface. More...
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | UCellId |
Basic type identification. More... | |
struct | UCellDatatype |
UCell structure for datatype! type. More... | |
struct | UCellNumber |
UCell structure for number types. More... | |
struct | UCellCoord |
UCell structure for coord type. More... | |
struct | UCellVec3 |
UCell structure for vec3! type. More... | |
struct | UCellWord |
UCell structure for word types. More... | |
struct | UCellSeries |
UCell structure for series types. More... | |
struct | UCellError |
UCell structure for error! type. More... | |
union | UCell |
A cell holds a single value of a simple type or a reference (often to a UBuffer) for a complex type. More... | |
struct | UBuffer |
The UBuffer struct holds information about a resource, usually a chunk of memory. More... | |
struct | UThread |
The UThread struct stores the data specific to a thread of execution. More... | |
struct | USeriesIter |
Iterator for const series of any type. More... | |
struct | UBlockIt |
Iterator for const UCell array. More... | |
struct | UBindTarget |
Holds information for binding functions. More... | |
struct | UDatatype |
The UDatatype struct holds methods for a specific class of data. More... | |
struct | USeriesType |
The USeriesType struct holds extra methods for series datatypes. More... | |
struct | UEnvParameters |
The UEnvParameters struct allows the user to override default buffer and structure sizes. More... | |
Macros | |
#define | UR_FLAG_INT_HEX 0x01 |
This UCellId::flags bit indicates that an UR_INT value is printed as hexidecimal. | |
#define | UR_FLAG_SOL 0x80 |
This UCellId::flags bit indicates that the cell starts a new line of code. | |
#define | UR_STATIC 0x80 |
This UBuffer::flags bit is set when the UBuffer::ptr points to memory outside of the Urlan datatype system and must not be freed. | |
#define | ur_strFree ur_arrFree |
A string is a simple array. | |
#define | ur_blkFree ur_arrFree |
A block is a simple array. | |
#define | ur_ctxCell(c, n) |
Get pointer of UCell in context by index. | |
#define | ur_avail(buf) |
Returns the capacity of a UBuffer that is known to have been allocated. | |
#define | ur_testAvail(buf) |
Returns the capacity of a UBuffer. | |
#define | ur_type(c) |
Return UrlanDataType of cell. | |
#define | ur_setId(c, t) |
Set type and initialize the other 24 bits of UCellId to zero. | |
#define | ur_datatype(c) |
Access the UrlanDataType that a UCellDatatype represents. | |
#define | ur_isShared(n) |
True if buffer number refers to a buffer in the shared environment. | |
#define | ur_isSliced(c) |
True if the end member of a series cell is set. | |
#define | ur_pop(ut) |
Decrement stack.used. | |
#define | ur_hold(n) |
Convenience macro for ur_holdBuffer(). | |
#define | ur_release(h) |
Convenience macro for ur_releaseBuffer(). | |
#define | ur_buffer(n) |
Macro to get buffer known to be in thread dataStore. | |
#define | ur_bufferE(n) |
Convenience macro for ur_bufferEnv(). | |
#define | ur_bufferSer(c) |
Convenience macro for ur_bufferSeries(). | |
#define | ur_bufferSerM(c) |
Convenience macro for ur_bufferSeriesM(). | |
#define | ur_foreach(bi) |
Loop over all members of an iterator struct. | |
#define | ur_cstr(strC, bin) |
Make null terminated UTF-8 string in binary buffer. | |
Typedefs | |
typedef int32_t | UIndex |
This is an index into an array. | |
Enumerations | |
enum | UrlanDataType { } |
enum | UrlanWordBindings { UR_BIND_UNBOUND = 0 , UR_BIND_THREAD , UR_BIND_ENV , UR_BIND_STACK , UR_BIND_SELF , UR_BIND_SECURE , UR_BIND_USER } |
enum | UStatus { UR_THROW = 0 , UR_OK = 1 } |
enum | UrlanErrorType { UR_ERR_TYPE , UR_ERR_SCRIPT , UR_ERR_SYNTAX , UR_ERR_ACCESS , UR_ERR_INTERNAL , UR_ERR_COUNT } |
enum | UThreadMethod { UR_THREAD_INIT , UR_THREAD_FREE , UR_THREAD_FREEZE } |
enum | UrlanRecyclePhase { UR_RECYCLE_MARK , UR_RECYCLE_SWEEP } |
Functions | |
UEnvParameters * | ur_envParam (UEnvParameters *par) |
Initialize UEnvParameters structure to default values. | |
UThread * | ur_makeEnv (const UEnvParameters *) |
Allocate UEnv and initial UThread. | |
void | ur_freeEnv (UThread *) |
Free environment and the initial thread. | |
void | ur_freezeEnv (UThread *) |
Move the startup thread dataStore to the shared environment. | |
UThread * | ur_makeThread (const UThread *, uint32_t flags) |
Create a new thread. | |
int | ur_destroyThread (UThread *) |
Free memory used by UThread. | |
int | ur_datatypeCount (UThread *) |
Get number of datatypes installed in the environment. | |
UAtom | ur_intern (UThread *, const char *name, int len) |
Add a single atom to the shared environment. | |
UAtom | ur_internAtom (UThread *, const char *it, const char *end) |
Add a single atom to the shared environment. | |
UAtom * | ur_internAtoms (UThread *, const char *words, UAtom *atoms) |
Add atoms to the shared environment. | |
const char * | ur_atomCStr (UThread *, UAtom atom) |
Get name of atom. | |
void | ur_atomsSort (UAtomEntry *entries, int low, int high) |
Sort UAtomEntry table in ascending atom value order. | |
int | ur_atomsSearch (const UAtomEntry *entries, int count, UAtom atom) |
Find an atom in a UAtomEntry table using a binary search. | |
UBuffer * | ur_genBuffers (UThread *, int count, UIndex *index) |
Generate new buffers in dataStore. | |
UBuffer * | ur_generate (UThread *, int count, UIndex *index, const uint8_t *) |
Generate and initialize buffers of given types. | |
void | ur_destroyBuffer (UThread *, UBuffer *) |
Destroy buffer in dataStore. | |
UIndex | ur_holdBuffer (UThread *, UIndex bufN) |
Keeps buffer in thread dataStore from being garbage collected by ur_recycle(). | |
void | ur_releaseBuffer (UThread *, UIndex hold) |
Enables garbage collection of dataStore buffer which was held by ur_holdBuffer(). | |
void | ur_recycle (UThread *) |
Perform garbage collection on thread dataStore. | |
int | ur_markBuffer (UThread *, UIndex bufN) |
Makes sure the buffer is marked as used. | |
UCell * | ur_push (UThread *, int type) |
Set id of cell on top of stack and increment stack.used. | |
UCell * | ur_pushCell (UThread *, const UCell *) |
Copy cell to top of stack and increment stack.used. | |
UStatus | ur_error (UThread *, int errorType, const char *fmt,...) |
Create error! exception. | |
UBuffer * | ur_threadContext (UThread *) |
Get thread global context. | |
UBuffer * | ur_envContext (UThread *) |
Get shared global context. | |
void | ur_appendTrace (UThread *, UIndex blkN, UIndex it) |
Append block position to the current exception error! trace. | |
UIndex | ur_tokenize (UThread *, const char *it, const char *end, UCell *res) |
Convert a UTF-8 data string into a block. | |
UStatus | ur_tokenizeB (UThread *, UIndex blkN, int inputEncoding, const uint8_t *start, const uint8_t *end) |
Parse UTF-8 or Latin1 data into block. | |
UStatus | ur_serialize (UThread *, UIndex blkN, UCell *res) |
Serialize block. | |
UStatus | ur_unserialize (UThread *, const uint8_t *start, const uint8_t *end, UCell *res) |
Unserialize binary. | |
void | ur_toStr (UThread *, const UCell *cell, UBuffer *str, int depth) |
Append data representation of cell to a string. | |
void | ur_toText (UThread *, const UCell *cell, UBuffer *str) |
Append textual representation of cell to a string. | |
const UCell * | ur_wordCell (UThread *, const UCell *cell) |
Get word value for read-only operations. | |
UCell * | ur_wordCellM (UThread *, const UCell *cell) |
Get modifiable word value. | |
UStatus | ur_setWord (UThread *, const UCell *wordCell, const UCell *src) |
Set word. | |
const UBuffer * | ur_bufferEnv (UThread *, UIndex n) |
Get buffer from either the thread dataStore or environment sharedStore. | |
const UBuffer * | ur_bufferSeries (const UThread *, const UCell *cell) |
Get series buffer. | |
UBuffer * | ur_bufferSeriesM (UThread *, const UCell *cell) |
Get modifiable series buffer. | |
void | ur_seriesSlice (const UThread *, USeriesIter *si, const UCell *cell) |
Set USeriesIter to series slice. | |
UStatus | ur_seriesSliceM (UThread *, USeriesIterM *si, const UCell *cell) |
Set USeriesIterM to modifiable series slice. | |
const UBuffer * | ur_blockIt (const UThread *ut, UBlockIt *bi, const UCell *blkCell) |
Set UBlockIt to the start and end of a block slice. | |
void | ur_bind (UThread *, UBuffer *blk, const UBuffer *ctx, int bindType) |
Bind block to context. | |
void | ur_bindCells (UThread *, UCell *it, UCell *end, const UBindTarget *bt) |
Bind an array of cells to a target. | |
void | ur_bindCopy (UThread *, const UBuffer *ctx, UCell *it, UCell *end) |
Recursively bind blocks to the bindings found in a context. | |
void | ur_unbindCells (UThread *, UCell *it, UCell *end, int deep) |
Unbind all words in an array of cells. | |
void | ur_infuse (UThread *, UCell *it, UCell *end, const UBuffer *ctx) |
Replace words in cells with their values from a context. | |
int | ur_true (const UCell *cell) |
Check if a value is "true". | |
int | ur_same (UThread *, const UCell *a, const UCell *b) |
int | ur_equal (UThread *, const UCell *a, const UCell *b) |
int | ur_equalCase (UThread *, const UCell *a, const UCell *b) |
Case-sensitive equality test. | |
int | ur_compare (UThread *, const UCell *a, const UCell *b) |
int | ur_compareCase (UThread *, const UCell *a, const UCell *b) |
Case-sensitive ordering comparison. | |
void | ur_makeDatatype (UCell *cell, int type) |
Initialize cell to be a UT_DATATYPE value of the given type. | |
int | ur_isDatatype (const UCell *cell, const UCell *datatype) |
Test if cell is of a certain datatype. | |
void | ur_datatypeAddType (UCell *cell, int type) |
Add type to multi-type UT_DATATYPE cell. | |
int | ur_charLowercase (int c) |
Convert UCS2 character to lowercase. | |
int | ur_charUppercase (int c) |
Convert UCS2 character to uppercase. | |
UIndex | ur_makeBinary (UThread *, int size) |
Generate and initialize a single binary buffer. | |
UBuffer * | ur_makeBinaryCell (UThread *, int size, UCell *cell) |
Generate a single binary and set cell to reference it. | |
void | ur_binInit (UBuffer *, int size) |
Initialize buffer to type UT_BINARY. | |
void | ur_binReserve (UBuffer *, int size) |
Allocates enough memory to hold size bytes. | |
void | ur_binExpand (UBuffer *, int index, int count) |
Create space in the binary for count bytes starting at index. | |
void | ur_binErase (UBuffer *, int start, int count) |
Remove bytes from the binary. | |
void | ur_binAppendData (UBuffer *, const uint8_t *data, int len) |
Append data to binary buffer. | |
void | ur_binAppendArray (UBuffer *, const USeriesIter *si) |
Append array slice to binary buffer. | |
const char * | ur_binAppendBase (UBuffer *buf, const char *it, const char *end, enum UrlanBinaryEncoding enc) |
Append encoded ASCII string to binary buffer. | |
void | ur_binFree (UBuffer *) |
Free binary data. | |
void | ur_binSlice (UThread *, UBinaryIter *, const UCell *cell) |
Set UBinaryIter to binary slice. | |
UStatus | ur_binSliceM (UThread *, UBinaryIterM *, const UCell *cell) |
Set UBinaryIterM to binary slice. | |
void | ur_binToStr (UBuffer *, int encoding) |
Convert binary buffer to string buffer. | |
UIndex | ur_makeString (UThread *, int enc, int size) |
Generate and initialize a single string buffer. | |
UBuffer * | ur_makeStringCell (UThread *, int enc, int size, UCell *cell) |
Generate a single string and set cell to reference it. | |
UIndex | ur_makeStringLatin1 (UThread *, const uint8_t *it, const uint8_t *end) |
Generate and initialize a single string buffer from memory holding a Latin-1 string. | |
UIndex | ur_makeStringUtf8 (UThread *, const uint8_t *it, const uint8_t *end) |
Generate and initialize a single string buffer from memory holding a UTF-8 string. | |
void | ur_strInit (UBuffer *, int enc, int size) |
Initialize buffer to type UT_STRING. | |
void | ur_strInitUtf8 (UBuffer *, const uint8_t *it, const uint8_t *end) |
Initialize a single string buffer from memory holding a UTF-8 string. | |
void | ur_strAppendCStr (UBuffer *, const char *) |
Append a null-terminated UTF-8 string to a string buffer. | |
void | ur_strAppendChar (UBuffer *, int) |
Append a single UCS2 character to a string. | |
void | ur_strAppendInt (UBuffer *, int32_t) |
Append an integer to a string. | |
void | ur_strAppendInt64 (UBuffer *, int64_t) |
Append an 64-bit integer to a string. | |
void | ur_strAppendHex (UBuffer *, uint32_t n, uint32_t hi) |
Append a hexidecimal integer to a string. | |
void | ur_strAppendDouble (UBuffer *, double) |
Append a double to a string. | |
void | ur_strAppendFloat (UBuffer *, float) |
Append a float to a string. | |
void | ur_strAppendIndent (UBuffer *, int depth) |
Append tabs to a string. | |
void | ur_strAppend (UBuffer *, const UBuffer *strB, UIndex itB, UIndex endB) |
Append another string buffer to this string. | |
void | ur_strAppendBinary (UBuffer *, const uint8_t *it, const uint8_t *end, enum UrlanBinaryEncoding enc) |
Append binary data as text of the specified encoding. | |
void | ur_strTermNull (UBuffer *) |
Terminate with null character so buffer can be used as a C string. | |
int | ur_strIsAscii (const UBuffer *) |
Test if all characters are ASCII. | |
void | ur_strFlatten (UBuffer *) |
Convert a UTF-8 or UCS-2 string buffer to Latin-1 if possible. | |
void | ur_strLowercase (UBuffer *str, UIndex start, UIndex send) |
Convert characters of string slice to lowercase. | |
void | ur_strUppercase (UBuffer *str, UIndex start, UIndex send) |
Convert characters of string slice to uppercase. | |
UIndex | ur_strFindChar (const UBuffer *, UIndex, UIndex, int ch, int opt) |
Find the first instance of a character in a string. | |
UIndex | ur_strFindChars (const UBuffer *, UIndex start, UIndex end, const uint8_t *charSet, int len) |
Find the first character of a set in a string. | |
UIndex | ur_strFindCharsRev (const UBuffer *, UIndex start, UIndex end, const uint8_t *charSet, int len) |
Find the last character of a set in a string. | |
UIndex | ur_strFind (const USeriesIter *, const USeriesIter *, int matchCase) |
Find string in another string or binary series. | |
UIndex | ur_strFindRev (const USeriesIter *, const USeriesIter *, int matchCase) |
Find last string in another string or binary series. | |
UIndex | ur_strMatch (const USeriesIter *, const USeriesIter *, int matchCase) |
Compare characters in two string or binary series. | |
int | ur_strChar (const UBuffer *, UIndex pos) |
Return the character at a given position. | |
char * | ur_cstring (const UBuffer *, UBuffer *bin, UIndex start, UIndex end) |
Make null terminated UTF-8 string in binary buffer. | |
UIndex | ur_makeBlock (UThread *, int size) |
Generate a single block of type UT_BLOCK. | |
UBuffer * | ur_makeBlockCell (UThread *, int type, int size, UCell *cell) |
Generate a single block and set cell to reference it. | |
UIndex | ur_blkClone (UThread *, UIndex blkN) |
Make deep copy of block. | |
void | ur_blkInit (UBuffer *, int type, int size) |
Initialize block buffer. | |
UCell * | ur_blkAppendNew (UBuffer *, int type) |
Add cell to end of block. | |
void | ur_blkAppendCells (UBuffer *, const UCell *cells, int count) |
Append cells to block. | |
void | ur_blkInsert (UBuffer *, UIndex it, const UCell *cells, int count) |
Insert cells into block. | |
void | ur_blkPush (UBuffer *, const UCell *cell) |
Copy cell to end of block. | |
UCell * | ur_blkPop (UBuffer *) |
Remove cell from end of block. | |
void | ur_blkSlice (UThread *, UBlockIter *, const UCell *cell) |
Set UBlockIter to block slice. | |
UStatus | ur_blkSliceM (UThread *, UBlockIterM *, const UCell *cell) |
Set UBlockIterM to block slice. | |
void | ur_blkCollectType (UThread *, const UCell *blkCell, uint32_t typeMask, UBuffer *dest, int unique) |
Find all values of a certain type and append them to another block. | |
UBuffer * | ur_makePathCell (UThread *, const UCell *nodes, int size, UCell *cell) |
Initialize path cell and generate block if needed. | |
UStatus | ur_setPath (UThread *, const UCell *path, const UCell *src) |
Set path. | |
UIndex | ur_makeContext (UThread *, int size) |
Generate and initialize a single context. | |
UBuffer * | ur_makeContextCell (UThread *, int size, UCell *cell) |
Generate a single context and set cell to reference it. | |
UBuffer * | ur_ctxClone (UThread *, const UBuffer *src, UCell *cell) |
Clone a new context and set cell to reference it. | |
UBuffer * | ur_ctxMirror (UThread *, const UBuffer *src, UCell *cell) |
Create a shallow copy of a context and set cell to reference the new context. | |
void | ur_ctxInit (UBuffer *, int size) |
Initialize context buffer. | |
void | ur_ctxReserve (UBuffer *, int size) |
Allocates enough memory to hold size words. | |
void | ur_ctxFree (UBuffer *) |
Free context data. | |
UBuffer * | ur_ctxSort (UBuffer *) |
Sort the internal context search table so ur_ctxLookup() is faster. | |
void | ur_ctxSetWords (UBuffer *, const UCell *it, const UCell *end) |
Add the set-word! values in a series of cells to the words in a context. | |
int | ur_ctxAppendWord (UBuffer *, UAtom atom) |
Append word to context. | |
int | ur_ctxAddWordI (UBuffer *, UAtom atom) |
Add word to context if it does not already exist. | |
UCell * | ur_ctxAddWord (UBuffer *, UAtom atom) |
Similar to ur_ctxAddWordI(), but safely returns the cell pointer. | |
void | ur_ctxWordAtoms (const UBuffer *, UAtom *atoms) |
Get word atoms in order. | |
int | ur_ctxLookup (const UBuffer *, UAtom atom) |
Find word in context by atom. | |
const UBuffer * | ur_sortedContext (UThread *, const UCell *) |
Get context and make sure it is fully sorted for minimal ur_ctxLookup() time. | |
UIndex | ur_makeVector (UThread *, enum UrlanVectorType, int size) |
Generate a single vector buffer. | |
UBuffer * | ur_makeVectorCell (UThread *, enum UrlanVectorType, int size, UCell *) |
Generate a single vector and set cell to reference it. | |
void | ur_arrInit (UBuffer *, int size, int count) |
Initialize array buffer. | |
void | ur_arrReserve (UBuffer *, int count) |
Allocates enough memory to hold count elements. | |
void | ur_arrExpand (UBuffer *, int index, int count) |
Create space in the array for count elements starting at index. | |
void | ur_arrErase (UBuffer *, int start, int count) |
Remove elements from the array. | |
void | ur_arrFree (UBuffer *) |
Free array data. | |
void | ur_arrAppendInt32 (UBuffer *, int32_t) |
Append int32_t to array. | |
void | ur_arrAppendFloat (UBuffer *, float) |
Append float to array. | |
The Urlan programmer interface.
This is a C library which provides a garbage collected datatype system and data format which can be used for building domain specific languages.
#define ur_avail | ( | buf | ) |
Returns the capacity of a UBuffer that is known to have been allocated.
This macro is quicker than ur_testAvail, but must not be used when the UBuffer::ptr is NULL.
#define UR_STATIC 0x80 |
This UBuffer::flags bit is set when the UBuffer::ptr points to memory outside of the Urlan datatype system and must not be freed.
It indicates that the UBuffer::used member should not be modifed and that the ur_avail & ur_testAvail macros must not be used on the buffer.
#define ur_testAvail | ( | buf | ) |
typedef int32_t UIndex |
This is an index into an array.
For buffer references, a negative value indicates one in the shared environment rather than in the UThread::dataStore.
enum UrlanDataType |
Enumerator | |
---|---|
UT_TYPEMASK | Used in UCellDatatype to declare a multi-type datatype!. |
enum UrlanErrorType |
enum UrlanRecyclePhase |
Enumerator | |
---|---|
UR_RECYCLE_MARK | Phase passed to UDatatype::recycle. |
UR_RECYCLE_SWEEP | Phase passed to UDatatype::recycle. |
enum UrlanWordBindings |
Enumerator | |
---|---|
UR_BIND_UNBOUND | ur_setId() zeros binding so this is default. |
UR_BIND_THREAD | Bound to buffer in thread dataStore. |
UR_BIND_ENV | Bound to buffer in shared env dataStore. |
UR_BIND_STACK | Bound to thread stack. |
UR_BIND_SELF | Evaluate to bound context rather than value. |
UR_BIND_SECURE | As UR_BIND_THREAD but unbind if not in context. |
UR_BIND_USER | Start of user defined bindings. |
enum UStatus |
enum UThreadMethod |
void ur_arrAppendFloat | ( | UBuffer * | buf, |
float | n ) |
Append float to array.
buf | Array buffer with elemSize of 4. |
n | Number to append. |
void ur_arrAppendInt32 | ( | UBuffer * | buf, |
int32_t | n ) |
Append int32_t to array.
buf | Array buffer with elemSize of 4. |
n | Number to append. |
void ur_arrErase | ( | UBuffer * | buf, |
int | start, | ||
int | count ) |
Remove elements from the array.
buf | Initialized array buffer. |
start | Start index of erase. |
count | Number of elements to remove. |
void ur_arrExpand | ( | UBuffer * | buf, |
int | index, | ||
int | count ) |
Create space in the array for count elements starting at index.
The memory in the new space is uninitialized.
buf | Initialized array buffer. |
index | Position to expand at. |
count | Number of elements to expand. |
void ur_arrFree | ( | UBuffer * | buf | ) |
Free array data.
buf->ptr and buf->used are set to zero.
void ur_arrInit | ( | UBuffer * | buf, |
int | size, | ||
int | count ) |
Initialize array buffer.
The buf type, form, flags, and used members are set to zero.
buf | Uninitialized buffer. |
size | Element byte size. Must be less than 256. |
count | Number of elements to allocate. |
void ur_arrReserve | ( | UBuffer * | buf, |
int | count ) |
Allocates enough memory to hold count elements.
buf->used is not changed.
buf | Initialized array buffer. |
count | Total number of elements. |
Test if cell is of a certain datatype.
cell | Cell to test. |
datatype | Valid cell of type UT_DATATYPE. |
Generate a single vector buffer.
If you need multiple buffers then ur_genBuffers() should be used.
The caller must create a UCell for this block in a held block before the next ur_recycle() or else it will be garbage collected.
type | Element type (UR_VEC_U16, UR_VEC_I32, UR_VEC_F32, etc.). |
size | Number of elements to reserve. |
Generate a single vector and set cell to reference it.
type | Element type (UR_VEC_U16, UR_VEC_I32, UR_VEC_F32, etc.). |
size | Number of elements to reserve. |
cell | Cell to initialize. |
Makes sure the buffer is marked as used.
If the buffer had not already been marked as used, then non-zero is returned, and the caller is expected to invoke the UDatatype::markBuf method.
bufN | Buffer index into thread dataStore. |
void ur_recycle | ( | UThread * | ut | ) |
Perform garbage collection on thread dataStore.
This is a precise, tracing, mark-sweep collector. If starts with held buffers and the datatypes trace any buffers they reference.
Any UBuffer pointers to the thread dataStore must be considered invalid after this call. Note that while the buffer structures may move, the data that they point to (the UBuffer::ptr member) will not change.
Serialize block.
blkN | Index to valid block buffer. |
res | Cell to be set to new output binary. |