diff --git a/include/picrin/port.h b/include/picrin/port.h new file mode 100644 index 00000000..6ae638f2 --- /dev/null +++ b/include/picrin/port.h @@ -0,0 +1,27 @@ +#ifndef PORT_H__ +#define PORT_H__ + +#include "picrin.h" + +enum pic_port_flag { + PIC_PORT_IN, + PIC_PORT_OUT, + PIC_PORT_TEXT, + PIC_PORT_BINARY +}; + +enum pic_port_status { + PIC_PORT_OPEN, + PIC_PORT_CLOSE, +}; + +struct pic_port { + PIC_OBJECT_HEADER + FILE *file; + short flags; + char status; +}; + +#define pic_port_ptr(v) ((struct pic_port_t *)v.u.data) + +#endif diff --git a/include/picrin/value.h b/include/picrin/value.h index 743e04dd..c6ade674 100644 --- a/include/picrin/value.h +++ b/include/picrin/value.h @@ -27,7 +27,8 @@ enum pic_tt { /* heap */ PIC_TT_PAIR, PIC_TT_SYMBOL, - PIC_TT_PROC + PIC_TT_PROC, + PIC_TT_PORT }; #define PIC_OBJECT_HEADER \ @@ -49,6 +50,7 @@ struct pic_symbol { }; struct pic_proc; +struct pic_port; #define pic_obj_ptr(o) ((struct pic_object *)o.u.data) #define pic_pair_ptr(o) ((struct pic_pair *)o.u.data) diff --git a/src/port.c b/src/port.c index f4e5de2b..db278eb5 100644 --- a/src/port.c +++ b/src/port.c @@ -3,6 +3,7 @@ #include "picrin.h" #include "picrin/proc.h" +#include "picrin/port.h" static void write_pair(pic_state *pic, struct pic_pair *pair); @@ -36,6 +37,9 @@ write(pic_state *pic, pic_value obj) case PIC_TT_PROC: printf("#", pic_proc_ptr(obj)); break; + case PIC_TT_PORT: + printf("#", pic_port_ptr(obj)); + break; } }