From b284973035a71e9b25d0fb8d3323ba0a84b05144 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 12 Oct 2013 14:40:01 +0900 Subject: [PATCH] add # --- include/picrin/value.h | 3 +++ src/value.c | 12 ++++++++++++ src/vm.c | 5 +++++ src/write.c | 3 +++ 4 files changed, 23 insertions(+) diff --git a/include/picrin/value.h b/include/picrin/value.h index d155674b..3666aec1 100644 --- a/include/picrin/value.h +++ b/include/picrin/value.h @@ -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); diff --git a/src/value.c b/src/value.c index 7c5c6acc..2233fb95 100644 --- a/src/value.c +++ b/src/value.c @@ -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; +} diff --git a/src/vm.c b/src/vm.c index d8f514b7..f669fd84 100644 --- a/src/vm.c +++ b/src/vm.c @@ -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--; diff --git a/src/write.c b/src/write.c index c920e455..c0705711 100644 --- a/src/write.c +++ b/src/write.c @@ -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("#"); + break; } }