diff --git a/include/picrin/value.h b/include/picrin/value.h index adc135b4..d155674b 100644 --- a/include/picrin/value.h +++ b/include/picrin/value.h @@ -3,6 +3,7 @@ enum pic_vtype { PIC_VTYPE_NIL, + PIC_VTYPE_INT, PIC_VTYPE_HEAP }; @@ -10,12 +11,14 @@ typedef struct { enum pic_vtype type; union { void *data; + int i; } u; } pic_value; enum pic_tt { /* immediate */ PIC_TT_NIL, + PIC_TT_INT, /* heap */ PIC_TT_PAIR, PIC_TT_SYMBOL @@ -46,6 +49,9 @@ enum pic_tt pic_type(pic_value); pic_value pic_nil_value(); pic_value pic_obj_value(void *); +pic_value pic_int_value(int); + +#define pic_int(v) ((v).u.i) #define pic_nil_p(v) (pic_type(v) == PIC_TT_NIL) diff --git a/src/scan.l b/src/scan.l index cd8077fe..27416a63 100644 --- a/src/scan.l +++ b/src/scan.l @@ -15,7 +15,6 @@ struct parser_control { "(" return tLPAREN; ")" return tRPAREN; [a-z0-9A-Z]+ { yylval.datum = pic_intern_cstr(p->pic, yytext); return tSYMBOL; } -"'" return tQUOTE; %% diff --git a/src/value.c b/src/value.c index 7c6c1604..7c5c6acc 100644 --- a/src/value.c +++ b/src/value.c @@ -6,6 +6,8 @@ pic_type(pic_value v) switch (v.type) { case PIC_VTYPE_NIL: return PIC_TT_NIL; + case PIC_VTYPE_INT: + return PIC_TT_INT; case PIC_VTYPE_HEAP: return ((struct pic_object *)v.u.data)->tt; } @@ -30,3 +32,13 @@ pic_obj_value(void *ptr) v.u.data = ptr; return v; } + +pic_value +pic_int_value(int i) +{ + pic_value v; + + v.type = PIC_VTYPE_INT; + v.u.i = i; + return v; +} diff --git a/src/write.c b/src/write.c index bc4483e3..c920e455 100644 --- a/src/write.c +++ b/src/write.c @@ -20,7 +20,8 @@ pic_debug(pic_state *pic, pic_value obj) case PIC_TT_SYMBOL: printf("%s", pic_symbol_ptr(obj)->name); break; - default: - abort(); + case PIC_TT_INT: + printf("%d", pic_int(obj)); + break; } }