indentation for pretty printer
This commit is contained in:
parent
38b044921f
commit
c8b6f12851
20
main.c
20
main.c
|
@ -745,7 +745,7 @@ static void init_gc(void)
|
|||
alloc_of_type(&empty_list, EMPTY_LIST);
|
||||
}
|
||||
|
||||
static void display(struct uns_ctr *ctr)
|
||||
static void display(struct uns_ctr *ctr, long indent)
|
||||
{
|
||||
struct uns_ctr tmp = {0};
|
||||
long l;
|
||||
|
@ -762,13 +762,21 @@ static void display(struct uns_ctr *ctr)
|
|||
|
||||
printf("(");
|
||||
tmp.p = gc.record_get_ptr(ctr->p, 1);
|
||||
display(&tmp);
|
||||
display(&tmp, indent);
|
||||
|
||||
ctr->p = gc.record_get_ptr(ctr->p, 2);
|
||||
while (get_type(ctr->p) == CELL) {
|
||||
printf(" ");
|
||||
tmp.p = gc.record_get_ptr(ctr->p, 1);
|
||||
display(&tmp);
|
||||
if (get_type(tmp.p) == CELL) {
|
||||
printf("\n");
|
||||
for (l = 0; l < indent; l++)
|
||||
printf(" ");
|
||||
display(&tmp, indent + 1);
|
||||
} else {
|
||||
printf(" ");
|
||||
display(&tmp, indent);
|
||||
}
|
||||
|
||||
ctr->p = gc.record_get_ptr(ctr->p, 2);
|
||||
}
|
||||
|
||||
|
@ -778,7 +786,7 @@ static void display(struct uns_ctr *ctr)
|
|||
break;
|
||||
default:
|
||||
printf(" . ");
|
||||
display(ctr);
|
||||
display(ctr, indent);
|
||||
printf(")");
|
||||
break;
|
||||
}
|
||||
|
@ -861,7 +869,7 @@ int main(void)
|
|||
switch (expr_parse(stdin, &expr)) {
|
||||
case EXPR_PARSE_OK:
|
||||
expr.p = gc.record_get_ptr(expr.p, 0);
|
||||
display(&expr);
|
||||
display(&expr, 1);
|
||||
printf("\n");
|
||||
break;
|
||||
case EXPR_PARSE_INCOMPLETE:
|
||||
|
|
15
prelude.scm
15
prelude.scm
|
@ -31,7 +31,6 @@
|
|||
; __define-macro: Like __define but for macros
|
||||
; set!
|
||||
; __exec: apply an argument to a lambda and return it to the continuation.
|
||||
; __continue-if: continuation version of if.
|
||||
;
|
||||
; Others:
|
||||
; <undefined>: A value that can only be passed to __unilambda. It cannot
|
||||
|
@ -41,12 +40,18 @@
|
|||
;
|
||||
; Macros are functions that return an sexpr.
|
||||
|
||||
; (define (__exec function argument continuation)
|
||||
; (continuation (function argument))
|
||||
; )
|
||||
|
||||
; __continuation-if runs the first continuation if the argument is true,
|
||||
; and the second if the argument is false.
|
||||
(__define-macro if
|
||||
(__unilambda l
|
||||
(__continue-if (car l)
|
||||
(__unilambda <undefined> (car (cdr l)))
|
||||
(__unilambda <undefined> (car (cdr (cdr l))))
|
||||
)
|
||||
`(__continue-if ,(car l)
|
||||
(__unilambda <undefined> ,(car (cdr l)))
|
||||
(__unilambda <undefined> ,(car (cdr (cdr l))))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
|
Reference in New Issue