summaryrefslogtreecommitdiff
path: root/lisp.h
diff options
context:
space:
mode:
authorFelix Perktold <Felix.Perktold@student.uibk.ac.at>2025-12-21 17:00:37 +0100
committerFelix Perktold <Felix.Perktold@student.uibk.ac.at>2025-12-21 17:00:37 +0100
commit47debf8cc2197187a347b43a795120638b017d5f (patch)
tree8e20ef789acc0ff398df5f793dbd7be3c055c9fb /lisp.h
parent20b1cea7a74a4feb759155eedbb6299bd891a325 (diff)
renamed enum values VALTYPE->VT, implemented lambdas, apply
Diffstat (limited to 'lisp.h')
-rw-r--r--lisp.h26
1 files changed, 18 insertions, 8 deletions
diff --git a/lisp.h b/lisp.h
index 6ebf9a2..a43f750 100644
--- a/lisp.h
+++ b/lisp.h
@@ -1,16 +1,19 @@
#ifndef LISP_H
#define LISP_H
+typedef struct value value;
+typedef struct env env;
+
typedef enum {
- VALTYPE_INT,
- VALTYPE_DOUBLE,
- VALTYPE_SYMBOL,
- VALTYPE_STRING,
- VALTYPE_NIL,
- VALTYPE_PAIR
+ VT_INT,
+ VT_DOUBLE,
+ VT_SYMBOL,
+ VT_STRING,
+ VT_NIL,
+ VT_PAIR,
+ VT_LAMBDA
} val_type;
-typedef struct value value;
struct value {
val_type type;
union {
@@ -22,6 +25,11 @@ struct value {
value *car;
value *cdr;
} pair;
+ struct {
+ value *params;
+ value *body;
+ env *env;
+ } lambda;
} as;
};
@@ -30,6 +38,7 @@ value *make_double(double d);
value *make_symbol(const char *sym);
value *make_string(const char *str);
value *make_nil();
+value *make_lambda(env *e, value *params, value *body);
value *cons(value *car, value *cdr);
value *car(value *cons);
value *cdr(value *cons);
@@ -37,7 +46,6 @@ value *cdr(value *cons);
void *print_value(value *val);
// environments, TODO: make this use hashtable
// symbol->val
-typedef struct env env;
typedef struct env {
const char *symbol;
value *value;
@@ -54,4 +62,6 @@ extern env *global_env;
value *eval(env *e, value *val);
value *eval_pair(env *e, value *val);
+value *apply(value *lambda, value *args);
+
#endif