LambLisp 01 Red Fox Alpha
Lisp For Real-Time Control
Loading...
Searching...
No Matches
Cell Class Reference

Public Types

Cell type enumeration
Note the following properties of this enumeration:
NIL is a singleton, in the middle of the enumeration.
Types <= NIL are atoms.
Types >= NIL are lists.
Types > NIL are pairs.
Types <= T_PORT_HEAP are heap-allocated objects, requiring specialized finalizing but not specialized marking.
Types <= T_ANY_HEAP_SVEC are heap allocated vectors requiring specialized marking in addition to finalizing.
For Scheme purposes, there is one pair type, but there are several other specialized pair types that facilitate execution.
These additional pair types are atoms, but list operations such as car, cdr, and append can operate on them.
enum  {
  T_SVEC_HEAP =0 , T_SVEC2N_HEAP , T_ANY_HEAP_SVEC = T_SVEC2N_HEAP , T_SYM_HEAP ,
  T_BVEC_HEAP , T_STR_HEAP , T_CPP_HEAP , T_PORT_HEAP ,
  T_NEEDS_FINALIZING = T_PORT_HEAP , T_BVEC_EXT , T_STR_EXT , T_BVEC_IMM ,
  T_STR_IMM , T_GENSYM , T_BOOL , T_CHAR ,
  T_INT , T_REAL , T_RATIONAL , T_MOP3_PROC ,
  T_MOP3_NPROC , T_VOID , T_UNDEF , T_NIL ,
  T_PAIR , T_SVEC_IMM , T_PROC , T_NPROC ,
  T_MACRO , T_DICT , T_THUNK_SEXPR , T_THUNK_BODY ,
  T_ERROR , Ntypes
}

Public Member Functions

Sexpr_t mk_error (const char *fmt,...) CHECKPRINTF_pos2
Sexpr_t mk_error (Sexpr_t irritants, const char *fmt,...) CHECKPRINTF_pos3
Static Cell constructors, used only for "well-known" atomic cells (nilL, true, false etc).

In general, it is best not to do anything complex at static construction time. There is no guarantee that dependencies will be ready. In particular, use of the terminal may cause the system to crash. Most applications should leave any construction activities to more purposeful code at runtime, using only cells obtained through cons.

 Cell (Word_t typ, Word_t w1, Word_t w2)
 Cell (Word_t typ, Int_t w1, Sexpr_t w2)
 Cell (Word_t typ, Sexpr_t w1, Sexpr_t w2)
Low-level cell field manipulation.

Note that the type field occupies all of byte 0, although not all bits are required. This speeds up the very common type-checking operation, because no mask is required to extract the type bits.

The flags are in byte 1, and a mask operation is required to access the individual flag fields.

void zero ()
Int_t type (void)
void type (Int_t t)
Int_t flags (void)
void flags_set (Int_t f)
void flags_clr (Int_t f)
void rplaca (Word_t p)
void rplacd (Word_t p)
Cell value extractors, dependent on Cell type.
Ptr_t get_car_addr ()
Word_t get_car (void)
Word_t get_cdr (void)
Bool_t as_Bool_t ()
Char_t as_Char_t ()
Int_t as_Int_t ()
Real_t as_Real_t ()
Ptr_t as_Ptr_t ()
Charst_t as_Charst_t ()
Bytest_t as_Bytest_t ()
CharVec_t as_CharVec_t ()
ByteVec_t as_ByteVec_t ()
Portst_t as_Portst_t ()
Int_t as_numerator ()
Int_t as_denominator ()
Cell hash value

Hashing is used extensively throughout LambLisp. Each Cell has a hash value, calculated as follows:

  • If the Cell is a symbol, the Cell's hash value is the hash value of the symbol.

  • Otherwise, the address of the Cell is hashed, and that is the result.

