pnuts.lang
Class Runtime

java.lang.Object
  |
  +--pnuts.lang.Runtime
Direct Known Subclasses:
Function

public class Runtime
extends java.lang.Object
implements PnutsParserTreeConstants

This class provides runtime supports for Pnuts compiler/interpreter. All mehtods are protected static, so that only subclasses can access them.


Fields inherited from interface pnuts.lang.PnutsParserTreeConstants
JJTADDNODE, JJTANDNODE, JJTAPPLICATIONNODE, JJTARRAYTYPE, JJTASSIGNMENT, JJTASSIGNMENTAA, JJTASSIGNMENTDA, JJTASSIGNMENTEA, JJTASSIGNMENTLA, JJTASSIGNMENTMA, JJTASSIGNMENTOA, JJTASSIGNMENTPA, JJTASSIGNMENTRA, JJTASSIGNMENTRAA, JJTASSIGNMENTSA, JJTASSIGNMENTTA, JJTBLOCK, JJTBREAK, JJTCASTEXPRESSION, JJTCHARACTERNODE, JJTCLASS, JJTCONTINUE, JJTDIVIDENODE, JJTELSEIFNODE, JJTELSENODE, JJTEQUALNODE, JJTEXPRESSIONLIST, JJTFALSENODE, JJTFLOATINGNODE, JJTFOREACHSTATEMENT, JJTFORINIT, JJTFORSTATEMENT, JJTFORUPDATE, JJTFUNCTIONSTATEMENT, JJTGENODE, JJTGLOBAL, JJTGTNODE, JJTIDNODE, JJTIFSTATEMENT, JJTINDEXNODE, JJTINSTANCEOFEXPRESSION, JJTINTEGERNODE, JJTLENODE, JJTLISTELEMENTS, JJTLOCAL, JJTLOGANDNODE, JJTLOGEXORNODE, JJTLOGNOTNODE, JJTLOGORNODE, JJTLTNODE, JJTMEMBERNODE, JJTMETHODNODE, JJTMODNODE, JJTMULTNODE, JJTNEGATIVENODE, jjtNodeName, JJTNOTEQNODE, JJTNOTNODE, JJTNULLNODE, JJTORNODE, JJTPACKAGE, JJTPARAM, JJTPARAMLIST, JJTPOSTDECRNODE, JJTPOSTINCRNODE, JJTPREDECRNODE, JJTPREINCRNODE, JJTRANGENODE, JJTRETURN, JJTSHIFTARITHMETICNODE, JJTSHIFTLEFTNODE, JJTSHIFTRIGHTNODE, JJTSTART, JJTSTARTSET, JJTSTATICMEMBERNODE, JJTSTATICMETHODNODE, JJTSTRINGNODE, JJTSUBTRACTNODE, JJTSWITCHBLOCK, JJTSWITCHLABEL, JJTSWITCHSTATEMENT, JJTTRUENODE, JJTVOID, JJTWHILESTATEMENT
 
Constructor Summary
protected Runtime()
           
 
Method Summary
static java.lang.Class arrayType(java.lang.Class c, int dim)
           
protected static java.lang.Object assignRange(java.lang.Object target, java.lang.Number idx1, java.lang.Number idx2, java.lang.Object expr)
          This method is called by the syntax "id[from..to] = sth"
static java.lang.Object callConstructor(java.lang.Class c, java.lang.Object[] args)
          Call a constructor
static java.lang.Object callConstructor(java.lang.Class c, java.lang.Object[] args, java.lang.Class[] types)
          Call a constructor
static java.lang.Object callConstructor(Context context, java.lang.Class c, java.lang.Object[] args, java.lang.Class[] types)
           
protected static java.lang.Object callFunction(Context context, PnutsFunction func, java.lang.Object[] args)
           
static java.lang.Object callMethod(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 callMethod(java.lang.Class c, java.lang.String name, java.lang.Object[] args, java.lang.Object target)
          Call a method
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 t, PnutsFunction f, 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, java.util.Hashtable tab)
           
protected static void doReturn(java.lang.Object v)
           
static java.lang.Object getField(Context context, java.lang.Object target, java.lang.String name)
           
protected static java.lang.Object getIndex(java.lang.Object target, int index, Context context)
           
protected static Visitor getInterpreter()
           
protected static SimpleNode getNodes(Pnuts pnuts)
           
static java.lang.Object getStaticField(Context context, java.lang.Class clazz, java.lang.String name)
           
static boolean isArray(java.lang.Object obj)
          Check if the parameter is an array
protected static java.lang.Object newInstance(Context context, java.lang.Class clazz, java.lang.Object[] args, java.lang.Class[] casts)
           
static java.lang.Character parseChar(java.lang.String s)
           
static java.lang.Object[] parseFloat(java.lang.String str)
          [Number number, int offset_of_unit_symbol]
static java.lang.Object[] parseInt(java.lang.String str)
          [Number number, int offset_of_unit_symbol]
static java.lang.String parseString(java.lang.String s)
           
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 putField(Context context, java.lang.Object target, java.lang.String name, java.lang.Object expr)
           
static void putStaticField(Context context, java.lang.Class clazz, java.lang.String name, java.lang.Object expr)
           
