Is there a way to add words to the end of a definition? If my word is declared like this:
: myword firstWord secondWord ;
is there a way to append a word to the end of this word so it looks like this:
: myword firstWord secondWord thirdWord ;
On 2012-Mar-22 00:09 , Programmingkid wrote:
Is there a way to add words to the end of a definition? If my word is declared like this:
: myword firstWord secondWord ;
is there a way to append a word to the end of this word so it looks like this:
: myword firstWord secondWord thirdWord ;
The usual way I'd do something like that if I had to patch a live system would be as follows:
ok : anotherWord secondWord thirdWord ; ok patch anotherWord secondWord myword ok
On Mar 22, 2012, at 1:29 AM, Tarl Neustaedter wrote:
On 2012-Mar-22 00:09 , Programmingkid wrote:
Is there a way to add words to the end of a definition? If my word is declared like this:
: myword firstWord secondWord ;
is there a way to append a word to the end of this word so it looks like this:
: myword firstWord secondWord thirdWord ;
The usual way I'd do something like that if I had to patch a live system would be as follows:
ok : anotherWord secondWord thirdWord ; ok patch anotherWord secondWord myword ok
You can also use (patch) with the XT's if the words are not externally visible.
Steve
On 22/03/12 12:16, Stephen Ehring wrote:
On 2012-Mar-22 00:09 , Programmingkid wrote:
Is there a way to add words to the end of a definition? If my word is declared like this:
: myword firstWord secondWord ;
is there a way to append a word to the end of this word so it looks like this:
: myword firstWord secondWord thirdWord ;
The usual way I'd do something like that if I had to patch a live system would be as follows:
ok : anotherWord secondWord thirdWord ; ok patch anotherWord secondWord myword ok
You can also use (patch) with the XT's if the words are not externally visible.
Steve
I'm fairly sure that OpenBIOS don't implement either patch or (patch) at the moment. If it's just a case of replacing one XT with another within a word definition, then it shouldn't be too hard - or does it do something more clever?
ATB,
Mark.
On Apr 13, 2012, at 11:53 AM, Mark Cave-Ayland wrote:
On 22/03/12 12:16, Stephen Ehring wrote:
On 2012-Mar-22 00:09 , Programmingkid wrote:
Is there a way to add words to the end of a definition? If my word is declared like this:
: myword firstWord secondWord ;
is there a way to append a word to the end of this word so it looks like this:
: myword firstWord secondWord thirdWord ;
The usual way I'd do something like that if I had to patch a live system would be as follows:
ok : anotherWord secondWord thirdWord ; ok patch anotherWord secondWord myword ok
You can also use (patch) with the XT's if the words are not externally visible.
Steve
I'm fairly sure that OpenBIOS don't implement either patch or (patch) at the moment. If it's just a case of replacing one XT with another within a word definition, then it shouldn't be too hard - or does it do something more clever?
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.
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.
You can also use (patch) with the XT's if the words are not externally visible.
Steve
I'm fairly sure that OpenBIOS don't implement either patch or (patch) at the moment. If it's just a case of replacing one XT with another within a word definition, then it shouldn't be too hard - or does it do something more clever?
That's exactly what it does. If you look at the IEEE 1275 definition of "patch" and "(patch)", you see it has to do something a bit more carefully with numbers vs xt's - replacing "157" with "noop" requires a bit of finesse...