Unless I misunderstand the original problem, I don't consider it to be a self-modifying program, but rather a program generator, which is a significantly less hazardous programming technique. (With a self-modifying program, the program alters its own code as it is running, and you end up with a different program from the one you started with. There are actually very few legitimate reasons to do this.)
It sounds, instead, as if what is wanted here is a program that can write another program, based on some user input, and then run that generated program repeatedly under controlled conditions. Without knowing more about why this approach is considered the only reasonable one for performance reasons, my approach to the problem as stated would be to write the Petri net engine first, which would also force me to design the corresponding graph data representation in registers. Then I'd re-write the core of the engine in machine code, while leaving the user interface in user code (which, of course, requires you to have some additional hardware for executing your own machine code, which you might not have).
(But really, if performance was going to be that poor, I'd seriously consider switching platforms, if only to a 41 emulator on a PDA or something.)
Quote:
So the solution was to write the code sequence to RAM, modify the address byte and call the modified code.
This is pretty similar to a technique I (and probably many others) use to implement graceful degradation of Javascript-dependent functionality in web pages. The version of the page that works without Javascript is sent to the browser, but includes a call to a Javascript function that alters appropriate nodes in the web page's in-memory representation to change it into the corresponding Javascript-enhanced version. If Javascript is not available in the browser for any reason, the function call gets ignored and the user sees the non-JS version; if Javascript is available, the user only sees the Javascript-enhanced version. (This also allows more fine-grained feature switching, based on things like platform, screen size, rendering engine and other fiddling details. In general, though, trying to be too smart about this leads to madness at both ends of the network.)
The only real differences with the MS BASIC technique are that the RAM I'm using is in the memory space of the browser on another computer, possibly on another continent, and the instruction sets I'm toggling between are vastly more elaborate and flakey than the old Intel/Zilog operations.