Is there a way to go from the AST output of compiler.paser to byte
code
i.e. in the example below, is there a way to compile m and get a code
object that could then be called?
cheers and thanks for the help
chris wright
[color=blue][color=green][color=darkred]
>>> s = """[/color][/color][/color]
.... def test(x):
.... y = x + 1
.... print x, y
.... """[color=blue][color=green][color=darkred]
>>> m = compiler.parse( s)
>>> m[/color][/color][/color]
Module(None, Stmt([Function('test' , ['x'], [], 0, None,
Stmt([Assign([AssName('y', 'OP_ASSIGN')], Add((Name('x'), Const(1)))),
Printnl([Name('x'), Name('y')], None)]))]))[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
code
i.e. in the example below, is there a way to compile m and get a code
object that could then be called?
cheers and thanks for the help
chris wright
[color=blue][color=green][color=darkred]
>>> s = """[/color][/color][/color]
.... def test(x):
.... y = x + 1
.... print x, y
.... """[color=blue][color=green][color=darkred]
>>> m = compiler.parse( s)
>>> m[/color][/color][/color]
Module(None, Stmt([Function('test' , ['x'], [], 0, None,
Stmt([Assign([AssName('y', 'OP_ASSIGN')], Add((Name('x'), Const(1)))),
Printnl([Name('x'), Name('y')], None)]))]))[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
Comment