changed module functions to include the mod argument

This commit is contained in:
hyunghwan.chung 2018-05-07 16:53:16 +00:00
parent b891d31e8b
commit 2bb2bd82fc
6 changed files with 89 additions and 42 deletions

View File

@ -52,7 +52,7 @@ struct console_t
};
/* ------------------------------------------------------------------------ */
static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_open (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
#if defined(_WIN32)
HANDLE h;
@ -127,7 +127,7 @@ static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs)
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_close (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_close (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
#if defined(_WIN32)
HANDLE h;
@ -149,7 +149,7 @@ static moo_pfrc_t pf_close (moo_t* moo, moo_ooi_t nargs)
#endif
}
static moo_pfrc_t pf_write (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_write (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
#if defined(_WIN32)
#elif defined(__DOS__)
@ -197,7 +197,7 @@ einval:
#endif
}
static moo_pfrc_t pf_clear (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_clear (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
#if defined(_WIN32)
#elif defined(__DOS__)
@ -214,7 +214,7 @@ static moo_pfrc_t pf_clear (moo_t* moo, moo_ooi_t nargs)
#endif
}
static moo_pfrc_t pf_setcursor (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_setcursor (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
#if defined(_WIN32)
#elif defined(__DOS__)

View File

@ -74,7 +74,7 @@ static void free_linked_cas (moo_t* moo, ffi_t* ffi)
}
}
static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_open (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
ffi_t* ffi;
moo_oop_t name;
@ -134,7 +134,7 @@ softfail:
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_close (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_close (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
ffi_t* ffi;
@ -168,7 +168,7 @@ softfail:
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_call (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_call (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
#if defined(USE_DYNCALL)
ffi_t* ffi;
@ -476,7 +476,7 @@ hardfail:
#endif
}
static moo_pfrc_t pf_getsym (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_getsym (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
ffi_t* ffi;
moo_oop_t name;
@ -541,7 +541,7 @@ static moo_pfinfo_t pfinfos[] =
static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
{
if (moo_setclasstrsize (moo, _class, MOO_SIZEOF(ffi_t), MOO_NULL) <= -1) return -1;
if (moo_setclasstrsize(moo, _class, MOO_SIZEOF(ffi_t), MOO_NULL) <= -1) return -1;
return 0;
}

View File

@ -483,7 +483,7 @@ no_rbrack:
}
static moo_pfrc_t pf_from_string (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_from_string (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
moo_oop_t rcv;
moo_oop_t str;

View File

@ -40,7 +40,13 @@
#include <arpa/inet.h>
#include <string.h>
static moo_pfrc_t pf_open_socket (moo_t* moo, moo_ooi_t nargs)
typedef struct sck_modctx_t sck_modctx_t;
struct sck_modctx_t
{
moo_oop_class_t sck_class;
};
static moo_pfrc_t pf_open_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_sck_t sck;
moo_oop_t dom, type, proto;
@ -117,7 +123,7 @@ oops:
return MOO_PF_FAILURE;
}
static moo_pfrc_t pf_close_socket (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_close_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_sck_t sck;
int fd;
@ -150,7 +156,7 @@ static moo_pfrc_t pf_close_socket (moo_t* moo, moo_ooi_t nargs)
return MOO_PF_FAILURE;
}
static moo_pfrc_t pf_bind_socket (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_bind_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_sck_t sck;
moo_oop_t arg;
@ -184,7 +190,7 @@ static moo_pfrc_t pf_bind_socket (moo_t* moo, moo_ooi_t nargs)
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_accept_socket (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_accept_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_sck_t sck, newsck;
moo_oop_t arg;
@ -245,7 +251,8 @@ static moo_pfrc_t pf_accept_socket (moo_t* moo, moo_ooi_t nargs)
if (fcntl(newfd, F_SETFL, fl) == -1) goto fcntl_failure;
accept_done:
newsck = (oop_sck_t)moo_instantiate (moo, MOO_OBJ_GET_CLASS(sck), MOO_NULL, 0);
/*newsck = (oop_sck_t)moo_instantiate(moo, MOO_OBJ_GET_CLASS(sck), MOO_NULL, 0);*/
newsck = (oop_sck_t)moo_instantiate(moo, ((sck_modctx_t*)mod->ctx)->sck_class, MOO_NULL, 0);
if (!newsck)
{
close (newfd);
@ -261,11 +268,14 @@ accept_done:
}
newsck->handle = MOO_SMOOI_TO_OOP(newfd);
/* return the partially initialized socket object. the handle field is set to the new file
* descriptor. however all other fields are just set to nil. so the user of this primitive
* method should call application-level initializer. */
MOO_STACK_SETRET (moo, nargs, (moo_oop_t)newsck);
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_listen_socket (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_listen_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_sck_t sck;
moo_oop_t arg;
@ -277,7 +287,7 @@ static moo_pfrc_t pf_listen_socket (moo_t* moo, moo_ooi_t nargs)
MOO_PF_CHECK_RCV (moo,
MOO_OOP_IS_POINTER(sck) &&
MOO_OBJ_BYTESOF(sck) >= (MOO_SIZEOF(*sck) - MOO_SIZEOF(moo_obj_t)) &&
MOO_OOP_IS_SMOOI(sck->handle));
MOO_OOP_IS_SMOOI(sck->handle));/*newsck = (oop_sck_t)moo_instantiate (moo, MOO_OBJ_GET_CLASS(sck), MOO_NULL, 0);*/
MOO_PF_CHECK_ARGS (moo, nargs, MOO_OOP_IS_SMOOI(arg));
fd = MOO_OOP_TO_SMOOI(sck->handle);
@ -299,7 +309,7 @@ static moo_pfrc_t pf_listen_socket (moo_t* moo, moo_ooi_t nargs)
}
static moo_pfrc_t pf_connect_socket (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_connect_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_sck_t sck;
int fd, n;
@ -341,7 +351,7 @@ static moo_pfrc_t pf_connect_socket (moo_t* moo, moo_ooi_t nargs)
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_get_socket_error (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_get_socket_error (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_sck_t sck;
int fd, ret;
@ -374,7 +384,7 @@ static moo_pfrc_t pf_get_socket_error (moo_t* moo, moo_ooi_t nargs)
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_read_socket (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_read_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_sck_t sck;
moo_oop_byte_t buf;
@ -417,7 +427,7 @@ static moo_pfrc_t pf_read_socket (moo_t* moo, moo_ooi_t nargs)
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_write_socket (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_write_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_sck_t sck;
moo_oop_byte_t buf;
@ -523,25 +533,62 @@ static moo_pfinfo_t pfinfos[] =
static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
{
/*if (moo_setclasstrsize (moo, _class, MOO_SIZEOF(sck_t), MOO_NULL) <= -1) return -1;*/
/*if (moo_setclasstrsize(moo, _class, MOO_SIZEOF(sck_t), MOO_NULL) <= -1) return -1;*/
return 0;
}
static moo_pfbase_t* query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name, moo_oow_t namelen)
{
return moo_findpfbase (moo, pfinfos, MOO_COUNTOF(pfinfos), name, namelen);
return moo_findpfbase(moo, pfinfos, MOO_COUNTOF(pfinfos), name, namelen);
}
static void unload (moo_t* moo, moo_mod_t* mod)
{
/* TODO: anything? close open open dll handles? For that, pf_open must store the value it returns to mod->ctx or somewhere..*/
if (mod->ctx) moo_freemem (moo, mod->ctx);
}
static void gc_mod_sck (moo_t* moo, moo_mod_t* mod)
{
sck_modctx_t* ctx = mod->ctx;
MOO_ASSERT (moo, ctx != MOO_NULL);
if (ctx->sck_class)
{
ctx->sck_class = (moo_oop_class_t)moo_moveoop(moo, (moo_oop_t)ctx->sck_class);
}
}
int moo_mod_sck (moo_t* moo, moo_mod_t* mod)
{
if (mod->hints & MOO_MOD_LOAD_FOR_IMPORT)
{
mod->gc = MOO_NULL;
mod->ctx = MOO_NULL;
}
else
{
sck_modctx_t* ctx;
static moo_ooch_t name_sck[] = { 'S','o','c','k','e','t','\0' };
ctx = moo_callocmem(moo, MOO_SIZEOF(*ctx));
if (!ctx) return -1;
ctx->sck_class = (moo_oop_class_t)moo_findclass(moo, moo->sysdic, name_sck);
if (!ctx->sck_class)
{
MOO_DEBUG0 (moo, "Socket class not found\n");
moo_freemem (moo, ctx);
return -1;
}
mod->gc = gc_mod_sck;
mod->ctx = ctx;
}
mod->import = import;
mod->query = query;
mod->unload = unload;
mod->ctx = MOO_NULL;
return 0;
}

View File

@ -42,7 +42,7 @@ struct stdio_t
FILE* fp;
};
static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_open (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
moo_oop_char_t name;
moo_oop_char_t mode;
@ -87,7 +87,7 @@ softfail:
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_close (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_close (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
stdio_t* stdio;
@ -102,7 +102,7 @@ static moo_pfrc_t pf_close (moo_t* moo, moo_ooi_t nargs)
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_gets (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_gets (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
/* TODO: ...*/
MOO_STACK_SETRETTORCV (moo, nargs);
@ -189,12 +189,12 @@ softfail:
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_putc (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_putc (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
return __pf_puts (moo, nargs, 1);
}
static moo_pfrc_t pf_puts (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_puts (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
return __pf_puts (moo, nargs, MOO_TYPE_MAX(moo_oow_t));
}

View File

@ -71,7 +71,7 @@ static XChar2b* uchars_to_xchar2bstr (moo_t* moo, const moo_uch_t* inptr, moo_oo
}
/* ------------------------------------------------------------------------ */
static moo_pfrc_t pf_open_display (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_open_display (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_x11_t x11;
x11_trailer_t* tr;
@ -160,7 +160,7 @@ oops:
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_close_display (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_close_display (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_x11_t x11;
x11_trailer_t* tr;
@ -187,7 +187,7 @@ static moo_pfrc_t pf_close_display (moo_t* moo, moo_ooi_t nargs)
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_get_fd (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_get_fd (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
x11_trailer_t* tr;
// TODO: CHECK if the receiver is an X11 object
@ -196,7 +196,7 @@ static moo_pfrc_t pf_get_fd (moo_t* moo, moo_ooi_t nargs)
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_get_llevent (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_get_llevent (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_x11_t x11;
x11_trailer_t* tr;
@ -298,7 +298,7 @@ MOO_DEBUG0 (moo, "NO PENDING EVENT....\n");
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_create_window (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_create_window (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
Display* disp;
Window wind; /* Window -> XID, unsigned long */
@ -391,7 +391,7 @@ static moo_pfrc_t pf_create_window (moo_t* moo, moo_ooi_t nargs)
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_destroy_window (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_destroy_window (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_x11_t x11;
moo_oop_t a0;
@ -420,7 +420,7 @@ static moo_pfrc_t pf_destroy_window (moo_t* moo, moo_ooi_t nargs)
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_create_gc (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_create_gc (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
Display* disp;
Window wind;
@ -459,7 +459,7 @@ static moo_pfrc_t pf_create_gc (moo_t* moo, moo_ooi_t nargs)
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_destroy_gc (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_destroy_gc (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_x11_t x11;
oop_x11_gc_t gc;
@ -492,7 +492,7 @@ MOO_DEBUG0 (moo, "Freed Font Set\n");
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_apply_gc (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_apply_gc (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_x11_t x11;
oop_x11_gc_t a0;
@ -613,7 +613,7 @@ MOO_DEBUG0 (moo, "XCreateFontSet ok....\n");
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_draw_rectangle (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_draw_rectangle (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_x11_t x11;
Display* disp;
@ -645,7 +645,7 @@ static moo_pfrc_t pf_draw_rectangle (moo_t* moo, moo_ooi_t nargs)
}
static moo_pfrc_t pf_fill_rectangle (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_fill_rectangle (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_x11_t x11;
Display* disp;
@ -677,7 +677,7 @@ static moo_pfrc_t pf_fill_rectangle (moo_t* moo, moo_ooi_t nargs)
}
static moo_pfrc_t pf_draw_string (moo_t* moo, moo_ooi_t nargs)
static moo_pfrc_t pf_draw_string (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
{
oop_x11_t x11;
oop_x11_gc_t gc;