functions for interacting with keithlisp internals

This commit is contained in:
~keith 2021-09-23 13:26:36 -04:00
parent b8cfcc21e1
commit 27401372af
4 changed files with 52 additions and 0 deletions

View File

@ -7,3 +7,4 @@ categories:
- [Boolean Logic](stdlib_boolean.md)
- [Comparison](stdlib_comparison.md)
- [Miscellaneous Functions](stdlib_misc.md)
- [Keithlisp Internals](stdlib_internals.md)

29
doc/stdlib_internals.md Normal file
View File

@ -0,0 +1,29 @@
# Keithlisp Internals
These functions allow code to query and interact with the internals of
Keithlisp directly.
**Functions whose names end in `!` are particularly dangerous, and
should be avoided in almost all circumstances. You do not need them.**
## `syms-alist!`
```
(syms-alist!)
```
`syms-alist!` returns a reference to the syms-alist, which holds every
currently defined variable.
## `funs-alist!`
```
(funs-alist!)
```
`funs-alist!` returns a reference to the funs-alist, which holds every
currently defined function.
## `atoms-alist!`
```
(atoms-alist!)
```
`atoms-alist!` returns a reference to the atoms-alist, which stores the
original string of every atom that Keithlisp has parsed. It returns nil
if the atoms-alist has been disabled.

View File

@ -428,6 +428,19 @@ void lisp_fun(lisp_cons* cons, lisp_value* value) {
*value = pair->cdr;
}
void lisp_internals_syms_alist(lisp_cons* cons, lisp_value* value) {
value->type = LISP_T_CONS;
value->value.cons = syms_alist;
}
void lisp_internals_funs_alist(lisp_cons* cons, lisp_value* value) {
value->type = LISP_T_CONS;
value->value.cons = funs_alist;
}
void lisp_internals_atoms_alist(lisp_cons* cons, lisp_value* value) {
value->type = LISP_T_CONS;
value->value.cons = atoms_alist;
}
void init_native_funs() {
// arithmetic
lisp_defun_native(lisp_string_create("+"), &lisp_add);
@ -454,4 +467,9 @@ void init_native_funs() {
lisp_defun_native(lisp_string_create("addr-of"), &lisp_addr_of);
lisp_defun_native(lisp_string_create("set"), &lisp_set);
lisp_defun_native(lisp_string_create("fun"), &lisp_fun);
// internals
lisp_defun_native(lisp_string_create("syms-alist!"), &lisp_internals_syms_alist);
lisp_defun_native(lisp_string_create("funs-alist!"), &lisp_internals_funs_alist);
lisp_defun_native(lisp_string_create("atoms-alist!"), &lisp_internals_atoms_alist);
}

View File

@ -30,5 +30,9 @@ void lisp_addr_of(lisp_cons* cons, lisp_value* value);
void lisp_set(lisp_cons* cons, lisp_value* value);
void lisp_fun(lisp_cons* cons, lisp_value* value);
void lisp_internals_syms_alist(lisp_cons* cons, lisp_value* value);
void lisp_internals_funs_alist(lisp_cons* cons, lisp_value* value);
void lisp_internals_atoms_alist(lisp_cons* cons, lisp_value* value);
void init_native_funs();
#endif