initial port commit

This commit is contained in:
Yuichi Nishiwaki 2013-10-17 22:42:47 +09:00
parent e87f632327
commit 1646de5e8d
3 changed files with 34 additions and 1 deletions

27
include/picrin/port.h Normal file
View File

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

View File

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

View File

@ -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("#<proc %p>", pic_proc_ptr(obj));
break;
case PIC_TT_PORT:
printf("#<port %p>", pic_port_ptr(obj));
break;
}
}