[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bsf-discussion
Subject:    Re: [bsf-discussion] BSFManager::compileScript and  BSFManager::compileExpr
From:       "Pontus Rydin" <pontus () rydin ! nu>
Date:       2000-12-01 15:06:38
[Download RAW message or body]

> I would really like to see some methods in BSF that break the
> source-->execution into two steps: source-->compiled object, and compiled
> object-->execution. The compiled object could really be a
java.lang.Object,
> which would allow scripting engines that compile to either Java bytecodes
or
> some internal format to both work. Rhino currently only interprets source
when
> called from BSF rather than using its much faster bytecode compilation
mode
> because the performance savings of running the compiled bytecode are
swamped by
> the translation and classloading costs. A two-step evaluation would allow
> applications that use BSF to compile a script once and evaluate it many
times
> for better performance. It's easy to imagine that JSP page compilers and
XSL
> engines could use this functionality at least.

An Object seems a little too "loose". I've played around with Callable and
Expression interfaces. They seem to cover most of the stuff you can do in
the different script engines.

Since BSF didn't suit the needs of the project I'm working on right now, I
wrote my own framework (currently semi-supporting Rhino and jPython) My
"Callable" look something like this (very experimental right now).

public interface Callable
 {
 public Object call()
 throws Exception;

 public Object call(ExecutionContext ctx)
 throws Exception;

 public Object callWith(Object[] args)
 throws Exception;

 public Object callWith(Object[] args, ExecutionContext ctx)
 throws Exception;

 public Object callMethod(Object self)
 throws Exception;

 public Object callMethod(Object self, ExecutionContext ctx)
 throws Exception;

 public Object callMethodWith(Object self, Object[] args)
 throws Exception;

 public Object callMethodWith(Object self, Object[] args, ExecutionContext
ctx)
 throws Exception;
 }

The "call" and "callWith" methods are self explanatory. The callMethod*
methods are used when you want to introduce some notion of 'this'. Each
method comes in two flavors, with a persistent or a temporary context. The
idea is this: Either you just want to evaluate something "standalon", i.e.
you're not interested in keeping a context longer than it takes to make the
call, or you want to execute multiple scripts in the same context (i.e. the
same set of global symbols).

The Callable interface is intented for compiled or uncompiled script
functions. For Expresssions, there's a similar interface.

Engine implementations can wrap whatever they like inside these objects
(bytecodes, javacode that's compiled later, the script source or some
internal pseudocompiled format).

Pontus Rydin
Grasse, France
Stockholm, Sweden (depending on the weather)



- ----
To get off the bsf-discussion list, send a message containing the word
"unsubscribe" (in the body, not the subject) to
<bsf-discussion-Request@OSS.Software.IBM.Com>.

Send Majordomo commands to: <bsf-discussion-Request@OSS.Software.IBM.Com>
To contact a human:         <bsf-discussion-Owner@OSS.Software.IBM.Com>
To post to the list:        <bsf-discussion@OSS.Software.IBM.Com>
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic