[e-lang] A different way to optimize parameterizations: eliminating intermediate objects
Kevin Reid
kpreid at attglobal.net
Tue May 16 13:07:42 EDT 2006
The advantages of this technique over the previously-discussed
constant folding are that it requires no interaction between
DeepFrozen and the compiler, no compile-time evaluation, and can work
for non-DeepFrozen parameterizations such as the expansion of
quasiliteral $-holes.
However, it is, I think, complicated to implement correctly and
efficiently.
If one has a call sequence such as
List.get(int).coerce(arg, null)
then it could be compiled into:
List.<<get/1 + coerce/2>>(int, arg, null)
(the <<>> here stands for something which is not actually E source)
The Miranda behavior for any such magic combination verb (these verbs
would not be implementable in user code, much like auditing checks)
is to execute the chain:
def MirandaMethods { # not real E
match [[v1, v2] :UnpackChainVerb, args] {
E.call(E.call(self, v1, args(0, v1.arity())),
v2,
args(v1.arity()))
}
}
However, when a compiler has access to a nested object definition, it
can compile in an (invisible) combined method.
Input:
def List {
to get(elementGuard) {
def TypedList {
to coerce(specimen, optEjector) {
...
}
}
return TypedList
}
}
Output:
def List {
to get(elementGuard :Guard) {
def TypedList {
to coerce(specimen, optEjector) {
...
}
}
return TypedList
}
# Generated method
to <<get/1 + coerce/2>>(elementGuard :Guard, specimen,
optEjector) {
# same as body of TypedList#coerce/2.
# compiler could take steps to use the same compiled code to
# implement both
...
}
}
Or:
def <<List$TypedList#coerce/2>>(elementGuard, specimen, optEjector) {
# note that this function's argument list is unguarded; this is
really transfer of lexical variables, and would not be implemented as
actual ENode generation
...
}
def List {
to get(elementGuard :Guard) {
def TypedList {
to coerce(specimen, optEjector) {
<<List$TypedList#coerce/2>>(elementGuard, specimen,
optEjector)
}
}
return TypedList
}
to <<get/1 + coerce/2>>(elementGuard :Guard, specimen,
optEjector) {
<<List$TypedList#coerce/2>>(elementGuard, specimen, optEjector)
}
}
--
Kevin Reid <http://homepage.mac.com/kpreid/>
More information about the e-lang
mailing list