pnuts.lang
Class PnutsFunction

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

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 DEFINED
           
static PnutsFunction EVAL
           
static PnutsFunction GET_CONTEXT
           
static PnutsFunction IMPORT
           
static PnutsFunction LOAD
           
static PnutsFunction LOAD_FILE
           
static PnutsFunction PACKAGE
           
static java.lang.String[] primitive_names
           
static PnutsFunction[] primitives
           
static PnutsFunction QUIT
           
static PnutsFunction THROW
           
 
Constructor Summary
protected PnutsFunction()
           
protected PnutsFunction(java.lang.String name)
           
 
Method Summary
 java.lang.Object accept(int narg, Visitor visitor, Context context)
           
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.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 getId()
           
 java.lang.Object[] getImportEnv(int narg)
           
 java.lang.String getName()
           
 Package getPackage(int narg)
           
 boolean isBuiltin()
           
protected  void put(int narg, Function f)
           
 java.lang.String toString()
           
 java.lang.String unparse(int narg)
          Retrieve the symbolic definition of a 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

CATCH

public static final PnutsFunction CATCH

PACKAGE

public static final PnutsFunction PACKAGE

IMPORT

public static final PnutsFunction IMPORT

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

primitives

public static final PnutsFunction[] primitives

primitive_names

public static final java.lang.String[] primitive_names
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

put

protected void put(int narg,
                   Function f)

get

protected 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

getId

public java.lang.String getId()
Returns:
the unique name

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 a function.
Parameters:
narg - the number of paramters. -1 means a arbitrary length parameter.
Returns:
the function definition

getPackage

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

getImportEnv

public java.lang.Object[] 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.