added STIX_EPFULL
fixed a bug in starting an initial process started writing an integer-to-string conversion function
This commit is contained in:
parent
283c3652db
commit
2fbb4d3a71
@ -109,6 +109,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#method asString
|
||||||
|
{
|
||||||
|
<primitive: #_integer_inttostr>
|
||||||
|
self primitiveFailed.
|
||||||
|
}
|
||||||
|
|
||||||
#method to: end by: step do: aBlock
|
#method to: end by: step do: aBlock
|
||||||
{
|
{
|
||||||
|
@ -256,6 +256,8 @@ PROCESS TESTING
|
|||||||
'333333333333333333' dump.
|
'333333333333333333' dump.
|
||||||
'444444444444444444' dump.
|
'444444444444444444' dump.
|
||||||
"
|
"
|
||||||
|
|
||||||
|
|
||||||
(-2305843009213693952 - 1) dump.
|
(-2305843009213693952 - 1) dump.
|
||||||
|
|
||||||
(1 + 2) dump.
|
(1 + 2) dump.
|
||||||
@ -297,6 +299,7 @@ PROCESS TESTING
|
|||||||
(-270000000000000000000000000000000000000000000000000000000000000000000 \\ -1) dump.
|
(-270000000000000000000000000000000000000000000000000000000000000000000 \\ -1) dump.
|
||||||
(-270000000000000000000000000000000000000000000000000000000000000000000 // -1) dump.
|
(-270000000000000000000000000000000000000000000000000000000000000000000 // -1) dump.
|
||||||
|
|
||||||
|
(-27029038 // 2) asString dump.
|
||||||
|
|
||||||
##(0 rem: -50) dump.
|
##(0 rem: -50) dump.
|
||||||
##(0 quo: -50) dump.
|
##(0 quo: -50) dump.
|
||||||
|
@ -159,6 +159,7 @@ static STIX_INLINE int is_integer (stix_t* stix, stix_oop_t oop)
|
|||||||
c = STIX_CLASSOF(stix,oop);
|
c = STIX_CLASSOF(stix,oop);
|
||||||
|
|
||||||
/* TODO: is it better to introduce a special integer mark into the class itself */
|
/* TODO: is it better to introduce a special integer mark into the class itself */
|
||||||
|
/* TODO: or should it check if it's a subclass, subsubclass, subsubsubclass, etc of a large_integer as well? */
|
||||||
return c == stix->_small_integer ||
|
return c == stix->_small_integer ||
|
||||||
c == stix->_large_positive_integer ||
|
c == stix->_large_positive_integer ||
|
||||||
c == stix->_large_negative_integer;
|
c == stix->_large_negative_integer;
|
||||||
@ -1128,7 +1129,6 @@ stix_oop_t stix_divints (stix_t* stix, stix_oop_t x, stix_oop_t y, int modulo, s
|
|||||||
return STIX_SMOOI_TO_OOP(0);
|
return STIX_SMOOI_TO_OOP(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* In C89, integer division with a negative number is
|
/* In C89, integer division with a negative number is
|
||||||
* implementation dependent. In C99, it truncates towards zero.
|
* implementation dependent. In C99, it truncates towards zero.
|
||||||
*
|
*
|
||||||
@ -1210,10 +1210,14 @@ stix_oop_t stix_divints (stix_t* stix, stix_oop_t x, stix_oop_t y, int modulo, s
|
|||||||
|
|
||||||
return STIX_SMOOI_TO_OOP((stix_ooi_t)q);
|
return STIX_SMOOI_TO_OOP((stix_ooi_t)q);
|
||||||
}
|
}
|
||||||
else if (STIX_OOP_IS_SMOOI(x))
|
else
|
||||||
|
{
|
||||||
|
if (STIX_OOP_IS_SMOOI(x))
|
||||||
{
|
{
|
||||||
stix_ooi_t v;
|
stix_ooi_t v;
|
||||||
|
|
||||||
|
if (!is_integer(stix,y)) goto oops_einval;
|
||||||
|
|
||||||
v = STIX_OOP_TO_SMOOI(x);
|
v = STIX_OOP_TO_SMOOI(x);
|
||||||
if (v == 0)
|
if (v == 0)
|
||||||
{
|
{
|
||||||
@ -1229,6 +1233,8 @@ stix_oop_t stix_divints (stix_t* stix, stix_oop_t x, stix_oop_t y, int modulo, s
|
|||||||
{
|
{
|
||||||
stix_ooi_t v;
|
stix_ooi_t v;
|
||||||
|
|
||||||
|
if (!is_integer(stix,x)) goto oops_einval;
|
||||||
|
|
||||||
v = STIX_OOP_TO_SMOOI(y);
|
v = STIX_OOP_TO_SMOOI(y);
|
||||||
switch (v)
|
switch (v)
|
||||||
{
|
{
|
||||||
@ -1267,6 +1273,12 @@ if v is powerof2, do shifting???
|
|||||||
y = make_bigint_with_ooi (stix, v);
|
y = make_bigint_with_ooi (stix, v);
|
||||||
stix_poptmp (stix);
|
stix_poptmp (stix);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!is_integer(stix,x)) goto oops_einval;
|
||||||
|
if (!is_integer(stix,y)) goto oops_einval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
x_neg = (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer);
|
x_neg = (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer);
|
||||||
y_neg = (STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer);
|
y_neg = (STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer);
|
||||||
@ -1336,6 +1348,10 @@ if v is powerof2, do shifting???
|
|||||||
|
|
||||||
if (rem) *rem = r;
|
if (rem) *rem = r;
|
||||||
return normalize_bigint (stix, z);
|
return normalize_bigint (stix, z);
|
||||||
|
|
||||||
|
oops_einval:
|
||||||
|
stix->errnum = STIX_EINVAL;
|
||||||
|
return STIX_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -1562,14 +1578,6 @@ stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len,
|
|||||||
while (ptr < end);
|
while (ptr < end);
|
||||||
}
|
}
|
||||||
|
|
||||||
{ int i;
|
|
||||||
for (i = hwlen; i > 0;)
|
|
||||||
{
|
|
||||||
printf ("%0*lx ", (int)(STIX_SIZEOF(stix_liw_t) * 2), (unsigned long)hwp[--i]);
|
|
||||||
}
|
|
||||||
printf ("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
STIX_ASSERT (hwlen >= 1);
|
STIX_ASSERT (hwlen >= 1);
|
||||||
#if defined(STIX_USE_FULL_WORD)
|
#if defined(STIX_USE_FULL_WORD)
|
||||||
if (hwlen == 1)
|
if (hwlen == 1)
|
||||||
@ -1615,37 +1623,113 @@ oops_einval:
|
|||||||
static stix_oow_t oow_to_text (stix_oow_t w, int radix, stix_ooch_t* buf)
|
static stix_oow_t oow_to_text (stix_oow_t w, int radix, stix_ooch_t* buf)
|
||||||
{
|
{
|
||||||
stix_ooch_t* ptr;
|
stix_ooch_t* ptr;
|
||||||
static char* c = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
static char* digitc = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
|
||||||
STIX_ASSERT (radix >= 2 && radix <= 36);
|
STIX_ASSERT (radix >= 2 && radix <= 36);
|
||||||
|
|
||||||
ptr = buf;
|
ptr = buf;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
*ptr++ = c[w % radix];
|
*ptr++ = digitc[w % radix];
|
||||||
w /= radix;
|
w /= radix;
|
||||||
}
|
}
|
||||||
while (w <= 0);
|
while (w > 0);
|
||||||
|
|
||||||
return ptr - buf;
|
return ptr - buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void reverse_string (stix_ooch_t* str, stix_oow_t len)
|
||||||
|
{
|
||||||
|
stix_ooch_t ch;
|
||||||
|
stix_ooch_t* start = str;
|
||||||
|
stix_ooch_t* end = str + len - 1;
|
||||||
|
|
||||||
|
while (start < end)
|
||||||
|
{
|
||||||
|
ch = *start;
|
||||||
|
*start++ = *end;
|
||||||
|
*end-- = ch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stix_oop_t stix_inttostr (stix_t* stix, stix_oop_t num, int radix)
|
stix_oop_t stix_inttostr (stix_t* stix, stix_oop_t num, int radix)
|
||||||
{
|
{
|
||||||
stix_oow_t w;
|
stix_oow_t w;
|
||||||
|
stix_ooi_t v = 0;
|
||||||
|
|
||||||
if (STIX_OOP_IS_SMOOI(num))
|
if (STIX_OOP_IS_SMOOI(num))
|
||||||
{
|
{
|
||||||
stix_ooi_t v;
|
v = STIX_OOP_TO_SMOOI(num);
|
||||||
|
if (v < 0)
|
||||||
|
{
|
||||||
|
w = -v;
|
||||||
|
v = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
w = v;
|
||||||
|
v = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!is_integer(stix,num))
|
||||||
|
{
|
||||||
|
goto oops_einval;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if STIX_LIW_BITS == STIX_OOW_BITS
|
||||||
|
if (STIX_OBJ_GET_SIZE(num) == 1)
|
||||||
|
{
|
||||||
|
w = ((stix_oop_word_t)num)->slot[0];
|
||||||
|
v = (STIX_OBJ_GET_CLASS(num) == stix->_large_negative_integer)? -1: 1;
|
||||||
|
}
|
||||||
|
#elif STIX_LIW_BITS == STIX_OOHW_BITS
|
||||||
|
if (STIX_OBJ_GET_SIZE(num) == 1)
|
||||||
|
{
|
||||||
|
w = ((stix_oop_halfword_t)num)->slot[0];
|
||||||
|
v = (STIX_OBJ_GET_CLASS(num) == stix->_large_negative_integer)? -1: 1;
|
||||||
|
}
|
||||||
|
else if (STIX_OBJ_GET_SIZE(num) == 2)
|
||||||
|
{
|
||||||
|
w = MAKE_WORD (((stix_oop_halfword_t)num)->slot[0], ((stix_oop_halfword_t)num)->slot[1]);
|
||||||
|
v = (STIX_OBJ_GET_CLASS(oop) == stix->_large_negative_integer)? -1: 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (v)
|
||||||
|
{
|
||||||
|
/* Use a static buffer for simple conversion as the largest
|
||||||
|
* size is known. The largest buffer is required for radix 2.
|
||||||
|
* For a binary conversion(radix 2), the number of bits is
|
||||||
|
* the maximum number of digits that can be produced. +1 is
|
||||||
|
* needed for the sign. */
|
||||||
stix_ooch_t buf[STIX_OOW_BITS + 1];
|
stix_ooch_t buf[STIX_OOW_BITS + 1];
|
||||||
stix_oow_t len;
|
stix_oow_t len;
|
||||||
|
|
||||||
v = STIX_OOP_TO_SMOOI(num);
|
|
||||||
w = (v < 0)? -v: v;
|
|
||||||
|
|
||||||
len = oow_to_text (w, radix, buf);
|
len = oow_to_text (w, radix, buf);
|
||||||
if (v < 0) buf[len++] = '-';
|
if (v < 0) buf[len++] = '-';
|
||||||
return stix_makestring (stix, buf, len, invert);
|
|
||||||
|
reverse_string (buf, len);
|
||||||
|
return stix_makestring (stix, buf, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Do it in a hard way */
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (is_less_unsigned_array (b, .s, a, as))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
r = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
while (1);
|
||||||
|
|
||||||
|
oops_einval:
|
||||||
|
stix->errnum = STIX_EINVAL;
|
||||||
|
return STIX_NULL;
|
||||||
|
}
|
||||||
|
@ -115,24 +115,6 @@ void print_object (stix_t* stix, stix_oop_t oop)
|
|||||||
printf ("$%.*s", (int)bcslen, bcs);
|
printf ("$%.*s", (int)bcslen, bcs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (STIX_OBJ_GET_CLASS(oop) == stix->_large_negative_integer)
|
|
||||||
{
|
|
||||||
stix_oow_t i;
|
|
||||||
printf ("-16r");
|
|
||||||
for (i = STIX_OBJ_GET_SIZE(oop); i > 0;)
|
|
||||||
{
|
|
||||||
printf ("%0*lX", (int)(STIX_SIZEOF(stix_liw_t) * 2), (unsigned long)((stix_oop_liword_t)oop)->slot[--i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (STIX_OBJ_GET_CLASS(oop) == stix->_large_positive_integer)
|
|
||||||
{
|
|
||||||
stix_oow_t i;
|
|
||||||
printf ("16r");
|
|
||||||
for (i = STIX_OBJ_GET_SIZE(oop); i > 0;)
|
|
||||||
{
|
|
||||||
printf ("%0*lX", (int)(STIX_SIZEOF(stix_liw_t) * 2), (unsigned long)((stix_oop_liword_t)oop)->slot[--i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stix_oop_class_t c;
|
stix_oop_class_t c;
|
||||||
@ -141,8 +123,28 @@ void print_object (stix_t* stix, stix_oop_t oop)
|
|||||||
stix_bch_t bcs[32];
|
stix_bch_t bcs[32];
|
||||||
stix_size_t ucslen, bcslen;
|
stix_size_t ucslen, bcslen;
|
||||||
|
|
||||||
c = (stix_oop_class_t)STIX_CLASSOF(stix, oop);
|
STIX_ASSERT (STIX_OOP_IS_POINTER(oop));
|
||||||
if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_CHAR)
|
c = (stix_oop_class_t)STIX_OBJ_GET_CLASS(oop); /*STIX_CLASSOF(stix, oop);*/
|
||||||
|
|
||||||
|
if (c == stix->_large_negative_integer)
|
||||||
|
{
|
||||||
|
stix_oow_t i;
|
||||||
|
printf ("-16r");
|
||||||
|
for (i = STIX_OBJ_GET_SIZE(oop); i > 0;)
|
||||||
|
{
|
||||||
|
printf ("%0*lX", (int)(STIX_SIZEOF(stix_liw_t) * 2), (unsigned long)((stix_oop_liword_t)oop)->slot[--i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (c == stix->_large_positive_integer)
|
||||||
|
{
|
||||||
|
stix_oow_t i;
|
||||||
|
printf ("16r");
|
||||||
|
for (i = STIX_OBJ_GET_SIZE(oop); i > 0;)
|
||||||
|
{
|
||||||
|
printf ("%0*lX", (int)(STIX_SIZEOF(stix_liw_t) * 2), (unsigned long)((stix_oop_liword_t)oop)->slot[--i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_CHAR)
|
||||||
{
|
{
|
||||||
if ((stix_oop_t)c == stix->_symbol) printf ("#");
|
if ((stix_oop_t)c == stix->_symbol) printf ("#");
|
||||||
else if ((stix_oop_t)c == stix->_string) printf ("'");
|
else if ((stix_oop_t)c == stix->_string) printf ("'");
|
||||||
@ -167,6 +169,25 @@ void print_object (stix_t* stix, stix_oop_t oop)
|
|||||||
}
|
}
|
||||||
printf ("]");
|
printf ("]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_HALFWORD)
|
||||||
|
{
|
||||||
|
printf ("#[["); /* TODO: fix this symbol */
|
||||||
|
for (i = 0; i < STIX_OBJ_GET_SIZE(oop); i++)
|
||||||
|
{
|
||||||
|
printf (" %lX", (unsigned long int)((stix_oop_halfword_t)oop)->slot[i]);
|
||||||
|
}
|
||||||
|
printf ("]]");
|
||||||
|
}
|
||||||
|
else if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_WORD)
|
||||||
|
{
|
||||||
|
printf ("#[[["); /* TODO: fix this symbol */
|
||||||
|
for (i = 0; i < STIX_OBJ_GET_SIZE(oop); i++)
|
||||||
|
{
|
||||||
|
printf (" %lX", (unsigned long int)((stix_oop_word_t)oop)->slot[i]);
|
||||||
|
}
|
||||||
|
printf ("]]]");
|
||||||
|
}
|
||||||
else if ((stix_oop_t)c == stix->_array)
|
else if ((stix_oop_t)c == stix->_array)
|
||||||
{
|
{
|
||||||
printf ("#(");
|
printf ("#(");
|
||||||
|
107
stix/lib/exec.c
107
stix/lib/exec.c
@ -118,7 +118,6 @@ static stix_oop_process_t make_process (stix_t* stix, stix_oop_context_t c)
|
|||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void switch_process (stix_t* stix, stix_oop_process_t proc)
|
static void switch_process (stix_t* stix, stix_oop_process_t proc)
|
||||||
{
|
{
|
||||||
if (stix->processor->active != proc)
|
if (stix->processor->active != proc)
|
||||||
@ -126,45 +125,58 @@ static void switch_process (stix_t* stix, stix_oop_process_t proc)
|
|||||||
printf ("ACTUAL PROCESS SWITCHING BF...%d %p\n", (int)stix->ip, stix->active_context);
|
printf ("ACTUAL PROCESS SWITCHING BF...%d %p\n", (int)stix->ip, stix->active_context);
|
||||||
|
|
||||||
/* store the active context to the active process */
|
/* store the active context to the active process */
|
||||||
|
STIX_ASSERT ((stix_oop_t)stix->processor->active != stix->_nil);
|
||||||
stix->processor->active->active_context = stix->active_context;
|
stix->processor->active->active_context = stix->active_context;
|
||||||
|
|
||||||
SWITCH_ACTIVE_CONTEXT (stix, proc->active_context);
|
SWITCH_ACTIVE_CONTEXT (stix, proc->active_context);
|
||||||
printf ("ACTUAL PROCESS SWITCHING AF...%d %p\n", (int)stix->ip, stix->active_context);
|
printf ("ACTUAL PROCESS SWITCHING AF...%d %p\n", (int)stix->ip, stix->active_context);
|
||||||
/*TODO: set the state to RUNNING */
|
/*TODO: set the state to RUNNING */
|
||||||
stix->processor->active = proc;
|
stix->processor->active = proc;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void switch_to_next_process (stix_t* stix)
|
static void switch_to_next_process (stix_t* stix)
|
||||||
{
|
{
|
||||||
/* TODO: this is experimental. rewrite it */
|
/* TODO: this is experimental. rewrite it */
|
||||||
if (stix->processor->active->next == stix->_nil)
|
if ((stix_oop_t)stix->processor->active->next == stix->_nil)
|
||||||
{
|
{
|
||||||
|
printf ("SWITCHING TO THE HEAD PROCESS\n");
|
||||||
switch_process (stix, stix->processor->head);
|
switch_process (stix, stix->processor->head);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
printf ("SWITCHING TO THE NEXT PROCESS\n");
|
||||||
switch_process (stix, stix->processor->active->next);
|
switch_process (stix, stix->processor->active->next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void schedule_process (stix_t* stix, stix_oop_process_t proc)
|
static STIX_INLINE int register_new_process (stix_t* stix, stix_oop_process_t proc)
|
||||||
{
|
|
||||||
if (proc->state == STIX_SMOOI_TO_OOP(0))
|
|
||||||
{
|
{
|
||||||
|
/* the process is not scheduled at all.
|
||||||
|
* link it to the processor's process list. */
|
||||||
stix_ooi_t tally;
|
stix_ooi_t tally;
|
||||||
|
|
||||||
|
STIX_ASSERT (proc->state == STIX_SMOOI_TO_OOP(0));
|
||||||
STIX_ASSERT ((stix_oop_t)proc->prev == stix->_nil);
|
STIX_ASSERT ((stix_oop_t)proc->prev == stix->_nil);
|
||||||
STIX_ASSERT ((stix_oop_t)proc->next == stix->_nil);
|
STIX_ASSERT ((stix_oop_t)proc->next == stix->_nil);
|
||||||
|
STIX_ASSERT ((stix_oop_t)proc->active_context == stix->_nil);
|
||||||
|
|
||||||
tally = STIX_OOP_TO_SMOOI(stix->processor->tally);
|
tally = STIX_OOP_TO_SMOOI(stix->processor->tally);
|
||||||
if (tally <= 0)
|
if (tally <= 0)
|
||||||
{
|
{
|
||||||
|
/* the process schedule has no process.
|
||||||
|
* it is the first process */
|
||||||
stix->processor->head = proc;
|
stix->processor->head = proc;
|
||||||
stix->processor->tail = proc;
|
stix->processor->tail = proc;
|
||||||
stix->processor->tally = STIX_SMOOI_TO_OOP(1);
|
stix->processor->tally = STIX_SMOOI_TO_OOP(1);
|
||||||
printf ("ADD NEW PROCESS X - %d\n", (int)1);
|
printf ("ADD NEW PROCESS X - %d\n", (int)1);
|
||||||
}
|
}
|
||||||
|
else if (tally >= STIX_SMOOI_MAX)
|
||||||
|
{
|
||||||
|
printf ("TOO MANY PROCESS\n");
|
||||||
|
stix->errnum = STIX_EPFULL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* TODO: over flow check or maximum number of process check using the tally field? */
|
/* TODO: over flow check or maximum number of process check using the tally field? */
|
||||||
@ -177,15 +189,27 @@ printf ("ADD NEW PROCESS Y - %d\n", (int)tally + 1);
|
|||||||
|
|
||||||
proc->state = STIX_SMOOI_TO_OOP(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;
|
proc->active_context = proc->initial_context;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int schedule_process (stix_t* stix, stix_oop_process_t proc)
|
||||||
|
{
|
||||||
|
if (proc->state == STIX_SMOOI_TO_OOP(0))
|
||||||
|
{
|
||||||
|
/* the process is not scheduled at all. it must not exist in the
|
||||||
|
* process list of the process scheduler. */
|
||||||
|
if (register_new_process (stix, proc) <= -1) return -1;
|
||||||
switch_process (stix, proc);
|
switch_process (stix, proc);
|
||||||
}
|
}
|
||||||
else if (stix->processor->active != proc)
|
else if (stix->processor->active != proc)
|
||||||
{
|
{
|
||||||
switch_process (stix, proc);
|
switch_process (stix, proc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
static stix_oop_process_t start_new_process (stix_t* stix, stix_oop_context_t c)
|
static stix_oop_process_t start_new_process (stix_t* stix, stix_oop_context_t c)
|
||||||
{
|
{
|
||||||
stix_oop_process_t proc;
|
stix_oop_process_t proc;
|
||||||
@ -193,10 +217,29 @@ static stix_oop_process_t start_new_process (stix_t* stix, stix_oop_context_t c)
|
|||||||
proc = make_process (stix, c);
|
proc = make_process (stix, c);
|
||||||
if (!proc) return STIX_NULL;
|
if (!proc) return STIX_NULL;
|
||||||
|
|
||||||
schedule_process (stix, proc);
|
if (schedule_process (stix, proc) <= -1) return STIX_NULL;
|
||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static stix_oop_process_t start_initial_process (stix_t* stix, stix_oop_context_t c)
|
||||||
|
{
|
||||||
|
stix_oop_process_t proc;
|
||||||
|
|
||||||
|
proc = make_process (stix, c);
|
||||||
|
if (!proc) return STIX_NULL;
|
||||||
|
|
||||||
|
if (register_new_process (stix, proc) <= -1) return STIX_NULL;
|
||||||
|
|
||||||
|
/* do somthing that schedule_process() would do with less overhead */
|
||||||
|
STIX_ASSERT ((stix_oop_t)proc->active_context != stix->_nil);
|
||||||
|
STIX_ASSERT (proc->active_context == proc->initial_context);
|
||||||
|
SWITCH_ACTIVE_CONTEXT (stix, proc->active_context);
|
||||||
|
/*TODO: set the state to RUNNING */
|
||||||
|
stix->processor->active = proc;
|
||||||
|
|
||||||
|
return proc;
|
||||||
|
}
|
||||||
|
|
||||||
static STIX_INLINE int activate_new_method (stix_t* stix, stix_oop_method_t mth)
|
static STIX_INLINE int activate_new_method (stix_t* stix, stix_oop_method_t mth)
|
||||||
{
|
{
|
||||||
@ -480,11 +523,12 @@ TODO: overcome this problem
|
|||||||
stix->active_context = ctx;
|
stix->active_context = ctx;
|
||||||
ACTIVE_STACK_PUSH (stix, ass->value); /* push the receiver */
|
ACTIVE_STACK_PUSH (stix, ass->value); /* push the receiver */
|
||||||
|
|
||||||
STORE_ACTIVE_IP (stix);
|
STORE_ACTIVE_IP (stix); /* stix->active_context->ip = STIX_SMOOI_TO_OOP(stix->ip) */
|
||||||
STORE_ACTIVE_SP (stix);
|
STORE_ACTIVE_SP (stix); /* stix->active_context->sp = STIX_SMOOI_TO_OOP(stix->sp) */
|
||||||
|
|
||||||
stix_pushtmp (stix, (stix_oop_t*)&mth);
|
stix_pushtmp (stix, (stix_oop_t*)&mth);
|
||||||
proc = start_new_process (stix, ctx);
|
/* call start_initial_process() intead of start_new_process() */
|
||||||
|
proc = start_initial_process (stix, ctx);
|
||||||
stix_poptmp (stix);
|
stix_poptmp (stix);
|
||||||
if (!proc) return -1;
|
if (!proc) return -1;
|
||||||
|
|
||||||
@ -1291,10 +1335,24 @@ static int prim_integer_ge (stix_t* stix, stix_ooi_t nargs)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: handle LargeInteger */
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int prim_integer_inttostr (stix_t* stix, stix_ooi_t nargs)
|
||||||
|
{
|
||||||
|
stix_oop_t rcv, str;
|
||||||
|
|
||||||
|
STIX_ASSERT (nargs == 0);
|
||||||
|
|
||||||
|
rcv = ACTIVE_STACK_GET(stix, stix->sp);
|
||||||
|
|
||||||
|
str = stix_inttostr (stix, rcv, 10);
|
||||||
|
if (!str) return (stix->errnum == STIX_EINVAL? 0: -1);
|
||||||
|
|
||||||
|
ACTIVE_STACK_SETTOP (stix, str);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int prim_processor_schedule (stix_t* stix, stix_ooi_t nargs)
|
static int prim_processor_schedule (stix_t* stix, stix_ooi_t nargs)
|
||||||
{
|
{
|
||||||
stix_oop_t rcv, arg;
|
stix_oop_t rcv, arg;
|
||||||
@ -1309,7 +1367,12 @@ static int prim_processor_schedule (stix_t* stix, stix_ooi_t nargs)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
schedule_process (stix, (stix_oop_process_t)arg);
|
if (!schedule_process (stix, (stix_oop_process_t)arg))
|
||||||
|
{
|
||||||
|
/* TODO: Can this be a soft failure? */
|
||||||
|
return (stix->errnum == STIX_EPFULL)? 0: -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1537,13 +1600,21 @@ printf ("CALL ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSUPPORTED_MODE);
|
|||||||
case 's':
|
case 's':
|
||||||
{
|
{
|
||||||
stix_size_t bcslen, ucslen;
|
stix_size_t bcslen, ucslen;
|
||||||
stix_uch_t ucs[1024];
|
stix_ooch_t ucs[1024];
|
||||||
|
stix_oop_t s;
|
||||||
char* r = dcCallPointer (dc, f);
|
char* r = dcCallPointer (dc, f);
|
||||||
|
|
||||||
bcslen = strlen(r);
|
bcslen = strlen(r);
|
||||||
stix_utf8toucs (r, &bcslen, ucs, &ucslen); /* proper string conversion */
|
stix_utf8toucs (r, &bcslen, ucs, &ucslen); /* proper string conversion */
|
||||||
|
|
||||||
ACTIVE_STACK_SETTOP (stix, stix_makestring(stix, ucs, ucslen)); /* TODO: proper error h andling */
|
s = stix_makestring(stix, ucs, ucslen)
|
||||||
|
if (!s)
|
||||||
|
{
|
||||||
|
dcFree (dc);
|
||||||
|
return -1; /* TODO: proper error h andling */
|
||||||
|
}
|
||||||
|
|
||||||
|
ACTIVE_STACK_SETTOP (stix, s);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1643,6 +1714,7 @@ static prim_t primitives[] =
|
|||||||
{ 1, prim_integer_gt, "_integer_gt" },
|
{ 1, prim_integer_gt, "_integer_gt" },
|
||||||
{ 1, prim_integer_le, "_integer_le" },
|
{ 1, prim_integer_le, "_integer_le" },
|
||||||
{ 1, prim_integer_ge, "_integer_ge" },
|
{ 1, prim_integer_ge, "_integer_ge" },
|
||||||
|
{ 0, prim_integer_inttostr, "_integer_inttostr" },
|
||||||
|
|
||||||
{ 1, prim_processor_schedule, "_processor_schedule" },
|
{ 1, prim_processor_schedule, "_processor_schedule" },
|
||||||
{ 1, prim_processor_remove, "_processor_remove" },
|
{ 1, prim_processor_remove, "_processor_remove" },
|
||||||
@ -1831,11 +1903,9 @@ int stix_execute (stix_t* stix)
|
|||||||
|
|
||||||
STIX_ASSERT (stix->active_context != STIX_NULL);
|
STIX_ASSERT (stix->active_context != STIX_NULL);
|
||||||
|
|
||||||
|
printf ("QQQQQQQQQQQQQQQQQQQQQQQQQq\n");
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
printf ("IP<BF> => %d\n", (int)stix->ip);
|
printf ("IP<BF> => %d\n", (int)stix->ip);
|
||||||
#endif
|
#endif
|
||||||
@ -2324,9 +2394,10 @@ print_object (stix, (stix_oop_t)selector);
|
|||||||
fflush (stdout);
|
fflush (stdout);
|
||||||
#endif
|
#endif
|
||||||
STIX_ASSERT (STIX_CLASSOF(stix, selector) == stix->_symbol);
|
STIX_ASSERT (STIX_CLASSOF(stix, selector) == stix->_symbol);
|
||||||
|
|
||||||
newrcv = ACTIVE_STACK_GET(stix, stix->sp - b1);
|
newrcv = ACTIVE_STACK_GET(stix, stix->sp - b1);
|
||||||
|
|
||||||
#if defined(STIX_DEBUG_EXEC)
|
#if defined(STIX_DEBUG_EXEC)
|
||||||
|
printf ("NEWRCV => %p\n", newrcv);
|
||||||
printf (" RECEIVER = ");
|
printf (" RECEIVER = ");
|
||||||
print_object(stix, newrcv);
|
print_object(stix, newrcv);
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
|
@ -291,6 +291,7 @@ void stix_gc (stix_t* stix)
|
|||||||
stix->_object = stix_moveoop (stix, stix->_object);
|
stix->_object = stix_moveoop (stix, stix->_object);
|
||||||
stix->_array = stix_moveoop (stix, stix->_array);
|
stix->_array = stix_moveoop (stix, stix->_array);
|
||||||
stix->_byte_array = stix_moveoop (stix, stix->_byte_array);
|
stix->_byte_array = stix_moveoop (stix, stix->_byte_array);
|
||||||
|
|
||||||
stix->_string = stix_moveoop (stix, stix->_string);
|
stix->_string = stix_moveoop (stix, stix->_string);
|
||||||
stix->_symbol = stix_moveoop (stix, stix->_symbol);
|
stix->_symbol = stix_moveoop (stix, stix->_symbol);
|
||||||
stix->_symbol_set = stix_moveoop (stix, stix->_symbol_set);
|
stix->_symbol_set = stix_moveoop (stix, stix->_symbol_set);
|
||||||
|
@ -217,7 +217,6 @@ stix_oop_t stix_instantiate (stix_t* stix, stix_oop_t _class, const void* vptr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
stix_pushtmp (stix, &_class); tmp_count++;
|
stix_pushtmp (stix, &_class); tmp_count++;
|
||||||
/*TODO: protected vptr if it's not STIX_NULL and the variability(indexed_type) is OOP. the current impl is buggy */
|
|
||||||
|
|
||||||
switch (indexed_type)
|
switch (indexed_type)
|
||||||
{
|
{
|
||||||
@ -229,13 +228,18 @@ stix_oop_t stix_instantiate (stix_t* stix, stix_oop_t _class, const void* vptr,
|
|||||||
STIX_ASSERT (vptr == STIX_NULL);
|
STIX_ASSERT (vptr == STIX_NULL);
|
||||||
/*
|
/*
|
||||||
This function is not GC-safe. so i don't want to initialize
|
This function is not GC-safe. so i don't want to initialize
|
||||||
propagate the payload of a pointer object. The caller can
|
the payload of a pointer object. The caller can call this
|
||||||
call this function and initialize payloads then.
|
function and initialize payloads then.
|
||||||
if (oop && vptr && vlen > 0)
|
if (oop && vptr && vlen > 0)
|
||||||
{
|
{
|
||||||
stix_oop_oop_t hdr = (stix_oop_oop_t)oop;
|
stix_oop_oop_t hdr = (stix_oop_oop_t)oop;
|
||||||
STIX_MEMCPY (&hdr->slot[named_instvar], vptr, vlen * STIX_SIZEOF(stix_oop_t));
|
STIX_MEMCPY (&hdr->slot[named_instvar], vptr, vlen * STIX_SIZEOF(stix_oop_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
For the above code to work, it should protect the elements of
|
||||||
|
the vptr array with stix_pushtmp(). So it might be better
|
||||||
|
to disallow a non-NULL vptr when indexed_type is OOP. See
|
||||||
|
the assertion above this comment block.
|
||||||
*/
|
*/
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
#define STIX_USE_OBJECT_TRAILER
|
#define STIX_USE_OBJECT_TRAILER
|
||||||
|
|
||||||
/* this is for gc debugging */
|
/* this is for gc debugging */
|
||||||
/*#define STIX_DEBUG_GC_001*/
|
#define STIX_DEBUG_GC_001
|
||||||
/*#define STIX_DEBUG_EXEC*/
|
/*#define STIX_DEBUG_EXEC*/
|
||||||
#define STIX_PROFILE_EXEC
|
#define STIX_PROFILE_EXEC
|
||||||
|
|
||||||
@ -960,6 +960,7 @@ stix_oop_t stix_makestring (
|
|||||||
stix_oow_t len
|
stix_oow_t len
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
/* dic.c */
|
/* dic.c */
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
@ -1103,6 +1104,13 @@ stix_oop_t stix_strtoint (
|
|||||||
stix_oow_t len,
|
stix_oow_t len,
|
||||||
int radix
|
int radix
|
||||||
);
|
);
|
||||||
|
|
||||||
|
stix_oop_t stix_inttostr (
|
||||||
|
stix_t* stix,
|
||||||
|
stix_oop_t num,
|
||||||
|
int radix
|
||||||
|
);
|
||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
/* comp.c */
|
/* comp.c */
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
|
@ -244,9 +244,6 @@ void stix_deregcb (stix_t* stix, stix_cb_t* cb)
|
|||||||
stix_freemem (stix, cb);
|
stix_freemem (stix, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void* stix_allocmem (stix_t* stix, stix_size_t size)
|
void* stix_allocmem (stix_t* stix, stix_size_t size)
|
||||||
{
|
{
|
||||||
void* ptr;
|
void* ptr;
|
||||||
|
@ -50,6 +50,7 @@ enum stix_errnum_t
|
|||||||
STIX_ERANGE, /**< range error. overflow and underflow */
|
STIX_ERANGE, /**< range error. overflow and underflow */
|
||||||
STIX_ENOENT, /**< no matching entry */
|
STIX_ENOENT, /**< no matching entry */
|
||||||
STIX_EDFULL, /**< dictionary full */
|
STIX_EDFULL, /**< dictionary full */
|
||||||
|
STIX_EPFULL, /**< processor full */
|
||||||
STIX_EDIVBY0, /**< divide by zero */
|
STIX_EDIVBY0, /**< divide by zero */
|
||||||
STIX_EIOERR, /**< I/O error */
|
STIX_EIOERR, /**< I/O error */
|
||||||
STIX_EECERR, /**< encoding conversion error */
|
STIX_EECERR, /**< encoding conversion error */
|
||||||
|
Loading…
Reference in New Issue
Block a user