/*------------------------------------------------------------ * Bport filenum */ static int bport_filenum(ScmPort *p) { bport *data = (bport*)p->src.buf.data; SCM_ASSERT(data != NULL); if (SCM_FALSEP(data->filenum_proc)) { return -1; } else { ScmObj s = Scm_ApplyRec(data->filenum_proc, SCM_NIL); if (SCM_INTP(s)) return SCM_INT_VALUE(s); else return -1; } }
/*------------------------------------------------------------ * Bport Ready */ static int bport_ready(ScmPort *p) { bport *data = (bport*)p->src.buf.data; SCM_ASSERT(data != NULL); if (!SCM_FALSEP(data->ready_proc)) { ScmObj s = Scm_ApplyRec(data->ready_proc, SCM_NIL); return SCM_FALSEP(s)? SCM_FD_WOULDBLOCK:SCM_FD_READY; } else { /* if no method is given, always return #t */ return SCM_FD_READY; } }
/*------------------------------------------------------------ * Bport seek */ static off_t bport_seek(ScmPort *p, off_t off, int whence) { bport *data = (bport*)p->src.buf.data; SCM_ASSERT(data != NULL); if (!SCM_FALSEP(data->seek_proc)) { ScmObj r = Scm_ApplyRec(data->seek_proc, SCM_LIST2(Scm_OffsetToInteger(off), Scm_MakeInteger(whence))); if (SCM_INTEGERP(r)) { return Scm_IntegerToOffset(r); } } return (off_t)-1; }
/*------------------------------------------------------------ * Vport Ready */ static int vport_ready(ScmPort *p, int charp) { vport *data = (vport*)p->src.vt.data; SCM_ASSERT(data != NULL); if (!SCM_FALSEP(data->ready_proc)) { ScmObj s = Scm_ApplyRec(data->ready_proc, SCM_LIST1(SCM_MAKE_BOOL(charp))); return !SCM_FALSEP(s); } else { /* if no method is given, always return #t */ return TRUE; } }
/*------------------------------------------------------------ * Bport fill */ static int bport_fill(ScmPort *p, int cnt) { bport *data = (bport*)p->src.buf.data; SCM_ASSERT(data != NULL); if (SCM_FALSEP(data->fill_proc)) { return 0; /* indicates EOF */ } ScmObj vec = Scm_MakeU8VectorFromArrayShared( cnt, (unsigned char*)p->src.buf.buffer); ScmObj r = Scm_ApplyRec(data->fill_proc, SCM_LIST1(vec)); if (SCM_INTP(r)) return SCM_INT_VALUE(r); else if (SCM_EOFP(r)) return 0; else return -1; }
/*------------------------------------------------------------ * Bport flush */ static int bport_flush(ScmPort *p, int cnt, int forcep) { bport *data = (bport*)p->src.buf.data; ScmObj vec, r; SCM_ASSERT(data != NULL); if (SCM_FALSEP(data->flush_proc)) { return cnt; /* blackhole */ } vec = Scm_MakeU8VectorFromArrayShared(cnt, (unsigned char*)p->src.buf.buffer); r = Scm_ApplyRec(data->flush_proc, SCM_LIST2(vec, SCM_MAKE_BOOL(forcep))); if (SCM_INTP(r)) return SCM_INT_VALUE(r); else if (SCM_EOFP(r)) return 0; else return -1; }
/* Default object printer delegates print action to generic function write-object. We can't use VMApply here since this function can be called deep in the recursive stack of Scm_Write, so the control may not return to VM immediately. */ static void write_object(ScmObj obj, ScmPort *port, ScmWriteContext *ctx) { Scm_ApplyRec(SCM_OBJ(&Scm_GenericWriteObject), SCM_LIST2(obj, SCM_OBJ(port))); }
static void timer_cb(int value) { if (!SCM_FALSEP(timer_closure)) { Scm_ApplyRec(timer_closure, SCM_LIST1(Scm_MakeInteger(value))); } }
static void idle_cb(void) { if (!SCM_FALSEP(idle_closure)) { Scm_ApplyRec(idle_closure, SCM_NIL); } }
ScmObj Scm_SockAddrFamily(ScmSockAddr *addr) { return Scm_ApplyRec(SCM_OBJ(&Scm_GenericSockAddrFamily), SCM_LIST1(SCM_OBJ(addr))); }