cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Oliver <res1c...@verizon.net>
Subject Re: FYI: Using Java to define Cocoon Flow
Date Fri, 16 May 2003 15:11:50 GMT
Nicola Ken Barozzi wrote:

>
> Christopher Oliver wrote, On 16/05/2003 11.53:
>
>> Actually, it's very easy if the scripting language doesn't rely on 
>> the Java call stack to implement function calls. Instead, it must 
>> create its own call-frames and push them on its own stack. The 
>> continuation of the current function invocation is simply the stack 
>> itself. To instantate a continuation object, you  make a copy of the 
>> stack and store it in the continuation object. To implement tail-call 
>> elimination, you overwrite the call-frame at the top of the stack 
>> with the tail function invocation. To implement continuations, you 
>> replace the _entire_ stack with the one stored in the continuation. 
>> Other than optimizing the stack-copying, that's it.
>
>
> Ok, so if I get it right, to support continuations in BSF one has to 
> add support in each and every scripting language that needs them, or 
> make the bsf handle the stack for them.

Each scripting language would need to support continuations. The problem 
for most (including Jython) is that they implement function calls with 
recursive Java calls to an "eval()" function of some kind. It isn't 
possible to implement continuations with such languages (because there's 
no way to copy the Java stack).

>
>
> "
> Usually, a scripting language author extends the BSFEngineImpl class, 
> which implements BSFEngine, and only requires the scripting language 
> author to implement the eval() method. However, the following methods 
> specified by the BSFEngine interface are the most commonly implemented:
>
>     * initialize() - used to set up the underlying scripting language
>     * call() - used to call functions or methods within the scripting
>     * eval() - used to evaluate a script
>     * exec() - used to execute a script
>     * declareBean() - used to create an implicit object
>     * undeclareBean() - used to remove an implicit object
> "
>
> So when I run exec() on a script, I loose complete control over it, 
> and it's the script that has to stop itself and handle me the 
> continuation that I'll have to handle him later:
>
>    * resume(cont)
>
> Am I getting there?
>
Yes,  but it should be

    *resume(cont, arg)

You are allowed to pass an argument to a continuation. This argument 
becomes the return value of the function invocation that created the 
continuation when the continuation is resumed.

Regards,

Chris     


Mime
View raw message