gnu.expr
Class PrimProcedure

java.lang.Object
  extended by gnu.mapping.PropertySet
      extended by gnu.mapping.Procedure
          extended by gnu.mapping.ProcedureN
              extended by gnu.mapping.MethodProc
                  extended by gnu.expr.PrimProcedure
All Implemented Interfaces:
Inlineable, Named

public class PrimProcedure
extends MethodProc
implements Inlineable

A primitive Procedure implemented by a plain Java method.


Field Summary
 
Fields inherited from class gnu.mapping.MethodProc
NO_MATCH, NO_MATCH_AMBIGUOUS, NO_MATCH_BAD_TYPE, NO_MATCH_TOO_FEW_ARGS, NO_MATCH_TOO_MANY_ARGS
 
Fields inherited from class gnu.mapping.ProcedureN
noArgs
 
Constructor Summary
PrimProcedure(int op_code, ClassType classtype, java.lang.String name, Type retType, Type[] argTypes)
           
PrimProcedure(int opcode, Type retType, Type[] argTypes)
           
PrimProcedure(Method method)
           
PrimProcedure(Method method, char mode, Language language)
           
PrimProcedure(Method method, LambdaExp source)
           
PrimProcedure(java.lang.reflect.Method method, Language language)
           
PrimProcedure(Method method, Language language)
           
PrimProcedure(java.lang.String className, java.lang.String methodName, int numArgs)
           
 
Method Summary
 void apply(CallContext ctx)
          Call this Procedure using the explicit-CallContext-convention.
 void compile(ApplyExp exp, Compilation comp, Target target)
           
static void compileInvoke(Compilation comp, Method method, Target target, boolean isTailCall, int op_code, Type stackType)
          Emit the actual invoke operation, after arguments have been pushed.
 Method getMethod()
           
static PrimProcedure getMethodFor(java.lang.Class procClass, java.lang.String name, Declaration decl, Expression[] args, Language language)
          Get PrimProcedure for matching method in given class.
static PrimProcedure getMethodFor(ClassType procClass, java.lang.String name, Declaration decl, Expression[] args, Language language)
           
static PrimProcedure getMethodFor(ClassType procClass, java.lang.String name, Declaration decl, Type[] atypes, Language language)
           
static PrimProcedure getMethodFor(Procedure pproc, Declaration decl, Expression[] args, Language language)
          Search for a matching static method in a procedure's class.
static PrimProcedure getMethodFor(Procedure pproc, Declaration decl, Type[] atypes, Language language)
           
static PrimProcedure getMethodFor(Procedure pproc, Expression[] args)
           
 java.lang.String getName()
           
 Type getParameterType(int index)
           
 Type[] getParameterTypes()
           
static java.lang.Class getProcedureClass(java.lang.Object pproc)
           
 Type getReturnType()
           
 Type getReturnType(Expression[] args)
           
 boolean getStaticFlag()
          True if there is no 'this' parameter.
 java.lang.String getVerboseName()
           
 boolean isConstructor()
           
 boolean isSpecial()
           
static PrimProcedure makeBuiltinBinary(int opcode, Type type)
           
static PrimProcedure makeBuiltinUnary(int opcode, Type type)
           
 int match0(CallContext ctx)
          Pass zero arguments.
 int match1(java.lang.Object arg1, CallContext ctx)
          Pass one argument.
 int match2(java.lang.Object arg1, java.lang.Object arg2, CallContext ctx)
          Pass two arguments.
 int match3(java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, CallContext ctx)
          Pass three arguments.
 int match4(java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4, CallContext ctx)
          Pass four arguments.
 int matchN(java.lang.Object[] args, CallContext ctx)
           
 int numArgs()
          The (minimum, number) of arguments.
 int opcode()
           
 void print(java.io.PrintWriter ps)
           
 void setReturnType(Type retType)
           
 boolean takesContext()
           
static boolean takesContext(Method method)
           
 boolean takesTarget()
          Whether we are passed an argument for the 'target' / 'receiver' / 'this'.
 boolean takesVarArgs()
          Return true iff the last parameter is a "rest" argument.
 java.lang.String toString()
           
 
Methods inherited from class gnu.mapping.MethodProc
applyN, isApplicable, matchFailAsException, mostSpecific, mostSpecific, numParameters, resolveParameterTypes
 
Methods inherited from class gnu.mapping.ProcedureN
apply0, apply1, apply2, apply3, apply4
 
Methods inherited from class gnu.mapping.Procedure
apply, check0, check1, check2, check3, check4, checkArgCount, checkN, getSetter, getSourceLocation, maxArgs, minArgs, set0, set1, setN, setSetter, setSourceLocation
 
Methods inherited from class gnu.mapping.PropertySet
getProperty, getSymbol, removeProperty, setName, setProperty, setProperty, setSymbol
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PrimProcedure

public PrimProcedure(java.lang.String className,
                     java.lang.String methodName,
                     int numArgs)

PrimProcedure

public PrimProcedure(java.lang.reflect.Method method,
                     Language language)

PrimProcedure

public PrimProcedure(Method method)

PrimProcedure

public PrimProcedure(Method method,
                     Language language)

PrimProcedure

public PrimProcedure(Method method,
                     char mode,
                     Language language)

PrimProcedure

public PrimProcedure(Method method,
                     LambdaExp source)

PrimProcedure

public PrimProcedure(int opcode,
                     Type retType,
                     Type[] argTypes)

