added moo_pfbase_t and changed some functions to return moo_pfbase_t* instead of moo_pfimpl_t

touched up some modules
This commit is contained in:
hyunghwan.chung 2017-03-30 14:59:55 +00:00
parent 9748410354
commit 0f84a115ae
13 changed files with 159 additions and 256 deletions

View File

@ -1,3 +1,4 @@
## TODO: move Pointe to a separate file
class Point(Object)
{
dcl x y.
@ -46,20 +47,22 @@ extend SmallInteger
}
}
class Console(Object)
class Console(Object) from 'console'
{
dcl handle.
"
method(#primitive) _open.
method(#primitive) _close.
method(#primitive) _clear.
method(#primitive) _setcursor(x, y).
method(#primitive) _write(msg).
(*
method finalize
{
handle notNil ifTrue: [
self _close: handle.
]
if (still open) {
self _close.
}
}
"
*)
## method(#class) input
@ -72,7 +75,7 @@ class Console(Object)
| c |
c := self new.
c handle: (c _open).
c _open. ## TODO error check - if ((e := c _open) isError) { ^e }.
^c
}
@ -80,127 +83,24 @@ class Console(Object)
## {
## }
method handle: v
{
self.handle := v.
}
method close
{
self _close: self.handle.
self.handle := nil.
self _close.
}
method write: text
{
^self _writeOn: self.handle text: text.
^self _write(text)
}
method clear
{
^self _clear: self.handle
^self _clear.
}
method setCursor: point
{
^self _setCursor: self.handle point: point.
}
"
method _open: filename mode: mode
{
self.handle := self __open: filename mode: mode.
^self.
}
method __open: filename mode: mode
{
<primitive: #console.open>
##StdioException signal: ('cannot open ' & filename).
}
"
method _open
{
<primitive: #console.open>
}
method _close: handle
{
<primitive: #console.close>
self primitiveFailed.
}
method _clear: handle
{
<primitive: #console.clear>
self primitiveFailed.
}
method _writeOn: handle text: text
{
<primitive: #console.write>
self primitiveFailed.
}
method _setCursor: handle point: point
{
<primitive: #console.setcursor>
self primitiveFailed.
}
"
method(#class) open
{
<primitive: #console.open>
self primitiveFailed.
}
method close
{
<primitive: #console.close>
self primitiveFailed.
}
method setCursorTo: point
{
<primitive: #console.setcursor>
self primitiveFailed.
}
"
##x := Colsole new.
##x := Console open.
##(x isError) ifTrue: [
## handle error...
## ]
## ifFalse: [
## x setCursor (1, 2).
## x clear.
## x close.
## ]
##x := File open: 'abc.def'
##t := x read: 1000.
##x close.
}
"
Moo define: 'console_write'
forClass: Console
method: 'write: aString upto: length'
returns: 'size_t'
arguments: 'void* size_t'
---> produces a method like this internally...
class Console
{
method write: aString upto: length
{
<ffi: int console_write (int*, char*, [int, int, char]* )> <== parse the string, create a descriptor table, key is console_write, value is resolved to a function pointer.
^self _setcursor(point x, point y)
}
}
"

View File

@ -1,13 +1,11 @@
class _FFI(Object) from 'ffi'
{
(*
* the ffi module installs the following methods
* method(#class) _newInstSize
* method open: name
* method close
* method call
* method call: func sig: sig with: args.
*)
method(#primitive) open(name).
method(#primitive) close().
method(#primitive) getsym(name).
(* TODO: make call variadic? method(#primitive,#variadic) call (func, sig). *)
method(#primitive) call(func, sig, args).
}
class FFI(Object)
@ -31,7 +29,7 @@ class FFI(Object)
self.funcs removeAllKeys.
self.name := name.
x := self.ffi open: name.
x := self.ffi open(name).
(x isError) ifTrue: [^x].
^self.
@ -47,12 +45,11 @@ class FFI(Object)
| f |
f := self.funcs at: name.
(f isError) ifTrue: [
f := self.ffi getsym: name.
f := self.ffi getsym(name).
(f isError) ifTrue: [^f].
self.funcs at: name put: f.
].
(*^self.ffi call: f sig: sig with: args*)
^self.ffi call(f, sig, args)
}
}

View File

@ -331,6 +331,7 @@ class MyObject(Object)
(System at: #Processor) dump.
System logNl: 'Sleeping start now....'.
Processor sleepFor: 2.
}

View File

@ -3,16 +3,15 @@ class Stdio(Object) from 'stdio'
{
dcl(#class) in out err.
(*
* The following methods are generated by the module.
* method(#class) _newInstSize { <primitive: #stdio._newInstSize> }
* method open: name for: mode { <primitive: #stdio.open> }
* method close { <primitive: #stdio.close> }
*)
method(#primitive) open(name, mode).
method(#primitive) close.
method(#primitive) gets.
method(#primitive,#variadic) puts().
method(#primitive,#variadic) putc().
method(#class) open: name for: mode
{
^(self new) open: name for: mode
^(self new) open(name, mode)
}
(* ---------------------
@ -71,5 +70,4 @@ class Stdio2(Stdio)
##raise exception. prohibited...
^(super new).
}
}

View File

@ -51,12 +51,12 @@ class B.TestObject(Object)
pooldic ABC
{
#KKK := 20.
KKK := 20.
}
pooldic SRX.ABC
{
#JJJ := 1000.
JJJ := 1000.
}
class MyConsole(Console)
{
@ -125,7 +125,7 @@ class MyObject(TestObject)
##v1 := Stdio2 open: '/tmp/1.txt' for: 'w+'.
v1 := Stdio2 new open: '/tmp/1.txt' for: 'w+'.
v1 := Stdio2 new open('/tmp/1.txt', 'w+').
(v1 isError)
ifTrue: [
System logNl: ('Error in opening a file....' & v1 asString).
@ -195,21 +195,21 @@ class MyObject(TestObject)
v2 dump.
}
method(#class) varg_test()
method(#class,#variadic) varg_test()
{
0 to: (thisContext vargCount - 1) do: [:k |
(thisContext vargAt: k) dump.
].
^999
}
method(#class) varg_test2(a,b,c)
method(#class,#variadic) varg_test2(a,b,c)
{
0 to: (thisContext vargCount - 1) do: [:k |
(thisContext vargAt: k) dump.
].
^a
}
method(#class) varg_test3(a,b,c,d,e,f)
method(#class,#variadic) varg_test3(a,b,c,d,e,f)
{
0 to: (thisContext vargCount - 1) do: [:k |
(thisContext vargAt: k) dump.
@ -218,7 +218,7 @@ class MyObject(TestObject)
^f
}
method(#class) t001(a)
method(#class,#variadic) t001(a)
{
a isNil ifTrue: [^error(10)].
(a = 20) ifTrue: [^error].
@ -242,4 +242,4 @@ extend MyObject
System logNl: JJJ.
System logNl: -200 asString.
}
}
}

View File

@ -3163,7 +3163,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs)
{
moo_ooi_t pf_name_index;
moo_oop_t name;
moo_pfimpl_t handler;
moo_pfbase_t* pfbase;
moo_oow_t w;
stack_base = moo->sp - nargs - 1; /* stack base before receiver and arguments */
@ -3182,22 +3182,22 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs)
/* merge two SmallIntegers to get a full pointer from the cached data */
w = (moo_oow_t)MOO_OOP_TO_SMOOI(method->preamble_data[0]) << (MOO_OOW_BITS / 2) |
(moo_oow_t)MOO_OOP_TO_SMOOI(method->preamble_data[1]);
handler = (moo_pfimpl_t)w;
if (handler) goto exec_handler;
pfbase = (moo_pfbase_t*)w;
if (pfbase) goto exec_handler;
#if defined(NDEBUG)
pf_name_index = MOO_METHOD_GET_PREAMBLE_INDEX(preamble);
name = method->slot[pf_name_index];
#endif
handler = moo_querymod (moo, ((moo_oop_char_t)name)->slot, MOO_OBJ_GET_SIZE(name));
if (handler)
pfbase = moo_querymod (moo, ((moo_oop_char_t)name)->slot, MOO_OBJ_GET_SIZE(name));
if (pfbase)
{
int n;
/* split a pointer to two OOP fields as SmallIntegers for storing/caching. */
method->preamble_data[0] = MOO_SMOOI_TO_OOP((moo_oow_t)handler >> (MOO_OOW_BITS / 2));
method->preamble_data[1] = MOO_SMOOI_TO_OOP((moo_oow_t)handler & MOO_LBMASK(moo_oow_t, MOO_OOW_BITS / 2));
method->preamble_data[0] = MOO_SMOOI_TO_OOP((moo_oow_t)pfbase >> (MOO_OOW_BITS / 2));
method->preamble_data[1] = MOO_SMOOI_TO_OOP((moo_oow_t)pfbase & MOO_LBMASK(moo_oow_t, MOO_OOW_BITS / 2));
exec_handler:
moo_pushtmp (moo, (moo_oop_t*)&method);
@ -3208,18 +3208,18 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs)
* directly in the stack unlik a normal activated method context where the
* arguments are copied to the back. */
n = handler (moo, nargs);
n = pfbase->handler (moo, nargs);
moo_poptmp (moo);
if (n <= MOO_PF_HARD_FAILURE)
{
MOO_DEBUG4 (moo, "Hard failure indicated by primitive function %p - %.*js - return code %d\n", handler, MOO_OBJ_GET_SIZE(name), ((moo_oop_char_t)name)->slot, n);
MOO_DEBUG4 (moo, "Hard failure indicated by primitive function %p - %.*js - return code %d\n", pfbase->handler, MOO_OBJ_GET_SIZE(name), ((moo_oop_char_t)name)->slot, n);
return -1; /* hard primitive failure */
}
if (n >= MOO_PF_SUCCESS) break; /* primitive ok*/
/* soft primitive failure */
MOO_DEBUG3 (moo, "Soft failure indicated by primitive function %p - %.*js\n", handler, MOO_OBJ_GET_SIZE(name), ((moo_oop_char_t)name)->slot);
MOO_DEBUG3 (moo, "Soft failure indicated by primitive function %p - %.*js\n", pfbase->handler, MOO_OBJ_GET_SIZE(name), ((moo_oop_char_t)name)->slot);
}
else
{

View File

@ -1202,7 +1202,7 @@ int moo_importmod (
* The moo_querymod() function finds a primitive function in modules
* with a full primitive identifier.
*/
moo_pfimpl_t moo_querymod (
moo_pfbase_t* moo_querymod (
moo_t* moo,
const moo_ooch_t* pfid,
moo_oow_t pfidlen

View File

@ -603,7 +603,7 @@ done2:
return r;
}
moo_pfimpl_t moo_querymod (moo_t* moo, const moo_ooch_t* pfid, moo_oow_t pfidlen)
moo_pfbase_t* moo_querymod (moo_t* moo, const moo_ooch_t* pfid, moo_oow_t pfidlen)
{
/* primitive function identifier
* _funcname
@ -614,7 +614,7 @@ moo_pfimpl_t moo_querymod (moo_t* moo, const moo_ooch_t* pfid, moo_oow_t pfidlen
const moo_ooch_t* sep;
moo_oow_t mod_name_len;
moo_pfimpl_t handler;
moo_pfbase_t* pfbase;
sep = moo_rfindoochar (pfid, pfidlen, '.');
if (!sep)
@ -647,7 +647,7 @@ moo_pfimpl_t moo_querymod (moo_t* moo, const moo_ooch_t* pfid, moo_oow_t pfidlen
if (!mdp) return MOO_NULL;
}
if ((handler = mdp->mod.query (moo, &mdp->mod, sep + 1)) == MOO_NULL)
if ((pfbase = mdp->mod.query (moo, &mdp->mod, sep + 1)) == MOO_NULL)
{
/* the primitive function is not found. but keep the module open even if it's opened above */
MOO_DEBUG2 (moo, "Cannot find a primitive function [%js] in a module [%js]\n", sep + 1, mdp->mod.name);
@ -655,12 +655,13 @@ moo_pfimpl_t moo_querymod (moo_t* moo, const moo_ooch_t* pfid, moo_oow_t pfidlen
return MOO_NULL;
}
MOO_DEBUG3 (moo, "Found a primitive function [%js] in a module [%js] - %p\n", sep + 1, mdp->mod.name, handler);
return handler;
MOO_DEBUG3 (moo, "Found a primitive function [%js] in a module [%js] - %p\n", sep + 1, mdp->mod.name, pfbase);
return pfbase;
}
/* -------------------------------------------------------------------------- */
#if 0
/* add a new primitive method */
int moo_genpfmethod (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class, moo_method_type_t type, const moo_ooch_t* mthname, int variadic, const moo_ooch_t* pfname)
{
@ -792,8 +793,9 @@ int moo_genpfmethods (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class, const
moo_poptmp (moo);
return ret;
}
#endif
moo_pfimpl_t moo_findpfimpl (moo_t* moo, const moo_pfinfo_t* pfinfo, moo_oow_t pfcount, const moo_ooch_t* name)
moo_pfbase_t* moo_findpfbase (moo_t* moo, const moo_pfinfo_t* pfinfo, moo_oow_t pfcount, const moo_ooch_t* name)
{
int left, right, mid, n;
@ -808,7 +810,7 @@ moo_pfimpl_t moo_findpfimpl (moo_t* moo, const moo_pfinfo_t* pfinfo, moo_oow_t p
else if (n > 0) left = mid + 1;
else
{
return pfinfo[mid].handler;
return &pfinfo[mid].base;
}
}

View File

@ -831,13 +831,21 @@ typedef moo_pfrc_t (*moo_pfimpl_t) (
moo_ooi_t nargs
);
typedef struct moo_pfbase_t moo_pfbase_t;
struct moo_pfbase_t
{
moo_pfimpl_t handler;
moo_oow_t minargs;
moo_oow_t maxargs;
};
typedef struct moo_pfinfo_t moo_pfinfo_t;
struct moo_pfinfo_t
{
moo_method_type_t type;
moo_ooch_t mthname[32];
int variadic;
moo_pfimpl_t handler;
moo_pfbase_t base;
};
typedef struct moo_mod_t moo_mod_t;
@ -859,7 +867,7 @@ typedef int (*moo_mod_import_t) (
moo_oop_class_t _class
);
typedef moo_pfimpl_t (*moo_mod_query_t) (
typedef moo_pfbase_t* (*moo_mod_query_t) (
moo_t* moo,
moo_mod_t* mod,
const moo_ooch_t* name
@ -1559,6 +1567,7 @@ MOO_EXPORT int moo_genpfmethod (
const moo_ooch_t* name
);
/*
MOO_EXPORT int moo_genpfmethods (
moo_t* moo,
moo_mod_t* mod,
@ -1566,8 +1575,9 @@ MOO_EXPORT int moo_genpfmethods (
const moo_pfinfo_t* pfinfo,
moo_oow_t pfcount
);
*/
MOO_EXPORT moo_pfimpl_t moo_findpfimpl (
MOO_EXPORT moo_pfbase_t* moo_findpfbase (
moo_t* moo,
const moo_pfinfo_t* pfinfo,
moo_oow_t pfcount,

View File

@ -79,8 +79,7 @@ static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs)
int err;
char* term;
con = moo_callocmem (moo, MOO_SIZEOF(*con));
if (!con) return 0;
con = (console_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
if (isatty(1))
{
@ -100,7 +99,7 @@ static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs)
}
term = getenv ("TERM");
if (term && setupterm (term, con->fd, &err) == OK)
if (term && setupterm (term, con->fd, &err) == OK)
{
}
@ -122,7 +121,7 @@ static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs)
}
#endif
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP((moo_oow_t)con));
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(con->fd));
#endif
return MOO_PF_SUCCESS;
}
@ -140,12 +139,10 @@ static moo_pfrc_t pf_close (moo_t* moo, moo_ooi_t nargs)
#else
console_t* con;
con = (console_t*)MOO_OOP_TO_SMOOI(MOO_STACK_GETARG (moo, nargs, 0));
/* TODO: sanity check */
con = (console_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
if (con->fd_opened) close (con->fd);
moo_freemem (moo, con);
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS;
#endif
@ -158,29 +155,25 @@ static moo_pfrc_t pf_write (moo_t* moo, moo_ooi_t nargs)
#else
console_t* con;
moo_oop_char_t oomsg;
moo_oop_char_t msg;
moo_oow_t ucspos, ucsrem, ucslen, bcslen;
moo_bch_t bcs[1024];
int n;
con = MOO_OOP_TO_SMOOI(MOO_STACK_GETARG (moo, nargs, 0));
oomsg = (moo_oop_char_t)MOO_STACK_GETARG (moo, nargs, 1);
con = (console_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
msg = (moo_oop_char_t)MOO_STACK_GETARG (moo, nargs, 0);
if (MOO_CLASSOF(moo,oomsg) != moo->_string)
{
/* TODO: invalid message */
return MOO_PF_FAILURE;
}
if (!MOO_OBJ_IS_CHAR_POINTER(msg)) goto einval;
#if defined(MOO_OOCH_IS_UCH)
ucspos = 0;
ucsrem = MOO_OBJ_GET_SIZE(oomsg);
ucsrem = MOO_OBJ_GET_SIZE(msg);
while (ucsrem > 0)
{
ucslen = ucsrem;
bcslen = MOO_COUNTOF(bcs);
if ((n = moo_convootobchars (moo, &oomsg->slot[ucspos], &ucslen, bcs, &bcslen)) <= -1)
if ((n = moo_convootobchars (moo, &msg->slot[ucspos], &ucslen, bcs, &bcslen)) <= -1)
{
if (n != -2 || ucslen <= 0) return MOO_PF_HARD_FAILURE;
}
@ -191,11 +184,15 @@ static moo_pfrc_t pf_write (moo_t* moo, moo_ooi_t nargs)
ucsrem -= ucslen;
}
#else
write (con->fd, oomsg->slot, MOO_OBJ_GET_SIZE(oomsg)); /* TODO: error handling. incomplete write handling */
write (con->fd, MOO_GET_OBJ_CHAR_SLOT(msg), MOO_OBJ_GET_SIZE(msg)); /* TODO: error handling. incomplete write handling */
#endif
MOO_STACK_SETRETTORCV (moo, nargs); /* TODO: change return code */
return MOO_PF_SUCCESS;
einval:
MOO_STACK_SETRETTOERROR (moo, nargs); /* TODO: be more specific about the error code */
return MOO_PF_SUCCESS;
#endif
}
@ -207,7 +204,7 @@ static moo_pfrc_t pf_clear (moo_t* moo, moo_ooi_t nargs)
#else
console_t* con;
con = MOO_OOP_TO_SMOOI(MOO_STACK_GETARG(moo, nargs, 0));
con = (console_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
write (con->fd, con->clear, strlen(con->clear));
@ -223,23 +220,24 @@ static moo_pfrc_t pf_setcursor (moo_t* moo, moo_ooi_t nargs)
#else
console_t* con;
moo_oop_oop_t point;
moo_oop_t x, y;
char* cup;
con = MOO_OOP_TO_SMOOI(MOO_STACK_GETARG(moo, nargs, 0));
point = MOO_STACK_GETARG(moo, nargs, 1);
con = (console_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
x = MOO_STACK_GETARG(moo, nargs, 0);
y = MOO_STACK_GETARG(moo, nargs, 1);
/* TODO: error check, class check, size check.. */
if (MOO_OBJ_GET_SIZE(point) != 2)
{
return MOO_PF_FAILURE;
}
if (!MOO_OOP_IS_SMOOI(x) || !MOO_OOP_IS_SMOOI(y)) goto einval;
cup = tiparm (con->cup, MOO_OOP_TO_SMOOI(point->slot[1]), MOO_OOP_TO_SMOOI(point->slot[0]));
cup = tiparm (con->cup, MOO_OOP_TO_SMOOI(y), MOO_OOP_TO_SMOOI(x));
write (con->fd, cup, strlen(cup)); /* TODO: error check */
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS;
einval:
MOO_STACK_SETRETTOERROR (moo, nargs); /* TODO: be more specific about the error code */
return MOO_PF_SUCCESS;
#endif
}
@ -250,18 +248,24 @@ static moo_pfrc_t pf_setcursor (moo_t* moo, moo_ooi_t nargs)
static moo_pfinfo_t pfinfos[] =
{
{ I, { 'c','l','e','a','r','\0' }, 0, pf_clear },
{ I, { 'c','l','o','s','e','\0' }, 0, pf_close },
{ I, { 'o','p','e','n','\0' }, 0, pf_open },
{ I, { 's','e','t','c','u','r','s','o','r','\0' }, 0, pf_setcursor },
{ I, { 'w','r','i','t','e','\0' }, 0, pf_write }
{ I, { '_','c','l','e','a','r','\0' }, 0, { pf_clear, 0, 0 } },
{ I, { '_','c','l','o','s','e','\0' }, 0, { pf_close, 0, 0 } },
{ I, { '_','o','p','e','n','\0' }, 0, { pf_open, 0, 0 } },
{ I, { '_','s','e','t','c','u','r','s','o','r','\0' }, 0, { pf_setcursor, 2, 2 } },
{ I, { '_','w','r','i','t','e','\0' }, 0, { pf_write, 1, 1 } }
};
/* ------------------------------------------------------------------------ */
static moo_pfimpl_t query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name)
static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
{
return moo_findpfimpl(moo, pfinfos, MOO_COUNTOF(pfinfos), name);
if (moo_setclasstrsize (moo, _class, MOO_SIZEOF(console_t)) <= -1) return -1;
return 0;
}
static moo_pfbase_t* query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name)
{
return moo_findpfbase(moo, pfinfos, MOO_COUNTOF(pfinfos), name);
}
@ -272,6 +276,7 @@ static void unload (moo_t* moo, moo_mod_t* mod)
int moo_mod_console (moo_t* moo, moo_mod_t* mod)
{
mod->import = import;
mod->query = query;
mod->unload = unload;
mod->ctx = MOO_NULL;

View File

@ -83,11 +83,7 @@ static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs)
DCCallVM* dc;
#endif
if (nargs != 1)
{
moo_seterrnum (moo, MOO_EINVAL);
goto softfail;
}
MOO_ASSERT (moo, nargs == 1);
ffi = (ffi_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
name = MOO_STACK_GETARG(moo, nargs, 0);
@ -142,11 +138,7 @@ static moo_pfrc_t pf_close (moo_t* moo, moo_ooi_t nargs)
{
ffi_t* ffi;
if (nargs != 0)
{
moo_seterrnum (moo, MOO_EINVAL);
goto softfail;
}
MOO_ASSERT (moo, nargs == 0);
ffi = (ffi_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
@ -188,7 +180,7 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_ooi_t nargs)
ffi = (ffi_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
if (nargs < 3) goto inval;
MOO_ASSERT (moo, nargs == 3);
fun = MOO_STACK_GETARG(moo, nargs, 0);
sig = MOO_STACK_GETARG(moo, nargs, 1);
args = MOO_STACK_GETARG(moo, nargs, 2);
@ -490,11 +482,7 @@ static moo_pfrc_t pf_getsym (moo_t* moo, moo_ooi_t nargs)
moo_oop_t name;
void* sym;
if (nargs != 1)
{
moo_seterrnum (moo, MOO_EINVAL);
goto softfail;
}
MOO_ASSERT (moo, nargs == 1);
ffi = (ffi_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
name = MOO_STACK_GETARG(moo, nargs, 0);
@ -539,13 +527,14 @@ struct fnctab_t
#define C MOO_METHOD_CLASS
#define I MOO_METHOD_INSTANCE
#define MA MOO_TYPE_MAX(moo_oow_t)
static moo_pfinfo_t pfinfos[] =
{
{ I, { 'c','a','l','l','\0' }, 1, pf_call },
{ I, { 'c','a','l','l',':','s','i','g',':','w','i','t','h',':','\0' }, 0, pf_call },
{ I, { 'c','l','o','s','e','\0' }, 0, pf_close },
{ I, { 'g','e','t','s','y','m',':','\0' }, 0, pf_getsym },
{ I, { 'o','p','e','n',':','\0' }, 0, pf_open }
{ I, { 'c','a','l','l','\0' }, 0, { pf_call, 3, 3 } },
{ I, { 'c','l','o','s','e','\0' }, 0, { pf_close, 0, 0 } },
{ I, { 'g','e','t','s','y','m','\0' }, 0, { pf_getsym, 1, 1 } },
{ I, { 'o','p','e','n','\0' }, 0, { pf_open, 1, 1 } }
};
/* ------------------------------------------------------------------------ */
@ -553,12 +542,12 @@ 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)) <= -1) return -1;
return moo_genpfmethods (moo, mod, _class, pfinfos, MOO_COUNTOF(pfinfos));
return 0;
}
static moo_pfimpl_t query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name)
static moo_pfbase_t* query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name)
{
return moo_findpfimpl (moo, pfinfos, MOO_COUNTOF(pfinfos), name);
return moo_findpfbase (moo, pfinfos, MOO_COUNTOF(pfinfos), name);
}
static void unload (moo_t* moo, moo_mod_t* mod)

View File

@ -208,28 +208,28 @@ static moo_pfrc_t pf_puts (moo_t* moo, moo_ooi_t nargs)
#define C MOO_METHOD_CLASS
#define I MOO_METHOD_INSTANCE
#define MA MOO_TYPE_MAX(moo_oow_t)
static moo_pfinfo_t pfinfos[] =
{
{ I, { 'c','l','o','s','e','\0' }, 0, pf_close },
{ I, { 'g','e','t','s','\0' }, 0, pf_gets },
{ I, { 'o','p','e','n',':','f','o','r',':','\0' }, 0, pf_open },
{ I, { 'p','u','t','c','\0' }, 1, pf_putc },
{ I, { 'p','u','t','c',':','\0' }, 0, pf_putc },
{ I, { 'p','u','t','s','\0' }, 1, pf_puts },
{ I, { 'p','u','t','s',':','\0' }, 0, pf_puts }
{ I, { 'c','l','o','s','e','\0' }, 0, { pf_close, 0, 0 } },
{ I, { 'g','e','t','s','\0' }, 0, { pf_gets, 0, 0 } },
{ I, { 'o','p','e','n','\0' }, 0, { pf_open, 2, 2 } },
{ I, { 'p','u','t','c','\0' }, 1, { pf_putc, 0, MA } },
{ I, { 'p','u','t','s','\0' }, 1, { pf_puts, 0, MA } }
};
/* ------------------------------------------------------------------------ */
static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
{
if (moo_setclasstrsize (moo, _class, MOO_SIZEOF(stdio_t)) <= -1) return -1;
return moo_genpfmethods (moo, mod, _class, pfinfos, MOO_COUNTOF(pfinfos));
return 0;
/*return moo_genpfmethods (moo, mod, _class, pfinfos, MOO_COUNTOF(pfinfos));*/
}
static moo_pfimpl_t query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name)
static moo_pfbase_t* query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name)
{
return moo_findpfimpl (moo, pfinfos, MOO_COUNTOF(pfinfos), name);
return moo_findpfbase (moo, pfinfos, MOO_COUNTOF(pfinfos), name);
}
#if 0

View File

@ -486,10 +486,10 @@ reterr:
static moo_pfinfo_t x11_pfinfo[] =
{
{ I, { '_','c','o','n','n','e','c','t','\0' }, 0, pf_connect },
{ I, { '_','d','i','s','c','o','n','n','e','c','t','\0' }, 0, pf_disconnect },
{ I, { '_','g','e','t','_','e','v','e','n','t','\0'}, 0, pf_getevent },
{ I, { '_','g','e','t','_','f','d','\0' }, 0, pf_get_fd }
{ I, { '_','c','o','n','n','e','c','t','\0' }, 0, { pf_connect, 0, 0 } },
{ I, { '_','d','i','s','c','o','n','n','e','c','t','\0' }, 0, { pf_disconnect, 0, 0 } },
{ I, { '_','g','e','t','_','e','v','e','n','t','\0'}, 0, { pf_getevent, 0, 0 } },
{ I, { '_','g','e','t','_','f','d','\0' }, 0, { pf_get_fd, 0, 0 } }
};
static int x11_import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
@ -499,9 +499,9 @@ static int x11_import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
return 0;
}
static moo_pfimpl_t x11_query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name)
static moo_pfbase_t* x11_query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name)
{
return moo_findpfimpl (moo, x11_pfinfo, MOO_COUNTOF(x11_pfinfo), name);
return moo_findpfbase (moo, x11_pfinfo, MOO_COUNTOF(x11_pfinfo), name);
}
static void x11_unload (moo_t* moo, moo_mod_t* mod)
@ -558,12 +558,12 @@ int moo_mod_x11 (moo_t* moo, moo_mod_t* mod)
static moo_pfinfo_t x11_gc_pfinfo[] =
{
{ I, { '_','d','r','a','w','L','i','n','e' }, 0, pf_gc_draw_line },
{ I, { '_','d','r','a','w','R','e','c','t' }, 0, pf_gc_draw_rect },
{ I, { '_','f','o','r','e','g','r','o','u','n','d',':','\0' }, 0, pf_gc_set_foreground },
{ I, { '_','g','e','t','_','i','d','\0' }, 0, pf_gc_get_id },
{ I, { '_','k','i','l','l','\0' }, 0, pf_gc_kill },
{ I, { '_','m','a','k','e','_','o','n',':','\0' }, 0, pf_gc_make }
{ I, { '_','d','r','a','w','L','i','n','e' }, 0, { pf_gc_draw_line, 4, 4 } },
{ I, { '_','d','r','a','w','R','e','c','t' }, 0, { pf_gc_draw_rect, 4, 4 } },
{ I, { '_','f','o','r','e','g','r','o','u','n','d',':','\0' }, 0, { pf_gc_set_foreground, 1, 1 } },
{ I, { '_','g','e','t','_','i','d','\0' }, 0, { pf_gc_get_id, 0, 0 } },
{ I, { '_','k','i','l','l','\0' }, 0, { pf_gc_kill, 0, 0 } },
{ I, { '_','m','a','k','e','_','o','n',':','\0' }, 0, { pf_gc_make, 1, 1 } }
};
@ -573,9 +573,9 @@ static int x11_gc_import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
return 0;
}
static moo_pfimpl_t x11_gc_query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name)
static moo_pfbase_t* x11_gc_query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name)
{
return moo_findpfimpl(moo, x11_gc_pfinfo, MOO_COUNTOF(x11_gc_pfinfo), name);
return moo_findpfbase(moo, x11_gc_pfinfo, MOO_COUNTOF(x11_gc_pfinfo), name);
}
static void x11_gc_unload (moo_t* moo, moo_mod_t* mod)
@ -599,11 +599,12 @@ int moo_mod_x11_gc (moo_t* moo, moo_mod_t* mod)
static moo_pfinfo_t x11_win_pfinfo[] =
{
{ I, { '_','g','e','t','_','d','w','a','t','o','m','\0'}, 0, pf_win_get_dwatom },
{ I, { '_','g','e','t','_','i','d','\0' }, 0, pf_win_get_id },
{ I, { '_','g','e','t','_','d','w','a','t','o','m','\0'}, 0, { pf_win_get_dwatom, 0, 0 } },
{ I, { '_','g','e','t','_','i','d','\0' }, 0, { pf_win_get_id, 0, 0 } },
{ I, { '_','k','i','l','l','\0' }, 0, pf_win_kill },
{ I, { '_','m','a','k','e','_','o','n',':','\0' }, 0, pf_win_make }
{ I, { '_','k','i','l','l','\0' }, 0, { pf_win_kill, 0, 0 } },
{ I, { '_','m','a','k','e','\0' }, 0, { pf_win_make, 1, 1 } },
{ I, { '_','m','a','k','e','_','o','n',':','\0' }, 0, { pf_win_make, 1, 1 } }
};
static int x11_win_import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
@ -613,9 +614,9 @@ static int x11_win_import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
return 0;
}
static moo_pfimpl_t x11_win_query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name)
static moo_pfbase_t* x11_win_query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name)
{
return moo_findpfimpl(moo, x11_win_pfinfo, MOO_COUNTOF(x11_win_pfinfo), name);
return moo_findpfbase(moo, x11_win_pfinfo, MOO_COUNTOF(x11_win_pfinfo), name);
}
static void x11_win_unload (moo_t* moo, moo_mod_t* mod)