pnuts.lang
Class Runtime

java.lang.Object
  extended by pnuts.lang.Runtime
All Implemented Interfaces:
Executable
Direct Known Subclasses:
Compiler, DynamicRuntime, Function, PnutsFunction, PnutsImpl, PnutsInterpreter, VisualDebuggerModel

public class Runtime
extends java.lang.Object
implements Executable

This class provides runtime supports for Pnuts compiler/interpreter. Most of the methods are protected static, so that only subclasses can access them.


Nested Class Summary
protected static class Runtime.Accessor
           
static class Runtime.Break
           
static class Runtime.Continue
           
static interface Runtime.FunctionSerializer
           
protected static class Runtime.TypeMap
           
 
Field Summary
protected static java.lang.String BOOLEAN_SYMBOL
           
protected static java.lang.String BYTE_SYMBOL
           
protected static java.lang.String CHAR_SYMBOL
           
protected static java.lang.String CLONE
           
protected static java.lang.String DOUBLE_SYMBOL
           
protected static java.lang.String EXCEPTOIN_FIELD_SYMBOL
           
protected static java.lang.String FLOAT_SYMBOL
           
protected static java.lang.String INT_SYMBOL
           
protected static java.lang.String LONG_SYMBOL
           
protected static java.lang.String SHORT_SYMBOL
           
protected static java.lang.String VOID_SYMBOL
           
 
Constructor Summary
protected Runtime()
           
 
Method Summary
protected  java.lang.Object _callConstructor(Context context, java.lang.Class c, java.lang.Object[] args, java.lang.Class[] types)
          Call a constructor
protected  java.lang.Object _callMethod(Context context, java.lang.Class c, java.lang.String name, java.lang.Object[] args, java.lang.Class[] types, java.lang.Object target)
          Call a method
static java.lang.Object add(java.lang.Object n1, java.lang.Object n2)
          + operation
protected static java.lang.Object add(java.lang.Object n1, java.lang.Object n2, Context context)
           
static java.lang.Object add1(java.lang.Object n)
          Add 1 to an object (integer)
protected static java.lang.Object add1(java.lang.Object n, Context context)
           
static void addImport(Context context, java.lang.String name)
           
static void addStaticMembers(Context context, java.lang.String name, boolean wildcard)
           
static java.lang.Object and(java.lang.Object n1, java.lang.Object n2)
          & operation
protected static java.lang.Object and(java.lang.Object n1, java.lang.Object n2, Context context)
           
static java.lang.Object applyGenerator(Generator g, PnutsFunction closure, Context context)
           
protected static int arraydim(java.lang.Object o)
           
static java.lang.Class arrayType(java.lang.Class c, int dim)
          Creates an array type
static java.lang.Object call(Context context, java.lang.Object target, java.lang.Object[] args, java.lang.Class[] casts)
          This method is called by the syntax "funcOrClass(args...)"
static java.lang.Object call(Context context, java.lang.Object target, java.lang.Object[] args, java.lang.Class[] casts, int line, int column)
           
static java.lang.Object callConstructor(Context context, java.lang.Class c, java.lang.Object[] args, java.lang.Class[] types)
          Call a constructor
protected static java.lang.Object callFunction(Context context, PnutsFunction func, java.lang.Object[] args)
          Call a function
static java.lang.Object callMethod(Context context, java.lang.Class c, java.lang.String name, java.lang.Object[] args, java.lang.Class[] types, java.lang.Object target)
          Call a method
static java.lang.Object cast(Context context, java.lang.Class type, java.lang.Object object, boolean flag)
          This method is called by the syntax "(Class)object"
protected static void catchException(java.lang.Class type, PnutsFunction func, Context context)
          This method is called when catch() function is called in a package(non-local) scope
protected static void checkException(Context context, java.lang.Throwable throwable)
           
protected static void checkException(Context context, java.lang.Throwable throwable, Runtime.TypeMap tmap)
          Check if any exception handler is registered to the specified exception.
static int compareObjects(java.lang.Object e1, java.lang.Object e2)
          Compare two objects Elements of List and array are recursively compared.
static int compareTo(java.lang.Object n1, java.lang.Object n2)
          Compares n1 with n2
protected static int compareTo(java.lang.Object n1, java.lang.Object n2, Context context)
           
protected static java.util.List createList(Context context)
           
protected static java.util.Map createMap(int size, Context context)
           
protected static PnutsFunction defineTopLevelFunction(Function f, java.lang.String symbol, Package pkg, Context context)
           
protected static PnutsFunction defineUnboundFunction(Function f, java.lang.String symbol, Package pkg)
           