static java.lang.Object quantity(java.lang.Number number, java.lang.String numberString, java.lang.String unit, Context context)
           
static void readSymbolTable(pnuts.lang.SymbolTable table, java.io.ObjectInputStream s)
          Read a hashtable from objectInputStream.
protected static void setInterpreter(Visitor visitor)
           
protected static void setLine(Context context, int beginLine)
          Set line number information for error reporting
static int writeSymbolTable(pnuts.lang.SymbolTable tab, pnuts.lang.SymbolTable notToSerialize, java.io.ObjectOutputStream s)
          Write a hashtable to the objectOutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Runtime

protected Runtime()
Method Detail

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

callMethod

public static java.lang.Object callMethod(java.lang.Class c,
                                          java.lang.String name,
                                          java.lang.Object[] args,
                                          java.lang.Object target)
                                   throws java.lang.IllegalAccessException,
                                          java.lang.IllegalArgumentException,
                                          java.lang.reflect.InvocationTargetException
Call a method
Parameters:
c - the class of method
name - the method name
args - the paramters
target - the target object
Returns:
the return value

callMethod

public static java.lang.Object callMethod(java.lang.Class c,
                                          java.lang.String name,
                                          java.lang.Object[] args,
                                          java.lang.Class[] types,
                                          java.lang.Object target)
                                   throws java.lang.IllegalAccessException,
                                          java.lang.IllegalArgumentException,
                                          java.lang.reflect.InvocationTargetException
Call a method
Parameters:
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

callConstructor

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

callConstructor

public static java.lang.Object callConstructor(java.lang.Class c,
                                               java.lang.Object[] args)
                                        throws java.lang.IllegalAccessException,
                                               java.lang.IllegalArgumentException,
                                               java.lang.reflect.InvocationTargetException,
                                               java.lang.InstantiationException
Call a constructor
Parameters:
c - the class of constructor
args - the paramters
Returns:
the created instance

callConstructor

public static java.lang.Object callConstructor(java.lang.Class c,
                                               java.lang.Object[] args,
                                               java.lang.Class[] types)
                                        throws java.lang.IllegalAccessException,
                                               java.lang.IllegalArgumentException,
                                               java.lang.reflect.InvocationTargetException,
                                               java.lang.InstantiationException
Call a constructor
Parameters:
c - the class of constructor
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)

getStaticField

public static java.lang.Object getStaticField(Context context,
                                              java.lang.Class clazz,
                                              java.lang.String name)

putField

public static void putField(Context context,
                            java.lang.Object target,
                            java.lang.String name,
                            java.lang.Object expr)

getField

public static java.lang.Object getField(Context context,
                                        java.lang.Object target,
                                        java.lang.String name)

arrayType

public static java.lang.Class arrayType(java.lang.Class c,
                                        int dim)

writeSymbolTable

public static int writeSymbolTable(pnuts.lang.SymbolTable tab,
                                   pnuts.lang.SymbolTable notToSerialize,
                                   java.io.ObjectOutputStream s)
                            throws java.io.IOException
Write a hashtable to the objectOutputStream. If a value of the hashtable is a Class object, it is encapsulated to avoid NotSerializableException. But if a value contains a Class object in its structure e.g. "new Class[]{ Object.class }", NotSerializableException is thrown, even though the Class object is Serializable. If notToSerialize is not null, falied keys are accumulated in notToSerialize. This is a workaround for bug:4075221.

readSymbolTable

public static void readSymbolTable(pnuts.lang.SymbolTable table,
                                   java.io.ObjectInputStream s)
                            throws java.io.IOException,
                                   java.lang.ClassNotFoundException
Read a hashtable from objectInputStream. If Class objects are encapsulated, it retrieves the Class objects from them.

parseInt

public static java.lang.Object[] parseInt(java.lang.String str)
[Number number, int offset_of_unit_symbol]

parseFloat

public static java.lang.Object[] parseFloat(java.lang.String str)
[Number number, int offset_of_unit_symbol]

parseString

public static java.lang.String parseString(java.lang.String s)

parseChar

public static java.lang.Character parseChar(java.lang.String s)

quantity

public static java.lang.Object quantity(java.lang.Number number,
                                        java.lang.String numberString,
                                        java.lang.String unit,
                                        Context context)

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

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

assignRange

protected static java.lang.Object assignRange(java.lang.Object target,
                                              java.lang.Number idx1,
                                              java.lang.Number idx2,
                                              java.lang.Object expr)
This method is called by the syntax "id[from..to] = sth"

checkException

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

checkException

protected static void checkException(Context context,
                                     java.lang.Throwable throwable,
                                     java.util.Hashtable tab)
Parameters:
context - the Context in which the exception is checked
throwable - the exception
tab - the exception handler table

catchException

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

getIndex

protected static final java.lang.Object getIndex(java.lang.Object target,
                                                 int index,
                                                 Context context)

newInstance

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

callFunction

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

getInterpreter

protected static Visitor getInterpreter()

setInterpreter

protected static void setInterpreter(Visitor visitor)

getNodes

protected static SimpleNode getNodes(Pnuts pnuts)

doReturn

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

setLine

protected static void setLine(Context context,
                              int beginLine)
Set line number information for error reporting