On 13/04/12 17:06, Stephen Ehring wrote:
I'm surprised this isn't implemented. From the IEEE 1275 spec:
patch ( "new-name< >old-name< >word-to-patch< >" -- ) Change contents of word-to-patch. In the compiled definition of word-to-patch, change the first occurrence of old-name to new-name. Works properly even if old-name and/or new-name are numbers. Used as: ok patch 555 test patch-me to edit the definition of patch-me, replacing the command test with the literal value 555. Implementation note: When replacing a command with a number, an implementation might need to automatically create a named constant value for the replacement number. (The reason is that Forth commands often compile into a smaller memory space than literal numbers, so patching a number in place of an existing command is a problem.) A suggested name format is h#---, i.e., the number 555 (hex) would be named “h#555” . A name containing only digits (i.e., 555 constant 555) is not recommended, since changing base would cause incorrect evaluation of subsequent uses of that named value.
(patch) ( new-n1 num1? old-n2 num2? xt -- ) Change contents of command indicated by xt. In the compiled definition of the command indicated by xt, change the first occurrence of old-n2 to new-n1. n1 and n2 can each be either an execution token or a literal number. The flag num1?, if true, indicates that new-n1 is a literal number. If false, it indicates that new-n1 is an execution token. The flag num2? is interpreted similarly. Used as: ['] new-name false 555 true ['] patch-me (patch) to edit the definition of patch-me, replacing the value 555 with the command new-name. See: patch for more information.
To be honest, I suspect the reason it's not been needed is that if we find any Forth bugs then it's easy enough just to update the binary image supplied with QEMU (i.e. we don't have to do updates to real hardware in the field).
ATB,
Mark.