gnu.expr

Class PrimProcedure

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, argTypes

Fields inherited from class gnu.mapping.ProcedureN

noArgs

Constructor Summary

PrimProcedure(String className, String methodName, int numArgs)
PrimProcedure(Method method)
PrimProcedure(Method method, char mode, Language language)
PrimProcedure(Method method, LambdaExp source)
PrimProcedure(Method method, Language language)
PrimProcedure(int op_code, ClassType classtype, String name, Type retType, Type[] argTypes)
PrimProcedure(int opcode, Type retType, Type[] argTypes)
PrimProcedure(java.lang.reflect.Method method, Language language)

Method Summary

void
apply(CallContext ctx)
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(Class procClass, String name, Declaration decl, Expression[] args, Language language)
Get PrimProcedure for matching method in given class.
static PrimProcedure
getMethodFor(ClassType procClass, String name, Declaration decl, Type[] atypes, Language language)
static PrimProcedure
getMethodFor(ClassType procClass, String name, Declaration decl, Expression[] args, Language language)
static PrimProcedure
getMethodFor(Procedure pproc, 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, Expression[] args)
String
getName()
Type
getParameterType(int index)
Type[]
getParameterTypes()
static Class
getProcedureClass(Object pproc)
Type
getReturnType()
Type
getReturnType(Expression[] args)
boolean
getStaticFlag()
True if there is no 'this' parameter.
String
getVerboseName()
boolean
isConstructor()
boolean
isSpecial()
static PrimProcedure
makeBuiltinBinary(int opcode, Type type)
static PrimProcedure
makeBuiltinUnary(int opcode, Type type)
int
match0(CallContext ctx)
int
match1(Object arg1, CallContext ctx)
int
match2(Object arg1, Object arg2, CallContext ctx)
int
match3(Object arg1, Object arg2, Object arg3, CallContext ctx)
int
match4(Object arg1, Object arg2, Object arg3, Object arg4, CallContext ctx)
int
matchN(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.
String
toString()

Methods inherited from class gnu.mapping.MethodProc

applyN, getParameterType, isApplicable, matchFailAsException, mostSpecific, mostSpecific, numParameters, resolveParameterTypes

Methods inherited from class gnu.mapping.ProcedureN

apply0, apply1, apply2, apply3, apply4, applyN

Methods inherited from class gnu.mapping.Procedure

apply, apply, apply0, apply1, apply2, apply3, apply4, applyN, check0, check1, check2, check3, check4, checkArgCount, checkN, getSetter, getSourceLocation, match0, match1, match2, match3, match4, matchN, maxArgs, minArgs, numArgs, set0, set1, setN, setSetter, setSourceLocation, toString

Methods inherited from class gnu.mapping.PropertySet

getName, getProperty, getSymbol, removeProperty, setName, setProperty, setProperty, setSymbol

Constructor Details

PrimProcedure

public PrimProcedure(String className,
                     String methodName,
                     int numArgs)

PrimProcedure

public PrimProcedure(Method method)

PrimProcedure

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

PrimProcedure

public PrimProcedure(Method method,
                     LambdaExp source)

PrimProcedure

public PrimProcedure(Method method,
                     Language language)

PrimProcedure

public PrimProcedure(int op_code,
                     ClassType classtype,
                     String name,
                     Type retType,
                     Type[] argTypes)

PrimProcedure

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

PrimProcedure

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

Method Details

apply

public void apply(CallContext ctx)
            throws Throwable
Overrides:
apply in interface Procedure

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.

getMethod

public Method getMethod()

getMethodFor

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

getMethodFor

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

getMethodFor

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

getMethodFor

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

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,
                                         Expression[] args)

getName

public String getName()
Specified by:
getName in interface Named
Overrides:
getName in interface PropertySet

getParameterType

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

getParameterTypes

public final Type[] getParameterTypes()

getProcedureClass

public static Class getProcedureClass(Object pproc)

getReturnType

public Type getReturnType()

getReturnType

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

getStaticFlag

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

getVerboseName

public String getVerboseName()

isConstructor

public final boolean isConstructor()

isSpecial

public boolean isSpecial()

makeBuiltinBinary

public static PrimProcedure makeBuiltinBinary(int opcode,
                                              Type type)

makeBuiltinUnary

public static PrimProcedure makeBuiltinUnary(int opcode,
                                             Type type)

match0

public int match0(CallContext ctx)
Overrides:
match0 in interface Procedure

match1

public int match1(Object arg1,
                  CallContext ctx)
Overrides:
match1 in interface Procedure

match2

public int match2(Object arg1,
                  Object arg2,
                  CallContext ctx)
Overrides:
match2 in interface Procedure

match3

public int match3(Object arg1,
                  Object arg2,
                  Object arg3,
                  CallContext ctx)
Overrides:
match3 in interface Procedure

match4

public int match4(Object arg1,
                  Object arg2,
                  Object arg3,
                  Object arg4,
                  CallContext ctx)
Overrides:
match4 in interface Procedure

matchN

public int matchN(Object[] args,
                  CallContext ctx)
Overrides:
matchN in interface Procedure

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 interface Procedure

opcode

public final int opcode()

print

public void print(java.io.PrintWriter ps)

setReturnType

public void setReturnType(Type retType)

takesContext

public boolean takesContext()

takesContext

public static boolean takesContext(Method method)

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.

takesVarArgs

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

toString

public String toString()
Overrides:
toString in interface Procedure