Using bytecode, not code objects

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fabiano Sidler

    #1

    Using bytecode, not code objects

    Hi folks!

    I'm looking for a way to compile python source to bytecode instead of
    code-objects. Is there a possibility to do that? The reason is: I want
    to store pure bytecode with no additional data.

    The second question is, therefore: How can I get the correct values
    for a given bytecode, such as the stacksize and flags attributes of
    the correspondent code object?

    No, I don't want to extract all of these things out of a code object.

    Best wishes and thanks for answering!
    F. Sidler
  • Raymond Hettinger

    #2
    Re: Using bytecode, not code objects

    [Fabiano Sidler][color=blue]
    > I'm looking for a way to compile python source to bytecode instead of
    > code-objects. Is there a possibility to do that? The reason is: I want
    > to store pure bytecode with no additional data.
    >
    > The second question is, therefore: How can I get the correct values
    > for a given bytecode, such as the stacksize and flags attributes of
    > the correspondent code object?
    >
    > No, I don't want to extract all of these things out of a code object.[/color]

    Why not? The code object gives you all of these values directly.

    But if you want to make your life unnecessarily hard, you can hack the
    compiler module just upstream from the creation of the code object --
    alter the newCodeObject() method in pyassem.py.

    It's a pointless exercise, but maybe you'll have fun doing it or
    perhaps learn not to avoid obvious, direct solutions to the problem at
    hand.


    Raymond

    Comment

    • Fabiano Sidler

      #3
      Re: Using bytecode, not code objects

      2006/1/29, Fabiano Sidler <fabianosidler@ gmail.com>:[color=blue]
      > 28 Jan 2006 22:02:45 -0800, Raymond Hettinger <python@rcn.com >:[color=green]
      > > But if you want to make your life unnecessarily hard, you can hack the
      > > compiler module just upstream from the creation of the code object --
      > > alter the newCodeObject() method in pyassem.py.[/color]
      >
      > Thanks! I think this will help me, because it demonstrates how a code
      > object is to be created (with new.code), although in a very
      > complicated way.[/color]

      Are you familiar with this module? I don't get the essence of it, even
      with pdb (which I'm surely not using as neatly as it could be). Or is
      there any documentation on it I couldn't find?

      Greetings,
      F. Sidler

      Comment

      • Raymond Hettinger

        #4
        Re: Using bytecode, not code objects


        Fabiano Sidler wrote:[color=blue]
        > 2006/1/29, Fabiano Sidler <fabianosidler@ gmail.com>:[color=green]
        > > 28 Jan 2006 22:02:45 -0800, Raymond Hettinger <python@rcn.com >:[color=darkred]
        > > > But if you want to make your life unnecessarily hard, you can hack the
        > > > compiler module just upstream from the creation of the code object --
        > > > alter the newCodeObject() method in pyassem.py.[/color]
        > >
        > > Thanks! I think this will help me, because it demonstrates how a code
        > > object is to be created (with new.code), although in a very
        > > complicated way.[/color]
        >
        > Are you familiar with this module? I don't get the essence of it, even
        > with pdb (which I'm surely not using as neatly as it could be). Or is
        > there any documentation on it I couldn't find?[/color]

        The pysassem module is part of the compiler package:




        Raymond

        Comment

        • Terry Reedy

          #5
          Re: Using bytecode, not code objects


          "Raymond Hettinger" <python@rcn.com > wrote in message
          news:1139263624 .553961.236730@ g14g2000cwa.goo glegroups.com.. .[color=blue]
          >
          > Fabiano Sidler wrote:[color=green]
          >> with pdb (which I'm surely not using as neatly as it could be). Or is
          >> there any documentation on it I couldn't find?[/color]
          >
          > The pysassem module is part of the compiler package:
          >
          > http://docs.python.org/lib/compiler.html[/color]

          The 2.4 docs, which the above links to, only has sections on modules
          compiler, compiler.ast, and compiler.visito r and not on .consts, .future,
          ..misc, .pyassem, .pycodegen, .symbols, and .transformer. However,

          import compiler
          help(compiler.a st)

          gives a few pages of info derived from the module.

          Terry Jan Reedy



          Comment

          Working...