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 MethodHandlestatic booleanSupport 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_EXCEPTIONFields inherited from class gnu.mapping.ProcedureN
applyToObject, noArgsFields inherited from class gnu.mapping.Procedure
applyMethodType, applyToConsumerDefault, applyToConsumerMethod, applyToObjectDefault, applyToObjectMethod, compilerKey, compilerXKey, inlineIfConstantSymbol, validateApplyKey, validateXApplyKeyFields 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 ObjectapplyToConsumer(Procedure proc, CallContext ctx) booleancanCompile(ApplyExp exp) booleancompile(ApplyExp exp, Compilation comp, Target target) static voidcompileInvoke(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 voidstatic final voidcompileRestArg(Type arg_type, ApplyExp exp, int startArg, int i, Compilation comp) static TypedecodeType(Type javaType, String[] annotTypes, int annotIndex, ParameterizedType parameterizedType, Language lang) static voiddisassemble(Procedure proc, ClassTypeWriter cwriter) static voiddisassemble(Procedure proc, Writer out) static voiddisassemble$X(Procedure pproc, CallContext ctx) static PrimProceduregetMethodFor(ClassType procClass, String name, Declaration decl, Type[] atypes, Language language) static PrimProceduregetMethodFor(ClassType procClass, String name, Declaration decl, Expression[] args, Language language) static PrimProceduregetMethodFor(Procedure pproc, Declaration decl, Type[] atypes, Language language) static PrimProceduregetMethodFor(Procedure pproc, Declaration decl, Expression[] args, Language language) Search for a matching static method in a procedure's class.static PrimProceduregetMethodFor(Procedure pproc, Expression[] args) static PrimProceduregetMethodFor(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 ClassgetProcedureClass(Object pproc) getReturnType(Expression[] args) Semi-deprecated - instead should be set at Inline time.final booleanTrue if there is no 'this' parameter.booleanintisApplicable(Type[] argTypes, Type restType) Test if method is applicable to an invocation with given arguments.final booleanbooleanTrue if this Procedure (definitely) has no side-effects.booleanstatic PrimProceduremakeBuiltinBinary(int opcode, Type type) static PrimProceduremakeBuiltinUnary(int opcode, Type type) static intmostSpecific(PrimProcedure[] procs, int length) Return the index of the most specific method.intnumArgs()The (minimum, number) of arguments.final intopcode()voidprint(PrintWriter ps) voidvoidsetReturnType(Type retType) voidbooleanstatic booleantakesContext(Method method) booleanWhether we are passed an argument for the 'target' / 'receiver' / 'this'.booleanReturn true iff the last parameter is a "rest" argument.static booleantakesVarArgs(Method method) toString()Methods inherited from class gnu.mapping.MethodProc
applyToConsumerDefaultMP, matchFailAsException, mostSpecific, numParameters, overrideEquivalent, resolveParameterTypesMethods inherited from class gnu.mapping.ProcedureN
applyToObjectMethods 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, setSourceLocationMethods 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:ProcedureSemi-deprecated - instead should be set at Inline time. FIXME- Overrides:
getReturnTypein classProcedure
-
getDeclaringClass
-
getMethod
-
setMethodForInvoke
-
isSideEffectFree
public boolean isSideEffectFree()Description copied from class:ProcedureTrue if this Procedure (definitely) has no side-effects. Note side-effect-free does not imply idempotent if this allocates an object with "identity".- Overrides:
isSideEffectFreein 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:MethodProcTest if method is applicable to an invocation with given arguments.- Overrides:
isApplicablein 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 theobjectis 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:
getParameterTypein 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:
getNamein interfaceNamed- Overrides:
getNamein classPropertySet
-
getVerboseName
-
toString
-
print
-