pnuts.lang
Class PnutsFunction

java.lang.Object
  |
  +--pnuts.lang.PnutsFunction
Direct Known Subclasses:
DynamicClass, Prototype, ScriptPackage.Function

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
           
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.
static void autoload(java.lang.String name, AutoloadHook loadHook)
           
static void autoload(java.lang.String name, java.lang.String file)
          register "name" as an autoloaded function.
 java.lang.Object call(java.lang.Object[] args)
          call a function with arguments "args"
 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)
          call a function "pkg::name" with arguments "args"
 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  Function get(int narg)
           
 java.lang.String[] getImportEnv(int narg)
           
 java.lang.String getName()
           
 Package getPackage()
           
 Package getPackage(int narg)
          Deprecated.  
 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
Constructor Detail

PnutsFunction

protected PnutsFunction()

PnutsFunction

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

autoload

public static void autoload(java.lang.String name,
                            java.lang.String file)
register "name" as an autoloaded function. Later "file" is automatically loaded if the function is not defined

autoload

public static void autoload(java.lang.String name,
                            AutoloadHook loadHook)

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)
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)
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"

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(int narg)
Deprecated.  

Parameters:
narg - the number of paramters. -1 means a arbitrary length parameter.
Returns:
Package in which the function is defined

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()