static java.lang.Object divide(java.lang.Object n1, java.lang.Object n2)
          / operation
protected static java.lang.Object divide(java.lang.Object n1, java.lang.Object n2, Context context)
           
static boolean eq(java.lang.Object n1, java.lang.Object n2)
          == operation
protected static boolean eq(java.lang.Object n1, java.lang.Object n2, Context context)
           
protected static void escape(java.lang.Object v)
           
protected  java.lang.Object exec(Context context)
          This method is overrided by classes generated by the compiler.
 java.lang.Object execute(Context context)
          Deprecated. replaced by run(Context)
static java.net.URL fileToURL(java.io.File file)
          Gets a URL from a File
protected static java.lang.reflect.Method findCallableMethod(java.lang.Class clazz, java.lang.String name, java.lang.Class[] args)
           
static java.lang.String format(java.lang.Object object, int maxArrayLength)
          Get the String representation of the specified object.
static java.lang.String format(java.lang.Object object, int maxArrayLength, int maxFormatSize)
           
static boolean ge(java.lang.Object n1, java.lang.Object n2)
          >= operation
protected static boolean ge(java.lang.Object n1, java.lang.Object n2, Context context)
           
static int getArrayLength(java.lang.Object array)
          Gets an array's length
static java.lang.Object getBeanProperty(Context context, java.lang.Object target, java.lang.String name)
          Gets a Bean property of the specified bean.
 java.lang.Object getBeanProperty(java.lang.Object target, java.lang.String name)
          Gets a Bean property of the specified bean.
protected  java.lang.Object getBeanProperty(java.lang.Object target, java.lang.String name, java.lang.Class stopClass)
          Gets a Bean property of the specified bean.
 java.lang.Class getBeanPropertyType(java.lang.Class cls, java.lang.String name)
          Gets the type of a bean property
protected static int getBeginColumn(Context context)
           
protected static int getBeginLine(Context context)
           
static java.lang.Class getBottomType(java.lang.Class clazz)
          Get true component type from an array type.
static Executable getCompiledScript(java.lang.String name, Context context)
          This method is called by Pnuts.load() when the property "pnuts.compiled.script.prefix" is defined, to load pre-compiled scripts.
protected static java.lang.reflect.Constructor[] getConstructors(Context context, java.lang.Class cls)
           
static java.lang.Object getElement(java.lang.Object target, java.lang.Object key, Context context)
          This method is called by the syntax "target[key]"
static java.lang.Object getElementAt(java.lang.Object target, int idx, Context context)
           
protected static int getEndLine(Context context)
           
protected static java.lang.reflect.Field getField(java.lang.Class cls, java.lang.String name)
           
static java.lang.Object getField(Context context, java.lang.Object target, java.lang.String name)
          Get the value of a instance field.
protected static Function getFunction(Context context)
           
protected static Function getFunction(PnutsFunction pf, int nargs)
           
protected static java.util.Enumeration getFunctions(PnutsFunction pf)
           
protected static java.lang.String getMessage(java.lang.String bundleName, java.lang.String key, java.lang.Object[] a)
           
protected static java.lang.reflect.Method[] getMethods(Context context, java.lang.Class cls)
           
static java.lang.String getProperty(java.lang.String key)
           
static java.lang.Object getRange(java.lang.Object target, java.lang.Object idx1, java.lang.Object idx2, Context context)
          Range expression 'target[idx1..idx2]'.
protected static Runtime getRuntime(Context context)
           
static java.io.Reader getScriptReader(java.io.InputStream in, Context context)
          Gets a Reader to read script files If context.getScriptEncoding() is non-null, it would be used as the encoding.
protected static java.lang.Object getScriptSource(Context context)
           
static java.net.URL getScriptURL(java.lang.String name, Context context)
          Returns a URL of a script
static java.lang.Object getStaticField(Context context, java.lang.Class clazz, java.lang.String name)
          Get the value of a static field.
static Context getThreadContext()
          Sets the context bound to the current thread
static boolean gt(java.lang.Object n1, java.lang.Object n2)
          > operation
protected static boolean gt(java.lang.Object n1, java.lang.Object n2, Context context)
           
static boolean isArray(java.lang.Object obj)
          Check if the parameter is an array
static boolean isGenerator(SimpleNode node)
           
protected static void jump(java.lang.Object v)
           
static boolean le(java.lang.Object n1, java.lang.Object n2)
          <= operation
protected static boolean le(java.lang.Object n1, java.lang.Object n2, Context context)
           
static SimpleNode loadNode(java.lang.String str)
           
static boolean lt(java.lang.Object n1, java.lang.Object n2)
          < operation
