python interpreter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • g.franzkowiak

    #1

    python interpreter

    Hi everybody,

    my interest is for the internals of the Python interpreter.

    I've used up to now FORTH for something and this indirect interpreter is
    very smart.
    --- ASM ---------------------------------------------------------------

    NEXT: LODSW ; WA <- [IP]
    ; IP <- IP+2
    MOV T,WA ; T <- WA1 (CFA)
    JMP [T] ; JMP [CFA]

    --- C -----------------------------------------------------------------

    for (;;)
    {
    w = *ip++;
    (**w) ();
    }

    -------------------------------------------------------------------------

    Where can I find informations like this for Python ?

    gerd
  • Paul Rubin

    #2
    Re: python interpreter

    "g.franzkow iak" <g.franzkowiak@ onlinehome.de> writes:[color=blue]
    > Where can I find informations like this for Python ?[/color]

    "Use the force, read the source". Python's interpreter is more like a
    big switch statement on bytecodes, though.

    Comment

    • Marc 'BlackJack' Rintsch

      #3
      Re: python interpreter

      In <digm1h$9si$1@o nline.de>, g.franzkowiak wrote:
      [color=blue]
      > my interest is for the internals of the Python interpreter.
      >
      > I've used up to now FORTH for something and this indirect interpreter is
      > very smart.
      > --- ASM ---------------------------------------------------------------
      >
      > NEXT: LODSW ; WA <- [IP]
      > ; IP <- IP+2
      > MOV T,WA ; T <- WA1 (CFA)
      > JMP [T] ; JMP [CFA]
      >
      > --- C -----------------------------------------------------------------
      >
      > for (;;)
      > {
      > w = *ip++;
      > (**w) ();
      > }
      >
      > -------------------------------------------------------------------------
      >
      > Where can I find informations like this for Python ?[/color]

      I don't really grok the assembler code. The C code seems to assume that
      there is an infinitive number of function pointers stored at `*ip`!?

      The Python equivalent might be ::

      for w in ip:
      w()

      if `ip` is a (finite) sequence of functions or callables in general.

      Ciao,
      Marc 'BlackJack' Rintsch

      Comment

      • Neal  Norwitz

        #4
        Re: python interpreter

        g.franzkowiak wrote:[color=blue]
        > Hi everybody,
        >
        > my interest is for the internals of the Python interpreter.
        >
        > I've used up to now FORTH for something and this indirect interpreter is
        > very smart.
        > --- ASM ---------------------------------------------------------------
        >
        > Where can I find informations like this for Python ?[/color]

        Depends on what you want. If you want to see the disassembled bytes
        similar to what I cut out, see the dis module. (e.g.,
        dis.dis(foo_fun c))

        If you want to know how the byte codes are created, it's mostly in
        Python/compile.c. If you want to know how the byte codes are executed,
        it's mostly in Python/ceval.c.

        All base Python objects implemented in C are under Objects/. All
        standard modules implemented in C are under Modules/.

        Get the source and build it. It's quite readable.

        n

        Comment

        Working...