Hey all,

I'm trying to get functions working
in python, and I'm not sure the best way
to do this.

What seems natural to me is to define 
subroutines in the middle of the code 
as I walk the parse tree:

.sub __main__
    goto endsub
    .sub _f
        print ":(\n"
        ret
   .end
endsub:
   $I0 = addr _f
   end
.end


But of course, this prints a sad face. :/

I've read imcc/docs/parsing.pod, so I know
why it does this... But what's the alternative?

I can store all my subroutine definitions in 
a list or something and then dump them out
after the "__main__" routine. Is that the
right approach? It seems strange to me,
but I'm new at this.

---

Incidentally, I spent all day working on pirate,
and it now generates (and runs!) code for a bunch
of python structures:

    - lists, strings, ints
    - assignment and multi-assignment ( x,y=1,2 )
    - while, for, if/elif/else, break, continue
    - math operations (+, -, *, /, %)
    - boolean logic (and, or, not)
    - comparison operators

It now runs amk's euclid.py perfectly now.
Do we have a way to compare the speed vs python? :)

Also, I wrote a pretty-printer for the lists in
parrot, and you can call it (and presumably
other parrot subs) directly from python code:

if 1 > 2:
    _pyprint("one is greater than two...")
    print "neat,huh?"

If I could get this subroutine stuff figured
out, you could call functions written in 
python, too. :)

  http://sixthdev.versionhost.com/viewcvs.cgi/pirate/

Sincerely,
 
Michal J Wallace
Sabren Enterprises, Inc.
-------------------------------------
contact: [EMAIL PROTECTED]
hosting: http://www.cornerhost.com/
my site: http://www.withoutane.com/
--------------------------------------


Reply via email to