PrimProcedure

public PrimProcedure(int op_code,
                     ClassType classtype,
                     java.lang.String name,
                     Type retType,
                     Type[] argTypes)
Method Detail

opcode

public final int opcode()

getReturnType

public Type getReturnType()

setReturnType

public void setReturnType(Type retType)

isSpecial

public boolean isSpecial()

getReturnType

public Type getReturnType(Expression[] args)
Specified by:
getReturnType in interface Inlineable

getMethod

public Method getMethod()

takesVarArgs

public boolean takesVarArgs()
Return true iff the last parameter is a "rest" argument.


takesContext

public boolean takesContext()

takesContext

public static boolean takesContext(Method method)

isConstructor

public final boolean isConstructor()

takesTarget

public boolean takesTarget()
Whether we are passed an argument for the 'target' / 'receiver' / 'this'. Normally this is false for static methods and true for non-static methods. However, we may need to be able to call a static method using object.name(args...) (Java syntax) or (invoke object 'name args...) (Scheme syntax). This includes when the object is implied. In this case we need to ignore the first argument's value.


numArgs

public int numArgs()
The (minimum, number) of arguments. Doesn't not count implicit CallContext argument. Does count 'this' argument for non-static methods. Does count an implicit staticLink argument for constructor.

Overrides:
numArgs in class Procedure

match0

public int match0(CallContext ctx)
Description copied from class: Procedure
Pass zero arguments.

Overrides:
match0 in class Procedure
Returns:
non-negative if the match succeeded, else negative.

match1

public int match1(java.lang.Object arg1,
                  CallContext ctx)
Description copied from class: Procedure
Pass one argument.

Overrides:
match1 in class Procedure
Returns:
non-negative if the match succeeded, else negative.

match2

public int match2(java.lang.Object arg1,
                  java.lang.Object arg2,
                  CallContext ctx)
Description copied from class: Procedure
Pass two arguments.

Overrides:
match2 in class Procedure
Returns:
non-negative if the match succeeded, else negative.

match3

public int match3(java.lang.Object arg1,
                  java.lang.Object arg2,
                  java.lang.Object arg3,
                  CallContext ctx)
Description copied from class: Procedure
Pass three arguments.

Overrides:
match3 in class Procedure
Returns:
non-negative if the match succeeded, else negative.

match4

public int match4(java.lang.Object arg1,
                  java.lang.Object arg2,
                  java.lang.Object arg3,
                  java.lang.Object arg4,
                  CallContext ctx)
Description copied from class: Procedure
Pass four arguments.

Overrides:
match4 in class Procedure
Returns:
non-negative if the match succeeded, else negative.

matchN

public int matchN(java.lang.Object[] args,
                  CallContext ctx)
Overrides:
matchN in class Procedure

apply

public void apply(CallContext ctx)
           throws java.lang.Throwable
Description copied from class: Procedure
Call this Procedure using the explicit-CallContext-convention. The input arguments are (by default) in stack.args; the result is written to ctx.consumer.

Overrides:
apply in class Procedure
Throws:
java.lang.Throwable

makeBuiltinUnary

public static PrimProcedure makeBuiltinUnary(int opcode,
                                             Type type)

makeBuiltinBinary

public static PrimProcedure makeBuiltinBinary(int opcode,
                                              Type type)

getStaticFlag

public final boolean getStaticFlag()
True if there is no 'this' parameter.


getParameterTypes

public final Type[] getParameterTypes()

compile

public void compile(ApplyExp exp,
                    Compilation comp,
                    Target target)
Specified by:
compile in interface Inlineable

compileInvoke

public static void compileInvoke(Compilation comp,
                                 Method method,
                                 Target target,
                                 boolean isTailCall,
                                 int op_code,
                                 Type stackType)
Emit the actual invoke operation, after arguments have been pushed. Does whatever magic is needed to pass the result to target, including passing CallContext or special handling of ConsumerTarget.


getParameterType

public Type getParameterType(int index)
Overrides:
getParameterType in class MethodProc

getMethodFor

public static PrimProcedure getMethodFor(Procedure pproc,
                                         Expression[] args)

getMethodFor

public static PrimProcedure getMethodFor(Procedure pproc,
                                         Declaration decl,
                                         Expression[] args,
                                         Language language)
Search for a matching static method in a procedure's class.

Returns:
a PrimProcedure that is suitable, or null.

getMethodFor

public static PrimProcedure getMethodFor(Procedure pproc,
                                         Declaration decl,
                                         Type[] atypes,
                                         Language language)

getProcedureClass

public static java.lang.Class getProcedureClass(java.lang.Object pproc)

getMethodFor

public static PrimProcedure getMethodFor(java.lang.Class procClass,
                                         java.lang.String name,
                                         Declaration decl,
                                         Expression[] args,
                                         Language language)
Get PrimProcedure for matching method in given class.


getMethodFor

public static PrimProcedure getMethodFor(ClassType procClass,
                                         java.lang.String name,
                                         Declaration decl,
                                         Expression[] args,
                                         Language language)

getMethodFor

public static PrimProcedure getMethodFor(ClassType procClass,
                                         java.lang.String name,
                                         Declaration decl,
                                         Type[] atypes,
                                         Language language)

getName

public java.lang.String getName()
Specified by:
getName in interface Named
Overrides:
getName in class PropertySet

getVerboseName

public java.lang.String getVerboseName()

toString

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

print

public void print(java.io.PrintWriter ps)