added more code for bigint.
changed SMINT to SMOOI and renamed relevant macros accordingly
This commit is contained in:
parent
7b28bba988
commit
b0f8561238
@ -258,9 +258,13 @@ PROCESS TESTING
|
||||
"
|
||||
(-2305843009213693952 - 1) dump.
|
||||
|
||||
(1 + 2) dump.
|
||||
##(-2305843009213693952 * 2305843009213693952) dump.
|
||||
(((-2305843009213693952 - 10) * (-2305843009213693952 - 10) *(-2305843009213693952 - 10) * (-2305843009213693952 - 10) * 255) * ((-2305843009213693952 - 10) * (-2305843009213693952 - 10) *(-2305843009213693952 - 10) * (-2305843009213693952 - 10) * 255)) dump.
|
||||
##((-2305843009213693952 - 10) * (-2305843009213693952 - 10) *(-2305843009213693952 - 10) * (-2305843009213693952 - 10) * 255) dump.
|
||||
|
||||
##(-16rFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF * 1) dump.
|
||||
((-2305843009213693952 * -1) - 1 + 2) dump.
|
||||
"
|
||||
FFI isNil dump.
|
||||
FFI notNil dump.
|
||||
|
@ -156,6 +156,28 @@ static STIX_INLINE stix_oop_t make_bigint_with_ooi (stix_t* stix, stix_ooi_t i)
|
||||
#endif
|
||||
}
|
||||
|
||||
static STIX_INLINE stix_oop_t make_bigint_with_intmax (stix_t* stix, stix_intmax_t v)
|
||||
{
|
||||
/* this is not a generic function. it can't handle v
|
||||
* if it's STIX_TYPE_MIN(stix_intmax_t) */
|
||||
stix_oow_t len;
|
||||
atom_t buf[STIX_SIZEOF_INTMAX_T / SIZEOF_ATOM_T];
|
||||
stix_uintmax_t ui;
|
||||
|
||||
STIX_ASSERT (v > STIX_TYPE_MIN(stix_intmax_t));
|
||||
|
||||
ui = (v >= 0)? v: -v;
|
||||
len = 0;
|
||||
do
|
||||
{
|
||||
buf[len++] = (atom_t)ui;
|
||||
ui = ui >> ATOM_BITS;
|
||||
}
|
||||
while (ui > 0);
|
||||
|
||||
return stix_instantiate (stix, ((v >= 0)? stix->_large_positive_integer: stix->_large_negative_integer), buf, len);
|
||||
}
|
||||
|
||||
static STIX_INLINE stix_oop_t clone_bigint (stix_t* stix, stix_oop_t oop, stix_oow_t count)
|
||||
{
|
||||
stix_oop_t z;
|
||||
@ -176,6 +198,31 @@ static STIX_INLINE stix_oop_t clone_bigint (stix_t* stix, stix_oop_t oop, stix_o
|
||||
return z;
|
||||
}
|
||||
|
||||
static STIX_INLINE stix_oop_t clone_bigint_negated (stix_t* stix, stix_oop_t oop, stix_oow_t count)
|
||||
{
|
||||
stix_oop_t z, c;
|
||||
stix_oow_t i;
|
||||
|
||||
STIX_ASSERT (STIX_OOP_IS_POINTER(oop));
|
||||
if (count <= 0) count = STIX_OBJ_GET_SIZE(oop);
|
||||
|
||||
if (STIX_OBJ_GET_CLASS(oop) == stix->_large_positive_integer)
|
||||
c = stix->_large_negative_integer;
|
||||
else
|
||||
c = stix->_large_positive_integer;
|
||||
|
||||
stix_pushtmp (stix, &oop);
|
||||
z = stix_instantiate (stix, c, STIX_NULL, count);
|
||||
stix_poptmp (stix);
|
||||
if (!z) return STIX_NULL;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
((oop_atom_t)z)->slot[i] = ((oop_atom_t)oop)->slot[i];
|
||||
}
|
||||
return z;
|
||||
}
|
||||
|
||||
static STIX_INLINE stix_oow_t count_effective_digits (stix_oop_t oop)
|
||||
{
|
||||
stix_oow_t i;
|
||||
@ -204,13 +251,13 @@ static stix_oop_t normalize_bigint (stix_t* stix, stix_oop_t oop)
|
||||
w = ((oop_atom_t)oop)->slot[0];
|
||||
if (STIX_OBJ_GET_CLASS(oop) == stix->_large_positive_integer)
|
||||
{
|
||||
if (w <= STIX_SMINT_MAX) return STIX_OOP_FROM_SMINT(w);
|
||||
if (w <= STIX_SMOOI_MAX) return STIX_SMOOI_TO_OOP(w);
|
||||
}
|
||||
else
|
||||
{
|
||||
STIX_ASSERT (STIX_OBJ_GET_CLASS(oop) == stix->_large_negative_integer);
|
||||
/*if (w <= -STIX_SMINT_MIN) */
|
||||
if (w <= ((stix_oow_t)STIX_SMINT_MAX + 1)) return STIX_OOP_FROM_SMINT(-(stix_ooi_t)w);
|
||||
/*if (w <= -STIX_SMOOI_MIN) */
|
||||
if (w <= ((stix_oow_t)STIX_SMOOI_MAX + 1)) return STIX_SMOOI_TO_OOP(-(stix_ooi_t)w);
|
||||
}
|
||||
}
|
||||
#else
|
||||
@ -218,12 +265,12 @@ static stix_oop_t normalize_bigint (stix_t* stix, stix_oop_t oop)
|
||||
{
|
||||
if (STIX_OBJ_GET_CLASS(oop) == stix->_large_positive_integer)
|
||||
{
|
||||
return STIX_OOP_FROM_SMINT(((oop_atom_t)oop)->slot[0]);
|
||||
return STIX_SMOOI_TO_OOP(((oop_atom_t)oop)->slot[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
STIX_ASSERT (STIX_OBJ_GET_CLASS(oop) == stix->_large_negative_integer);
|
||||
return STIX_OOP_FROM_SMINT(-(stix_oow_t)((oop_atom_t)oop)->slot[0]);
|
||||
return STIX_SMOOI_TO_OOP(-(stix_oow_t)((oop_atom_t)oop)->slot[0]);
|
||||
}
|
||||
}
|
||||
else if (count == 2)
|
||||
@ -233,13 +280,13 @@ static stix_oop_t normalize_bigint (stix_t* stix, stix_oop_t oop)
|
||||
w = MAKE_WORD (((oop_atom_t)oop)->slot[0], ((oop_atom_t)oop)->slot[1]);
|
||||
if (STIX_OBJ_GET_CLASS(oop) == stix->_large_positive_integer)
|
||||
{
|
||||
if (w <= STIX_SMINT_MAX) return STIX_OOP_FROM_SMINT(w);
|
||||
if (w <= STIX_SMOOI_MAX) return STIX_SMOOI_TO_OOP(w);
|
||||
}
|
||||
else
|
||||
{
|
||||
STIX_ASSERT (STIX_OBJ_GET_CLASS(oop) == stix->_large_negative_integer);
|
||||
/*if (w <= -STIX_SMINT_MIN) */
|
||||
if (w <= ((stix_oow_t)STIX_SMINT_MAX + 1)) return STIX_OOP_FROM_SMINT(-(stix_ooi_t)w);
|
||||
/*if (w <= -STIX_SMOOI_MIN) */
|
||||
if (w <= ((stix_oow_t)STIX_SMOOI_MAX + 1)) return STIX_SMOOI_TO_OOP(-(stix_ooi_t)w);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -521,29 +568,30 @@ stix_oop_t stix_addints (stix_t* stix, stix_oop_t x, stix_oop_t y)
|
||||
{
|
||||
stix_oop_t z;
|
||||
|
||||
if (STIX_OOP_IS_SMINT(x) && STIX_OOP_IS_SMINT(y))
|
||||
if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y))
|
||||
{
|
||||
stix_ooi_t i;
|
||||
|
||||
/* no integer overflow/underflow must occur as the possible integer
|
||||
* range is narrowed by the tag bits used */
|
||||
i = STIX_OOP_TO_SMINT(x) + STIX_OOP_TO_SMINT(y);
|
||||
if (STIX_OOI_IN_SMINT_RANGE(i)) return STIX_OOP_FROM_SMINT(i);
|
||||
STIX_ASSERT (STIX_SMOOI_MAX + STIX_SMOOI_MAX < STIX_TYPE_MAX(stix_ooi_t));
|
||||
STIX_ASSERT (STIX_SMOOI_MIN + STIX_SMOOI_MIN > STIX_TYPE_MIN(stix_ooi_t));
|
||||
|
||||
i = STIX_OOP_TO_SMOOI(x) + STIX_OOP_TO_SMOOI(y);
|
||||
if (STIX_IN_SMOOI_RANGE(i)) return STIX_SMOOI_TO_OOP(i);
|
||||
|
||||
STIX_ASSERT (STIX_SMINT_MAX + STIX_SMINT_MAX < STIX_TYPE_MAX(stix_ooi_t));
|
||||
STIX_ASSERT (STIX_SMINT_MIN + STIX_SMINT_MIN > STIX_TYPE_MAX(stix_ooi_t));
|
||||
return make_bigint_with_ooi (stix, i);
|
||||
}
|
||||
else
|
||||
{
|
||||
stix_ooi_t v;
|
||||
int neg;
|
||||
|
||||
if (STIX_OOP_IS_SMINT(x))
|
||||
if (STIX_OOP_IS_SMOOI(x))
|
||||
{
|
||||
if (!is_integer(stix,y)) goto oops_einval;
|
||||
|
||||
v = STIX_OOP_TO_SMINT(x);
|
||||
if (v == 0) return y;
|
||||
v = STIX_OOP_TO_SMOOI(x);
|
||||
if (v == 0) return clone_bigint (stix, y, STIX_OBJ_GET_SIZE(y));
|
||||
|
||||
stix_pushtmp (stix, &y);
|
||||
x = make_bigint_with_ooi (stix, v);
|
||||
@ -551,12 +599,12 @@ stix_oop_t stix_addints (stix_t* stix, stix_oop_t x, stix_oop_t y)
|
||||
|
||||
if (!x) return STIX_NULL;
|
||||
}
|
||||
else if (STIX_OOP_IS_SMINT(y))
|
||||
else if (STIX_OOP_IS_SMOOI(y))
|
||||
{
|
||||
if (!is_integer(stix,x)) goto oops_einval;
|
||||
|
||||
v = STIX_OOP_TO_SMINT(y);
|
||||
if (v == 0) return x;
|
||||
v = STIX_OOP_TO_SMOOI(y);
|
||||
if (v == 0) return clone_bigint (stix, x, STIX_OBJ_GET_SIZE(x));
|
||||
|
||||
stix_pushtmp (stix, &x);
|
||||
y = make_bigint_with_ooi (stix, v);
|
||||
@ -586,6 +634,7 @@ stix_oop_t stix_addints (stix_t* stix, stix_oop_t x, stix_oop_t y)
|
||||
}
|
||||
else
|
||||
{
|
||||
int neg;
|
||||
/* both are positive or negative */
|
||||
neg = (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer);
|
||||
z = add_unsigned_integers (stix, x, y);
|
||||
@ -605,13 +654,17 @@ stix_oop_t stix_subints (stix_t* stix, stix_oop_t x, stix_oop_t y)
|
||||
{
|
||||
stix_oop_t z;
|
||||
|
||||
if (STIX_OOP_IS_SMINT(x) && STIX_OOP_IS_SMINT(y))
|
||||
if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y))
|
||||
{
|
||||
stix_ooi_t i;
|
||||
|
||||
/* no integer overflow/underflow must occur as the possible integer
|
||||
* range is narrowed by the tag bits used */
|
||||
i = STIX_OOP_TO_SMINT(x) - STIX_OOP_TO_SMINT(y);
|
||||
if (STIX_OOI_IN_SMINT_RANGE(i)) return STIX_OOP_FROM_SMINT(i);
|
||||
STIX_ASSERT (STIX_SMOOI_MAX - STIX_SMOOI_MIN < STIX_TYPE_MAX(stix_ooi_t));
|
||||
STIX_ASSERT (STIX_SMOOI_MIN - STIX_SMOOI_MAX > STIX_TYPE_MIN(stix_ooi_t));
|
||||
|
||||
i = STIX_OOP_TO_SMOOI(x) - STIX_OOP_TO_SMOOI(y);
|
||||
if (STIX_IN_SMOOI_RANGE(i)) return STIX_SMOOI_TO_OOP(i);
|
||||
|
||||
return make_bigint_with_ooi (stix, i);
|
||||
}
|
||||
@ -620,18 +673,15 @@ stix_oop_t stix_subints (stix_t* stix, stix_oop_t x, stix_oop_t y)
|
||||
stix_ooi_t v;
|
||||
int neg;
|
||||
|
||||
if (STIX_OOP_IS_SMINT(x))
|
||||
if (STIX_OOP_IS_SMOOI(x))
|
||||
{
|
||||
if (!is_integer(stix,y)) goto oops_einval;
|
||||
|
||||
v = STIX_OOP_TO_SMINT(x);
|
||||
v = STIX_OOP_TO_SMOOI(x);
|
||||
if (v == 0)
|
||||
{
|
||||
/* switch the sign to the opposite and return it */
|
||||
neg = (STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer);
|
||||
z = clone_bigint (stix, y, 0);
|
||||
if (!neg) STIX_OBJ_SET_CLASS(z, stix->_large_negative_integer);
|
||||
return z;
|
||||
return clone_bigint_negated (stix, y, STIX_OBJ_GET_SIZE(y));
|
||||
}
|
||||
|
||||
stix_pushtmp (stix, &y);
|
||||
@ -639,12 +689,12 @@ stix_oop_t stix_subints (stix_t* stix, stix_oop_t x, stix_oop_t y)
|
||||
if (!x) return STIX_NULL;
|
||||
stix_poptmp (stix);
|
||||
}
|
||||
else if (STIX_OOP_IS_SMINT(y))
|
||||
else if (STIX_OOP_IS_SMOOI(y))
|
||||
{
|
||||
if (!is_integer(stix,x)) goto oops_einval;
|
||||
|
||||
v = STIX_OOP_TO_SMINT(y);
|
||||
if (v == 0) return x;
|
||||
v = STIX_OOP_TO_SMOOI(y);
|
||||
if (v == 0) return clone_bigint (stix, x, STIX_OBJ_GET_SIZE(x));
|
||||
|
||||
stix_pushtmp (stix, &x);
|
||||
y = make_bigint_with_ooi (stix, v);
|
||||
@ -691,34 +741,45 @@ oops_einval:
|
||||
return STIX_NULL;
|
||||
}
|
||||
|
||||
|
||||
stix_oop_t stix_mulints (stix_t* stix, stix_oop_t x, stix_oop_t y)
|
||||
{
|
||||
stix_oop_t z;
|
||||
|
||||
if (STIX_OOP_IS_SMINT(x) && STIX_OOP_IS_SMINT(y))
|
||||
if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y))
|
||||
{
|
||||
/* TODO: XXXXXXXXXXXXXXXXXXXXXXXxx */
|
||||
stix_ooi_t i;
|
||||
/* no integer overflow/underflow must occur as the possible integer
|
||||
* range is narrowed by the tag bits used */
|
||||
i = STIX_OOP_TO_SMINT(x) * STIX_OOP_TO_SMINT(y);
|
||||
if (STIX_OOI_IN_SMINT_RANGE(i)) return STIX_OOP_FROM_SMINT(i);
|
||||
#if STIX_SIZEOF_INTMAX_T > STIX_SIZEOF_OOI_T
|
||||
stix_intmax_t i;
|
||||
|
||||
i = (stix_intmax_t)STIX_OOP_TO_SMOOI(x) * (stix_intmax_t)STIX_OOP_TO_SMOOI(y);
|
||||
if (STIX_IN_SMOOI_RANGE(i)) return STIX_SMOOI_TO_OOP((stix_ooi_t)i);
|
||||
|
||||
return make_bigint_with_intmax (stix, i);
|
||||
#else
|
||||
stix_ooi_t i;
|
||||
i = STIX_OOP_TO_SMOOI(x) * STIX_OOP_TO_SMOOI(y);
|
||||
if (STIX_IN_SMOOI_RANGE(i)) return STIX_SMOOI_TO_OOP(i);
|
||||
|
||||
STIX_ASSERT (STIX_SMINT_MAX + STIX_SMINT_MAX < STIX_TYPE_MAX(stix_ooi_t));
|
||||
STIX_ASSERT (STIX_SMINT_MIN + STIX_SMINT_MIN > STIX_TYPE_MAX(stix_ooi_t));
|
||||
return make_bigint_with_ooi (stix, i);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
stix_ooi_t v;
|
||||
|
||||
if (STIX_OOP_IS_SMINT(x))
|
||||
if (STIX_OOP_IS_SMOOI(x))
|
||||
{
|
||||
if (!is_integer(stix,y)) goto oops_einval;
|
||||
|
||||
v = STIX_OOP_TO_SMINT(x);
|
||||
if (v == 0) return STIX_OOP_FROM_SMINT(0);
|
||||
v = STIX_OOP_TO_SMOOI(x);
|
||||
switch (v)
|
||||
{
|
||||
case 0:
|
||||
return STIX_SMOOI_TO_OOP(0);
|
||||
case 1:
|
||||
return clone_bigint (stix, y, STIX_OBJ_GET_SIZE(y));
|
||||
case -1:
|
||||
return clone_bigint_negated (stix, y, STIX_OBJ_GET_SIZE(y));
|
||||
}
|
||||
|
||||
stix_pushtmp (stix, &y);
|
||||
x = make_bigint_with_ooi (stix, v);
|
||||
@ -726,12 +787,20 @@ stix_oop_t stix_mulints (stix_t* stix, stix_oop_t x, stix_oop_t y)
|
||||
|
||||
if (!x) return STIX_NULL;
|
||||
}
|
||||
else if (STIX_OOP_IS_SMINT(y))
|
||||
else if (STIX_OOP_IS_SMOOI(y))
|
||||
{
|
||||
if (!is_integer(stix,x)) goto oops_einval;
|
||||
|
||||
v = STIX_OOP_TO_SMINT(y);
|
||||
if (v == 0) return STIX_OOP_FROM_SMINT(0);
|
||||
v = STIX_OOP_TO_SMOOI(y);
|
||||
switch (v)
|
||||
{
|
||||
case 0:
|
||||
return STIX_SMOOI_TO_OOP(0);
|
||||
case 1:
|
||||
return clone_bigint (stix, x, STIX_OBJ_GET_SIZE(x));
|
||||
case -1:
|
||||
return clone_bigint_negated (stix, x, STIX_OBJ_GET_SIZE(x));
|
||||
}
|
||||
|
||||
stix_pushtmp (stix, &x);
|
||||
y = make_bigint_with_ooi (stix, v);
|
||||
@ -779,7 +848,7 @@ static stix_uint8_t ooch_val_tab[] =
|
||||
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 99, 99, 99, 99, 99
|
||||
};
|
||||
|
||||
stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len, unsigned int radix)
|
||||
stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len, int radix)
|
||||
{
|
||||
int neg = 0;
|
||||
const stix_ooch_t* ptr, * start, * end;
|
||||
@ -788,6 +857,12 @@ stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len,
|
||||
stix_oow_t hwlen, outlen;
|
||||
stix_oop_t res;
|
||||
|
||||
if (radix < 0)
|
||||
{
|
||||
neg = 1;
|
||||
radix = -radix;
|
||||
}
|
||||
|
||||
STIX_ASSERT (radix >= 2 && radix <= 36);
|
||||
|
||||
ptr = str;
|
||||
@ -813,7 +888,7 @@ stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len,
|
||||
if (ptr >= end)
|
||||
{
|
||||
/* all zeros */
|
||||
return STIX_OOP_FROM_SMINT(0);
|
||||
return STIX_SMOOI_TO_OOP(0);
|
||||
}
|
||||
|
||||
hwlen = 0;
|
||||
@ -979,32 +1054,32 @@ printf ("%08lx ", (unsigned long)hwp[--i]);
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
STIX_ASSERT (hwlen > 1);
|
||||
STIX_ASSERT (hwlen >= 1);
|
||||
#if defined(USE_FULL_WORD)
|
||||
if (hwlen == 1)
|
||||
{
|
||||
w = hwp[0];
|
||||
if (neg)
|
||||
{
|
||||
if (w <= STIX_SMINT_MAX + 1) return STIX_OOP_FROM_SMINT(-(stix_ooi_t)w);
|
||||
if (w <= STIX_SMOOI_MAX + 1) return STIX_SMOOI_TO_OOP(-(stix_ooi_t)w);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (w <= STIX_SMINT_MAX) return STIX_OOP_FROM_SMINT(w);
|
||||
if (w <= STIX_SMOOI_MAX) return STIX_SMOOI_TO_OOP(w);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (hwlen == 1) return STIX_OOP_FROM_SMINT((stix_ooi_t)hwp[0] * -neg);
|
||||
if (hwlen == 1) return STIX_SMOOI_TO_OOP((stix_ooi_t)hwp[0] * -neg);
|
||||
else if (hwlen == 2)
|
||||
{
|
||||
w = MAKE_WORD(hwp[0], hwp[1]);
|
||||
if (neg)
|
||||
{
|
||||
if (w <= STIX_SMINT_MAX + 1) return STIX_OOP_FROM_SMINT(-(stix_ooi_t)w);
|
||||
if (w <= STIX_SMOOI_MAX + 1) return STIX_SMOOI_TO_OOP(-(stix_ooi_t)w);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (w <= STIX_SMINT_MAX) return STIX_OOP_FROM_SMINT(w);
|
||||
if (w <= STIX_SMOOI_MAX) return STIX_SMOOI_TO_OOP(w);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
106
stix/lib/comp.c
106
stix/lib/comp.c
@ -467,8 +467,8 @@ static int string_to_smint (stix_t* stix, stix_oocs_t* str, int radixed, stix_oo
|
||||
|
||||
if (negsign)
|
||||
{
|
||||
/*if (value > -STIX_SMINT_MIN) */
|
||||
if (value > ((stix_oow_t)STIX_SMINT_MAX + 1))
|
||||
/*if (value > -STIX_SMOOI_MIN) */
|
||||
if (value > ((stix_oow_t)STIX_SMOOI_MAX + 1))
|
||||
{
|
||||
stix->errnum = STIX_ERANGE;
|
||||
return -1;
|
||||
@ -478,7 +478,7 @@ static int string_to_smint (stix_t* stix, stix_oocs_t* str, int radixed, stix_oo
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value > STIX_SMINT_MAX)
|
||||
if (value > STIX_SMOOI_MAX)
|
||||
{
|
||||
stix->errnum = STIX_ERANGE;
|
||||
return -1;
|
||||
@ -489,6 +489,44 @@ static int string_to_smint (stix_t* stix, stix_oocs_t* str, int radixed, stix_oo
|
||||
return 0;
|
||||
}
|
||||
|
||||
static stix_oop_t string_to_num (stix_t* stix, stix_oocs_t* str, int radixed)
|
||||
{
|
||||
int negsign, base;
|
||||
const stix_ooch_t* ptr, * end;
|
||||
|
||||
negsign = 0;
|
||||
ptr = str->ptr,
|
||||
end = str->ptr + str->len;
|
||||
|
||||
STIX_ASSERT (ptr < end);
|
||||
|
||||
if (*ptr == '+' || *ptr == '-')
|
||||
{
|
||||
negsign = *ptr - '+';
|
||||
ptr++;
|
||||
}
|
||||
|
||||
if (radixed)
|
||||
{
|
||||
STIX_ASSERT (ptr < end);
|
||||
|
||||
base = 0;
|
||||
do
|
||||
{
|
||||
base = base * 10 + CHAR_TO_NUM(*ptr, 10);
|
||||
ptr++;
|
||||
}
|
||||
while (*ptr != 'r');
|
||||
|
||||
ptr++;
|
||||
}
|
||||
else base = 10;
|
||||
|
||||
/* TODO: handle floating point numbers ... etc */
|
||||
if (negsign) base = -base;
|
||||
return stix_strtoint (stix, ptr, end - ptr, base);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* Tokenizer
|
||||
* --------------------------------------------------------------------- */
|
||||
@ -1761,7 +1799,7 @@ static int emit_push_smint_literal (stix_t* stix, stix_ooi_t i)
|
||||
return emit_single_param_instruction(stix, BCODE_PUSH_NEGINTLIT, -i);
|
||||
}
|
||||
|
||||
if (add_literal(stix, STIX_OOP_FROM_SMINT(i), &index) <= -1 ||
|
||||
if (add_literal(stix, STIX_SMOOI_TO_OOP(i), &index) <= -1 ||
|
||||
emit_single_param_instruction(stix, BCODE_PUSH_LITERAL_0, index) <= -1) return -1;
|
||||
|
||||
return 0;
|
||||
@ -2021,7 +2059,7 @@ done:
|
||||
* accumulated for inheritance. the position found in the
|
||||
* local variable string can be adjusted by adding the
|
||||
* number in the superclass */
|
||||
spec = STIX_OOP_TO_SMINT(((stix_oop_class_t)super)->spec);
|
||||
spec = STIX_OOP_TO_SMOOI(((stix_oop_class_t)super)->spec);
|
||||
pos += STIX_CLASS_SPEC_NAMED_INSTVAR(spec);
|
||||
break;
|
||||
|
||||
@ -2036,7 +2074,7 @@ done:
|
||||
break;
|
||||
|
||||
case VAR_CLASSINST:
|
||||
spec = STIX_OOP_TO_SMINT(((stix_oop_class_t)super)->selfspec);
|
||||
spec = STIX_OOP_TO_SMOOI(((stix_oop_class_t)super)->selfspec);
|
||||
pos += STIX_CLASS_SELFSPEC_CLASSINSTVAR(spec);
|
||||
break;
|
||||
}
|
||||
@ -2741,7 +2779,7 @@ printf ("\n");
|
||||
/* increment the position by the number of class instance variables
|
||||
* as the class variables are placed after the class instance variables */
|
||||
var->pos += STIX_CLASS_NAMED_INSTVARS +
|
||||
STIX_CLASS_SELFSPEC_CLASSINSTVAR(STIX_OOP_TO_SMINT(var->cls->selfspec));
|
||||
STIX_CLASS_SELFSPEC_CLASSINSTVAR(STIX_OOP_TO_SMOOI(var->cls->selfspec));
|
||||
break;
|
||||
|
||||
case VAR_CLASSINST:
|
||||
@ -3198,7 +3236,7 @@ printf ("LARGE NOT IMPLEMENTED IN COMPILE_ARRAY_LITERAL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
lit = STIX_OOP_FROM_SMINT(tmp);
|
||||
lit = STIX_SMOOI_TO_OOP(tmp);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -3491,6 +3529,7 @@ printf ("\tpush symbol literal %d\n", (int)index);
|
||||
case STIX_IOTOK_RADNUMLIT:
|
||||
{
|
||||
/* TODO: other types of numbers, negative numbers, etc */
|
||||
#if 0
|
||||
/* TODO: proper numbeic literal handling */
|
||||
stix_ooi_t tmp;
|
||||
|
||||
@ -3509,6 +3548,23 @@ printf ("NOT IMPLEMENTED LARGE_INTEGER or ERROR?\n");
|
||||
printf ("\tpush int literal\n");
|
||||
if (emit_push_smint_literal(stix, tmp) <= -1) return -1;
|
||||
}
|
||||
#else
|
||||
|
||||
stix_oop_t tmp;
|
||||
tmp = string_to_num (stix, &stix->c->tok.name, stix->c->tok.type == STIX_IOTOK_RADNUMLIT);
|
||||
if (!tmp) return -1;
|
||||
|
||||
if (STIX_OOP_IS_SMOOI(tmp))
|
||||
{
|
||||
printf ("\tpush int literal\n");
|
||||
if (emit_push_smint_literal(stix, STIX_OOP_TO_SMOOI(tmp)) <= -1) return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (add_literal(stix, tmp, &index) <= -1 ||
|
||||
emit_single_param_instruction(stix, BCODE_PUSH_LITERAL_0, index) <= -1) return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
GET_TOKEN (stix);
|
||||
break;
|
||||
@ -4225,11 +4281,11 @@ static int add_compiled_method (stix_t* stix)
|
||||
STIX_ASSERT (STIX_OOI_IN_PREAMBLE_INDEX_RANGE(preamble_index));
|
||||
|
||||
mth->owner = stix->c->cls.self_oop;
|
||||
mth->preamble = STIX_OOP_FROM_SMINT(STIX_METHOD_MAKE_PREAMBLE(preamble_code, preamble_index));
|
||||
mth->preamble_data[0] = STIX_OOP_FROM_SMINT(0);
|
||||
mth->preamble_data[1] = STIX_OOP_FROM_SMINT(0);
|
||||
mth->tmpr_count = STIX_OOP_FROM_SMINT(stix->c->mth.tmpr_count);
|
||||
mth->tmpr_nargs = STIX_OOP_FROM_SMINT(stix->c->mth.tmpr_nargs);
|
||||
mth->preamble = STIX_SMOOI_TO_OOP(STIX_METHOD_MAKE_PREAMBLE(preamble_code, preamble_index));
|
||||
mth->preamble_data[0] = STIX_SMOOI_TO_OOP(0);
|
||||
mth->preamble_data[1] = STIX_SMOOI_TO_OOP(0);
|
||||
mth->tmpr_count = STIX_SMOOI_TO_OOP(stix->c->mth.tmpr_count);
|
||||
mth->tmpr_nargs = STIX_SMOOI_TO_OOP(stix->c->mth.tmpr_nargs);
|
||||
|
||||
#if defined(STIX_USE_OBJECT_TRAILER)
|
||||
/* do nothing */
|
||||
@ -4354,14 +4410,14 @@ printf (" instvars %d classvars %d classinstvars %d\n", (int)stix->c->cls.var_co
|
||||
STIX_ASSERT (STIX_CLASSOF(stix, stix->c->cls.self_oop) == stix->_class);
|
||||
STIX_ASSERT (STIX_OBJ_GET_FLAGS_KERNEL (stix->c->cls.self_oop) == 1);
|
||||
|
||||
if (spec != STIX_OOP_TO_SMINT(stix->c->cls.self_oop->spec) ||
|
||||
self_spec != STIX_OOP_TO_SMINT(stix->c->cls.self_oop->selfspec))
|
||||
if (spec != STIX_OOP_TO_SMOOI(stix->c->cls.self_oop->spec) ||
|
||||
self_spec != STIX_OOP_TO_SMOOI(stix->c->cls.self_oop->selfspec))
|
||||
{
|
||||
/* it conflicts with internal definition */
|
||||
#if 0
|
||||
printf (" CONFLICTING CLASS DEFINITION %lu %lu %lu %lu\n",
|
||||
(unsigned long)spec, (unsigned long)self_spec,
|
||||
(unsigned long)STIX_OOP_TO_SMINT(stix->c->cls.self_oop->spec), (unsigned long)STIX_OOP_TO_SMINT(stix->c->cls.self_oop->selfspec)
|
||||
(unsigned long)STIX_OOP_TO_SMOOI(stix->c->cls.self_oop->spec), (unsigned long)STIX_OOP_TO_SMOOI(stix->c->cls.self_oop->selfspec)
|
||||
);
|
||||
#endif
|
||||
set_syntax_error (stix, STIX_SYNERR_CLASSCONTRA, &stix->c->cls.fqn_loc, &stix->c->cls.name);
|
||||
@ -4381,8 +4437,8 @@ printf (" CONFLICTING CLASS DEFINITION %lu %lu %lu %lu\n",
|
||||
|
||||
STIX_ASSERT (STIX_CLASSOF(stix, stix->c->cls.self_oop) == stix->_class);
|
||||
|
||||
stix->c->cls.self_oop->spec = STIX_OOP_FROM_SMINT(spec);
|
||||
stix->c->cls.self_oop->selfspec = STIX_OOP_FROM_SMINT(self_spec);
|
||||
stix->c->cls.self_oop->spec = STIX_SMOOI_TO_OOP(spec);
|
||||
stix->c->cls.self_oop->selfspec = STIX_SMOOI_TO_OOP(self_spec);
|
||||
}
|
||||
|
||||
/* TODO: check if the current class definition conflicts with the superclass.
|
||||
@ -4681,8 +4737,8 @@ printf ("\n");
|
||||
stix_oow_t spec, self_spec;
|
||||
|
||||
c = (stix_oop_class_t)stix->c->cls.super_oop;
|
||||
spec = STIX_OOP_TO_SMINT(c->spec);
|
||||
self_spec = STIX_OOP_TO_SMINT(c->selfspec);
|
||||
spec = STIX_OOP_TO_SMOOI(c->spec);
|
||||
self_spec = STIX_OOP_TO_SMOOI(c->selfspec);
|
||||
stix->c->cls.var_count[VAR_INSTANCE] = STIX_CLASS_SPEC_NAMED_INSTVAR(spec);
|
||||
stix->c->cls.var_count[VAR_CLASSINST] = STIX_CLASS_SELFSPEC_CLASSINSTVAR(self_spec);
|
||||
}
|
||||
@ -4888,6 +4944,7 @@ printf ("\n");
|
||||
case STIX_IOTOK_NUMLIT:
|
||||
case STIX_IOTOK_RADNUMLIT:
|
||||
{
|
||||
#if 0
|
||||
stix_ooi_t tmp;
|
||||
|
||||
if (string_to_smint(stix, &stix->c->tok.name, stix->c->tok.type == STIX_IOTOK_RADNUMLIT, &tmp) <= -1)
|
||||
@ -4902,9 +4959,12 @@ printf ("NOT IMPLEMENTED LARGE_INTEGER or ERROR?\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
lit = STIX_OOP_FROM_SMINT(tmp);
|
||||
lit = STIX_SMOOI_TO_OOP(tmp);
|
||||
}
|
||||
|
||||
#else
|
||||
lit = string_to_num (stix, &stix->c->tok.name, stix->c->tok.type == STIX_IOTOK_RADNUMLIT);
|
||||
if (!lit) return -1;
|
||||
#endif
|
||||
goto add_literal;
|
||||
}
|
||||
|
||||
@ -4951,7 +5011,7 @@ printf ("NOT IMPLEMENTED LARGE_INTEGER or ERROR?\n");
|
||||
|
||||
tally = stix->c->mth.arlit_count / 2;
|
||||
/*TODO: tally and arlit_count range check */
|
||||
/*if (!STIX_OOI_IN_SMINT_RANGE(tally)) ERROR??*/
|
||||
/*if (!STIX_IN_SMOOI_RANGE(tally)) ERROR??*/
|
||||
|
||||
stix->c->cls.mthdic_oop[0] = stix_makedic (stix, stix->_pool_dictionary, STIX_ALIGN(tally + 10, POOL_DICTIONARY_SIZE_ALIGN));
|
||||
if (!stix->c->cls.mthdic_oop[0]) return -1;
|
||||
|
@ -97,9 +97,9 @@ void print_object (stix_t* stix, stix_oop_t oop)
|
||||
{
|
||||
printf ("false");
|
||||
}
|
||||
else if (STIX_OOP_IS_SMINT(oop))
|
||||
else if (STIX_OOP_IS_SMOOI(oop))
|
||||
{
|
||||
printf ("%ld", (long int)STIX_OOP_TO_SMINT(oop));
|
||||
printf ("%ld", (long int)STIX_OOP_TO_SMOOI(oop));
|
||||
}
|
||||
else if (STIX_OOP_IS_CHAR(oop))
|
||||
{
|
||||
@ -209,9 +209,9 @@ static void __dump_object (stix_t* stix, stix_oop_t oop, int depth)
|
||||
{
|
||||
printf (" false");
|
||||
}
|
||||
else if (STIX_OOP_IS_SMINT(oop))
|
||||
else if (STIX_OOP_IS_SMOOI(oop))
|
||||
{
|
||||
printf (" %ld", (long int)STIX_OOP_TO_SMINT(oop));
|
||||
printf (" %ld", (long int)STIX_OOP_TO_SMOOI(oop));
|
||||
}
|
||||
else if (STIX_OOP_IS_CHAR(oop))
|
||||
{
|
||||
|
@ -105,7 +105,7 @@ static stix_oop_association_t find_or_upsert (stix_t* stix, stix_oop_set_t dic,
|
||||
stix_pushtmp (stix, (stix_oop_t*)&key); tmp_count++;
|
||||
stix_pushtmp (stix, &value); tmp_count++;
|
||||
|
||||
tally = STIX_OOP_TO_SMINT(dic->tally);
|
||||
tally = STIX_OOP_TO_SMOOI(dic->tally);
|
||||
if (tally + 1 >= STIX_OBJ_GET_SIZE(dic->bucket))
|
||||
{
|
||||
stix_oop_oop_t bucket;
|
||||
@ -138,8 +138,8 @@ static stix_oop_association_t find_or_upsert (stix_t* stix, stix_oop_set_t dic,
|
||||
ass->key = (stix_oop_t)key;
|
||||
ass->value = value;
|
||||
|
||||
STIX_ASSERT (tally < STIX_SMINT_MAX);
|
||||
dic->tally = STIX_OOP_FROM_SMINT(tally + 1);
|
||||
STIX_ASSERT (tally < STIX_SMOOI_MAX);
|
||||
dic->tally = STIX_SMOOI_TO_OOP(tally + 1);
|
||||
dic->bucket->slot[index] = (stix_oop_t)ass;
|
||||
|
||||
stix_poptmps (stix, tmp_count);
|
||||
@ -235,7 +235,7 @@ stix_oop_set_t stix_makedic (stix_t* stix, stix_oop_t cls, stix_oow_t size)
|
||||
stix_poptmp (stix);
|
||||
if (!tmp) return STIX_NULL;
|
||||
|
||||
dic->tally = STIX_OOP_FROM_SMINT(0);
|
||||
dic->tally = STIX_SMOOI_TO_OOP(0);
|
||||
dic->bucket = (stix_oop_oop_t)tmp;
|
||||
|
||||
STIX_ASSERT (STIX_OBJ_GET_SIZE(dic) == STIX_SET_NAMED_INSTVARS);
|
||||
|
194
stix/lib/exec.c
194
stix/lib/exec.c
@ -35,11 +35,11 @@
|
||||
/* TOOD: determine the right stack size */
|
||||
#define CONTEXT_STACK_SIZE 96
|
||||
|
||||
#define LOAD_IP(stix, v_ctx) ((stix)->ip = STIX_OOP_TO_SMINT((v_ctx)->ip))
|
||||
#define STORE_IP(stix, v_ctx) ((v_ctx)->ip = STIX_OOP_FROM_SMINT((stix)->ip))
|
||||
#define LOAD_IP(stix, v_ctx) ((stix)->ip = STIX_OOP_TO_SMOOI((v_ctx)->ip))
|
||||
#define STORE_IP(stix, v_ctx) ((v_ctx)->ip = STIX_SMOOI_TO_OOP((stix)->ip))
|
||||
|
||||
#define LOAD_SP(stix, v_ctx) ((stix)->sp = STIX_OOP_TO_SMINT((v_ctx)->sp))
|
||||
#define STORE_SP(stix, v_ctx) ((v_ctx)->sp = STIX_OOP_FROM_SMINT((stix)->sp))
|
||||
#define LOAD_SP(stix, v_ctx) ((stix)->sp = STIX_OOP_TO_SMOOI((v_ctx)->sp))
|
||||
#define STORE_SP(stix, v_ctx) ((v_ctx)->sp = STIX_SMOOI_TO_OOP((stix)->sp))
|
||||
|
||||
#define LOAD_ACTIVE_IP(stix) LOAD_IP(stix, (stix)->active_context)
|
||||
#define STORE_ACTIVE_IP(stix) STORE_IP(stix, (stix)->active_context)
|
||||
@ -112,7 +112,7 @@ static stix_oop_process_t make_process (stix_t* stix, stix_oop_context_t c)
|
||||
stix_poptmp (stix);
|
||||
if (!proc) return STIX_NULL;
|
||||
|
||||
proc->state = STIX_OOP_FROM_SMINT(0);
|
||||
proc->state = STIX_SMOOI_TO_OOP(0);
|
||||
proc->initial_context = c;
|
||||
|
||||
return proc;
|
||||
@ -151,18 +151,18 @@ static void switch_to_next_process (stix_t* stix)
|
||||
|
||||
static void schedule_process (stix_t* stix, stix_oop_process_t proc)
|
||||
{
|
||||
if (proc->state == STIX_OOP_FROM_SMINT(0))
|
||||
if (proc->state == STIX_SMOOI_TO_OOP(0))
|
||||
{
|
||||
stix_ooi_t tally;
|
||||
STIX_ASSERT ((stix_oop_t)proc->prev == stix->_nil);
|
||||
STIX_ASSERT ((stix_oop_t)proc->next == stix->_nil);
|
||||
|
||||
tally = STIX_OOP_TO_SMINT(stix->processor->tally);
|
||||
tally = STIX_OOP_TO_SMOOI(stix->processor->tally);
|
||||
if (tally <= 0)
|
||||
{
|
||||
stix->processor->head = proc;
|
||||
stix->processor->tail = proc;
|
||||
stix->processor->tally = STIX_OOP_FROM_SMINT(1);
|
||||
stix->processor->tally = STIX_SMOOI_TO_OOP(1);
|
||||
printf ("ADD NEW PROCESS X - %d\n", (int)1);
|
||||
}
|
||||
else
|
||||
@ -171,11 +171,11 @@ printf ("ADD NEW PROCESS X - %d\n", (int)1);
|
||||
proc->next = stix->processor->head;
|
||||
stix->processor->head->prev = proc;
|
||||
stix->processor->head = proc;
|
||||
stix->processor->tally = STIX_OOP_FROM_SMINT(tally + 1);
|
||||
stix->processor->tally = STIX_SMOOI_TO_OOP(tally + 1);
|
||||
printf ("ADD NEW PROCESS Y - %d\n", (int)tally + 1);
|
||||
}
|
||||
|
||||
proc->state = STIX_OOP_FROM_SMINT(1); /* TODO: change the code properly... changing state alone doesn't help */
|
||||
proc->state = STIX_SMOOI_TO_OOP(1); /* TODO: change the code properly... changing state alone doesn't help */
|
||||
proc->active_context = proc->initial_context;
|
||||
|
||||
switch_process (stix, proc);
|
||||
@ -226,8 +226,8 @@ static STIX_INLINE int activate_new_method (stix_t* stix, stix_oop_method_t mth)
|
||||
* | | slot[stack_size - 1]
|
||||
* +---------------------+
|
||||
*/
|
||||
ntmprs = STIX_OOP_TO_SMINT(mth->tmpr_count);
|
||||
nargs = STIX_OOP_TO_SMINT(mth->tmpr_nargs);
|
||||
ntmprs = STIX_OOP_TO_SMOOI(mth->tmpr_count);
|
||||
nargs = STIX_OOP_TO_SMOOI(mth->tmpr_nargs);
|
||||
|
||||
STIX_ASSERT (ntmprs >= 0);
|
||||
STIX_ASSERT (nargs <= ntmprs);
|
||||
@ -240,7 +240,7 @@ static STIX_INLINE int activate_new_method (stix_t* stix, stix_oop_method_t mth)
|
||||
if (!ctx) return -1;
|
||||
|
||||
ctx->sender = (stix_oop_t)stix->active_context;
|
||||
ctx->ip = STIX_OOP_FROM_SMINT(0);
|
||||
ctx->ip = STIX_SMOOI_TO_OOP(0);
|
||||
/* the stack front has temporary variables including arguments.
|
||||
*
|
||||
* New Context
|
||||
@ -263,8 +263,8 @@ static STIX_INLINE int activate_new_method (stix_t* stix, stix_oop_method_t mth)
|
||||
*
|
||||
* if no temporaries exist, the initial sp is -1.
|
||||
*/
|
||||
ctx->sp = STIX_OOP_FROM_SMINT(ntmprs - 1);
|
||||
ctx->ntmprs = STIX_OOP_FROM_SMINT(ntmprs);
|
||||
ctx->sp = STIX_SMOOI_TO_OOP(ntmprs - 1);
|
||||
ctx->ntmprs = STIX_SMOOI_TO_OOP(ntmprs);
|
||||
ctx->method_or_nargs = (stix_oop_t)mth;
|
||||
/* the 'home' field of a method context is always stix->_nil.
|
||||
ctx->home = stix->_nil;*/
|
||||
@ -337,7 +337,7 @@ printf ("\n");
|
||||
ctx->sender =
|
||||
*/
|
||||
|
||||
ctx->ntmprs = STIX_OOP_FROM_SMINT(ntmprs);
|
||||
ctx->ntmprs = STIX_SMOOI_TO_OOP(ntmprs);
|
||||
ctx->method_or_nargs = (stix_oop_t)mth;
|
||||
ctx->home = stix->_nil;
|
||||
ctx->origin = ctx;
|
||||
@ -446,7 +446,7 @@ static int activate_initial_context (stix_t* stix, const stix_oocs_t* objname, c
|
||||
mth = find_method (stix, ass->value, mthname, 0);
|
||||
if (!mth) return -1;
|
||||
|
||||
if (STIX_OOP_TO_SMINT(mth->tmpr_nargs) > 0)
|
||||
if (STIX_OOP_TO_SMOOI(mth->tmpr_nargs) > 0)
|
||||
{
|
||||
/* this method expects more than 0 arguments.
|
||||
* i can't use it as a start-up method.
|
||||
@ -593,9 +593,9 @@ static int prim_basic_new_with_size (stix_t* stix, stix_ooi_t nargs)
|
||||
}
|
||||
|
||||
szoop = ACTIVE_STACK_GET(stix, stix->sp);
|
||||
if (STIX_OOP_IS_SMINT(szoop))
|
||||
if (STIX_OOP_IS_SMOOI(szoop))
|
||||
{
|
||||
size = STIX_OOP_TO_SMINT(szoop);
|
||||
size = STIX_OOP_TO_SMOOI(szoop);
|
||||
}
|
||||
/* TODO: support LargeInteger */
|
||||
else
|
||||
@ -644,7 +644,7 @@ static int prim_basic_size (stix_t* stix, stix_ooi_t nargs)
|
||||
STIX_ASSERT (nargs == 0);
|
||||
|
||||
rcv = ACTIVE_STACK_GETTOP(stix);
|
||||
ACTIVE_STACK_SETTOP(stix, STIX_OOP_FROM_SMINT(STIX_OBJ_GET_SIZE(rcv)));
|
||||
ACTIVE_STACK_SETTOP(stix, STIX_SMOOI_TO_OOP(STIX_OBJ_GET_SIZE(rcv)));
|
||||
/* TODO: use LargeInteger if the size is very big */
|
||||
return 1;
|
||||
}
|
||||
@ -664,14 +664,14 @@ static int prim_basic_at (stix_t* stix, stix_ooi_t nargs)
|
||||
}
|
||||
|
||||
pos = ACTIVE_STACK_GET(stix, stix->sp);
|
||||
if (!STIX_OOP_IS_SMINT(pos))
|
||||
if (!STIX_OOP_IS_SMOOI(pos))
|
||||
{
|
||||
/* TODO: handle LargeInteger */
|
||||
/* the position must be an integer */
|
||||
return 0;
|
||||
}
|
||||
|
||||
idx = STIX_OOP_TO_SMINT(pos);
|
||||
idx = STIX_OOP_TO_SMOOI(pos);
|
||||
if (idx < 1 || idx > STIX_OBJ_GET_SIZE(rcv))
|
||||
{
|
||||
/* index out of range */
|
||||
@ -684,7 +684,7 @@ static int prim_basic_at (stix_t* stix, stix_ooi_t nargs)
|
||||
switch (STIX_OBJ_GET_FLAGS_TYPE(rcv))
|
||||
{
|
||||
case STIX_OBJ_TYPE_BYTE:
|
||||
v = STIX_OOP_FROM_SMINT(((stix_oop_byte_t)rcv)->slot[idx]);
|
||||
v = STIX_SMOOI_TO_OOP(((stix_oop_byte_t)rcv)->slot[idx]);
|
||||
break;
|
||||
|
||||
case STIX_OBJ_TYPE_CHAR:
|
||||
@ -693,12 +693,12 @@ static int prim_basic_at (stix_t* stix, stix_ooi_t nargs)
|
||||
|
||||
case STIX_OBJ_TYPE_HALFWORD:
|
||||
/* TODO: LargeInteger if the halfword is too large */
|
||||
v = STIX_OOP_FROM_SMINT(((stix_oop_halfword_t)rcv)->slot[idx]);
|
||||
v = STIX_SMOOI_TO_OOP(((stix_oop_halfword_t)rcv)->slot[idx]);
|
||||
break;
|
||||
|
||||
case STIX_OBJ_TYPE_WORD:
|
||||
/* TODO: LargeInteger if the word is too large */
|
||||
v = STIX_OOP_FROM_SMINT(((stix_oop_word_t)rcv)->slot[idx]);
|
||||
v = STIX_SMOOI_TO_OOP(((stix_oop_word_t)rcv)->slot[idx]);
|
||||
break;
|
||||
|
||||
case STIX_OBJ_TYPE_OOP:
|
||||
@ -730,7 +730,7 @@ static int prim_basic_at_put (stix_t* stix, stix_ooi_t nargs)
|
||||
}
|
||||
|
||||
pos = ACTIVE_STACK_GET(stix, stix->sp - 1);
|
||||
if (!STIX_OOP_IS_SMINT(pos))
|
||||
if (!STIX_OOP_IS_SMOOI(pos))
|
||||
{
|
||||
/* TODO: handle LargeInteger */
|
||||
/* the position must be an integer */
|
||||
@ -739,7 +739,7 @@ static int prim_basic_at_put (stix_t* stix, stix_ooi_t nargs)
|
||||
|
||||
val = ACTIVE_STACK_GET(stix, stix->sp);
|
||||
|
||||
idx = STIX_OOP_TO_SMINT(pos);
|
||||
idx = STIX_OOP_TO_SMOOI(pos);
|
||||
if (idx < 1 || idx > STIX_OBJ_GET_SIZE(rcv))
|
||||
{
|
||||
/* index out of range */
|
||||
@ -760,13 +760,13 @@ static int prim_basic_at_put (stix_t* stix, stix_ooi_t nargs)
|
||||
switch (STIX_OBJ_GET_FLAGS_TYPE(rcv))
|
||||
{
|
||||
case STIX_OBJ_TYPE_BYTE:
|
||||
if (!STIX_OOP_IS_SMINT(val))
|
||||
if (!STIX_OOP_IS_SMOOI(val))
|
||||
{
|
||||
/* the value is not a character */
|
||||
return 0;
|
||||
}
|
||||
/* TOOD: must I check the range of the value? */
|
||||
((stix_oop_char_t)rcv)->slot[idx] = STIX_OOP_TO_SMINT(val);
|
||||
((stix_oop_char_t)rcv)->slot[idx] = STIX_OOP_TO_SMOOI(val);
|
||||
break;
|
||||
|
||||
case STIX_OBJ_TYPE_CHAR:
|
||||
@ -779,24 +779,24 @@ static int prim_basic_at_put (stix_t* stix, stix_ooi_t nargs)
|
||||
break;
|
||||
|
||||
case STIX_OBJ_TYPE_HALFWORD:
|
||||
if (!STIX_OOP_IS_SMINT(val))
|
||||
if (!STIX_OOP_IS_SMOOI(val))
|
||||
{
|
||||
/* the value is not a number */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* if the small integer is too large, it will get truncated */
|
||||
((stix_oop_halfword_t)rcv)->slot[idx] = STIX_OOP_TO_SMINT(val);
|
||||
((stix_oop_halfword_t)rcv)->slot[idx] = STIX_OOP_TO_SMOOI(val);
|
||||
break;
|
||||
|
||||
case STIX_OBJ_TYPE_WORD:
|
||||
/* TODO: handle largeINteger */
|
||||
if (!STIX_OOP_IS_SMINT(val))
|
||||
if (!STIX_OOP_IS_SMOOI(val))
|
||||
{
|
||||
/* the value is not a number */
|
||||
return 0;
|
||||
}
|
||||
((stix_oop_word_t)rcv)->slot[idx] = STIX_OOP_TO_SMINT(val);
|
||||
((stix_oop_word_t)rcv)->slot[idx] = STIX_OOP_TO_SMOOI(val);
|
||||
break;
|
||||
|
||||
case STIX_OBJ_TYPE_OOP:
|
||||
@ -857,7 +857,7 @@ printf ("PRIM REVALUING AN BLOCKCONTEXT\n");
|
||||
}
|
||||
STIX_ASSERT (STIX_OBJ_GET_SIZE(org_blkctx) == STIX_CONTEXT_NAMED_INSTVARS);
|
||||
|
||||
if (STIX_OOP_TO_SMINT(org_blkctx->method_or_nargs) != actual_arg_count /* nargs */)
|
||||
if (STIX_OOP_TO_SMOOI(org_blkctx->method_or_nargs) != actual_arg_count /* nargs */)
|
||||
{
|
||||
/* the number of argument doesn't match */
|
||||
#if defined(STIX_DEBUG_EXEC)
|
||||
@ -922,11 +922,11 @@ printf ("~~~~~~~~~~ BLOCK VALUING %p TO NEW BLOCK %p\n", org_blkctx, blkctx);
|
||||
/* the number of temporaries stored in the block context
|
||||
* accumulates the number of temporaries starting from the origin.
|
||||
* simple calculation is needed to find the number of local temporaries */
|
||||
local_ntmprs = STIX_OOP_TO_SMINT(blkctx->ntmprs) -
|
||||
STIX_OOP_TO_SMINT(((stix_oop_context_t)blkctx->home)->ntmprs);
|
||||
local_ntmprs = STIX_OOP_TO_SMOOI(blkctx->ntmprs) -
|
||||
STIX_OOP_TO_SMOOI(((stix_oop_context_t)blkctx->home)->ntmprs);
|
||||
STIX_ASSERT (local_ntmprs >= nargs);
|
||||
|
||||
blkctx->sp = STIX_OOP_FROM_SMINT(local_ntmprs);
|
||||
blkctx->sp = STIX_SMOOI_TO_OOP(local_ntmprs);
|
||||
blkctx->sender = (stix_oop_t)stix->active_context;
|
||||
|
||||
*pblkctx = blkctx;
|
||||
@ -1019,15 +1019,15 @@ static int prim_integer_add (stix_t* stix, stix_ooi_t nargs)
|
||||
arg = ACTIVE_STACK_GET(stix, stix->sp);
|
||||
|
||||
#if 0
|
||||
if (STIX_OOP_IS_SMINT(rcv) && STIX_OOP_IS_SMINT(arg))
|
||||
if (STIX_OOP_IS_SMOOI(rcv) && STIX_OOP_IS_SMOOI(arg))
|
||||
{
|
||||
stix_ooi_t tmp;
|
||||
|
||||
tmp = STIX_OOP_TO_SMINT(rcv) + STIX_OOP_TO_SMINT(arg);
|
||||
tmp = STIX_OOP_TO_SMOOI(rcv) + STIX_OOP_TO_SMOOI(arg);
|
||||
/* TODO: check overflow. if so convert it to LargeInteger */
|
||||
|
||||
ACTIVE_STACK_POP (stix);
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_OOP_FROM_SMINT(tmp));
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(tmp));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1055,14 +1055,14 @@ static int prim_integer_sub (stix_t* stix, stix_ooi_t nargs)
|
||||
arg = ACTIVE_STACK_GET(stix, stix->sp);
|
||||
|
||||
#if 0
|
||||
if (STIX_OOP_IS_SMINT(rcv) && STIX_OOP_IS_SMINT(arg))
|
||||
if (STIX_OOP_IS_SMOOI(rcv) && STIX_OOP_IS_SMOOI(arg))
|
||||
{
|
||||
stix_ooi_t tmp;
|
||||
tmp = STIX_OOP_TO_SMINT(rcv) - STIX_OOP_TO_SMINT(arg);
|
||||
tmp = STIX_OOP_TO_SMOOI(rcv) - STIX_OOP_TO_SMOOI(arg);
|
||||
/* TODO: check overflow. if so convert it to LargeInteger */
|
||||
|
||||
ACTIVE_STACK_POP (stix);
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_OOP_FROM_SMINT(tmp));
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(tmp));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1088,15 +1088,15 @@ static int prim_integer_mul (stix_t* stix, stix_ooi_t nargs)
|
||||
arg = ACTIVE_STACK_GET(stix, stix->sp);
|
||||
|
||||
#if 0
|
||||
if (STIX_OOP_IS_SMINT(rcv) && STIX_OOP_IS_SMINT(arg))
|
||||
if (STIX_OOP_IS_SMOOI(rcv) && STIX_OOP_IS_SMOOI(arg))
|
||||
{
|
||||
stix_ooi_t tmp;
|
||||
|
||||
tmp = STIX_OOP_TO_SMINT(rcv) * STIX_OOP_TO_SMINT(arg);
|
||||
tmp = STIX_OOP_TO_SMOOI(rcv) * STIX_OOP_TO_SMOOI(arg);
|
||||
/* TODO: check overflow. if so convert it to LargeInteger */
|
||||
|
||||
ACTIVE_STACK_POP (stix);
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_OOP_FROM_SMINT(tmp));
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(tmp));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1121,10 +1121,10 @@ static int prim_integer_eq (stix_t* stix, stix_ooi_t nargs)
|
||||
rcv = ACTIVE_STACK_GET(stix, stix->sp - 1);
|
||||
arg = ACTIVE_STACK_GET(stix, stix->sp);
|
||||
|
||||
if (STIX_OOP_IS_SMINT(rcv) && STIX_OOP_IS_SMINT(arg))
|
||||
if (STIX_OOP_IS_SMOOI(rcv) && STIX_OOP_IS_SMOOI(arg))
|
||||
{
|
||||
ACTIVE_STACK_POP (stix);
|
||||
if (STIX_OOP_TO_SMINT(rcv) == STIX_OOP_TO_SMINT(arg))
|
||||
if (STIX_OOP_TO_SMOOI(rcv) == STIX_OOP_TO_SMOOI(arg))
|
||||
{
|
||||
ACTIVE_STACK_SETTOP (stix, stix->_true);
|
||||
}
|
||||
@ -1149,10 +1149,10 @@ static int prim_integer_ne (stix_t* stix, stix_ooi_t nargs)
|
||||
rcv = ACTIVE_STACK_GET(stix, stix->sp - 1);
|
||||
arg = ACTIVE_STACK_GET(stix, stix->sp);
|
||||
|
||||
if (STIX_OOP_IS_SMINT(rcv) && STIX_OOP_IS_SMINT(arg))
|
||||
if (STIX_OOP_IS_SMOOI(rcv) && STIX_OOP_IS_SMOOI(arg))
|
||||
{
|
||||
ACTIVE_STACK_POP (stix);
|
||||
if (STIX_OOP_TO_SMINT(rcv) != STIX_OOP_TO_SMINT(arg))
|
||||
if (STIX_OOP_TO_SMOOI(rcv) != STIX_OOP_TO_SMOOI(arg))
|
||||
{
|
||||
ACTIVE_STACK_SETTOP (stix, stix->_true);
|
||||
}
|
||||
@ -1176,10 +1176,10 @@ static int prim_integer_lt (stix_t* stix, stix_ooi_t nargs)
|
||||
rcv = ACTIVE_STACK_GET(stix, stix->sp - 1);
|
||||
arg = ACTIVE_STACK_GET(stix, stix->sp);
|
||||
|
||||
if (STIX_OOP_IS_SMINT(rcv) && STIX_OOP_IS_SMINT(arg))
|
||||
if (STIX_OOP_IS_SMOOI(rcv) && STIX_OOP_IS_SMOOI(arg))
|
||||
{
|
||||
ACTIVE_STACK_POP (stix);
|
||||
if (STIX_OOP_TO_SMINT(rcv) < STIX_OOP_TO_SMINT(arg))
|
||||
if (STIX_OOP_TO_SMOOI(rcv) < STIX_OOP_TO_SMOOI(arg))
|
||||
{
|
||||
ACTIVE_STACK_SETTOP (stix, stix->_true);
|
||||
}
|
||||
@ -1204,10 +1204,10 @@ static int prim_integer_gt (stix_t* stix, stix_ooi_t nargs)
|
||||
rcv = ACTIVE_STACK_GET(stix, stix->sp - 1);
|
||||
arg = ACTIVE_STACK_GET(stix, stix->sp);
|
||||
|
||||
if (STIX_OOP_IS_SMINT(rcv) && STIX_OOP_IS_SMINT(arg))
|
||||
if (STIX_OOP_IS_SMOOI(rcv) && STIX_OOP_IS_SMOOI(arg))
|
||||
{
|
||||
ACTIVE_STACK_POP (stix);
|
||||
if (STIX_OOP_TO_SMINT(rcv) > STIX_OOP_TO_SMINT(arg))
|
||||
if (STIX_OOP_TO_SMOOI(rcv) > STIX_OOP_TO_SMOOI(arg))
|
||||
{
|
||||
ACTIVE_STACK_SETTOP (stix, stix->_true);
|
||||
}
|
||||
@ -1232,10 +1232,10 @@ static int prim_integer_le (stix_t* stix, stix_ooi_t nargs)
|
||||
rcv = ACTIVE_STACK_GET(stix, stix->sp - 1);
|
||||
arg = ACTIVE_STACK_GET(stix, stix->sp);
|
||||
|
||||
if (STIX_OOP_IS_SMINT(rcv) && STIX_OOP_IS_SMINT(arg))
|
||||
if (STIX_OOP_IS_SMOOI(rcv) && STIX_OOP_IS_SMOOI(arg))
|
||||
{
|
||||
ACTIVE_STACK_POP (stix);
|
||||
if (STIX_OOP_TO_SMINT(rcv) <= STIX_OOP_TO_SMINT(arg))
|
||||
if (STIX_OOP_TO_SMOOI(rcv) <= STIX_OOP_TO_SMOOI(arg))
|
||||
{
|
||||
ACTIVE_STACK_SETTOP (stix, stix->_true);
|
||||
}
|
||||
@ -1260,10 +1260,10 @@ static int prim_integer_ge (stix_t* stix, stix_ooi_t nargs)
|
||||
rcv = ACTIVE_STACK_GET(stix, stix->sp - 1);
|
||||
arg = ACTIVE_STACK_GET(stix, stix->sp);
|
||||
|
||||
if (STIX_OOP_IS_SMINT(rcv) && STIX_OOP_IS_SMINT(arg))
|
||||
if (STIX_OOP_IS_SMOOI(rcv) && STIX_OOP_IS_SMOOI(arg))
|
||||
{
|
||||
ACTIVE_STACK_POP (stix);
|
||||
if (STIX_OOP_TO_SMINT(rcv) >= STIX_OOP_TO_SMINT(arg))
|
||||
if (STIX_OOP_TO_SMOOI(rcv) >= STIX_OOP_TO_SMOOI(arg))
|
||||
{
|
||||
ACTIVE_STACK_SETTOP (stix, stix->_true);
|
||||
}
|
||||
@ -1343,7 +1343,7 @@ static int prim_ffi_open (stix_t* stix, stix_ooi_t nargs)
|
||||
|
||||
ACTIVE_STACK_POP (stix);
|
||||
/* TODO: how to hold an address? as an integer???? or a byte array? */
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_OOP_FROM_SMINT(handle));
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(handle));
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -1360,7 +1360,7 @@ static int prim_ffi_close (stix_t* stix, stix_ooi_t nargs)
|
||||
rcv = ACTIVE_STACK_GET(stix, stix->sp - 1);
|
||||
arg = ACTIVE_STACK_GET(stix, stix->sp);
|
||||
|
||||
if (!STIX_OOP_IS_SMINT(arg))
|
||||
if (!STIX_OOP_IS_SMOOI(arg))
|
||||
{
|
||||
/* TODO: more info on error */
|
||||
return 0;
|
||||
@ -1368,7 +1368,7 @@ static int prim_ffi_close (stix_t* stix, stix_ooi_t nargs)
|
||||
|
||||
ACTIVE_STACK_POP (stix);
|
||||
|
||||
handle = STIX_OOP_TO_SMINT(arg); /* TODO: how to store void* ??? */
|
||||
handle = STIX_OOP_TO_SMOOI(arg); /* TODO: how to store void* ??? */
|
||||
if (stix->vmprim.mod_close) stix->vmprim.mod_close (stix, handle);
|
||||
return 1;
|
||||
}
|
||||
@ -1385,7 +1385,7 @@ static int prim_ffi_call (stix_t* stix, stix_ooi_t nargs)
|
||||
sig = ACTIVE_STACK_GET(stix, stix->sp - 1);
|
||||
args = ACTIVE_STACK_GET(stix, stix->sp);
|
||||
|
||||
if (!STIX_OOP_IS_SMINT(fun)) /* TODO: how to store pointer */
|
||||
if (!STIX_OOP_IS_SMOOI(fun)) /* TODO: how to store pointer */
|
||||
{
|
||||
/* TODO: more info on error */
|
||||
return 0;
|
||||
@ -1410,7 +1410,7 @@ printf ("wrong signature...\n");
|
||||
stix_oop_oop_t arr;
|
||||
int mode_set;
|
||||
|
||||
f = STIX_OOP_TO_SMINT(fun); /* TODO: decode pointer properly */
|
||||
f = STIX_OOP_TO_SMOOI(fun); /* TODO: decode pointer properly */
|
||||
arr = (stix_oop_oop_t)args;
|
||||
|
||||
dc = dcNewCallVM (4096);
|
||||
@ -1451,15 +1451,15 @@ printf ("CALL MODE 222 ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSUPPORTED_MOD
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
dcArgInt (dc, STIX_OOP_TO_SMINT(arr->slot[i - 2]));
|
||||
dcArgInt (dc, STIX_OOP_TO_SMOOI(arr->slot[i - 2]));
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
dcArgLong (dc, STIX_OOP_TO_SMINT(arr->slot[i - 2]));
|
||||
dcArgLong (dc, STIX_OOP_TO_SMOOI(arr->slot[i - 2]));
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
dcArgLongLong (dc, STIX_OOP_TO_SMINT(arr->slot[i - 2]));
|
||||
dcArgLongLong (dc, STIX_OOP_TO_SMOOI(arr->slot[i - 2]));
|
||||
break;
|
||||
|
||||
case 's':
|
||||
@ -1500,21 +1500,21 @@ printf ("CALL MODE 222 ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSUPPORTED_MOD
|
||||
int r = dcCallInt (dc, f);
|
||||
printf ("CALLED... %d\n", r);
|
||||
printf ("CALL ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSUPPORTED_MODE);
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_OOP_FROM_SMINT(r));
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(r));
|
||||
break;
|
||||
}
|
||||
|
||||
case 'l':
|
||||
{
|
||||
long r = dcCallLong (dc, f);
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_OOP_FROM_SMINT(r));
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(r));
|
||||
break;
|
||||
}
|
||||
|
||||
case 'L':
|
||||
{
|
||||
long long r = dcCallLongLong (dc, f);
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_OOP_FROM_SMINT(r));
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(r));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1556,7 +1556,7 @@ static int prim_ffi_getsym (stix_t* stix, stix_ooi_t nargs)
|
||||
fun = ACTIVE_STACK_GET(stix, stix->sp - 1);
|
||||
hnd = ACTIVE_STACK_GET(stix, stix->sp);
|
||||
|
||||
if (!STIX_OOP_IS_SMINT(hnd)) /* TODO: how to store pointer */
|
||||
if (!STIX_OOP_IS_SMOOI(hnd)) /* TODO: how to store pointer */
|
||||
{
|
||||
/* TODO: more info on error */
|
||||
return 0;
|
||||
@ -1573,7 +1573,7 @@ printf ("wrong function name...\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
sym = stix->vmprim.mod_getsym (stix, STIX_OOP_TO_SMINT(hnd), ((stix_oop_char_t)fun)->slot);
|
||||
sym = stix->vmprim.mod_getsym (stix, STIX_OOP_TO_SMOOI(hnd), ((stix_oop_char_t)fun)->slot);
|
||||
if (!sym)
|
||||
{
|
||||
return 0;
|
||||
@ -1581,7 +1581,7 @@ printf ("wrong function name...\n");
|
||||
|
||||
ACTIVE_STACK_POPS (stix, 2);
|
||||
/* TODO: how to hold an address? as an integer???? or a byte array? */
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_OOP_FROM_SMINT(sym));
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(sym));
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -1952,7 +1952,7 @@ printf ("BCODE = %x\n", bcode);
|
||||
|
||||
do
|
||||
{
|
||||
home_ntmprs = STIX_OOP_TO_SMINT(((stix_oop_context_t)home)->ntmprs);
|
||||
home_ntmprs = STIX_OOP_TO_SMOOI(((stix_oop_context_t)home)->ntmprs);
|
||||
if (b1 >= home_ntmprs) break;
|
||||
|
||||
ctx = (stix_oop_context_t)home;
|
||||
@ -2323,9 +2323,9 @@ printf ("]\n");
|
||||
goto oops;
|
||||
}
|
||||
|
||||
STIX_ASSERT (STIX_OOP_TO_SMINT(newmth->tmpr_nargs) == b1);
|
||||
STIX_ASSERT (STIX_OOP_TO_SMOOI(newmth->tmpr_nargs) == b1);
|
||||
|
||||
preamble = STIX_OOP_TO_SMINT(newmth->preamble);
|
||||
preamble = STIX_OOP_TO_SMOOI(newmth->preamble);
|
||||
preamble_code = STIX_METHOD_GET_PREAMBLE_CODE(preamble);
|
||||
switch (preamble_code)
|
||||
{
|
||||
@ -2355,13 +2355,13 @@ printf ("]\n");
|
||||
case STIX_METHOD_PREAMBLE_RETURN_INDEX:
|
||||
DBGOUT_EXEC_1 ("METHOD_PREAMBLE_RETURN_INDEX %d", (int)STIX_METHOD_GET_PREAMBLE_INDEX(preamble));
|
||||
ACTIVE_STACK_POPS (stix, b1);
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_OOP_FROM_SMINT(STIX_METHOD_GET_PREAMBLE_INDEX(preamble)));
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(STIX_METHOD_GET_PREAMBLE_INDEX(preamble)));
|
||||
break;
|
||||
|
||||
case STIX_METHOD_PREAMBLE_RETURN_NEGINDEX:
|
||||
DBGOUT_EXEC_1 ("METHOD_PREAMBLE_RETURN_NEGINDEX %d", (int)STIX_METHOD_GET_PREAMBLE_INDEX(preamble));
|
||||
ACTIVE_STACK_POPS (stix, b1);
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_OOP_FROM_SMINT(-STIX_METHOD_GET_PREAMBLE_INDEX(preamble)));
|
||||
ACTIVE_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(-STIX_METHOD_GET_PREAMBLE_INDEX(preamble)));
|
||||
break;
|
||||
|
||||
case STIX_METHOD_PREAMBLE_RETURN_INSTVAR:
|
||||
@ -2438,8 +2438,8 @@ printf ("]\n");
|
||||
STIX_ASSERT (STIX_CLASSOF(stix,name) == stix->_symbol);
|
||||
|
||||
/* merge two SmallIntegers to get a full pointer */
|
||||
handler = (stix_oow_t)STIX_OOP_TO_SMINT(newmth->preamble_data[0]) << (STIX_OOW_BITS / 2) |
|
||||
(stix_oow_t)STIX_OOP_TO_SMINT(newmth->preamble_data[1]);
|
||||
handler = (stix_oow_t)STIX_OOP_TO_SMOOI(newmth->preamble_data[0]) << (STIX_OOW_BITS / 2) |
|
||||
(stix_oow_t)STIX_OOP_TO_SMOOI(newmth->preamble_data[1]);
|
||||
if (!handler) handler = query_prim_module (stix, ((stix_oop_char_t)name)->slot, STIX_OBJ_GET_SIZE(name));
|
||||
|
||||
if (handler)
|
||||
@ -2447,8 +2447,8 @@ printf ("]\n");
|
||||
int n;
|
||||
|
||||
/* split a pointer to two OOP fields as SmallIntegers for storing. */
|
||||
newmth->preamble_data[0] = STIX_OOP_FROM_SMINT((stix_oow_t)handler >> (STIX_OOW_BITS / 2));
|
||||
newmth->preamble_data[1] = STIX_OOP_FROM_SMINT((stix_oow_t)handler & STIX_LBMASK(stix_oow_t, STIX_OOW_BITS / 2));
|
||||
newmth->preamble_data[0] = STIX_SMOOI_TO_OOP((stix_oow_t)handler >> (STIX_OOW_BITS / 2));
|
||||
newmth->preamble_data[1] = STIX_SMOOI_TO_OOP((stix_oow_t)handler & STIX_LBMASK(stix_oow_t, STIX_OOW_BITS / 2));
|
||||
|
||||
stix_pushtmp (stix, (stix_oop_t*)&newmth);
|
||||
n = handler (stix, b1);
|
||||
@ -2501,34 +2501,34 @@ printf ("]\n");
|
||||
|
||||
case BCODE_PUSH_NEGONE:
|
||||
DBGOUT_EXEC_0 ("PUSH_NEGONE");
|
||||
ACTIVE_STACK_PUSH (stix, STIX_OOP_FROM_SMINT(-1));
|
||||
ACTIVE_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(-1));
|
||||
break;
|
||||
|
||||
case BCODE_PUSH_ZERO:
|
||||
DBGOUT_EXEC_0 ("PUSH_ZERO");
|
||||
ACTIVE_STACK_PUSH (stix, STIX_OOP_FROM_SMINT(0));
|
||||
ACTIVE_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(0));
|
||||
break;
|
||||
|
||||
case BCODE_PUSH_ONE:
|
||||
DBGOUT_EXEC_0 ("PUSH_ONE");
|
||||
ACTIVE_STACK_PUSH (stix, STIX_OOP_FROM_SMINT(1));
|
||||
ACTIVE_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(1));
|
||||
break;
|
||||
|
||||
case BCODE_PUSH_TWO:
|
||||
DBGOUT_EXEC_0 ("PUSH_TWO");
|
||||
ACTIVE_STACK_PUSH (stix, STIX_OOP_FROM_SMINT(2));
|
||||
ACTIVE_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(2));
|
||||
break;
|
||||
|
||||
case BCODE_PUSH_INTLIT:
|
||||
FETCH_PARAM_CODE_TO (stix, b1);
|
||||
DBGOUT_EXEC_1 ("PUSH_INTLIT %d", (int)b1);
|
||||
ACTIVE_STACK_PUSH (stix, STIX_OOP_FROM_SMINT(b1));
|
||||
ACTIVE_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(b1));
|
||||
break;
|
||||
|
||||
case BCODE_PUSH_NEGINTLIT:
|
||||
FETCH_PARAM_CODE_TO (stix, b1);
|
||||
DBGOUT_EXEC_1 ("PUSH_NEGINTLIT %d", (int)-b1);
|
||||
ACTIVE_STACK_PUSH (stix, STIX_OOP_FROM_SMINT(-b1));
|
||||
ACTIVE_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(-b1));
|
||||
break;
|
||||
|
||||
/* -------------------------------------------------------- */
|
||||
@ -2680,15 +2680,15 @@ printf ("TERMINATE A PROCESS............\n");
|
||||
* 11000100 KKKKKKKK or 11000100 KKKKKKKK KKKKKKKK
|
||||
* depending on STIX_BCODE_LONG_PARAM_SIZE. change 'ip' to point to
|
||||
* the instruction after the jump. */
|
||||
blkctx->ip = STIX_OOP_FROM_SMINT(stix->ip + STIX_BCODE_LONG_PARAM_SIZE + 1);
|
||||
blkctx->ip = STIX_SMOOI_TO_OOP(stix->ip + STIX_BCODE_LONG_PARAM_SIZE + 1);
|
||||
/* stack pointer below the bottom. this block context has an
|
||||
* empty stack anyway. */
|
||||
blkctx->sp = STIX_OOP_FROM_SMINT(-1);
|
||||
blkctx->sp = STIX_SMOOI_TO_OOP(-1);
|
||||
/* the number of arguments for a block context is local to the block */
|
||||
blkctx->method_or_nargs = STIX_OOP_FROM_SMINT(b1);
|
||||
blkctx->method_or_nargs = STIX_SMOOI_TO_OOP(b1);
|
||||
/* the number of temporaries here is an accumulated count including
|
||||
* the number of temporaries of a home context */
|
||||
blkctx->ntmprs = STIX_OOP_FROM_SMINT(b2);
|
||||
blkctx->ntmprs = STIX_SMOOI_TO_OOP(b2);
|
||||
|
||||
blkctx->home = (stix_oop_t)stix->active_context;
|
||||
blkctx->receiver_or_source = stix->_nil; /* no source */
|
||||
@ -2710,11 +2710,11 @@ printf ("TERMINATE A PROCESS............\n");
|
||||
STIX_ASSERT (stix->sp >= 2);
|
||||
|
||||
STIX_ASSERT (STIX_CLASSOF(stix, ACTIVE_STACK_GETTOP(stix)) == stix->_small_integer);
|
||||
ntmprs = STIX_OOP_TO_SMINT(ACTIVE_STACK_GETTOP(stix));
|
||||
ntmprs = STIX_OOP_TO_SMOOI(ACTIVE_STACK_GETTOP(stix));
|
||||
ACTIVE_STACK_POP (stix);
|
||||
|
||||
STIX_ASSERT (STIX_CLASSOF(stix, ACTIVE_STACK_GETTOP(stix)) == stix->_small_integer);
|
||||
nargs = STIX_OOP_TO_SMINT(ACTIVE_STACK_GETTOP(stix));
|
||||
nargs = STIX_OOP_TO_SMOOI(ACTIVE_STACK_GETTOP(stix));
|
||||
ACTIVE_STACK_POP (stix);
|
||||
|
||||
STIX_ASSERT (nargs >= 0);
|
||||
@ -2753,13 +2753,13 @@ printf ("TERMINATE A PROCESS............\n");
|
||||
* 0000XXXX KKKKKKKK or 0000XXXX KKKKKKKK KKKKKKKK
|
||||
* depending on STIX_BCODE_LONG_PARAM_SIZE. change 'ip' to point to
|
||||
* the instruction after the jump. */
|
||||
blkctx->ip = STIX_OOP_FROM_SMINT(stix->ip + STIX_BCODE_LONG_PARAM_SIZE + 1);
|
||||
blkctx->sp = STIX_OOP_FROM_SMINT(-1);
|
||||
blkctx->ip = STIX_SMOOI_TO_OOP(stix->ip + STIX_BCODE_LONG_PARAM_SIZE + 1);
|
||||
blkctx->sp = STIX_SMOOI_TO_OOP(-1);
|
||||
/* the number of arguments for a block context is local to the block */
|
||||
blkctx->method_or_nargs = STIX_OOP_FROM_SMINT(nargs);
|
||||
blkctx->method_or_nargs = STIX_SMOOI_TO_OOP(nargs);
|
||||
/* the number of temporaries here is an accumulated count including
|
||||
* the number of temporaries of a home context */
|
||||
blkctx->ntmprs = STIX_OOP_FROM_SMINT(ntmprs);
|
||||
blkctx->ntmprs = STIX_SMOOI_TO_OOP(ntmprs);
|
||||
|
||||
blkctx->home = (stix_oop_t)rctx;
|
||||
blkctx->receiver_or_source = stix->_nil;
|
||||
|
@ -38,7 +38,7 @@ static void compact_symbol_table (stix_t* stix, stix_oop_t _nil)
|
||||
|
||||
bucket_size = STIX_OBJ_GET_SIZE(stix->symtab->bucket);
|
||||
|
||||
tally = STIX_OOP_TO_SMINT(stix->symtab->tally);
|
||||
tally = STIX_OOP_TO_SMOOI(stix->symtab->tally);
|
||||
if (tally <= 0) return;
|
||||
|
||||
for (index = 0; index < bucket_size; )
|
||||
@ -79,8 +79,8 @@ static void compact_symbol_table (stix_t* stix, stix_oop_t _nil)
|
||||
tally--;
|
||||
}
|
||||
|
||||
STIX_ASSERT (tally <= STIX_SMINT_MAX);
|
||||
stix->symtab->tally = STIX_OOP_FROM_SMINT(tally);
|
||||
STIX_ASSERT (tally <= STIX_SMOOI_MAX);
|
||||
stix->symtab->tally = STIX_SMOOI_TO_OOP(tally);
|
||||
}
|
||||
|
||||
|
||||
@ -221,7 +221,7 @@ static stix_uint8_t* scan_new_heap (stix_t* stix, stix_uint8_t* ptr)
|
||||
* scanned in full. the slots above the stack pointer
|
||||
* are garbages. */
|
||||
size = STIX_CONTEXT_NAMED_INSTVARS +
|
||||
STIX_OOP_TO_SMINT(((stix_oop_context_t)oop)->sp) + 1;
|
||||
STIX_OOP_TO_SMOOI(((stix_oop_context_t)oop)->sp) + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -262,8 +262,8 @@ void stix_gc (stix_t* stix)
|
||||
{
|
||||
/* store the stack pointer to the actual active context */
|
||||
/* TODO: verify if this is correct */
|
||||
stix->active_context->sp = STIX_OOP_FROM_SMINT(stix->sp);
|
||||
stix->active_context->ip = STIX_OOP_FROM_SMINT(stix->ip);
|
||||
stix->active_context->sp = STIX_SMOOI_TO_OOP(stix->sp);
|
||||
stix->active_context->ip = STIX_SMOOI_TO_OOP(stix->ip);
|
||||
}
|
||||
|
||||
/*printf ("STARTING GC curheap base %p ptr %p newheap base %p ptr %p\n",
|
||||
@ -402,7 +402,7 @@ stix_oop_t stix_shallowcopy (stix_t* stix, stix_oop_t oop)
|
||||
|
||||
c = (stix_oop_class_t)STIX_OBJ_GET_CLASS(oop);
|
||||
stix_pushtmp (stix, &oop);
|
||||
z = stix_instantiate (stix, (stix_oop_t)c, STIX_NULL, STIX_OBJ_GET_SIZE(oop) - STIX_CLASS_SPEC_NAMED_INSTVAR(STIX_OOP_TO_SMINT(c->spec)));
|
||||
z = stix_instantiate (stix, (stix_oop_t)c, STIX_NULL, STIX_OBJ_GET_SIZE(oop) - STIX_CLASS_SPEC_NAMED_INSTVAR(STIX_OOP_TO_SMOOI(c->spec)));
|
||||
stix_poptmp(stix);
|
||||
|
||||
if (!z) return z;
|
||||
|
@ -79,8 +79,8 @@ static stix_oop_t alloc_kernel_class (stix_t* stix, stix_oow_t indexed, stix_oow
|
||||
|
||||
STIX_OBJ_SET_FLAGS_KERNEL (c, 1);
|
||||
STIX_OBJ_SET_CLASS (c, stix->_class);
|
||||
c->spec = STIX_OOP_FROM_SMINT(spec);
|
||||
c->selfspec = STIX_OOP_FROM_SMINT(STIX_CLASS_SELFSPEC_MAKE(indexed, 0));
|
||||
c->spec = STIX_SMOOI_TO_OOP(spec);
|
||||
c->selfspec = STIX_SMOOI_TO_OOP(STIX_CLASS_SELFSPEC_MAKE(indexed, 0));
|
||||
|
||||
return (stix_oop_t)c;
|
||||
}
|
||||
@ -187,7 +187,7 @@ static int ignite_2 (stix_t* stix)
|
||||
if (!tmp) return -1;
|
||||
stix->symtab = (stix_oop_set_t)tmp;
|
||||
|
||||
stix->symtab->tally = STIX_OOP_FROM_SMINT(0);
|
||||
stix->symtab->tally = STIX_SMOOI_TO_OOP(0);
|
||||
/* It's important to assign the result of stix_instantiate() to a temporary
|
||||
* variable first and then assign it to stix->symtab->bucket.
|
||||
* The pointer 'stix->symtab; can change in stix_instantiate() and the
|
||||
@ -207,7 +207,7 @@ static int ignite_2 (stix_t* stix)
|
||||
if (!tmp) return -1;
|
||||
stix->processor = (stix_oop_process_scheduler_t)tmp;
|
||||
/* initialize the tally field to 0, keep other fields as nils */
|
||||
stix->processor->tally = STIX_OOP_FROM_SMINT(0);
|
||||
stix->processor->tally = STIX_SMOOI_TO_OOP(0);
|
||||
|
||||
/* Export the system dictionary via the first class variable of the Stix class */
|
||||
((stix_oop_class_t)stix->_apex)->slot[0] = (stix_oop_t)stix->sysdic;
|
||||
|
@ -388,10 +388,10 @@ int main (int argc, char* argv[])
|
||||
(unsigned long int)STIX_MAX_CLASSVARS,
|
||||
(unsigned long int)STIX_MAX_CLASSINSTVARS,
|
||||
(unsigned long int)STIX_TYPE_MAX(stix_oow_t),
|
||||
(long)STIX_SMINT_MAX, (long)STIX_SMINT_MIN);
|
||||
(long)STIX_SMOOI_MAX, (long)STIX_SMOOI_MIN);
|
||||
|
||||
printf ("STIX_SMINT_MIN + STIX_SMINT_MIN => %ld\n", (long)(STIX_SMINT_MIN + STIX_SMINT_MIN));
|
||||
printf ("STIX_SMINT_MIN - STIX_SMINT_MAX => %ld\n", (long)(STIX_SMINT_MIN - STIX_SMINT_MAX));
|
||||
printf ("STIX_SMOOI_MIN + STIX_SMOOI_MIN => %ld\n", (long)(STIX_SMOOI_MIN + STIX_SMOOI_MIN));
|
||||
printf ("STIX_SMOOI_MIN - STIX_SMOOI_MAX => %ld\n", (long)(STIX_SMOOI_MIN - STIX_SMOOI_MAX));
|
||||
|
||||
#if !defined(macintosh)
|
||||
if (argc < 2)
|
||||
@ -406,18 +406,18 @@ int main (int argc, char* argv[])
|
||||
stix_oop_t k;
|
||||
stix_oow_t x;
|
||||
|
||||
k = STIX_OOP_FROM_SMINT(-1);
|
||||
printf ("%ld %ld %ld %lX\n", (long int)STIX_OOP_TO_SMINT(k), (long int)STIX_SMINT_MIN, (long int)STIX_SMINT_MAX, (long)LONG_MIN);
|
||||
k = STIX_SMOOI_TO_OOP(-1);
|
||||
printf ("%ld %ld %ld %lX\n", (long int)STIX_OOP_TO_SMOOI(k), (long int)STIX_SMOOI_MIN, (long int)STIX_SMOOI_MAX, (long)LONG_MIN);
|
||||
|
||||
k = STIX_OOP_FROM_SMINT(STIX_SMINT_MAX);
|
||||
printf ("%ld\n", (long int)STIX_OOP_TO_SMINT(k));
|
||||
k = STIX_SMOOI_TO_OOP(STIX_SMOOI_MAX);
|
||||
printf ("%ld\n", (long int)STIX_OOP_TO_SMOOI(k));
|
||||
|
||||
k = STIX_OOP_FROM_SMINT(STIX_SMINT_MIN);
|
||||
printf ("%ld\n", (long int)STIX_OOP_TO_SMINT(k));
|
||||
k = STIX_SMOOI_TO_OOP(STIX_SMOOI_MIN);
|
||||
printf ("%ld\n", (long int)STIX_OOP_TO_SMOOI(k));
|
||||
|
||||
printf ("%u\n", STIX_BITS_MAX(unsigned int, 5));
|
||||
x = STIX_CLASS_SPEC_MAKE (10, 1, STIX_OBJ_TYPE_CHAR);
|
||||
printf ("%lu %lu %lu %lu\n", (unsigned long int)x, (unsigned long int)STIX_OOP_FROM_SMINT(x),
|
||||
printf ("%lu %lu %lu %lu\n", (unsigned long int)x, (unsigned long int)STIX_SMOOI_TO_OOP(x),
|
||||
(unsigned long int)STIX_CLASS_SPEC_NAMED_INSTVAR(x),
|
||||
(unsigned long int)STIX_CLASS_SPEC_INDEXED_TYPE(x));
|
||||
}*/
|
||||
|
@ -183,8 +183,8 @@ stix_oop_t stix_instantiate (stix_t* stix, stix_oop_t _class, const void* vptr,
|
||||
STIX_ASSERT (STIX_OOP_IS_POINTER(_class));
|
||||
STIX_ASSERT (STIX_CLASSOF(stix, _class) == stix->_class);
|
||||
|
||||
STIX_ASSERT (STIX_OOP_IS_SMINT(((stix_oop_class_t)_class)->spec));
|
||||
spec = STIX_OOP_TO_SMINT(((stix_oop_class_t)_class)->spec);
|
||||
STIX_ASSERT (STIX_OOP_IS_SMOOI(((stix_oop_class_t)_class)->spec));
|
||||
spec = STIX_OOP_TO_SMOOI(((stix_oop_class_t)_class)->spec);
|
||||
|
||||
named_instvar = STIX_CLASS_SPEC_NAMED_INSTVAR(spec); /* size of the named_instvar part */
|
||||
|
||||
@ -286,8 +286,8 @@ stix_oop_t stix_instantiatewithtrailer (stix_t* stix, stix_oop_t _class, stix_oo
|
||||
STIX_ASSERT (STIX_OOP_IS_POINTER(_class));
|
||||
STIX_ASSERT (STIX_CLASSOF(stix, _class) == stix->_class);
|
||||
|
||||
STIX_ASSERT (STIX_OOP_IS_SMINT(((stix_oop_class_t)_class)->spec));
|
||||
spec = STIX_OOP_TO_SMINT(((stix_oop_class_t)_class)->spec);
|
||||
STIX_ASSERT (STIX_OOP_IS_SMOOI(((stix_oop_class_t)_class)->spec));
|
||||
spec = STIX_OOP_TO_SMOOI(((stix_oop_class_t)_class)->spec);
|
||||
|
||||
named_instvar = STIX_CLASS_SPEC_NAMED_INSTVAR(spec); /* size of the named_instvar part */
|
||||
|
||||
|
@ -36,7 +36,7 @@ stix_oop_process_t stix_addnewproc (stix_t* stix)
|
||||
proc = (stix_oop_process_t)stix_instantiate (stix, stix->_process, STIX_NULL, stix->option.dfl_procstk_size);
|
||||
if (!proc) return STIX_NULL;
|
||||
|
||||
proc->state = STIX_OOP_FROM_SMINT(0);
|
||||
proc->state = STIX_SMOOI_TO_OOP(0);
|
||||
|
||||
STIX_ASSERT (STIX_OBJ_GET_SIZE(proc) == STIX_PROCESS_NAMED_INSTVARS + stix->option.dfl_procstk_size);
|
||||
return proc;
|
||||
|
@ -110,16 +110,18 @@
|
||||
typedef stix_uintmax_t bigatom_t;
|
||||
typedef stix_oow_t atom_t;
|
||||
typedef stix_oop_word_t oop_atom_t;
|
||||
# define ATOM_BITS STIX_OOW_BITS
|
||||
# define BIGATOM_BITS (STIX_SIZEOF(bigatom_t) * 8)
|
||||
# define SIZEOF_ATOM_T STIX_SIZEOF_OOW_T
|
||||
# define SIZEOF_BIGATOM_T STIX_SIZEOF_UINTMAX_T
|
||||
# define ATOM_BITS STIX_OOW_BITS
|
||||
# define BIGATOM_BITS (STIX_SIZEOF_UINTMAX_T * 8)
|
||||
#else
|
||||
typedef stix_oow_t bigatom_t;
|
||||
typedef stix_oohw_t atom_t;
|
||||
typedef stix_oop_halfword_t oop_atom_t;
|
||||
# define SIZEOF_ATOM_T STIX_SIZEOF_OOHW_T
|
||||
# define SIZEOF_BIGATOM_T STIX_SIZEOF_OOW_T
|
||||
# define ATOM_BITS STIX_OOHW_BITS
|
||||
# define BIGATOM_BITS STIX_OOW_BITS
|
||||
# define SIZEOF_ATOM_T STIX_SIZEOF_OOHW_T
|
||||
# define MAKE_WORD(hw1,hw2) ((stix_oow_t)(hw1) | (stix_oow_t)(hw2) << ATOM_BITS)
|
||||
#endif
|
||||
|
||||
@ -158,14 +160,14 @@
|
||||
|
||||
/*
|
||||
* The STIX_CLASS_SPEC_MAKE() macro creates a class spec value.
|
||||
* _class->spec = STIX_OOP_FROM_SMINT(STIX_CLASS_SPEC_MAKE(0, 1, STIX_OBJ_TYPE_CHAR));
|
||||
* _class->spec = STIX_SMOOI_TO_OOP(STIX_CLASS_SPEC_MAKE(0, 1, STIX_OBJ_TYPE_CHAR));
|
||||
*/
|
||||
#define STIX_CLASS_SPEC_MAKE(named_instvar,is_indexed,indexed_type) ( \
|
||||
(((stix_oow_t)(named_instvar)) << (STIX_OBJ_FLAGS_TYPE_BITS + 1)) | \
|
||||
(((stix_oow_t)(indexed_type)) << 1) | (((stix_oow_t)is_indexed) & 1) )
|
||||
|
||||
/* what is the number of named instance variables?
|
||||
* STIX_CLASS_SPEC_NAMED_INSTVAR(STIX_OOP_TO_SMINT(_class->spec))
|
||||
* STIX_CLASS_SPEC_NAMED_INSTVAR(STIX_OOP_TO_SMOOI(_class->spec))
|
||||
*/
|
||||
#define STIX_CLASS_SPEC_NAMED_INSTVAR(spec) \
|
||||
(((stix_oow_t)(spec)) >> (STIX_OBJ_FLAGS_TYPE_BITS + 1))
|
||||
@ -1117,7 +1119,7 @@ stix_oop_t stix_strtoint (
|
||||
stix_t* stix,
|
||||
const stix_ooch_t* str,
|
||||
stix_oow_t len,
|
||||
unsigned int radix
|
||||
int radix
|
||||
);
|
||||
/* ========================================================================= */
|
||||
/* comp.c */
|
||||
|
@ -119,21 +119,21 @@ typedef struct stix_obj_word_t* stix_oop_word_t;
|
||||
#define STIX_OOP_IS_POINTER(oop) (!STIX_OOP_IS_NUMERIC(oop))
|
||||
#define STIX_OOP_GET_TAG(oop) (((stix_oow_t)oop) & STIX_LBMASK(stix_oow_t, STIX_OOP_TAG_BITS))
|
||||
|
||||
#define STIX_OOP_IS_SMINT(oop) (((stix_ooi_t)oop) & STIX_OOP_TAG_SMINT)
|
||||
#define STIX_OOP_IS_SMOOI(oop) (((stix_ooi_t)oop) & STIX_OOP_TAG_SMINT)
|
||||
#define STIX_OOP_IS_CHAR(oop) (((stix_oow_t)oop) & STIX_OOP_TAG_CHAR)
|
||||
#define STIX_OOP_FROM_SMINT(num) ((stix_oop_t)((((stix_ooi_t)(num)) << STIX_OOP_TAG_BITS) | STIX_OOP_TAG_SMINT))
|
||||
#define STIX_OOP_TO_SMINT(oop) (((stix_ooi_t)oop) >> STIX_OOP_TAG_BITS)
|
||||
#define STIX_SMOOI_TO_OOP(num) ((stix_oop_t)((((stix_ooi_t)(num)) << STIX_OOP_TAG_BITS) | STIX_OOP_TAG_SMINT))
|
||||
#define STIX_OOP_TO_SMOOI(oop) (((stix_ooi_t)oop) >> STIX_OOP_TAG_BITS)
|
||||
#define STIX_OOP_FROM_CHAR(num) ((stix_oop_t)((((stix_oow_t)(num)) << STIX_OOP_TAG_BITS) | STIX_OOP_TAG_CHAR))
|
||||
#define STIX_OOP_TO_CHAR(oop) (((stix_oow_t)oop) >> STIX_OOP_TAG_BITS)
|
||||
|
||||
#define STIX_SMINT_BITS (STIX_SIZEOF(stix_ooi_t) * 8 - STIX_OOP_TAG_BITS)
|
||||
#define STIX_SMINT_MAX ((stix_ooi_t)(~((stix_oow_t)0) >> (STIX_OOP_TAG_BITS + 1)))
|
||||
#define STIX_SMINT_MIN (-STIX_SMINT_MAX - 1)
|
||||
#define STIX_OOI_IN_SMINT_RANGE(ooi) ((ooi) >= STIX_SMINT_MIN && (ooi) <= STIX_SMINT_MAX)
|
||||
#define STIX_SMOOI_MAX ((stix_ooi_t)(~((stix_oow_t)0) >> (STIX_OOP_TAG_BITS + 1)))
|
||||
#define STIX_SMOOI_MIN (-STIX_SMOOI_MAX - 1)
|
||||
#define STIX_IN_SMOOI_RANGE(ooi) ((ooi) >= STIX_SMOOI_MIN && (ooi) <= STIX_SMOOI_MAX)
|
||||
|
||||
/* TODO: There are untested code where smint is converted to stix_oow_t.
|
||||
* for example, the spec making macro treats the number as stix_oow_t instead of stix_ooi_t.
|
||||
* as of this writing, i skip testing that part with the spec value exceeding STIX_SMINT_MAX.
|
||||
* as of this writing, i skip testing that part with the spec value exceeding STIX_SMOOI_MAX.
|
||||
* later, please verify it works, probably by limiting the value ranges in such macros
|
||||
*/
|
||||
|
||||
@ -509,7 +509,7 @@ struct stix_process_scheduler_t
|
||||
* object encoded into a pointer.
|
||||
*/
|
||||
#define STIX_CLASSOF(stix,oop) ( \
|
||||
STIX_OOP_IS_SMINT(oop)? (stix)->_small_integer: \
|
||||
STIX_OOP_IS_SMOOI(oop)? (stix)->_small_integer: \
|
||||
STIX_OOP_IS_CHAR(oop)? (stix)->_character: STIX_OBJ_GET_CLASS(oop) \
|
||||
)
|
||||
|
||||
|
@ -95,7 +95,7 @@ static stix_oop_t find_or_make_symbol (stix_t* stix, const stix_ooch_t* ptr, sti
|
||||
return STIX_NULL;
|
||||
}
|
||||
|
||||
tally = STIX_OOP_TO_SMINT(stix->symtab->tally);
|
||||
tally = STIX_OOP_TO_SMOOI(stix->symtab->tally);
|
||||
if (tally + 1 >= STIX_OBJ_GET_SIZE(stix->symtab->bucket))
|
||||
{
|
||||
stix_oop_oop_t bucket;
|
||||
@ -124,8 +124,8 @@ static stix_oop_t find_or_make_symbol (stix_t* stix, const stix_ooch_t* ptr, sti
|
||||
symbol = (stix_oop_char_t)stix_instantiate(stix, stix->_symbol, ptr, len);
|
||||
if (symbol)
|
||||
{
|
||||
STIX_ASSERT (tally < STIX_SMINT_MAX);
|
||||
stix->symtab->tally = STIX_OOP_FROM_SMINT(tally + 1);
|
||||
STIX_ASSERT (tally < STIX_SMOOI_MAX);
|
||||
stix->symtab->tally = STIX_SMOOI_TO_OOP(tally + 1);
|
||||
stix->symtab->bucket->slot[index] = (stix_oop_t)symbol;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user