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
A primitive Procedure implemented by a plain Java method.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final MethodHandle
static boolean
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
ConstructorsConstructorDescriptionPrimProcedure
(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
Modifier and TypeMethodDescriptionstatic Object
applyToConsumer
(Procedure proc, 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
static final 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) 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.getName()
getParameterType
(int index) final Type[]
static Class
getProcedureClass
(Object pproc) getReturnType
(Expression[] args) Semi-deprecated - instead should be set at Inline time.final boolean
True if there is no 'this' parameter.boolean
int
isApplicable
(Type[] argTypes, Type restType) Test if method is applicable to an invocation with given arguments.final boolean
boolean
True if this Procedure (definitely) has no side-effects.boolean
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.final int
opcode()
void
print
(PrintWriter ps) void
void
setReturnType
(Type retType) void
boolean
static boolean
takesContext
(Method method) boolean
Whether we are passed an argument for the 'target' / 'receiver' / 'this'.boolean
Return true iff the last parameter is a "rest" argument.static boolean
takesVarArgs
(Method method) 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 Details
-
explicitArrayAsVarArgsAllowed
public static boolean explicitArrayAsVarArgsAllowedSupport 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
-
-
Constructor Details
-
PrimProcedure
-
PrimProcedure
-
PrimProcedure
-
PrimProcedure
-
PrimProcedure
-
PrimProcedure
public PrimProcedure(Method method, char mode, Language language, ParameterizedType parameterizedType) -
PrimProcedure
-
PrimProcedure
-
PrimProcedure
-
-
Method Details
-
opcode
public final int opcode() -
getReturnType
-
setReturnType
-
isSpecial
public boolean isSpecial() -
getReturnType
Description copied from class:Procedure
Semi-deprecated - instead should be set at Inline time. FIXME- Overrides:
getReturnType
in classProcedure
-
getDeclaringClass
-
getMethod
-
setMethodForInvoke
-
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
-
takesContext
public boolean takesContext() -
takesContext
-
isApplicable
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
- Throws:
Throwable
-
applyToConsumerX
- Throws:
Throwable
-
decodeType
public static Type decodeType(Type javaType, String[] annotTypes, int annotIndex, ParameterizedType parameterizedType, Language lang) -
makeBuiltinUnary
-
makeBuiltinBinary
-
getStaticFlag
public final boolean getStaticFlag()True if there is no 'this' parameter. -
getParameterTypes
-
compileRestArg
public static final void compileRestArg(Type arg_type, ApplyExp exp, int startArg, int i, Compilation comp) -
canCompile
-
compile
-
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
-
getParameterType
- Overrides:
getParameterType
in classMethodProc
-
mostSpecific
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
-
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
- Throws:
Exception
-
disassemble
- Throws:
Exception
-
disassemble
- Throws:
Exception
-
getProcedureClass
-
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
- Specified by:
getName
in interfaceNamed
- Overrides:
getName
in classPropertySet
-
getVerboseName
-
toString
-
print
-