diff --git a/stix/kernel/Context.st b/stix/kernel/Context.st index 4d6f18c..2538b38 100644 --- a/stix/kernel/Context.st +++ b/stix/kernel/Context.st @@ -246,7 +246,7 @@ thisContext isHandlerContext dump. (thisContext basicAt: 8) dump. ## this should be anException (thisContext basicAt: 9) dump. ## this should be anExceptionBlock (thisContext basicAt: 10) dump. ## this should be handlerActive -'on:do: ok.............' dump. +'on:do: ABOUT TO EVALUE THE RECEIVER BLOCK' dump. ^self value. } @@ -291,9 +291,18 @@ thisContext isHandlerContext dump. #method signal { self.signalContext := thisContext. - self isHandled - ifTrue: [ self handle ] - ifFalse: [ self notHandled ]. + + self.handlerContext isNil ifTrue: [ + self.handlerContext := self findHandlerContextStartingFrom: self.signalContext + ]. + + self.handlerContext isNil + ifTrue: [ self notHandled ] + ifFalse: [ self handle ]. + + ## self isHandled + ## ifTrue: [ self handle ] + ## ifFalse: [ self notHandled ]. } #method signal: text @@ -306,8 +315,33 @@ thisContext isHandlerContext dump. { ## pass the exception to the outer context ## TODO: + self.handlerContext := self findHandlerContextStartingFrom: (self.handlerContext sender). + self.handlerContext isNil + ifTrue: [ self notHandled ] + ifFalse: [ self handle ]. } + #method return: value + { + self.handlerContext isNil ifFalse: [ + Processor return: value to: (self.handlerContext sender) + ] + } + + #method retry + { + ## ##>>> Processor return: nil to: (self.signalContext sender). + } + + #method resume + { + ## is this correct??? + Processor return: nil to: (self.signalContext sender). + } + + ## #################################################################### + ## #################################################################### + #method isHandled { ^self handlerContext notNil diff --git a/stix/kernel/test-011.st b/stix/kernel/test-011.st index ccfc3ea..abab6c2 100644 --- a/stix/kernel/test-011.st +++ b/stix/kernel/test-011.st @@ -41,7 +41,23 @@ { | k | k := ['this is test-011' dump. Exception signal. 8888 dump. ] - on: Exception do: [ :ex | 'Exception occurred' dump. ex dump. 'Getting back to' dump. 80. ex pass ]. + on: Exception do: [ :ex | 'Exception occurred' dump. ex dump. 'Getting back to' dump. ex return: 9999. 'AFTER RETURN' dump. ]. + + k dump. + 'END OF test-011' dump. + } + + #method(#class) test3 + { + | k j | + j := 20. + k := [ + '>>> TEST3 METHOD >>> ' dump. + j dump. + (j < 25) ifTrue: [Exception signal]. + 'OOOOOOOOOOOOOOOOOOOOOOO' dump. + 'JJJJJJJJJJJJJJ' dump. + ] on: Exception do: [ :ex | 'Exception occurred' dump. j := j + 1. ex resume. ]. k dump. 'END OF test-011' dump. @@ -50,9 +66,11 @@ #method(#class) main { '>>>>> BEGINNING OF MAIN' dump. - - [ self main2 ] on: Exception do: [ :ex | 'EXCEPTION CAUGHT IN MAIN....' dump ]. + [ self main2 ] on: Exception do: [ :ex | 'EXCEPTION CAUGHT IN MAIN....' dump. "ex pass" ]. + + '##############################' dump. + self test3. '>>>>> END OF MAIN' dump. } } diff --git a/stix/lib/exec.c b/stix/lib/exec.c index 9e35a58..aa866c6 100644 --- a/stix/lib/exec.c +++ b/stix/lib/exec.c @@ -1854,13 +1854,12 @@ static int prim_processor_return_to (stix_t* stix, stix_ooi_t nargs) ctx = ACTIVE_STACK_GET(stix, stix->sp); if (rcv != (stix_oop_t)stix->processor) return 0; -/* TODO: check if ctx is a block context or a method context */ - STIX_ASSERT (STIX_CLASSOF(stix, ctx) == stix->_block_context || - STIX_CLASSOF(stix, ctx) == stix->_method_context); + + if (STIX_CLASSOF(stix, ctx) != stix->_block_context && + STIX_CLASSOF(stix, ctx) == stix->_method_context) return 0; ACTIVE_STACK_POPS (stix, nargs + 1); /* pop arguments and receiver */ - ACTIVE_STACK_PUSH (stix, ret); SWITCH_ACTIVE_CONTEXT (stix, (stix_oop_context_t)ctx);