protected static boolean lt(java.lang.Object n1, java.lang.Object n2, Context context)
           
protected static java.lang.Object makeArray(java.lang.Object[] parameters, Context context)
           
protected static int matchType(java.lang.Class type, java.lang.Object obj)
           
static java.lang.Object mod(java.lang.Object n1, java.lang.Object n2)
          % operation
protected static java.lang.Object mod(java.lang.Object n1, java.lang.Object n2, Context context)
           
static java.lang.Object multiply(java.lang.Object n1, java.lang.Object n2)
          * operation
protected static java.lang.Object multiply(java.lang.Object n1, java.lang.Object n2, Context context)
           
static boolean ne(java.lang.Object n1, java.lang.Object n2)
          != operation
protected static boolean ne(java.lang.Object n1, java.lang.Object n2, Context context)
           
static java.lang.Object negate(java.lang.Object n)
          Negates an number
protected static java.lang.Object negate(java.lang.Object n, Context context)
           
protected static java.lang.Object newInstance(Context context, java.lang.Class c, java.lang.Object[] args, java.lang.Class[] casts)
           
static java.lang.Object not(java.lang.Object n)
           
protected static java.lang.Object not(java.lang.Object n, Context context)
           
static java.lang.Object or(java.lang.Object n1, java.lang.Object n2)
          | operation
protected static java.lang.Object or(java.lang.Object n1, java.lang.Object n2, Context context)
           
static java.lang.Character parseChar(java.lang.String str)
          Parse a character literal.
static java.lang.Object[] parseFloat(java.lang.String str)
          Parse a floating point number.
static java.lang.Object[] parseInt(java.lang.String str)
          Parse an integer.
static java.lang.String parseString(java.lang.String str)
          Parse a string literal.
static java.lang.Object primitive(Context context, java.lang.Class primitiveType, java.lang.Object param, boolean flag)
          This method is called by the syntax "primitiveType(object)" and "(primitiveType)object"
static void printError(java.lang.Throwable t, Context context)
           
static void putField(Context context, java.lang.Object target, java.lang.String name, java.lang.Object expr)
          Assign an object to a instance field.
static void putStaticField(Context context, java.lang.Class clazz, java.lang.String name, java.lang.Object expr)
          Assign an object to a static field.
static java.lang.Object quantity(java.lang.Number number, java.lang.String numberString, java.lang.String unit, Context context)
          Creates an object from a number literal and a unit symbol
static java.lang.String replaceChar(java.lang.String str, java.lang.Number n, java.lang.Object expr)
           
 java.lang.Object run(Context context)
          Executes a compiled script.
static java.lang.String saveNode(SimpleNode node)
           
static void setBeanProperty(Context context, java.lang.Object target, java.lang.String name, java.lang.Object value)
          Sets a Bean property of the specified bean.
 void setBeanProperty(java.lang.Object target, java.lang.String name, java.lang.Object value)
          Sets a Bean property of the specified bean.
protected  void setBeanProperty(java.lang.Object target, java.lang.String name, java.lang.Object value, java.lang.Class stopClass)
          Sets a Bean property of the specified bean.
static void setElement(java.lang.Object target, java.lang.Object key, java.lang.Object value, Context context)
          This method is called by the syntax "target[key] = value"
static void setExitHook(Context context, PnutsFunction func)
           
static void setLine(Context context, int line)
           
protected static void setLine(Context context, int beginLine, int beginColumn)
          Deprecated.  
protected static void setPackage(Package pkg, Context context)
           
static java.lang.Object setRange(java.lang.Object target, java.lang.Object idx1, java.lang.Object idx2, java.lang.Object expr, Context context)
          This method is called by the syntax "id[from..to] = sth"
static void setThreadContext(Context context)
          Gets the context bound to the current thread
static java.lang.Object shiftArithmetic(java.lang.Object n1, java.lang.Object n2)
          >>> operation
protected static java.lang.Object shiftArithmetic(java.lang.Object n1, java.lang.Object n2, Context context)
           
static java.lang.Object shiftLeft(java.lang.Object n1, java.lang.Object n2)
          < < operation
protected static java.lang.Object shiftLeft(java.lang.Object n1, java.lang.Object n2, Context context)
           
static java.lang.Object shiftRight(java.lang.Object n1, java.lang.Object n2)
          >> operation
protected static java.lang.Object shiftRight(java.lang.Object n1, java.lang.Object n2, Context context)
           
static java.lang.Object subtract(java.lang.Object n1, java.lang.Object n2)
          - operation
protected static java.lang.Object subtract(java.lang.Object n1, java.lang.Object n2, Context context)
           
