add #<undef>

This commit is contained in:
Yuichi Nishiwaki 2013-10-12 14:40:01 +09:00
parent 8d23ef666f
commit b284973035
4 changed files with 23 additions and 0 deletions

View File

@ -4,6 +4,7 @@
enum pic_vtype {
PIC_VTYPE_NIL,
PIC_VTYPE_INT,
PIC_VTYPE_UNDEF,
PIC_VTYPE_HEAP
};
@ -19,6 +20,7 @@ enum pic_tt {
/* immediate */
PIC_TT_NIL,
PIC_TT_INT,
PIC_TT_UNDEF,
/* heap */
PIC_TT_PAIR,
PIC_TT_SYMBOL
@ -48,6 +50,7 @@ struct pic_symbol {
enum pic_tt pic_type(pic_value);
pic_value pic_nil_value();
pic_value pic_undef_value();
pic_value pic_obj_value(void *);
pic_value pic_int_value(int);

View File

@ -8,6 +8,8 @@ pic_type(pic_value v)
return PIC_TT_NIL;
case PIC_VTYPE_INT:
return PIC_TT_INT;
case PIC_VTYPE_UNDEF:
return PIC_TT_UNDEF;
case PIC_VTYPE_HEAP:
return ((struct pic_object *)v.u.data)->tt;
}
@ -42,3 +44,13 @@ pic_int_value(int i)
v.u.i = i;
return v;
}
pic_value
pic_undef_value()
{
pic_value v;
v.type = PIC_VTYPE_UNDEF;
v.u.data = NULL;
return v;
}

View File

@ -5,6 +5,7 @@
enum pic_instruction {
OP_PUSHNIL,
OP_PUSHI,
OP_PUSHUNDEF,
OP_CONS,
OP_ADD,
OP_STOP
@ -114,6 +115,10 @@ pic_run(pic_state *pic, struct pic_proc *proc, pic_value args)
*++sp = pic_int_value(pc->u.i);
break;
}
case OP_PUSHUNDEF: {
*++sp = pic_undef_value();
break;
}
case OP_CONS: {
pic_value a, b;
a = *sp--;

View File

@ -23,5 +23,8 @@ pic_debug(pic_state *pic, pic_value obj)
case PIC_TT_INT:
printf("%d", pic_int(obj));
break;
case PIC_TT_UNDEF:
printf("#<undef>");
break;
}
}