
karl3@writeme.com wrote:
karl3@writeme.com wrote:
karl3@writeme.com wrote: karl3@writeme.com wrote: karl3@writeme.com wrote: GPT-4 User Come up with an analog to "goto" in python that engages the raw interpreter and/or bytecode systems of python to function. i want to try! it sounds like one preference is to see if it works to create a function that accesses the bytes of its caller's code and uses ctypes to modify them taking a pause cause it feels funny, might do a different thing now i bet however pdb and trace work would be a higher level way without ctypes!
they use sys.settrace() which lets one install an event handler for major interpreter actions like line, call, return meanwhile, the frame object does have access to the local variables of callers, so one could have a function that turns callers into coroutines by collecting little chunks of code and evaluating them with injected locals. whenever a goto()-like function is called, execution would return to this alternative-vm that would break functions apart and move between frames by injecting locals into bytecode. it would only return if its original frame were goto'd back into. a little wonky but interesting! the frame.f_locals[] object is writeable, so one could theoretically update the locals of callers properly if they are changed in a side-vm