static java.lang.Object subtract1(java.lang.Object n)
          Subtracts 1 from a object (integer)
protected static java.lang.Object subtract1(java.lang.Object n, Context context)
           
static void throwException(java.lang.Object arg, Context context)
           
static java.lang.Boolean toBoolean(java.lang.Object param)
          Convert a given object to a boolean value
static java.util.Enumeration toEnumeration(java.lang.Object target, Context context)
           
static java.lang.Object transform(java.lang.Class type, java.lang.Object obj)
           
static java.lang.Object transform(java.lang.Class type, java.lang.Object obj, Context context)
           
static java.lang.String unparse(SimpleNode node, Context context)
           
static java.lang.Object xor(java.lang.Object n1, java.lang.Object n2)
          ^ operation
protected static java.lang.Object xor(java.lang.Object n1, java.lang.Object n2, Context context)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INT_SYMBOL

protected static final java.lang.String INT_SYMBOL

SHORT_SYMBOL

protected static final java.lang.String SHORT_SYMBOL

CHAR_SYMBOL

protected static final java.lang.String CHAR_SYMBOL

BYTE_SYMBOL

protected static final java.lang.String BYTE_SYMBOL

LONG_SYMBOL

protected static final java.lang.String LONG_SYMBOL

FLOAT_SYMBOL

protected static final java.lang.String FLOAT_SYMBOL

DOUBLE_SYMBOL

protected static final java.lang.String DOUBLE_SYMBOL

BOOLEAN_SYMBOL

protected static final java.lang.String BOOLEAN_SYMBOL

VOID_SYMBOL

protected static final java.lang.String VOID_SYMBOL

CLONE

protected static final java.lang.String CLONE

EXCEPTOIN_FIELD_SYMBOL

protected static final java.lang.String EXCEPTOIN_FIELD_SYMBOL
Constructor Detail

Runtime

protected Runtime()
Method Detail

run

public java.lang.Object run(Context context)
Executes a compiled script. Exceptions are checked if an exception handler is registered with the catch() function. Output stream of the specified context is flushed after the script is executed or an exception is thrown.

Specified by:
run in interface Executable
Parameters:
context - the context in which this object is executed
Returns:
the result of the execution

execute

public java.lang.Object execute(Context context)
Deprecated. replaced by run(Context)

Executes a compiled script. Exceptions are checked if an exception handler is registered with the catch() function. Output stream of the specified context is flushed after the script is executed or an exception is thrown.

Parameters:
context - the context in which this object is executed
Returns:
the result of the execution

exec

protected java.lang.Object exec(Context context)
This method is overrided by classes generated by the compiler.

Parameters:
context - the context in which this object is executed
Returns:
the result of the execution

callMethod

public static java.lang.Object callMethod(Context context,
                                          java.lang.Class c,
                                          java.lang.String name,
                                          java.lang.Object[] args,
                                          java.lang.Class[] types,
                                          java.lang.Object target)
Call a method

Parameters:
context - the context in which the method is called
c - the class of method
name - the method name
args - the paramters
types - the types of the paramters
target - the target object
Returns:
the return value of the call

callConstructor

public static java.lang.Object callConstructor(Context context,
                                               java.lang.Class c,
                                               java.lang.Object[] args,
                                               java.lang.Class[] types)
Call a constructor

Parameters:
context - the context in which the constructor is called
c - the class of method
args - the paramters
types - the types of the formal arguments
Returns:
the created instance

_callMethod

protected java.lang.Object _callMethod(Context context,
                                       java.lang.Class c,
                                       java.lang.String name,
                                       java.lang.Object[] args,
                                       java.lang.Class[] types,
                                       java.lang.Object target)
Call a method

Parameters:
context - the context
c - the class of method
name - the method name
args - the paramters
types - the types of the formal arguments
target - the target object
Returns:
the return value

findCallableMethod

protected static java.lang.reflect.Method findCallableMethod(java.lang.Class clazz,
                                                             java.lang.String name,
                                                             java.lang.Class[] args)

_callConstructor

protected java.lang.Object _callConstructor(Context context,
                                            java.lang.Class c,
                                            java.lang.Object[] args,
                                            java.lang.Class[] types)
Call a constructor

Parameters:
context - the context in which the constructor is called
c - the class of method
args - the paramters
types - the types of the formal arguments
Returns:
the created instance

putStaticField

public static void putStaticField(Context context,
                                  java.lang.Class clazz,
                                  java.lang.String name,
                                  java.lang.Object expr)
Assign an object to a static field.

Parameters:
context - the context in which the field is accessed
clazz - the class in which the static field is defined
name - the name of the static field
expr - the value to be assigned

getStaticField

