|
x-engine-c v0.2.13
The C engine for x-lang
|
Byte buffer type with read/write cursors for tokenizer input. More...
#include "x-type.h"Go to the source code of this file.
Macros | |
| #define | X_TYPE_BUFFER_NAME "BUFFER" |
| #define | X_TYPE_BUFFER_FLAG_INNER X_OBJ_FLAG_4 |
Predicates | |
| #define | x_obj_type_isbuffer(B, X) x_obj_is_type((B), (X), X_TYPE_BUFFER_NAME) |
Accessors | |
| #define | x_bufferval(X) x_firststr(X) |
| #define | x_bufferread(X) x_firststr(x_restobj(X)) |
| #define | x_bufferwrite(X) x_reststr(x_restobj(X)) |
| #define | x_bufferlen(X) (x_bufferread(X) - x_bufferval(X)) |
| #define | x_bufferunread(X) (x_bufferwrite(X) - x_bufferread(X)) |
| #define | x_bufferlastchar(X) (x_bufferread(X)[-1]) |
| #define | x_buffereof(X) (x_bufferread(X) >= x_bufferwrite(X)) |
Constructors | |
| #define | x_mkbuffer(B, P) x_make_buffer((B), X_OBJ_FLAG_NONE, (P)) |
| #define | x_mkbufferro(B, P) x_make_buffer((B), X_OBJ_FLAG_RO, (P)) |
| #define | x_mkfbuffer(B, F, P) x_make_buffer((B), (F), (P)) |
| #define | x_mkbufferown(B, P) x_make_buffer((B), X_OBJ_FLAG_OWN, (P)) |
| #define | x_mkfbufferown(B, F, P) x_make_buffer((B), X_OBJ_FLAG_OWN | (F), (P)) |
Functions | |
| x_obj_t * | x_make_buffer (x_obj_t *p_base, x_obj_flag_t flags, void *p) |
| x_obj_t * | x_type_buffer_register (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_type_buffer_struct (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_type_buffer_mark (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_type_buffer_make (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_type_buffer_reset (x_obj_t *p_base, x_obj_t *p_obj) |
| x_obj_t * | x_type_buffer_retain (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_type_buffer_append (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_type_buffer_read (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_type_buffer_read_text (x_obj_t *p_base, x_obj_t *p_args) |
Byte buffer type with read/write cursors for tokenizer input.
A BUFFER wraps a character array with separate read and write pointers, supporting incremental consumption from stdin or a pre-filled string. The read cursor advances as characters are consumed; the write cursor advances as new input arrives. Read-only buffers (X_OBJ_FLAG_RO) do not extend from stdin when exhausted.
Buffer layout: (base-ptr . (read-ptr . write-ptr)).
| #define x_buffereof | ( | X | ) | (x_bufferread(X) >= x_bufferwrite(X)) |
True when the read cursor has reached the write cursor.
| #define x_bufferlastchar | ( | X | ) | (x_bufferread(X)[-1]) |
The last character consumed (one behind the read cursor).
| #define x_bufferlen | ( | X | ) | (x_bufferread(X) - x_bufferval(X)) |
Number of characters already consumed (read - base).
| #define x_bufferread | ( | X | ) | x_firststr(x_restobj(X)) |
Read cursor – next character to be consumed.
| #define x_bufferunread | ( | X | ) | (x_bufferwrite(X) - x_bufferread(X)) |
Number of characters available to read (write - read).
| #define x_bufferval | ( | X | ) | x_firststr(X) |
Base pointer – start of the underlying character array.
| #define x_mkbuffer | ( | B, | |
| P | |||
| ) | x_make_buffer((B), X_OBJ_FLAG_NONE, (P)) |
Create a read/write buffer with default flags.
| #define x_mkbufferown | ( | B, | |
| P | |||
| ) | x_make_buffer((B), X_OBJ_FLAG_OWN, (P)) |
Create an owning buffer (frees underlying array on GC).
| #define x_mkbufferro | ( | B, | |
| P | |||
| ) | x_make_buffer((B), X_OBJ_FLAG_RO, (P)) |
Create a read-only buffer.
| #define x_mkfbuffer | ( | B, | |
| F, | |||
| P | |||
| ) | x_make_buffer((B), (F), (P)) |
Create a buffer with explicit flags.
| #define x_mkfbufferown | ( | B, | |
| F, | |||
| P | |||
| ) | x_make_buffer((B), X_OBJ_FLAG_OWN | (F), (P)) |
Create an owning buffer with extra flags.
| #define x_obj_type_isbuffer | ( | B, | |
| X | |||
| ) | x_obj_is_type((B), (X), X_TYPE_BUFFER_NAME) |
Test whether X is a BUFFER object.
| #define X_TYPE_BUFFER_FLAG_INNER X_OBJ_FLAG_4 |
The flag that marks a buffer's INNER object, (read . write), apart from its outer, (bytes . inner). Both are BUFFER-typed, and the inner's two slots are raw pointers into the bytes, so nothing may read them as objects to tell the two apart: the make sets this bit on the inner, and the save reads it. It shares its bit with the evaluator's #X_OBJ_FLAG_FNFRAME, which marks env spine cells; a buffer is never one.
| #define X_TYPE_BUFFER_NAME "BUFFER" |
Canonical type name (overridable).
| x_obj_t * x_make_buffer | ( | x_obj_t * | p_base, |
| x_obj_flag_t | flags, | ||
| void * | p | ||
| ) |
Allocate a BUFFER wrapping the character array at p.
Allocate a BUFFER wrapping the character array at p.
Both read and write cursors are initialized to point at p.
| p_base | Base (execution context). |
| flags | Object flags (e.g. X_OBJ_FLAG_OWN, X_OBJ_FLAG_RO). |
| p | Pointer to the underlying character array. |
Append a single character at the write cursor.
Append a single character at the write cursor.
Writes the character from the second argument and advances the write cursor by one.
| p_base | Base (execution context). |
| p_args | Argument list: (buffer char-object). |
Type-system make handler for BUFFER objects.
Type-system make handler for BUFFER objects.
Creates a two-level structure: the outer pair holds the base pointer, and the inner pair holds the read and write cursors (both initialized to the base pointer). The X_OBJ_FLAG_OWN flag is set only on the outer object.
| p_base | Base (execution context). |
| p_args | Argument list: (buffer-atom [flags-atom]). |
GC mark handler – flags inner bookkeeping object without traversing raw pointers.
GC mark handler for BUFFER objects.
Flags the inner bookkeeping pair directly without traversing its slots, since those contain raw char* pointers rather than objects.
| p_base | Base (execution context). |
| p_args | Argument list: (buffer-object flags). |
Read one character, extending from stdin if needed.
Read one character from the buffer, extending from stdin if needed.
If the buffer is exhausted and not read-only, reads one character from the base input channel and appends it. Advances the read cursor by one and tracks newlines for error reporting.
| p_base | Base (execution context). |
| p_args | Argument list whose first element is the buffer. |
Read one text character, treating NUL as EOF.
Read one text character, treating NUL as EOF.
Delegates to x_type_buffer_read() and returns NULL if the result is NULL or the last character read was '\0'.
| p_base | Base (execution context). |
| p_args | Argument list whose first element is the buffer. |
Register (or retrieve) the BUFFER type in the type alist.
Register (or retrieve) the BUFFER type in the type alist.
| p_base | Base (execution context). |
| p_args | Unused. |
Reset both cursors to the base pointer.
Reset both read and write cursors to the base pointer.
Effectively empties the buffer without deallocating the array.
| p_base | Base (execution context). |
| p_args | Argument list whose first element is the buffer. |
Compact unread data to the front of the array.
Compact unread data to the front of the underlying array.
Copies the remaining unread bytes to position 0 and adjusts both cursors accordingly, freeing space at the end of the buffer.
| p_base | Base (execution context). |
| p_args | Argument list whose first element is the buffer. |