help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] [Q] How can I get sender from ContextPart?


From: Sungjin Chun
Subject: [Help-smalltalk] [Q] How can I get sender from ContextPart?
Date: Mon, 05 Mar 2007 18:00:59 +0900
User-agent: Thunderbird 1.5.0.9 (X11/20070104)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I'm trying to port Seaside(yeah!) and first target is its Continuation
mechanism. (Refer Attached Files). I need to implement swapSender:
method into ContextPart, which in turn, requires sender information.
What I need to do is swap sender with other(coroutine from
Seaside/Squeak source).

Can anyone help me on this?

Thanks in advance.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF69xKQqspS1+XJHgRAg5mAKDHS/PMK3/G7sVksVNxyIBt2yZflgCglMtk
MwlAG2WiBdroT6W8r9gVYoM=
=qZWb
-----END PGP SIGNATURE-----
Smalltalk.Object subclass: #Continuation
    instanceVariableNames: 'values'
    classVariableNames: ''
    poolDictionaries: ''
    category: 'Seaside-Continuations'!

Continuation comment: nil!

!Continuation class methodsFor: 'instance creation'!

current
    ^ self fromContext: thisContext sender
!

currentDo: aBlock
    ^ aBlock value: (self fromContext: thisContext sender)
!

fromContext: aStack
    ^ self new initializeFromContext: aStack
! !


!Continuation methodsFor: 'private'!

initializeFromContext: aContext
    | valueStream context |
    valueStream _ WriteStream on: (Array new: 20).
    context _ aContext.
    [context notNil] whileTrue: [
        valueStream nextPut: aContext.
        1 to: context class instSize do: [:i | 
            valueStream nextPut: (context instVarAt: i)
        ].
        1 to: context localSize do: [:i |
            valueStream nextPut: (context localAt: i)
        ].
        context _ context sender
    ].
    values _ valueStream contents
!

terminate: aContext
    | context |
    context _ aContext.
    [context notNil] whileTrue: [context _ context swapSender: nil]
! !


!Continuation methodsFor: 'invocation'!

numArgs
    ^ 1
!

value
    self value: nil
!

valueWithArguments: v
    v size == 1 ifFalse: [^ self error: 'continuations can only be resumed with 
only one argument' ].
    self value: v first
!

value: v
    self terminate: thisContext.
    self restoreValues.
    thisContext swapSender: values first.
    ^ v
! !


!Continuation methodsFor: 'resuming'!

restoreValues
    | valueStream context |
    valueStream _ values readStream.
    [valueStream atEnd] whileFalse: [
        context _ valueStream next.
        1 to: context class instSize do: [:i |
            context instVarAt: i put: valueStream next
        ].
        1 to: context localSize do: [:i |
            context localAt: i put: valueStream next
        ]
    ]
! !


!ContextPart methodsFor: 'continuation'!

homeReceiver
    ^ self home receiver
!

localAt: aNumber
    ^ self at: aNumber
!

localAt: aNumber put: anObject
    ^ self at: aNumber put: anObject
!

localSize
    ^ self size
! !

reply via email to

[Prev in Thread] Current Thread [Next in Thread]