Int_t hash_sexpr (void)
Int_t hash_contents (void)
Int_t hash (void)
Cell setters converting the C types into S-expressions.
Sexpr_t set (Int_t typ, Word_t w1, Word_t w2)
Sexpr_t set (Int_t typ, Int_t a, Sexpr_t b)
Sexpr_t set (Int_t typ, Sexpr_t a, Sexpr_t b)
Sexpr_t set (Bool_t b)
Sexpr_t set (Char_t c)
Sexpr_t set (Int_t i)
Sexpr_t set (Real_t r)
Sexpr_t set (Port_t &p)
Sexpr_t set (Int_t typ, Int_t a, Charst_t b)
Sexpr_t set (Int_t typ, Int_t a, Bytest_t b)
Sexpr_t set (Int_t typ, Int_t a, CharVec_t b)
Sexpr_t set (Int_t typ, Int_t a, ByteVec_t b)
Accessors for use when the type is known.

If the cell type is already known, then these accessors can be used to efficiently access the cell contents.

Sexpr_t prechecked_anypair_get_car ()
Sexpr_t prechecked_anypair_get_cdr ()
Int_t prechecked_sym_heap_get_hash ()
Charst_t prechecked_sym_heap_get_chars ()
void prechecked_sym_heap_get_info (Int_t &hsh, Charst_t &chars)
CharVec_t prechecked_str_heap_get_chars ()
CharVec_t prechecked_str_ext_get_chars ()
CharVec_t prechecked_str_imm_get_chars ()
void prechecked_bvec_imm_set_length (Int_t l)
Charst_t prechecked_gensym_get_chars ()
void prechecked_gensym_get_info (Int_t &hsh, Charst_t &chars)
Sexpr_t prechecked_error_get_irritants ()
Sexpr_t prechecked_error_get_str ()
Charst_t prechecked_error_get_chars ()
Accessors for use when the cell type is unverified.

The any and mustbe accessors will perform type checking and throw an error if an improper access is attempted. The coerce operators will perform C coercion on its operand if possible, otherwise throw an error.

Bool_t mustbe_Bool_t ()
Char_t mustbe_Char_t ()
Int_t mustbe_Int_t ()
Real_t mustbe_Real_t ()
Sexpr_t mustbe_any_str_t ()
Sexpr_t mustbe_cppobj_t ()
CPPDeleterPtr prechecked_cppobj_get_deleter ()
Ptr_t prechecked_cppobj_get_ptr ()
CPPDeleterPtr any_cppobj_get_deleter ()
Ptr_t any_cppobj_get_ptr ()
void any_cppobj_get_info (CPPDeleterPtr &d, Ptr_t &p)
Real_t coerce_Real_t ()
Real_t coerce_Int_t ()
Sexpr_t anypair_get_car ()
Sexpr_t anypair_get_cdr ()
Sexpr_t error_get_str ()
Sexpr_t error_get_irritants ()
Charst_t error_get_chars ()
Int_t any_sym_get_hash ()
Charst_t any_sym_get_chars ()
void any_sym_get_info (Int_t &hsh, Charst_t &chars)
Operations on strings

LambLisp supports several subtypes of strings. At the time of writing, there are heap-allocated strings (read-write), strings whose characters outside of LambLisp's managed memory, (aka external or EXT strings), and short immediate strings that are contained completely within a single cell. Additional subtypes (such as load-on-demand strings) may be added in future.

There are functions of the form any_xxx() that can be used with any subtype, and there are type-specific functions of the form any_xxx_yyy() for use where the type is already known, with yyy being a code hint.

CharVec_t any_str_get_chars ()
Int_t any_str_get_length ()
void any_str_get_info (Int_t &len, CharVec_t &chars)
Operations on vectors and sub-types of vectors

Within the LambLisp virtual machine, a Lisp vector is referred to as svec. This is an array of S-expressions having a fixed dimension. There are also bytevectors; these are an array of bytes, also of fixed dimension.