public static java.lang.Object getStaticField(Context context,
                                              java.lang.Class clazz,
                                              java.lang.String name)
Get the value of a static field.

Parameters:
context - the context in which the field is accessed
clazz - the class in which the static field is defined
name - the name of the static field
Returns:
the value

putField

public static void putField(Context context,
                            java.lang.Object target,
                            java.lang.String name,
                            java.lang.Object expr)
Assign an object to a instance field.

Parameters:
context - the context in which the field is accessed
target - the target object of the field
name - the name of the field
expr - the value to be assigned

getField

public static java.lang.Object getField(Context context,
                                        java.lang.Object target,
                                        java.lang.String name)
Get the value of a instance field.

Parameters:
context - the context in which the field is accessed
target - the target object of the field
name - the name of the field
Returns:
the value

getBottomType

public static java.lang.Class getBottomType(java.lang.Class clazz)
Get true component type from an array type. e.g. int[][] ==> int, String[] ==> String

Parameters:
clazz - An array type to be examined
Returns:
The component type of the array type.

arrayType

public static java.lang.Class arrayType(java.lang.Class c,
                                        int dim)
Creates an array type

Parameters:
c - the component type
dim - the number of dimensions

arraydim

protected static int arraydim(java.lang.Object o)

transform

public static java.lang.Object transform(java.lang.Class type,
                                         java.lang.Object obj)

transform

public static java.lang.Object transform(java.lang.Class type,
                                         java.lang.Object obj,
                                         Context context)

matchType

protected static int matchType(java.lang.Class type,
                               java.lang.Object obj)

getMethods

protected static java.lang.reflect.Method[] getMethods(Context context,
                                                       java.lang.Class cls)

getConstructors

protected static java.lang.reflect.Constructor[] getConstructors(Context context,
                                                                 java.lang.Class cls)

parseInt

public static java.lang.Object[] parseInt(java.lang.String str)
                                   throws ParseException
Parse an integer.

Returns:
an array [Number number, int offset_of_unit_symbol]
Throws:
ParseException

parseFloat

public static java.lang.Object[] parseFloat(java.lang.String str)
Parse a floating point number.

Returns:
an array [Number number, int offset_of_unit_symbol]

parseString

public static java.lang.String parseString(java.lang.String str)
                                    throws ParseException
Parse a string literal.

Returns:
the value
Throws:
ParseException

parseChar

public static java.lang.Character parseChar(java.lang.String str)
                                     throws ParseException
Parse a character literal.

Returns:
the value
Throws:
ParseException

quantity

public static java.lang.Object quantity(java.lang.Number number,
                                        java.lang.String numberString,
                                        java.lang.String unit,
                                        Context context)
Creates an object from a number literal and a unit symbol

Parameters:
number - a number object
numberString - a symbol of the number literal
unit - a unit symbol
context - a context in which the quantity is created

primitive

public static java.lang.Object primitive(Context context,
                                         java.lang.Class primitiveType,
                                         java.lang.Object param,
                                         boolean flag)
This method is called by the syntax "primitiveType(object)" and "(primitiveType)object"

Parameters:
context - the context
primitiveType - a primitive type
param - the parameter
flag - string <->number conversion

toBoolean

public static java.lang.Boolean toBoolean(java.lang.Object param)
Convert a given object to a boolean value


cast

public static java.lang.Object cast(Context context,
                                    java.lang.Class type,
                                    java.lang.Object object,
                                    boolean flag)
This method is called by the syntax "(Class)object"

Parameters:
context - the context
type - the type
flag - object_array <->primitive_array conversion

isArray

public static final boolean isArray(java.lang.Object obj)
Check if the parameter is an array

Parameters:
obj - the object to be checked
Returns:
true if the obj is an array, false otherwise.

getArrayLength

public static final int getArrayLength(java.lang.Object array)
Gets an array's length

Parameters:
array - the array
Returns:
the length

getRange

public static java.lang.Object getRange(java.lang.Object target,
                                        java.lang.Object idx1,
                                        java.lang.Object idx2,
                                        Context context)
Range expression 'target[idx1..idx2]'.

Returns:
the intersection of the whole range of the target object and the range [idx1..idx2]. This method never throw ArrayIndexOutOfBoundsException.

setRange

public static java.lang.Object setRange(java.lang.Object target,
                                        java.lang.Object idx1,
                                        java.lang.Object idx2,
                                        java.lang.Object expr,
                                        Context context)
This method is called by the syntax "id[from..to] = sth"


replaceChar

public static java.lang.String replaceChar(java.lang.String str,
                                           java.lang.Number n,
                                           java.lang.Object expr)

