-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.c
More file actions
67 lines (61 loc) · 1.3 KB
/
debug.c
File metadata and controls
67 lines (61 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdlib.h>
#include <stdio.h>
#include "lisp.h"
void dump(Value *v, int indent)
{
switch (v->type) {
default:
printf("[type %d]", v->type); break;
case TNil:
printf("nil"); break;
case TFunc:
printf("[func 0x%08x]", (unsigned)(long unsigned)v->func); break;
case TWeak:
printf("[ref 0x%08x]", (unsigned)(long unsigned)v->weak); break;
case TNumber:
printf("%lg", v->number); break;
case TSymbol:
fwrite(v->symbol->d, sizeof(char), v->symbol->len, stdout); break;
case TString:
putchar('\"');
fwrite(v->string->d, sizeof(char), v->string->len, stdout);
putchar('\"');
break;
case TList: {
int i, j;
putchar('(');
for (i = 0; i < v->list->len; i++) {
dump(&list(v, i), indent+1);
if (i + 1 < v->list->len) {
if (islist(list(v, i))) { /* indentation formatting part */
putchar('\n');
for (j = 0; j <= indent; j++)
putchar(' ');
} else {
putchar(' ');
}
}
}
putchar(')');
}
break;
}
}
Value eval_write(Value *ctx, Value *args)
{
Value v = nil;
if (args->list->len > 1)
set(&v, eval(ctx, &list(args, 1)));
else
set(&v, *ctx);
dump(&v, 0);
unmark(&v);
putchar('\n');
return v;
}
Value eval_debug(Value *ctx, Value *args)
{
extern int _objects;
printf("objects in memory: %d\n", _objects);
return nil;
}