some improvements to the ffi module.
changed hawk::function_exists() to check a module function
This commit is contained in:
parent
7b9f3cd9f5
commit
80f9d6bc85
@ -353,7 +353,6 @@ pdfdir = @pdfdir@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
program_transform_name = @program_transform_name@
|
program_transform_name = @program_transform_name@
|
||||||
psdir = @psdir@
|
psdir = @psdir@
|
||||||
runstatedir = @runstatedir@
|
|
||||||
sbindir = @sbindir@
|
sbindir = @sbindir@
|
||||||
sharedstatedir = @sharedstatedir@
|
sharedstatedir = @sharedstatedir@
|
||||||
srcdir = @srcdir@
|
srcdir = @srcdir@
|
||||||
|
@ -322,7 +322,6 @@ pdfdir = @pdfdir@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
program_transform_name = @program_transform_name@
|
program_transform_name = @program_transform_name@
|
||||||
psdir = @psdir@
|
psdir = @psdir@
|
||||||
runstatedir = @runstatedir@
|
|
||||||
sbindir = @sbindir@
|
sbindir = @sbindir@
|
||||||
sharedstatedir = @sharedstatedir@
|
sharedstatedir = @sharedstatedir@
|
||||||
srcdir = @srcdir@
|
srcdir = @srcdir@
|
||||||
|
24
hawk/configure
vendored
24
hawk/configure
vendored
@ -784,7 +784,6 @@ infodir
|
|||||||
docdir
|
docdir
|
||||||
oldincludedir
|
oldincludedir
|
||||||
includedir
|
includedir
|
||||||
runstatedir
|
|
||||||
localstatedir
|
localstatedir
|
||||||
sharedstatedir
|
sharedstatedir
|
||||||
sysconfdir
|
sysconfdir
|
||||||
@ -886,7 +885,6 @@ datadir='${datarootdir}'
|
|||||||
sysconfdir='${prefix}/etc'
|
sysconfdir='${prefix}/etc'
|
||||||
sharedstatedir='${prefix}/com'
|
sharedstatedir='${prefix}/com'
|
||||||
localstatedir='${prefix}/var'
|
localstatedir='${prefix}/var'
|
||||||
runstatedir='${localstatedir}/run'
|
|
||||||
includedir='${prefix}/include'
|
includedir='${prefix}/include'
|
||||||
oldincludedir='/usr/include'
|
oldincludedir='/usr/include'
|
||||||
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
|
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
|
||||||
@ -1139,15 +1137,6 @@ do
|
|||||||
| -silent | --silent | --silen | --sile | --sil)
|
| -silent | --silent | --silen | --sile | --sil)
|
||||||
silent=yes ;;
|
silent=yes ;;
|
||||||
|
|
||||||
-runstatedir | --runstatedir | --runstatedi | --runstated \
|
|
||||||
| --runstate | --runstat | --runsta | --runst | --runs \
|
|
||||||
| --run | --ru | --r)
|
|
||||||
ac_prev=runstatedir ;;
|
|
||||||
-runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
|
|
||||||
| --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
|
|
||||||
| --run=* | --ru=* | --r=*)
|
|
||||||
runstatedir=$ac_optarg ;;
|
|
||||||
|
|
||||||
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
|
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
|
||||||
ac_prev=sbindir ;;
|
ac_prev=sbindir ;;
|
||||||
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
|
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
|
||||||
@ -1285,7 +1274,7 @@ fi
|
|||||||
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
|
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
|
||||||
datadir sysconfdir sharedstatedir localstatedir includedir \
|
datadir sysconfdir sharedstatedir localstatedir includedir \
|
||||||
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
|
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
|
||||||
libdir localedir mandir runstatedir
|
libdir localedir mandir
|
||||||
do
|
do
|
||||||
eval ac_val=\$$ac_var
|
eval ac_val=\$$ac_var
|
||||||
# Remove trailing slashes.
|
# Remove trailing slashes.
|
||||||
@ -1438,7 +1427,6 @@ Fine tuning of the installation directories:
|
|||||||
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
|
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
|
||||||
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
|
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
|
||||||
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
|
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
|
||||||
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
|
|
||||||
--libdir=DIR object code libraries [EPREFIX/lib]
|
--libdir=DIR object code libraries [EPREFIX/lib]
|
||||||
--includedir=DIR C header files [PREFIX/include]
|
--includedir=DIR C header files [PREFIX/include]
|
||||||
--oldincludedir=DIR C header files for non-gcc [/usr/include]
|
--oldincludedir=DIR C header files for non-gcc [/usr/include]
|
||||||
@ -18083,7 +18071,7 @@ else
|
|||||||
We can't simply define LARGE_OFF_T to be 9223372036854775807,
|
We can't simply define LARGE_OFF_T to be 9223372036854775807,
|
||||||
since some C++ compilers masquerading as C compilers
|
since some C++ compilers masquerading as C compilers
|
||||||
incorrectly reject 9223372036854775807. */
|
incorrectly reject 9223372036854775807. */
|
||||||
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
|
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
|
||||||
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
|
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
|
||||||
&& LARGE_OFF_T % 2147483647 == 1)
|
&& LARGE_OFF_T % 2147483647 == 1)
|
||||||
? 1 : -1];
|
? 1 : -1];
|
||||||
@ -18129,7 +18117,7 @@ else
|
|||||||
We can't simply define LARGE_OFF_T to be 9223372036854775807,
|
We can't simply define LARGE_OFF_T to be 9223372036854775807,
|
||||||
since some C++ compilers masquerading as C compilers
|
since some C++ compilers masquerading as C compilers
|
||||||
incorrectly reject 9223372036854775807. */
|
incorrectly reject 9223372036854775807. */
|
||||||
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
|
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
|
||||||
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
|
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
|
||||||
&& LARGE_OFF_T % 2147483647 == 1)
|
&& LARGE_OFF_T % 2147483647 == 1)
|
||||||
? 1 : -1];
|
? 1 : -1];
|
||||||
@ -18153,7 +18141,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
|||||||
We can't simply define LARGE_OFF_T to be 9223372036854775807,
|
We can't simply define LARGE_OFF_T to be 9223372036854775807,
|
||||||
since some C++ compilers masquerading as C compilers
|
since some C++ compilers masquerading as C compilers
|
||||||
incorrectly reject 9223372036854775807. */
|
incorrectly reject 9223372036854775807. */
|
||||||
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
|
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
|
||||||
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
|
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
|
||||||
&& LARGE_OFF_T % 2147483647 == 1)
|
&& LARGE_OFF_T % 2147483647 == 1)
|
||||||
? 1 : -1];
|
? 1 : -1];
|
||||||
@ -18198,7 +18186,7 @@ else
|
|||||||
We can't simply define LARGE_OFF_T to be 9223372036854775807,
|
We can't simply define LARGE_OFF_T to be 9223372036854775807,
|
||||||
since some C++ compilers masquerading as C compilers
|
since some C++ compilers masquerading as C compilers
|
||||||
incorrectly reject 9223372036854775807. */
|
incorrectly reject 9223372036854775807. */
|
||||||
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
|
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
|
||||||
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
|
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
|
||||||
&& LARGE_OFF_T % 2147483647 == 1)
|
&& LARGE_OFF_T % 2147483647 == 1)
|
||||||
? 1 : -1];
|
? 1 : -1];
|
||||||
@ -18222,7 +18210,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
|||||||
We can't simply define LARGE_OFF_T to be 9223372036854775807,
|
We can't simply define LARGE_OFF_T to be 9223372036854775807,
|
||||||
since some C++ compilers masquerading as C compilers
|
since some C++ compilers masquerading as C compilers
|
||||||
incorrectly reject 9223372036854775807. */
|
incorrectly reject 9223372036854775807. */
|
||||||
#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
|
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
|
||||||
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
|
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
|
||||||
&& LARGE_OFF_T % 2147483647 == 1)
|
&& LARGE_OFF_T % 2147483647 == 1)
|
||||||
? 1 : -1];
|
? 1 : -1];
|
||||||
|
@ -561,7 +561,6 @@ pdfdir = @pdfdir@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
program_transform_name = @program_transform_name@
|
program_transform_name = @program_transform_name@
|
||||||
psdir = @psdir@
|
psdir = @psdir@
|
||||||
runstatedir = @runstatedir@
|
|
||||||
sbindir = @sbindir@
|
sbindir = @sbindir@
|
||||||
sharedstatedir = @sharedstatedir@
|
sharedstatedir = @sharedstatedir@
|
||||||
srcdir = @srcdir@
|
srcdir = @srcdir@
|
||||||
|
@ -418,13 +418,15 @@ skip_close:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int flush_io (hawk_rtx_t* rtx, int rio, const hawk_ooch_t* name, int n)
|
static int flush_io (hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* name, int n)
|
||||||
{
|
{
|
||||||
int n2;
|
int n2;
|
||||||
|
hawk_rio_type_t rio;
|
||||||
|
|
||||||
|
rio = hawk_rtx_outtoriotype(rtx, out_type);
|
||||||
if (rtx->rio.handler[rio])
|
if (rtx->rio.handler[rio])
|
||||||
{
|
{
|
||||||
n2 = hawk_rtx_flushio(rtx, rio, name);
|
n2 = hawk_rtx_flushio(rtx, out_type, name);
|
||||||
if (n2 <= -1)
|
if (n2 <= -1)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -173,16 +173,6 @@ typedef struct hawk_tree_t hawk_tree_t;
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum hawk_rio_type_t
|
|
||||||
{
|
|
||||||
/* rio types available */
|
|
||||||
HAWK_RIO_PIPE,
|
|
||||||
HAWK_RIO_FILE,
|
|
||||||
HAWK_RIO_CONSOLE,
|
|
||||||
|
|
||||||
/* reserved for internal use only */
|
|
||||||
HAWK_RIO_NUM
|
|
||||||
};
|
|
||||||
|
|
||||||
struct hawk_tree_t
|
struct hawk_tree_t
|
||||||
{
|
{
|
||||||
|
@ -89,6 +89,7 @@ static hawk_oow_t push_args_from_stack (hawk_rtx_t* rtx, hawk_nde_fncall_t* call
|
|||||||
|
|
||||||
static int fnc_call (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
static int fnc_call (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||||
{
|
{
|
||||||
|
/* TODO: support to call a module function such as sys::getpid() */
|
||||||
hawk_fun_t* fun;
|
hawk_fun_t* fun;
|
||||||
hawk_oow_t nargs;
|
hawk_oow_t nargs;
|
||||||
hawk_nde_fncall_t call;
|
hawk_nde_fncall_t call;
|
||||||
@ -126,24 +127,33 @@ static int fnc_call (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* hawk::function_exists("xxxx"); */
|
/* hawk::function_exists("xxxx");
|
||||||
|
* hawk::function_exists("sys::getpid") */
|
||||||
static int fnc_function_exists (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
static int fnc_function_exists (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||||
{
|
{
|
||||||
hawk_val_t* a0;
|
hawk_val_t* a0;
|
||||||
hawk_ooch_t* str;
|
hawk_oocs_t name;
|
||||||
hawk_oow_t len;
|
|
||||||
int rx;
|
int rx;
|
||||||
|
|
||||||
a0 = hawk_rtx_getarg(rtx, 0);
|
a0 = hawk_rtx_getarg(rtx, 0);
|
||||||
str = hawk_rtx_getvaloocstr(rtx, a0, &len);
|
name.ptr = hawk_rtx_getvaloocstr(rtx, a0, &name.len);
|
||||||
if (HAWK_UNLIKELY(!str))
|
if (HAWK_UNLIKELY(!name.ptr))
|
||||||
{
|
{
|
||||||
rx = 0;
|
rx = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rx = (hawk_rtx_findfunwithoocstr(rtx, str) != HAWK_NULL);
|
if (hawk_count_oocstr(name.ptr) != name.len) rx = 0;
|
||||||
hawk_rtx_freevaloocstr (rtx, a0, str);
|
else
|
||||||
|
{
|
||||||
|
rx = (hawk_rtx_findfunwithoocstr(rtx, name.ptr) != HAWK_NULL);
|
||||||
|
if (!rx)
|
||||||
|
{
|
||||||
|
hawk_mod_sym_t sym;
|
||||||
|
rx = (hawk_query_module_with_name(hawk_rtx_gethawk(rtx), &name, &sym) != HAWK_NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hawk_rtx_freevaloocstr (rtx, a0, name.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||||
|
@ -116,6 +116,13 @@ void hawk_clearsionames (
|
|||||||
hawk_t* hawk
|
hawk_t* hawk
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
hawk_mod_t* hawk_query_module_with_name (
|
||||||
|
hawk_t* hawk,
|
||||||
|
const hawk_oocs_t* name,
|
||||||
|
hawk_mod_sym_t* sym
|
||||||
|
);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -254,7 +254,6 @@ static int flush_out (hawk_t* hawk);
|
|||||||
static hawk_mod_t* query_module (hawk_t* hawk, const hawk_oocs_t segs[], int nsegs, hawk_mod_sym_t* sym);
|
static hawk_mod_t* query_module (hawk_t* hawk, const hawk_oocs_t segs[], int nsegs, hawk_mod_sym_t* sym);
|
||||||
|
|
||||||
typedef struct kwent_t kwent_t;
|
typedef struct kwent_t kwent_t;
|
||||||
|
|
||||||
struct kwent_t
|
struct kwent_t
|
||||||
{
|
{
|
||||||
hawk_oocs_t name;
|
hawk_oocs_t name;
|
||||||
@ -3061,7 +3060,7 @@ static hawk_nde_t* parse_print (hawk_t* hawk, const hawk_loc_t* xloc)
|
|||||||
hawk_nde_print_t* nde;
|
hawk_nde_print_t* nde;
|
||||||
hawk_nde_t* args = HAWK_NULL;
|
hawk_nde_t* args = HAWK_NULL;
|
||||||
hawk_nde_t* out = HAWK_NULL;
|
hawk_nde_t* out = HAWK_NULL;
|
||||||
int out_type;
|
hawk_out_type_t out_type;
|
||||||
hawk_nde_type_t type;
|
hawk_nde_type_t type;
|
||||||
hawk_loc_t eloc;
|
hawk_loc_t eloc;
|
||||||
|
|
||||||
@ -3224,7 +3223,6 @@ static hawk_nde_t* parse_print (hawk_t* hawk, const hawk_loc_t* xloc)
|
|||||||
|
|
||||||
out = ep->right;
|
out = ep->right;
|
||||||
out_type = tab[i].out;
|
out_type = tab[i].out;
|
||||||
|
|
||||||
hawk_freemem (hawk, tmp);
|
hawk_freemem (hawk, tmp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -7468,7 +7466,7 @@ static hawk_mod_t* query_module (hawk_t* hawk, const hawk_oocs_t segs[], int nse
|
|||||||
/* TODO: binary search ... */
|
/* TODO: binary search ... */
|
||||||
for (n = 0; n < HAWK_COUNTOF(static_modtab); n++)
|
for (n = 0; n < HAWK_COUNTOF(static_modtab); n++)
|
||||||
{
|
{
|
||||||
if (hawk_comp_oocstr(static_modtab[n].modname, segs[0].ptr, 0) == 0)
|
if (hawk_comp_oochars_oocstr(segs[0].ptr, segs[0].len, static_modtab[n].modname) == 0)
|
||||||
{
|
{
|
||||||
load = static_modtab[n].modload;
|
load = static_modtab[n].modload;
|
||||||
break;
|
break;
|
||||||
@ -7491,7 +7489,7 @@ static hawk_mod_t* query_module (hawk_t* hawk, const hawk_oocs_t segs[], int nse
|
|||||||
/* i copy-insert 'md' into the table before calling 'load'.
|
/* i copy-insert 'md' into the table before calling 'load'.
|
||||||
* to pass the same address to load(), query(), etc */
|
* to pass the same address to load(), query(), etc */
|
||||||
pair = hawk_rbt_insert(hawk->modtab, segs[0].ptr, segs[0].len, &md, HAWK_SIZEOF(md));
|
pair = hawk_rbt_insert(hawk->modtab, segs[0].ptr, segs[0].len, &md, HAWK_SIZEOF(md));
|
||||||
if (pair == HAWK_NULL) return HAWK_NULL;
|
if (!pair) return HAWK_NULL;
|
||||||
|
|
||||||
mdp = (hawk_mod_data_t*)HAWK_RBT_VPTR(pair);
|
mdp = (hawk_mod_data_t*)HAWK_RBT_VPTR(pair);
|
||||||
if (load(&mdp->mod, hawk) <= -1)
|
if (load(&mdp->mod, hawk) <= -1)
|
||||||
@ -7601,3 +7599,26 @@ done:
|
|||||||
}
|
}
|
||||||
return &mdp->mod;
|
return &mdp->mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
hawk_mod_t* hawk_query_module_with_name (hawk_t* hawk, const hawk_oocs_t* name, hawk_mod_sym_t* sym)
|
||||||
|
{
|
||||||
|
const hawk_ooch_t* dc;
|
||||||
|
hawk_oocs_t segs[2];
|
||||||
|
/*TOOD: non-module builtin function? fnc? */
|
||||||
|
|
||||||
|
dc = hawk_find_oochars_in_oochars(name->ptr, name->len, HAWK_T("::"), 2, 0);
|
||||||
|
if (!dc)
|
||||||
|
{
|
||||||
|
hawk_seterrfmt (hawk, HAWK_NULL, HAWK_EINVAL, HAWK_T("invalid module name - %js"), name);
|
||||||
|
return HAWK_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
segs[0].ptr = name->ptr;
|
||||||
|
segs[0].len = dc - name->ptr;
|
||||||
|
|
||||||
|
segs[1].ptr = segs[0].ptr + segs[0].len + 2;
|
||||||
|
segs[1].len = name->len - segs[0].len - 2;
|
||||||
|
|
||||||
|
return query_module(hawk, segs, 2, sym);
|
||||||
|
}
|
||||||
|
@ -27,38 +27,53 @@
|
|||||||
#ifndef _HAWK_RIO_PRV_H_
|
#ifndef _HAWK_RIO_PRV_H_
|
||||||
#define _HAWK_RIO_PRV_H_
|
#define _HAWK_RIO_PRV_H_
|
||||||
|
|
||||||
|
enum hawk_rio_type_t
|
||||||
|
{
|
||||||
|
/* rio types available */
|
||||||
|
HAWK_RIO_PIPE = 0,
|
||||||
|
HAWK_RIO_FILE = 1,
|
||||||
|
HAWK_RIO_CONSOLE = 2,
|
||||||
|
|
||||||
|
/* reserved for internal use only */
|
||||||
|
HAWK_RIO_NUM
|
||||||
|
};
|
||||||
|
typedef enum hawk_rio_type_t hawk_rio_type_t;
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
hawk_rio_type_t hawk_rtx_intoriotype (hawk_rtx_t* rtx, hawk_in_type_t in_type);
|
||||||
|
hawk_rio_type_t hawk_rtx_outtoriotype (hawk_rtx_t* rtx, hawk_in_type_t out_type);
|
||||||
|
|
||||||
int hawk_rtx_readio (
|
int hawk_rtx_readio (
|
||||||
hawk_rtx_t* rtx, int in_type,
|
hawk_rtx_t* rtx, hawk_in_type_t in_type,
|
||||||
const hawk_ooch_t* name, hawk_ooecs_t* buf);
|
const hawk_ooch_t* name, hawk_ooecs_t* buf);
|
||||||
|
|
||||||
int hawk_rtx_readiobytes (
|
int hawk_rtx_readiobytes (
|
||||||
hawk_rtx_t* rtx, int in_type,
|
hawk_rtx_t* rtx, hawk_in_type_t in_type,
|
||||||
const hawk_ooch_t* name, hawk_becs_t* buf);
|
const hawk_ooch_t* name, hawk_becs_t* buf);
|
||||||
|
|
||||||
int hawk_rtx_writeioval (
|
int hawk_rtx_writeioval (
|
||||||
hawk_rtx_t* rtx, int out_type,
|
hawk_rtx_t* rtx, hawk_out_type_t out_type,
|
||||||
const hawk_ooch_t* name, hawk_val_t* v);
|
const hawk_ooch_t* name, hawk_val_t* v);
|
||||||
|
|
||||||
int hawk_rtx_writeiostr (
|
int hawk_rtx_writeiostr (
|
||||||
hawk_rtx_t* rtx, int out_type,
|
hawk_rtx_t* rtx, hawk_out_type_t out_type,
|
||||||
const hawk_ooch_t* name, hawk_ooch_t* str, hawk_oow_t len);
|
const hawk_ooch_t* name, hawk_ooch_t* str, hawk_oow_t len);
|
||||||
|
|
||||||
int hawk_rtx_writeiobytes (
|
int hawk_rtx_writeiobytes (
|
||||||
hawk_rtx_t* rtx, int out_type,
|
hawk_rtx_t* rtx, hawk_out_type_t out_type,
|
||||||
const hawk_ooch_t* name, hawk_bch_t* str, hawk_oow_t len);
|
const hawk_ooch_t* name, hawk_bch_t* str, hawk_oow_t len);
|
||||||
|
|
||||||
int hawk_rtx_flushio (
|
int hawk_rtx_flushio (
|
||||||
hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* name);
|
hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* name);
|
||||||
|
|
||||||
int hawk_rtx_nextio_read (
|
int hawk_rtx_nextio_read (
|
||||||
hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name);
|
hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_ooch_t* name);
|
||||||
|
|
||||||
int hawk_rtx_nextio_write (
|
int hawk_rtx_nextio_write (
|
||||||
hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* name);
|
hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* name);
|
||||||
|
|
||||||
int hawk_rtx_closeio (
|
int hawk_rtx_closeio (
|
||||||
hawk_rtx_t* rtx,
|
hawk_rtx_t* rtx,
|
||||||
|
@ -34,7 +34,7 @@ enum io_mask_t
|
|||||||
IO_MASK_CLEAR = 0x00FF
|
IO_MASK_CLEAR = 0x00FF
|
||||||
};
|
};
|
||||||
|
|
||||||
static int in_type_map[] =
|
static hawk_rio_type_t in_type_map[] =
|
||||||
{
|
{
|
||||||
/* the order should match the order of the
|
/* the order should match the order of the
|
||||||
* HAWK_IN_XXX values in tree.h */
|
* HAWK_IN_XXX values in tree.h */
|
||||||
@ -62,7 +62,7 @@ static int in_mask_map[] =
|
|||||||
IO_MASK_READ
|
IO_MASK_READ
|
||||||
};
|
};
|
||||||
|
|
||||||
static int out_type_map[] =
|
static hawk_rio_type_t out_type_map[] =
|
||||||
{
|
{
|
||||||
/* the order should match the order of the
|
/* the order should match the order of the
|
||||||
* HAWK_OUT_XXX values in tree.h */
|
* HAWK_OUT_XXX values in tree.h */
|
||||||
@ -93,8 +93,18 @@ static int out_mask_map[] =
|
|||||||
IO_MASK_WRITE
|
IO_MASK_WRITE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
hawk_rio_type_t hawk_rtx_intoriotype (hawk_rtx_t* rtx, hawk_in_type_t in_type)
|
||||||
|
{
|
||||||
|
return in_type_map[in_type];
|
||||||
|
}
|
||||||
|
|
||||||
|
hawk_rio_type_t hawk_rtx_outtoriotype (hawk_rtx_t* rtx, hawk_in_type_t out_type)
|
||||||
|
{
|
||||||
|
return out_type_map[out_type];
|
||||||
|
}
|
||||||
|
|
||||||
static int find_rio_in (
|
static int find_rio_in (
|
||||||
hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name,
|
hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_ooch_t* name,
|
||||||
int mbs_if_new, hawk_rio_arg_t** rio, hawk_rio_impl_t* fun)
|
int mbs_if_new, hawk_rio_arg_t** rio, hawk_rio_impl_t* fun)
|
||||||
{
|
{
|
||||||
hawk_rio_arg_t* p = rtx->rio.chain;
|
hawk_rio_arg_t* p = rtx->rio.chain;
|
||||||
@ -353,7 +363,7 @@ static HAWK_INLINE int match_long_brs(hawk_rtx_t* rtx, hawk_becs_t* buf, hawk_ri
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hawk_rtx_readio (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name, hawk_ooecs_t* buf)
|
int hawk_rtx_readio (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_ooch_t* name, hawk_ooecs_t* buf)
|
||||||
{
|
{
|
||||||
hawk_rio_arg_t* p;
|
hawk_rio_arg_t* p;
|
||||||
hawk_rio_impl_t handler;
|
hawk_rio_impl_t handler;
|
||||||
@ -671,7 +681,7 @@ int hawk_rtx_readio (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name, hawk
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int hawk_rtx_readiobytes (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name, hawk_becs_t* buf)
|
int hawk_rtx_readiobytes (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_ooch_t* name, hawk_becs_t* buf)
|
||||||
{
|
{
|
||||||
hawk_rio_arg_t* p;
|
hawk_rio_arg_t* p;
|
||||||
hawk_rio_impl_t handler;
|
hawk_rio_impl_t handler;
|
||||||
@ -989,7 +999,7 @@ int hawk_rtx_readiobytes (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int hawk_rtx_writeioval (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* name, hawk_val_t* v)
|
int hawk_rtx_writeioval (hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* name, hawk_val_t* v)
|
||||||
{
|
{
|
||||||
hawk_val_type_t vtype;
|
hawk_val_type_t vtype;
|
||||||
vtype = HAWK_RTX_GETVALTYPE (rtx, v);
|
vtype = HAWK_RTX_GETVALTYPE (rtx, v);
|
||||||
@ -1034,7 +1044,7 @@ struct write_io_data_t
|
|||||||
};
|
};
|
||||||
typedef struct write_io_data_t write_io_data_t;
|
typedef struct write_io_data_t write_io_data_t;
|
||||||
|
|
||||||
static int prepare_for_write_io_data (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* name, write_io_data_t* wid)
|
static int prepare_for_write_io_data (hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* name, write_io_data_t* wid)
|
||||||
{
|
{
|
||||||
hawk_rio_arg_t* p = rtx->rio.chain;
|
hawk_rio_arg_t* p = rtx->rio.chain;
|
||||||
hawk_rio_impl_t handler;
|
hawk_rio_impl_t handler;
|
||||||
@ -1122,7 +1132,7 @@ static int prepare_for_write_io_data (hawk_rtx_t* rtx, int out_type, const hawk_
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hawk_rtx_writeiostr (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* name, hawk_ooch_t* str, hawk_oow_t len)
|
int hawk_rtx_writeiostr (hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* name, hawk_ooch_t* str, hawk_oow_t len)
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
write_io_data_t wid;
|
write_io_data_t wid;
|
||||||
@ -1149,7 +1159,7 @@ int hawk_rtx_writeiostr (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* name,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hawk_rtx_writeiobytes (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* name, hawk_bch_t* str, hawk_oow_t len)
|
int hawk_rtx_writeiobytes (hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* name, hawk_bch_t* str, hawk_oow_t len)
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
write_io_data_t wid;
|
write_io_data_t wid;
|
||||||
@ -1176,7 +1186,7 @@ int hawk_rtx_writeiobytes (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* nam
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hawk_rtx_flushio (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* name)
|
int hawk_rtx_flushio (hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* name)
|
||||||
{
|
{
|
||||||
hawk_rio_arg_t* p = rtx->rio.chain;
|
hawk_rio_arg_t* p = rtx->rio.chain;
|
||||||
hawk_rio_impl_t handler;
|
hawk_rio_impl_t handler;
|
||||||
@ -1226,7 +1236,7 @@ int hawk_rtx_flushio (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* name)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hawk_rtx_nextio_read (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name)
|
int hawk_rtx_nextio_read (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_ooch_t* name)
|
||||||
{
|
{
|
||||||
hawk_rio_arg_t* p = rtx->rio.chain;
|
hawk_rio_arg_t* p = rtx->rio.chain;
|
||||||
hawk_rio_impl_t handler;
|
hawk_rio_impl_t handler;
|
||||||
@ -1295,7 +1305,7 @@ int hawk_rtx_nextio_read (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int hawk_rtx_nextio_write (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* name)
|
int hawk_rtx_nextio_write (hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* name)
|
||||||
{
|
{
|
||||||
hawk_rio_arg_t* p = rtx->rio.chain;
|
hawk_rio_arg_t* p = rtx->rio.chain;
|
||||||
hawk_rio_impl_t handler;
|
hawk_rio_impl_t handler;
|
||||||
@ -1360,7 +1370,7 @@ int hawk_rtx_nextio_write (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* nam
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int hawk_rtx_closio_read (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name)
|
int hawk_rtx_closio_read (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_ooch_t* name)
|
||||||
{
|
{
|
||||||
hawk_rio_arg_t* p = rtx->rio.chain, * px = HAWK_NULL;
|
hawk_rio_arg_t* p = rtx->rio.chain, * px = HAWK_NULL;
|
||||||
hawk_rio_impl_t handler;
|
hawk_rio_impl_t handler;
|
||||||
@ -1417,7 +1427,7 @@ int hawk_rtx_closio_read (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hawk_rtx_closio_write (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* name)
|
int hawk_rtx_closio_write (hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* name)
|
||||||
{
|
{
|
||||||
hawk_rio_arg_t* p = rtx->rio.chain, * px = HAWK_NULL;
|
hawk_rio_arg_t* p = rtx->rio.chain, * px = HAWK_NULL;
|
||||||
hawk_rio_impl_t handler;
|
hawk_rio_impl_t handler;
|
||||||
|
@ -101,8 +101,8 @@ static int run_reset (hawk_rtx_t* rtx, hawk_nde_reset_t* nde);
|
|||||||
static int run_print (hawk_rtx_t* rtx, hawk_nde_print_t* nde);
|
static int run_print (hawk_rtx_t* rtx, hawk_nde_print_t* nde);
|
||||||
static int run_printf (hawk_rtx_t* rtx, hawk_nde_print_t* nde);
|
static int run_printf (hawk_rtx_t* rtx, hawk_nde_print_t* nde);
|
||||||
|
|
||||||
static int output_formatted (hawk_rtx_t* run, int out_type, const hawk_ooch_t* dst, const hawk_ooch_t* fmt, hawk_oow_t fmt_len, hawk_nde_t* args);
|
static int output_formatted (hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* dst, const hawk_ooch_t* fmt, hawk_oow_t fmt_len, hawk_nde_t* args);
|
||||||
static int output_formatted_bytes (hawk_rtx_t* run, int out_type, const hawk_ooch_t* dst, const hawk_bch_t* fmt, hawk_oow_t fmt_len, hawk_nde_t* args);
|
static int output_formatted_bytes (hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* dst, const hawk_bch_t* fmt, hawk_oow_t fmt_len, hawk_nde_t* args);
|
||||||
|
|
||||||
static hawk_val_t* eval_expression (hawk_rtx_t* rtx, hawk_nde_t* nde);
|
static hawk_val_t* eval_expression (hawk_rtx_t* rtx, hawk_nde_t* nde);
|
||||||
static hawk_val_t* eval_expression0 (hawk_rtx_t* rtx, hawk_nde_t* nde);
|
static hawk_val_t* eval_expression0 (hawk_rtx_t* rtx, hawk_nde_t* nde);
|
||||||
@ -3307,8 +3307,7 @@ static int run_print (hawk_rtx_t* rtx, hawk_nde_print_t* nde)
|
|||||||
/* check if print is followed by any arguments */
|
/* check if print is followed by any arguments */
|
||||||
if (!nde->args)
|
if (!nde->args)
|
||||||
{
|
{
|
||||||
/* if it doesn't have any arguments, print the entire
|
/* if it doesn't have any arguments, print the entire input record */
|
||||||
* input record */
|
|
||||||
n = hawk_rtx_writeiostr(rtx, nde->out_type, out.ptr, HAWK_OOECS_PTR(&rtx->inrec.line), HAWK_OOECS_LEN(&rtx->inrec.line));
|
n = hawk_rtx_writeiostr(rtx, nde->out_type, out.ptr, HAWK_OOECS_PTR(&rtx->inrec.line), HAWK_OOECS_LEN(&rtx->inrec.line));
|
||||||
if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/)
|
if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/)
|
||||||
{
|
{
|
||||||
@ -3525,7 +3524,7 @@ oops_1:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int output_formatted (
|
static int output_formatted (
|
||||||
hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* dst,
|
hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* dst,
|
||||||
const hawk_ooch_t* fmt, hawk_oow_t fmt_len, hawk_nde_t* args)
|
const hawk_ooch_t* fmt, hawk_oow_t fmt_len, hawk_nde_t* args)
|
||||||
{
|
{
|
||||||
hawk_ooch_t* ptr;
|
hawk_ooch_t* ptr;
|
||||||
@ -3545,7 +3544,7 @@ static int output_formatted (
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int output_formatted_bytes (
|
static int output_formatted_bytes (
|
||||||
hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* dst,
|
hawk_rtx_t* rtx, hawk_out_type_t out_type, const hawk_ooch_t* dst,
|
||||||
const hawk_bch_t* fmt, hawk_oow_t fmt_len, hawk_nde_t* args)
|
const hawk_bch_t* fmt, hawk_oow_t fmt_len, hawk_nde_t* args)
|
||||||
{
|
{
|
||||||
hawk_bch_t* ptr;
|
hawk_bch_t* ptr;
|
||||||
|
@ -313,6 +313,8 @@ static void* std_mod_open_checked (hawk_t* hawk, const hawk_mod_spec_t* spec)
|
|||||||
void* hawk_stdmodopen (hawk_t* hawk, const hawk_mod_spec_t* spec)
|
void* hawk_stdmodopen (hawk_t* hawk, const hawk_mod_spec_t* spec)
|
||||||
{
|
{
|
||||||
#if defined(USE_LTDL)
|
#if defined(USE_LTDL)
|
||||||
|
if (spec)
|
||||||
|
{
|
||||||
void* h;
|
void* h;
|
||||||
lt_dladvise adv;
|
lt_dladvise adv;
|
||||||
hawk_bch_t* modpath;
|
hawk_bch_t* modpath;
|
||||||
@ -351,14 +353,25 @@ void* hawk_stdmodopen (hawk_t* hawk, const hawk_mod_spec_t* spec)
|
|||||||
/*lt_dladvise_resident (&adv); useful for debugging with valgrind */
|
/*lt_dladvise_resident (&adv); useful for debugging with valgrind */
|
||||||
|
|
||||||
h = lt_dlopenadvise(modpath, adv);
|
h = lt_dlopenadvise(modpath, adv);
|
||||||
|
if (!h) hawk_seterrfmt (hawk, HAWK_NULL, HAWK_ESYSERR, HAWK_T("%hs"), lt_dlerror());
|
||||||
|
|
||||||
lt_dladvise_destroy (&adv);
|
lt_dladvise_destroy (&adv);
|
||||||
|
|
||||||
if (modpath) hawk_freemem(hawk, modpath);
|
if (modpath) hawk_freemem(hawk, modpath);
|
||||||
return h;
|
return h;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
void* h;
|
||||||
|
h = lt_dlopen(NULL);
|
||||||
|
if (HAWK_UNLIKELY(!h)) hawk_seterrfmt (hawk, HAWK_NULL, HAWK_ESYSERR, HAWK_T("%hs"), lt_dlerror());
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
|
|
||||||
|
if (spec)
|
||||||
|
{
|
||||||
HMODULE h;
|
HMODULE h;
|
||||||
hawk_ooch_t* modpath;
|
hawk_ooch_t* modpath;
|
||||||
const hawk_ooch_t* tmp[6];
|
const hawk_ooch_t* tmp[6];
|
||||||
@ -392,9 +405,19 @@ void* hawk_stdmodopen (hawk_t* hawk, const hawk_mod_spec_t* spec)
|
|||||||
|
|
||||||
HAWK_ASSERT (HAWK_SIZEOF(h) <= HAWK_SIZEOF(void*));
|
HAWK_ASSERT (HAWK_SIZEOF(h) <= HAWK_SIZEOF(void*));
|
||||||
return h;
|
return h;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HMODULE h;
|
||||||
|
h = GetModuleHandle(NULL);
|
||||||
|
if (!h) hawk_seterrnum (hawk, HAWK_NULL, hawk_syserr_to_errnum(GetLastError());
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
#elif defined(__OS2__)
|
#elif defined(__OS2__)
|
||||||
|
|
||||||
|
if (spec)
|
||||||
|
{
|
||||||
HMODULE h;
|
HMODULE h;
|
||||||
hawk_bch_t* modpath;
|
hawk_bch_t* modpath;
|
||||||
const hawk_ooch_t* tmp[6];
|
const hawk_ooch_t* tmp[6];
|
||||||
@ -422,7 +445,7 @@ void* hawk_stdmodopen (hawk_t* hawk, const hawk_mod_spec_t* spec)
|
|||||||
#else
|
#else
|
||||||
modpath = hawk_dupucstrarrtobcstr(hawk, tmp, HAWK_NULL);
|
modpath = hawk_dupucstrarrtobcstr(hawk, tmp, HAWK_NULL);
|
||||||
#endif
|
#endif
|
||||||
if (!modpath) return HAWK_NULL;
|
if (HAWK_UNLIKELY(!modpath)) return HAWK_NULL;
|
||||||
|
|
||||||
/* DosLoadModule() seems to have severe limitation on
|
/* DosLoadModule() seems to have severe limitation on
|
||||||
* the file name it can load (max-8-letters.xxx) */
|
* the file name it can load (max-8-letters.xxx) */
|
||||||
@ -437,9 +460,17 @@ void* hawk_stdmodopen (hawk_t* hawk, const hawk_mod_spec_t* spec)
|
|||||||
|
|
||||||
HAWK_ASSERT (HAWK_SIZEOF(h) <= HAWK_SIZEOF(void*));
|
HAWK_ASSERT (HAWK_SIZEOF(h) <= HAWK_SIZEOF(void*));
|
||||||
return h;
|
return h;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hawk_seterrnum (hawk, HAWK_NULL, HAWK_ENOIMPL);
|
||||||
|
return HAWK_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#elif defined(__DOS__) && defined(HAWK_ENABLE_DOS_DYNAMIC_MODULE)
|
#elif defined(__DOS__) && defined(HAWK_ENABLE_DOS_DYNAMIC_MODULE)
|
||||||
|
|
||||||
|
if (spec)
|
||||||
|
{
|
||||||
/* the DOS code here is not generic enough. it's for a specific
|
/* the DOS code here is not generic enough. it's for a specific
|
||||||
* dos-extender only. the best is not to use dynamic loading
|
* dos-extender only. the best is not to use dynamic loading
|
||||||
* when building for DOS. */
|
* when building for DOS. */
|
||||||
@ -477,8 +508,18 @@ void* hawk_stdmodopen (hawk_t* hawk, const hawk_mod_spec_t* spec)
|
|||||||
|
|
||||||
HAWK_ASSERT (HAWK_SIZEOF(h) <= HAWK_SIZEOF(void*));
|
HAWK_ASSERT (HAWK_SIZEOF(h) <= HAWK_SIZEOF(void*));
|
||||||
return h;
|
return h;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
void* h;
|
||||||
|
h = GetModuleHandle(NULL);
|
||||||
|
if (!h) hawk_seterrnum (hawk, HAWK_NULL, HAWK_ESYSERR);
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
#elif defined(USE_DLFCN)
|
#elif defined(USE_DLFCN)
|
||||||
|
if (spec)
|
||||||
|
{
|
||||||
void* h;
|
void* h;
|
||||||
hawk_bch_t* modpath;
|
hawk_bch_t* modpath;
|
||||||
const hawk_ooch_t* tmp[6];
|
const hawk_ooch_t* tmp[6];
|
||||||
@ -512,7 +553,14 @@ void* hawk_stdmodopen (hawk_t* hawk, const hawk_mod_spec_t* spec)
|
|||||||
hawk_freemem (hawk, modpath);
|
hawk_freemem (hawk, modpath);
|
||||||
|
|
||||||
return h;
|
return h;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
void* h;
|
||||||
|
h = dlopen(NULL, RTLD_NOW | RTLD_LOCAL);
|
||||||
|
if (!h) hawk_seterrfmt (hawk, HAWK_NULL, HAWK_ESYSERR, HAWK_T("%hs"), dlerror());
|
||||||
|
return h;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
hawk_seterrnum (hawk, HAWK_NULL, HAWK_ENOIMPL);
|
hawk_seterrnum (hawk, HAWK_NULL, HAWK_ENOIMPL);
|
||||||
return HAWK_NULL;
|
return HAWK_NULL;
|
||||||
@ -524,11 +572,11 @@ void hawk_stdmodclose (hawk_t* hawk, void* handle)
|
|||||||
#if defined(USE_LTDL)
|
#if defined(USE_LTDL)
|
||||||
lt_dlclose (handle);
|
lt_dlclose (handle);
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
FreeLibrary ((HMODULE)handle);
|
if (handle != GetModuleHandle(NULL)) FreeLibrary ((HMODULE)handle);
|
||||||
#elif defined(__OS2__)
|
#elif defined(__OS2__)
|
||||||
DosFreeModule ((HMODULE)handle);
|
DosFreeModule ((HMODULE)handle);
|
||||||
#elif defined(__DOS__) && defined(HAWK_ENABLE_DOS_DYNAMIC_MODULE)
|
#elif defined(__DOS__) && defined(HAWK_ENABLE_DOS_DYNAMIC_MODULE)
|
||||||
FreeModule (handle);
|
if (handle != GetModuleHandle(NULL)) FreeModule (handle);
|
||||||
#elif defined(USE_DLFCN)
|
#elif defined(USE_DLFCN)
|
||||||
dlclose (handle);
|
dlclose (handle);
|
||||||
#else
|
#else
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#ifndef _HAWK_TREE_PRV_H_
|
#ifndef _HAWK_TREE_PRV_H_
|
||||||
#define _HAWK_TREE_PRV_H_
|
#define _HAWK_TREE_PRV_H_
|
||||||
|
|
||||||
|
|
||||||
enum hawk_in_type_t
|
enum hawk_in_type_t
|
||||||
{
|
{
|
||||||
/* the order of these values match
|
/* the order of these values match
|
||||||
@ -37,6 +38,8 @@ enum hawk_in_type_t
|
|||||||
HAWK_IN_FILE,
|
HAWK_IN_FILE,
|
||||||
HAWK_IN_CONSOLE
|
HAWK_IN_CONSOLE
|
||||||
};
|
};
|
||||||
|
typedef enum hawk_in_type_t hawk_in_type_t;
|
||||||
|
|
||||||
|
|
||||||
enum hawk_out_type_t
|
enum hawk_out_type_t
|
||||||
{
|
{
|
||||||
@ -49,6 +52,7 @@ enum hawk_out_type_t
|
|||||||
HAWK_OUT_APFILE, /* file for appending */
|
HAWK_OUT_APFILE, /* file for appending */
|
||||||
HAWK_OUT_CONSOLE
|
HAWK_OUT_CONSOLE
|
||||||
};
|
};
|
||||||
|
typedef enum hawk_out_type_t hawk_out_type_t;
|
||||||
|
|
||||||
typedef struct hawk_nde_blk_t hawk_nde_blk_t;
|
typedef struct hawk_nde_blk_t hawk_nde_blk_t;
|
||||||
typedef struct hawk_nde_grp_t hawk_nde_grp_t;
|
typedef struct hawk_nde_grp_t hawk_nde_grp_t;
|
||||||
@ -258,7 +262,7 @@ struct hawk_nde_getline_t
|
|||||||
HAWK_NDE_HDR;
|
HAWK_NDE_HDR;
|
||||||
hawk_nde_t* var;
|
hawk_nde_t* var;
|
||||||
int mbs;
|
int mbs;
|
||||||
int in_type; /* HAWK_IN_CONSOLE, HAWK_IN_FILE, etc */
|
hawk_in_type_t in_type; /* HAWK_IN_CONSOLE, HAWK_IN_FILE, etc */
|
||||||
hawk_nde_t* in;
|
hawk_nde_t* in;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -356,7 +360,7 @@ struct hawk_nde_print_t
|
|||||||
{
|
{
|
||||||
HAWK_NDE_HDR;
|
HAWK_NDE_HDR;
|
||||||
hawk_nde_t* args;
|
hawk_nde_t* args;
|
||||||
int out_type; /* HAWK_OUT_XXX */
|
hawk_out_type_t out_type; /* HAWK_OUT_XXX */
|
||||||
hawk_nde_t* out;
|
hawk_nde_t* out;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -398,7 +398,6 @@ pdfdir = @pdfdir@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
program_transform_name = @program_transform_name@
|
program_transform_name = @program_transform_name@
|
||||||
psdir = @psdir@
|
psdir = @psdir@
|
||||||
runstatedir = @runstatedir@
|
|
||||||
sbindir = @sbindir@
|
sbindir = @sbindir@
|
||||||
sharedstatedir = @sharedstatedir@
|
sharedstatedir = @sharedstatedir@
|
||||||
srcdir = @srcdir@
|
srcdir = @srcdir@
|
||||||
|
@ -194,21 +194,28 @@ static ffi_node_t* new_ffi_node (hawk_rtx_t* rtx, ffi_list_t* ffi_list, const ha
|
|||||||
{
|
{
|
||||||
hawk_t* hawk = hawk_rtx_gethawk(rtx);
|
hawk_t* hawk = hawk_rtx_gethawk(rtx);
|
||||||
ffi_node_t* ffi_node;
|
ffi_node_t* ffi_node;
|
||||||
hawk_mod_spec_t spec;
|
|
||||||
void* handle;
|
void* handle;
|
||||||
|
|
||||||
ffi_node = __new_ffi_node(rtx, ffi_list);
|
ffi_node = __new_ffi_node(rtx, ffi_list);
|
||||||
if (!ffi_node) return HAWK_NULL;
|
if (!ffi_node) return HAWK_NULL;
|
||||||
|
|
||||||
|
if (name)
|
||||||
|
{
|
||||||
|
hawk_mod_spec_t spec;
|
||||||
HAWK_MEMSET (&spec, 0, HAWK_SIZEOF(spec));
|
HAWK_MEMSET (&spec, 0, HAWK_SIZEOF(spec));
|
||||||
spec.name = name;
|
spec.name = name;
|
||||||
|
|
||||||
handle = hawk->prm.modopen(hawk, &spec);
|
handle = hawk->prm.modopen(hawk, &spec);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
handle = hawk->prm.modopen(hawk, HAWK_NULL);
|
||||||
|
}
|
||||||
if (!handle)
|
if (!handle)
|
||||||
{
|
{
|
||||||
const hawk_ooch_t* olderrmsg;
|
const hawk_ooch_t* olderrmsg;
|
||||||
olderrmsg = hawk_backuperrmsg(hawk);
|
olderrmsg = hawk_backuperrmsg(hawk);
|
||||||
hawk_rtx_seterrfmt (rtx, HAWK_NULL, HAWK_ENOMEM, HAWK_T("unable to open the '%js' ffi module - %js"), name, olderrmsg);
|
hawk_rtx_seterrfmt (rtx, HAWK_NULL, HAWK_ENOMEM, HAWK_T("unable to open the '%js' ffi module - %js"), (name? name: HAWK_T("")), olderrmsg);
|
||||||
|
|
||||||
__free_ffi_node (rtx, ffi_list, ffi_node);
|
__free_ffi_node (rtx, ffi_list, ffi_node);
|
||||||
return HAWK_NULL;
|
return HAWK_NULL;
|
||||||
@ -318,6 +325,8 @@ static int fnc_open (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
|
|
||||||
ffi_list = rtx_to_ffi_list(rtx, fi);
|
ffi_list = rtx_to_ffi_list(rtx, fi);
|
||||||
|
|
||||||
|
if (hawk_rtx_getnargs(rtx) >= 1)
|
||||||
|
{
|
||||||
a0 = hawk_rtx_getarg(rtx, 0);
|
a0 = hawk_rtx_getarg(rtx, 0);
|
||||||
name.ptr = hawk_rtx_getvaloocstr(rtx, a0, &name.len);
|
name.ptr = hawk_rtx_getvaloocstr(rtx, a0, &name.len);
|
||||||
if (HAWK_UNLIKELY(!name.ptr))
|
if (HAWK_UNLIKELY(!name.ptr))
|
||||||
@ -331,6 +340,12 @@ static int fnc_open (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
ret = set_error_on_ffi_list(rtx, ffi_list, HAWK_EINVAL, HAWK_T("invalid ffi module name '%.*js'"), name.len, name.ptr);
|
ret = set_error_on_ffi_list(rtx, ffi_list, HAWK_EINVAL, HAWK_T("invalid ffi module name '%.*js'"), name.len, name.ptr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
name.ptr = HAWK_NULL;
|
||||||
|
a0 = HAWK_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
ffi_node = new_ffi_node(rtx, ffi_list, name.ptr);
|
ffi_node = new_ffi_node(rtx, ffi_list, name.ptr);
|
||||||
if (ffi_node) ret = ffi_node->id;
|
if (ffi_node) ret = ffi_node->id;
|
||||||
@ -623,7 +638,7 @@ oops:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int capture_return (hawk_rtx_t* rtx, ffi_list_t* ffi_list, ffi_node_t* ffi_node, hawk_ooch_t fmtc, int _unsigned, hawk_int_t* rx)
|
static int capture_return (hawk_rtx_t* rtx, ffi_list_t* ffi_list, ffi_node_t* ffi_node, hawk_ooch_t fmtc, int _unsigned, hawk_oow_t refidx, hawk_int_t* rx)
|
||||||
{
|
{
|
||||||
hawk_val_t* r;
|
hawk_val_t* r;
|
||||||
ffi_t* ffi = &ffi_node->ffi;
|
ffi_t* ffi = &ffi_node->ffi;
|
||||||
@ -688,7 +703,7 @@ static int capture_return (hawk_rtx_t* rtx, ffi_list_t* ffi_list, ffi_node_t* ff
|
|||||||
}
|
}
|
||||||
if (HAWK_UNLIKELY(!r)) goto oops;
|
if (HAWK_UNLIKELY(!r)) goto oops;
|
||||||
|
|
||||||
if (hawk_rtx_setrefval(rtx, (hawk_val_ref_t*)hawk_rtx_getarg(rtx, 1), r) <= -1) goto oops;
|
if (hawk_rtx_setrefval(rtx, (hawk_val_ref_t*)hawk_rtx_getarg(rtx, refidx), r) <= -1) goto oops;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
oops:
|
oops:
|
||||||
@ -733,8 +748,8 @@ static int fnc_call (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
hawk_t* hawk = hawk_rtx_gethawk(rtx);
|
hawk_t* hawk = hawk_rtx_gethawk(rtx);
|
||||||
ffi_list_t* ffi_list;
|
ffi_list_t* ffi_list;
|
||||||
ffi_node_t* ffi_node;
|
ffi_node_t* ffi_node;
|
||||||
ffi_t* ffi = HAWK_NULL;
|
ffi_t* ffi;
|
||||||
hawk_int_t ret = -1;
|
hawk_int_t ret;
|
||||||
|
|
||||||
hawk_val_t* a2;
|
hawk_val_t* a2;
|
||||||
hawk_oocs_t fun;
|
hawk_oocs_t fun;
|
||||||
@ -749,6 +764,15 @@ static int fnc_call (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
|
|
||||||
ffi_status fs;
|
ffi_status fs;
|
||||||
|
|
||||||
|
#define FNC_CALL_ARG_BASE 4
|
||||||
|
|
||||||
|
ret = -1;
|
||||||
|
ffi = HAWK_NULL;
|
||||||
|
fun.ptr = HAWK_NULL;
|
||||||
|
sig.ptr = HAWK_NULL;
|
||||||
|
a2 = HAWK_NULL;
|
||||||
|
a3 = HAWK_NULL;
|
||||||
|
|
||||||
/* ffi::call (ffi-handle, return-value, "function name", "signature", argument....); */
|
/* ffi::call (ffi-handle, return-value, "function name", "signature", argument....); */
|
||||||
ffi_list = rtx_to_ffi_list(rtx, fi);
|
ffi_list = rtx_to_ffi_list(rtx, fi);
|
||||||
ffi_node = get_ffi_list_node_with_arg(rtx, ffi_list, hawk_rtx_getarg(rtx, 0), &ret);
|
ffi_node = get_ffi_list_node_with_arg(rtx, ffi_list, hawk_rtx_getarg(rtx, 0), &ret);
|
||||||
@ -762,6 +786,12 @@ static int fnc_call (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hawk_count_oocstr(fun.ptr) != fun.len)
|
||||||
|
{
|
||||||
|
ret = set_error_on_ffi_list(rtx, ffi_list, HAWK_EINVAL, HAWK_T("invalid function name - %.*js"), fun.len, fun.ptr);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
a3 = hawk_rtx_getarg(rtx, 3);
|
a3 = hawk_rtx_getarg(rtx, 3);
|
||||||
sig.ptr = hawk_rtx_getvaloocstr(rtx, a3, &sig.len);
|
sig.ptr = hawk_rtx_getvaloocstr(rtx, a3, &sig.len);
|
||||||
if (HAWK_UNLIKELY(!sig.ptr))
|
if (HAWK_UNLIKELY(!sig.ptr))
|
||||||
@ -770,12 +800,6 @@ static int fnc_call (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hawk_count_oocstr(fun.ptr) != fun.len)
|
|
||||||
{
|
|
||||||
ret = set_error_on_ffi_list(rtx, ffi_list, HAWK_EINVAL, HAWK_T("invalid function name - %.*js"), fun.len, fun.ptr);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
ffi = &ffi_node->ffi;
|
ffi = &ffi_node->ffi;
|
||||||
ffi->arg_count = 0;
|
ffi->arg_count = 0;
|
||||||
|
|
||||||
@ -815,13 +839,13 @@ static int fnc_call (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* more items in signature than the actual argument */
|
/* more items in signature than the actual argument */
|
||||||
if (j >= hawk_rtx_getnargs(rtx) - 4)
|
if (j >= hawk_rtx_getnargs(rtx) - FNC_CALL_ARG_BASE)
|
||||||
{
|
{
|
||||||
ret = set_error_on_ffi_list(rtx, ffi_list, HAWK_EINVAL, HAWK_T("two few arguments for the argument signature"));
|
ret = set_error_on_ffi_list(rtx, ffi_list, HAWK_EINVAL, HAWK_T("two few arguments for the argument signature"));
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (add_ffi_arg(rtx, ffi_list, ffi_node, fmtc, _unsigned, hawk_rtx_getarg(rtx, j + 4), &ret) <= -1) goto done;
|
if (add_ffi_arg(rtx, ffi_list, ffi_node, fmtc, _unsigned, hawk_rtx_getarg(rtx, j + FNC_CALL_ARG_BASE), &ret) <= -1) goto done;
|
||||||
_unsigned = 0;
|
_unsigned = 0;
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
@ -854,7 +878,7 @@ static int fnc_call (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
|
|
||||||
ffi_call (&ffi->cif, FFI_FN(funx), &ffi->ret_sv, ffi->arg_values);
|
ffi_call (&ffi->cif, FFI_FN(funx), &ffi->ret_sv, ffi->arg_values);
|
||||||
|
|
||||||
if (fmtc != FMTC_NULL && capture_return(rtx, ffi_list, ffi_node, fmtc, _unsigned, &ret) <= -1) goto done;
|
if (fmtc != FMTC_NULL && capture_return(rtx, ffi_list, ffi_node, fmtc, _unsigned, 1, &ret) <= -1) goto done;
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
@ -869,6 +893,9 @@ done:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sig.ptr) hawk_rtx_freevaloocstr(rtx, a3, sig.ptr);
|
||||||
|
if (fun.ptr) hawk_rtx_freevaloocstr(rtx, a2, fun.ptr);
|
||||||
|
|
||||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, ret));
|
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, ret));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -891,13 +918,10 @@ static int fnc_errmsg (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
|
|
||||||
static hawk_mod_fnc_tab_t fnctab[] =
|
static hawk_mod_fnc_tab_t fnctab[] =
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
* TODO: implement ffi::_call() that calls in the current module without open...
|
|
||||||
{ HAWK_T("_call"), { { 3, A_MAX, HAWK_T("rv") }, fnc_call, 0 } }, */
|
|
||||||
{ HAWK_T("call"), { { 4, A_MAX, HAWK_T("vrv") }, fnc_call, 0 } },
|
{ HAWK_T("call"), { { 4, A_MAX, HAWK_T("vrv") }, fnc_call, 0 } },
|
||||||
{ HAWK_T("close"), { { 1, 1, HAWK_NULL }, fnc_close, 0 } },
|
{ HAWK_T("close"), { { 1, 1, HAWK_NULL }, fnc_close, 0 } },
|
||||||
{ HAWK_T("errmsg"), { { 0, 0, HAWK_NULL }, fnc_errmsg, 0 } },
|
{ HAWK_T("errmsg"), { { 0, 0, HAWK_NULL }, fnc_errmsg, 0 } },
|
||||||
{ HAWK_T("open"), { { 1, 1, HAWK_NULL }, fnc_open, 0 } },
|
{ HAWK_T("open"), { { 0, 1, HAWK_NULL }, fnc_open, 0 } },
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
|
@ -351,7 +351,6 @@ pdfdir = @pdfdir@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
program_transform_name = @program_transform_name@
|
program_transform_name = @program_transform_name@
|
||||||
psdir = @psdir@
|
psdir = @psdir@
|
||||||
runstatedir = @runstatedir@
|
|
||||||
sbindir = @sbindir@
|
sbindir = @sbindir@
|
||||||
sharedstatedir = @sharedstatedir@
|
sharedstatedir = @sharedstatedir@
|
||||||
srcdir = @srcdir@
|
srcdir = @srcdir@
|
||||||
|
@ -557,7 +557,6 @@ pdfdir = @pdfdir@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
program_transform_name = @program_transform_name@
|
program_transform_name = @program_transform_name@
|
||||||
psdir = @psdir@
|
psdir = @psdir@
|
||||||
runstatedir = @runstatedir@
|
|
||||||
sbindir = @sbindir@
|
sbindir = @sbindir@
|
||||||
sharedstatedir = @sharedstatedir@
|
sharedstatedir = @sharedstatedir@
|
||||||
srcdir = @srcdir@
|
srcdir = @srcdir@
|
||||||
|
@ -328,7 +328,6 @@ pdfdir = @pdfdir@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
program_transform_name = @program_transform_name@
|
program_transform_name = @program_transform_name@
|
||||||
psdir = @psdir@
|
psdir = @psdir@
|
||||||
runstatedir = @runstatedir@
|
|
||||||
sbindir = @sbindir@
|
sbindir = @sbindir@
|
||||||
sharedstatedir = @sharedstatedir@
|
sharedstatedir = @sharedstatedir@
|
||||||
srcdir = @srcdir@
|
srcdir = @srcdir@
|
||||||
|
Loading…
Reference in New Issue
Block a user