aboutsummaryrefslogtreecommitdiff
path: root/src/value.h
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2024-08-23 19:55:13 +0300
committerkartofen <mladenovnasko0@gmail.com>2024-08-23 19:55:13 +0300
commit68a62ad356603d64d537e231f06b5d9445e79abe (patch)
tree3682d6b607fed96eafaf7e218d85a03fbc71d914 /src/value.h
usefull commit message
Diffstat (limited to 'src/value.h')
-rw-r--r--src/value.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/value.h b/src/value.h
new file mode 100644
index 0000000..c2f43e3
--- /dev/null
+++ b/src/value.h
@@ -0,0 +1,66 @@
+#ifndef VALUE_H
+#define VALUE_H
+
+#include "lexer.h"
+#include "env.h"
+
+typedef struct value * value_t;
+#define VALUE_EMPTY NULL
+
+typedef value_t (*builtin_proc_t)(value_t *args);
+
+#define VALUE_TYPES(X) \
+ X(VALUE_NIL) \
+ X(VALUE_ATOM) \
+ X(VALUE_STR) \
+ X(VALUE_INT) \
+ X(VALUE_CONS) \
+ X(VALUE_PROC) \
+ X(VALUE_PROC_BUILTIN)
+
+#define TO_ENUM(type) type,
+#define TO_STRING(type) #type,
+
+extern const char * const value_type_string[];
+
+struct value {
+ enum value_type {
+ VALUE_TYPES(TO_ENUM)
+ } type;
+
+ union value_union {
+ char *atom;
+ char *str;
+ int num;
+
+ struct cons {
+ value_t left;
+ value_t right;
+ } cons;
+
+ struct proc {
+ size_t argc;
+ value_t *arg_keys;
+ env_t parent_env;
+
+ size_t body_len;
+ struct token *body;
+ } proc;
+
+ struct proc_builtin {
+ size_t argc;
+ builtin_proc_t proc;
+ } proc_builtin;
+ } value;
+
+ size_t refs;
+};
+
+value_t value_create(enum value_type type, void * value);
+void value_destroy(value_t value);
+
+value_t value_from_token(struct token *token);
+value_t value_copy(value_t value);
+int value_string(value_t value, size_t buf_sz, char *buf);
+
+#endif