small refactoring. use DEFINE_STANDARD_PORT_ACCESSOR macro to define pic_stdxx

This commit is contained in:
Yuichi Nishiwaki 2015-06-18 23:15:09 +09:00
parent 61ff69b968
commit b4c3e2cc4f
3 changed files with 23 additions and 28 deletions

View File

@ -201,6 +201,10 @@ void pic_load_port(pic_state *, struct pic_port *);
void pic_load_cstr(pic_state *, const char *);
pic_value pic_funcall(pic_state *pic, struct pic_lib *, const char *, pic_list);
pic_value pic_funcall0(pic_state *pic, struct pic_lib *, const char *);
pic_value pic_funcall1(pic_state *pic, struct pic_lib *, const char *, pic_value);
pic_value pic_funcall2(pic_state *pic, struct pic_lib *, const char *, pic_value, pic_value);
pic_value pic_funcall3(pic_state *pic, struct pic_lib *, const char *, pic_value, pic_value, pic_value);
pic_value pic_ref(pic_state *, struct pic_lib *, const char *);
void pic_set(pic_state *, struct pic_lib *, const char *, pic_value);

View File

@ -14,35 +14,20 @@ pic_eof_object()
return v;
}
struct pic_port *
pic_stdin(pic_state *pic)
{
pic_value obj;
#define DEFINE_STANDARD_PORT_ACCESSOR(name, var) \
struct pic_port * \
name(pic_state *pic) \
{ \
pic_value obj; \
\
obj = pic_funcall0(pic, pic->PICRIN_BASE, var); \
\
return pic_port_ptr(obj); \
}
obj = pic_funcall(pic, pic->PICRIN_BASE, "current-input-port", pic_nil_value());
return pic_port_ptr(obj);
}
struct pic_port *
pic_stdout(pic_state *pic)
{
pic_value obj;
obj = pic_funcall(pic, pic->PICRIN_BASE, "current-output-port", pic_nil_value());
return pic_port_ptr(obj);
}
struct pic_port *
pic_stderr(pic_state *pic)
{
pic_value obj;
obj = pic_funcall(pic, pic->PICRIN_BASE, "current-error-port", pic_nil_value());
return pic_port_ptr(obj);
}
DEFINE_STANDARD_PORT_ACCESSOR(pic_stdin, "current-input-port")
DEFINE_STANDARD_PORT_ACCESSOR(pic_stdout, "current-output-port")
DEFINE_STANDARD_PORT_ACCESSOR(pic_stderr, "current-error-port")
struct pic_port *
pic_make_standard_port(pic_state *pic, xFILE *file, short dir)

View File

@ -467,6 +467,12 @@ pic_funcall(pic_state *pic, struct pic_lib *lib, const char *name, pic_list args
return pic_apply(pic, pic_proc_ptr(proc), args);
}
pic_value
pic_funcall0(pic_state *pic, struct pic_lib *lib, const char *name)
{
return pic_funcall(pic, lib, name, pic_nil_value());
}
void
pic_defun(pic_state *pic, const char *name, pic_func_t cfunc)
{