On Sat, 9 Aug 2003, Benjamin Goldberg wrote: > Michal Wallace wrote: > [snip] > > def f(): > > return g() > [snip] > > # f from line 3 > > .pcc_sub _sub1 non_prototyped > > .local object res1 # (visitReturn:528) > > find_lex $P2, 'g' # (callingExpression:325) > > newsub $P3, .Continuation, ret0# (callingExpression:331) > > .pcc_begin non_prototyped # (callingExpression:332) > > .pcc_call $P2, $P3 # (callingExpression:335) > > ret0: > > .result res1 # (callingExpression:338) > > .pcc_end # (callingExpression:339) > > .pcc_begin_return # (visitReturn:530) > > .return res1 # (visitReturn:531) > > .pcc_end_return # (visitReturn:532) > > .end > > Does python allow tail calls to be optomized? That is, would it be > legal python semantics if f were to become: > > .pcc_sub _sub1 non_prototyped > find_lex $P2, 'g' > .pcc_begin non_prototyped > .pcc_call $P2, P1 > .pcc_end > .end
Well, the "real" python doesn't optimize tail-calls at all. You'll get a nasty "max recursion depth exceeded" traceback if you try running "def f(x): return f(x+1)" But I don't see any reason pirate shouldn't do it, since the difference is pretty much transparent. > (untested) > Also... why is $P2 merely an imcc temporary, without a real name? That > is, why not do: > > .pcc_sub _sub1 non_prototyped > .local object sub1 > find_lex sub1, 'g' > .pcc_begin non_prototyped > .pcc_call sub1, P1 > .pcc_end > .end > > The more different prefixes you use ("res", "sub", "$P"), the lower the > numbers you'll need to append to them to make the names unique. Not to > mention, it'll make the generated code more meaningful. > > Another advantage is that with '.local' names, if you accidentally use a > name declared in one subroutine, in another, imcc will consider this to > be an error. Such a mistake might be otherwise difficult to spot. Hmmm. The counters are global so there shouldn't be any conflicts. I'd actually been trying to move away from .local now that I started using lexicals... If there's going to be two sets of names for everything I'd rather one of them was just $Pxx... Now, if I could say: .lexical g That would be really nice... :) Sincerely, Michal J Wallace Sabren Enterprises, Inc. ------------------------------------- contact: [EMAIL PROTECTED] hosting: http://www.cornerhost.com/ my site: http://www.withoutane.com/ --------------------------------------