fixed the bug not popping an argument in the _integer_inttostr primitive.

added a new primitive _processor_return_to_and_eval to support proper exception handling
This commit is contained in:
hyunghwan.chung 2016-06-13 15:52:09 +00:00
parent 1ab2faaf1f
commit f22b896ed2
11 changed files with 180 additions and 72 deletions

View File

@ -55,10 +55,10 @@
{
## concatenate two strings.
## TOOD: make this a primitive for performance.
| newsize newstr self_ubound|
| newsize newstr self_ubound |
newsize := self basicSize + aString basicSize.
##newstr := self class basicNew: newsize.
newstr := String basicNew: newsize. ## TODO: redefine , for symbol... it's a work arouind... symbols are not contacated to a symbol at this moment.
newstr := String basicNew: newsize. ## TODO: redefine , for symbol... it's a work arouind... symbols are not concatenated to a symbol at this moment.
self_ubound := self ubound.
0 to: self_ubound do: [:i | newstr at: i put: (self at: i)].
0 to: (aString ubound) do: [:i | newstr at: (i + self_ubound + 1) put: (aString at: i)].

View File

@ -328,13 +328,15 @@ thisContext isExceptionHandlerContext dump.
#method ensure: aBlock
{
## TODO: ensure that the ensured block is executed after exception handler...
| value |
value := self on: Exception do: [:ex | aBlock value. ex pass].
## value := self valueAndResumeOnUnwind.
| v |
v := self on: Exception do: [:ex |
aBlock value.
ex pass
].
aBlock value.
^value
^v
}
#method ifCurtailed: aBlock
@ -424,8 +426,21 @@ thisContext isExceptionHandlerContext dump.
#method handleException
{
self.handlerContext notNil
ifTrue: [
Processor return: (self.handlerBlock value: self) to: (self.handlerContext sender)
ifTrue: [
##'RETURNING TO....' dump.
##self.handlerContext dump.
##self.handlerContext sender dump.
##' ............' dump.
## arrange to execute the hander block after having returned
## to the sender of the exception handler context.
## if handler block is evaluated before returning, an
## exception raised in the handler block causes a kind of
## a recursive call to here.
##Processor return: (self.handlerBlock value: self) to: (self.handlerContext sender)
## so use a different primitive method that evaluate the block
## after having returned to the given context.
Processor returnTo: (self.handlerContext sender) andEval: (self.handlerBlock) with: self.
]
ifFalse: [
('### EXCEPTION NOT HANDLED #### ', self class name, ' - ', self messageText) dump.
@ -434,13 +449,6 @@ thisContext isExceptionHandlerContext dump.
].
}
## #method handlerContext
## {
## (self.handlerContext notNil) ifTrue: [ ^self.handlerContext ].
## self findHandlerContextStartingFrom: self.signalContext.
## ^self.handlerContext.
## }
#method findHandlerContextStartingFrom: aContext
{
## Find exception handling context starting from a given context
@ -448,19 +456,21 @@ thisContext isExceptionHandlerContext dump.
ctx := aContext.
[ ctx notNil ] whileTrue: [
##(ctx handles: self) ifTrue: [ ^ ctx ].
(ctx isExceptionHandlerContext) ifTrue: [
| blk |
blk := ctx findExceptionHandlerBlock: (self class).
(blk notNil) ifTrue: [
self.handlerBlock := blk.
self.handlerContext := ctx.
^ctx
].
##ctx dump.
##(ctx handles: self) ifTrue: [ ^ ctx ].
(ctx isExceptionHandlerContext) ifTrue: [
| blk |
blk := ctx findExceptionHandlerBlock: (self class).
(blk notNil) ifTrue: [
self.handlerBlock := blk.
self.handlerContext := ctx.
##'-------------' dump.
^ctx
].
ctx := ctx sender
].
ctx := ctx sender
].
##'-------------' dump.
## no handler is found
self.handlerBlock := nil.
self.handlerContext := nil.

View File

@ -401,6 +401,12 @@
self primitiveFailed.
}
#method returnTo: anObject andEval: aBlock with: arg
{
<primitive: #_processor_return_to_and_eval>
self primitiveFailed.
}
#method forceContext: aContext
{
<primitive: #_processor_force_context>

View File

@ -25,6 +25,10 @@
#class Character(Magnitude)
{
## #method basicSize
## {
## ^0
## }
}
#class Number(Magnitude)
@ -153,7 +157,7 @@
#method asString
{
self printStringRadix: 10
^self printStringRadix: 10
}
#method printStringRadix: aNumber
@ -213,6 +217,10 @@
#class SmallInteger(Integer)
{
## #method basicSize
## {
## ^0
## }
}
#class(#liword) LargeInteger(Integer)

View File

@ -67,7 +67,7 @@
}
#method(#class) main
#method(#class) main987
{
|t1 t2 s1 s2 s3|
@ -110,20 +110,43 @@
s1 wait.
"
"
}
#method(#class) main
{
| v1 |
'START OF MAIN' dump.
##[1 xxx] ifCurtailed: ['XXXXXXXX CURTAILED XXXXXXXXX' dump].
##['ENSURE TEST' dump] ensure: ['XXXXXXXXX ENSURE XXXXXXXXXXXXXx' dump].
v1 := [ ['kkk' dump.] ensure: ['XXXXXXXXX ENSURE XXXXXXXXXXXXXx' dump. 30] ] on: Exception do: [:ex | 'EXCEPTION OUTSIDE ENSURE...' dump. ].
v1 dump.
##v1 := [ ['kkk' dump.] ensure: ['XXXXXXXXX ENSURE XXXXXXXXXXXXXx' dump. 30] ] on: Exception do: [:ex | 'EXCEPTION OUTSIDE ENSURE...' dump. ].
##v1 dump.
'END OF MAIN' dump."
##[ Exception signal: 'simulated error' ] on: Exception do: [:ex | 'CAUGHT...' dump. Exception signal: 'jjjjjjj' ].
"[
[ Exception signal: 'simulated error' ] ensure: ['ensure 1' dump ].
] on: Exception do: [:ex | ('EXCETION - ' , ex messageText) dump. Exception signal: 'qqq'. ]."
"[1 xxx] ifCurtailed: ['XXXXXXXX CURTAILED XXXXXXXXX' dump. Exception signal: 'jjjj']."
v1 := [
| k |
k := 99.
[
[ Exception signal: 'simulated error' ] ensure: [('ensure 1 ', (k asString)) dump ].
] ensure: ['ensure 2' dump ].
] on: Exception do: [:ex |
('EXCETION - ' , ex messageText) dump.
## Exception signal: 'qqq'.
].
'--------------------------------' dump.
v1 dump.
'END OF MAIN' dump.
}
#method(#class) main22222
{
|t1 t2 s1 s2 s3|

View File

@ -40,11 +40,19 @@
#method(#class) main2
{
| k |
'BEGINNING OF main2' dump.
k := ['this is test-011' dump. Exception signal: 'main2 screwed...'. 8888 dump. ]
on: Exception do: [ :ex | 'Exception occurred' dump. ex messageText dump. 'Getting back to....' dump. "ex return: 9999." ex pass. 'AFTER RETURN' dump. ].
on: Exception do: [ :ex |
'Exception occurred' dump.
ex messageText dump.
'Getting back to....' dump.
"ex return: 9999."
ex pass.
'AFTER RETURN' dump.
].
k dump.
'END OF test-011' dump.
'END OF main2' dump.
}
#method(#class) raise_exception
@ -138,33 +146,45 @@
## exception is raised in a new process. it can't be captured
## by an exception handler of a calling process.
## exception handling must not cross the process boundary.
'BEGINNING OF test11' dump.
[
|p |
p := [Exception signal: 'Sample Exception' ] newProcess.
p := [ Exception signal: 'Exception in a new process of test11'. ] newProcess.
'JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ' dump.
p resume.
] on: Exception do: [:ex | 'EXCEPTION ----------' dump. ex messageText dump ].
'END OF test11' dump.
}
#method(#class) test12
{
'BEGINNING OF test12' dump.
[
|p |
p := [
[ Exception signal: 'Sample Exception' ] on: Exception do: [:ex | 'EXCEPTION CAUGHT...' dump. ex messageText dump. ]
[ Exception signal: 'Exception in a new process of test12' ]
on: Exception do: [:ex |
('EXCEPTION CAUGHT...in test12 ==> ', (ex messageText)) dump.
]
] newProcess.
'JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ' dump.
p resume.
] on: Exception do: [:ex | 'EXCEPTION ----------' dump. ex messageText dump ].
'END OF test12' dump.
}
#method(#class) main
{
'>>>>> BEGINNING OF MAIN' dump.
## [ self main2 ] on: Exception do: [ :ex | 'EXCEPTION CAUGHT IN MAIN....' dump. ex messageText dump. "ex pass." ex resume. ].
[ self main2 ] on: Exception do: [ :ex |
'EXCEPTION CAUGHT IN MAIN....' dump.
ex messageText dump.
"ex pass."
'Returning back to where the exception has signalled in main2...' dump.
ex resume.
].
'##############################' dump.
## self test3.
@ -173,7 +193,7 @@
## self test5.
self test11.
## self test12.
##100 timesRepeat: ['>>>>> END OF MAIN' dump].
## 100 timesRepeat: ['>>>>> END OF MAIN' dump].
"(Exception isKindOf: Apex) dump.

View File

@ -139,7 +139,7 @@
#if defined(STIX_DEBUG_VM_EXEC)
# define LOG_MASK_INST (STIX_LOG_VM | STIX_LOG_MNEMONIC)
# define LOG_MASK_INST (STIX_LOG_IC | STIX_LOG_MNEMONIC)
# define LOG_INST_0(stix,fmt) STIX_LOG0(stix, LOG_MASK_INST, "\t" fmt "\n")
# define LOG_INST_1(stix,fmt,a1) STIX_LOG1(stix, LOG_MASK_INST, "\t" fmt "\n",a1)
@ -301,7 +301,7 @@ static stix_oop_process_t make_process (stix_t* stix, stix_oop_context_t c)
STIX_ASSERT ((stix_oop_t)c->sender == stix->_nil);
#if defined(STIX_DEBUG_VM_PROCESSOR)
STIX_LOG2 (stix, STIX_LOG_VM | STIX_LOG_DEBUG, "Processor - made process %O of size %zd\n", proc, STIX_OBJ_GET_SIZE(proc));
STIX_LOG2 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Processor - made process %O of size %zd\n", proc, STIX_OBJ_GET_SIZE(proc));
#endif
return proc;
}
@ -309,7 +309,7 @@ static stix_oop_process_t make_process (stix_t* stix, stix_oop_context_t c)
static STIX_INLINE void sleep_active_process (stix_t* stix, int state)
{
#if defined(STIX_DEBUG_VM_PROCESSOR)
STIX_LOG3 (stix, STIX_LOG_VM | STIX_LOG_DEBUG, "Processor - put process %O context %O ip=%zd to sleep\n", stix->processor->active, stix->active_context, stix->ip);
STIX_LOG3 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Processor - put process %O context %O ip=%zd to sleep\n", stix->processor->active, stix->active_context, stix->ip);
#endif
#if defined(STIX_USE_PROCSTK)
@ -341,7 +341,7 @@ static STIX_INLINE void wake_new_process (stix_t* stix, stix_oop_process_t proc)
SWITCH_ACTIVE_CONTEXT (stix, proc->current_context);
#if defined(STIX_DEBUG_VM_PROCESSOR)
STIX_LOG3 (stix, STIX_LOG_VM | STIX_LOG_DEBUG, "Processor - woke up process %O context %O ip=%zd\n", stix->processor->active, stix->active_context, stix->ip);
STIX_LOG3 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Processor - woke up process %O context %O ip=%zd\n", stix->processor->active, stix->active_context, stix->ip);
#endif
}
@ -395,7 +395,7 @@ static STIX_INLINE int chain_into_processor (stix_t* stix, stix_oop_process_t pr
if (tally >= STIX_SMOOI_MAX)
{
#if defined(STIX_DEBUG_VM_PROCESSOR)
STIX_LOG0 (stix, STIX_LOG_VM | STIX_LOG_FATAL, "Processor - too many process\n");
STIX_LOG0 (stix, STIX_LOG_IC | STIX_LOG_FATAL, "Processor - too many process\n");
#endif
stix->errnum = STIX_EPFULL;
return -1;
@ -494,7 +494,7 @@ static void terminate_process (stix_t* stix, stix_oop_process_t proc)
/* RUNNING/RUNNABLE ---> TERMINATED */
#if defined(STIX_DEBUG_VM_PROCESSOR)
STIX_LOG1 (stix, STIX_LOG_VM | STIX_LOG_DEBUG, "Processor - process %O RUNNING/RUNNABLE->TERMINATED\n", proc);
STIX_LOG1 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Processor - process %O RUNNING/RUNNABLE->TERMINATED\n", proc);
#endif
if (proc == stix->processor->active)
@ -515,7 +515,7 @@ static void terminate_process (stix_t* stix, stix_oop_process_t proc)
{
/* no runnable process after termination */
STIX_ASSERT (stix->processor->active == stix->nil_process);
STIX_LOG0 (stix, STIX_LOG_VM | STIX_LOG_DEBUG, "No runnable process after process termination\n");
STIX_LOG0 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "No runnable process after process termination\n");
}
else
{
@ -532,7 +532,7 @@ static void terminate_process (stix_t* stix, stix_oop_process_t proc)
{
/* SUSPENDED ---> TERMINATED */
#if defined(STIX_DEBUG_VM_PROCESSOR)
STIX_LOG1 (stix, STIX_LOG_VM | STIX_LOG_DEBUG, "Processor - process %O SUSPENDED->TERMINATED\n", proc);
STIX_LOG1 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Processor - process %O SUSPENDED->TERMINATED\n", proc);
#endif
proc->state = STIX_SMOOI_TO_OOP(PROC_STATE_TERMINATED);
@ -559,7 +559,7 @@ static void resume_process (stix_t* stix, stix_oop_process_t proc)
STIX_ASSERT ((stix_oop_t)proc->next == stix->_nil);
#if defined(STIX_DEBUG_VM_PROCESSOR)
STIX_LOG1 (stix, STIX_LOG_VM | STIX_LOG_DEBUG, "Processor - process %O SUSPENDED->RUNNING\n", proc);
STIX_LOG1 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Processor - process %O SUSPENDED->RUNNING\n", proc);
#endif
chain_into_processor (stix, proc); /* TODO: error check */
@ -589,7 +589,7 @@ static void suspend_process (stix_t* stix, stix_oop_process_t proc)
/* RUNNING/RUNNABLE ---> SUSPENDED */
#if defined(STIX_DEBUG_VM_PROCESSOR)
STIX_LOG1 (stix, STIX_LOG_VM | STIX_LOG_DEBUG, "Processor - process %O RUNNING/RUNNABLE->SUSPENDED\n", proc);
STIX_LOG1 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Processor - process %O RUNNING/RUNNABLE->SUSPENDED\n", proc);
#endif
if (proc == stix->processor->active)
@ -645,7 +645,7 @@ static void yield_process (stix_t* stix, stix_oop_process_t proc)
if (nrp != proc)
{
#if defined(STIX_DEBUG_VM_PROCESSOR)
STIX_LOG1 (stix, STIX_LOG_VM | STIX_LOG_DEBUG, "Processor - process %O RUNNING->RUNNABLE\n", proc);
STIX_LOG1 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Processor - process %O RUNNING->RUNNABLE\n", proc);
#endif
switch_to_process (stix, nrp, PROC_STATE_RUNNABLE);
}
@ -1043,7 +1043,7 @@ static stix_oop_method_t find_method (stix_t* stix, stix_oop_t receiver, const s
/* TODO: implement method lookup cache */
#if defined(STIX_DEBUG_VM_METHOD_LOOKUP)
STIX_LOG3 (stix, STIX_LOG_VM | STIX_LOG_DEBUG, "Method lookup - Finding method %.*S for %O in ", message->len, message->ptr, receiver);
STIX_LOG3 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Method lookup - Finding method %.*S for %O in ", message->len, message->ptr, receiver);
#endif
cls = (stix_oop_class_t)STIX_CLASSOF(stix, receiver);
@ -1053,7 +1053,7 @@ static stix_oop_method_t find_method (stix_t* stix, stix_oop_t receiver, const s
c = receiver;
dic_no = STIX_CLASS_MTHDIC_CLASS;
#if defined(STIX_DEBUG_VM_METHOD_LOOKUP)
STIX_LOG1 (stix, STIX_LOG_VM | STIX_LOG_DEBUG, "Method lookup - class method dictionary of %O\n", c);
STIX_LOG1 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Method lookup - class method dictionary of %O\n", c);
#endif
}
else
@ -1061,7 +1061,7 @@ static stix_oop_method_t find_method (stix_t* stix, stix_oop_t receiver, const s
c = (stix_oop_t)cls;
dic_no = STIX_CLASS_MTHDIC_INSTANCE;
#if defined(STIX_DEBUG_VM_METHOD_LOOKUP)
STIX_LOG1 (stix, STIX_LOG_VM | STIX_LOG_DEBUG, "Method lookup - instance method dictionary of %O\n", c);
STIX_LOG1 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Method lookup - instance method dictionary of %O\n", c);
#endif
}
@ -1379,16 +1379,25 @@ static int prim_shallow_copy (stix_t* stix, stix_ooi_t nargs)
static int prim_basic_size (stix_t* stix, stix_ooi_t nargs)
{
/* return the number of indexable fields */
stix_oop_t rcv, sz;
STIX_ASSERT (nargs == 0);
rcv = STIX_STACK_GETTOP(stix);
sz = stix_oowtoint (stix, STIX_OBJ_GET_SIZE(rcv));
if (!sz) return -1; /* hard failure */
STIX_STACK_SETTOP(stix, sz);
if (!STIX_OOP_IS_POINTER(rcv))
{
sz = STIX_SMOOI_TO_OOP(0);
}
else
{
sz = stix_oowtoint (stix, STIX_OBJ_GET_SIZE(rcv));
if (!sz) return -1; /* hard failure */
}
STIX_STACK_SETTOP(stix, sz);
return 1;
}
@ -1979,6 +1988,33 @@ static int prim_processor_return_to (stix_t* stix, stix_ooi_t nargs)
return 1;
}
static int prim_processor_return_to_and_eval (stix_t* stix, stix_ooi_t nargs)
{
stix_oop_t rcv, ctx, blk, blkarg;
STIX_ASSERT (nargs == 3);
rcv = STIX_STACK_GET(stix, stix->sp - 3);
ctx = STIX_STACK_GET(stix, stix->sp - 2);
blk = STIX_STACK_GET(stix, stix->sp - 1);
blkarg = STIX_STACK_GET(stix, stix->sp);
if (rcv != (stix_oop_t)stix->processor) return 0;
if (STIX_CLASSOF(stix, ctx) != stix->_block_context &&
STIX_CLASSOF(stix, ctx) != stix->_method_context) return 0;
if (STIX_CLASSOF(stix, blk) != stix->_block_context) return 0;
STIX_STACK_POPS (stix, nargs + 1); /* pop arguments and receiver */
STIX_STACK_PUSH (stix, stix->_nil); /* TODO: change the return value.. */
SWITCH_ACTIVE_CONTEXT (stix, (stix_oop_context_t)ctx);
STIX_STACK_PUSH (stix, blk);
STIX_STACK_PUSH (stix, blkarg);
return prim_block_value (stix, 1);
}
static int prim_processor_force_context (stix_t* stix, stix_ooi_t nargs)
{
stix_oop_t rcv, ctx;
@ -2358,7 +2394,9 @@ static int prim_integer_inttostr (stix_t* stix, stix_ooi_t nargs)
str = stix_inttostr (stix, rcv, radix);
if (!str) return (stix->errnum == STIX_EINVAL? 0: -1);
STIX_STACK_POP (stix);
STIX_STACK_SETTOP (stix, str);
return 1;
}
@ -2690,6 +2728,7 @@ static prim_t primitives[] =
{ 2, 3, prim_processor_add_timed_semaphore, "_processor_add_timed_semaphore" },
{ 1, 1, prim_processor_remove_semaphore, "_processor_remove_semaphore" },
{ 2, 2, prim_processor_return_to, "_processor_return_to" },
{ 3, 3, prim_processor_return_to_and_eval, "_processor_return_to_and_eval" },
{ 1, 1, prim_processor_force_context, "_processor_force_context" },
{ 1, 1, prim_integer_add, "_integer_add" },
@ -2915,7 +2954,7 @@ static int send_message (stix_t* stix, stix_oop_char_t selector, int to_super, s
{
/* this must not happen as long as doesNotUnderstand: is implemented under Apex.
* this check should indicate a very serious internal problem */
STIX_LOG4 (stix, STIX_LOG_VM | STIX_LOG_FATAL,
STIX_LOG4 (stix, STIX_LOG_IC | STIX_LOG_FATAL,
"Fatal error - receiver [%O] of class [%O] doesNotUnderstand: [%.*S]\n",
receiver, STIX_CLASSOF(stix, receiver), mthname.len, mthname.ptr);
@ -3167,7 +3206,7 @@ int stix_execute (stix_t* stix)
{
/* no more waiting semaphore and no more process */
STIX_ASSERT (stix->processor->tally = STIX_SMOOI_TO_OOP(0));
STIX_LOG0 (stix, STIX_LOG_VM | STIX_LOG_DEBUG, "No more runnable process\n");
STIX_LOG0 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "No more runnable process\n");
#if 0
if (there is semaphore awaited.... )
@ -3497,7 +3536,7 @@ if (there is semaphore awaited.... )
case BCODE_JUMP_IF_FALSE_1:
case BCODE_JUMP_IF_FALSE_2:
case BCODE_JUMP_IF_FALSE_3:
STIX_LOG0 (stix, STIX_LOG_VM | STIX_LOG_FATAL, "<<<<<<<<<<<<<< JUMP NOT IMPLEMENTED YET >>>>>>>>>>>>\n");
STIX_LOG0 (stix, STIX_LOG_IC | STIX_LOG_FATAL, "<<<<<<<<<<<<<< JUMP NOT IMPLEMENTED YET >>>>>>>>>>>>\n");
stix->errnum = STIX_ENOIMPL;
return -1;
@ -3838,7 +3877,7 @@ return -1;
{
if (stix->active_context->origin->ip == STIX_SMOOI_TO_OOP(STIX_SMOOI_MIN))
{
STIX_LOG0 (stix, STIX_LOG_VM | STIX_LOG_ERROR, "Error - cannot return from dead context\n");
STIX_LOG0 (stix, STIX_LOG_IC | STIX_LOG_ERROR, "Error - cannot return from dead context\n");
stix->errnum = STIX_EINTERN; /* TODO: make this error catchable at the stix level... */
return -1;
}
@ -4091,10 +4130,9 @@ return -1;
default:
STIX_LOG1 (stix, STIX_LOG_VM | STIX_LOG_FATAL, "Fatal error - unknown byte code 0x%zx\n", bcode);
STIX_LOG1 (stix, STIX_LOG_IC | STIX_LOG_FATAL, "Fatal error - unknown byte code 0x%zx\n", bcode);
stix->errnum = STIX_EINTERN;
break;
}
}
@ -4102,7 +4140,7 @@ done:
vm_cleanup (stix);
#if defined(STIX_PROFILE_VM)
STIX_LOG1 (stix, STIX_LOG_VM | STIX_LOG_INFO, "TOTAL_INST_COUTNER = %zu\n", inst_counter);
STIX_LOG1 (stix, STIX_LOG_IC | STIX_LOG_INFO, "TOTAL_INST_COUTNER = %zu\n", inst_counter);
#endif
return 0;

View File

@ -65,10 +65,10 @@ void* stix_allocheapmem (stix_t* stix, stix_heap_t* heap, stix_oow_t size)
{
stix_uint8_t* ptr;
/*printf ("heap ptr %p %p %lld %lld\n", heap->ptr, heap->limit, (long long int)size, (long long int)(heap->limit - heap->ptr));*/
/* check the heap size limit */
if (heap->ptr >= heap->limit || heap->limit - heap->ptr < size)
{
STIX_LOG4 (stix, STIX_LOG_ERROR, "Cannot allocate %zd bytes from heap - ptr %p limit %p size %zd\n", size, heap->ptr, heap->limit, (stix_oow_t)(heap->limit - heap->ptr));
stix->errnum = STIX_EOOMEM;
return STIX_NULL;
}

View File

@ -342,6 +342,9 @@ static void log_write (stix_t* stix, unsigned int mask, const stix_ooch_t* msg,
msgidx = 0;
/* TODO: beautify the log message.
* do classification based on mask. */
while (len > 0)
{
ucslen = len;
@ -691,8 +694,8 @@ int main (int argc, char* argv[])
cancel_tick ();
g_stix = STIX_NULL;
stix_dumpsymtab(stix);
stix_dumpdic(stix, stix->sysdic, "System dictionary");
/*stix_dumpsymtab(stix);
*stix_dumpdic(stix, stix->sysdic, "System dictionary");*/
stix_close (stix);

View File

@ -35,7 +35,7 @@ void* stix_allocbytes (stix_t* stix, stix_oow_t size)
#endif
ptr = stix_allocheapmem (stix, stix->curheap, size);
if (!ptr && !(stix->option.trait & STIX_NOGC))
if (!ptr && stix->errnum == STIX_EOOMEM && !(stix->option.trait & STIX_NOGC))
{
stix_gc (stix);
ptr = stix_allocheapmem (stix, stix->curheap, size);

View File

@ -900,7 +900,7 @@ enum stix_log_mask_t
STIX_LOG_MNEMONIC = (1 << 8), /* bytecode mnemonic */
STIX_LOG_GC = (1 << 9),
STIX_LOG_VM = (1 << 10)
STIX_LOG_IC = (1 << 10) /* instruction cycle, fetch-decode-execute */
};
typedef enum stix_log_mask_t stix_log_mask_t;