checkException

protected static void checkException(Context context,
                                     java.lang.Throwable throwable)

checkException

protected static void checkException(Context context,
                                     java.lang.Throwable throwable,
                                     Runtime.TypeMap tmap)
Check if any exception handler is registered to the specified exception. If any an exception handler is executed. If not, the exception is thrown.

Parameters:
context - the Context in which the exception is checked
throwable - the exception
tmap - the exception handler table

catchException

protected static void catchException(java.lang.Class type,
                                     PnutsFunction func,
                                     Context context)
This method is called when catch() function is called in a package(non-local) scope

Parameters:
type - the exception type of which an exception handler is registered
func - the function to be registered as an exception handler
context - the context in which the exception handler is registered

throwException

public static void throwException(java.lang.Object arg,
                                  Context context)

setExitHook

public static void setExitHook(Context context,
                               PnutsFunction func)

getElement

public static java.lang.Object getElement(java.lang.Object target,
                                          java.lang.Object key,
                                          Context context)
This method is called by the syntax "target[key]"


getElementAt

public static java.lang.Object getElementAt(java.lang.Object target,
                                            int idx,
                                            Context context)

setElement

public static void setElement(java.lang.Object target,
                              java.lang.Object key,
                              java.lang.Object value,
                              Context context)
This method is called by the syntax "target[key] = value"


toEnumeration

public static java.util.Enumeration toEnumeration(java.lang.Object target,
                                                  Context context)

callFunction

protected static final java.lang.Object callFunction(Context context,
                                                     PnutsFunction func,
                                                     java.lang.Object[] args)
Call a function

Parameters:
context - the context in which the function is called
func - the function to be called
args - the arguments

call

public static final java.lang.Object call(Context context,
                                          java.lang.Object target,
                                          java.lang.Object[] args,
                                          java.lang.Class[] casts)
This method is called by the syntax "funcOrClass(args...)"


call

public static final java.lang.Object call(Context context,
                                          java.lang.Object target,
                                          java.lang.Object[] args,
                                          java.lang.Class[] casts,
                                          int line,
                                          int column)

newInstance

protected static java.lang.Object newInstance(Context context,
                                              java.lang.Class c,
                                              java.lang.Object[] args,
                                              java.lang.Class[] casts)

makeArray

protected static java.lang.Object makeArray(java.lang.Object[] parameters,
                                            Context context)

createMap

protected static java.util.Map createMap(int size,
                                         Context context)

createList

protected static java.util.List createList(Context context)

jump

protected static void jump(java.lang.Object v)

escape

protected static void escape(java.lang.Object v)

setLine

protected static void setLine(Context context,
                              int beginLine,
                              int beginColumn)
Deprecated. 

Set line number information for error reporting


setLine

public static void setLine(Context context,
                           int line)

getBeginLine

protected static int getBeginLine(Context context)

getBeginColumn

protected static int getBeginColumn(Context context)

getEndLine

protected static int getEndLine(Context context)

getFunction

protected static Function getFunction(PnutsFunction pf,
                                      int nargs)

getFunctions

protected static java.util.Enumeration getFunctions(PnutsFunction pf)

getRuntime

protected static Runtime getRuntime(Context context)

getScriptSource

protected static java.lang.Object getScriptSource(Context context)

getFunction

protected static Function getFunction(Context context)

setPackage

protected static void setPackage(Package pkg,
                                 Context context)

format

public static java.lang.String format(java.lang.Object object,
                                      int maxArrayLength)
Get the String representation of the specified object.

Parameters:
object - the target object.
maxArrayLength - When the target object is an array and maxArrayLength is greater than zero, only the first maxArrayLength elements are printed and the rest of the elements are omitted as "...".

format

public static java.lang.String format(java.lang.Object object,
                                      int maxArrayLength,
                                      int maxFormatSize)

add1

public static final java.lang.Object add1(java.lang.Object n)
Add 1 to an object (integer)


add1

protected static final java.lang.Object add1(java.lang.Object n,
                                             Context context)

subtract1

public static final java.lang.Object subtract1(java.lang.Object n)
Subtracts 1 from a object (integer)


subtract1

protected static final java.lang.Object subtract1(java.lang.Object n,
                                                  Context context)

negate

public static final java.lang.Object negate(java.lang.Object n)
Negates an number


negate

protected static final java.lang.Object negate(java.lang.Object n,
                                               Context context)

not

public static final java.lang.Object not(java.lang.Object n)

not

protected static final java.lang.Object not(java.lang.Object n,
                                            Context context)

add

public static final java.lang.Object add(java.lang.Object n1,
                                         java.lang.Object n2)
