Custom Code Block

Amir Hadar amir at clockwise3d.com
Tue Jan 21 06:08:24 EST 2003


I'm a colleague of Mr. Zeev. We have patched Python 2.2 with holger
patch and it worked real nice. This can really make things easier for
us.
However we still have a problem implementing a certain feature that we
need.
What we need is a fork bock
Example:
def func():
	<fork>
		print "hello"
	print "func end"

In this method we want the command print "hello" to run in a different
thread. A more generic solution will be something like a complex
macro. Means that this method will be translated to this:
def func():
	def uniquename():
		print "hello"
	fork(uniquename)
	print "func end"

If we could do the same without using a unique name it will be better.
I can do this without inventing new bytecodes by simply manipulating
the parse tree in the com_node(c,n) function. The problem is that the
node functions/macros lake the ability to extract a child node and
more important to get to the parent node. Without getting to the
parent node I can't replace the block statement with another one (I
can modify the current node instead).

Another solution is to insert the correct bytecodes as if this
manipulation was done. However, though I have some experience in Java
VMs, I don't really fully understand the python compiler and running
model to be able to do that without introducing bugs.
So I have the following questions:
-Where can I find documentation on the python bytecode, running model,
etc.?
-Is there something like a VM Spec to reference.
-If I want to manipulate the parse tree, can I hook to the parser
before the pars tree hits the compiler?
-If I modify the parse tree, can it harm in some way the compiler
(assuming that I leave a legal parse tree after I modify it)?
-Is there a way to hook to the parser through python code? Means that
python will use python to compile its files in import statment.

Any other help will be welcomed.

Thanks 
	Amir Hadar




More information about the Python-list mailing list