4#include "ll_platform_generic.h"
19typedef LL_Port Port_t;
20typedef Port_t *Portst_t;
24typedef void CPPDeleter(
void *cpp_obj);
25typedef CPPDeleter *CPPDeleterPtr;
43extern Sexpr_t OBJ_EOF;
44extern Sexpr_t OBJ_UNDEF;
45extern Sexpr_t OBJ_VOID;
46extern Sexpr_t OBJ_SYSERROR;
115 Cell(Word_t typ, Word_t w1, Word_t w2) {
type(typ);
rplaca(w1);
rplacd(w2); }
116 Cell(Word_t typ, Int_t w1, Sexpr_t w2) {
type(typ);
rplaca((Word_t) w1);
rplacd((Word_t) w2); }
117 Cell(Word_t typ, Sexpr_t w1, Sexpr_t w2) {
type(typ);
rplaca((Word_t) w1);
rplacd((Word_t) w2); }
217#define _type_ (_contents._byte[0])
218#define _flags_ (_contents._byte[1])
219#define _car_ (_contents._word[1])
220#define _cdr_ (_contents._word[2])
221#define _car_addr_ (&(_car_))
222#define _int_ptr_ ((Int_t *) _car_addr_)
223#define _real_ptr_ ((Real_t *) _car_addr_)
224#define _byte2_ptr_ (&(_contents._byte[2]))
226 void zero() { _contents._word[0] = _contents._word[1] = _contents._word[2] = 0; }
227 Int_t
type(
void) {
return _type_; }
228 void type(Int_t t) { _type_ = t; }
230 Int_t
flags(
void) {
return _flags_; }
257 bool is_any_pair, is_any_svec, is_any_svec2n, is_any_str, is_any_sym, is_any_bvec;
258 const char *type_name;
261 static const CellFeatures features[
Ntypes];
263 void init_static_data();
296 enum { gcst_idle, gcst_issued, gcst_stacked, gcst_marked, gcst_free, Ngcstates };
343 Sexpr_t
set(Int_t typ, Word_t w1, Word_t w2) { _type_ = typ; _car_ = w1; _cdr_ = w2;
return this; }
344 Sexpr_t
set(Int_t typ, Int_t a, Sexpr_t b) { _type_ = typ; _car_ = (Word_t) a; _cdr_ = (Word_t) b;
return this; }
345 Sexpr_t
set(Int_t typ, Sexpr_t a, Sexpr_t b) { _type_ = typ; _car_ = (Word_t) a; _cdr_ = (Word_t) b;
return this; }
349 Sexpr_t
set(Int_t i) { _type_ =
T_INT; _car_ = _cdr_ = 0; *_int_ptr_ = i;
return this; }
350 Sexpr_t
set(Real_t r) { _type_ =
T_REAL; _car_ = _cdr_ = 0; *_real_ptr_ = r;
return this; }
354 Sexpr_t
set(Int_t typ, Int_t a, Charst_t b) {
return set(typ, (Word_t) a, (Word_t) b); }
355 Sexpr_t
set(Int_t typ, Int_t a, Bytest_t b) {
return set(typ, (Word_t) a, (Word_t) b); }
356 Sexpr_t
set(Int_t typ, Int_t a, CharVec_t b) {
return set(typ, (Word_t) a, (Word_t) b); }
357 Sexpr_t
set(Int_t typ, Int_t a, ByteVec_t b) {
return set(typ, (Word_t) a, (Word_t) b); }
360 Sexpr_t
mk_error(
const char *fmt, ...) CHECKPRINTF_pos2;
361 Sexpr_t
mk_error(Sexpr_t irritants, const
char *fmt, ...) CHECKPRINTF_pos3;
368 Sexpr_t prechecked_anypair_get_car() {
return (Sexpr_t)
get_car(); }
369 Sexpr_t prechecked_anypair_get_cdr() {
return (Sexpr_t)
get_cdr(); }
371 Int_t prechecked_sym_heap_get_hash() {
return as_Int_t(); }
372 Charst_t prechecked_sym_heap_get_chars() {
return (Charst_t)
as_Ptr_t(); }
373 void prechecked_sym_heap_get_info(Int_t &hsh, Charst_t &chars) { hsh =
as_Int_t(); chars = (Charst_t)
as_Ptr_t(); }
379 void prechecked_bvec_imm_set_length(Int_t l) { _contents._byte[2] = l; }
381 Charst_t prechecked_gensym_get_chars() {
static String s =
""; s = toString(
"G%s", ascii.hex(_cdr_));
return s.c_str(); }
382 void prechecked_gensym_get_info(Int_t &hsh, Charst_t &chars) { hsh =
as_Int_t(); chars = prechecked_gensym_get_chars(); }
384 Sexpr_t prechecked_error_get_irritants() {
return (Sexpr_t)
get_cdr(); }
385 Sexpr_t prechecked_error_get_str() {
return (Sexpr_t)
get_car(); }
386 Charst_t prechecked_error_get_chars() {
return prechecked_error_get_str()->any_str_get_chars(); }
393#define THROW_BAD_TYPE { throw mk_error("%s Bad type %s", me, dump().c_str()); }
410 Real_t coerce_Real_t()
412 ME(
"Cell::coerce_Real_t()");
420 Real_t coerce_Int_t()
422 ME(
"Cell::coerce_Int_t()");
430 Sexpr_t anypair_get_car() { ME(
"Cell::anypair_get_car()");
if (
is_any_pair())
return prechecked_anypair_get_car(); THROW_BAD_TYPE; }
431 Sexpr_t anypair_get_cdr() { ME(
"Cell::anypair_get_cdr()");
if (
is_any_pair())
return prechecked_anypair_get_cdr(); THROW_BAD_TYPE; }
433 Sexpr_t error_get_str() { ME(
"Cell::error_get_str()");
if (_type_ ==
T_ERROR)
return prechecked_error_get_str(); THROW_BAD_TYPE; }
434 Sexpr_t error_get_irritants() { ME(
"Cell::error_get_irritants()");
if (_type_ ==
T_ERROR)
return prechecked_error_get_irritants(); THROW_BAD_TYPE; }
435 Charst_t error_get_chars() { ME(
"Cell::error_get_chars()");
if (_type_ ==
T_ERROR)
return prechecked_error_get_chars(); THROW_BAD_TYPE; }
437 Int_t any_sym_get_hash() { ME(
"any_sym_get_hash()");
if (
is_any_sym_atom())
return as_Int_t(); THROW_BAD_TYPE; }
439 Charst_t any_sym_get_chars() {
440 ME(
"Cell::any_sym_get_chars()");
441 if (_type_ ==
T_SYM_HEAP)
return prechecked_sym_heap_get_chars();
442 else if (_type_ ==
T_GENSYM)
return prechecked_gensym_get_chars();
446 void any_sym_get_info(Int_t &hsh, Charst_t &chars) {
447 ME(
"Cell::any_sym_get_info()");
448 if (_type_ ==
T_SYM_HEAP) prechecked_sym_heap_get_info(hsh, chars);
449 else if (_type_ ==
T_GENSYM) prechecked_gensym_get_info(hsh, chars);
469 ME(
"Cell::anystring_get_chars()");
477 void any_str_get_info(Int_t &len, CharVec_t &chars) { len = strlen(chars =
any_str_get_chars()); }
507 void any_svec_get_info(Int_t &Nelems, Sexpr_t *&elems) {
508 ME(
"Cell::any_svec_get_info()");
516 if (prechecked_anypair_get_cdr() == OBJ_VOID) Nelems--;
517 if (prechecked_anypair_get_car() == OBJ_VOID) Nelems--;
518 elems = (Sexpr_t *) _car_addr_;
523 Sexpr_t *any_svec_get_elems()
525 ME(
"Cell::any_svec_get_elems()");
530 else if (typ ==
T_SVEC_IMM) res = (Sexpr_t *) _car_addr_;
536 Int_t any_bvec_get_length()
538 ME(
"Cell::any_bvec_get_length()");
541 ByteVec_t b = (ByteVec_t) _byte2_ptr_;
550 ByteVec_t any_bvec_get_elems()
552 ME(
"Cell::any_bvec_get_elems()");
555 ByteVec_t b = (ByteVec_t) _byte2_ptr_;
556 res = (ByteVec_t) &(b[1]);
563 void any_bvec_get_info(Int_t &Nelems, ByteVec_t &elems)
565 ME(
"Cell::any_bvec_get_info()");
567 ByteVec_t b = (ByteVec_t) _byte2_ptr_;
569 elems = (ByteVec_t) &(b[1]);
598 Charst_t type_name(
void) {
return type_name(this->
type()); }
603 String str(Sexpr_t sx, Bool_t as_write_or_display, Int_t env_depth, Int_t max_depth);
604 String str(Bool_t as_write_or_display, Int_t env_depth, Int_t max_depth) {
return str(
this, as_write_or_display, env_depth, max_depth); }
605 String str(Bool_t as_write_or_display, Int_t env_depth) {
return str(
this, as_write_or_display, env_depth, 10); }
606 String str(Bool_t as_write_or_display) {
return str(
this, as_write_or_display, 1, 10); }
607 String str(Int_t env_depth) {
return str(
this,
true, env_depth, 10); }
608 String str(
void) {
return str(
this,
true, 1, 10); }
613 Byte_t _byte[3 *
sizeof(Word_t)];
619static_assert(
sizeof(
Cell) == 3*
sizeof(Word_t),
"Cell size != 3*Word_t size\n");
620static_assert(
sizeof(
Cell) == 3*
sizeof(Ptr_t),
"Cell size != 3*Ptr_t size\n");
624extern Sexpr_t LAMB_INPUT;
625extern Sexpr_t LAMB_OUTPUT;
628class LambMemoryManager;
660 typedef Sexpr_t (*
Mop3st_t)(Lamb &lamb, Sexpr_t sexpr, Sexpr_t env_exec);
671 void log(
const char *fmt, ...) CHECKPRINTF_pos2;
672 void printf(const
char *fmt, ...) CHECKPRINTF_pos2;
695 Sexpr_t
tcons(Int_t typ, Word_t a, Word_t b, Sexpr_t env_exec);
696 Sexpr_t
tcons(Int_t typ, Sexpr_t a, Sexpr_t b, Sexpr_t env_exec);
708 Sexpr_t car(Sexpr_t l);
709 Sexpr_t cdr(Sexpr_t l);
710 Sexpr_t caar(Sexpr_t l) {
return car(car(l)); }
711 Sexpr_t cadr(Sexpr_t l) {
return car(cdr(l)); }
712 Sexpr_t cdar(Sexpr_t l) {
return cdr(car(l)); }
713 Sexpr_t cddr(Sexpr_t l) {
return cdr(cdr(l)); }
714 Sexpr_t caddr(Sexpr_t l) {
return car(cddr(l)); }
715 Sexpr_t cdddr(Sexpr_t l) {
return cdr(cddr(l)); }
716 Sexpr_t cadddr(Sexpr_t l) {
return car(cdddr(l)); }
717 Sexpr_t cddddr(Sexpr_t l) {
return cdr(cdddr(l)); }
730 Sexpr_t
eq_q(Sexpr_t obj1, Sexpr_t obj2);
731 Sexpr_t
eqv_q(Sexpr_t obj1, Sexpr_t obj2);
733 Sexpr_t
assq(Sexpr_t obj, Sexpr_t alist);
757 Sexpr_t oblist_query(Sexpr_t oblist,
const char *identifier, Bool_t force, Sexpr_t env_exec);
758 Sexpr_t oblist_test(Sexpr_t oblist,
const char *identifier, Sexpr_t env_exec) {
return oblist_query(oblist, identifier,
false, env_exec); }
759 Sexpr_t oblist_intern(Sexpr_t oblist,
const char *identifier, Sexpr_t env_exec) {
return oblist_query(oblist, identifier,
true, env_exec); }
760 Sexpr_t oblist_analyze(Sexpr_t oblist, Int_t verbosity, Sexpr_t env_exec);
769 Sexpr_t
dict_new(Int_t framesize, Sexpr_t env_exec) {
return dict_add_empty_frame(NIL, framesize, env_exec); }
770 Sexpr_t
dict_new(Sexpr_t env_exec) {
return dict_add_empty_frame(NIL, 0, env_exec); }
772 Sexpr_t dict_add_empty_frame(Sexpr_t dict, Int_t framesize, Sexpr_t env_exec);
776 Sexpr_t
dict_add_alist_frame(Sexpr_t dict, Sexpr_t alist, Sexpr_t env_exec) {
return mk_dict(alist, dict, env_exec); }
800 Sexpr_t read(LL_Port &src, Sexpr_t env_exec) {
return read_sexpr(src, env_exec,
false); }
802 Sexpr_t write_or_display(Sexpr_t sexpr, Bool_t do_write);
803 Sexpr_t write_simple(Sexpr_t sexpr);
805 String sprintf(Charst_t fmt, Sexpr_t sexpr, Sexpr_t env_exec);
807 Sexpr_t
printf(Sexpr_t args, LL_Port &outp);
808 Sexpr_t
printf(Sexpr_t args);
813 Sexpr_t
eval(Sexpr_t sexpr, Sexpr_t env_exec);
816 Sexpr_t
map_proc(Sexpr_t proc, Sexpr_t lists, Sexpr_t env_exec);
821 Sexpr_t r5_base_environment() {
return _r5_base_environment; }
822 Sexpr_t r5_interaction_environment() {
return _r5_interaction_environment; }
823 Sexpr_t lamb_oblist() {
return _lamb_oblist; }
825 Sexpr_t current_input_port() {
return _r5_current_input_port; }
826 Sexpr_t current_output_port() {
return _r5_current_output_port; }
827 Sexpr_t current_error_port() {
return _r5_current_error_port; }
830 Sexpr_t
load(Charst_t name, Sexpr_t env_exec, Int_t verbosity = 0);
834 Sexpr_t append(Sexpr_t sexpr, Sexpr_t env_exec);
835 Sexpr_t
append2(Sexpr_t lis, Sexpr_t obj, Sexpr_t env_exec);
836 Sexpr_t list_copy(Sexpr_t sexpr, Sexpr_t env_exec);
838 Sexpr_t list_to_vector(Sexpr_t l, Sexpr_t env_exec);
839 Sexpr_t vector_to_list(Sexpr_t v, Sexpr_t env_exec);
840 Sexpr_t vector_copy(Sexpr_t from, Sexpr_t env_exec);
847 Sexpr_t vector_to_sparsevec(Sexpr_t vec, Sexpr_t skip, Sexpr_t env_exec);
848 Sexpr_t sparsevec_to_vector(Sexpr_t alist, Sexpr_t fill, Sexpr_t env_exec);
857 Sexpr_t
mk_error(Sexpr_t env_exec, Sexpr_t irritants,
const char *fmt, ...) CHECKPRINTF_pos4;
858 Sexpr_t
mk_error(Sexpr_t env_exec, const
char *fmt, ...) CHECKPRINTF_pos3;
860 Sexpr_t
mk_syserror(Sexpr_t irritants, const
char *fmt, ...) CHECKPRINTF_pos3;
869 Sexpr_t mk_bool(Bool_t b, Sexpr_t env_exec) {
return tcons(
Cell::T_PAIR, NIL, NIL, env_exec)->
set(b); }
870 Sexpr_t mk_character(Char_t ch, Sexpr_t env_exec) {
return tcons(
Cell::T_PAIR, NIL, NIL, env_exec)->
set(ch); }
871 Sexpr_t mk_integer(Int_t i, Sexpr_t env_exec) {
return tcons(
Cell::T_PAIR, NIL, NIL, env_exec)->
set(i); }
872 Sexpr_t mk_real(Real_t r, Sexpr_t env_exec) {
return tcons(
Cell::T_PAIR, NIL, NIL, env_exec)->
set(r); }
874 Sexpr_t mk_number(Charst_t str, Sexpr_t env_exec);
875 Sexpr_t mk_sharp_const(Charst_t name, Sexpr_t env_exec);
904 Sexpr_t mk_string(Sexpr_t env_exec,
const char *fmt, ...) CHECKPRINTF_pos3;
905 Sexpr_t mk_string(Int_t k, Charst_t src, Sexpr_t env_exec);
906 Sexpr_t mk_string(String s, Sexpr_t env_exec) {
return mk_string(s.length(), s.c_str(), env_exec); }
908 Sexpr_t mk_symbol_or_number(Charst_t str, Sexpr_t env_exec);
909 Sexpr_t mk_symbol(Charst_t str, Sexpr_t env_exec) {
return oblist_intern(_lamb_oblist, str, env_exec); }
921 Sexpr_t
mk_intvector(Int_t k, Int_t fill, Sexpr_t env_exec);
922 Sexpr_t
mk_realvector(Int_t k, Real_t fill, Sexpr_t env_exec);
924 Sexpr_t mk_vector(Int_t len, Sexpr_t fill, Sexpr_t env_exec);
925 Sexpr_t mk_hashtbl(Int_t len, Sexpr_t fill, Sexpr_t env_exec);
927 Sexpr_t mk_serial_port(Sexpr_t env_exec);
928 Sexpr_t mk_input_file_port(Charst_t name, Sexpr_t env_exec);
929 Sexpr_t mk_output_file_port(Charst_t name, Sexpr_t env_exec);
930 Sexpr_t mk_input_string_port(Charst_t inp, Sexpr_t env_exec);
931 Sexpr_t mk_output_string_port(Sexpr_t env_exec);
938 Sexpr_t mk_cppobj(
void *obj, CPPDeleterPtr deleter, Sexpr_t env_exec) {
return tcons(
Cell::T_CPP_HEAP, (Word_t) deleter, (Word_t) obj, env_exec); }
954 Sexpr_t mk_macro(Sexpr_t nlam, Sexpr_t env_nlam, Sexpr_t env_exec) {
return tcons(
Cell::T_MACRO, nlam, env_nlam, env_exec); }
955 Sexpr_t mk_procedure(Sexpr_t formals, Sexpr_t body, Sexpr_t env_proc, Sexpr_t env_exec) {
return tcons(
Cell::T_PROC,
cons(formals, body, env_proc), env_proc, env_exec); }
956 Sexpr_t mk_nprocedure(Sexpr_t formals, Sexpr_t body, Sexpr_t env_nproc, Sexpr_t env_exec) {
return tcons(
Cell::T_NPROC,
cons(formals, body, env_nproc), env_nproc, env_exec); }
957 Sexpr_t mk_thunk_sexpr(Sexpr_t sexpr, Sexpr_t env_thunk, Sexpr_t env_exec) {
return tcons(
Cell::T_THUNK_SEXPR, sexpr, env_thunk, env_exec); }
958 Sexpr_t mk_thunk_body(Sexpr_t body, Sexpr_t env_thunk, Sexpr_t env_exec) {
return tcons(
Cell::T_THUNK_BODY, body, env_thunk, env_exec); }
959 Sexpr_t mk_dict(Sexpr_t frame, Sexpr_t base, Sexpr_t env_exec) {
return tcons(
Cell::T_DICT, frame, base, env_exec); }
960 Sexpr_t mk_dict(Int_t framesize, Sexpr_t env_exec);
968 Sexpr_t macroexpand(Sexpr_t form, Sexpr_t env_exec);
969 Sexpr_t macroexpand1(Sexpr_t form, Sexpr_t env_exec);
971 Sexpr_t macroexpand(Sexpr_t proc, Sexpr_t args, Sexpr_t env_exec);
972 Sexpr_t macroexpand1(Sexpr_t proc, Sexpr_t args, Sexpr_t env_exec);
981 LambMemoryManager *mem;
983 bool _debug_in_progress;
987 static const Int_t _lamb_oblist_size = 2048;
988 static const Int_t _r5_base_frame_size = 1024;
989 static const Int_t _r5_interaction_frame_size = 512;
991 Sexpr_t _lamb_oblist;
992 Sexpr_t _r5_base_environment;
993 Sexpr_t _r5_interaction_environment;
995 Sexpr_t _r5_current_input_port;
996 Sexpr_t _r5_current_output_port;
997 Sexpr_t _r5_current_error_port;
1000 const char *DELIMITERS =
"()\";\f\t\v\n\r ";
1022 Int_t produce_token(LL_Port &src);
1023 Sexpr_t consume_token(Int_t tok, LL_Port &src, Sexpr_t env_exec,
bool quoted);
1028 Sexpr_t sym_unquote;
1029 Sexpr_t sym_uqsplice;
1037 Sexpr_t sym_colon_hook;
1038 Sexpr_t sym_sharp_hook;
1040 Sexpr_t sym_ellipsis;
1041 Sexpr_t sym_fatarrow;
1046 Sexpr_t vector_eqv_q(Sexpr_t obj1, Sexpr_t obj2);
1047 Sexpr_t hashtbl_eqv_q(Sexpr_t obj1, Sexpr_t obj2);
1048 Sexpr_t bytevector_eqv_q(Sexpr_t obj1, Sexpr_t obj2);
1051 Sexpr_t dump_frame(Sexpr_t frame);
1052 Sexpr_t dump_env_stack(Sexpr_t env_stack);
1055 const char *token2name(Int_t tok);
1057 Sexpr_t read_sexpr(LL_Port &src, Sexpr_t &env_exec,
bool quoted);
1058 Sexpr_t read_atom(LL_Port &src, Sexpr_t &env_exec);
1060 Sexpr_t read_any_quote(Sexpr_t symbol, LL_Port &src, Sexpr_t &env_exec);
1061 Sexpr_t read_squote(LL_Port &src, Sexpr_t env_exec) {
return read_any_quote(sym_squote, src, env_exec); }
1062 Sexpr_t read_qquote(LL_Port &src, Sexpr_t env_exec) {
return read_any_quote(sym_qquote, src, env_exec); }
1063 Sexpr_t read_unquote(LL_Port &src, Sexpr_t env_exec) {
return read_any_quote(sym_unquote, src, env_exec); }
1064 Sexpr_t read_uqsplice(LL_Port &src, Sexpr_t env_exec) {
return read_any_quote(sym_uqsplice, src, env_exec); }
1066 Sexpr_t read_sharp_const(LL_Port &src, Sexpr_t &env_exec);
1067 Sexpr_t read_sharp(LL_Port &src, Sexpr_t &env_exec);
1068 Sexpr_t read_vector(LL_Port &src, Sexpr_t &env_exec);
1069 Sexpr_t read_quotedvector(LL_Port &src, Sexpr_t &env_exec);
1070 Sexpr_t read_list(LL_Port &src, Sexpr_t &env_exec,
bool quoted);
1071 Sexpr_t read_string(LL_Port &src, Sexpr_t &env_exec);
1076inline Sexpr_t Lamb::car(Sexpr_t c) {
1079 embedded_debug_catcher();
1083inline Sexpr_t Lamb::cdr(Sexpr_t c) {
1086 embedded_debug_catcher();
Definition LambLisp.h:104
Sexpr_t set(Int_t typ, Int_t a, Bytest_t b)
Set cell as a immutable bytevector.
Definition LambLisp.h:355
static const int F_GC02
gc flag
Definition LambLisp.h:199
Sexpr_t set(Bool_t b)
Set cell as boolean.
Definition LambLisp.h:347
Real_t as_Real_t()
Return the value of this cell as a real number.
Definition LambLisp.h:314
Bool_t is_any_pair(void)
Return true if the cell is any pair type.
Definition LambLisp.h:269
Sexpr_t set(Int_t typ, Int_t a, CharVec_t b)
Set cell as a mutable string.
Definition LambLisp.h:356
CharVec_t any_str_get_chars()
If the cell is any kind of string, return a pointer to the zero-terminated character array.
Definition LambLisp.h:468
void flags_set(Int_t f)
Set the selected flags.
Definition LambLisp.h:231
void rplaca(Word_t p)
Replace the cell car field. Called rplaca for historical reasons, and to distinguish it from set-car!...
Definition LambLisp.h:234
Sexpr_t mustbe_cppobj_t()
Return this cell if it is a CPP object.
Definition LambLisp.h:401
Sexpr_t set(Int_t typ, Int_t a, ByteVec_t b)
Set cell as a mutable bytevector.
Definition LambLisp.h:357
Bool_t is_any_str_atom(void)
Return true if the cell is any kind of string.
Definition LambLisp.h:272
CharVec_t prechecked_str_ext_get_chars()
Return a pointer to the character array located outside the heap.
Definition LambLisp.h:376
ByteVec_t as_ByteVec_t()
Return the value of this cell as a pointer to an array of bytes.
Definition LambLisp.h:320
Bool_t is_any_svec2n_atom()
Return true if the cell is Sexpr_t vector of size 2^n.
Definition LambLisp.h:271
String cell_name(void)
A convenience feature to produce a string name for cells which are "well known" like NIL....
Sexpr_t set(Int_t i)
Set cell as integer.
Definition LambLisp.h:349
Word_t get_car(void)
Return the value of the cell car.
Definition LambLisp.h:308
void rplacd(Word_t p)
Replace the cell cdr field. Called rplacd for historical reasons, and to distinguish it from set-cdr!...
Definition LambLisp.h:235
Ptr_t get_car_addr()
Return the address of the cell car.
Definition LambLisp.h:307
static const int F_GC04
gc flag
Definition LambLisp.h:200
Real_t mustbe_Real_t()
Return the value of this cell as a real number.
Definition LambLisp.h:398
CharVec_t as_CharVec_t()
Return the value of this cell as a pointer to a zero-terminated character array.
Definition LambLisp.h:319
Char_t as_Char_t()
Return the value of this cell as a character.
Definition LambLisp.h:312
Char_t mustbe_Char_t()
Return the value of this cell as a character.
Definition LambLisp.h:396
Sexpr_t tail_state_set(void)
Set the tail state flag on this cell, and return the cell.
Definition LambLisp.h:301
Bool_t is_any_bvec_atom(void)
Return true if the cell is any kind of bytevector.
Definition LambLisp.h:274
Sexpr_t set(Real_t r)
Set cell as real.
Definition LambLisp.h:350
Int_t type(void)
Return the type of the cell as a small integer.
Definition LambLisp.h:227
Charst_t type_name(Int_t typ)
Return a pointer to the C string corresponding to the cell type.
Int_t as_Int_t()
Return the value of this cell as an integer.
Definition LambLisp.h:313
static const int F_0x20
spare
Definition LambLisp.h:203
static const int F_0x40
spare
Definition LambLisp.h:204
static const int GC_STATE_MASK
Mask for obtaining garbage collection state bits from Cell flag byte.
Definition LambLisp.h:206
Ptr_t as_Ptr_t()
Return the value of this cell as a generic pointer (i.e., void*).
Definition LambLisp.h:316
Bool_t is_atom(void)
Return true if the cell is an atom.
Definition LambLisp.h:265
Bool_t as_Bool_t()
Return the value of this cell as a boolean.
Definition LambLisp.h:311
Int_t as_numerator()
Return the value of this cell as the numerator of a rational number.
Definition LambLisp.h:323
Sexpr_t set(Int_t typ, Int_t a, Charst_t b)
Set cell as a immutable string.
Definition LambLisp.h:354
Sexpr_t mustbe_any_str_t()
Return this cell if it is a string.
Definition LambLisp.h:400
void flags_clr(Int_t f)
Clear the selected flags.
Definition LambLisp.h:232
Word_t get_cdr(void)
Return the value of the cell cdr.
Definition LambLisp.h:309
static const int F_GC01
gc flag
Definition LambLisp.h:198
Bool_t is_any_svec_atom()
Return true if the cell is any kind of Sexpr_t vector.
Definition LambLisp.h:270
Charst_t as_Charst_t()
Return the value of this cell as a pointer to a zero-terminated character array.
Definition LambLisp.h:317
static const int F_0x80
spare
Definition LambLisp.h:205
Bool_t is_pair(void)
Return true if the cell is a cons pair.
Definition LambLisp.h:266
Int_t gc_state(void)
Return the garbage collection stat eof this cell.
Definition LambLisp.h:298
CharVec_t prechecked_str_imm_get_chars()
Return a pointer to the character array embedded in this cell.
Definition LambLisp.h:377
void zero()
Set all cell bits to zero.
Definition LambLisp.h:226
Int_t hash_sexpr(void)
For symbols, the hash of its characters; for numbers, the hash of the number; otherwise the hash of t...
Sexpr_t gc_state(Int_t st)
Set the garbage collection state of this cell, and return the cell.
Definition LambLisp.h:299
@ T_STR_EXT
(reserved Charst_t) Same as T_STR but externally allocated; the character array is not freed at GC ti...
Definition LambLisp.h:151
@ T_ERROR
(Sexpr_t Sexpr_t) An error cell; car is a T_STRING, cdr is a pointer to irritants.
Definition LambLisp.h:190
@ T_CHAR
(Char_t reserved) Character atom
Definition LambLisp.h:159
@ T_NEEDS_FINALIZING
Any types less than or equal to this have data stored in the heap, and need specialized finalizing at...
Definition LambLisp.h:148
@ T_BVEC_IMM
Special format: type and flag bytes as usual, byte 2 is vector length, remaining bytes are vector ele...
Definition LambLisp.h:153
@ T_PORT_HEAP
(reserved Ptr_t) car is unused, cdr is ptr to underlying C++ port instance
Definition LambLisp.h:147
@ T_BVEC_EXT
(Int_t Bytest_t) Same as T_BYTEVEC but externally allocated; the byte array is not freed at GC time.
Definition LambLisp.h:150
@ T_SVEC_HEAP
(Int_t Sexpr_t[]) A vector of Sexprs is a (len Sexpr_t*) pair.
Definition LambLisp.h:137
@ T_VOID
(don't care) VOID has its own type and a singleton instance OBJ_VOID
Definition LambLisp.h:169
@ T_INT
(Int_t reserved) Integer atom
Definition LambLisp.h:160
@ T_PAIR
(Sexpr_t Sexpr_t) Normal untyped cons cell. All C++ types < T_PAIR are atoms.
Definition LambLisp.h:182
@ T_GENSYM
Runtime symbol generation with no heap operations.
Definition LambLisp.h:155
@ T_SVEC2N_HEAP
(Int_t Sexpr_t[]) Same as vector, but length must be a power of 2; useful for hash tables.
Definition LambLisp.h:138
@ T_MACRO
(Sexpr_t Sexpr_t) Macro; car is transformer (proc of 1 arg) and cdr is env.
Definition LambLisp.h:186
@ T_UNDEF
(ERROR ERROR) UNDEF has its own type and a singleton instance OBJ_UNDEF
Definition LambLisp.h:170
@ T_THUNK_SEXPR
(Sexpr_t Sexpr_t) S-expression thunk pair; car is sexpr, cdr is environment with all variable binding...
Definition LambLisp.h:188
@ T_CPP_HEAP
(ptr-to-cpp-deleter ptr-to-cpp-object) Deleter is a function void f(void *cpp_obj) of the appropriate...
Definition LambLisp.h:145
@ T_THUNK_BODY
(Sexpr_t Sexpr_t) Code body thunk pair; car is body (i.e., list of sexprs), cdr is environment with a...
Definition LambLisp.h:189
@ T_NIL
(ERROR ERROR) NIL has its own type and a singleton instance.
Definition LambLisp.h:176
@ T_BVEC_HEAP
(Int_t Bytest_t) Bytevector is a (len byte*) pair.
Definition LambLisp.h:143
@ T_STR_HEAP
(reserved Charst_t) The reserved field may be used in future to store the string length (not possible...
Definition LambLisp.h:144
@ T_SYM_HEAP
(Int_t Charst_t) Symbol is a (hash char*) pair.
Definition LambLisp.h:142
@ T_MOP3_NPROC
(reserved *Mop3st_t) pointer to native macro processor - args are not evaluated before calling
Definition LambLisp.h:166
@ Ntypes
Number of LambLisp virtual machine types.
Definition LambLisp.h:192
@ T_SVEC_IMM
(Sexpr_t Sexpr_t) Vector of 0, 1 or 2 elements.
Definition LambLisp.h:183
@ T_REAL
(Special format: Real_t uses double word) Real number atom
Definition LambLisp.h:161
@ T_PROC
(Sexpr_t Sexpr_t) Procedure pair; car is lambda (formals + body containing free variables),...
Definition LambLisp.h:184
@ T_BOOL
(Bool_t reserved) Boolean atom
Definition LambLisp.h:158
@ T_DICT
(Sexpr_t Sexpr_t) Dictionary pair; car is local frame, cdr is list of parent frames,...
Definition LambLisp.h:187
@ T_ANY_HEAP_SVEC
Any types less than or equal to this are heap-stored vectors of S-expressions. They need specialized ...
Definition LambLisp.h:140
@ T_NPROC
(Sexpr_t Sexpr_t) Non-evaluating procedure pair; car is nlambda (formals + body containing free varia...
Definition LambLisp.h:185
@ T_MOP3_PROC
(reserved *Mop3st_t) pointer to native function - args are evaluated before calling
Definition LambLisp.h:165
@ T_STR_IMM
Special format: type and flag bytes as usual, remaining bytes are 0-terminated string embedded in the...
Definition LambLisp.h:154
@ T_RATIONAL
(Int_t Int_t) The fields are numerator and denominator of a rational number.
Definition LambLisp.h:162
static const int F_TAIL
trampoline tail marker
Definition LambLisp.h:201
Sexpr_t set(Int_t typ, Word_t w1, Word_t w2)
This is the lowest-level generic "set" function.
Definition LambLisp.h:343
Bytest_t as_Bytest_t()
Return the value of this cell as a pointer to an array of bytes.
Definition LambLisp.h:318
Sexpr_t set(Int_t typ, Sexpr_t a, Sexpr_t b)
This is a convenience function for common cases.
Definition LambLisp.h:345
Ptr_t prechecked_cppobj_get_ptr()
Return a pointer to a C++ object obtained earlier.
Definition LambLisp.h:404
Bool_t is_any_sym_atom(void)
Return true if the cell is any kind of symbol.
Definition LambLisp.h:273
Sexpr_t tail_state_clr(void)
Clear the tail state flag on this cell, and return the cell.
Definition LambLisp.h:302
Sexpr_t set(Int_t typ, Int_t a, Sexpr_t b)
This is a convenience function for common cases.
Definition LambLisp.h:344
Int_t tail_state(void)
Return the taill state of this cell.
Definition LambLisp.h:300
Bool_t mustbe_Bool_t()
Return the value of this cell as a boolean.
Definition LambLisp.h:395
Sexpr_t mk_error(const char *fmt,...) CHECKPRINTF_pos2
Fills and returns the single Cell-level T_ERROR object.
Portst_t as_Portst_t()
Return the value of this cell as a pointer to an instance of the system underlying "port" implementat...
Definition LambLisp.h:321
Int_t hash(void)
Return the hash value of this cell.
Definition LambLisp.h:338
CPPDeleterPtr prechecked_cppobj_get_deleter()
Return the function to be called at garbage collection time to recycle the C++ object.
Definition LambLisp.h:403
static const int F_0x10
spare
Definition LambLisp.h:202
Sexpr_t set(Char_t c)
Set cell as character.
Definition LambLisp.h:348
Int_t hash_contents(void)
For symbols, the hash of its characters; for numbers, strings, vectors, and bytevectors,...
Int_t mustbe_Int_t()
Return the value of this cell as an integer.
Definition LambLisp.h:397
Int_t flags(void)
Return the entire set of cell flags.
Definition LambLisp.h:230
Sexpr_t set(Port_t &p)
Set cell as port.
Definition LambLisp.h:351
Charst_t gcstate_name(void)
Return a pointer to a C string corresponding to the given GC state.
String dump()
Return a printable representation of the Cell internals.
Int_t as_denominator()
Return the value of this cell as the denominator of a rational number.
Definition LambLisp.h:324
CharVec_t prechecked_str_heap_get_chars()
Return a pointer to the character array in the heap.
Definition LambLisp.h:375
void type(Int_t t)
Set the type of this cell.
Definition LambLisp.h:228
Sexpr_t mk_bytevector_ext(Int_t k, Bytest_t ext, Sexpr_t env_exec)
Injection of externally allocated memory, which will not be freed at GC time.
Definition LambLisp.h:916
Sexpr_t apply_proc_partial(Sexpr_t proc, Sexpr_t sexpr, Sexpr_t env_exec)
Evaluate the function arguments and then apply the function to them. The result may be a tail requiri...
Sexpr_t assq(Sexpr_t obj, Sexpr_t alist)
Search an association list for a matching key, and return the (key . value) pair, or false if not fou...
Sexpr_t alist_to_dict(Sexpr_t alist, Sexpr_t env_exec)
Convert an alist into a dictionary. The resulting dictionary has no parent.
Sexpr_t(* Mop3st_t)(Lamb &lamb, Sexpr_t sexpr, Sexpr_t env_exec)
Definition LambLisp.h:660
const char * build_buildDate()
Return a pointer to a character array containing the build date.
Sexpr_t mk_realvector(Int_t k, Sexpr_t env_exec)
Allocates a bytevector from the heap to ensure proper alignment (no IMM type).
Sexpr_t loop(void)
Run often to maintain control. The main responsibility of C++ Lamb::loop() is to call the LambLisp fu...
Sexpr_t gensym(Sexpr_t env_exec)
Produce a new unique symbol.
Sexpr_t eqv_q(Sexpr_t obj1, Sexpr_t obj2)
Return true if 1 cells are the same cell, or are atoms with the same value.
Sexpr_t tcons(Int_t typ, Word_t a, Word_t b, Sexpr_t env_exec)
Generic cell constructor with no GC protection for its arguments.
void printf(const char *fmt,...) CHECKPRINTF_pos2
C-level printf feature with a limit on the length of strings produced.
Sexpr_t eq_q(Sexpr_t obj1, Sexpr_t obj2)
Return true if 2 cells are the same cell, or are atoms with the same value.
Sexpr_t cons(Sexpr_t a, Sexpr_t b, Sexpr_t env_exec)
Cell constructor for normal pairs.
Definition LambLisp.h:698
Sexpr_t dict_values(Sexpr_t dict, Sexpr_t env_exec)
Return a list of all the values in this dictionary. If the dictionary has parents,...
Sexpr_t mk_bytevector(Int_t k, Bytest_t src, Sexpr_t env_exec)
Heap allocation with initialization.
Sexpr_t mk_bytevector(Int_t k, Sexpr_t env_exec)
Simplest heap allocation with no initialization.
unsigned long build_version()
Return the build version as a long integer (implemented as a UTC time stamp).
Sexpr_t reverse_bang(Sexpr_t l)
Reverse the list in-place and return the new list head (the former list tail).
Sexpr_t list_analyze(Sexpr_t sexpr, Sexpr_t env_exec)
Traverse the list and return either false (if circular), the list length (if a proper list),...
Sexpr_t mk_bytevector(Int_t k, Int_t fill, Sexpr_t env_exec)
Heap allocation with initialization.
const char * build_pushDate()
Return a pointer to a character array containing the date this repo was last pushed.
void gc_root_pop(Int_t n=1)
Release the preserved cells for normal GC processing.
const char * build_buildRelease()
Return a pointer to a character array containing the release description.
void set_cdr_bang(Sexpr_t c, Sexpr_t val)
Replace the cdr field in the cell with val. GC flags will be maintained as required.
Sexpr_t twolist_to_dict(Sexpr_t twolist, Sexpr_t env_exec)
Convert a list of 2-element lists into a dictionary. The resulting dictionary has no parent.
Sexpr_t dict_to_2list(Sexpr_t dict, Sexpr_t env_exec)
Convert the dictionary to a list of 2-element lists, retaining only the top-level (key value) sublist...
Sexpr_t dict_add_empty_frame(Sexpr_t dict, Sexpr_t env_exec)
Returns a new dictionary with an empty top frame, and an existing dictionary as parent.
Definition LambLisp.h:773
Sexpr_t equal_q(Sexpr_t obj1, Sexpr_t obj2)
Returns true when obj1 and obj2 are eqv?, and also all their descendants.
Sexpr_t dict_ref_q(Sexpr_t dict, Sexpr_t key)
Returns (key value) pair, or false if key is unbound.
Sexpr_t mk_intvector(Int_t k, Sexpr_t env_exec)
Note that integer vectors and real vectors are just bytevectors underneath.
unsigned long build_UTC()
Return the UTC time of this build.
Sexpr_t dict_to_alist(Sexpr_t dict, Sexpr_t env_exec)
Convert the dictionary to an alist, retaining only the top-level (key . value) pairs.
void expand()
Add another block of cells to the population.
Sexpr_t mk_syserror(const char *fmt,...) CHECKPRINTF_pos2
Fill the system error object with the info given, and return it.
Sexpr_t eval_list(Sexpr_t args, Sexpr_t env_exec)
Evaluate the list of S-expressions in the environment provided, and return a lkist of results.
void log(const char *fmt,...) CHECKPRINTF_pos2
C-level printf feature with a limit on the length of strings produced. Takes care of log prompt.
void end(void)
Release resources used by the Lamb virtual machine.
bool debug(void)
Return the state of the Lamb internal debug flag.
void dict_bind_alist_bang(Sexpr_t dict, Sexpr_t alist, Sexpr_t env_exec)
Modify the target dictionary; binding keys in the alist to their corresponding values.
Sexpr_t dict_keys(Sexpr_t dict, Sexpr_t env_exec)
Note that keys and values are guaranteed to return in the corresponding order in dict_keys and dict_v...
Sexpr_t dict_add_alist_frame(Sexpr_t dict, Sexpr_t alist, Sexpr_t env_exec)
Returns a new dictionary with the alist bindings added in a new frame on top of the base dictionary.
Definition LambLisp.h:776
Sexpr_t dict_ref(Sexpr_t dict, Sexpr_t key)
Returns the value associated with the key in the given dictionary; throws error if key is unbound.
void dict_rebind_alist_bang(Sexpr_t dict, Sexpr_t alist, Sexpr_t env_exec)
Modify the target dictionary; rebinding keys in the alist to their corresponding values.
Sexpr_t dict_new(Sexpr_t env_exec)
Return a new empty dictionary with alist top frame.
Definition LambLisp.h:770
void dict_bind_bang(Sexpr_t dict, Sexpr_t key, Sexpr_t value, Sexpr_t env_exec)
Modify the target dictionary; value is re-assigned to keyif found, else created in the top frame.
void gc_root_push(Sexpr_t p)
Preserve the cell given from GC, until popped.
Sexpr_t dict_add_keyval_frame(Sexpr_t dict, Sexpr_t keys, Sexpr_t vals, Sexpr_t env_exec)
Returns a new dictionary with a new top frame containing the keys bound to the values.
void dict_rebind_bang(Sexpr_t dict, Sexpr_t key, Sexpr_t value, Sexpr_t env_exec)
Modify the target dictionary; value is assigned to key wherever first found in env,...
Sexpr_t dict_analyze(Sexpr_t dict, Int_t verbosity=0)
Internal integrity check.
Sexpr_t eval(Sexpr_t sexpr, Sexpr_t env_exec)
Evaluate the S-expression in the environment provided.
unsigned long build_pushUTC()
Return the UTC time this repo was last pushed.
Sexpr_t dict_new(Int_t framesize, Sexpr_t env_exec)
Return a new empty dictionary with the given top frame size.
Definition LambLisp.h:769
Sexpr_t append2(Sexpr_t lis, Sexpr_t obj, Sexpr_t env_exec)
Destructively attach obj to the end of lis, which must be a proper list.
void vector_set_bang(Sexpr_t vec, Int_t k, Sexpr_t val)
Replace the specified vector element with val. GC flags will be maintained as required.
bool build_isDebug()
Return true if this build is not checked in. This is unrelated to the runtime debug flag.
Sexpr_t mk_error(Sexpr_t env_exec, Sexpr_t irritants, const char *fmt,...) CHECKPRINTF_pos4
Fill a new error object with the information given, and return it.
void set_car_bang(Sexpr_t c, Sexpr_t val)
Replace the car field in the cell with val. GC flags will be maintained as required.
Sexpr_t load(Charst_t name, Sexpr_t env_exec, Int_t verbosity=0)
Load and evaluate S-expressions from the named file.
Sexpr_t map_proc(Sexpr_t proc, Sexpr_t lists, Sexpr_t env_exec)
Apply the procecure to the lists per R5RS.
Sexpr_t setup(void)
Run once after base platform has started. In particular, Serial should be initialized before calling ...