As with strings, there are several subtypes of S-expression vectors. There is a heap-allocated vector, which may be of any size. There is a second type of heap-allocated vector, that is always sized to be a power of 2. These are provided to support efficient hash tables. There are immediate vectors, which may be of 0, 1, or 2 elements. The 2-element immediate vector can also be used as a hash table. This can reduce search time by half without requiring any heap allocation, at the cost of 1 extra cell allocation.

Bytevectors are also diverse, having heap, external, and immediate variants. Heap bytevectors are allocated, obviously, on the system heap, and the heap space is freed when the bytevector is garbage-collected.

External bytevectors operate on bytes provided externally to LambLisp's memory manager. This space may heve been dynamically allocated from outside LambLisp, or may be located in read-only memory. When a C++ object os injected into LambLisp, it can optionally be provided with a garbage collector callback; in that case the external object can be automatically garbage collected when no it's longer used in the Lisp program.

Immediate bytevectors are contained within a LambLisp Cell. The maximum size is limited by the word size of the underlying platform.

Within the LambLisp virtual machine, there are generic functions of the form any_xvec_xxx() that can operate on any xvec (svec or bvec) subtype, as well as type-specific functions of the form xvec_yyy_xxx(), where yyy is a code hint for the cell storage type (heap, immediate, ROM).

void any_svec_get_info (Int_t &Nelems, Sexpr_t *&elems)
Sexpr_t * any_svec_get_elems ()
Int_t any_bvec_get_length ()
ByteVec_t any_bvec_get_elems ()
void any_bvec_get_info (Int_t &Nelems, ByteVec_t &elems)
Cell conversions to printable representation

These functions convert a Cell (or parts of a Cell) to a printable representation of the S-expression contents of the Cell. Because environments are often included in the descendants of the Cell being printed, the depth of environment recursiveness is limited.

String cell_name (void)
Charst_t type_name (Int_t typ)
Charst_t type_name (void)
Charst_t gcstate_name (void)
String dump ()
String str (Sexpr_t sx, Bool_t as_write_or_display, Int_t env_depth, Int_t max_depth)
String str (Bool_t as_write_or_display, Int_t env_depth, Int_t max_depth)
String str (Bool_t as_write_or_display, Int_t env_depth)
String str (Bool_t as_write_or_display)
String str (Int_t env_depth)
String str (void)

Static Public Attributes

Cell flags, including gc states for multi-pass incremental gc, tail marker, and spares.
static const int F_GC01 = 0x01
static const int F_GC02 = 0x02
static const int F_GC04 = 0x04
static const int F_TAIL = 0x08
static const int F_0x10 = 0x10
static const int F_0x20 = 0x20
static const int F_0x40 = 0x40
static const int F_0x80 = 0x80
static const int GC_STATE_MASK = F_GC01 | F_GC02 | F_GC04

Flag testing & setting for garbage collection and tail recursion.

The garbage collection algorithm is based on the tricolor abstraction described in Dijkstra 1978. The original set of 3 colors was enlarged to 4 with Kung and Song 1977, with their correctness proof of the incremental GC algorithm. In LambLisp, is is useful to have a fifth state, and to think of the state or color as a stage in the Cell life cycle. When GC is in progress, Cells may advance in their life cycle, but may also be moved back to an earlier as the result of an assignment. This enumeration allows some tests to be combined in an inequality rather than a sequence of equality tests or s C switch.

LambLisp* uses a trampoline technique to implement tail recursion. The tail of a series of expressions is the last one evaluated; this is the expression that will return the value of the series.

In the trampoline, instead of evaluating the last expression in the series and returning the value (as in C/C++), the expression is returned unevaluated, with the tail flag set. The evaluator checks every result to see if it is a tail that needs additional evaluation, or is a final result to be returned.

This removes the need for an additional stack frame during recursion.

enum  {
  gcst_idle , gcst_issued , gcst_stacked , gcst_marked ,
  gcst_free , Ngcstates
}
Int_t gc_state (void)
Sexpr_t gc_state (Int_t st)
Int_t tail_state (void)
Sexpr_t tail_state_set (void)
Sexpr_t tail_state_clr (void)

