added some code for the byte-character literal support.
enhanced value comparison routines
This commit is contained in:
parent
2e25911bfd
commit
e983d7701a
@ -2017,7 +2017,6 @@ val_map:
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
||||
val_arr:
|
||||
{
|
||||
hawk_arr_t* arr;
|
||||
@ -2033,8 +2032,8 @@ val_arr:
|
||||
|
||||
ssz = HAWK_ARR_SIZE(arr);
|
||||
HAWK_ASSERT (msz <= ssz);
|
||||
HAWK_ASSERT (msz <= HAWK_QUICKINT_MAX);
|
||||
HAWK_ASSERT (ssz <= HAWK_QUICKINT_MAX);
|
||||
HAWK_ASSERT (msz <= HAWK_QINT_MAX);
|
||||
HAWK_ASSERT (ssz <= HAWK_QINT_MAX);
|
||||
|
||||
va = (hawk_val_t**)hawk_rtx_allocmem(rtx, msz * HAWK_SIZEOF(*va));
|
||||
if (HAWK_UNLIKELY(!va)) return -1;
|
||||
|
@ -413,6 +413,7 @@ enum hawk_nde_type_t
|
||||
HAWK_NDE_FNCALL_FUN,
|
||||
HAWK_NDE_FNCALL_VAR,
|
||||
HAWK_NDE_CHAR,
|
||||
HAWK_NDE_BCHR,
|
||||
HAWK_NDE_INT,
|
||||
HAWK_NDE_FLT,
|
||||
HAWK_NDE_STR,
|
||||
@ -1381,21 +1382,23 @@ typedef enum hawk_gbl_id_t hawk_gbl_id_t;
|
||||
*/
|
||||
enum hawk_val_type_t
|
||||
{
|
||||
/* the values between HAWK_VAL_NIL and HAWK_VAL_FUN inclusive
|
||||
/* - the enumerators between HAWK_VAL_NIL and HAWK_VAL_ARR inclusive
|
||||
* must be synchronized with an internal table of the __cmp_val
|
||||
* function in run.c and the __val_type_name in val.c */
|
||||
* function in run.c.
|
||||
* - all enumerators must be in sync with __val_type_name in val.c */
|
||||
HAWK_VAL_NIL = 0, /**< nil */
|
||||
HAWK_VAL_CHAR = 1, /**< character */
|
||||
HAWK_VAL_INT = 2, /**< integer */
|
||||
HAWK_VAL_FLT = 3, /**< floating-pointer number */
|
||||
HAWK_VAL_STR = 4, /**< string */
|
||||
HAWK_VAL_MBS = 5, /**< byte array */
|
||||
HAWK_VAL_FUN = 6, /**< function pointer */
|
||||
HAWK_VAL_MAP = 7, /**< map */
|
||||
HAWK_VAL_ARR = 8, /**< array */
|
||||
HAWK_VAL_BCHR = 2, /**< byte character */
|
||||
HAWK_VAL_INT = 3, /**< integer */
|
||||
HAWK_VAL_FLT = 4, /**< floating-pointer number */
|
||||
HAWK_VAL_STR = 5, /**< string */
|
||||
HAWK_VAL_MBS = 6, /**< byte array */
|
||||
HAWK_VAL_FUN = 7, /**< function pointer */
|
||||
HAWK_VAL_MAP = 8, /**< map */
|
||||
HAWK_VAL_ARR = 9, /**< array */
|
||||
|
||||
HAWK_VAL_REX = 9, /**< regular expression */
|
||||
HAWK_VAL_REF = 10 /**< reference to other types */
|
||||
HAWK_VAL_REX = 10, /**< regular expression */
|
||||
HAWK_VAL_REF = 11 /**< reference to other types */
|
||||
};
|
||||
typedef enum hawk_val_type_t hawk_val_type_t;
|
||||
|
||||
@ -2671,6 +2674,11 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_makecharval (
|
||||
hawk_ooch_t v
|
||||
);
|
||||
|
||||
HAWK_EXPORT hawk_val_t* hawk_rtx_makebchrval (
|
||||
hawk_rtx_t* rtx,
|
||||
hawk_bch_t v
|
||||
);
|
||||
|
||||
/**
|
||||
* The hawk_rtx_makeintval() function creates an integer value.
|
||||
* If \a v is one of -1, 0, 1, this function never fails.
|
||||
|
@ -166,7 +166,7 @@ static int fnc_gc (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
gen = hawk_rtx_gc(rtx, gen);
|
||||
#endif
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(gen));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(gen));
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, gen));
|
||||
return 0;
|
||||
}
|
||||
@ -182,7 +182,7 @@ static int fnc_gc_get_threshold (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
|
||||
threshold = rtx->gc.threshold[gen];
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(threshold));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(threshold));
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, threshold));
|
||||
return 0;
|
||||
}
|
||||
@ -200,7 +200,7 @@ static int fnc_gc_set_threshold (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
|
||||
if (threshold >= 0)
|
||||
{
|
||||
if (threshold >= HAWK_QUICKINT_MAX) threshold = HAWK_QUICKINT_MAX;
|
||||
if (threshold >= HAWK_QINT_MAX) threshold = HAWK_QINT_MAX;
|
||||
rtx->gc.threshold[gen] = threshold; /* update */
|
||||
}
|
||||
else
|
||||
@ -208,7 +208,7 @@ static int fnc_gc_set_threshold (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
threshold = rtx->gc.threshold[gen]; /* no update. but retrieve the existing value */
|
||||
}
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(threshold));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(threshold));
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, threshold));
|
||||
return 0;
|
||||
}
|
||||
@ -364,7 +364,202 @@ static int fnc_typename (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
hawk_rtx_setretval (rtx, r);
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#include "mod-bin.c"
|
||||
|
||||
#if 0
|
||||
static int pack_data (hawk_rtx_t* rtx, const hawk_oocs_t* fmt, const hawk_fnc_info_t* fi)
|
||||
{
|
||||
hawk_oow_t rep_cnt = 0;
|
||||
|
||||
const hawk_ooch_t* fmtp, *fmte;
|
||||
hawk_uint8_t *bp;
|
||||
int endian = ENDIAN_NATIVE;
|
||||
char* s;
|
||||
|
||||
bp = buf;
|
||||
|
||||
fmte = fmt->ptr + fmt->len;
|
||||
for (fmtp = fmt,ptr; fmtp < fmte; fmtp++)
|
||||
{
|
||||
switch (*fmtp)
|
||||
{
|
||||
case '=': /* native */
|
||||
endian = ENDIAN_NATIVE;
|
||||
break;
|
||||
|
||||
case '<': /* little-endian */
|
||||
endian = ENDIAN_LITTLE;
|
||||
break;
|
||||
|
||||
case '>': /* big-endian */
|
||||
endian = ENDIAN_BIG;
|
||||
break;
|
||||
|
||||
case '!': /* network (= big-endian) */
|
||||
endian = ENDIAN_BIG;
|
||||
break;
|
||||
|
||||
case 'b': /* byte, char */
|
||||
{
|
||||
signed char v;
|
||||
BEGIN_REPETITION();
|
||||
v = va_arg(args, int);
|
||||
*bp++ = v;
|
||||
END_REPETITION();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'B':
|
||||
{
|
||||
unsigned char v;
|
||||
BEGIN_REPETITION();
|
||||
v = va_arg(args, unsigned int);
|
||||
*bp++ = v;
|
||||
END_REPETITION();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'h':
|
||||
{
|
||||
short int v;
|
||||
BEGIN_REPETITION();
|
||||
v = va_arg(args, int);
|
||||
bp = pack_int16_t(bp, v, endian);
|
||||
END_REPETITION();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'H':
|
||||
{
|
||||
unsigned short int v;
|
||||
BEGIN_REPETITION();
|
||||
v = va_arg(args, int);
|
||||
bp = pack_int16_t(bp, v, endian);
|
||||
END_REPETITION();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'i':
|
||||
case 'l':
|
||||
{
|
||||
hawk_int32_t v;
|
||||
BEGIN_REPETITION();
|
||||
v = va_arg(args, hawk_int32_t);
|
||||
bp = pack_int32_t(bp, v, endian);
|
||||
END_REPETITION();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'I': /* fall through */
|
||||
case 'L':
|
||||
{
|
||||
hawk_uint32_t v;
|
||||
BEGIN_REPETITION();
|
||||
v = va_arg(args, hawk_uint32_t);
|
||||
bp = pack_int32_t(bp, v, endian);
|
||||
END_REPETITION();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'q':
|
||||
{
|
||||
hawk_int64_t v;
|
||||
BEGIN_REPETITION();
|
||||
v = va_arg(args, hawk_int64_t);
|
||||
bp = pack_int64_t(bp, v, endian);
|
||||
END_REPETITION();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'Q':
|
||||
{
|
||||
hawk_uint64_t v;
|
||||
BEGIN_REPETITION();
|
||||
v = va_arg(args, hawk_uint64_t);
|
||||
bp = pack_int64_t(bp, v, endian);
|
||||
END_REPETITION();
|
||||
break;
|
||||
}
|
||||
|
||||
#if 0
|
||||
case 'f':
|
||||
BEGIN_REPETITION();
|
||||
f = va_arg(args, double);
|
||||
pack_float(&bp, f, *ep);
|
||||
END_REPETITION();
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
BEGIN_REPETITION();
|
||||
d = va_arg(args, double);
|
||||
pack_double(&bp, d, *ep);
|
||||
END_REPETITION();
|
||||
break;
|
||||
#endif
|
||||
|
||||
case 's':
|
||||
case 'p':
|
||||
{
|
||||
int i = 0;
|
||||
s = va_arg(args, char*);
|
||||
BEGIN_REPETITION();
|
||||
*bp++ = s[i++];
|
||||
END_REPETITION();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'x':
|
||||
BEGIN_REPETITION();
|
||||
*bp++ = 0;
|
||||
END_REPETITION();
|
||||
break;
|
||||
|
||||
default:
|
||||
if (hawk_is_bch_digit(*fmtp))
|
||||
{
|
||||
INC_REPETITION();
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!hawk_is_bch_digit((int)*fmtp)) CLEAR_REPETITION();
|
||||
}
|
||||
|
||||
return (bp - buf);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static int fnc_pack (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
{
|
||||
hawk_val_t* a0, * r;
|
||||
hawk_oocs_t fmt;
|
||||
|
||||
a0 = hawk_rtx_getarg(rtx, 0);
|
||||
fmt.ptr = hawk_rtx_getvaloocstr(rtx, a0, &fmt.len);
|
||||
if (HAWK_UNLIKELY(!fmt.ptr)) return -1;
|
||||
|
||||
#if 0
|
||||
pack_data (rtx, &fmt, &buf, fi);
|
||||
|
||||
r = hawk_rtx_makembsvalwithbchars(rtx, buf.ptr, buf.len);
|
||||
if (HAWK_UNLIKELY(!r)) return -1;
|
||||
|
||||
hawk_rtx_setretval (rtx, r);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fnc_unpack (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
{
|
||||
/* TODO: */
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
typedef struct fnctab_t fnctab_t;
|
||||
@ -386,7 +581,7 @@ struct inttab_t
|
||||
static fnctab_t fnctab[] =
|
||||
{
|
||||
/* keep this table sorted for binary search in query(). */
|
||||
{ HAWK_T("array"), { { 0, A_MAX }, fnc_array, 0 } },
|
||||
{ HAWK_T("array"), { { 0, A_MAX, HAWK_NULL }, fnc_array, 0 } },
|
||||
{ HAWK_T("call"), { { 1, A_MAX, HAWK_T("vR") }, fnc_call, 0 } },
|
||||
{ HAWK_T("function_exists"), { { 1, 1, HAWK_NULL }, fnc_function_exists, 0 } },
|
||||
{ HAWK_T("gc"), { { 0, 1, HAWK_NULL }, fnc_gc, 0 } },
|
||||
@ -398,7 +593,9 @@ static fnctab_t fnctab[] =
|
||||
{ HAWK_T("isnil"), { { 1, 1, HAWK_NULL }, fnc_isnil, 0 } },
|
||||
{ HAWK_T("map"), { { 0, A_MAX, HAWK_NULL }, fnc_map, 0 } },
|
||||
{ HAWK_T("modlibdirs"), { { 0, 0, HAWK_NULL }, fnc_modlibdirs, 0 } },
|
||||
{ HAWK_T("typename"), { { 1, 1, HAWK_NULL }, fnc_typename, 0 } }
|
||||
{ HAWK_T("pack"), { { 1, A_MAX, HAWK_NULL }, fnc_pack, 0 } },
|
||||
{ HAWK_T("typename"), { { 1, 1, HAWK_NULL }, fnc_typename, 0 } },
|
||||
//{ HAWK_T("unpack"), { { 1, A_MAX, HAWK_NULL }, fnc_unpack, 0 } }
|
||||
};
|
||||
|
||||
static inttab_t inttab[] =
|
||||
|
@ -604,7 +604,7 @@ static int fnc_subchar (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
len = ((hawk_val_mbs_t*)a0)->val.len;
|
||||
|
||||
if (lindex >= 0 && lindex < (hawk_int_t)len)
|
||||
r = hawk_rtx_makecharval(rtx, str[lindex]);
|
||||
r = hawk_rtx_makebchrval(rtx, str[lindex]);
|
||||
else
|
||||
r = hawk_rtx_makenilval(rtx);
|
||||
|
||||
|
@ -635,7 +635,7 @@ static int fnc_open (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
rx = copy_error_to_sys_list(rtx, sys_list);
|
||||
}
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(rx));
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
}
|
||||
@ -678,7 +678,7 @@ static int fnc_openfd (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_T("invalid file descriptor %jd"), (hawk_intmax_t)fd);
|
||||
}
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(rx));
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
}
|
||||
@ -703,7 +703,7 @@ static int fnc_read (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
if (sys_node)
|
||||
{
|
||||
if (hawk_rtx_getnargs(rtx) >= 3 && (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 2), &reqsize) <= -1 || reqsize <= 0)) reqsize = 8192;
|
||||
if (reqsize > HAWK_QUICKINT_MAX) reqsize = HAWK_QUICKINT_MAX;
|
||||
if (reqsize > HAWK_QINT_MAX) reqsize = HAWK_QINT_MAX;
|
||||
|
||||
if (reqsize > sys_list->ctx.readbuf_capa)
|
||||
{
|
||||
@ -813,7 +813,7 @@ static int fnc_read (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
}
|
||||
|
||||
done:
|
||||
/* the value in 'rx' never exceeds HAWK_QUICKINT_MAX as 'reqsize' has been limited to
|
||||
/* the value in 'rx' never exceeds HAWK_QINT_MAX as 'reqsize' has been limited to
|
||||
* it before the call to 'read'. so it's safe not to check the result of hawk_rtx_makeintval() */
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
@ -982,7 +982,7 @@ static int fnc_dup (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
}
|
||||
|
||||
done:
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx)); /* assume a file descriptor never gets larger than HAWK_QUICKINT_MAX */
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(rx)); /* assume a file descriptor never gets larger than HAWK_QINT_MAX */
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
}
|
||||
@ -1759,7 +1759,7 @@ static int fnc_opendir (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
rx = copy_error_to_sys_list(rtx, sys_list);
|
||||
}
|
||||
|
||||
/*HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));*/
|
||||
/*HAWK_ASSERT (HAWK_IN_QINT_RANGE(rx));*/
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
}
|
||||
@ -2787,7 +2787,7 @@ done:
|
||||
if (val) hawk_rtx_freevalbcstr (rtx, a1, val);
|
||||
if (var) hawk_rtx_freevalbcstr (rtx, a0, var);
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(rx));
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
}
|
||||
@ -2824,7 +2824,7 @@ static int fnc_unsetenv (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
done:
|
||||
if (str) hawk_rtx_freevalbcstr (rtx, a0, str);
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(rx));
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
}
|
||||
@ -2989,7 +2989,7 @@ static int fnc_system (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
done:
|
||||
if (str) hawk_rtx_freevaloocstr (rtx, a0, str);
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(rx));
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
}
|
||||
@ -3038,7 +3038,7 @@ static int fnc_chroot (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
}
|
||||
#endif
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(rx));
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
}
|
||||
@ -3090,7 +3090,7 @@ static int fnc_chmod (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
}
|
||||
#endif
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(rx));
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
}
|
||||
@ -3170,7 +3170,7 @@ static int fnc_mkdir (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
}
|
||||
#endif
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(rx));
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
}
|
||||
@ -3246,7 +3246,7 @@ static int fnc_rmdir (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
}
|
||||
#endif
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(rx));
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
}
|
||||
@ -3324,7 +3324,7 @@ static int fnc_unlink (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
}
|
||||
#endif
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(rx));
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
}
|
||||
@ -3372,7 +3372,7 @@ static int fnc_symlink (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
}
|
||||
#endif
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(rx));
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
}
|
||||
@ -3541,7 +3541,7 @@ static int fnc_stat (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
}
|
||||
done:
|
||||
#endif
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(rx));
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
}
|
||||
@ -3606,7 +3606,7 @@ static int fnc_utime (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
}
|
||||
#endif
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(rx));
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
}
|
||||
@ -3662,7 +3662,7 @@ static int fnc_openmux (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL);
|
||||
#endif
|
||||
|
||||
/*HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));*/
|
||||
/*HAWK_ASSERT (HAWK_IN_QINT_RANGE(rx));*/
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
}
|
||||
@ -3923,11 +3923,11 @@ static int fnc_getmuxevt (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
goto done;
|
||||
}
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(file_node->id));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(file_node->id));
|
||||
x = hawk_rtx_setrefval(rtx, (hawk_val_ref_t*)hawk_rtx_getarg(rtx, 2), hawk_rtx_makeintval(rtx, file_node->id));
|
||||
if (x <= -1) goto fail;
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(mux_data->x_evt[index].events));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(mux_data->x_evt[index].events));
|
||||
x = hawk_rtx_setrefval(rtx, (hawk_val_ref_t*)hawk_rtx_getarg(rtx, 3), hawk_rtx_makeintval(rtx, mux_data->x_evt[index].events));
|
||||
if (x <= -1) goto fail;
|
||||
}
|
||||
@ -3974,7 +3974,7 @@ static int fnc_sockaddrdom (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
rx = copy_error_to_sys_list(rtx, sys_list);
|
||||
}
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(rx));
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
}
|
||||
@ -4015,7 +4015,7 @@ static int fnc_socket (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_NULL);
|
||||
}
|
||||
|
||||
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
|
||||
HAWK_ASSERT (HAWK_IN_QINT_RANGE(rx));
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
}
|
||||
@ -4083,7 +4083,7 @@ static int fnc_recvfrom (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
socklen_t addrlen;
|
||||
|
||||
if (hawk_rtx_getnargs(rtx) >= 3 && (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 2), &reqsize) <= -1 || reqsize <= 0)) reqsize = 8192;
|
||||
if (reqsize > HAWK_QUICKINT_MAX) reqsize = HAWK_QUICKINT_MAX;
|
||||
if (reqsize > HAWK_QINT_MAX) reqsize = HAWK_QINT_MAX;
|
||||
|
||||
if (reqsize > sys_list->ctx.readbuf_capa)
|
||||
{
|
||||
@ -4153,7 +4153,7 @@ static int fnc_recvfrom (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
}
|
||||
|
||||
done:
|
||||
/* the value in 'rx' never exceeds HAWK_QUICKINT_MAX as 'reqsize' has been limited to
|
||||
/* the value in 'rx' never exceeds HAWK_QINT_MAX as 'reqsize' has been limited to
|
||||
* it before the call to 'read'. so it's safe not to check the result of hawk_rtx_makeintval() */
|
||||
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
|
||||
return 0;
|
||||
|
@ -154,6 +154,7 @@ enum tok_t
|
||||
|
||||
TOK_IDENT,
|
||||
TOK_CHAR,
|
||||
TOK_BCHR,
|
||||
TOK_INT,
|
||||
TOK_FLT,
|
||||
TOK_STR,
|
||||
@ -4686,6 +4687,31 @@ oops:
|
||||
return HAWK_NULL;
|
||||
}
|
||||
|
||||
static hawk_nde_t* parse_primary_bchr (hawk_t* hawk, const hawk_loc_t* xloc)
|
||||
{
|
||||
hawk_nde_bchr_t* nde;
|
||||
|
||||
nde = (hawk_nde_bchr_t*)hawk_callocmem (hawk, HAWK_SIZEOF(*nde));
|
||||
if (HAWK_UNLIKELY(!nde))
|
||||
{
|
||||
ADJERR_LOC (hawk, xloc);
|
||||
return HAWK_NULL;
|
||||
}
|
||||
|
||||
nde->type = HAWK_NDE_BCHR;
|
||||
nde->loc = *xloc;
|
||||
nde->val = HAWK_OOECS_CHAR(hawk->tok.name, 0);
|
||||
|
||||
if (get_token(hawk) <= -1) goto oops;
|
||||
|
||||
return (hawk_nde_t*)nde;
|
||||
|
||||
oops:
|
||||
HAWK_ASSERT (nde != HAWK_NULL);
|
||||
hawk_freemem (hawk, nde);
|
||||
return HAWK_NULL;
|
||||
}
|
||||
|
||||
static hawk_nde_t* parse_primary_int (hawk_t* hawk, const hawk_loc_t* xloc)
|
||||
{
|
||||
hawk_nde_int_t* nde;
|
||||
@ -5122,6 +5148,9 @@ static hawk_nde_t* parse_primary_nopipe (hawk_t* hawk, const hawk_loc_t* xloc)
|
||||
case TOK_CHAR:
|
||||
return parse_primary_char(hawk, xloc);
|
||||
|
||||
case TOK_BCHR:
|
||||
return parse_primary_bchr(hawk, xloc);
|
||||
|
||||
case TOK_INT:
|
||||
return parse_primary_int(hawk, xloc);
|
||||
|
||||
@ -6741,17 +6770,21 @@ retry:
|
||||
}
|
||||
else if (c == '\"')
|
||||
{
|
||||
/* B, b - byte string */
|
||||
/* @B"XXX", @b"XXX" - byte string */
|
||||
SET_TOKEN_TYPE (hawk, tok, TOK_MBS);
|
||||
if (get_string(hawk, c, HAWK_T('\\'), 0, 1, 0, tok) <= -1) return -1;
|
||||
}
|
||||
#if 0
|
||||
|
||||
else if (c == '\'')
|
||||
{
|
||||
/* TODO: character literal when I add a character type?? */
|
||||
/* @B'X' @b'x' - byte character */
|
||||
SET_TOKEN_TYPE (hawk, tok, TOK_BCHR);
|
||||
if (get_string(hawk, c, '\\', 0, 1, 0, tok) <= -1) return -1;
|
||||
if (HAWK_OOECS_LEN(tok->name) != 1)
|
||||
{
|
||||
hawk_seterrfmt (hawk, &tok->loc, HAWK_ELXCHR, HAWK_T("invalid byte-character token"));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
unget_char (hawk, &hawk->sio.last);
|
||||
|
445
hawk/lib/run.c
445
hawk/lib/run.c
@ -157,6 +157,7 @@ static int get_reference (hawk_rtx_t* rtx, hawk_nde_t* nde, hawk_val_t*** ref);
|
||||
static hawk_val_t** get_reference_indexed (hawk_rtx_t* rtx, hawk_nde_var_t* var);
|
||||
|
||||
static hawk_val_t* eval_char (hawk_rtx_t* rtx, hawk_nde_t* nde);
|
||||
static hawk_val_t* eval_bchr (hawk_rtx_t* rtx, hawk_nde_t* nde);
|
||||
static hawk_val_t* eval_int (hawk_rtx_t* rtx, hawk_nde_t* nde);
|
||||
static hawk_val_t* eval_flt (hawk_rtx_t* rtx, hawk_nde_t* nde);
|
||||
static hawk_val_t* eval_str (hawk_rtx_t* rtx, hawk_nde_t* nde);
|
||||
@ -3647,6 +3648,7 @@ static hawk_val_t* eval_expression0 (hawk_rtx_t* rtx, hawk_nde_t* nde)
|
||||
eval_fncall_fun,
|
||||
eval_fncall_var,
|
||||
eval_char,
|
||||
eval_bchr,
|
||||
eval_int,
|
||||
eval_flt,
|
||||
eval_str,
|
||||
@ -4635,7 +4637,13 @@ static HAWK_INLINE int __cmp_nil_nil (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
|
||||
|
||||
static HAWK_INLINE int __cmp_nil_char (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
hawk_ooch_t v = HAWK_RTX_GETCHARFROMVAL(rtx, right);
|
||||
hawk_oochu_t v = HAWK_RTX_GETCHARFROMVAL(rtx, right);
|
||||
return (v < 0)? 1: ((v > 0)? -1: 0);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_nil_bchr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
hawk_bchu_t v = HAWK_RTX_GETBCHRFROMVAL(rtx, right);
|
||||
return (v < 0)? 1: ((v > 0)? -1: 0);
|
||||
}
|
||||
|
||||
@ -4670,38 +4678,67 @@ static HAWK_INLINE int __cmp_nil_fun (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
|
||||
|
||||
static HAWK_INLINE int __cmp_nil_map (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
return (HAWK_HTB_SIZE(((hawk_val_map_t*)right)->map) == 0)? 0: -1;
|
||||
return (HAWK_MAP_SIZE(((hawk_val_map_t*)right)->map) == 0)? 0: -1;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_nil_arr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
return (HAWK_ARR_SIZE(((hawk_val_arr_t*)right)->arr) == 0)? 0: -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
static HAWK_INLINE int __cmp_char_nil (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
hawk_ooch_t v = HAWK_RTX_GETCHARFROMVAL(rtx, left);
|
||||
return (v > 0)? 1: ((v < 0)? -1: 0);
|
||||
int n;
|
||||
n = __cmp_nil_char(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_char_char (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
hawk_ooch_t v1 = HAWK_RTX_GETCHARFROMVAL(rtx, left);
|
||||
hawk_ooch_t v2 = HAWK_RTX_GETCHARFROMVAL(rtx, right);
|
||||
hawk_oochu_t v1 = HAWK_RTX_GETCHARFROMVAL(rtx, left);
|
||||
hawk_oochu_t v2 = HAWK_RTX_GETCHARFROMVAL(rtx, right);
|
||||
return (v1 > v2)? 1: ((v1 < v2)? -1: 0);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_char_bchr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
hawk_oochu_t v1 = HAWK_RTX_GETCHARFROMVAL(rtx, left);
|
||||
hawk_bchu_t v2 = HAWK_RTX_GETBCHRFROMVAL(rtx, right);
|
||||
return (v1 > v2)? 1: ((v1 < v2)? -1: 0);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_char_int (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
hawk_ooch_t v1 = HAWK_RTX_GETCHARFROMVAL(rtx, left);
|
||||
hawk_ooch_t v2 = HAWK_RTX_GETCHARFROMVAL(rtx, right);
|
||||
/*
|
||||
hawk_oochu_t v1 = HAWK_RTX_GETCHARFROMVAL(rtx, left);
|
||||
hawk_int_t v2 = HAWK_RTX_GETINTFROMVAL(rtx, right);
|
||||
return (v1 > v2)? 1: ((v1 < v2)? -1: 0);
|
||||
*/
|
||||
hawk_ooch_t v1;
|
||||
hawk_ooch_t* str0;
|
||||
hawk_oow_t len0;
|
||||
int n;
|
||||
|
||||
v1 = HAWK_RTX_GETCHARFROMVAL(rtx, left);
|
||||
str0 = hawk_rtx_getvaloocstr(rtx, right, &len0);
|
||||
if (!str0) return CMP_ERROR;
|
||||
n = hawk_comp_oochars(&v1, 1, str0, len0, rtx->gbl.ignorecase);
|
||||
hawk_rtx_freevaloocstr (rtx, right, str0);
|
||||
return n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_char_flt (
|
||||
hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
static HAWK_INLINE int __cmp_char_flt (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
/*
|
||||
hawk_ooch_t v1 = HAWK_RTX_GETCHARFROMVAL(rtx, left);
|
||||
if (v1 > ((hawk_val_flt_t*)right)->val) return 1;
|
||||
if (v1 < ((hawk_val_flt_t*)right)->val) return -1;
|
||||
return 0;
|
||||
*/
|
||||
return __cmp_char_int(rtx, left, right, op_hint);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_char_str (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
@ -4726,27 +4763,122 @@ static HAWK_INLINE int __cmp_char_fun (hawk_rtx_t* rtx, hawk_val_t* left, hawk_v
|
||||
|
||||
static HAWK_INLINE int __cmp_char_map (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
/* compare an integer and the size of a map */
|
||||
hawk_ooch_t v1 = HAWK_RTX_GETCHARFROMVAL(rtx, left);
|
||||
hawk_int_t v2 = HAWK_HTB_SIZE(((hawk_val_map_t*)right)->map);
|
||||
if (v1 > v2) return 1;
|
||||
if (v1 < v2) return -1;
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_char_arr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
static HAWK_INLINE int __cmp_bchr_nil (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
int n;
|
||||
n = __cmp_nil_bchr(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_bchr_char (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
int n;
|
||||
n = __cmp_char_bchr(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_bchr_bchr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
hawk_bchu_t v1 = HAWK_RTX_GETBCHRFROMVAL(rtx, left);
|
||||
hawk_bchu_t v2 = HAWK_RTX_GETBCHRFROMVAL(rtx, right);
|
||||
return (v1 > v2)? 1: ((v1 < v2)? -1: 0);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_bchr_int (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
/*
|
||||
hawk_bchu_t v1 = HAWK_RTX_GETBCHRFROMVAL(rtx, left);
|
||||
hawk_int_t v2 = HAWK_RTX_GETINTFROMVAL(rtx, right);
|
||||
return (v1 > v2)? 1: ((v1 < v2)? -1: 0);
|
||||
*/
|
||||
hawk_bch_t v1;
|
||||
hawk_bch_t* str0;
|
||||
hawk_oow_t len0;
|
||||
int n;
|
||||
|
||||
v1 = HAWK_RTX_GETBCHRFROMVAL(rtx, left);
|
||||
str0 = hawk_rtx_getvalbcstr(rtx, right, &len0);
|
||||
if (!str0) return CMP_ERROR;
|
||||
n = hawk_comp_bchars(&v1, 1, str0, len0, rtx->gbl.ignorecase);
|
||||
hawk_rtx_freevalbcstr (rtx, right, str0);
|
||||
return n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_bchr_flt (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
/*
|
||||
hawk_bchu_t v1 = HAWK_RTX_GETBCHRFROMVAL(rtx, left);
|
||||
if (v1 > ((hawk_val_flt_t*)right)->val) return 1;
|
||||
if (v1 < ((hawk_val_flt_t*)right)->val) return -1;
|
||||
return 0;
|
||||
*/
|
||||
return __cmp_bchr_int(rtx, left, right, op_hint);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_bchr_str (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
hawk_bchu_t v1 = HAWK_RTX_GETBCHRFROMVAL(rtx, left);
|
||||
hawk_oochu_t oc = v1;
|
||||
return hawk_comp_oochars(&oc, 1, ((hawk_val_str_t*)right)->val.ptr, ((hawk_val_str_t*)right)->val.len, rtx->gbl.ignorecase);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_bchr_mbs (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
hawk_bch_t v1 = HAWK_RTX_GETBCHRFROMVAL(rtx, left);
|
||||
return hawk_comp_bchars(&v1, 1, ((hawk_val_mbs_t*)right)->val.ptr, ((hawk_val_mbs_t*)right)->val.len, rtx->gbl.ignorecase);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_bchr_fun (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_bchr_map (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_bchr_arr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
static HAWK_INLINE int __cmp_int_nil (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
hawk_int_t v = HAWK_RTX_GETINTFROMVAL(rtx, left);
|
||||
return (v > 0)? 1: ((v < 0)? -1: 0);
|
||||
int n;
|
||||
n = __cmp_nil_int(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_int_char (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
hawk_int_t v1 = HAWK_RTX_GETINTFROMVAL(rtx, left);
|
||||
hawk_ooch_t v2 = HAWK_RTX_GETCHARFROMVAL(rtx, right);
|
||||
return (v1 > v2)? 1: ((v1 < v2)? -1: 0);
|
||||
int n;
|
||||
n = __cmp_char_int(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_int_bchr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
int n;
|
||||
n = __cmp_bchr_int(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_int_int (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
@ -4756,8 +4888,7 @@ static HAWK_INLINE int __cmp_int_int (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
|
||||
return (v1 > v2)? 1: ((v1 < v2)? -1: 0);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_int_flt (
|
||||
hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
static HAWK_INLINE int __cmp_int_flt (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
hawk_int_t v1 = HAWK_RTX_GETINTFROMVAL (rtx, left);
|
||||
if (v1 > ((hawk_val_flt_t*)right)->val) return 1;
|
||||
@ -4798,11 +4929,10 @@ static HAWK_INLINE int __cmp_int_str (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
|
||||
}
|
||||
}
|
||||
|
||||
str0 = hawk_rtx_valtooocstrdup(rtx, left, &len0);
|
||||
str0 = hawk_rtx_getvaloocstr(rtx, left, &len0);
|
||||
if (!str0) return CMP_ERROR;
|
||||
|
||||
n = hawk_comp_oochars(str0, len0, ((hawk_val_str_t*)right)->val.ptr, ((hawk_val_str_t*)right)->val.len, rtx->gbl.ignorecase);
|
||||
hawk_rtx_freemem (rtx, str0);
|
||||
hawk_rtx_freevaloocstr (rtx, left, str0);
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -4838,11 +4968,10 @@ static HAWK_INLINE int __cmp_int_mbs (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
|
||||
}
|
||||
}
|
||||
|
||||
str0 = hawk_rtx_valtobcstrdup(rtx, left, &len0);
|
||||
str0 = hawk_rtx_getvalbcstr(rtx, left, &len0);
|
||||
if (!str0) return -1;
|
||||
|
||||
n = hawk_comp_bchars(str0, len0, ((hawk_val_mbs_t*)right)->val.ptr, ((hawk_val_mbs_t*)right)->val.len, rtx->gbl.ignorecase);
|
||||
hawk_rtx_freemem (rtx, str0);
|
||||
hawk_rtx_freevalbcstr (rtx, left, str0);
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -4853,45 +4982,51 @@ static HAWK_INLINE int __cmp_int_fun (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
|
||||
|
||||
static HAWK_INLINE int __cmp_int_map (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
/* compare an integer and the size of a map */
|
||||
hawk_int_t v1 = HAWK_RTX_GETINTFROMVAL(rtx, left);
|
||||
hawk_int_t v2 = HAWK_HTB_SIZE(((hawk_val_map_t*)right)->map);
|
||||
if (v1 > v2) return 1;
|
||||
if (v1 < v2) return -1;
|
||||
return 0;
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_int_arr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
static HAWK_INLINE int __cmp_flt_nil (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
if (((hawk_val_flt_t*)left)->val > 0) return 1;
|
||||
if (((hawk_val_flt_t*)left)->val < 0) return -1;
|
||||
return 0;
|
||||
int n;
|
||||
n = __cmp_nil_flt(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_flt_char (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
hawk_ooch_t v2 = HAWK_RTX_GETCHARFROMVAL(rtx, right);
|
||||
if (((hawk_val_flt_t*)left)->val > v2) return 1;
|
||||
if (((hawk_val_flt_t*)left)->val < v2) return -1;
|
||||
return 0;
|
||||
int n;
|
||||
n = __cmp_char_flt(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_flt_bchr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
int n;
|
||||
n = __cmp_bchr_flt(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_flt_int (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
hawk_int_t v2 = HAWK_RTX_GETINTFROMVAL(rtx, right);
|
||||
if (((hawk_val_flt_t*)left)->val > v2) return 1;
|
||||
if (((hawk_val_flt_t*)left)->val < v2) return -1;
|
||||
return 0;
|
||||
int n;
|
||||
n = __cmp_int_flt(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_flt_flt (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
if (((hawk_val_flt_t*)left)->val >
|
||||
((hawk_val_flt_t*)right)->val) return 1;
|
||||
if (((hawk_val_flt_t*)left)->val <
|
||||
((hawk_val_flt_t*)right)->val) return -1;
|
||||
if (((hawk_val_flt_t*)left)->val > ((hawk_val_flt_t*)right)->val) return 1;
|
||||
if (((hawk_val_flt_t*)left)->val < ((hawk_val_flt_t*)right)->val) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -4916,11 +5051,10 @@ static HAWK_INLINE int __cmp_flt_str (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
|
||||
}
|
||||
}
|
||||
|
||||
str0 = hawk_rtx_valtooocstrdup(rtx, left, &len0);
|
||||
str0 = hawk_rtx_getvaloocstr(rtx, left, &len0);
|
||||
if (!str0) return CMP_ERROR;
|
||||
|
||||
n = hawk_comp_oochars(str0, len0, ((hawk_val_str_t*)right)->val.ptr, ((hawk_val_str_t*)right)->val.len, rtx->gbl.ignorecase);
|
||||
hawk_rtx_freemem (rtx, str0);
|
||||
hawk_rtx_freevaloocstr (rtx, left, str0);
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -4944,11 +5078,10 @@ static HAWK_INLINE int __cmp_flt_mbs (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
|
||||
}
|
||||
}
|
||||
|
||||
str0 = hawk_rtx_valtobcstrdup(rtx, left, &len0);
|
||||
str0 = hawk_rtx_getvalbcstr(rtx, left, &len0);
|
||||
if (HAWK_UNLIKELY(!str0)) return CMP_ERROR;
|
||||
|
||||
n = hawk_comp_bchars(str0, len0, ((hawk_val_mbs_t*)right)->val.ptr, ((hawk_val_mbs_t*)right)->val.len, rtx->gbl.ignorecase);
|
||||
hawk_rtx_freemem (rtx, str0);
|
||||
hawk_rtx_freevalbcstr (rtx, left, str0);
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -4959,18 +5092,22 @@ static HAWK_INLINE int __cmp_flt_fun (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
|
||||
|
||||
static HAWK_INLINE int __cmp_flt_map (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
/* compare a float with the size of a map */
|
||||
hawk_int_t v2 = HAWK_HTB_SIZE(((hawk_val_map_t*)right)->map);
|
||||
if (((hawk_val_flt_t*)left)->val > v2) return 1;
|
||||
if (((hawk_val_flt_t*)left)->val < v2) return -1;
|
||||
return 0;
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_flt_arr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
static HAWK_INLINE int __cmp_str_nil (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
return (((hawk_val_str_t*)left)->val.len == 0)? 0: 1;
|
||||
int n;
|
||||
n = __cmp_nil_str(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_str_char (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
@ -4981,6 +5118,14 @@ static HAWK_INLINE int __cmp_str_char (hawk_rtx_t* rtx, hawk_val_t* left, hawk_v
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_str_bchr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
int n;
|
||||
n = __cmp_bchr_str(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_str_int (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
int n;
|
||||
@ -5105,11 +5250,20 @@ static HAWK_INLINE int __cmp_str_map (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_str_arr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
static HAWK_INLINE int __cmp_mbs_nil (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
return (((hawk_val_mbs_t*)left)->val.len == 0)? 0: 1;
|
||||
int n;
|
||||
n = __cmp_nil_mbs(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_mbs_char (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
@ -5120,6 +5274,15 @@ static HAWK_INLINE int __cmp_mbs_char (hawk_rtx_t* rtx, hawk_val_t* left, hawk_v
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_mbs_bchr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
int n;
|
||||
n = __cmp_bchr_mbs(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
|
||||
static HAWK_INLINE int __cmp_mbs_int (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
int n;
|
||||
@ -5164,6 +5327,11 @@ static HAWK_INLINE int __cmp_mbs_map (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_mbs_arr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
static HAWK_INLINE int __cmp_fun_nil (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
@ -5176,6 +5344,11 @@ static HAWK_INLINE int __cmp_fun_char (hawk_rtx_t* rtx, hawk_val_t* left, hawk_v
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_fun_bchr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_fun_int (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
@ -5206,6 +5379,11 @@ static HAWK_INLINE int __cmp_fun_map (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_fun_arr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
static HAWK_INLINE int __cmp_map_nil (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
@ -5224,6 +5402,14 @@ static HAWK_INLINE int __cmp_map_char (hawk_rtx_t* rtx, hawk_val_t* left, hawk_v
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_map_bchr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
int n;
|
||||
n = __cmp_bchr_map(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_map_int (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
int n;
|
||||
@ -5261,6 +5447,85 @@ static HAWK_INLINE int __cmp_map_map (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
|
||||
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EOPERAND);
|
||||
return CMP_ERROR;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_map_arr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
/* can't compare a map with an array */
|
||||
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EOPERAND);
|
||||
return CMP_ERROR;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
static HAWK_INLINE int __cmp_arr_nil (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
int n;
|
||||
n = __cmp_nil_arr(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_arr_char (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
int n;
|
||||
n = __cmp_char_arr(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_arr_bchr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
int n;
|
||||
n = __cmp_bchr_arr(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_arr_int (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
int n;
|
||||
n = __cmp_int_arr(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_arr_flt (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
int n;
|
||||
n = __cmp_flt_arr(rtx, right, left, inverse_cmp_op(op_hint));
|
||||
if (n == CMP_ERROR) return CMP_ERROR;
|
||||
return -n;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_arr_str (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_arr_mbs (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_arr_fun (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
return __cmp_ensure_not_equal(rtx, op_hint);
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_arr_map (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
/* can't compare a map with a map */
|
||||
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EOPERAND);
|
||||
return CMP_ERROR;
|
||||
}
|
||||
|
||||
static HAWK_INLINE int __cmp_arr_arr (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t* right, cmp_op_t op_hint)
|
||||
{
|
||||
/* can't compare a map with an array */
|
||||
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EOPERAND);
|
||||
return CMP_ERROR;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
|
||||
@ -5272,47 +5537,49 @@ static HAWK_INLINE int __cmp_val (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t*
|
||||
|
||||
static cmp_val_t func[] =
|
||||
{
|
||||
/* this table must be synchronized with
|
||||
* the HAWK_VAL_XXX values in hawk.h */
|
||||
__cmp_nil_nil, __cmp_nil_char, __cmp_nil_int, __cmp_nil_flt, __cmp_nil_str, __cmp_nil_mbs, __cmp_nil_fun, __cmp_nil_map,
|
||||
__cmp_char_nil, __cmp_char_char, __cmp_char_int, __cmp_char_flt, __cmp_char_str, __cmp_char_mbs, __cmp_char_fun, __cmp_char_map,
|
||||
__cmp_int_nil, __cmp_int_char, __cmp_int_int, __cmp_int_flt, __cmp_int_str, __cmp_int_mbs, __cmp_int_fun, __cmp_int_map,
|
||||
__cmp_flt_nil, __cmp_flt_char, __cmp_flt_int, __cmp_flt_flt, __cmp_flt_str, __cmp_flt_mbs, __cmp_flt_fun, __cmp_flt_map,
|
||||
__cmp_str_nil, __cmp_str_char, __cmp_str_int, __cmp_str_flt, __cmp_str_str, __cmp_str_mbs, __cmp_str_fun, __cmp_str_map,
|
||||
__cmp_mbs_nil, __cmp_mbs_char, __cmp_mbs_int, __cmp_mbs_flt, __cmp_mbs_str, __cmp_mbs_mbs, __cmp_mbs_fun, __cmp_mbs_map,
|
||||
__cmp_fun_nil, __cmp_fun_char, __cmp_fun_int, __cmp_fun_flt, __cmp_fun_str, __cmp_fun_mbs, __cmp_fun_fun, __cmp_fun_map,
|
||||
__cmp_map_nil, __cmp_map_char, __cmp_map_int, __cmp_map_flt, __cmp_map_str, __cmp_map_mbs, __cmp_map_fun, __cmp_map_map
|
||||
/* this table must be synchronized with the HAWK_VAL_XXX values in hawk.h */
|
||||
__cmp_nil_nil, __cmp_nil_char, __cmp_nil_bchr, __cmp_nil_int, __cmp_nil_flt, __cmp_nil_str, __cmp_nil_mbs, __cmp_nil_fun, __cmp_nil_map, __cmp_nil_arr,
|
||||
__cmp_char_nil, __cmp_char_char, __cmp_char_bchr, __cmp_char_int, __cmp_char_flt, __cmp_char_str, __cmp_char_mbs, __cmp_char_fun, __cmp_char_map, __cmp_char_arr,
|
||||
__cmp_bchr_nil, __cmp_bchr_char, __cmp_bchr_bchr, __cmp_bchr_int, __cmp_bchr_flt, __cmp_bchr_str, __cmp_bchr_mbs, __cmp_bchr_fun, __cmp_bchr_map, __cmp_bchr_arr,
|
||||
__cmp_int_nil, __cmp_int_char, __cmp_int_bchr, __cmp_int_int, __cmp_int_flt, __cmp_int_str, __cmp_int_mbs, __cmp_int_fun, __cmp_int_map, __cmp_int_arr,
|
||||
__cmp_flt_nil, __cmp_flt_char, __cmp_flt_bchr, __cmp_flt_int, __cmp_flt_flt, __cmp_flt_str, __cmp_flt_mbs, __cmp_flt_fun, __cmp_flt_map, __cmp_flt_arr,
|
||||
__cmp_str_nil, __cmp_str_char, __cmp_str_bchr, __cmp_str_int, __cmp_str_flt, __cmp_str_str, __cmp_str_mbs, __cmp_str_fun, __cmp_str_map, __cmp_str_arr,
|
||||
__cmp_mbs_nil, __cmp_mbs_char, __cmp_mbs_bchr, __cmp_mbs_int, __cmp_mbs_flt, __cmp_mbs_str, __cmp_mbs_mbs, __cmp_mbs_fun, __cmp_mbs_map, __cmp_mbs_arr,
|
||||
__cmp_fun_nil, __cmp_fun_char, __cmp_fun_bchr, __cmp_fun_int, __cmp_fun_flt, __cmp_fun_str, __cmp_fun_mbs, __cmp_fun_fun, __cmp_fun_map, __cmp_fun_arr,
|
||||
__cmp_map_nil, __cmp_map_char, __cmp_map_bchr, __cmp_map_int, __cmp_map_flt, __cmp_map_str, __cmp_map_mbs, __cmp_map_fun, __cmp_map_map, __cmp_map_arr,
|
||||
__cmp_arr_nil, __cmp_arr_char, __cmp_arr_bchr, __cmp_arr_int, __cmp_arr_flt, __cmp_arr_str, __cmp_arr_mbs, __cmp_arr_fun, __cmp_arr_map, __cmp_arr_arr
|
||||
};
|
||||
|
||||
lvtype = HAWK_RTX_GETVALTYPE(rtx, left);
|
||||
rvtype = HAWK_RTX_GETVALTYPE(rtx, right);
|
||||
if (!(rtx->hawk->opt.trait & HAWK_FLEXMAP) &&
|
||||
(lvtype == HAWK_VAL_MAP || rvtype == HAWK_VAL_MAP))
|
||||
if (!(rtx->hawk->opt.trait & HAWK_FLEXMAP) && (lvtype == HAWK_VAL_MAP || rvtype == HAWK_VAL_MAP || lvtype == HAWK_VAL_ARR || rvtype == HAWK_VAL_ARR))
|
||||
{
|
||||
/* a map can't be compared againt other values */
|
||||
/* a map can't be compared againt other values in the non-flexible mode. */
|
||||
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EOPERAND);
|
||||
return -1;
|
||||
}
|
||||
|
||||
HAWK_ASSERT (lvtype >= HAWK_VAL_NIL && lvtype <= HAWK_VAL_MAP);
|
||||
HAWK_ASSERT (rvtype >= HAWK_VAL_NIL && rvtype <= HAWK_VAL_MAP);
|
||||
HAWK_ASSERT (lvtype >= HAWK_VAL_NIL && lvtype <= HAWK_VAL_ARR);
|
||||
HAWK_ASSERT (rvtype >= HAWK_VAL_NIL && rvtype <= HAWK_VAL_ARR);
|
||||
|
||||
/* mapping fomula and table layout assume:
|
||||
* HAWK_VAL_NIL = 0
|
||||
* HAWK_VAL_CHAR = 1
|
||||
* HAWK_VAL_INT = 2
|
||||
* HAWK_VAL_FLT = 3
|
||||
* HAWK_VAL_STR = 4
|
||||
* HAWK_VAL_MBS = 5
|
||||
* HAWK_VAL_FUN = 6
|
||||
* HAWK_VAL_MAP = 7
|
||||
* HAWK_VAL_BCHR = 2
|
||||
* HAWK_VAL_INT = 3
|
||||
* HAWK_VAL_FLT = 4
|
||||
* HAWK_VAL_STR = 5
|
||||
* HAWK_VAL_MBS = 6
|
||||
* HAWK_VAL_FUN = 7
|
||||
* HAWK_VAL_MAP = 8
|
||||
* HAWK_VAL_ARR = 9
|
||||
*
|
||||
* op_hint indicate the operation in progress when this function is called.
|
||||
* this hint doesn't require the comparison function to compare using this
|
||||
* operation. the comparision function should return 0 if equal, -1 if less,
|
||||
* 1 if greater, CMP_ERROR upon error regardless of this hint.
|
||||
*/
|
||||
n = func[lvtype * 8 + rvtype](rtx, left, right, op_hint);
|
||||
n = func[lvtype * 10 + rvtype](rtx, left, right, op_hint);
|
||||
if (n == CMP_ERROR) return -1;
|
||||
|
||||
*ret = n;
|
||||
@ -7063,6 +7330,14 @@ static hawk_val_t* eval_char (hawk_rtx_t* rtx, hawk_nde_t* nde)
|
||||
return val;
|
||||
}
|
||||
|
||||
static hawk_val_t* eval_bchr (hawk_rtx_t* rtx, hawk_nde_t* nde)
|
||||
{
|
||||
hawk_val_t* val;
|
||||
val = hawk_rtx_makebchrval(rtx, ((hawk_nde_char_t*)nde)->val);
|
||||
if (HAWK_UNLIKELY(!val)) ADJERR_LOC (rtx, &nde->loc);
|
||||
return val;
|
||||
}
|
||||
|
||||
static hawk_val_t* eval_int (hawk_rtx_t* rtx, hawk_nde_t* nde)
|
||||
{
|
||||
hawk_val_t* val;
|
||||
@ -7801,7 +8076,7 @@ static hawk_ooi_t idxnde_to_int (hawk_rtx_t* rtx, hawk_nde_t* nde, hawk_nde_t**
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (v < 0 || v > HAWK_QUICKINT_MAX)
|
||||
if (v < 0 || v > HAWK_QINT_MAX)
|
||||
{
|
||||
/* array index out of permitted range */
|
||||
hawk_rtx_seterrnum (rtx, &nde->loc, HAWK_EARRIDXRANGE);
|
||||
|
@ -58,6 +58,7 @@ typedef struct hawk_nde_cnd_t hawk_nde_cnd_t;
|
||||
typedef struct hawk_nde_pos_t hawk_nde_pos_t;
|
||||
|
||||
typedef struct hawk_nde_char_t hawk_nde_char_t;
|
||||
typedef struct hawk_nde_bchr_t hawk_nde_bchr_t;
|
||||
typedef struct hawk_nde_int_t hawk_nde_int_t;
|
||||
typedef struct hawk_nde_flt_t hawk_nde_flt_t;
|
||||
typedef struct hawk_nde_str_t hawk_nde_str_t;
|
||||
@ -143,6 +144,14 @@ struct hawk_nde_char_t
|
||||
hawk_ooch_t val;
|
||||
};
|
||||
|
||||
|
||||
/* HAWK_NDE_BCHR */
|
||||
struct hawk_nde_bchr_t
|
||||
{
|
||||
HAWK_NDE_HDR;
|
||||
hawk_bch_t val;
|
||||
};
|
||||
|
||||
/* HAWK_NDE_INT */
|
||||
struct hawk_nde_int_t
|
||||
{
|
||||
|
@ -338,6 +338,28 @@ static int print_expr (hawk_t* hawk, hawk_nde_t* nde)
|
||||
break;
|
||||
}
|
||||
|
||||
case HAWK_NDE_BCHR:
|
||||
{
|
||||
hawk_bch_t tmp = ((hawk_nde_char_t*)nde)->val;
|
||||
hawk_ooch_t buf[16];
|
||||
|
||||
PUT_SRCSTR (hawk, HAWK_T("@b\'"));
|
||||
if (tmp == '\0')
|
||||
PUT_SRCSTR (hawk, HAWK_T("\\0"));
|
||||
else if (tmp == '\'')
|
||||
PUT_SRCSTR (hawk, HAWK_T("\\'"));
|
||||
else if (hawk_is_bch_print(tmp))
|
||||
PUT_SRCSTRN (hawk, &tmp, 1);
|
||||
else
|
||||
{
|
||||
hawk_fmttooocstr (hawk, buf, HAWK_COUNTOF(buf), HAWK_T("\\x%02x"), tmp);
|
||||
PUT_SRCSTR (hawk, buf);
|
||||
}
|
||||
|
||||
PUT_SRCSTR (hawk, HAWK_T("\'"));
|
||||
break;
|
||||
}
|
||||
|
||||
case HAWK_NDE_INT:
|
||||
{
|
||||
if (((hawk_nde_int_t*)nde)->str)
|
||||
@ -1384,6 +1406,7 @@ void hawk_clrpt (hawk_t* hawk, hawk_nde_t* tree)
|
||||
}
|
||||
|
||||
case HAWK_NDE_CHAR:
|
||||
case HAWK_NDE_BCHR:
|
||||
{
|
||||
hawk_freemem (hawk, p);
|
||||
break;
|
||||
|
@ -77,58 +77,78 @@ struct hawk_val_rchunk_t
|
||||
*
|
||||
* is this a safe assumption? do i have to use memalign or write my own
|
||||
* aligned malloc()? */
|
||||
#define HAWK_VTR_NUM_TYPE_BITS 2 /* last 2 bits */
|
||||
#define HAWK_VTR_MASK_TYPE_BITS 3 /* all 1's in the last 2 bits */
|
||||
#define HAWK_VTR_NUM_TYPE_BITS_LO 2 /* last 2 bits */
|
||||
#define HAWK_VTR_MASK_TYPE_BITS_LO 3 /* 11 - all 1's in the last 2 bits */
|
||||
#define HAWK_VTR_NUM_TYPE_BITS_LOHI 4
|
||||
#define HAWK_VTR_MASK_TYPE_BITS_LOHI 15 /* 1111 */
|
||||
|
||||
#define HAWK_VTR_TYPE_BITS_POINTER 0
|
||||
#define HAWK_VTR_TYPE_BITS_QUICKINT 1
|
||||
#define HAWK_VTR_TYPE_BITS_QUICKCHAR 2
|
||||
|
||||
#define HAWK_VTR_TYPE_BITS_POINTER 0 /* 00 */
|
||||
#define HAWK_VTR_TYPE_BITS_QINT 1 /* 01 */
|
||||
#define HAWK_VTR_TYPE_BITS_QCHAR 2 /* 10 */
|
||||
#define HAWK_VTR_TYPE_BITS_QEXT 3 /* 11 extended */
|
||||
#define HAWK_VTR_TYPE_BITS_QBCHR 3 /* 0011 */
|
||||
#define HAWK_VTR_TYPE_BITS_RESERVED0 7 /* 0111 */
|
||||
#define HAWK_VTR_TYPE_BITS_RESERVED1 11 /* 1011 */
|
||||
#define HAWK_VTR_TYPE_BITS_RESERVED2 15 /* 1111 */
|
||||
#define HAWK_VTR_SIGN_BIT ((hawk_uintptr_t)1 << (HAWK_SIZEOF_UINTPTR_T * 8 - 1))
|
||||
|
||||
/* shrink the bit range by 1 more bit to ease signbit handling.
|
||||
/* shrink the bit range by 1 more bit to ease sign-bit handling.
|
||||
* i want abs(max) == abs(min).
|
||||
* i don't want abs(max) + 1 == abs(min). e.g min: -32768, max: 32767
|
||||
*/
|
||||
#define HAWK_QUICKINT_MAX ((hawk_int_t)((~(hawk_uintptr_t)0) >> (HAWK_VTR_NUM_TYPE_BITS + 1)))
|
||||
#define HAWK_QUICKINT_MIN (-HAWK_QUICKINT_MAX)
|
||||
#define HAWK_IN_QUICKINT_RANGE(i) ((i) >= HAWK_QUICKINT_MIN && (i) <= HAWK_QUICKINT_MAX)
|
||||
#define HAWK_QINT_MAX ((hawk_int_t)((~(hawk_uintptr_t)0) >> (HAWK_VTR_NUM_TYPE_BITS_LO + 1)))
|
||||
#define HAWK_QINT_MIN (-HAWK_QINT_MAX)
|
||||
#define HAWK_IN_QINT_RANGE(i) ((i) >= HAWK_QINT_MIN && (i) <= HAWK_QINT_MAX)
|
||||
|
||||
#define HAWK_VTR_TYPE_BITS_LO(p) (((hawk_uintptr_t)(p)) & HAWK_VTR_MASK_TYPE_BITS_LO)
|
||||
#define HAWK_VTR_TYPE_BITS_LOHI(p) (((hawk_uintptr_t)(p)) & HAWK_VTR_MASK_TYPE_BITS_LOHI)
|
||||
|
||||
//#define HAWK_VTR_TYPE_BITS(p) (((hawk_uintptr_t)(p)) & HAWK_VTR_MASK_TYPE_BITS)
|
||||
#define HAWK_VTR_TYPE_BITS(p) (HAWK_VTR_TYPE_BITS_LO(p) == HAWK_VTR_TYPE_BITS_QEXT? HAWK_VTR_TYPE_BITS_LOHI(p): HAWK_VTR_TYPE_BITS_LO(p))
|
||||
|
||||
|
||||
#define HAWK_VTR_TYPE_BITS(p) (((hawk_uintptr_t)(p)) & HAWK_VTR_MASK_TYPE_BITS)
|
||||
#define HAWK_VTR_IS_POINTER(p) (HAWK_VTR_TYPE_BITS(p) == HAWK_VTR_TYPE_BITS_POINTER)
|
||||
#define HAWK_VTR_IS_QUICKINT(p) (HAWK_VTR_TYPE_BITS(p) == HAWK_VTR_TYPE_BITS_QUICKINT)
|
||||
#define HAWK_VTR_IS_QUICKCHAR(p) (HAWK_VTR_TYPE_BITS(p) == HAWK_VTR_TYPE_BITS_QUICKCHAR)
|
||||
#define HAWK_VTR_IS_QINT(p) (HAWK_VTR_TYPE_BITS(p) == HAWK_VTR_TYPE_BITS_QINT)
|
||||
#define HAWK_VTR_IS_QCHAR(p) (HAWK_VTR_TYPE_BITS(p) == HAWK_VTR_TYPE_BITS_QCHAR)
|
||||
#define HAWK_VTR_IS_QBCHR(p) (HAWK_VTR_TYPE_BITS(p) == HAWK_VTR_TYPE_BITS_QBCHR)
|
||||
|
||||
#define HAWK_QUICKINT_TO_VTR_POSITIVE(i) \
|
||||
(((hawk_uintptr_t)(i) << HAWK_VTR_NUM_TYPE_BITS) | HAWK_VTR_TYPE_BITS_QUICKINT)
|
||||
#define HAWK_QINT_TO_VTR_POSITIVE(i) \
|
||||
(((hawk_uintptr_t)(i) << HAWK_VTR_NUM_TYPE_BITS_LO) | HAWK_VTR_TYPE_BITS_QINT)
|
||||
|
||||
#define HAWK_QUICKINT_TO_VTR_NEGATIVE(i) \
|
||||
((((hawk_uintptr_t)-(i)) << HAWK_VTR_NUM_TYPE_BITS) | HAWK_VTR_TYPE_BITS_QUICKINT | HAWK_VTR_SIGN_BIT)
|
||||
#define HAWK_QINT_TO_VTR_NEGATIVE(i) \
|
||||
((((hawk_uintptr_t)-(i)) << HAWK_VTR_NUM_TYPE_BITS_LO) | HAWK_VTR_TYPE_BITS_QINT | HAWK_VTR_SIGN_BIT)
|
||||
|
||||
#define HAWK_QUICKINT_TO_VTR(i) \
|
||||
((hawk_val_t*)(((i) < 0)? HAWK_QUICKINT_TO_VTR_NEGATIVE(i): HAWK_QUICKINT_TO_VTR_POSITIVE(i)))
|
||||
#define HAWK_QINT_TO_VTR(i) \
|
||||
((hawk_val_t*)(((i) < 0)? HAWK_QINT_TO_VTR_NEGATIVE(i): HAWK_QINT_TO_VTR_POSITIVE(i)))
|
||||
|
||||
#define HAWK_QUICKCHAR_TO_VTR(i) ((hawk_val_t*)(((hawk_uintptr_t)(i) << HAWK_VTR_NUM_TYPE_BITS) | HAWK_VTR_TYPE_BITS_QUICKCHAR))
|
||||
#define HAWK_QCHAR_TO_VTR(i) ((hawk_val_t*)(((hawk_uintptr_t)(i) << HAWK_VTR_NUM_TYPE_BITS_LO) | HAWK_VTR_TYPE_BITS_QCHAR))
|
||||
#define HAWK_QBCHR_TO_VTR(i) ((hawk_val_t*)(((hawk_uintptr_t)(i) << HAWK_VTR_NUM_TYPE_BITS_LOHI) | HAWK_VTR_TYPE_BITS_QBCHR))
|
||||
|
||||
#define HAWK_VTR_ZERO ((hawk_val_t*)HAWK_QUICKINT_TO_VTR_POSITIVE(0))
|
||||
#define HAWK_VTR_ONE ((hawk_val_t*)HAWK_QUICKINT_TO_VTR_POSITIVE(1))
|
||||
#define HAWK_VTR_NEGONE ((hawk_val_t*)HAWK_QUICKINT_TO_VTR_NEGATIVE(-1))
|
||||
#define HAWK_VTR_ZERO ((hawk_val_t*)HAWK_QINT_TO_VTR_POSITIVE(0))
|
||||
#define HAWK_VTR_ONE ((hawk_val_t*)HAWK_QINT_TO_VTR_POSITIVE(1))
|
||||
#define HAWK_VTR_NEGONE ((hawk_val_t*)HAWK_QINT_TO_VTR_NEGATIVE(-1))
|
||||
|
||||
/* sizeof(hawk_intptr_t) may not be the same as sizeof(hawk_int_t).
|
||||
* so step-by-step type conversions are needed.
|
||||
* e.g) pointer to uintptr_t, uintptr_t to intptr_t, intptr_t to hawk_int_t */
|
||||
#define HAWK_VTR_TO_QUICKINT_POSITIVE(p) \
|
||||
((hawk_intptr_t)((hawk_uintptr_t)(p) >> HAWK_VTR_NUM_TYPE_BITS))
|
||||
#define HAWK_VTR_TO_QUICKINT_NEGATIVE(p) \
|
||||
(-(hawk_intptr_t)(((hawk_uintptr_t)(p) & ~HAWK_VTR_SIGN_BIT) >> HAWK_VTR_NUM_TYPE_BITS))
|
||||
#define HAWK_VTR_TO_QUICKINT(p) \
|
||||
(((hawk_uintptr_t)(p) & HAWK_VTR_SIGN_BIT)? HAWK_VTR_TO_QUICKINT_NEGATIVE(p): HAWK_VTR_TO_QUICKINT_POSITIVE(p))
|
||||
#define HAWK_VTR_TO_QINT_POSITIVE(p) \
|
||||
((hawk_intptr_t)((hawk_uintptr_t)(p) >> HAWK_VTR_NUM_TYPE_BITS_LO))
|
||||
#define HAWK_VTR_TO_QINT_NEGATIVE(p) \
|
||||
(-(hawk_intptr_t)(((hawk_uintptr_t)(p) & ~HAWK_VTR_SIGN_BIT) >> HAWK_VTR_NUM_TYPE_BITS_LO))
|
||||
#define HAWK_VTR_TO_QINT(p) \
|
||||
(((hawk_uintptr_t)(p) & HAWK_VTR_SIGN_BIT)? HAWK_VTR_TO_QINT_NEGATIVE(p): HAWK_VTR_TO_QINT_POSITIVE(p))
|
||||
|
||||
#define HAWK_VTR_TO_QUICKCHAR(p) ((hawk_ooch_t)((hawk_uintptr_t)(p) >> HAWK_VTR_NUM_TYPE_BITS))
|
||||
#define HAWK_VTR_TO_QCHAR(p) ((hawk_ooch_t)((hawk_uintptr_t)(p) >> HAWK_VTR_NUM_TYPE_BITS_LO))
|
||||
#define HAWK_VTR_TO_QBCHR(p) ((hawk_ooch_t)((hawk_uintptr_t)(p) >> HAWK_VTR_NUM_TYPE_BITS_LOHI))
|
||||
|
||||
#define HAWK_RTX_GETVALTYPE(rtx,p) (HAWK_VTR_IS_QUICKINT(p)? HAWK_VAL_INT: \
|
||||
HAWK_VTR_IS_QUICKCHAR(p)? HAWK_VAL_CHAR: (p)->v_type)
|
||||
#define HAWK_RTX_GETINTFROMVAL(rtx,p) ((HAWK_VTR_IS_QUICKINT(p)? (hawk_int_t)HAWK_VTR_TO_QUICKINT(p): ((hawk_val_int_t*)(p))->i_val))
|
||||
#define HAWK_RTX_GETCHARFROMVAL(rtx, p) (HAWK_VTR_TO_QUICKCHAR(p))
|
||||
#define HAWK_RTX_GETVALTYPE(rtx,p) (HAWK_VTR_IS_QINT(p)? HAWK_VAL_INT: \
|
||||
HAWK_VTR_IS_QCHAR(p)? HAWK_VAL_CHAR: \
|
||||
HAWK_VTR_IS_QBCHR(p)? HAWK_VAL_BCHR: (p)->v_type)
|
||||
|
||||
#define HAWK_RTX_GETINTFROMVAL(rtx,p) ((HAWK_VTR_IS_QINT(p)? (hawk_int_t)HAWK_VTR_TO_QINT(p): ((hawk_val_int_t*)(p))->i_val))
|
||||
#define HAWK_RTX_GETCHARFROMVAL(rtx, p) (HAWK_VTR_TO_QCHAR(p))
|
||||
#define HAWK_RTX_GETBCHRFROMVAL(rtx, p) (HAWK_VTR_TO_QBCHR(p))
|
||||
|
||||
|
||||
#define HAWK_VAL_ZERO HAWK_VTR_ZERO
|
||||
|
@ -486,14 +486,19 @@ hawk_val_t* hawk_rtx_makenilval (hawk_rtx_t* rtx)
|
||||
|
||||
hawk_val_t* hawk_rtx_makecharval (hawk_rtx_t* rtx, hawk_ooch_t v)
|
||||
{
|
||||
return HAWK_QUICKCHAR_TO_VTR(v);
|
||||
return HAWK_QCHAR_TO_VTR((hawk_oochu_t)v);
|
||||
}
|
||||
|
||||
hawk_val_t* hawk_rtx_makebchrval (hawk_rtx_t* rtx, hawk_bch_t v)
|
||||
{
|
||||
return HAWK_QBCHR_TO_VTR((hawk_bchu_t)v);
|
||||
}
|
||||
|
||||
hawk_val_t* hawk_rtx_makeintval (hawk_rtx_t* rtx, hawk_int_t v)
|
||||
{
|
||||
hawk_val_int_t* val;
|
||||
|
||||
if (HAWK_IN_QUICKINT_RANGE(v)) return HAWK_QUICKINT_TO_VTR(v);
|
||||
if (HAWK_IN_QINT_RANGE(v)) return HAWK_QINT_TO_VTR(v);
|
||||
|
||||
if (!rtx->vmgr.ifree)
|
||||
{
|
||||
@ -1418,6 +1423,7 @@ const hawk_ooch_t* hawk_rtx_getvaltypename(hawk_rtx_t* rtx, hawk_val_t* val)
|
||||
/* synchronize this table with enum hawk_val_type_t in hawk.h */
|
||||
HAWK_T("nil"),
|
||||
HAWK_T("char"),
|
||||
HAWK_T("bchar"),
|
||||
HAWK_T("int"),
|
||||
HAWK_T("flt"),
|
||||
HAWK_T("str"),
|
||||
@ -1425,6 +1431,7 @@ const hawk_ooch_t* hawk_rtx_getvaltypename(hawk_rtx_t* rtx, hawk_val_t* val)
|
||||
HAWK_T("fun"),
|
||||
HAWK_T("map"),
|
||||
HAWK_T("array"),
|
||||
|
||||
HAWK_T("rex"),
|
||||
HAWK_T("ref")
|
||||
};
|
||||
|
@ -1,4 +1,5 @@
|
||||
@pragma entry main
|
||||
@pragma implicit off
|
||||
|
||||
@include "ensure.inc";
|
||||
|
||||
@ -22,6 +23,95 @@ function call_by_ref_3(&x)
|
||||
|
||||
function main()
|
||||
{
|
||||
|
||||
{
|
||||
ensure ((@nil == 'A'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((@nil != 'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((@nil > 'A'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((@nil < 'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((@nil >= 'A'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((@nil <= 'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
ensure ((@nil == @b'A'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((@nil != @b'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((@nil > @b'A'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((@nil < @b'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((@nil >= @b'A'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((@nil <= @b'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
ensure (('A' == @b'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure (('\u00FF' == @b'\xFF'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
ensure (("10" == 10), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure (("10" == 10.00), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure (("10.0" == 10), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure (("10.00" == 10), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
ensure ((@b"10" == 10), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((@b"10" == 10.00), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((@b"10.0" == 10), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((@b"10.00" == 10), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
ensure ((79 < '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((79 <= '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((79 > '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((79 >= '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((79 == '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((79 != '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
ensure ((99 < '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((99 <= '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((99 > '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((99 >= '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((99 == '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((99 != '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
ensure ((8 < '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8 <= '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8 > '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8 >= '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8 == '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8 != '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
ensure ((8.00 < '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8.00 <= '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8.00 > '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8.00 >= '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8.00 == '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8.00 != '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
ensure ((79 < @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((79 <= @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((79 > @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((79 >= @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((79 == @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((79 != @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
ensure ((99 < @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((99 <= @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((99 > @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((99 >= @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((99 == @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((99 != @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
ensure ((8 < @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8 <= @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8 > @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8 >= @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8 == @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8 != @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
ensure ((8.00 < @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8.00 <= @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8.00 > @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8.00 >= @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8.00 == @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure ((8.00 != @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
}
|
||||
|
||||
{
|
||||
@local x, y, z, r;
|
||||
|
||||
x = 20;
|
||||
y = 90;
|
||||
r = call_by_ref_1(x, y, z);
|
||||
@ -29,6 +119,7 @@ function main()
|
||||
ensure (x, 20);
|
||||
ensure (y, 90);
|
||||
ensure (z, "hello, world");
|
||||
}
|
||||
|
||||
## TODO: add a new special word, @FILENAME, @FILELINE, @LINE <--- which are understood by the parser and swapped to the actual value
|
||||
## @SCRIPTNAME, @SCRIPTLINE doesn't tell the main file.
|
||||
@ -40,7 +131,7 @@ function main()
|
||||
}
|
||||
|
||||
{
|
||||
@local b;
|
||||
@local b, r;
|
||||
b[1] = 1;
|
||||
r = call_by_ref_2(99, b);
|
||||
ensure (r, 99);
|
||||
@ -48,7 +139,7 @@ function main()
|
||||
}
|
||||
|
||||
{
|
||||
@local b;
|
||||
@local b, r;
|
||||
b[1] = 1;
|
||||
r = hawk::call("call_by_ref_2", 99, b);
|
||||
ensure (r, 99);
|
||||
@ -122,7 +213,7 @@ function main()
|
||||
}
|
||||
|
||||
{
|
||||
@local a, b;
|
||||
@local a, b, c;
|
||||
a = hawk::array();
|
||||
a[10][20][30] = 20;
|
||||
b[12][20][30] = 20;
|
||||
@ -141,6 +232,16 @@ function main()
|
||||
ensure (((10,30,30) in c), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
}
|
||||
|
||||
{
|
||||
@local a;
|
||||
a = hawk::array(1,2,3);
|
||||
ensure (a[1], 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure (a[2], 2, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure (a[3], 3, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure (length(a), 3, @SCRIPTNAME, @SCRIPTLINE);
|
||||
ensure (hawk::typename(a), "array", @SCRIPTNAME, @SCRIPTLINE);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
# concatenation operator
|
||||
|
@ -299,9 +299,9 @@ function main()
|
||||
|
||||
ensure (str::subchar(@b"abc", -1) === @nil, 1, @SCRIPTNAME, @SCRIPTNAME);
|
||||
ensure (str::subchar(@b"abc", 0) === @nil, 1, @SCRIPTNAME, @SCRIPTNAME);
|
||||
ensure (str::subchar(@b"abc", 1) === 'a', 1, @SCRIPTNAME, @SCRIPTNAME);
|
||||
ensure (str::subchar(@b"abc", 2) === 'b', 1, @SCRIPTNAME, @SCRIPTNAME);
|
||||
ensure (str::subchar(@b"abc", 3) === 'c', 1, @SCRIPTNAME, @SCRIPTNAME);
|
||||
ensure (str::subchar(@b"abc", 1) === @b'a', 1, @SCRIPTNAME, @SCRIPTNAME);
|
||||
ensure (str::subchar(@b"abc", 2) === @b'b', 1, @SCRIPTNAME, @SCRIPTNAME);
|
||||
ensure (str::subchar(@b"abc", 3) === @b'c', 1, @SCRIPTNAME, @SCRIPTNAME);
|
||||
ensure (str::subchar(@b"abc", 4) === @nil, 1, @SCRIPTNAME, @SCRIPTNAME);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user