Package gnu.expr
Class PrimProcedure
- java.lang.Object
-
- gnu.mapping.PropertySet
-
- gnu.mapping.Procedure
-
- gnu.mapping.ProcedureN
-
- gnu.mapping.MethodProc
-
- gnu.expr.PrimProcedure
-
- All Implemented Interfaces:
Named
public class PrimProcedure extends MethodProc
A primitive Procedure implemented by a plain Java method.
-
-
Field Summary
Fields Modifier and Type Field Description static MethodHandle
applyToConsumer
static boolean
explicitArrayAsVarArgsAllowed
Support passing an explicit array to a varargs function.-
Fields inherited from class gnu.mapping.MethodProc
applyToConsumerDefaultMP, NO_MATCH, NO_MATCH_AMBIGUOUS, NO_MATCH_BAD_TYPE, NO_MATCH_GUARD_FALSE, NO_MATCH_TOO_FEW_ARGS, NO_MATCH_TOO_MANY_ARGS, NO_MATCH_UNUSED_KEYWORD, THROW_ON_EXCEPTION
-
Fields inherited from class gnu.mapping.ProcedureN
applyToObject, noArgs
-
Fields inherited from class gnu.mapping.Procedure
applyMethodType, applyToConsumerDefault, applyToConsumerMethod, applyToObjectDefault, applyToObjectMethod, compilerKey, compilerXKey, inlineIfConstantSymbol, validateApplyKey, validateXApplyKey
-
Fields inherited from class gnu.mapping.PropertySet
nameKey
-
-
Constructor Summary
Constructors Constructor Description PrimProcedure(int op_code, ClassType classtype, String name, Type retType, Type[] argTypes)
PrimProcedure(int opcode, Type retType, Type[] argTypes)
PrimProcedure(Method method)
PrimProcedure(Method method, char mode, Language language, ParameterizedType parameterizedType)
PrimProcedure(Method method, Type retType, Type[] argTypes)
PrimProcedure(Method method, LambdaExp source)
PrimProcedure(Method method, Language language)
PrimProcedure(Method method, Language language)
PrimProcedure(String className, String methodName, int numArgs)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Object
applyToConsumer(Procedure proc, CallContext ctx)
Object
applyToConsumerX(CallContext ctx)
boolean
canCompile(ApplyExp exp)
boolean
compile(ApplyExp exp, Compilation comp, Target target)
static void
compileInvoke(Compilation comp, Method method, Target target, boolean isTailCall, int op_code, Type returnType, boolean doFixUnsigned)
Emit the actual invoke operation, after arguments have been pushed.static void
compileReachedUnexpected(CodeAttr code)
static void
compileRestArg(Type arg_type, ApplyExp exp, int startArg, int i, Compilation comp)
static Type
decodeType(Type javaType, String[] annotTypes, int annotIndex, ParameterizedType parameterizedType, Language lang)
static void
disassemble(Procedure proc, ClassTypeWriter cwriter)
static void
disassemble(Procedure proc, Writer out)
static void
disassemble$X(Procedure pproc, CallContext ctx)
ClassType
getDeclaringClass()
Method
getMethod()
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)
static PrimProcedure
getMethodFor(Class procClass, String name, Declaration decl, Expression[] args, Language language)
Get PrimProcedure for matching method in given class.String
getName()
Type
getParameterType(int index)
Type[]
getParameterTypes()
static Class
getProcedureClass(Object pproc)
Type
getReturnType()
Type
getReturnType(Expression[] args)
Semi-deprecated - instead should be set at Inline time.boolean
getStaticFlag()
True if there is no 'this' parameter.String
getVerboseName()
boolean
isAbstract()
int
isApplicable(Type[] argTypes, Type restType)
Test if method is applicable to an invocation with given arguments.boolean
isConstructor()
boolean
isSideEffectFree()
True if this Procedure (definitely) has no side-effects.boolean
isSpecial()
static PrimProcedure
makeBuiltinBinary(int opcode, Type type)
static PrimProcedure
makeBuiltinUnary(int opcode, Type type)
static int
mostSpecific(PrimProcedure[] procs, int length)
Return the index of the most specific method.int
numArgs()
The (minimum, number) of arguments.int
opcode()
void
print(PrintWriter ps)
void
setMethodForInvoke(Method m)
void
setReturnType(Type retType)
void
setSideEffectFree()
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.static boolean
takesVarArgs(Method method)
String
toString()
-
Methods inherited from class gnu.mapping.MethodProc
applyToConsumerDefaultMP, matchFailAsException, mostSpecific, numParameters, overrideEquivalent, resolveParameterTypes
-
Methods inherited from class gnu.mapping.ProcedureN
applyToObject
-
Methods inherited from class gnu.mapping.Procedure
apply0, apply1, apply2, apply3, apply4, applyL, applyN, applyToConsumerDefault, applyToObjectDefault, checkArgCount, checkBadCode, getApplyMethod, getApplyToConsumerMethod, getApplyToObjectMethod, getSetter, getSourceLocation, lookupApplyHandle, maxArgs, maxArgs, minArgs, minArgs, set0, set1, setN, setSetter, setSourceLocation
-
Methods inherited from class gnu.mapping.PropertySet
getProperty, getSymbol, removeProperty, setName, setProperty, setProperty, setSymbol
-
-
-
-
Field Detail
-
explicitArrayAsVarArgsAllowed
public static boolean explicitArrayAsVarArgsAllowed
Support passing an explicit array to a varargs function. This is a kludge inherited from Java to support backwards compatibility after various methods were converte to take varargs. If Java5-style VARARGS we allow both a variable-length argument list, or if the last argument already is an array we can use it as is. The tricky part is we sometimes have to distinguish these cases at run-time - see the logic for createVarargsArrayIfNeeded in compileArgs. FIXME This is needless and unreliable complexity. We should by default create a varargs array - even if the actual argument is an array. People should now use splices instead.
-
applyToConsumer
public static final MethodHandle applyToConsumer
-
-
Constructor Detail
-
PrimProcedure
public PrimProcedure(Method method)
-
PrimProcedure
public PrimProcedure(Method method, char mode, Language language, ParameterizedType parameterizedType)
-
-
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)
Description copied from class:Procedure
Semi-deprecated - instead should be set at Inline time. FIXME- Overrides:
getReturnType
in classProcedure
-
getDeclaringClass
public ClassType getDeclaringClass()
-
getMethod
public Method getMethod()
-
setMethodForInvoke
public void setMethodForInvoke(Method m)
-
isSideEffectFree
public boolean isSideEffectFree()
Description copied from class:Procedure
True if this Procedure (definitely) has no side-effects. Note side-effect-free does not imply idempotent if this allocates an object with "identity".- Overrides:
isSideEffectFree
in classProcedure
-
setSideEffectFree
public void setSideEffectFree()
-
takesVarArgs
public boolean takesVarArgs()
Return true iff the last parameter is a "rest" argument.
-
takesVarArgs
public static boolean takesVarArgs(Method method)
-
takesContext
public boolean takesContext()
-
takesContext
public static boolean takesContext(Method method)
-
isApplicable
public int isApplicable(Type[] argTypes, Type restType)
Description copied from class:MethodProc
Test if method is applicable to an invocation with given arguments.- Overrides:
isApplicable
in classMethodProc
- Parameters:
argTypes
- array of known "single" arguments.restType
- If null, the arguments are fully specified by argTypes. If non-null, there may be an unknown number of extra arguments of the given restType. This is used for splices, where we usually don't know at compile-time how many argument values we have.- Returns:
- -1 if no; 1 if yes; 0 if need to check at run-time.
-
isAbstract
public boolean isAbstract()
-
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 usingobject.name(args...)
(Java syntax) or(invoke object 'name args...)
(Scheme syntax). This includes when theobject
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.
-
applyToConsumer
public static Object applyToConsumer(Procedure proc, CallContext ctx) throws Throwable
- Throws:
Throwable
-
applyToConsumerX
public Object applyToConsumerX(CallContext ctx) throws Throwable
- Throws:
Throwable
-
decodeType
public static Type decodeType(Type javaType, String[] annotTypes, int annotIndex, ParameterizedType parameterizedType, Language lang)
-
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()
-
compileRestArg
public static final void compileRestArg(Type arg_type, ApplyExp exp, int startArg, int i, Compilation comp)
-
canCompile
public boolean canCompile(ApplyExp exp)
-
compile
public boolean compile(ApplyExp exp, Compilation comp, Target target)
-
compileInvoke
public static void compileInvoke(Compilation comp, Method method, Target target, boolean isTailCall, int op_code, Type returnType, boolean doFixUnsigned)
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.
-
compileReachedUnexpected
public static void compileReachedUnexpected(CodeAttr code)
-
getParameterType
public Type getParameterType(int index)
- Overrides:
getParameterType
in classMethodProc
-
mostSpecific
public static int mostSpecific(PrimProcedure[] procs, int length)
Return the index of the most specific method. An approximation of the algorithm in JLS3 15.12.2.5 "Choosing the Most Specific Method."
-
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)
-
disassemble$X
public static void disassemble$X(Procedure pproc, CallContext ctx) throws Exception
- Throws:
Exception
-
disassemble
public static void disassemble(Procedure proc, Writer out) throws Exception
- Throws:
Exception
-
disassemble
public static void disassemble(Procedure proc, ClassTypeWriter cwriter) throws Exception
- Throws:
Exception
-
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, Expression[] args, Language language)
-
getMethodFor
public static PrimProcedure getMethodFor(ClassType procClass, String name, Declaration decl, Type[] atypes, Language language)
-
getName
public String getName()
- Specified by:
getName
in interfaceNamed
- Overrides:
getName
in classPropertySet
-
getVerboseName
public String getVerboseName()
-
print
public void print(PrintWriter ps)
-
-