+ operation


add

protected static final java.lang.Object add(java.lang.Object n1,
                                            java.lang.Object n2,
                                            Context context)

subtract

public static final java.lang.Object subtract(java.lang.Object n1,
                                              java.lang.Object n2)
- operation


subtract

protected static final java.lang.Object subtract(java.lang.Object n1,
                                                 java.lang.Object n2,
                                                 Context context)

multiply

public static final java.lang.Object multiply(java.lang.Object n1,
                                              java.lang.Object n2)
* operation


multiply

protected static final java.lang.Object multiply(java.lang.Object n1,
                                                 java.lang.Object n2,
                                                 Context context)

divide

public static final java.lang.Object divide(java.lang.Object n1,
                                            java.lang.Object n2)
/ operation


divide

protected static final java.lang.Object divide(java.lang.Object n1,
                                               java.lang.Object n2,
                                               Context context)

mod

public static final java.lang.Object mod(java.lang.Object n1,
                                         java.lang.Object n2)
% operation


mod

protected static final java.lang.Object mod(java.lang.Object n1,
                                            java.lang.Object n2,
                                            Context context)

shiftLeft

public static final java.lang.Object shiftLeft(java.lang.Object n1,
                                               java.lang.Object n2)
< < operation


shiftLeft

protected static final java.lang.Object shiftLeft(java.lang.Object n1,
                                                  java.lang.Object n2,
                                                  Context context)

shiftRight

public static final java.lang.Object shiftRight(java.lang.Object n1,
                                                java.lang.Object n2)
>> operation


shiftRight

protected static final java.lang.Object shiftRight(java.lang.Object n1,
                                                   java.lang.Object n2,
                                                   Context context)

shiftArithmetic

public static java.lang.Object shiftArithmetic(java.lang.Object n1,
                                               java.lang.Object n2)
>>> operation


shiftArithmetic

protected static final java.lang.Object shiftArithmetic(java.lang.Object n1,
                                                        java.lang.Object n2,
                                                        Context context)

or

public static final java.lang.Object or(java.lang.Object n1,
                                        java.lang.Object n2)
| operation


or

protected static final java.lang.Object or(java.lang.Object n1,
                                           java.lang.Object n2,
                                           Context context)

and

public static final java.lang.Object and(java.lang.Object n1,
                                         java.lang.Object n2)
& operation


and

protected static final java.lang.Object and(java.lang.Object n1,
                                            java.lang.Object n2,
                                            Context context)

xor

public static final java.lang.Object xor(java.lang.Object n1,
                                         java.lang.Object n2)
^ operation


xor

protected static final java.lang.Object xor(java.lang.Object n1,
                                            java.lang.Object n2,
                                            Context context)

lt

public static final boolean lt(java.lang.Object n1,
                               java.lang.Object n2)
< operation


lt

protected static final boolean lt(java.lang.Object n1,
                                  java.lang.Object n2,
                                  Context context)

gt

public static final boolean gt(java.lang.Object n1,
                               java.lang.Object n2)
> operation


gt

protected static final boolean gt(java.lang.Object n1,
                                  java.lang.Object n2,
                                  Context context)

ge

public static final boolean ge(java.lang.Object n1,
                               java.lang.Object n2)
>= operation


ge

protected static final boolean ge(java.lang.Object n1,
                                  java.lang.Object n2,
                                  Context context)

le

public static final boolean le(java.lang.Object n1,
                               java.lang.Object n2)
<= operation


le

protected static final boolean le(java.lang.Object n1,
                                  java.lang.Object n2,
                                  Context context)

eq

public static final boolean eq(java.lang.Object n1,
                               java.lang.Object n2)
== operation


eq

protected static final boolean eq(java.lang.Object n1,
                                  java.lang.Object n2,
                                  Context context)

ne

public static final boolean ne(java.lang.Object n1,
                               java.lang.Object n2)
!= operation


ne

protected static final boolean ne(java.lang.Object n1,
                                  java.lang.Object n2,
                                  Context context)

compareTo

public static final int compareTo(java.lang.Object n1,
                                  java.lang.Object n2)
Compares n1 with n2


compareTo

protected static final int compareTo(java.lang.Object n1,
                                     java.lang.Object n2,
                                     Context context)

compareObjects

public static int compareObjects(java.lang.Object e1,
                                 java.lang.Object e2)
Compare two objects Elements of List and array are recursively compared.


getScriptURL

public static java.net.URL getScriptURL(java.lang.String name,
                                        Context context)
Returns a URL of a script


getCompiledScript

public static Executable getCompiledScript(java.lang.String name,
                                           Context context)
