add parameter primitives: (picrin parameter) library

This commit is contained in:
Yuichi Nishiwaki 2014-01-09 00:39:13 +09:00
parent d7c510ae40
commit a9f4eff13e
7 changed files with 24 additions and 2 deletions

View File

@ -93,7 +93,8 @@ enum pic_tt {
PIC_TT_SENV,
PIC_TT_SYNTAX,
PIC_TT_SC,
PIC_TT_LIB
PIC_TT_LIB,
PIC_TT_VAR
};
#define PIC_OBJECT_HEADER \

View File

@ -673,7 +673,8 @@ codegen(codegen_state *state, pic_value obj, bool tailpos)
case PIC_TT_SENV:
case PIC_TT_SYNTAX:
case PIC_TT_SC:
case PIC_TT_LIB: {
case PIC_TT_LIB:
case PIC_TT_VAR: {
pic_error(pic, "invalid expression given");
}
}

View File

@ -10,6 +10,7 @@
#include "picrin/error.h"
#include "picrin/macro.h"
#include "picrin/lib.h"
#include "picrin/var.h"
#include "xhash/xhash.h"
#if GC_DEBUG
@ -403,6 +404,14 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
gc_mark_object(pic, (struct pic_object *)lib->senv);
break;
}
case PIC_TT_VAR: {
struct pic_var *var = (struct pic_var *)obj;
gc_mark(pic, var->value);
if (var->conv) {
gc_mark_object(pic, (struct pic_object *)var->conv);
}
break;
}
case PIC_TT_NIL:
case PIC_TT_BOOL:
case PIC_TT_FLOAT:
@ -539,6 +548,9 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj)
xh_destory(lib->exports);
break;
}
case PIC_TT_VAR: {
break;
}
case PIC_TT_NIL:
case PIC_TT_BOOL:
case PIC_TT_FLOAT:

View File

@ -22,6 +22,7 @@ void pic_init_char(pic_state *);
void pic_init_error(pic_state *);
void pic_init_str(pic_state *);
void pic_init_macro(pic_state *);
void pic_init_var(pic_state *);
void
pic_load_stdlib(pic_state *pic)
@ -124,6 +125,7 @@ pic_init_core(pic_state *pic)
pic_init_error(pic); DONE;
pic_init_str(pic); DONE;
pic_init_macro(pic); DONE;
pic_init_var(pic); DONE;
pic_load_stdlib(pic); DONE;

View File

@ -560,6 +560,7 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv)
case PIC_TT_SENV:
case PIC_TT_SYNTAX:
case PIC_TT_LIB:
case PIC_TT_VAR:
pic_error(pic, "unexpected value type");
return pic_undef_value(); /* unreachable */
}

View File

@ -112,6 +112,9 @@ write(pic_state *pic, pic_value obj)
case PIC_TT_LIB:
printf("#<library %p>", pic_ptr(obj));
break;
case PIC_TT_VAR:
printf("#<var %p>", pic_ptr(obj));
break;
}
}

View File

@ -78,6 +78,8 @@ pic_type_repr(enum pic_tt tt)
return "syntax";
case PIC_TT_LIB:
return "lib";
case PIC_TT_VAR:
return "var";
}
/* logic flaw */
abort();