Moritz Lenz wrote:
> Is there a construct that lets me find a multi, and that will later do
> dispatch based on the types of the parameters that I'll hand to it?
chromatic told me about "find_global", so that's what I tried, with
partial success.
This is what my local copy of the sort builtins look like (including
debug print output):
.namespace []
.sub 'sort' :multi()
.param pmc values :slurpy
.local pmc by
print "SUB sort\n"
find_global by, 'infix:cmp'
unless values goto have_by
$P0 = values[0]
$I0 = isa $P0, 'Sub'
unless $I0 goto have_by
by = shift values
have_by:
.return values.'sort'(by)
.end
.namespace ['Any']
.sub 'sort' :method :multi(_)
.param pmc by :optional
.param int has_by :opt_flag
print "METHOD sort\n"
if has_by goto have_by
find_global by, 'infix:cmp'
have_by:
.local pmc list, fpa
.local int elems
list = self.'list'()
list.'!flatten'()
elems = list.'elems'()
fpa = new 'FixedPMCArray'
fpa = elems
.local int i
i = 0
fpa_loop:
unless i < elems goto fpa_end
$P0 = list[i]
fpa[i] = $P0
inc i
goto fpa_loop
fpa_end:
fpa.'sort'(by)
.return 'list'(fpa)
.end
Now '<a b>.sort' works fine (it didn't before), but 'sort <a b>' fails
like this:
SUB sort
METHOD sort
No applicable methods.
current instr.: 'parrot;Any;sort' pc 3090 (src/gen_builtins.pir:2129)
called from Sub 'parrot;Any;sort' pc 10477 (src/gen_builtins.pir:6568)
So the sub sort calls the method sort, where it dies, and I have no idea
why.
Any thoughts on how I could fix this?
Moritz
--
Moritz Lenz
http://moritz.faui2k3.org/ | http://perl-6.de/
_______________________________________________
http://lists.parrot.org/mailman/listinfo/parrot-dev