Cell type testing

The cell type enumeration has been designed to group together cell types according to their most common operations.

The main groups are those needing special sweep and finalizing during garbage collection, those that are treated as pairs, and simple atoms. There is a subgroup of those needing special sweep, that also need specialised marking during the garbage collection mark phase.

There are some types that have optimized subtypes (such as immediate types), and they differ in their processing at GC time. Type-testing functions below have is_any_x() predicates that group all subtypes together (e.g., is_any_str_atom() returns true for any type of string (heap, immediate, external). There are also functions further down that will return the contents of complex cells, and throw an error if called with incorrect type. Therefore it is often not necessary to use the predicates before accessing the atom internals with any_x_get_info().

Note also: it is sometimes faster to check the types directly, rather than check the cell feature table. Preliminary testing indicates more than 2 type tests should use the table instead.

typedef struct { 
   Int_t   typ 
   bool   is_any_pair 
   bool   is_any_svec 
   bool   is_any_svec2n 
   bool   is_any_str 
   bool   is_any_sym 
   bool   is_any_bvec 
   const char *   type_name 
CellFeatures
static const CellFeatures features [Ntypes]
void init_static_data ()
Bool_t is_atom (void)
Bool_t is_pair (void)
Bool_t is_any_pair (void)
Bool_t is_any_svec_atom ()
Bool_t is_any_svec2n_atom ()
Bool_t is_any_str_atom (void)
Bool_t is_any_sym_atom (void)
Bool_t is_any_bvec_atom (void)

Detailed Description

The Cell class is the foundational class for the LambLisp Virtual Machine.

Nearly all the Cell methods are inline for performance. A Cell has only getters and setters; there are no other side effects. Cell fields are changed only through explicit requests, and not as the result of any other mutations. This means that Cells do not participate in garbage collection, which is managed from outside the Cell class. Indeed, there is no concept within the Cell that there might be a plurality of them; only the behavior of a single Cell is defined.

A Cell may be one of several types. Historically, the number of types varied with the variant of Lisp. In LambLisp, there are Cell types that correspond directly to the types described in the Scheme RxRS specifications (integers, procedures etc), and there are additional types that implement underlying behavior to support the higher-level language (thunks, dictionaries).

For example, LambLisp supports several types of strings internally, depending on whether the character are stored on the heap, in externally-provided memory, or immediately within the cell (for fast operations on short strings). Each of these string types is compatible with the string type in the Scheme RxRS specifications. Likewise, bytevectors have external and immediate variants.

LambLisp also supports specialized pair types, such as the LambLisp dictionary. These act as Lisp pairs for purposes of allocation and garbage collection, but their specialized operators are executed by the underlying LambLisp virtual machine and therefore operate at C++ speed.

The Cell type enumeration is purposefully ordered in such a way as to allow efficient integer comparisons instead of a C switch in most cases, enhancing runtime performance as well as garbage collection.

Cell enumeration characteristics:
Cells requiring submarking
Cells requiring finalizing
Simple atoms: immediate cell types like bool char int real etc
External (non-GC) objects and pointers to native C++ code
Cells that point to C++-allocated objects, paired with optional GC finalizers.
"well-known singleton atoms" such as NIL, undefined, and void types.
Pair - the Cell type that responds to the Lisp pair? predicate.
Other pairs - specialized pair types

With this ordering of Cell types, the solution to many common cases during expression evaluation can be obtained with an inequality, rather than a C++ switch statement. This provides a significant performance boost, because the most common cases are checked first, and the total number of cases is reduced.

Cell optimized type tests
(Types < "simple atoms") need specialized GC marking and heap reclamation.
(Types <= "cells requiring finalizing") need specialized GC heap reclamation.
(Types >= T_NIL) are lists.
(Types > T_NIL) are pairs (but not only Lisp pairs, extended pairs too).
(Types != T_PAIR) are atoms, including numbers, strings, vectors, and singletons such as NIL.
(Types > T_PAIR) are extended pairs, used for specialized lists known to LambVM, but receiving regular pair GC processing.

There are cases where the ordering does not help so much. For example the LambLisp type system allows for several types of strings. Because the type system is ordered according to GC requirements, these are not adjacent in the enumeration and less amenable to inequality tests. For these cases, there is a cell feature matrix available to be queried by type and feature. This allows the determination to be made with an array lookup, which is faster than several sequential tests or a C switch, putting a permanent cap on the cost of a type check. It also allows other details such as is-immediate? to be implemented inexpensively.

The garbage collector states are ordered for similar reasons. See the garbage collector chapter for details on the Cell life cycle.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
T_SVEC_HEAP 

(Int_t Sexpr_t[]) A vector of Sexprs is a (len Sexpr_t*) pair.

T_SVEC2N_HEAP 

(Int_t Sexpr_t[]) Same as vector, but length must be a power of 2; useful for hash tables.

T_ANY_HEAP_SVEC 

Any types less than or equal to this are heap-stored vectors of S-expressions. They need specialized marking at GC time.

T_SYM_HEAP 

(Int_t Charst_t) Symbol is a (hash char*) pair.

T_BVEC_HEAP 

(Int_t Bytest_t) Bytevector is a (len byte*) pair.

T_STR_HEAP 

(reserved Charst_t) The reserved field may be used in future to store the string length (not possible with immediate strings, so some details to be worked).

T_CPP_HEAP 

(ptr-to-cpp-deleter ptr-to-cpp-object) Deleter is a function void f(void *cpp_obj) of the appropriate type T of the C++ object, and performes delete (T *) cpp_obj;

T_PORT_HEAP 

(reserved Ptr_t) car is unused, cdr is ptr to underlying C++ port instance

T_NEEDS_FINALIZING 

Any types less than or equal to this have data stored in the heap, and need specialized finalizing at GC time.

T_BVEC_EXT 

(Int_t Bytest_t) Same as T_BYTEVEC but externally allocated; the byte array is not freed at GC time.

T_STR_EXT 

(reserved Charst_t) Same as T_STR but externally allocated; the character array is not freed at GC time.

T_BVEC_IMM 

Special format: type and flag bytes as usual, byte 2 is vector length, remaining bytes are vector elements.

T_STR_IMM 

Special format: type and flag bytes as usual, remaining bytes are 0-terminated string embedded in the cell.

T_GENSYM 

Runtime symbol generation with no heap operations.

T_BOOL 

(Bool_t reserved) Boolean atom

T_CHAR 

(Char_t reserved) Character atom

T_INT 

(Int_t reserved) Integer atom

T_REAL 

(Special format: Real_t uses double word) Real number atom

T_RATIONAL 

(Int_t Int_t) The fields are numerator and denominator of a rational number.

T_MOP3_PROC 

(reserved *Mop3st_t) pointer to native function - args are evaluated before calling

T_MOP3_NPROC 

(reserved *Mop3st_t) pointer to native macro processor - args are not evaluated before calling

T_VOID 

(don't care) VOID has its own type and a singleton instance OBJ_VOID

T_UNDEF 

(ERROR ERROR) UNDEF has its own type and a singleton instance OBJ_UNDEF

T_NIL 

(ERROR ERROR) NIL has its own type and a singleton instance.

  • The NIL singleton is both a list and an atom, but not a pair.

  • Types <= T_NIL are atoms, types >= T_NIL are lists, types > T_NIL are pairs, but only T_PAIR responds to the Scheme pair? predicate.

T_PAIR 

(Sexpr_t Sexpr_t) Normal untyped cons cell. All C++ types < T_PAIR are atoms.

  • Pair types. Types > NIL and types >= T_PAIR are pairs, but only T_PAIR responds to Scheme (pair?).

  • All pair types can be garbage collected without type-specific GC marking or finalizing.

T_SVEC_IMM 

(Sexpr_t Sexpr_t) Vector of 0, 1 or 2 elements.

T_PROC 

(Sexpr_t Sexpr_t) Procedure pair; car is lambda (formals + body containing free variables), cdr is environment.

T_NPROC 

(Sexpr_t Sexpr_t) Non-evaluating procedure pair; car is nlambda (formals + body containing free variables), cdr is environment.

T_MACRO 

(Sexpr_t Sexpr_t) Macro; car is transformer (proc of 1 arg) and cdr is env.

T_DICT 

(Sexpr_t Sexpr_t) Dictionary pair; car is local frame, cdr is list of parent frames, used for environments & object instances.

T_THUNK_SEXPR 

(Sexpr_t Sexpr_t) S-expression thunk pair; car is sexpr, cdr is environment with all variable bindings.

T_THUNK_BODY 

(Sexpr_t Sexpr_t) Code body thunk pair; car is body (i.e., list of sexprs), cdr is environment with all variable bindings.

T_ERROR 

(Sexpr_t Sexpr_t) An error cell; car is a T_STRING, cdr is a pointer to irritants.

Ntypes 

Number of LambLisp virtual machine types.

Member Function Documentation

◆ zero()

void Cell::zero ( )
inline

Set all cell bits to zero.

◆ type() [1/2]

Int_t Cell::type ( void )
inline

Return the type of the cell as a small integer.

◆ type() [2/2]

void Cell::type ( Int_t t)
inline

Set the type of this cell.

◆ flags()

Int_t Cell::flags ( void )
inline

Return the entire set of cell flags.

◆ flags_set()

void Cell::flags_set ( Int_t f)
inline

Set the selected flags.

◆ flags_clr()

void Cell::flags_clr ( Int_t f)
inline

Clear the selected flags.

◆ rplaca()

void Cell::rplaca ( Word_t p)
inline

Replace the cell car field. Called rplaca for historical reasons, and to distinguish it from set-car!, which must respect the GC flags.

◆ rplacd()

void Cell::rplacd ( Word_t p)
inline

Replace the cell cdr field. Called rplacd for historical reasons, and to distinguish it from set-cdr!, which must respect the GC flags.

◆ is_atom()

Bool_t Cell::is_atom ( void )
inline

Return true if the cell is an atom.

◆ is_pair()

Bool_t Cell::is_pair ( void )
inline

Return true if the cell is a cons pair.

◆ is_any_pair()

Bool_t Cell::is_any_pair ( void )
inline

Return true if the cell is any pair type.

◆ is_any_svec_atom()

Bool_t Cell::is_any_svec_atom ( )
inline

Return true if the cell is any kind of Sexpr_t vector.

◆ is_any_svec2n_atom()

Bool_t Cell::is_any_svec2n_atom ( )
inline

Return true if the cell is Sexpr_t vector of size 2^n.

◆ is_any_str_atom()

Bool_t Cell::is_any_str_atom ( void )
inline

Return true if the cell is any kind of string.

◆ is_any_sym_atom()

Bool_t Cell::is_any_sym_atom ( void )
inline

Return true if the cell is any kind of symbol.

◆ is_any_bvec_atom()

Bool_t Cell::is_any_bvec_atom ( void )
inline

Return true if the cell is any kind of bytevector.

◆ gc_state() [1/2]

Int_t Cell::gc_state ( void )
inline

Return the garbage collection stat eof this cell.

◆ gc_state() [2/2]

Sexpr_t Cell::gc_state ( Int_t st)
inline

Set the garbage collection state of this cell, and return the cell.

◆ tail_state()

Int_t Cell::tail_state ( void )
inline

Return the taill state of this cell.

◆ tail_state_set()

Sexpr_t Cell::tail_state_set ( void )
inline

Set the tail state flag on this cell, and return the cell.

◆ tail_state_clr()

Sexpr_t Cell::tail_state_clr ( void )
inline

Clear the tail state flag on this cell, and return the cell.

◆ get_car_addr()

Ptr_t Cell::get_car_addr ( )
inline

Return the address of the cell car.

◆ get_car()

Word_t Cell::get_car ( void )
inline

Return the value of the cell car.

◆ get_cdr()

Word_t Cell::get_cdr ( void )
inline

Return the value of the cell cdr.

◆ as_Bool_t()

Bool_t Cell::as_Bool_t ( )
inline

Return the value of this cell as a boolean.

◆ as_Char_t()

Char_t Cell::as_Char_t ( )
inline

Return the value of this cell as a character.

◆ as_Int_t()

Int_t Cell::as_Int_t ( )
inline

Return the value of this cell as an integer.

◆ as_Real_t()

Real_t Cell::as_Real_t ( )
inline

Return the value of this cell as a real number.

◆ as_Ptr_t()

Ptr_t Cell::as_Ptr_t ( )
inline

Return the value of this cell as a generic pointer (i.e., void*).

◆ as_Charst_t()

Charst_t Cell::as_Charst_t ( )
inline

Return the value of this cell as a pointer to a zero-terminated character array.

◆ as_Bytest_t()

Bytest_t Cell::as_Bytest_t ( )
inline

Return the value of this cell as a pointer to an array of bytes.

◆ as_CharVec_t()

CharVec_t Cell::as_CharVec_t ( )
inline

Return the value of this cell as a pointer to a zero-terminated character array.

◆ as_ByteVec_t()

ByteVec_t Cell::as_ByteVec_t ( )
inline

Return the value of this cell as a pointer to an array of bytes.

◆ as_Portst_t()

Portst_t Cell::as_Portst_t ( )
inline

Return the value of this cell as a pointer to an instance of the system underlying "port" implementation.

◆ as_numerator()

Int_t Cell::as_numerator ( )
inline

Return the value of this cell as the numerator of a rational number.

◆ as_denominator()

Int_t Cell::as_denominator ( )
inline

Return the value of this cell as the denominator of a rational number.

◆ hash_sexpr()

Int_t Cell::hash_sexpr ( void )

For symbols, the hash of its characters; for numbers, the hash of the number; otherwise the hash of the S-expression itself (i.e., the address of a cell).

◆ hash_contents()

Int_t Cell::hash_contents ( void )

For symbols, the hash of its characters; for numbers, strings, vectors, and bytevectors, the hash of the contents; otherwise the hash of the S-expression itself.

◆ hash()

Int_t Cell::hash ( void )
inline

Return the hash value of this cell.

◆ set() [1/12]

Sexpr_t Cell::set ( Int_t typ,
Word_t w1,
Word_t w2 )
inline

This is the lowest-level generic "set" function.

◆ set() [2/12]

Sexpr_t Cell::set ( Int_t typ,
Int_t a,
Sexpr_t b )
inline

This is a convenience function for common cases.

◆ set() [3/12]

Sexpr_t Cell::set ( Int_t typ,
Sexpr_t a,
Sexpr_t b )
inline

This is a convenience function for common cases.

◆ set() [4/12]

Sexpr_t Cell::set ( Bool_t b)
inline

Set cell as boolean.

◆ set() [5/12]

Sexpr_t Cell::set ( Char_t c)
inline

Set cell as character.

◆ set() [6/12]

Sexpr_t Cell::set ( Int_t i)
inline

Set cell as integer.

◆ set() [7/12]

Sexpr_t Cell::set ( Real_t r)
inline

Set cell as real.

◆ set() [8/12]

Sexpr_t Cell::set ( Port_t & p)
inline

Set cell as port.

◆ set() [9/12]

Sexpr_t Cell::set ( Int_t typ,
Int_t a,
Charst_t b )
inline

Set cell as a immutable string.

◆ set() [10/12]

Sexpr_t Cell::set ( Int_t typ,
Int_t a,
Bytest_t b )
inline

Set cell as a immutable bytevector.

◆ set() [11/12]

Sexpr_t Cell::set ( Int_t typ,
Int_t a,
CharVec_t b )
inline

Set cell as a mutable string.

◆ set() [12/12]

Sexpr_t Cell::set ( Int_t typ,
Int_t a,
ByteVec_t b )
inline

Set cell as a mutable bytevector.

◆ mk_error() [1/2]

Sexpr_t Cell::mk_error ( const char * fmt,
... )

Fills and returns the single Cell-level T_ERROR object.

◆ mk_error() [2/2]

Sexpr_t Cell::mk_error ( Sexpr_t irritants,
const char * fmt,
... )

Fills and returns the single Cell-level T_ERROR object.

◆ prechecked_str_heap_get_chars()

CharVec_t Cell::prechecked_str_heap_get_chars ( )
inline

Return a pointer to the character array in the heap.

◆ prechecked_str_ext_get_chars()

CharVec_t Cell::prechecked_str_ext_get_chars ( )
inline

Return a pointer to the character array located outside the heap.

◆ prechecked_str_imm_get_chars()

CharVec_t Cell::prechecked_str_imm_get_chars ( )
inline

Return a pointer to the character array embedded in this cell.

◆ mustbe_Bool_t()

Bool_t Cell::mustbe_Bool_t ( )
inline

Return the value of this cell as a boolean.

◆ mustbe_Char_t()

Char_t Cell::mustbe_Char_t ( )
inline

Return the value of this cell as a character.

◆ mustbe_Int_t()

Int_t Cell::mustbe_Int_t ( )
inline

Return the value of this cell as an integer.

◆ mustbe_Real_t()

Real_t Cell::mustbe_Real_t ( )
inline

Return the value of this cell as a real number.

◆ mustbe_any_str_t()

Sexpr_t Cell::mustbe_any_str_t ( )
inline

Return this cell if it is a string.

◆ mustbe_cppobj_t()

Sexpr_t Cell::mustbe_cppobj_t ( )
inline

Return this cell if it is a CPP object.

◆ prechecked_cppobj_get_deleter()

CPPDeleterPtr Cell::prechecked_cppobj_get_deleter ( )
inline

Return the function to be called at garbage collection time to recycle the C++ object.

◆ prechecked_cppobj_get_ptr()

Ptr_t Cell::prechecked_cppobj_get_ptr ( )
inline

Return a pointer to a C++ object obtained earlier.

◆ any_str_get_chars()

CharVec_t Cell::any_str_get_chars ( )
inline

If the cell is any kind of string, return a pointer to the zero-terminated character array.

◆ cell_name()

String Cell::cell_name ( void )

A convenience feature to produce a string name for cells which are "well known" like NIL. Otherwise the name is the hex representation of the cell address.

◆ type_name()

Charst_t Cell::type_name ( Int_t typ)

Return a pointer to the C string corresponding to the cell type.

◆ gcstate_name()

Charst_t Cell::gcstate_name ( void )

Return a pointer to a C string corresponding to the given GC state.

◆ dump()

String Cell::dump ( )

Return a printable representation of the Cell internals.

Member Data Documentation

◆ F_GC01

const int Cell::F_GC01 = 0x01
static

gc flag

◆ F_GC02

const int Cell::F_GC02 = 0x02
static

gc flag

◆ F_GC04

const int Cell::F_GC04 = 0x04
static

gc flag

◆ F_TAIL

const int Cell::F_TAIL = 0x08
static

trampoline tail marker

◆ F_0x10

const int Cell::F_0x10 = 0x10
static

spare

◆ F_0x20

const int Cell::F_0x20 = 0x20
static

spare

◆ F_0x40

const int Cell::F_0x40 = 0x40
static

spare

◆ F_0x80

const int Cell::F_0x80 = 0x80
static

spare

◆ GC_STATE_MASK

const int Cell::GC_STATE_MASK = F_GC01 | F_GC02 | F_GC04
static

Mask for obtaining garbage collection state bits from Cell flag byte.