added some code for unwind protection

This commit is contained in:
hyunghwan.chung
2016-06-20 15:42:51 +00:00
parent 67275b3ef3
commit 8b678c21fb
4 changed files with 186 additions and 94 deletions

View File

@ -18,6 +18,11 @@
{
^false
}
#method ensureBlock
{
^self.ensure_block
}
}
#class(#pointer) MethodContext(Context)
@ -307,7 +312,7 @@
ip := source pc.
}
"------ TODO: -------------------------------------"
#method on: anException do: anExceptionBlock
{
" | handlerActive |"
@ -339,7 +344,6 @@ thisContext isExceptionHandlerContext dump.
aBlock value.
ex pass
].
aBlock value.
^v
}
@ -349,7 +353,23 @@ thisContext isExceptionHandlerContext dump.
^self on: Exception do: [:ex | aBlock value. ex pass ]
}
"------ TODO: -------------------------------------"
#method unwindTo: aContext return: anObject
{
## private: called by VM upon unwinding
| ctx eb |
ctx := self.
[ctx ~~ aContext] whileTrue: [
eb := ctx ensureBlock.
(eb notNil) ifTrue: [eb value].
ctx := ctx sender.
].
eb := ctx ensureBlock.
(eb notNil) ifTrue: [eb value].
^anObject
}
}
## TODO: is it better to inherit from Object???

View File

@ -36,11 +36,12 @@
#class MyObject(TestObject)
{
#declare(#classinst) t1 t2.
#declare(#classinst) t1 t2 t3.
#method(#class) xxxx
{
| g1 g2 |
t1 dump.
t3 value.
t2 := [ g1 := 50. g2 := 100. ^g1 + g2 ].
(t1 < 10) ifFalse: [ ^self ].
t1 := t1 + 1.
@ -49,12 +50,16 @@
#method(#class) main
{
t3 := ['1111' dump. ^20.].
t1 := 1.
self xxxx.
'END OF XXX' dump.
t2 := t2 value.
'END OF t2 value' dump.
t2 dump.
}
}