Context
Context is an internal state in Pnuts runtime environment, which is represented by pnuts.lang.Context class. A context has the following information:
- Stack frame (in pure interpreter only)
- Which Pnuts-package being used
- Imported Java-package list
- OutputStream to which print() write data
- OutputStream to which error() write message
- OutputStream to which the prompt and the results are written
- ClassLoader by which load() find a script
- A PnutsImpl object
- Context-local variables
- Modules added by use()
- Symbol list registered by autoload()
- File list loaded by load()
See "Pnuts API Overview" for the overview of the class.
getContext() refers to the currently executing context, which is created when an interactive session starts. All other executions refer to the current context.
When context is specified to the parameter of these functions, a clone of the context is created and the script is executed with the clone.
When context is not specified, a clone of the current context is created and the script is executed with the clone. In this case, the import() state and the current package are reset to the default values.
OutputStream for Messages
For each context the following can be specified.
- Standard output
- Error output
- Where result of evaluation is printed
- context . setOutputStream
(OutputStream anOutputStream) or (Writer aWriter )
- context . setErrorStream
(OutputStream aOutputStream) or (Writer aWriter )
- context . setTerminalStream
(OutputStream anOutputStream) or (Writer aWriter )
- context . getOutputStream ()
- context . getErrorStream ()
- context . getTerminalStream ()
|
Context-local Variables
- context . set ( String key , Object value )
- context . get ( String key )
- context . keys ( )
|
Context-local variables are environment variables assiciated with a context.
Class Loader
- setClassLoader ( ClassLoader loader )
- getClassLoader ( )
|
A class loader can be associated with the context. It is used to resolve class names, and finds scripts when load() function is used.
It is shared among the context's clones.
PnutsImpl Object
- context . setPnutsImpl ( PnutsImpl impl )
- context . getPnutsImpl ( )
|
See "On-the-fly Compiler and Pure Interpreter".