Add list, quote
diff --git a/src/lisp/compiler.dasc b/src/lisp/compiler.dasc
index bc5aec8..32e2713 100644
--- a/src/lisp/compiler.dasc
+++ b/src/lisp/compiler.dasc
@@ -224,6 +224,23 @@
return n;
}
+void compile_backquote(struct environment *env, struct local *local,
+ value_t val, dasm_State **Dst)
+{
+ if (!listp(val))
+ {
+ | mov eax, (val);
+ }
+ else
+ {
+ value_t fsym = car(val),
+ args = cdr(val);
+ int nargs = length(args);
+
+ // TODO
+ }
+}
+
void compile_expression(struct environment *env, struct local *local,
value_t val, dasm_State **Dst)
{
@@ -311,6 +328,42 @@
| run_gc;
}
+ else if (symstreq(fsym, "quote"))
+ {
+ if (nargs != 1)
+ err("quote should take exactly 1 argument");
+
+ // Simple!
+ | mov eax, (car(args));
+ }
+ else if (symstreq(fsym, "backquote"))
+ {
+ if (nargs != 1)
+ err("backquote should take exactly 1 argument");
+
+ compile_backquote(env, local, car(args), Dst);
+ }
+ else if (symstreq(fsym, "list"))
+ {
+ | push (nil);
+
+ for (int i = nargs - 1; i >= 0; i--)
+ {
+ compile_expression(env, local, elt(args, i), Dst);
+
+ // push the ith item
+ | push eax;
+ // cons the top two stack items
+ | mov ebx, (cons);
+ | call ebx;
+ // remove the stack items from use
+ | add esp, (2 * value_size);
+ // put the new thing on the stack
+ | push eax;
+ }
+
+ | pop eax;
+ }
else
{
struct function *func =
diff --git a/src/lisp/compiler.h b/src/lisp/compiler.h
index 465c9fb..1cbd92d 100644
--- a/src/lisp/compiler.h
+++ b/src/lisp/compiler.h
@@ -56,8 +56,16 @@
void compile_expression(struct environment *env, struct local *local,
value_t val, dasm_State **Dst);
+
+/**
+ * Compile a backquoted expression
+ */
+void compile_backquote(struct environment *env, struct local *local,
+ value_t val, dasm_State **Dst);
+
void compile_expr_to_func(struct environment *env, char *name, value_t val,
dasm_State **Dst);
+
int nextpc(struct local *local, dasm_State **Dst);
// Local utilities
diff --git a/src/lisp/gc.c b/src/lisp/gc.c
index 2bdac4c..16ec471 100644
--- a/src/lisp/gc.c
+++ b/src/lisp/gc.c
@@ -20,8 +20,6 @@
void *pointer = (void *)(value & ~HEAP_MASK);
struct alloc *alloc = pointer - sizeof(struct alloc);
- fprintf(stderr, "[ GC ] Marking 0x%p\n", pointer);
-
// Only recursively mark if this hasn't been marked yet. i.e. prevent
// marking circular references twice
if (alloc->mark != gc_mark)
@@ -63,9 +61,6 @@
}
else
{
- printf("Freeing:\n");
- printval(alloc_to_value(a), 2);
-
// Free and remove from allocation list
struct alloc *p = a->prev, *n = a->next;
free_aligned(a);
@@ -90,8 +85,6 @@
gc_mark++;
- fprintf(stderr, "[ GC ] %d (esp 0x%p, ebp 0x%p)\n", gc_mark, esp_p, ebp_p);
-
// For every stack frame until the base of the stack
while (esp_p < gc_base)
{
@@ -111,8 +104,6 @@
esp_p += 2;
}
- fprintf(stderr, "Marked %d\n", num_marked);
-
_sweep();
}
diff --git a/src/lisp/lisp.c b/src/lisp/lisp.c
index 5006aa3..30b2861 100644
--- a/src/lisp/lisp.c
+++ b/src/lisp/lisp.c
@@ -309,7 +309,7 @@
symbol = symval("unquote");
break;
case '@':
- symbol = symval("splice");
+ symbol = symval("unquote-splice");
break;
}
diff --git a/src/lisp/test.lisp b/src/lisp/test.lisp
index 3c8f9ea..ea78d4f 100644
--- a/src/lisp/test.lisp
+++ b/src/lisp/test.lisp
@@ -11,11 +11,10 @@
(print a))
; These allocations should be freed
- (cons 12 (cons 34 (cons 45 nil)))
+ (list 12 34 56)
+ (list "a" "b" "c" "d")
; But these should not
(let1 (unused-but-bound (cons 5 6))
- (let1 (val (cons 1 (cons 2 (cons 3 nil))))
+ (let1 (val '(a b c d e))
(calls-gc val))))
-
-'(hello)
\ No newline at end of file