|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.vub.at.eval.PartialBinder
Instances of the class PartialBinder represent 'partial functions' whose task it is to bind the formal parameters of a function to the actual arguments upon function application. The binding process of formals to actuals is an ideal candidate for partial evaluation, because the binding algorithm depends mainly on two parameters: the formal parameter list (which is known at function definition time, and does not change) and the actual argument list (provided at call time). At function definition time, one may partially evaluate the binding algorithm according to the form of the formal parameter list. The resulting 'residual function' is an instance of this class and can subsequently be used to bind (define or assign) actual arguments at runtime, saving out a number of checks which would have otherwise been performed at every function invocation. The general form of a function's formal parameter list is: (mandatory arguments: ATSymbol)* (optional arguments: ATAssignVariable)* (rest argument: ATSplice)? Given such a formal parameter list, we define 8 different kinds of partial functions, each specialized for the absence of one of the three different kinds of parameters: (the numbers behind the partial function's name denote the number of mandatory, optional and rest args) - ZeroArity (0 0 0) example: f() - Mandatory (n 0 0) example: f(a,b) - MandatoryOptional (n m 0) example: f(a,b,c:=1) - Optional (0 m 0) example: f(a:=1,b:=2) - VariableArity (0 0 1) example: f(@rest) - MandatoryVariable (n 0 1) example: f(a,b,@rest) - OptionalVariable (0 m 1) example: f(a:=1,@rest) - Generic (n m 1) example: f(a,b:=1,@rest) Note also that the partial evaluation of the binding algorithm at function definition time allows the signalling of illegal parameter lists (e.g. when optional arguments are followed by mandatory arguments) early, rather than latently detecting such illegal parameter lists at method invocation time.
Nested Class Summary | |
private static interface |
PartialBinder.BindClosure
|
Constructor Summary | |
PartialBinder()
|
Method Summary | |
static void |
assignArgsToParams(PartialBinder residual,
ATContext context,
ATTable arguments)
Assign all of the formal parameter names in the scope object to the given arguments The scope is defined as the lexical scope of the given context. |
protected abstract void |
bind(ATObject[] arguments,
ATContext inContext,
PartialBinder.BindClosure binder)
Bind the given actual arguments to the formal parameters encapsulated by this partial bind function. |
static PartialBinder |
calculateResidual(java.lang.String forFunction,
ATTable parameters)
Performs the partial evaluation of the binding algorithm given the formal parameters. |
static void |
defineParamsForArgs(PartialBinder residual,
ATContext context,
ATTable arguments)
Bind all of the given parameters as newly defined slots in the given scope to the given arguments. |
private static PartialBinder |
makeGeneric(java.lang.String funnam,
ATObject[] formals,
int numMandatory,
int numOptional)
- Generic (n m 1) example: f(a,b:=1,@rest) |
private static PartialBinder |
makeMandatory(java.lang.String funnam,
ATObject[] formals)
- Mandatory (n 0 0) example: f(a,b) |
private static PartialBinder |
makeMandatoryOptional(java.lang.String funnam,
ATObject[] formals,
int numMandatory,
int numOptional)
- MandatoryOptional (n m 0) example: f(a,b,c:=1) |
private static PartialBinder |
makeMandatoryVariable(java.lang.String funnam,
ATObject[] formals)
- MandatoryVariable (n 0 1) example: f(a,b,@rest) |
private static PartialBinder |
makeOptional(java.lang.String funnam,
ATObject[] formals)
- Optional (0 m 0) example: f(a:=1,b:=2) |
private static PartialBinder |
makeOptionalVariable(java.lang.String funnam,
ATObject[] formals)
- OptionalVariable (0 m 1) example: f(a:=1,@rest) |
private static PartialBinder |
makeVariableArity(java.lang.String funnam,
ATSymbol formal)
- VariableArity (0 0 1) example: f(@rest) |
private static PartialBinder |
makeZeroArity(java.lang.String funnam)
- ZeroArity (0 0 0) example: f() |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PartialBinder()
Method Detail |
protected abstract void bind(ATObject[] arguments, ATContext inContext, PartialBinder.BindClosure binder) throws InterpreterException
arguments
- the actual arguments to the function, supplied at function application timeinContext
- the context in which to bind the formal parameters and in which to evaluate default optional parameter expressionsbinder
- a closure which determines whether to define or assign the formals in the scope
InterpreterException
public static final void defineParamsForArgs(PartialBinder residual, ATContext context, ATTable arguments) throws InterpreterException
InterpreterException
public static final void assignArgsToParams(PartialBinder residual, ATContext context, ATTable arguments) throws InterpreterException
InterpreterException
public static PartialBinder calculateResidual(java.lang.String forFunction, ATTable parameters) throws InterpreterException
forFunction
- the name of the function for which the parameter list is partially evaluated, for debugging purposes.parameters
- the formal parameter list
PartialBinder#bind(ATTable, ATContext, BindClosure)
method binds the formal parameters given here to the actual arguments supplied at function application time.
XIllegalParameter
- when the formal parameter list does not adhere to the language format
InterpreterException
private static final PartialBinder makeZeroArity(java.lang.String funnam)
private static final PartialBinder makeMandatory(java.lang.String funnam, ATObject[] formals)
private static final PartialBinder makeMandatoryOptional(java.lang.String funnam, ATObject[] formals, int numMandatory, int numOptional)
private static final PartialBinder makeOptional(java.lang.String funnam, ATObject[] formals)
private static final PartialBinder makeVariableArity(java.lang.String funnam, ATSymbol formal)
private static final PartialBinder makeMandatoryVariable(java.lang.String funnam, ATObject[] formals)
private static final PartialBinder makeOptionalVariable(java.lang.String funnam, ATObject[] formals)
private static final PartialBinder makeGeneric(java.lang.String funnam, ATObject[] formals, int numMandatory, int numOptional)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |