pnuts.lang
Class PnutsFunction

java.lang.Object
  |
  +--pnuts.lang.PnutsFunction
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
DynamicClass, Prototype, ScriptPackage.Function, SynchronizedFunction

public class PnutsFunction
extends java.lang.Object
implements java.io.Serializable

A PnutsFunction represents a group of Pnuts functions with a same name.

See Also:
Serialized Form

Field Summary
static PnutsFunction CATCH
           
static PnutsFunction CLASS
           
static PnutsFunction DEFINED
           
static PnutsFunction EVAL
           
static PnutsFunction GET_CONTEXT
           
static PnutsFunction IMPORT
           
static PnutsFunction LOAD
           
static PnutsFunction LOAD_FILE
           
static PnutsFunction PACKAGE
           
protected  Package pkg
          Deprecated.  
static PnutsFunction[] primitives
           
static PnutsFunction QUIT
           
static PnutsFunction REQUIRE
           
static PnutsFunction THROW
           
static PnutsFunction USE
           
 
Constructor Summary
protected PnutsFunction()
           
protected PnutsFunction(java.lang.String name)
           
 
Method Summary
 java.lang.Object accept(int narg, Visitor visitor, Context context)
           
protected  void added(int narg)
          This method is called when a Function object is registered to this object.
 java.lang.Object call(java.lang.Object[] args)
          Deprecated. Replaced by call(Object[], Context)
 java.lang.Object call(java.lang.Object[] args, Context context)
          Call a function in "context" with arguments "args".
static java.lang.Object call(java.lang.String name, java.lang.Object[] args)
          call a function "name" with arguments "args"
static java.lang.Object call(java.lang.String name, java.lang.Object[] args, Context context)
          call a function "name" in "context" with arguments "args"
static java.lang.Object call(java.lang.String name, java.lang.Object[] args, java.lang.String pkg)
          Deprecated. Replaced by call(String, Object[], Context)
 boolean defined(int narg)
          Check if the function with narg parameter is defined
protected  java.util.Enumeration elements()
           
protected  java.lang.Object exec(java.lang.Object[] args, Context context)
          Call a function in "context" with arguments "args".
protected static java.lang.Object exec(PnutsFunction func, java.lang.Object[] args, Context context)
           
protected  Function get(int narg)
           
 java.lang.String[] getImportEnv(int narg)
           
 java.lang.String getName()
           
 Package getPackage()
           
 boolean isBuiltin()
           
protected  void put(int narg, Function f)
           
 java.lang.String toString()
           
 java.lang.String unparse(int narg)
          Retrieve the symbolic definition of the function.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GET_CONTEXT

public static final PnutsFunction GET_CONTEXT

PACKAGE

public static final PnutsFunction PACKAGE

IMPORT

public static final PnutsFunction IMPORT

CATCH

public static final PnutsFunction CATCH

THROW

public static final PnutsFunction THROW

EVAL

public static final PnutsFunction EVAL

LOAD_FILE

public static final PnutsFunction LOAD_FILE

LOAD

public static final PnutsFunction LOAD

QUIT

public static final PnutsFunction QUIT

DEFINED

public static final PnutsFunction DEFINED

USE

public static final PnutsFunction USE

CLASS

public static final PnutsFunction CLASS

REQUIRE

public static final PnutsFunction REQUIRE

primitives

public static final PnutsFunction[] primitives

pkg

protected transient Package pkg
Deprecated.  

Constructor Detail

PnutsFunction

protected PnutsFunction()

PnutsFunction

protected PnutsFunction(java.lang.String name)
Method Detail

put

protected final void put(int narg,
                         Function f)

added

protected void added(int narg)
This method is called when a Function object is registered to this object. This method just returns. Subclass can override this as a hook method.
Parameters:
narg - the number of parameters

get

protected final Function get(int narg)

defined

public boolean defined(int narg)
Check if the function with narg parameter is defined
Parameters:
narg - the number of paramters. -1 means a arbitrary length parameter.
Returns:
true if a function with narg, otherwise false

getName

public java.lang.String getName()
Returns:
the name of functions

call

public final java.lang.Object call(java.lang.Object[] args,
                                   Context context)
Call a function in "context" with arguments "args". Increments the counter for Pnuts.evalDepth() during the execution.
Returns:
the result of the call

exec

protected java.lang.Object exec(java.lang.Object[] args,
                                Context context)
Call a function in "context" with arguments "args". Subclasses of this class should override this method.
Returns:
the result of the call

call

public final java.lang.Object call(java.lang.Object[] args)
Deprecated. Replaced by call(Object[], Context)

call a function with arguments "args"
Returns:
the result of the call

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

call

public static java.lang.Object call(java.lang.String name,
                                    java.lang.Object[] args,
                                    java.lang.String pkg)
Deprecated. Replaced by call(String, Object[], Context)

call a function "pkg::name" with arguments "args"

call

public static java.lang.Object call(java.lang.String name,
                                    java.lang.Object[] args,
                                    Context context)
call a function "name" in "context" with arguments "args"

call

public static java.lang.Object call(java.lang.String name,
                                    java.lang.Object[] args)
call a function "name" with arguments "args"

exec

protected static java.lang.Object exec(PnutsFunction func,
                                       java.lang.Object[] args,
                                       Context context)

unparse

public java.lang.String unparse(int narg)
Retrieve the symbolic definition of the function.
Parameters:
narg - the number of paramters. -1 means a arbitrary length parameter.
Returns:
the function definition

getPackage

public Package getPackage()
Returns:
Package in which the function is defined

getImportEnv

public java.lang.String[] getImportEnv(int narg)
Parameters:
narg - the number of paramters. -1 means a arbitrary length parameter.
Returns:
imports of the function (array of Class or String)

isBuiltin

public boolean isBuiltin()

accept

public java.lang.Object accept(int narg,
                               Visitor visitor,
                               Context context)
Parameters:
narg - the number of paramters. -1 means a arbitrary length parameter.

elements

protected java.util.Enumeration elements()