add fixnum

This commit is contained in:
Yuichi Nishiwaki 2013-10-12 00:15:46 +09:00
parent 6b0c1aa668
commit 03fbd0bdb6
4 changed files with 21 additions and 3 deletions

View File

@ -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)

View File

@ -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;
%%

View File

@ -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;
}

View File

@ -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;
}
}