The on-the-fly compiler of Pnuts compiles scripts at runtime and generate Java bytecode on memory, so that the processing speed gets faster.
|
When "-pure" option is given in pnuts command, on-the-fly compiler is disabled. Otherwise, on-the-fly compiler is enabled.
C:\> pnuts Copyright (c) 1997-1999 Sun Microsystems, Inc. All rights reserved. Pnuts interpreter Version 1.0beta4, 1.2.2 (Sun Microsystems Inc.) > getProperty("pnuts.engine") pnuts.compiler.Compiler
The on-the-fly compiler does not show the line number of an error, unless -v option is given to pnuts command.
Even in the pure interpreter, User can compile thier script selectively. See also "Compiling Scripts In Pnuts".
pnuts.lang.PnutsImpl class, which is introduced in 1.0beta8, defines the interface of script interpreter's implementation. The following classes are implementation classes of the interface provided in the Pnuts distribution.
- pnuts.lang.PnutsImpl
- The pure interpreter. The default class for Context object.
- pnuts.compiler.CompilerPnutsImpl
- The on-the-fly Compiler. The default class for pnuts command.
- pnuts.ext.CachedPnutsImpl
- Mixed mode, which caches compiled (or parsed) scripts and reuse them. The default class for Pnuts servlet.
- pnuts.ext.SecurePnutsImpl
- Secure mode, which executes scripts safely using Java2 Security API
An instance of the PnutsImpl class (or its subclass) is associated with a Context. A pair of methods Context.setPnutsImpl() and Context.getPnutsImpl() are the settter/getter method respectively.
import pnuts.lang.*; import pnuts.ext.*; Context context = new Context(); context.setPnutsImpl(new CachedPnutsImpl()); Pnuts.loadFile(fileName, context);
SecurePnutsImpl is a wrapper class of other PnutsImpl subclasses to add a securty functionality. When a SecurePnutsImpl is associated with the context, remote scripts are loaded safely.
context.setPnutsImpl(new SecurePnutsImpl(new CompilerPnutsImpl())); Pnuts.load(new URL("..."), context);
See Performance Hints on how to choose PnutsImpl class, and Secure Scripting on how to use SecurePnutsImpl class.