python interpreter

G

g.franzkowiak

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) ();
}
 
P

Paul Rubin

g.franzkowiak said:
Where can I find informations like this for Python ?

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

Marc 'BlackJack' Rintsch

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) ();
}

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
 
N

Neal Norwitz

g.franzkowiak said:
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 ?

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_func))

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top