Experimenting with a macro type

This commit is contained in:
Justin Ethier 2015-08-11 22:26:20 -04:00
parent 089e97cf99
commit 894dc6b6d2
2 changed files with 19 additions and 1 deletions

View file

@ -75,6 +75,7 @@ typedef long tag_type;
#define boolean_tag 15
#define cvar_tag 16
#define vector_tag 17
#define macro_tag 18
#define nil NULL
#define eq(x,y) (x == y)
@ -212,6 +213,7 @@ cons_type n; n.tag = cons_tag; n.cons_car = a; n.cons_cdr = d;
/* Closure types */
typedef struct {tag_type tag; function_type fn; int num_args; } macro_type;
typedef struct {tag_type tag; function_type fn; int num_args; } closure0_type;
typedef struct {tag_type tag; function_type fn; int num_args; object elt1;} closure1_type;
typedef struct {tag_type tag; function_type fn; int num_args; object elt1,elt2;} closure2_type;
@ -226,7 +228,9 @@ typedef closure3_type *closure3;
typedef closure4_type *closure4;
typedef closureN_type *closureN;
typedef closure0_type *closure;
typedef closure0_type *macro;
#define mmacro(c,f) macro_type c; c.tag = macro_tag; c.fn = f; c.num_args = -1;
#define mclosure0(c,f) closure0_type c; c.tag = closure0_tag; c.fn = f; c.num_args = -1;
#define mclosure1(c,f,a) closure1_type c; c.tag = closure1_tag; \
c.fn = f; c.num_args = -1; c.elt1 = a;

View file

@ -418,7 +418,8 @@ object Cyc_display(object x, FILE *port)
if (nullp(x)) {fprintf(port, "()"); return quote_void;}
if (obj_is_char(x)) {fprintf(port, "%c", obj_obj2char(x)); return quote_void;}
switch (type_of(x))
{case closure0_tag:
{case macro_tag:
case closure0_tag:
case closure1_tag:
case closure2_tag:
case closure3_tag:
@ -1852,6 +1853,7 @@ object apply(object cont, object func, object args){
// TODO: should probably check arg counts and error out if needed
((primitive_type *)func)->fn(cont, args);
break;
case macro_tag:
case closure0_tag:
case closure1_tag:
case closure2_tag:
@ -1962,6 +1964,13 @@ char *transport(x, gcgen) char *x; int gcgen;
forward(x) = nx; type_of(x) = forward_tag;
allocp = ((char *) nx)+sizeof(cons_type);
return (char *) nx;}
case macro_tag:
{register macro nx = (macro) allocp;
type_of(nx) = macro_tag; nx->fn = ((macro) x)->fn;
nx->num_args = ((macro) x)->num_args;
forward(x) = nx; type_of(x) = forward_tag;
allocp = ((char *) nx)+sizeof(macro_type);
return (char *) nx;}
case closure0_tag:
{register closure0 nx = (closure0) allocp;
type_of(nx) = closure0_tag; nx->fn = ((closure0) x)->fn;
@ -2200,6 +2209,11 @@ void GC_loop(int major, closure cont, object *ans, int num_ans)
#endif
transp(car(scanp)); transp(cdr(scanp));
scanp += sizeof(cons_type); break;
case macro_tag:
#if DEBUG_GC
printf("DEBUG transport macro \n");
#endif
scanp += sizeof(macro_type); break;
case closure0_tag:
#if DEBUG_GC
printf("DEBUG transport closure0 \n");