diff options
| author | Mistivia <i@mistivia.com> | 2025-06-17 09:12:35 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-06-17 09:12:35 +0800 |
| commit | 6f1cfbda4a519ad8a232d126539a2732ab43c671 (patch) | |
| tree | fe33602e4dd8419b216ca755ea91c63c72ffa65b /src/sexp.h | |
init
Diffstat (limited to 'src/sexp.h')
| -rw-r--r-- | src/sexp.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/sexp.h b/src/sexp.h new file mode 100644 index 0000000..dfbc4d9 --- /dev/null +++ b/src/sexp.h @@ -0,0 +1,80 @@ +#ifndef BAMBOO_LISP_SEXP_H_ +#define BAMBOO_LISP_SEXP_H_ + +#include <stdint.h> +#include <stdbool.h> + +#include <algds/vec.h> + +struct sexp; +typedef struct sexp SExp; + +typedef struct { + int idx; +} SExpRef; + +typedef struct { + SExpRef car; + SExpRef cdr; +} SExpPair; + +typedef struct { + SExpRef args; + SExpRef body; +} SExpFunc; + +typedef struct { + SExpRef args; + SExpRef body; +} SExpMacro; + +typedef struct { + SExpRef parent; + SExpRef child; + SExpRef bindings; +} SExpEnv; + +typedef struct { + SExpRef name; + SExpRef value; + SExpRef func; + SExpRef next; +} SExpBinding; + +typedef enum { + kIntegerSExp, + kRealSExp, + kBooleanSExp, + kNumberSExp, + kCharSExp, + kStringSExp, + kSymbolSExp, + kUserDataSExp, + kPairSExp, + kFuncSExp, + kEnvSExp, + kBindingSExp, + kMacroSExp, +} SExpType; + +struct sexp { + SExpType type; + union { + int64_t integer; + double real; + bool boolean; + char character; + const char *str; + const void *userdata; + SExpPair pair; + SExpFunc func; + SExpEnv env; + }; +}; + +void SExp_show(SExp self, FILE* fp); + +VECTOR_DEF(SExp); + +#endif + |