This method is called by Pnuts.load() when the property "pnuts.compiled.script.prefix" is defined, to load pre-compiled scripts.

Parameters:
name - the script name
context - the context in which the class is loaded.
Returns:
pnuts.lang.Runtime object if the class is found, otherwise null.

fileToURL

public static java.net.URL fileToURL(java.io.File file)
                              throws java.io.IOException
Gets a URL from a File

Parameters:
file - the File object
Returns:
the resulting URL object
Throws:
java.io.IOException

getScriptReader

public static java.io.Reader getScriptReader(java.io.InputStream in,
                                             Context context)
Gets a Reader to read script files If context.getScriptEncoding() is non-null, it would be used as the encoding. Otherwise, the platform encoding is used.

Parameters:
in - the input stream
context - the executing context
Returns:
the resulting reader object

printError

public static void printError(java.lang.Throwable t,
                              Context context)

getMessage

protected static java.lang.String getMessage(java.lang.String bundleName,
                                             java.lang.String key,
                                             java.lang.Object[] a)

getProperty

public static java.lang.String getProperty(java.lang.String key)

setBeanProperty

public static void setBeanProperty(Context context,
                                   java.lang.Object target,
                                   java.lang.String name,
                                   java.lang.Object value)
Sets a Bean property of the specified bean.

Parameters:
context - the context
target - the target bean
name - the Bean property name
value - the value of the Bean property

getBeanProperty

public static java.lang.Object getBeanProperty(Context context,
                                               java.lang.Object target,
                                               java.lang.String name)
Gets a Bean property of the specified bean.

Parameters:
context - the context
target - the target bean
name - the Bean property name

getBeanProperty

public java.lang.Object getBeanProperty(java.lang.Object target,
                                        java.lang.String name)
                                 throws java.lang.IllegalAccessException,
                                        java.lang.reflect.InvocationTargetException
Gets a Bean property of the specified bean.

Parameters:
target - the target bean
name - the Bean property name
Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

getBeanProperty

protected java.lang.Object getBeanProperty(java.lang.Object target,
                                           java.lang.String name,
                                           java.lang.Class stopClass)
                                    throws java.lang.IllegalAccessException,
                                           java.lang.reflect.InvocationTargetException
Gets a Bean property of the specified bean.

Parameters:
target - the target bean
name - the Bean property name
stopClass - the Introspector's "stopClass"
Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

getField

protected static java.lang.reflect.Field getField(java.lang.Class cls,
                                                  java.lang.String name)

setBeanProperty

public void setBeanProperty(java.lang.Object target,
                            java.lang.String name,
                            java.lang.Object value)
                     throws java.lang.IllegalAccessException,
                            java.lang.reflect.InvocationTargetException
Sets a Bean property of the specified bean.

Parameters:
target - the target bean
name - the Bean property name
value - the new property value
Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

setBeanProperty

protected void setBeanProperty(java.lang.Object target,
                               java.lang.String name,
                               java.lang.Object value,
                               java.lang.Class stopClass)
                        throws java.lang.IllegalAccessException,
                               java.lang.reflect.InvocationTargetException
Sets a Bean property of the specified bean.

Parameters:
target - the target bean
name - the Bean property name
value - the new property value
stopClass - the Introspector's "stopClass"
Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

getBeanPropertyType

public java.lang.Class getBeanPropertyType(java.lang.Class cls,
                                           java.lang.String name)
Gets the type of a bean property

Parameters:
cls - the class of the bean
name - the property name of the bean property
Returns:
the type of the property

isGenerator

public static boolean isGenerator(SimpleNode node)

applyGenerator

public static java.lang.Object applyGenerator(Generator g,
                                              PnutsFunction closure,
                                              Context context)

addImport

public static void addImport(Context context,
                             java.lang.String name)

addStaticMembers

public static void addStaticMembers(Context context,
                                    java.lang.String name,
                                    boolean wildcard)

defineUnboundFunction

protected static PnutsFunction defineUnboundFunction(Function f,
                                                     java.lang.String symbol,
                                                     Package pkg)

defineTopLevelFunction

protected static PnutsFunction defineTopLevelFunction(Function f,
                                                      java.lang.String symbol,
                                                      Package pkg,
                                                      Context context)

unparse

public static java.lang.String unparse(SimpleNode node,
                                       Context context)

setThreadContext

public static void setThreadContext(Context context)
Gets the context bound to the current thread

Parameters:
context - the context

getThreadContext

public static Context getThreadContext()
Sets the context bound to the current thread

Returns:
the context

saveNode

public static java.lang.String saveNode(SimpleNode node)

loadNode

public static SimpleNode loadNode(java.lang.String str)