some more work on process switching and exception handling
This commit is contained in:
@ -267,14 +267,6 @@
|
||||
self class primitiveFailed.
|
||||
}
|
||||
|
||||
#method(#class) doesNotUnderstand: messageSymbol
|
||||
{
|
||||
## TODO: implement this
|
||||
## UnrecognizedMessage signal.
|
||||
self class dump.
|
||||
'does not understand' dump.
|
||||
}
|
||||
|
||||
#method doesNotUnderstand: messageSymbol
|
||||
{
|
||||
self class doesNotUnderstand: messageSymbol
|
||||
|
@ -1,3 +1,10 @@
|
||||
#class Exception(Apex)
|
||||
{
|
||||
#dcl signalContext handlerContext handlerBlock messageText.
|
||||
|
||||
## To be extended below.
|
||||
}
|
||||
|
||||
#class(#pointer) Context(Apex)
|
||||
{
|
||||
#dcl sender ip sp ntmprs.
|
||||
@ -309,20 +316,18 @@ thisContext isExceptionHandlerContext dump.
|
||||
|
||||
#method ensure: aBlock
|
||||
{
|
||||
"##
|
||||
| complete returnValue |
|
||||
<ensure>
|
||||
|
||||
returnValue := self valueNoContextSwitch.
|
||||
complete ifNil: [
|
||||
complete := true.
|
||||
aBlock value.
|
||||
].
|
||||
^returnValue. ##"
|
||||
## 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.
|
||||
aBlock value.
|
||||
^value
|
||||
}
|
||||
|
||||
#method ifCurtailed: aBlock
|
||||
{
|
||||
^self on: Exception do: [:ex | aBlock value. ex pass ]
|
||||
}
|
||||
|
||||
"------ TODO: -------------------------------------"
|
||||
@ -330,9 +335,9 @@ thisContext isExceptionHandlerContext dump.
|
||||
|
||||
## TODO: is it better to inherit from Object???
|
||||
## or treat Exception specially like UndefinedObject or Class???
|
||||
#class Exception(Apex)
|
||||
#extend Exception
|
||||
{
|
||||
#dcl signalContext handlerContext handlerBlock messageText.
|
||||
|
||||
|
||||
#method(#class) signal
|
||||
{
|
||||
@ -403,9 +408,8 @@ thisContext isExceptionHandlerContext dump.
|
||||
]
|
||||
}
|
||||
|
||||
## ####################################################################
|
||||
## ####################################################################
|
||||
#method handleException
|
||||
## #################################################################### ## ####################################################################
|
||||
#method handleException
|
||||
{
|
||||
self.handlerContext notNil
|
||||
ifTrue: [
|
||||
@ -418,12 +422,12 @@ thisContext isExceptionHandlerContext dump.
|
||||
].
|
||||
}
|
||||
|
||||
#method handlerContext
|
||||
{
|
||||
(self.handlerContext notNil) ifTrue: [ ^self.handlerContext ].
|
||||
self.handlerContext := self findHandlerContextStartingFrom: self.signalContext.
|
||||
^self.handlerContext.
|
||||
}
|
||||
## #method handlerContext
|
||||
## {
|
||||
## (self.handlerContext notNil) ifTrue: [ ^self.handlerContext ].
|
||||
## self findHandlerContextStartingFrom: self.signalContext.
|
||||
## ^self.handlerContext.
|
||||
## }
|
||||
|
||||
#method findHandlerContextStartingFrom: aContext
|
||||
{
|
||||
@ -444,6 +448,10 @@ thisContext isExceptionHandlerContext dump.
|
||||
].
|
||||
ctx := ctx sender
|
||||
].
|
||||
|
||||
## no handler is found
|
||||
self.handlerBlock := nil.
|
||||
self.handlerContext := nil.
|
||||
^nil
|
||||
}
|
||||
}
|
||||
@ -470,6 +478,7 @@ ctx := thisContext.
|
||||
## TODO: include blockcontext???
|
||||
ctx := ctx sender.
|
||||
].
|
||||
'------ END OF BACKTRACE -----------' dump.
|
||||
PrimitiveFailureException signal: 'PRIMITIVE FAILED'.
|
||||
}
|
||||
|
||||
@ -477,4 +486,10 @@ ctx := thisContext.
|
||||
{
|
||||
Exception signal: 'Cannot instantiate'.
|
||||
}
|
||||
|
||||
#method(#class) doesNotUnderstand: messageSymbol
|
||||
{
|
||||
## TODO: implement this properly
|
||||
NoSuchMessageException signal: (messageSymbol, ' not understood by ', (self name)).
|
||||
}
|
||||
}
|
||||
|
@ -102,6 +102,14 @@
|
||||
self primitiveFailed
|
||||
}
|
||||
|
||||
#method critical: aBlock
|
||||
{
|
||||
'CRITICAL....11' dump.
|
||||
self wait.
|
||||
'CRITICAL....22' dump.
|
||||
^aBlock ensure: [ self signal ]
|
||||
}
|
||||
|
||||
## ==================================================================
|
||||
|
||||
#method heapIndex
|
||||
|
@ -45,7 +45,52 @@
|
||||
'END OF MAIN' dump.
|
||||
}
|
||||
|
||||
|
||||
#method(#class) main
|
||||
{
|
||||
## test critical region
|
||||
|t1 t2 s1 s2 s3|
|
||||
|
||||
'START OF MAIN' dump.
|
||||
|
||||
s1 := Semaphore new.
|
||||
s2 := Semaphore new.
|
||||
|
||||
t1 := [
|
||||
1000 timesRepeat: ['BLOCK #1' dump].
|
||||
##s2 critical: [
|
||||
## 10 timesRepeat: ['BLOCK #1' dump ]
|
||||
##]
|
||||
] newProcess.
|
||||
t2 := [
|
||||
1000 timesRepeat: ['BLOCK #2' dump].
|
||||
##s2 critical: [
|
||||
## 10 timesRepeat: ['BLOCK #2' dump. ]
|
||||
##].
|
||||
|
||||
s1 signal.
|
||||
] newProcess.
|
||||
|
||||
t1 resume.
|
||||
t2 resume.
|
||||
|
||||
s1 wait.
|
||||
|
||||
'END OF MAIN' dump.
|
||||
|
||||
"
|
||||
| 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.
|
||||
|
||||
'END OF MAIN' dump."
|
||||
}
|
||||
|
||||
#method(#class) main22222
|
||||
{
|
||||
|t1 t2 s1 s2 s3|
|
||||
|
||||
|
Reference in New Issue
Block a user