working on Hawk and HawkStd

This commit is contained in:
hyung-hwan 2020-01-05 15:12:24 +00:00
parent 6f6b860971
commit 8a990821a5
4 changed files with 344 additions and 256 deletions

View File

@ -138,7 +138,7 @@ static HAWK_INLINE rxtn_t* GET_RXTN(hawk_rtx_t* rtx) { return (rxtn_t*)((hawk_ui
// Hawk::RIO
//////////////////////////////////////////////////////////////////
Hawk::RIOBase::RIOBase (Run* run, rio_arg_t* riod): run (run), riod (riod)
Hawk::RIOBase::RIOBase (Run* run, hawk_rio_arg_t* riod): run (run), riod (riod)
{
}
@ -172,13 +172,13 @@ Hawk::RIOBase::operator Hawk* () const
return this->run->awk;
}
Hawk::RIOBase::operator Hawk::awk_t* () const
Hawk::RIOBase::operator hawk_t* () const
{
HAWK_ASSERT (hawk_rtx_getawk(this->run->rtx) == this->run->awk->getHandle());
return this->run->awk->getHandle();
}
Hawk::RIOBase::operator Hawk::rio_arg_t* () const
Hawk::RIOBase::operator hawk_rio_arg_t* () const
{
return this->riod;
}
@ -188,7 +188,7 @@ Hawk::RIOBase::operator Hawk::Run* () const
return this->run;
}
Hawk::RIOBase::operator Hawk::rtx_t* () const
Hawk::RIOBase::operator hawk_rtx_t* () const
{
return this->run->rtx;
}
@ -197,7 +197,7 @@ Hawk::RIOBase::operator Hawk::rtx_t* () const
// Hawk::Pipe
//////////////////////////////////////////////////////////////////
Hawk::Pipe::Pipe (Run* run, rio_arg_t* riod): RIOBase (run, riod)
Hawk::Pipe::Pipe (Run* run, hawk_rio_arg_t* riod): RIOBase (run, riod)
{
}
@ -215,7 +215,7 @@ Hawk::Pipe::CloseMode Hawk::Pipe::getCloseMode () const
// Hawk::File
//////////////////////////////////////////////////////////////////
Hawk::File::File (Run* run, rio_arg_t* riod): RIOBase (run, riod)
Hawk::File::File (Run* run, hawk_rio_arg_t* riod): RIOBase (run, riod)
{
}
@ -228,7 +228,7 @@ Hawk::File::Mode Hawk::File::getMode () const
// Hawk::Console
//////////////////////////////////////////////////////////////////
Hawk::Console::Console (Run* run, rio_arg_t* riod):
Hawk::Console::Console (Run* run, hawk_rio_arg_t* riod):
RIOBase (run, riod), filename (HAWK_NULL)
{
}
@ -237,7 +237,7 @@ Hawk::Console::~Console ()
{
if (filename != HAWK_NULL)
{
hawk_freemem ((awk_t*)this, filename);
hawk_freemem ((hawk_t*)this, filename);
}
}
@ -255,7 +255,7 @@ int Hawk::Console::setFileName (const hawk_ooch_t* name)
int Hawk::Console::setFNR (int_t fnr)
{
val_t* tmp;
hawk_val_t* tmp;
int n;
tmp = hawk_rtx_makeintval (this->run->rtx, fnr);
@ -660,7 +660,7 @@ int Hawk::Value::getMbs (const hawk_bch_t** str, hawk_oow_t* len) const
return 0;
}
int Hawk::Value::setVal (val_t* v)
int Hawk::Value::setVal (hawk_val_t* v)
{
if (this->run == HAWK_NULL)
{
@ -671,7 +671,7 @@ int Hawk::Value::setVal (val_t* v)
return this->setVal(this->run, v);
}
int Hawk::Value::setVal (Run* r, val_t* v)
int Hawk::Value::setVal (Run* r, hawk_val_t* v)
{
if (this->run != HAWK_NULL)
{
@ -713,7 +713,7 @@ int Hawk::Value::setInt (int_t v)
int Hawk::Value::setInt (Run* r, int_t v)
{
val_t* tmp;
hawk_val_t* tmp;
tmp = hawk_rtx_makeintval(r->rtx, v);
if (tmp == HAWK_NULL)
{
@ -739,7 +739,7 @@ int Hawk::Value::setFlt (flt_t v)
int Hawk::Value::setFlt (Run* r, flt_t v)
{
val_t* tmp;
hawk_val_t* tmp;
tmp = hawk_rtx_makefltval(r->rtx, v);
if (tmp == HAWK_NULL)
{
@ -765,7 +765,7 @@ int Hawk::Value::setStr (const hawk_ooch_t* str, hawk_oow_t len, bool numeric)
int Hawk::Value::setStr (Run* r, const hawk_ooch_t* str, hawk_oow_t len, bool numeric)
{
val_t* tmp;
hawk_val_t* tmp;
hawk_oocs_t oocs;
oocs.ptr = (hawk_ooch_t*)str;
@ -792,7 +792,7 @@ int Hawk::Value::setStr (const hawk_ooch_t* str, bool numeric)
int Hawk::Value::setStr (Run* r, const hawk_ooch_t* str, bool numeric)
{
val_t* tmp;
hawk_val_t* tmp;
tmp = numeric? hawk_rtx_makenstrvalwithoocstr(r->rtx, str):
hawk_rtx_makestrvalwithoocstr(r->rtx, str);
if (tmp == HAWK_NULL)
@ -820,7 +820,7 @@ int Hawk::Value::setMbs (const hawk_bch_t* str, hawk_oow_t len)
int Hawk::Value::setMbs (Run* r, const hawk_bch_t* str, hawk_oow_t len)
{
val_t* tmp;
hawk_val_t* tmp;
hawk_bcs_t oocs;
oocs.ptr = (hawk_bch_t*)str;
@ -846,7 +846,7 @@ int Hawk::Value::setMbs (const hawk_bch_t* str)
int Hawk::Value::setMbs (Run* r, const hawk_bch_t* str)
{
val_t* tmp;
hawk_val_t* tmp;
tmp = hawk_rtx_makembsval(r->rtx, str, hawk_count_bcstr(str));
if (!tmp)
{
@ -859,13 +859,13 @@ int Hawk::Value::setMbs (Run* r, const hawk_bch_t* str)
return n;
}
int Hawk::Value::setIndexedVal (const Index& idx, val_t* v)
int Hawk::Value::setIndexedVal (const Index& idx, hawk_val_t* v)
{
if (this->run == HAWK_NULL) return -1;
return this->setIndexedVal (this->run, idx, v);
}
int Hawk::Value::setIndexedVal (Run* r, const Index& idx, val_t* v)
int Hawk::Value::setIndexedVal (Run* r, const Index& idx, hawk_val_t* v)
{
HAWK_ASSERT (r != HAWK_NULL);
@ -873,7 +873,7 @@ int Hawk::Value::setIndexedVal (Run* r, const Index& idx, val_t* v)
{
// the previous value is not a map.
// a new map value needs to be created first.
val_t* map = hawk_rtx_makemapval(r->rtx);
hawk_val_t* map = hawk_rtx_makemapval(r->rtx);
if (map == HAWK_NULL)
{
r->awk->retrieveError (r);
@ -934,7 +934,7 @@ int Hawk::Value::setIndexedInt (const Index& idx, int_t v)
int Hawk::Value::setIndexedInt (Run* r, const Index& idx, int_t v)
{
val_t* tmp = hawk_rtx_makeintval (r->rtx, v);
hawk_val_t* tmp = hawk_rtx_makeintval (r->rtx, v);
if (tmp == HAWK_NULL)
{
r->awk->retrieveError (r);
@ -956,7 +956,7 @@ int Hawk::Value::setIndexedFlt (const Index& idx, flt_t v)
int Hawk::Value::setIndexedFlt (Run* r, const Index& idx, flt_t v)
{
val_t* tmp = hawk_rtx_makefltval(r->rtx, v);
hawk_val_t* tmp = hawk_rtx_makefltval(r->rtx, v);
if (tmp == HAWK_NULL)
{
r->awk->retrieveError (r);
@ -979,7 +979,7 @@ int Hawk::Value::setIndexedStr (const Index& idx, const hawk_ooch_t* str, hawk_o
int Hawk::Value::setIndexedStr (
Run* r, const Index& idx, const hawk_ooch_t* str, hawk_oow_t len, bool numeric)
{
val_t* tmp;
hawk_val_t* tmp;
hawk_oocs_t oocs;
oocs.ptr = (hawk_ooch_t*)str;
@ -1008,7 +1008,7 @@ int Hawk::Value::setIndexedStr (const Index& idx, const hawk_ooch_t* str, bool n
int Hawk::Value::setIndexedStr (Run* r, const Index& idx, const hawk_ooch_t* str, bool numeric)
{
val_t* tmp;
hawk_val_t* tmp;
tmp = numeric? hawk_rtx_makenstrvalwithoocstr(r->rtx, str):
hawk_rtx_makestrvalwithoocstr(r->rtx, str);
if (tmp == HAWK_NULL)
@ -1032,7 +1032,7 @@ int Hawk::Value::setIndexedMbs (const Index& idx, const hawk_bch_t* str, hawk_oo
int Hawk::Value::setIndexedMbs (Run* r, const Index& idx, const hawk_bch_t* str, hawk_oow_t len)
{
val_t* tmp;
hawk_val_t* tmp;
hawk_bcs_t oocs;
oocs.ptr = (hawk_bch_t*)str;
@ -1060,7 +1060,7 @@ int Hawk::Value::setIndexedMbs (const Index& idx, const hawk_bch_t* str)
int Hawk::Value::setIndexedMbs (Run* r, const Index& idx, const hawk_bch_t* str)
{
val_t* tmp;
hawk_val_t* tmp;
tmp = hawk_rtx_makembsval(r->rtx, str, hawk_count_bcstr(str));
if (tmp == HAWK_NULL)
{
@ -1094,7 +1094,7 @@ int Hawk::Value::getIndexed (const Index& idx, Value* v) const
}
// get the value from the map.
val_t* fv = hawk_rtx_getmapvalfld(this->run->rtx, val, (hawk_ooch_t*)idx.ptr, idx.len);
hawk_val_t* fv = hawk_rtx_getmapvalfld(this->run->rtx, val, (hawk_ooch_t*)idx.ptr, idx.len);
// the key is not found. it is not an error. v is just nil
if (fv == HAWK_NULL)
@ -1154,7 +1154,7 @@ Hawk::Run::Run (Hawk* awk): awk (awk), rtx (HAWK_NULL)
{
}
Hawk::Run::Run (Hawk* awk, rtx_t* rtx): awk (awk), rtx (rtx)
Hawk::Run::Run (Hawk* awk, hawk_rtx_t* rtx): awk (awk), rtx (rtx)
{
HAWK_ASSERT (this->rtx != HAWK_NULL);
}
@ -1163,16 +1163,6 @@ Hawk::Run::~Run ()
{
}
Hawk::Run::operator Hawk* () const
{
return this->awk;
}
Hawk::Run::operator Hawk::rtx_t* () const
{
return this->rtx;
}
void Hawk::Run::halt () const
{
HAWK_ASSERT (this->rtx != HAWK_NULL);
@ -1182,16 +1172,16 @@ void Hawk::Run::halt () const
bool Hawk::Run::isHalt () const
{
HAWK_ASSERT (this->rtx != HAWK_NULL);
return hawk_rtx_ishalt (this->rtx)? true: false;
return !!hawk_rtx_ishalt(this->rtx);
}
Hawk::errnum_t Hawk::Run::getErrorNumber () const
hawk_errnum_t Hawk::Run::getErrorNumber () const
{
HAWK_ASSERT (this->rtx != HAWK_NULL);
return hawk_rtx_geterrnum (this->rtx);
return hawk_rtx_geterrnum(this->rtx);
}
Hawk::loc_t Hawk::Run::getErrorLocation () const
hawk_loc_t Hawk::Run::getErrorLocation () const
{
HAWK_ASSERT (this->rtx != HAWK_NULL);
return *hawk_rtx_geterrloc (this->rtx);
@ -1203,32 +1193,35 @@ const hawk_ooch_t* Hawk::Run::getErrorMessage () const
return hawk_rtx_geterrmsg (this->rtx);
}
void Hawk::Run::setError (errnum_t code, const hawk_oocs_t* args, const loc_t* loc)
void Hawk::Run::setError (hawk_errnum_t code, const hawk_loc_t* loc)
{
HAWK_ASSERT (this->rtx != HAWK_NULL);
hawk_rtx_seterror (this->rtx, code, args, loc);
hawk_rtx_seterrnum (this->rtx, loc, code);
}
void Hawk::Run::setErrorWithMessage (
errnum_t code, const hawk_ooch_t* msg, const loc_t* loc)
void Hawk::Run::formatError (hawk_errnum_t code, const hawk_loc_t* loc, const hawk_bch_t* fmt, ...)
{
HAWK_ASSERT (this->rtx != HAWK_NULL);
va_list ap;
va_start (ap, fmt);
hawk_rtx_seterrbfmt (this->rtx, loc, code, fmt, ap);
va_end (ap);
}
errinf_t errinf;
HAWK_MEMSET (&errinf, 0, HAWK_SIZEOF(errinf));
errinf.num = code;
if (loc == HAWK_NULL) errinf.loc = *loc;
hawk_copy_oocstr (errinf.msg, HAWK_COUNTOF(errinf.msg), msg);
hawk_rtx_seterrinf (this->rtx, &errinf);
void Hawk::Run::formatError (hawk_errnum_t code, const hawk_loc_t* loc, const hawk_uch_t* fmt, ...)
{
HAWK_ASSERT (this->rtx != HAWK_NULL);
va_list ap;
va_start (ap, fmt);
hawk_rtx_seterrufmt (this->rtx, loc, code, fmt, ap);
va_end (ap);
}
int Hawk::Run::setGlobal (int id, int_t v)
{
HAWK_ASSERT (this->rtx != HAWK_NULL);
val_t* tmp = hawk_rtx_makeintval (this->rtx, v);
hawk_val_t* tmp = hawk_rtx_makeintval (this->rtx, v);
if (tmp == HAWK_NULL) return -1;
hawk_rtx_refupval (this->rtx, tmp);
@ -1241,7 +1234,7 @@ int Hawk::Run::setGlobal (int id, flt_t v)
{
HAWK_ASSERT (this->rtx != HAWK_NULL);
val_t* tmp = hawk_rtx_makefltval (this->rtx, v);
hawk_val_t* tmp = hawk_rtx_makefltval (this->rtx, v);
if (tmp == HAWK_NULL) return -1;
hawk_rtx_refupval (this->rtx, tmp);
@ -1254,7 +1247,7 @@ int Hawk::Run::setGlobal (int id, const hawk_ooch_t* ptr, hawk_oow_t len)
{
HAWK_ASSERT (this->rtx != HAWK_NULL);
val_t* tmp = hawk_rtx_makestrvalwithoochars(this->rtx, ptr, len);
hawk_val_t* tmp = hawk_rtx_makestrvalwithoochars(this->rtx, ptr, len);
if (tmp == HAWK_NULL) return -1;
hawk_rtx_refupval (this->rtx, tmp);
@ -1266,7 +1259,7 @@ int Hawk::Run::setGlobal (int id, const hawk_ooch_t* ptr, hawk_oow_t len)
int Hawk::Run::setGlobal (int id, const Value& gbl)
{
HAWK_ASSERT (this->rtx != HAWK_NULL);
return hawk_rtx_setgbl (this->rtx, id, (val_t*)gbl);
return hawk_rtx_setgbl (this->rtx, id, (hawk_val_t*)gbl);
}
int Hawk::Run::getGlobal (int id, Value& g) const
@ -1295,31 +1288,25 @@ Hawk::Hawk (Mmgr* mmgr):
errinf.num = HAWK_ENOERR;
}
Hawk::operator Hawk::awk_t* () const
{
return this->awk;
}
const hawk_ooch_t* Hawk::getErrorString (errnum_t num) const
const hawk_ooch_t* Hawk::getErrorString (hawk_errnum_t num) const
{
HAWK_ASSERT (awk != HAWK_NULL);
HAWK_ASSERT (dflerrstr != HAWK_NULL);
return dflerrstr (awk, num);
HAWK_ASSERT (this->dflerrstr != HAWK_NULL);
return this->dflerrstr(awk, num);
}
const hawk_ooch_t* Hawk::xerrstr (awk_t* a, errnum_t num)
const hawk_ooch_t* Hawk::xerrstr (hawk_t* a, hawk_errnum_t num)
{
Hawk* awk = *(Hawk**)GET_XTN(a);
return awk->getErrorString (num);
return awk->getErrorString(num);
}
Hawk::errnum_t Hawk::getErrorNumber () const
hawk_errnum_t Hawk::getErrorNumber () const
{
return this->errinf.num;
}
Hawk::loc_t Hawk::getErrorLocation () const
hawk_loc_t Hawk::getErrorLocation () const
{
return this->errinf.loc;
}
@ -1329,32 +1316,56 @@ const hawk_ooch_t* Hawk::getErrorMessage () const
return this->errinf.msg;
}
void Hawk::setError (errnum_t code, const hawk_oocs_t* args, const loc_t* loc)
void Hawk::setError (hawk_errnum_t code, const hawk_loc_t* loc)
{
if (awk != HAWK_NULL)
if (this->awk)
{
hawk_seterror (awk, code, args, loc);
hawk_seterrnum (this->awk, loc, code);
this->retrieveError ();
}
else
{
HAWK_MEMSET (&errinf, 0, HAWK_SIZEOF(errinf));
errinf.num = code;
if (loc != HAWK_NULL) errinf.loc = *loc;
hawk_copy_oocstr (errinf.msg, HAWK_COUNTOF(errinf.msg),
HAWK_T("not ready to set an error message"));
HAWK_MEMSET (&this->errinf, 0, HAWK_SIZEOF(this->errinf));
this->errinf.num = code;
if (loc != HAWK_NULL) this->errinf.loc = *loc;
hawk_copy_oocstr (this->errinf.msg, HAWK_COUNTOF(this->errinf.msg), HAWK_T("not ready to set an error message"));
}
}
void Hawk::setErrorWithMessage (errnum_t code, const hawk_ooch_t* msg, const loc_t* loc)
void Hawk::formatError (hawk_errnum_t code, const hawk_loc_t* loc, const hawk_bch_t* fmt, ...)
{
HAWK_MEMSET (&errinf, 0, HAWK_SIZEOF(errinf));
if (this->awk)
{
va_list ap;
va_start (ap, fmt);
hawk_seterrbfmt (this->awk, loc, code, fmt, ap);
va_end (ap);
}
else
{
HAWK_MEMSET (&this->errinf, 0, HAWK_SIZEOF(this->errinf));
this->errinf.num = code;
if (loc != HAWK_NULL) this->errinf.loc = *loc;
hawk_copy_oocstr (this->errinf.msg, HAWK_COUNTOF(this->errinf.msg), HAWK_T("not ready to set an error message"));
}
}
errinf.num = code;
if (loc != HAWK_NULL) errinf.loc = *loc;
hawk_copy_oocstr (errinf.msg, HAWK_COUNTOF(errinf.msg), msg);
if (awk != HAWK_NULL) hawk_seterrinf (awk, &errinf);
void Hawk::formatError (hawk_errnum_t code, const hawk_loc_t* loc, const hawk_uch_t* fmt, ...)
{
if (this->awk)
{
va_list ap;
va_start (ap, fmt);
hawk_seterrufmt (this->awk, loc, code, fmt, ap);
va_end (ap);
}
else
{
HAWK_MEMSET (&this->errinf, 0, HAWK_SIZEOF(this->errinf));
this->errinf.num = code;
if (loc != HAWK_NULL) this->errinf.loc = *loc;
hawk_copy_oocstr (this->errinf.msg, HAWK_COUNTOF(this->errinf.msg), HAWK_T("not ready to set an error message"));
}
}
void Hawk::clearError ()
@ -1367,7 +1378,7 @@ void Hawk::retrieveError ()
{
if (this->awk == HAWK_NULL)
{
clearError ();
this->clearError ();
}
else
{
@ -1426,8 +1437,11 @@ int Hawk::open ()
xtn->ecb.close = fini_xtn;
xtn->ecb.clear = clear_xtn;
/*
// TODO:
dflerrstr = hawk_geterrstr(this->awk);
hawk_seterrstr (this->awk, xerrstr);
hawk_seterrstr (this->awk, Hawk::xerrstr);
*/
#if defined(HAWK_USE_HTB_FOR_FUNCTION_MAP)
this->functionMap = hawk_htb_open(
@ -1555,7 +1569,7 @@ int Hawk::loop (Value* ret)
HAWK_ASSERT (this->awk != HAWK_NULL);
HAWK_ASSERT (this->runctx.rtx != HAWK_NULL);
val_t* rv = hawk_rtx_loop (this->runctx.rtx);
hawk_val_t* rv = hawk_rtx_loop (this->runctx.rtx);
if (rv == HAWK_NULL)
{
this->retrieveError (&this->runctx);
@ -1573,15 +1587,15 @@ int Hawk::call (const hawk_bch_t* name, Value* ret, const Value* args, hawk_oow_
HAWK_ASSERT (this->awk != HAWK_NULL);
HAWK_ASSERT (this->runctx.rtx != HAWK_NULL);
val_t* buf[16];
val_t** ptr = HAWK_NULL;
hawk_val_t* buf[16];
hawk_val_t** ptr = HAWK_NULL;
if (args != HAWK_NULL)
{
if (nargs <= HAWK_COUNTOF(buf)) ptr = buf;
else
{
ptr = (val_t**)hawk_allocmem(awk, HAWK_SIZEOF(val_t*) * nargs);
ptr = (hawk_val_t**)hawk_allocmem(awk, HAWK_SIZEOF(hawk_val_t*) * nargs);
if (ptr == HAWK_NULL)
{
this->runctx.setError (HAWK_ENOMEM);
@ -1590,10 +1604,10 @@ int Hawk::call (const hawk_bch_t* name, Value* ret, const Value* args, hawk_oow_
}
}
for (hawk_oow_t i = 0; i < nargs; i++) ptr[i] = (val_t*)args[i];
for (hawk_oow_t i = 0; i < nargs; i++) ptr[i] = (hawk_val_t*)args[i];
}
val_t* rv = hawk_rtx_callwithbcstr(this->runctx.rtx, name, ptr, nargs);
hawk_val_t* rv = hawk_rtx_callwithbcstr(this->runctx.rtx, name, ptr, nargs);
if (ptr != HAWK_NULL && ptr != buf) hawk_freemem (awk, ptr);
@ -1614,15 +1628,15 @@ int Hawk::call (const hawk_uch_t* name, Value* ret, const Value* args, hawk_oow_
HAWK_ASSERT (this->awk != HAWK_NULL);
HAWK_ASSERT (this->runctx.rtx != HAWK_NULL);
val_t* buf[16];
val_t** ptr = HAWK_NULL;
hawk_val_t* buf[16];
hawk_val_t** ptr = HAWK_NULL;
if (args != HAWK_NULL)
{
if (nargs <= HAWK_COUNTOF(buf)) ptr = buf;
else
{
ptr = (val_t**)hawk_allocmem(awk, HAWK_SIZEOF(val_t*) * nargs);
ptr = (hawk_val_t**)hawk_allocmem(awk, HAWK_SIZEOF(hawk_val_t*) * nargs);
if (ptr == HAWK_NULL)
{
this->runctx.setError (HAWK_ENOMEM);
@ -1631,10 +1645,10 @@ int Hawk::call (const hawk_uch_t* name, Value* ret, const Value* args, hawk_oow_
}
}
for (hawk_oow_t i = 0; i < nargs; i++) ptr[i] = (val_t*)args[i];
for (hawk_oow_t i = 0; i < nargs; i++) ptr[i] = (hawk_val_t*)args[i];
}
val_t* rv = hawk_rtx_callwithucstr(this->runctx.rtx, name, ptr, nargs);
hawk_val_t* rv = hawk_rtx_callwithucstr(this->runctx.rtx, name, ptr, nargs);
if (ptr != HAWK_NULL && ptr != buf) hawk_freemem (awk, ptr);
@ -1666,7 +1680,7 @@ int Hawk::init_runctx ()
rio.file = fileHandler;
rio.console = consoleHandler;
rtx_t* rtx = hawk_rtx_open(awk, HAWK_SIZEOF(rxtn_t), &rio);
hawk_rtx_t* rtx = hawk_rtx_open(awk, HAWK_SIZEOF(rxtn_t), &rio);
if (rtx == HAWK_NULL)
{
this->retrieveError();
@ -1726,20 +1740,20 @@ int Hawk::dispatch_function (Run* run, const fnc_info_t* fi)
#if defined(HAWK_USE_HTB_FOR_FUNCTION_MAP)
hawk_htb_pair_t* pair;
pair = hawk_htb_search (this->functionMap, fi->name.ptr, fi->name.len);
pair = hawk_htb_search(this->functionMap, fi->name.ptr, fi->name.len);
if (pair == HAWK_NULL)
{
run->setError (HAWK_EFUNNF, &fi->name);
run->formatError (HAWK_EFUNNF, HAWK_NULL, HAWK_T("function '%.*js' not defined"), &fi->name.len, &fi->name.ptr);
return -1;
}
FunctionHandler handler;
handler = *(FunctionHandler*)HAWK_HTB_VPTR(pair);
#else
FunctionMap::Pair* pair = this->functionMap.search (Cstr(fi->name.ptr, fi->name.len));
FunctionMap::Pair* pair = this->functionMap.search(Cstr(fi->name.ptr, fi->name.len));
if (pair == HAWK_NULL)
{
run->setError (HAWK_EFUNNF, &fi->name);
run->formatError (HAWK_EFUNNF, HAWK_NULL, HAWK_T("function '%.*js' not defined"), &fi->name.len, &fi->name.ptr);
return -1;
}
@ -1786,7 +1800,7 @@ int Hawk::dispatch_function (Run* run, const fnc_info_t* fi)
for (i = 0; i < nargs; i++)
{
int xx;
val_t* v = hawk_rtx_getarg (run->rtx, i);
hawk_val_t* v = hawk_rtx_getarg (run->rtx, i);
if (HAWK_RTX_GETVALTYPE (run->rtx, v) == HAWK_VAL_REF)
{
@ -1856,7 +1870,7 @@ int Hawk::dispatch_function (Run* run, const fnc_info_t* fi)
// Do NOT change the run field from function handler
HAWK_ASSERT (args[i].run == run);
val_t* v = hawk_rtx_getarg(run->rtx, i);
hawk_val_t* v = hawk_rtx_getarg(run->rtx, i);
if (HAWK_RTX_GETVALTYPE(run->rtx, v) == HAWK_VAL_REF)
{
if (hawk_rtx_setrefval(run->rtx, (hawk_val_ref_t*)v, args[i].toVal()) <= -1)
@ -1895,7 +1909,7 @@ int Hawk::dispatch_function (Run* run, const fnc_info_t* fi)
return 0;
}
int Hawk::xstrs_t::add (awk_t* awk, const hawk_ooch_t* arg, hawk_oow_t len)
int Hawk::xstrs_t::add (hawk_t* awk, const hawk_ooch_t* arg, hawk_oow_t len)
{
if (this->len >= this->capa)
{
@ -1921,7 +1935,7 @@ int Hawk::xstrs_t::add (awk_t* awk, const hawk_ooch_t* arg, hawk_oow_t len)
return 0;
}
void Hawk::xstrs_t::clear (awk_t* awk)
void Hawk::xstrs_t::clear (hawk_t* awk)
{
if (this->ptr != HAWK_NULL)
{
@ -2138,7 +2152,7 @@ int Hawk::deleteFunction (const hawk_ooch_t* name)
}
hawk_ooi_t Hawk::readSource (
awk_t* awk, sio_cmd_t cmd, sio_arg_t* arg,
hawk_t* awk, sio_cmd_t cmd, sio_arg_t* arg,
hawk_ooch_t* data, hawk_oow_t count)
{
xtn_t* xtn = GET_XTN(awk);
@ -2158,7 +2172,7 @@ hawk_ooi_t Hawk::readSource (
}
hawk_ooi_t Hawk::writeSource (
awk_t* awk, hawk_sio_cmd_t cmd, sio_arg_t* arg,
hawk_t* awk, hawk_sio_cmd_t cmd, sio_arg_t* arg,
hawk_ooch_t* data, hawk_oow_t count)
{
xtn_t* xtn = GET_XTN(awk);
@ -2177,7 +2191,7 @@ hawk_ooi_t Hawk::writeSource (
}
}
hawk_ooi_t Hawk::pipeHandler (rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod, void* data, hawk_oow_t count)
hawk_ooi_t Hawk::pipeHandler (hawk_rtx_t* rtx, rio_cmd_t cmd, hawk_rio_arg_t* riod, void* data, hawk_oow_t count)
{
rxtn_t* rxtn = GET_RXTN(rtx);
Hawk* awk = rxtn->run->awk;
@ -2241,7 +2255,7 @@ hawk_ooi_t Hawk::pipeHandler (rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod, void*
}
}
hawk_ooi_t Hawk::fileHandler (rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod, void* data, hawk_oow_t count)
hawk_ooi_t Hawk::fileHandler (hawk_rtx_t* rtx, rio_cmd_t cmd, hawk_rio_arg_t* riod, void* data, hawk_oow_t count)
{
rxtn_t* rxtn = GET_RXTN(rtx);
Hawk* awk = rxtn->run->awk;
@ -2305,7 +2319,7 @@ hawk_ooi_t Hawk::fileHandler (rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod, void*
}
}
hawk_ooi_t Hawk::consoleHandler (rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod, void* data, hawk_oow_t count)
hawk_ooi_t Hawk::consoleHandler (hawk_rtx_t* rtx, rio_cmd_t cmd, hawk_rio_arg_t* riod, void* data, hawk_oow_t count)
{
rxtn_t* rxtn = GET_RXTN(rtx);
Hawk* awk = rxtn->run->awk;
@ -2487,37 +2501,37 @@ int Hawk::nextConsole (Console& io)
return -1;
}
int Hawk::functionHandler (rtx_t* rtx, const fnc_info_t* fi)
int Hawk::functionHandler (hawk_rtx_t* rtx, const fnc_info_t* fi)
{
rxtn_t* rxtn = GET_RXTN(rtx);
return rxtn->run->awk->dispatch_function (rxtn->run, fi);
}
Hawk::flt_t Hawk::pow (awk_t* awk, flt_t x, flt_t y)
Hawk::flt_t Hawk::pow (hawk_t* awk, flt_t x, flt_t y)
{
xtn_t* xtn = GET_XTN(awk);
return xtn->awk->pow (x, y);
}
Hawk::flt_t Hawk::mod (awk_t* awk, flt_t x, flt_t y)
Hawk::flt_t Hawk::mod (hawk_t* awk, flt_t x, flt_t y)
{
xtn_t* xtn = GET_XTN(awk);
return xtn->awk->mod (x, y);
}
void* Hawk::modopen (awk_t* awk, const mod_spec_t* spec)
void* Hawk::modopen (hawk_t* awk, const mod_spec_t* spec)
{
xtn_t* xtn = GET_XTN(awk);
return xtn->awk->modopen (spec);
}
void Hawk::modclose (awk_t* awk, void* handle)
void Hawk::modclose (hawk_t* awk, void* handle)
{
xtn_t* xtn = GET_XTN(awk);
xtn->awk->modclose (handle);
}
void* Hawk::modgetsym (awk_t* awk, void* handle, const hawk_ooch_t* name)
void* Hawk::modgetsym (hawk_t* awk, void* handle, const hawk_ooch_t* name)
{
xtn_t* xtn = GET_XTN(awk);
return xtn->awk->modgetsym (handle, name);

View File

@ -371,23 +371,17 @@ private:
///
/// The Hawk class implements an AWK interpreter by wrapping around
/// #hawk_t and #hawk_rtx_t.
/// #hhawk_t and #hawk_rtx_t.
///
class HAWK_EXPORT Hawk: public Uncopyable, public Mmged
{
public:
// define a primitive handle
typedef hawk_t awk_t;
// redefine flt_t. To access Types::flt_t, use the fully qualified
// name as it's overriding Types::flt_t.
typedef hawk_flt_t flt_t;
typedef hawk_int_t int_t;
typedef hawk_uint_t uint_t;
typedef hawk_loc_t loc_t;
typedef hawk_errnum_t errnum_t;
typedef hawk_errstr_t errstr_t;
typedef hawk_errinf_t errinf_t;
@ -405,14 +399,7 @@ public:
/// The gbl_id_t type redefines #hawk_gbl_id_t.
typedef hawk_gbl_id_t gbl_id_t;
/** Represents an internal awk value */
typedef hawk_val_t val_t;
/** Represents a runtime context */
typedef hawk_rtx_t rtx_t;
/** Represents an runtime I/O data */
typedef hawk_rio_arg_t rio_arg_t;
typedef hawk_rio_cmd_t rio_cmd_t;
@ -444,7 +431,7 @@ protected:
/// different. The example below changes the formatting string for
/// #HAWK_ENOENT.
/// \code
/// const hawk_ooch_t* MyHawk::getErrorString (hawk_errnum_t num) const
/// const hawk_ooch_t* MyHawk::getErrorString (hawk_hawk_errnum_t num) const
/// {
/// if (num == HAWK_ENOENT) return HAWK_T("cannot find '${0}'");
/// return Hawk::getErrorString (num);
@ -452,7 +439,7 @@ protected:
/// \endcode
///
virtual const hawk_ooch_t* getErrorString (
errnum_t num
hawk_errnum_t num
) const;
public:
@ -460,13 +447,13 @@ public:
/// The getErrorNumber() function returns the number of the last
/// error occurred.
///
errnum_t getErrorNumber () const;
hawk_errnum_t getErrorNumber () const;
///
/// The getErrorLocation() function returns the location of the
/// last error occurred.
///
loc_t getErrorLocation () const;
hawk_loc_t getErrorLocation () const;
///
/// The Hawk::getErrorMessage() function returns a message describing
@ -474,24 +461,23 @@ public:
///
const hawk_ooch_t* getErrorMessage () const;
///
/// The setError() function sets error information.
///
void setError (
errnum_t code, ///< error code
const hawk_oocs_t* args = HAWK_NULL, ///< message formatting
/// argument array
const loc_t* loc = HAWK_NULL ///< error location
hawk_errnum_t code, ///< error code
const hawk_loc_t* loc = HAWK_NULL ///< error location
);
///
/// The setErrorWithMessage() functions sets error information
/// with a customized error message.
///
void setErrorWithMessage (
errnum_t code, ///< error code
const hawk_ooch_t* msg, ///< error message
const loc_t* loc ///< error location
void formatError (
hawk_errnum_t code,
const hawk_loc_t* loc,
const hawk_bch_t* fmt,
...
);
void formatError (
hawk_errnum_t code,
const hawk_loc_t* loc,
const hawk_uch_t* fmt,
...
);
///
@ -588,7 +574,7 @@ public:
return this->awk;
}
operator awk_t* () const
operator hawk_t* () const
{
return this->awk->getHandle();
}
@ -636,7 +622,7 @@ public:
class HAWK_EXPORT RIOBase
{
protected:
RIOBase (Run* run, rio_arg_t* riod);
RIOBase (Run* run, hawk_rio_arg_t* riod);
public:
const hawk_ooch_t* getName() const;
@ -648,14 +634,14 @@ public:
void setUflags (int uflags);
operator Hawk* () const;
operator awk_t* () const;
operator rio_arg_t* () const;
operator hawk_t* () const;
operator hawk_rio_arg_t* () const;
operator Run* () const;
operator rtx_t* () const;
operator hawk_rtx_t* () const;
protected:
Run* run;
rio_arg_t* riod;
hawk_rio_arg_t* riod;
private:
RIOBase (const RIOBase&);
@ -708,7 +694,7 @@ public:
};
protected:
Pipe (Run* run, rio_arg_t* riod);
Pipe (Run* run, hawk_rio_arg_t* riod);
public:
/// The getMode() function returns the opening mode requested.
@ -753,7 +739,7 @@ public:
};
protected:
File (Run* run, rio_arg_t* riod);
File (Run* run, hawk_rio_arg_t* riod);
public:
Mode getMode () const;
@ -826,7 +812,7 @@ public:
};
protected:
Console (Run* run, rio_arg_t* riod);
Console (Run* run, hawk_rio_arg_t* riod);
~Console ();
public:
@ -1010,7 +996,7 @@ public:
void clear ();
operator val_t* () const { return val; }
operator hawk_val_t* () const { return val; }
operator int_t () const;
operator flt_t () const;
operator const hawk_ooch_t* () const;
@ -1018,9 +1004,9 @@ public:
operator const hawk_bch_t* () const;
#endif
val_t* toVal () const
hawk_val_t* toVal () const
{
return operator val_t* ();
return operator hawk_val_t* ();
}
int_t toInt () const
@ -1069,8 +1055,8 @@ public:
int getStr (const hawk_ooch_t** str, hawk_oow_t* len) const;
int getMbs (const hawk_bch_t** str, hawk_oow_t* len) const;
int setVal (val_t* v);
int setVal (Run* r, val_t* v);
int setVal (hawk_val_t* v);
int setVal (Run* r, hawk_val_t* v);
int setInt (int_t v);
int setInt (Run* r, int_t v);
@ -1087,8 +1073,8 @@ public:
int setMbs (const hawk_bch_t* str);
int setMbs (Run* r, const hawk_bch_t* str);
int setIndexedVal (const Index& idx, val_t* v);
int setIndexedVal (Run* r, const Index& idx, val_t* v);
int setIndexedVal (const Index& idx, hawk_val_t* v);
int setIndexedVal (Run* r, const Index& idx, hawk_val_t* v);
int setIndexedInt (const Index& idx, int_t v);
int setIndexedInt (Run* r, const Index& idx, int_t v);
int setIndexedFlt (const Index& idx, flt_t v);
@ -1144,7 +1130,7 @@ public:
protected:
Run* run;
val_t* val;
hawk_val_t* val;
mutable struct
{
@ -1171,30 +1157,52 @@ public:
friend class Console;
Run (Hawk* awk);
Run (Hawk* awk, rtx_t* run);
Run (Hawk* awk, hawk_rtx_t* run);
~Run ();
public:
operator Hawk* () const;
operator rtx_t* () const;
operator Hawk* () const
{
return this->awk;
}
operator hawk_rtx_t* () const
{
return this->rtx;
}
operator hawk_gem_t* () const
{
return this->rtx? hawk_rtx_getgem(this->rtx): HAWK_NULL;
}
void halt () const;
bool isHalt () const;
errnum_t getErrorNumber () const;
loc_t getErrorLocation () const;
hawk_errnum_t getErrorNumber () const;
hawk_loc_t getErrorLocation () const;
const hawk_ooch_t* getErrorMessage () const;
///
/// The setError() function sets error information.
///
void setError (
errnum_t code,
const hawk_oocs_t* args = HAWK_NULL,
const loc_t* loc = HAWK_NULL
hawk_errnum_t code, ///< error code
const hawk_loc_t* loc = HAWK_NULL ///< error location
);
void setErrorWithMessage (
errnum_t code,
const hawk_ooch_t* msg,
const loc_t* loc
void formatError (
hawk_errnum_t code,
const hawk_loc_t* loc,
const hawk_bch_t* fmt,
...
);
void formatError (
hawk_errnum_t code,
const hawk_loc_t* loc,
const hawk_uch_t* fmt,
...
);
///
@ -1237,14 +1245,22 @@ public:
int getGlobal (int id, Value& v) const;
protected:
Hawk* awk;
rtx_t* rtx;
Hawk* awk;
hawk_rtx_t* rtx;
};
///
/// Returns the primitive handle
///
operator awk_t* () const;
operator hawk_t* () const
{
return this->awk;
}
operator hawk_gem_t* () const
{
return this->awk? hawk_getgem(this->awk): HAWK_NULL;
}
///
/// \name Basic Functions
@ -1499,7 +1515,7 @@ public:
Run& run,
Value& ret,
Value* args,
hawk_oow_t nargs,
hawk_oow_t nargs,
const fnc_info_t* fi
);
@ -1662,38 +1678,38 @@ protected:
// static glue members for various handlers
static hawk_ooi_t readSource (
awk_t* awk, sio_cmd_t cmd, sio_arg_t* arg,
hawk_t* awk, sio_cmd_t cmd, sio_arg_t* arg,
hawk_ooch_t* data, hawk_oow_t count);
static hawk_ooi_t writeSource (
awk_t* awk, sio_cmd_t cmd, sio_arg_t* arg,
hawk_t* awk, sio_cmd_t cmd, sio_arg_t* arg,
hawk_ooch_t* data, hawk_oow_t count);
static hawk_ooi_t pipeHandler (
rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod,
hawk_rtx_t* rtx, rio_cmd_t cmd, hawk_rio_arg_t* riod,
void* data, hawk_oow_t count);
static hawk_ooi_t fileHandler (
rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod,
hawk_rtx_t* rtx, rio_cmd_t cmd, hawk_rio_arg_t* riod,
void* data, hawk_oow_t count);
static hawk_ooi_t consoleHandler (
rtx_t* rtx, rio_cmd_t cmd, rio_arg_t* riod,
hawk_rtx_t* rtx, rio_cmd_t cmd, hawk_rio_arg_t* riod,
void* data, hawk_oow_t count);
static int functionHandler (rtx_t* rtx, const fnc_info_t* fi);
static int functionHandler (hawk_rtx_t* rtx, const fnc_info_t* fi);
static flt_t pow (awk_t* awk, flt_t x, flt_t y);
static flt_t mod (awk_t* awk, flt_t x, flt_t y);
static flt_t pow (hawk_t* awk, flt_t x, flt_t y);
static flt_t mod (hawk_t* awk, flt_t x, flt_t y);
static void* modopen (awk_t* awk, const mod_spec_t* spec);
static void modclose (awk_t* awk, void* handle);
static void* modgetsym (awk_t* awk, void* handle, const hawk_ooch_t* name);
static void* modopen (hawk_t* awk, const mod_spec_t* spec);
static void modclose (hawk_t* awk, void* handle);
static void* modgetsym (hawk_t* awk, void* handle, const hawk_ooch_t* name);
public:
// use this with care
awk_t* getHandle() const { return this->awk; }
hawk_t* getHandle() const { return this->awk; }
protected:
awk_t* awk;
hawk_t* awk;
errstr_t dflerrstr;
errinf_t errinf;
@ -1725,12 +1741,12 @@ protected:
{
xstrs_t (): ptr (HAWK_NULL), len (0), capa (0) {}
int add (awk_t* awk, const hawk_ooch_t* arg, hawk_oow_t len);
void clear (awk_t* awk);
int add (hawk_t* awk, const hawk_ooch_t* arg, hawk_oow_t len);
void clear (hawk_t* awk);
hawk_oocs_t* ptr;
hawk_oow_t len;
hawk_oow_t capa;
hawk_oow_t len;
hawk_oow_t capa;
};
xstrs_t runarg;
@ -1742,7 +1758,7 @@ private:
void fini_runctx ();
int dispatch_function (Run* run, const fnc_info_t* fi);
static const hawk_ooch_t* xerrstr (awk_t* a, errnum_t num);
static const hawk_ooch_t* xerrstr (hawk_t* a, hawk_errnum_t num);
};
/////////////////////////////////

View File

@ -25,6 +25,8 @@
*/
#include <HawkStd.hpp>
#include <hawk-sio.h>
#include <hawk-std.h>
#include "hawk-prv.h"
#include <stdlib.h>
@ -78,14 +80,19 @@ static hawk_sio_t* open_sio (Hawk* awk, HawkStd::Run* run, const hawk_ooch_t* fi
hawk_sio_t* sio;
//sio = hawk_sio_open ((run? ((Hawk::awk_t*)*(Hawk*)*run)->mmgr: awk->getMmgr()), 0, file, flags);
sio = hawk_sio_open ((run? ((Hawk*)*run)->getMmgr(): awk->getMmgr()), 0, file, flags);
sio = hawk_sio_open((run? (hawk_gem_t*)*run: (hawk_gem_t*)*awk), 0, file, flags);
if (sio == HAWK_NULL)
{
hawk_oocs_t ea;
ea.ptr = (hawk_ooch_t*)file;
ea.len = hawk_count_oocstr (file);
if (run) run->setError (HAWK_EOPEN, &ea);
else awk->setError (HAWK_EOPEN, &ea);
if (run)
{
const hawk_ooch_t* bem = hawk_rtx_backuperrmsg(*run);
run->formatError (HAWK_EOPEN, HAWK_NULL, HAWK_T("unable to open %js - %js"), file, bem);
}
else
{
const hawk_ooch_t* bem = hawk_backuperrmsg(*awk);
awk->formatError (HAWK_EOPEN, HAWK_NULL, HAWK_T("unable to open %js - %js"), file, bem);
}
}
return sio;
}
@ -101,14 +108,19 @@ static hawk_sio_t* open_sio_std (Hawk* awk, HawkStd::Run* run, hawk_sio_std_t st
};
//sio = hawk_sio_openstd ((run? ((Hawk::awk_t*)*(Hawk*)*run)->mmgr: awk->getMmgr()), 0, std, flags);
sio = hawk_sio_openstd ((run? ((Hawk*)*run)->getMmgr(): awk->getMmgr()), 0, std, flags);
sio = hawk_sio_openstd((run? (hawk_gem_t*)*run: (hawk_gem_t*)*awk), 0, std, flags);
if (sio == HAWK_NULL)
{
hawk_oocs_t ea;
ea.ptr = (hawk_ooch_t*)std_names[std];
ea.len = hawk_count_oocstr (std_names[std]);
if (run) run->setError (HAWK_EOPEN, &ea);
else awk->setError (HAWK_EOPEN, &ea);
if (run)
{
const hawk_ooch_t* bem = hawk_rtx_backuperrmsg(*run);
run->formatError (HAWK_EOPEN, HAWK_NULL, HAWK_T("unable to open %js - %js"), std_names[std], bem);
}
else
{
const hawk_ooch_t* bem = hawk_backuperrmsg(*awk);
awk->formatError (HAWK_EOPEN, HAWK_NULL, HAWK_T("unable to open %js - %js"), std_names[std], bem);
}
}
return sio;
}
@ -118,15 +130,10 @@ int HawkStd::open ()
int n = Hawk::open ();
if (n == -1) return n;
this->gbl_argc = addGlobal (HAWK_T("ARGC"));
this->gbl_argv = addGlobal (HAWK_T("ARGV"));
this->gbl_environ = addGlobal (HAWK_T("ENVIRON"));
if (this->gbl_argc <= -1 ||
this->gbl_argv <= -1 ||
this->gbl_environ <= -1)
{
goto oops;
}
this->gbl_argc = this->addGlobal(HAWK_T("ARGC"));
this->gbl_argv = this->addGlobal(HAWK_T("ARGV"));
this->gbl_environ = this->addGlobal(HAWK_T("ENVIRON"));
if (this->gbl_argc <= -1 || this->gbl_argv <= -1 || this->gbl_environ <= -1) goto oops;
if (addFunction (HAWK_T("rand"), 1, 0, HAWK_T("math"), HAWK_NULL, 0) <= -1 ||
addFunction (HAWK_T("srand"), 1, 0, HAWK_T("math"), HAWK_NULL, 0) <= -1 ||
@ -143,7 +150,7 @@ int HawkStd::open ()
if (hawk_setopt(awk, HAWK_MODPOSTFIX, HAWK_T(".so")) <= -1) goto oops;
#endif
if (hawk_stdmodstartup (this->awk) <= -1) goto oops;
if (hawk_stdmodstartup(this->awk) <= -1) goto oops;
this->stdmod_up = true;
}
@ -245,14 +252,20 @@ int HawkStd::build_argcv (Run* run)
return 0;
}
/* TODO: use wenviron where it's available */
typedef hawk_bch_t env_char_t;
#define ENV_CHAR_IS_BCH
extern char **environ;
int HawkStd::__build_environ (Run* run, void* envptr)
{
hawk_env_hawk_ooch_t** envarr = (hawk_env_hawk_ooch_t**)envptr;
en_char_t** envarr = (env_char_t**)envptr;
Value v_env (run);
if (envarr)
{
hawk_env_hawk_ooch_t* eq;
env_char_t* eq;
hawk_ooch_t* kptr, * vptr;
hawk_oow_t klen, count;
hawk_mmgr_t* mmgr = ((Hawk*)*run)->getMmgr();
@ -333,7 +346,7 @@ int HawkStd::build_environ (Run* run)
hawk_env_t env;
int xret;
if (hawk_env_init (&env, ((Hawk*)*run)->getMmgr(), 1) <= -1)
if (hawk_env_init(&env, ((Hawk*)*run)->getMmgr(), 1) <= -1)
{
this->setError (HAWK_ENOMEM);
return -1;
@ -347,8 +360,8 @@ int HawkStd::build_environ (Run* run)
int HawkStd::make_additional_globals (Run* run)
{
if (build_argcv (run) <= -1 ||
build_environ (run) <= -1) return -1;
if (build_argcv(run) <= -1 ||
build_environ(run) <= -1) return -1;
return 0;
}
@ -526,7 +539,7 @@ int HawkStd::open_nwio (Pipe& io, int flags, void* nwad)
hawk_nwio_tmout_t* tmout = HAWK_NULL;
const hawk_ooch_t* name = io.getName();
ioattr_t* ioattr = get_ioattr (name, hawk_count_oocstr(name));
ioattr_t* ioattr = get_ioattr(name, hawk_count_oocstr(name));
if (ioattr)
{
tmout = &tmout_buf;
@ -634,22 +647,27 @@ static int parse_rwpipe_uri (const hawk_ooch_t* uri, int* flags, hawk_nwad_t* nw
int HawkStd::openPipe (Pipe& io)
{
#if defined(ENABLE_NWIO)
int flags;
hawk_nwad_t nwad;
if (io.getMode() != Hawk::Pipe::RW ||
parse_rwpipe_uri (io.getName(), &flags, &nwad) <= -1)
{
return open_pio (io);
return open_pio(io);
}
else
{
return open_nwio (io, flags, &nwad);
}
#else
return this->open_pio(io);
#endif
}
int HawkStd::closePipe (Pipe& io)
{
#if defined(ENABLE_NWIO)
if (io.getUflags() > 0)
{
/* nwio can't honor partical close */
@ -657,6 +675,7 @@ int HawkStd::closePipe (Pipe& io)
}
else
{
#endif
hawk_pio_t* pio = (hawk_pio_t*)io.getHandle();
if (io.getMode() == Hawk::Pipe::RW)
{
@ -674,7 +693,9 @@ int HawkStd::closePipe (Pipe& io)
}
hawk_pio_close (pio);
#if defined(ENABLE_NWIO)
}
#endif
return 0;
}
@ -796,7 +817,7 @@ void HawkStd::clearConsoleOutputs ()
int HawkStd::open_console_in (Console& io)
{
hawk_rtx_t* rtx = (rtx_t*)io;
hawk_rtx_t* rtx = (hawk_rtx_t*)io;
if (this->runarg.ptr == HAWK_NULL)
{
@ -806,7 +827,7 @@ int HawkStd::open_console_in (Console& io)
{
hawk_sio_t* sio;
sio = open_sio_std (
sio = this->open_sio_std (
HAWK_NULL, io, HAWK_SIO_STDIN,
HAWK_SIO_READ | HAWK_SIO_IGNOREECERR);
if (sio == HAWK_NULL) return -1;
@ -849,7 +870,7 @@ int HawkStd::open_console_in (Console& io)
* 'BEGIN { ARGV[1]=""; ARGV[2]=""; }
* { print $0; }' file1 file2
*/
sio = open_sio_std (
sio = this->open_sio_std(
HAWK_NULL, io, HAWK_SIO_STDIN,
HAWK_SIO_READ | HAWK_SIO_IGNOREECERR);
if (sio == HAWK_NULL) return -1;
@ -923,9 +944,9 @@ int HawkStd::open_console_in (Console& io)
file = as.ptr;
if (file[0] == HAWK_T('-') && file[1] == HAWK_T('\0'))
sio = open_sio_std(HAWK_NULL, io, HAWK_SIO_STDIN, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR);
sio = this->open_sio_std(HAWK_NULL, io, HAWK_SIO_STDIN, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR);
else
sio = open_sio(HAWK_NULL, io, file, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR);
sio = this->open_sio(HAWK_NULL, io, file, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR);
if (sio == HAWK_NULL)
{
hawk_rtx_freevaloocstr (rtx, v, as.ptr);
@ -955,7 +976,7 @@ int HawkStd::open_console_in (Console& io)
int HawkStd::open_console_out (Console& io)
{
hawk_rtx_t* rtx = (rtx_t*)io;
hawk_rtx_t* rtx = (hawk_rtx_t*)io;
if (this->ofile.ptr == HAWK_NULL)
{
@ -964,13 +985,12 @@ int HawkStd::open_console_out (Console& io)
if (this->ofile_count == 0)
{
hawk_sio_t* sio;
sio = open_sio_std (
sio = this->open_sio_std(
HAWK_NULL, io, HAWK_SIO_STDOUT,
HAWK_SIO_WRITE | HAWK_SIO_IGNOREECERR | HAWK_SIO_LINEBREAK);
if (sio == HAWK_NULL) return -1;
if (this->console_cmgr)
hawk_sio_setcmgr (sio, this->console_cmgr);
if (this->console_cmgr) hawk_sio_setcmgr (sio, this->console_cmgr);
io.setHandle (sio);
this->ofile_count++;
@ -998,26 +1018,24 @@ int HawkStd::open_console_out (Console& io)
{
hawk_oocs_t arg;
arg.ptr = (hawk_ooch_t*)file;
arg.len = hawk_count_oocstr (arg.ptr);
arg.len = hawk_count_oocstr(arg.ptr);
((Run*)io)->setError (HAWK_EIONMNL, &arg);
return -1;
}
if (file[0] == HAWK_T('-') && file[1] == HAWK_T('\0'))
sio = open_sio_std (HAWK_NULL, io, HAWK_SIO_STDOUT, HAWK_SIO_WRITE | HAWK_SIO_IGNOREECERR | HAWK_SIO_LINEBREAK);
sio = this->open_sio_std(HAWK_NULL, io, HAWK_SIO_STDOUT, HAWK_SIO_WRITE | HAWK_SIO_IGNOREECERR | HAWK_SIO_LINEBREAK);
else
sio = open_sio (HAWK_NULL, io, file, HAWK_SIO_WRITE | HAWK_SIO_CREATE | HAWK_SIO_TRUNCATE | HAWK_SIO_IGNOREECERR);
sio = this->open_sio(HAWK_NULL, io, file, HAWK_SIO_WRITE | HAWK_SIO_CREATE | HAWK_SIO_TRUNCATE | HAWK_SIO_IGNOREECERR);
if (sio == HAWK_NULL) return -1;
if (hawk_rtx_setofilename (
rtx, file, hawk_count_oocstr(file)) == -1)
if (hawk_rtx_setofilename(rtx, file, hawk_count_oocstr(file)) == -1)
{
hawk_sio_close (sio);
return -1;
}
if (this->console_cmgr)
hawk_sio_setcmgr (sio, this->console_cmgr);
if (this->console_cmgr) hawk_sio_setcmgr (sio, this->console_cmgr);
io.setHandle (sio);
this->ofile_index++;
@ -1175,11 +1193,11 @@ int HawkStd::SourceFile::open (Data& io)
if (this->name[0] == HAWK_T('-') && this->name[1] == HAWK_T('\0'))
{
if (io.getMode() == READ)
sio = open_sio_std (
sio = this->open_sio_std (
io, HAWK_NULL, HAWK_SIO_STDIN,
HAWK_SIO_READ | HAWK_SIO_IGNOREECERR);
else
sio = open_sio_std (
sio = this->open_sio_std (
io, HAWK_NULL, HAWK_SIO_STDOUT,
HAWK_SIO_WRITE | HAWK_SIO_CREATE |
HAWK_SIO_TRUNCATE | HAWK_SIO_IGNOREECERR | HAWK_SIO_LINEBREAK);
@ -1187,7 +1205,7 @@ int HawkStd::SourceFile::open (Data& io)
}
else
{
sio = open_sio (
sio = this->open_sio (
io, HAWK_NULL, this->name,
(io.getMode() == READ?
(HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH):
@ -1228,7 +1246,7 @@ int HawkStd::SourceFile::open (Data& io)
totlen = hawk_count_oocstr(ioname) + dirlen;
if (totlen >= HAWK_COUNTOF(fbuf))
{
dbuf = (hawk_ooch_t*) HAWK_MMGR_ALLOC (
dbuf = (hawk_ooch_t*)HAWK_MMGR_ALLOC(
((Hawk*)io)->getMmgr(),
HAWK_SIZEOF(hawk_ooch_t) * (totlen + 1)
);
@ -1248,7 +1266,7 @@ int HawkStd::SourceFile::open (Data& io)
}
}
sio = open_sio (
sio = this->open_sio(
io, HAWK_NULL, file,
(io.getMode() == READ?
(HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH):
@ -1308,7 +1326,7 @@ int HawkStd::SourceString::open (Data& io)
{
const hawk_ooch_t* outer;
outer = hawk_sio_getpath ((hawk_sio_t*)io.getPrevHandle());
outer = hawk_sio_getpath((hawk_sio_t*)io.getPrevHandle());
if (outer)
{
const hawk_ooch_t* base;
@ -1336,13 +1354,13 @@ int HawkStd::SourceString::open (Data& io)
}
else file = fbuf;
tmplen = hawk_copy_oochars_to_oocstr_unlimited ((hawk_ooch_t*)file, outer, dirlen);
tmplen = hawk_copy_oochars_to_oocstr_unlimited((hawk_ooch_t*)file, outer, dirlen);
hawk_copy_oocstr_unlimited ((hawk_ooch_t*)file + tmplen, ioname);
}
}
}
sio = open_sio (
sio = this->open_sio (
io, HAWK_NULL, file,
(io.getMode() == READ?
(HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH):

View File

@ -220,6 +220,46 @@ HAWK_EXPORT hawk_cmgr_t* hawk_rtx_getiocmgrstd (
const hawk_ooch_t* ioname
);
/* ------------------------------------------------------------------------- */
HAWK_EXPORT hawk_flt_t hawk_stdmathpow (
hawk_t* hawk,
hawk_flt_t x,
hawk_flt_t y
);
HAWK_EXPORT hawk_flt_t hawk_stdmathmod (
hawk_t* hawk,
hawk_flt_t x,
hawk_flt_t y
);
HAWK_EXPORT int hawk_stdmodstartup (
hawk_t* hawk
);
HAWK_EXPORT void hawk_stdmodshutdown (
hawk_t* hawk
);
HAWK_EXPORT void* hawk_stdmodopen (
hawk_t* hawk,
const hawk_mod_spec_t* spec
);
HAWK_EXPORT void hawk_stdmodclose (
hawk_t* hawk,
void* handle
);
HAWK_EXPORT void* hawk_stdmodsym (
hawk_t* hawk,
void* handle,
const hawk_ooch_t* name
);
#if defined(__cplusplus)
}
#endif