2021-09-22 13:54:29 +00:00
|
|
|
#ifndef _MAIN_H
|
|
|
|
#define _MAIN_H
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "dbg_malloc.h"
|
|
|
|
#include "lisp_types.h"
|
|
|
|
#include "lisp_string.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "native_funs.h"
|
|
|
|
|
|
|
|
/* LISP_USE_ATOMS_ALIST:
|
|
|
|
* If enabled, atom names will be stored in atoms_alist.
|
|
|
|
* This assists debugging and reflection, but makes atom evaluation
|
2022-02-04 19:14:24 +00:00
|
|
|
* slightly slower and uses more memory. */
|
2021-09-22 13:54:29 +00:00
|
|
|
#define LISP_USE_ATOMS_ALIST
|
|
|
|
|
|
|
|
extern lisp_cons* syms_alist;
|
|
|
|
extern lisp_cons* funs_alist;
|
|
|
|
extern lisp_cons* atoms_alist;
|
|
|
|
|
|
|
|
bool lisp_is_nil(lisp_value value);
|
|
|
|
bool lisp_is_equal(lisp_value a, lisp_value b);
|
|
|
|
|
|
|
|
void lisp_cons_join(lisp_cons* head, lisp_cons* tail);
|
|
|
|
__attribute__((always_inline)) static inline lisp_cons* lisp_cons_pop(lisp_cons** head) {
|
|
|
|
lisp_cons* old_head = *head;
|
|
|
|
*head = old_head->cdr.value.cons;
|
|
|
|
return old_head;
|
|
|
|
}
|
|
|
|
|
2022-02-04 19:14:24 +00:00
|
|
|
#define LISP_FFLAG_RAWARG 0x1
|
|
|
|
#define LISP_FFLAG_EVALRES 0x2
|
|
|
|
#define LISP_FFLAG_EARLY 0x4
|
|
|
|
|
2021-09-22 13:54:29 +00:00
|
|
|
extern lisp_atom atom_t;
|
|
|
|
extern lisp_atom atom_quote;
|
|
|
|
|
|
|
|
extern lisp_atom atom_cons;
|
|
|
|
extern lisp_atom atom_atom;
|
|
|
|
extern lisp_atom atom_int;
|
|
|
|
extern lisp_atom atom_float;
|
|
|
|
extern lisp_atom atom_string;
|
|
|
|
extern lisp_atom atom_native_fun;
|
|
|
|
|
|
|
|
lisp_atom lisp_atomize(lisp_string* atom_lstr);
|
|
|
|
|
|
|
|
lisp_cons** lisp_alist_getptr(lisp_cons* alist, lisp_value key);
|
|
|
|
lisp_cons* lisp_alist_get(lisp_cons* alist, lisp_value key);
|
|
|
|
lisp_cons* lisp_alist_put(lisp_cons** alist, lisp_cons* pair);
|
|
|
|
lisp_cons* lisp_alist_del(lisp_cons** alist, lisp_value key);
|
|
|
|
|
2021-09-28 22:53:30 +00:00
|
|
|
void print_cons(lisp_cons* cons);
|
|
|
|
void print_value(lisp_value value);
|
2021-09-22 13:54:29 +00:00
|
|
|
|
2022-02-04 19:14:24 +00:00
|
|
|
lisp_cons* lisp_create_fundef(lisp_atom atom, long flags, lisp_value fun);
|
2021-09-22 13:54:29 +00:00
|
|
|
lisp_atom lisp_defun_native(lisp_string* lstr, lisp_native_fun funptr);
|
2022-02-04 19:14:24 +00:00
|
|
|
lisp_cons* lisp_defun(lisp_atom atom, lisp_cons* fun);
|
|
|
|
|
|
|
|
lisp_atom lisp_defun_special_native(lisp_string* lstr, long flags, lisp_native_fun funptr);
|
|
|
|
lisp_cons* lisp_defun_special(lisp_atom atom, long flags, lisp_cons* fun);
|
2021-09-22 13:54:29 +00:00
|
|
|
|
|
|
|
void lisp_evaluate_value(lisp_value input, lisp_value* result);
|
|
|
|
void lisp_evaluate(lisp_cons* cons, lisp_value* value);
|
|
|
|
extern lisp_atom atom_cond;
|
2021-09-23 13:51:39 +00:00
|
|
|
void lisp_sform_cond(lisp_cons* cons, lisp_value* value);
|
2021-09-23 16:57:26 +00:00
|
|
|
extern lisp_atom atom_let;
|
|
|
|
void lisp_sform_let(lisp_cons* cons, lisp_value* value);
|
2022-02-04 15:54:34 +00:00
|
|
|
extern lisp_atom atom_defun;
|
|
|
|
void lisp_sform_defun(lisp_cons* cons, lisp_value* value);
|
2022-02-04 19:14:24 +00:00
|
|
|
extern lisp_atom atom_defmacro;
|
|
|
|
void lisp_sform_defmacro(lisp_cons* cons, lisp_value* value);
|
|
|
|
|
2022-02-04 15:54:34 +00:00
|
|
|
lisp_cons* recursive_copy(lisp_cons* cons);
|
|
|
|
|
2022-02-04 19:14:24 +00:00
|
|
|
void lisp_evaluate_defun(lisp_cons* fun, lisp_cons* args, lisp_value* value);
|
2021-09-22 13:54:29 +00:00
|
|
|
|
|
|
|
#endif
|