peter at engcorp.com
Wed Aug 18 01:28:42 CEST 2004
Dave Benjamin wrote:
> I have been writing
> ActionScript for two years now, and I am so sick and tired of its lack of
> useful data structures (like sets and dictionaries), god-awful
> error-checking (any bad message results in the "undefined" value, which
> accpets any message and returns the "undefined" value, and so on, until your
> error surfaces someplace completely different from where it was caused),
> lack of exceptions, lack of any standard for modularity... I could just go
> on and on. I'm currently maintaining a 10,000 line ActionScript program, and
> I would be so happy to rewrite it in Python right now.
> And Python *is* magic. =)
So Dan was right on both counts. :-) ('''Either Dave thinks it just
can't be done, or he really, /really/ wants this compiler.''')
What version of the SWF format are you stuck writing to? It
by using attributes on an object. For example, "ActionEnumerate"
will let you iterate over all properties on an object ala the
Python "for k in dict".
As for exceptions, they were added in SWF 7, so I'm guessing you're
stuck somewhere prior to that. Your life must really suck. ;-)
> Peter Hansen wrote:
>>In any case, if this is a serious challenge, you'd better start
>>identifying the constraints and minimum requirements, as I'm
>>rather positive that it's possible to encode at least *one*
>>Python statement (print) into Flash bytecode which would
>>execute properly... shall I demonstrate for, say, one pie?
> Good point. I expect at least the full syntax as of Python 2.1, which means
> list comps but no "yield" or metaclasses or any fancy stuff like that.
> Perhaps one pie per Bagley's Shootout example, or maybe one pie per fully
> exposed Flash API (MovieClip, LocalConnection, etc.). I'm open to
Gosh you set a high target. Much as I like the taste of pie
(Mmmmm... piiiiie), and that cold clammy feeling as it drips down
inside my shirt, I don't think I'll be accepting the challenge any
time soon. Not, at least, until I learn a lot more about compilers
than I currently know (hint, it involves the word "sweet" and "all").
One thing that would help would be a little direction from
someone in the know as to how Jython handles things that are
simply not available in Java bytecode. For example, as far
as I know the main operators for basic primitive types in Java are
implemented with different bytecode instructions, while in
CPython things like "add" are implemented as a single bytecode
which happens to special case integers for performance, but
falls back to a dynamic lookup if the types being added are
That looks to me like a bit of a conundrum. To turn the Python
code into the appropriate Java bytecodes, wouldn't you have to
know the types of the data during compilation (as in static
data types)? But Python doesn't have that (yet), so how is
it done? Are all "adds" sent to some library routine which
is made available to all applications, and that routine then
handles the Python-style dynamic add operation?
In some ways, I think the SWF bytecode is even closer to Python
than Java's bytecode is, but I'm pretty sure that I couldn't
begin to imagine how one would target either of them...
More information about the Python-list