changed to use moo_bch_t* in moo_pfinfo_t from moo_ooch_t[]

This commit is contained in:
hyunghwan.chung 2019-10-25 03:22:40 +00:00
parent feb1825c41
commit dde69fb64e
12 changed files with 82 additions and 66 deletions

View File

@ -1571,15 +1571,15 @@ int moo_fmt_object_ (moo_fmtout_t* fmtout, moo_oop_t oop)
/* TODO: better memory allocation management? */ /* TODO: better memory allocation management? */
ns = ((moo_oop_nsdic_t)oop)->nsup; ns = ((moo_oop_nsdic_t)oop)->nsup;
while (/*ns != moo->_system &&*/ ns != moo->_system->nsdic) /* exclude System from the output */ while (/*ns != moo->_system &&*/ ns != (moo_oop_t)moo->_system->nsdic) /* exclude System from the output */
{ {
if (MOO_CLASSOF(moo, ns) == moo->_class) if (MOO_CLASSOF(moo, ns) == moo->_class)
{ {
ns = ((moo_oop_class_t)ns)->nsup; ns = (moo_oop_t)((moo_oop_class_t)ns)->nsup;
} }
else if (MOO_CLASSOF(moo, ns) == moo->_interface) else if (MOO_CLASSOF(moo, ns) == moo->_interface)
{ {
ns = ((moo_oop_interface_t)ns)->nsup; ns = (moo_oop_t)((moo_oop_interface_t)ns)->nsup;
} }
else else
{ {
@ -1622,16 +1622,16 @@ int moo_fmt_object_ (moo_fmtout_t* fmtout, moo_oop_t oop)
int ok = 1; int ok = 1;
/* TODO: collapse many duplicate code among namespace, class, interface name printing */ /* TODO: collapse many duplicate code among namespace, class, interface name printing */
ns = ((moo_oop_class_t)oop)->nsup; ns = (moo_oop_t)((moo_oop_class_t)oop)->nsup;
while (/*ns != moo->_system &&*/ ns != moo->_system->nsdic) /* exclude System from the output */ while (/*ns != moo->_system &&*/ ns != (moo_oop_t)moo->_system->nsdic) /* exclude System from the output */
{ {
if (MOO_CLASSOF(moo, ns) == moo->_class) if (MOO_CLASSOF(moo, ns) == moo->_class)
{ {
ns = ((moo_oop_class_t)ns)->nsup; ns = (moo_oop_t)((moo_oop_class_t)ns)->nsup;
} }
else if (MOO_CLASSOF(moo, ns) == moo->_interface) else if (MOO_CLASSOF(moo, ns) == moo->_interface)
{ {
ns = ((moo_oop_interface_t)ns)->nsup; ns = (moo_oop_t)((moo_oop_interface_t)ns)->nsup;
} }
else else
{ {
@ -1671,16 +1671,16 @@ int moo_fmt_object_ (moo_fmtout_t* fmtout, moo_oop_t oop)
}* tmp, * top = MOO_NULL; }* tmp, * top = MOO_NULL;
int ok = 1; int ok = 1;
ns = ((moo_oop_interface_t)oop)->nsup; ns = (moo_oop_t)((moo_oop_interface_t)oop)->nsup;
while (/*ns != moo->_system &&*/ ns != moo->_system->nsdic) /* exclude System from the output */ while (/*ns != moo->_system &&*/ ns != (moo_oop_t)moo->_system->nsdic) /* exclude System from the output */
{ {
if (MOO_CLASSOF(moo, ns) == moo->_class) if (MOO_CLASSOF(moo, ns) == moo->_class)
{ {
ns = ((moo_oop_class_t)ns)->nsup; ns = (moo_oop_t)((moo_oop_class_t)ns)->nsup;
} }
else if (MOO_CLASSOF(moo, ns) == moo->_interface) else if (MOO_CLASSOF(moo, ns) == moo->_interface)
{ {
ns = ((moo_oop_interface_t)ns)->nsup; ns = (moo_oop_t)((moo_oop_interface_t)ns)->nsup;
} }
else else
{ {

View File

@ -741,8 +741,8 @@ done2:
moo_pfbase_t* moo_querymod (moo_t* moo, const moo_ooch_t* pfid, moo_oow_t pfidlen, moo_mod_t** mod) moo_pfbase_t* moo_querymod (moo_t* moo, const moo_ooch_t* pfid, moo_oow_t pfidlen, moo_mod_t** mod)
{ {
/* primitive function identifier /* primitive function identifier
* _funcname * modname.funcname
* modname_funcname * modname.modname2.funcname
*/ */
moo_rbt_pair_t* pair; moo_rbt_pair_t* pair;
moo_mod_data_t* mdp; moo_mod_data_t* mdp;
@ -943,7 +943,7 @@ moo_pfbase_t* moo_findpfbase (moo_t* moo, moo_pfinfo_t* pfinfo, moo_oow_t pfcoun
/*mid = (left + right) / 2;*/ /*mid = (left + right) / 2;*/
mid = left + ((right - left) / 2); mid = left + ((right - left) / 2);
n = moo_comp_oochars_oocstr (name, namelen, pfinfo[mid].mthname); n = moo_comp_oochars_bcstr(name, namelen, pfinfo[mid].name);
if (n < 0) right = mid - 1; /* this substraction can make right negative. so i can't use moo_oow_t for the variable */ if (n < 0) right = mid - 1; /* this substraction can make right negative. so i can't use moo_oow_t for the variable */
else if (n > 0) left = mid + 1; else if (n > 0) left = mid + 1;
else return &pfinfo[mid].base; else return &pfinfo[mid].base;
@ -955,7 +955,7 @@ moo_pfbase_t* moo_findpfbase (moo_t* moo, moo_pfinfo_t* pfinfo, moo_oow_t pfcoun
for (base = 0, lim = pfcount; lim > 0; lim >>= 1) for (base = 0, lim = pfcount; lim > 0; lim >>= 1)
{ {
mid = base + (lim >> 1); mid = base + (lim >> 1);
n = moo_comp_oochars_oocstr (name, namelen, pfinfo[mid].mthname); n = moo_comp_oochars_bcstr(name, namelen, pfinfo[mid].name);
if (n == 0) return &pfinfo[mid].base; if (n == 0) return &pfinfo[mid].base;
if (n > 0) { base = mid + 1; lim--; } if (n > 0) { base = mid + 1; lim--; }
} }

View File

@ -1322,15 +1322,31 @@ struct moo_pfbase_t
moo_oow_t maxargs; moo_oow_t maxargs;
}; };
typedef struct moo_pfinfo_t moo_pfinfo_t; typedef struct moo_pfinfo_t moo_pfinfo_t;
struct moo_pfinfo_t struct moo_pfinfo_t
{ {
moo_method_type_t type; moo_method_type_t type;
moo_ooch_t mthname[32]; const moo_bch_t* name;
int variadic; int variadic;
moo_pfbase_t base; moo_pfbase_t base;
}; };
/*
typedef struct moo_pvbase_t moo_pvbase_t
{
void* ptr;
moo_oow_t len;
moo_oow_t type;
};
typedef struct moo_pvinfo_t moo_pvinfo_t;
struct moo_pvinfo_t
{
moo_ooch_t name[32];
moo_pvbase_t base;
};
*/
/* receiver check failure leads to hard failure. /* receiver check failure leads to hard failure.
* RATIONAL: the primitive handler should be used by relevant classes and * RATIONAL: the primitive handler should be used by relevant classes and

View File

@ -256,11 +256,11 @@ einval:
static moo_pfinfo_t pfinfos[] = static moo_pfinfo_t pfinfos[] =
{ {
{ I, { 'c','l','e','a','r','\0' }, 0, { pf_clear, 0, 0 } }, { I, "clear", 0, { pf_clear, 0, 0 } },
{ I, { 'c','l','o','s','e','\0' }, 0, { pf_close, 0, 0 } }, { I, "close", 0, { pf_close, 0, 0 } },
{ I, { 'o','p','e','n','\0' }, 0, { pf_open, 0, 0 } }, { I, "open", 0, { pf_open, 0, 0 } },
{ I, { 's','e','t','c','u','r','s','o','r','\0' }, 0, { pf_setcursor, 2, 2 } }, { I, "setcursor", 0, { pf_setcursor, 2, 2 } },
{ I, { 'w','r','i','t','e','\0' }, 0, { pf_write, 1, 1 } } { I, "write", 0, { pf_write, 1, 1 } }
}; };
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */

View File

@ -1198,10 +1198,10 @@ softfail:
static moo_pfinfo_t pfinfos[] = static moo_pfinfo_t pfinfos[] =
{ {
{ I, { 'c','a','l','l','\0' }, 0, { pf_call, 3, 3 } }, { I, "call", 0, { pf_call, 3, 3 } },
{ I, { 'c','l','o','s','e','\0' }, 0, { pf_close, 0, 0 } }, { I, "close", 0, { pf_close, 0, 0 } },
{ I, { 'g','e','t','s','y','m','\0' }, 0, { pf_getsym, 1, 1 } }, { I, "getsym", 0, { pf_getsym, 1, 1 } },
{ I, { 'o','p','e','n','\0' }, 0, { pf_open, 1, 1 } } { I, "open", 0, { pf_open, 1, 1 } }
}; };
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */

View File

@ -118,8 +118,8 @@ oops:
static moo_pfinfo_t pfinfos[] = static moo_pfinfo_t pfinfos[] =
{ {
{ I, { 'o','p','e','n',':','f','l','a','g','s',':','\0' }, 0, { pf_open_file, 2, 2 } }, { I, "open:flags:", 0, { pf_open_file, 2, 2 } },
{ I, { 'o','p','e','n',':','f','l','a','g','s',':','m','o','d','e',':','\0' }, 0, { pf_open_file, 3, 3 } }, { I, "open:flags:mode:", 0, { pf_open_file, 3, 3 } },
}; };
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */

View File

@ -219,11 +219,11 @@ static moo_pfrc_t pf_write_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
static moo_pfinfo_t pfinfos[] = static moo_pfinfo_t pfinfos[] =
{ {
{ I, { 'c','l','o','s','e','\0' }, 0, { pf_close_io, 0, 0 } }, { I, "close", 0, { pf_close_io, 0, 0 } },
{ I, { 'r','e','a','d','B','y','t','e','s','I','n','t','o',':','\0' }, 0, { pf_read_bytes, 1, 1 } }, { I, "readBytesInto:", 0, { pf_read_bytes, 1, 1 } },
{ I, { 'r','e','a','d','B','y','t','e','s','I','n','t','o',':','s','t','a','r','t','i','n','g','A','t',':','f','o','r',':','\0' }, 0, { pf_read_bytes, 3, 3 } }, { I, "readBytesInto:startingAt:for:", 0, { pf_read_bytes, 3, 3 } },
{ I, { 'w','r','i','t','e','B','y','t','e','s','F','r','o','m',':','\0' }, 0, { pf_write_bytes, 1, 1 } }, { I, "writeBytesFrom:", 0, { pf_write_bytes, 1, 1 } },
{ I, { 'w','r','i','t','e','B','y','t','e','s','F','r','o','m',':','s','t','a','r','t','i','n','g','A','t',':','f','o','r',':','\0' }, 0, { pf_write_bytes, 3, 3 } } { I, "writeBytesFrom:startingAt:for:", 0, { pf_write_bytes, 3, 3 } }
}; };
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */

View File

@ -494,8 +494,8 @@ static moo_pfrc_t pf_from_string (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
static moo_pfinfo_t pfinfos[] = static moo_pfinfo_t pfinfos[] =
{ {
{ I, { 'f','a','m','i','l','y' }, 0, { pf_get_family, 0, 0 } }, { I, "family", 0, { pf_get_family, 0, 0 } },
{ I, { 'f','r','o','m','S','t','r','i','n','g',':','\0' }, 0, { pf_from_string, 1, 1 } } { I, "fromString:", 0, { pf_from_string, 1, 1 } }
}; };
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */

View File

@ -576,17 +576,17 @@ static moo_pfrc_t pf_write_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
static moo_pfinfo_t pfinfos[] = static moo_pfinfo_t pfinfos[] =
{ {
{ I, { 'a','c','c','e','p','t',':','\0' }, 0, { pf_accept_socket, 1, 1 } }, { I, "accept:", 0, { pf_accept_socket, 1, 1 } },
{ I, { 'b','i','n','d',':','\0' }, 0, { pf_bind_socket, 1, 1 } }, { I, "bind:", 0, { pf_bind_socket, 1, 1 } },
{ I, { 'c','l','o','s','e','\0' }, 0, { pf_close_socket, 0, 0 } }, { I, "close", 0, { pf_close_socket, 0, 0 } },
{ I, { 'c','o','n','n','e','c','t',':','\0' }, 0, { pf_connect_socket, 1, 1 } }, { I, "connect:", 0, { pf_connect_socket, 1, 1 } },
{ I, { 'l','i','s','t','e','n',':','\0' }, 0, { pf_listen_socket, 1, 1 } }, { I, "listen:", 0, { pf_listen_socket, 1, 1 } },
{ I, { 'o','p','e','n','\0' }, 0, { pf_open_socket, 1, 3 } }, { I, "open", 0, { pf_open_socket, 1, 3 } },
{ I, { 'r','e','a','d','B','y','t','e','s','I','n','t','o',':','\0' }, 0, { pf_read_socket, 1, 1 } }, { I, "readBytesInto:", 0, { pf_read_socket, 1, 1 } },
{ I, { 'r','e','a','d','B','y','t','e','s','I','n','t','o',':','s','t','a','r','t','i','n','g','A','t',':','f','o','r',':','\0' }, 0, { pf_read_socket, 3, 3 } }, { I, "readBytesInto:startingAt:for:", 0, { pf_read_socket, 3, 3 } },
{ I, { 's','o','c','k','e','t','E','r','r','o','r','\0' }, 0, { pf_get_socket_error, 0, 0 } }, { I, "socketError", 0, { pf_get_socket_error, 0, 0 } },
{ I, { 'w','r','i','t','e','B','y','t','e','s','F','r','o','m',':','\0' }, 0, { pf_write_socket, 1, 1 } }, { I, "writeBytesFrom:", 0, { pf_write_socket, 1, 1 } },
{ I, { 'w','r','i','t','e','B','y','t','e','s','F','r','o','m',':','s','t','a','r','t','i','n','g','A','t',':','f','o','r',':','\0' }, 0, { pf_write_socket, 3, 3 } } { I, "writeBytesFrom:startingAt:for:", 0, { pf_write_socket, 3, 3 } }
}; };
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */

View File

@ -211,11 +211,11 @@ static moo_pfrc_t pf_puts (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
static moo_pfinfo_t pfinfos[] = static moo_pfinfo_t pfinfos[] =
{ {
{ I, { 'c','l','o','s','e','\0' }, 0, { pf_close, 0, 0 } }, { I, "close", 0, { pf_close, 0, 0 } },
{ I, { 'g','e','t','s','\0' }, 0, { pf_gets, 0, 0 } }, { I, "gets", 0, { pf_gets, 0, 0 } },
{ I, { 'o','p','e','n','\0' }, 0, { pf_open, 2, 2 } }, { I, "open", 0, { pf_open, 2, 2 } },
{ I, { 'p','u','t','c','\0' }, 1, { pf_putc, 0, MA } }, { I, "putc", 1, { pf_putc, 0, MA } },
{ I, { 'p','u','t','s','\0' }, 1, { pf_puts, 0, MA } } { I, "puts", 1, { pf_puts, 0, MA } }
}; };
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */

View File

@ -797,19 +797,19 @@ static moo_pfrc_t pf_draw_string (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
static moo_pfinfo_t x11_pfinfo[] = static moo_pfinfo_t x11_pfinfo[] =
{ {
{ MI, { 'a','p','p','l','y','_','g','c','\0' }, 0, { pf_apply_gc, 1, 1 } }, { MI, "apply_gc", 0, { pf_apply_gc, 1, 1 } },
{ MI, { 'c','l','o','s','e','_','d','i','s','p','l','a','y','\0' }, 0, { pf_close_display, 0, 0 } }, { MI, "close_display", 0, { pf_close_display, 0, 0 } },
{ MI, { 'c','r','e','a','t','e','_','g','c','\0' }, 0, { pf_create_gc, 1, 1 } }, { MI, "create_gc", 0, { pf_create_gc, 1, 1 } },
{ MI, { 'c','r','e','a','t','e','_','w','i','n','d','o','w','\0' }, 0, { pf_create_window, 7, 7 } }, { MI, "create_window", 0, { pf_create_window, 7, 7 } },
{ MI, { 'd','e','s','t','r','o','y','_','g','c','\0' }, 0, { pf_destroy_gc, 1, 1 } }, { MI, "destroy_gc", 0, { pf_destroy_gc, 1, 1 } },
{ MI, { 'd','e','s','t','r','o','y','_','w','i','n','d','o','w','\0' }, 0, { pf_destroy_window, 1, 1 } }, { MI, "destroy_window", 0, { pf_destroy_window, 1, 1 } },
{ MI, { 'd','r','a','w','_','r','e','c','t','a','n','g','l','e','\0' }, 0, { pf_draw_rectangle, 6, 6 } }, { MI, "draw_rectangle", 0, { pf_draw_rectangle, 6, 6 } },
{ MI, { 'd','r','a','w','_','s','t','r','i','n','g','\0' }, 0, { pf_draw_string, 4, 4 } }, { MI, "draw_string", 0, { pf_draw_string, 4, 4 } },
{ MI, { 'f','i','l','l','_','r','e','c','t','a','n','g','l','e','\0' }, 0, { pf_fill_rectangle, 6, 6 } }, { MI, "fill_rectangle", 0, { pf_fill_rectangle, 6, 6 } },
{ MI, { 'g','e','t','_','f','d','\0' }, 0, { pf_get_fd, 0, 0 } }, { MI, "get_fd", 0, { pf_get_fd, 0, 0 } },
{ MI, { 'g','e','t','_','l','l','e','v','e','n','t','\0'}, 0, { pf_get_llevent, 1, 1 } }, { MI, "get_llevent", 0, { pf_get_llevent, 1, 1 } },
{ MI, { 'o','p','e','n','_','d','i','s','p','l','a','y','\0' }, 0, { pf_open_display, 0, 1 } } { MI, "open_display", 0, { pf_open_display, 0, 1 } }
}; };
static int x11_import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class) static int x11_import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)