[sugar] Education?

Antoine van Gelder hummingbird
Mon Mar 12 02:50:37 EDT 2007


Neal Norwitz wrote:
> On 3/11/07, Antoine van Gelder <hummingbird at hivemind.net> wrote:
>>
>> > If you meant byte code, the final stage of the compiler should be able
>> > to do that just fine.
>>
>> Aha! Was not aware that this was already possible! Best to start digging
>> in compiler.pycodegen ?
> 
> You are so brave!


*laugh* - nah, I just don't know any better!!

What I did find was:

--------------------------------------------------------------
Kay Schluehr wrote and Paul Boddie answered:
> Indeed? What can I do with following expression:
>
> >>> import compiler
> >>> expr = compiler.parse("1+2")
> >>> expr
> Module(None, Stmt([Discard(Add((Const(1), Const(2))))]))
>
> Which library function accepts a compiler.ast.Module
> object and generates bytecodes from it?

They don't make it easy. ;-)

compiler.misc.set_filename("test", expr)
g = compiler.pycodegen.ModuleCodeGenerator(expr)
code_object = g.getCode()

Actually generating bytecode files is slightly more involved, but 
there's a tool called libxml2macro in libxml2dom which has the magic 
incantations. Right now, I can't remember where I looked to find all 
this out.
--------------------------------------------------------------
http://www.artima.com/forums/flat.jsp?forum=106&thread=148389&start=30&msRange=15



> a) is pycodegen.  This converts the AST that is output from the


<snipped some great info>


> My memory is suspect of course, so you should verify all the details.
> :-)  But the basics should give you a better idea what's going on.
>
> We've talked about making a common AST used by CPython, IronPython,
> PyPy, and Jython.  However, no work has been done to date and no one
> is actively working on it.


Thanks Neal!


  - antoine





More information about the Sugar-devel mailing list