mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 20:45:06 +02:00
Experimenting with a macro type
This commit is contained in:
parent
089e97cf99
commit
894dc6b6d2
2 changed files with 19 additions and 1 deletions
|
@ -75,6 +75,7 @@ typedef long tag_type;
|
||||||
#define boolean_tag 15
|
#define boolean_tag 15
|
||||||
#define cvar_tag 16
|
#define cvar_tag 16
|
||||||
#define vector_tag 17
|
#define vector_tag 17
|
||||||
|
#define macro_tag 18
|
||||||
|
|
||||||
#define nil NULL
|
#define nil NULL
|
||||||
#define eq(x,y) (x == y)
|
#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 */
|
/* 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; } 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;} closure1_type;
|
||||||
typedef struct {tag_type tag; function_type fn; int num_args; object elt1,elt2;} closure2_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 closure4_type *closure4;
|
||||||
typedef closureN_type *closureN;
|
typedef closureN_type *closureN;
|
||||||
typedef closure0_type *closure;
|
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 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; \
|
#define mclosure1(c,f,a) closure1_type c; c.tag = closure1_tag; \
|
||||||
c.fn = f; c.num_args = -1; c.elt1 = a;
|
c.fn = f; c.num_args = -1; c.elt1 = a;
|
||||||
|
|
16
runtime.c
16
runtime.c
|
@ -418,7 +418,8 @@ object Cyc_display(object x, FILE *port)
|
||||||
if (nullp(x)) {fprintf(port, "()"); return quote_void;}
|
if (nullp(x)) {fprintf(port, "()"); return quote_void;}
|
||||||
if (obj_is_char(x)) {fprintf(port, "%c", obj_obj2char(x)); return quote_void;}
|
if (obj_is_char(x)) {fprintf(port, "%c", obj_obj2char(x)); return quote_void;}
|
||||||
switch (type_of(x))
|
switch (type_of(x))
|
||||||
{case closure0_tag:
|
{case macro_tag:
|
||||||
|
case closure0_tag:
|
||||||
case closure1_tag:
|
case closure1_tag:
|
||||||
case closure2_tag:
|
case closure2_tag:
|
||||||
case closure3_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
|
// TODO: should probably check arg counts and error out if needed
|
||||||
((primitive_type *)func)->fn(cont, args);
|
((primitive_type *)func)->fn(cont, args);
|
||||||
break;
|
break;
|
||||||
|
case macro_tag:
|
||||||
case closure0_tag:
|
case closure0_tag:
|
||||||
case closure1_tag:
|
case closure1_tag:
|
||||||
case closure2_tag:
|
case closure2_tag:
|
||||||
|
@ -1962,6 +1964,13 @@ char *transport(x, gcgen) char *x; int gcgen;
|
||||||
forward(x) = nx; type_of(x) = forward_tag;
|
forward(x) = nx; type_of(x) = forward_tag;
|
||||||
allocp = ((char *) nx)+sizeof(cons_type);
|
allocp = ((char *) nx)+sizeof(cons_type);
|
||||||
return (char *) nx;}
|
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:
|
case closure0_tag:
|
||||||
{register closure0 nx = (closure0) allocp;
|
{register closure0 nx = (closure0) allocp;
|
||||||
type_of(nx) = closure0_tag; nx->fn = ((closure0) x)->fn;
|
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
|
#endif
|
||||||
transp(car(scanp)); transp(cdr(scanp));
|
transp(car(scanp)); transp(cdr(scanp));
|
||||||
scanp += sizeof(cons_type); break;
|
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:
|
case closure0_tag:
|
||||||
#if DEBUG_GC
|
#if DEBUG_GC
|
||||||
printf("DEBUG transport closure0 \n");
|
printf("DEBUG transport closure0 \n");
|
||||||
|
|
Loading…
Add table
Reference in a new issue