pnuts.lang
Class Context

java.lang.Object
  |
  +--pnuts.lang.Context
Direct Known Subclasses:
CompileContext, DebugContext

public class Context
extends java.lang.Object
implements java.lang.Cloneable

Context represents an internal state in Pnuts runtime environment. A Context object contains the following information.


Field Summary
protected  int beginLine
           
static java.io.PrintWriter defaultErrorStream
           
static java.io.PrintWriter defaultOutputStream
           
static java.io.PrintWriter defaultTerminalStream
           
protected  int depth
           
protected  int endLine
           
protected  pnuts.lang.ImportEnv importEnv
           
protected  pnuts.lang.Stack loadingResource
           
 
Constructor Summary
Context()
          Create a new context
Context(Package pkg)
          Creates a context.
Context(java.lang.String pkg)
          Creates a context.
 
Method Summary
 java.lang.Object clone()
          Make a clone of the context
 java.lang.Object clone(boolean clear)
          Make a clone of the context
protected  void close()
           
 boolean defined(java.lang.String name)
           
 java.lang.Object get(java.lang.String key)
          Get an environemnt variable associated with this context
 Package getCurrentPackage()
          get the current package
 java.io.PrintWriter getErrorStream()
          Get an OutputStream or a Writer to which error() write message
 java.lang.Object getId(java.lang.String symbol)
           
 java.lang.String getName()
          Gets the name of the context
 java.io.PrintWriter getOutputStream()
          get output stream of the context
 PnutsImpl getPnutsImpl()
          Gets the PnutsImpl object associated with this context
protected  java.lang.Object getScriptSource()
          Get the source of the script.
 java.io.PrintWriter getTerminalStream()
          get terminal-output-stream of the context
 java.util.Enumeration keys()
          Returns an enumeration of the keys in the environment of this context.
protected  void onError(java.lang.Throwable t)
          This method is called when an exception is thrown.
protected  void onExit(java.lang.Object arg)
          This method is called when the excecution is terminated normally.
protected  void open(java.lang.String[] locals)
           
 void set(java.lang.String key, java.lang.Object value)
          Define an environemnt variable associated with this context
 void setCurrentPackage(Package pkg)
          set the current package
 void setErrorStream(java.lang.Object errorStream)
          set an OutputStream or a Writer to which error() write message If errorStream is null, exception is thrown out of eval loop.
 void setErrorStream(java.lang.Object errorStream, boolean autoFlush)
          Set an OutputStream or a Writer to which error() write message If errorStream is null, exception is thrown out of eval loop.
 void setName(java.lang.String name)
          Sets the name of the context
 void setOutputStream(java.lang.Object outputStream)
           
 void setOutputStream(java.lang.Object out, boolean autoFlush)
          set output stream of the context
 void setPnutsImpl(PnutsImpl impl)
          Changes the PnutsImpl object associated with this context
 void setTerminalStream(java.lang.Object stream)
           
 void setTerminalStream(java.lang.Object str, boolean autoFlush)
          set terminal-output-stream of the context
protected  void setValue(java.lang.String symbol, java.lang.Object obj)
           
protected  java.lang.Object undefinedHook(java.lang.String symbol)
           
protected  void updateLine(SimpleNode node)
           
protected  void updateLine(SimpleNode node, int beginLine, int endLine)
           
 java.lang.String[] usedPackages()
          Returns the list of use()'d packages
 void usePackage(java.lang.String name)
          Add a package to the use()'d package list.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultOutputStream

public static final java.io.PrintWriter defaultOutputStream

defaultTerminalStream

public static final java.io.PrintWriter defaultTerminalStream

defaultErrorStream

public static final java.io.PrintWriter defaultErrorStream

depth

protected int depth

loadingResource

protected pnuts.lang.Stack loadingResource

beginLine

protected int beginLine

endLine

protected int endLine

importEnv

protected pnuts.lang.ImportEnv importEnv
Constructor Detail

Context

public Context()
Create a new context

Context

public Context(java.lang.String pkg)
Creates a context.
Parameters:
pkg - the name of the package.

Context

public Context(Package pkg)
Creates a context.
Parameters:
pkg - the initial package of the context.
Method Detail

clone

public java.lang.Object clone()
Make a clone of the context
Overrides:
clone in class java.lang.Object

clone

public java.lang.Object clone(boolean clear)
Make a clone of the context
Parameters:
clear - If true, import() state and current package are reset to the default values.

setName

public void setName(java.lang.String name)
Sets the name of the context

getName

public java.lang.String getName()
Gets the name of the context

setPnutsImpl

public void setPnutsImpl(PnutsImpl impl)
Changes the PnutsImpl object associated with this context

getPnutsImpl

public PnutsImpl getPnutsImpl()
Gets the PnutsImpl object associated with this context

get

public java.lang.Object get(java.lang.String key)
Get an environemnt variable associated with this context
Parameters:
key - the name of the variable
Returns:
the value of the variable
Since:
1.0beta8

set

public void set(java.lang.String key,
                java.lang.Object value)
Define an environemnt variable associated with this context
Parameters:
key - the name of the variable
value - the value of the variable
Since:
1.0beta8

keys

public java.util.Enumeration keys()
Returns an enumeration of the keys in the environment of this context.

setOutputStream

public void setOutputStream(java.lang.Object out,
                            boolean autoFlush)
set output stream of the context

setOutputStream

public void setOutputStream(java.lang.Object outputStream)

getOutputStream

public java.io.PrintWriter getOutputStream()
get output stream of the context

setTerminalStream

public void setTerminalStream(java.lang.Object str,
                              boolean autoFlush)
set terminal-output-stream of the context

setTerminalStream

public void setTerminalStream(java.lang.Object stream)

getTerminalStream

public java.io.PrintWriter getTerminalStream()
get terminal-output-stream of the context

setErrorStream

public void setErrorStream(java.lang.Object errorStream,
                           boolean autoFlush)
Set an OutputStream or a Writer to which error() write message If errorStream is null, exception is thrown out of eval loop.

setErrorStream

public void setErrorStream(java.lang.Object errorStream)
set an OutputStream or a Writer to which error() write message If errorStream is null, exception is thrown out of eval loop.

getErrorStream

public java.io.PrintWriter getErrorStream()
Get an OutputStream or a Writer to which error() write message

getCurrentPackage

public Package getCurrentPackage()
get the current package

setCurrentPackage

public void setCurrentPackage(Package pkg)
set the current package

usedPackages

public java.lang.String[] usedPackages()
Returns the list of use()'d packages

usePackage

public void usePackage(java.lang.String name)
Add a package to the use()'d package list.
Parameters:
name - the package name

getScriptSource

protected java.lang.Object getScriptSource()
Get the source of the script.
Returns:
 java.net.URL object, when the script is not precompiled
 pnuts.lang.Runtime object, when the script is precompiled
 

updateLine

protected void updateLine(SimpleNode node)

updateLine

protected void updateLine(SimpleNode node,
                          int beginLine,
                          int endLine)

onExit

protected void onExit(java.lang.Object arg)
This method is called when the excecution is terminated normally.

onError

protected void onError(java.lang.Throwable t)
This method is called when an exception is thrown.

getId

public java.lang.Object getId(java.lang.String symbol)

undefinedHook

protected java.lang.Object undefinedHook(java.lang.String symbol)

defined

public boolean defined(java.lang.String name)

open

protected void open(java.lang.String[] locals)

close

protected void close()

setValue

protected void setValue(java.lang.String symbol,
                        java.lang.Object obj)