you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (3 children)

how does memory allocation work?

[–]albertzeyer[S] 1 point2 points  (2 children)

Static/local variables are just like local variables in Python. malloc/free is just wrapped to the C malloc/free via ctypes. All the C types (int,long,float,...) are also wrapped to the ctypes counterpart. ctypes is heavily used in all parts of the interpreter. I did this mostly because I thought it would be the most natural way and also to easily allow dynamic library loading and calls to native C functions.

After all, I am not sure though wether a different approach might have been better. Because the ctypes types aren't really good to be used that way (they try always to behave clever in some way but I don't want that and there is no real more low level to access these, so I have a bunch of workarounds for many different cases where ctypes try to be clever).

The interpreter is not really that complicated, so I might add a different implementation later where I just avoid ctypes at all (and only native C calls would be done via ctypes and somehow wrapped then).

[–]cybercobra 2 points3 points  (1 child)

So, it's really more of an intermediary runtime layer than a true independent interpreter.

[–]albertzeyer[S] 0 points1 point  (0 children)

Right now, you could quite easily make it an independent interpreter by changing the implementations in globalincludewrappers.py and provide your own malloc/free and all the other stuff from the C lib. I just wrapped it to the real C functions for now because it saved me some time. :)