aboutsummaryrefslogtreecommitdiff
path: root/lisp/lisp.h
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2025-05-14 21:12:58 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2025-05-15 22:25:45 +0100
commit12de1e8db90bccd5a0eefd21075f07c7b7e3dfaa (patch)
tree0434141f2bfd24207a2864f613a1c2e3ee7181fc /lisp/lisp.h
parentba5c0a4579ece5d53c009a14d00e683e70b982f4 (diff)
downloadoats-12de1e8db90bccd5a0eefd21075f07c7b7e3dfaa.tar.gz
oats-12de1e8db90bccd5a0eefd21075f07c7b7e3dfaa.tar.bz2
oats-12de1e8db90bccd5a0eefd21075f07c7b7e3dfaa.zip
Refactor for cleanliness
Move files into separate folders for ease of reading, include source directory so we can use angle bracket includes, adjust build system to make directories for objects
Diffstat (limited to 'lisp/lisp.h')
-rw-r--r--lisp/lisp.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/lisp/lisp.h b/lisp/lisp.h
new file mode 100644
index 0000000..2892bdb
--- /dev/null
+++ b/lisp/lisp.h
@@ -0,0 +1,57 @@
+/* Copyright (C) 2025 Aryadev Chavali
+
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License Version 2 for
+ * details.
+
+ * You may distribute and modify this code under the terms of the GNU General
+ * Public License Version 2, which you should have received a copy of along with
+ * this program. If not, please go to <https://www.gnu.org/licenses/>.
+
+ * Created: 2025-04-06
+ * Description: Object model where we deal with contexts
+ */
+
+#ifndef LISP_H
+#define LISP_H
+
+#include <lib/sv.h>
+#include <lib/vec.h>
+#include <lisp/context.h>
+#include <lisp/tag.h>
+
+typedef struct Cons
+{
+ lisp_t *car, *cdr;
+} cons_t;
+
+typedef struct Cell
+{
+ u64 size;
+ u8 data[];
+} cell_t;
+
+lisp_t *make_int(i64 integer);
+lisp_t *make_sym(context_t *ctx, char *data, u64 size);
+lisp_t *make_cons(context_t *ctx, lisp_t *car, lisp_t *cdr);
+lisp_t *make_list(context_t *ctx, lisp_t **lisps, u64 size);
+lisp_t *make_vec(context_t *ctx, u32 size);
+lisp_t *make_str(context_t *ctx, char *data, u64 size);
+
+i64 as_int(lisp_t *obj);
+u32 as_char(lisp_t *obj);
+cell_t *as_sym(lisp_t *obj);
+void as_ssym(lisp_t *obj, sv_t *sv);
+bool as_bool(lisp_t *obj);
+f64 as_float(lisp_t *obj);
+cons_t *as_cons(lisp_t *obj);
+vec_t *as_vec(lisp_t *obj);
+vec_t *as_str(lisp_t *obj);
+
+sv_t serialise(context_t *ctx, lisp_t *lisp);
+
+#define CAR(PTR) (as_cons(PTR)->car)
+#define CDR(PTR) (as_cons(PTR)->cdr)
+
+#endif