|
|||
|
Hi All,
I want to copy existing words into a new wordlist. My first thought was to use: : & ( <w> -- ) >IN @ ' SWAP >IN ! CREATE , DOES> @ EXECUTE ; However, this doesn't work for copying IMMEDIATE words. I can use EVALUATE, but it's very wordy: : & ( <w> -- ) S" : " PAD PLACE BL WORD DUP >R COUNT 2DUP PAD APPEND S" " PAD APPEND R> FIND NIP DUP IF 1 = IF S" POSTPONE " PAD APPEND PAD APPEND S" ; IMMEDIATE" PAD APPEND \ : FOO POSTPONE FOO ; IMMEDIATE ELSE PAD APPEND S" ;" PAD APPEND \ : FOO FOO ; THEN PAD COUNT EVALUATE ELSE 3DROP THEN \ Not found, don't make an alias ; Is there a simpler (but portable) way? Does 200x propose ALIAS? -Brad |
|
|
||||
|
||||
|
|
|
|||
|
On Feb 7, 11:53*am, Brad <hwfw...@gmail.com> wrote:
> Hi All, > > I want to copy existing words into a new wordlist. > > My first thought was to use: > > : & *( <w> -- ) *>IN @ ' SWAP >IN ! *CREATE , *DOES> @ EXECUTE ; > > However, this doesn't work for copying IMMEDIATE words. I can use > EVALUATE, but it's very wordy: I see why you switch from ' to FIND to get the IMMEDIATE status, but I don't see why you switch to EVALUATE at the same time. Wouldn't something along the lines of ... : does-@EXECUTE ( -- ) DOES> @ EXECUTE ; : & ( "word" -- ) >IN @ BL WORD FIND ?DUP IF ROT >IN ! CREATE SWAP , does-@EXECUTE 1 = IF IMMEDIATE THEN ELSE CR ." Cannot find: " COUNT TYPE DROP THEN ; .... do it? |
|
|||
|
On Feb 7, 10:59*am, stephen...@mpeforth.com (Stephen Pelc) wrote:
> SYNONYM <newname> <oldname> > Okay. But for brevity (and since the names are identical): : & ( <name> -- ) >IN @ BL WORD FIND DUP 0= THROW ROT >IN ! CREATE SWAP , 1 = IF IMMEDIATE THEN DOES> @ EXECUTE ; |
|
|||
|
On Feb 7, 5:59*pm, stephen...@mpeforth.com (Stephen Pelc) wrote:
> On Tue, 7 Feb 2012 08:53:41 -0800 (PST), Brad <hwfw...@gmail.com> > wrote: > > >I want to copy existing words into a new wordlist. > > >My first thought was to use: > > >: & *( <w> -- ) *>IN @ ' SWAP >IN ! *CREATE , *DOES> @ EXECUTE ; > > ... > > >Is there a simpler (but portable) way? Does 200x propose ALIAS? > > SYNONYM <newname> <oldname> > > Stephen > > -- > Stephen Pelc, stephen...@mpeforth.com > MicroProcessor Engineering Ltd - More Real, Less Time > 133 Hill Lane, Southampton SO15 5AF, England > tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691 > web:http://www.mpeforth.com- free VFX Forth downloads I thought Synonym would only create a synonym. It doesn't copy the original code into a new word. The OP wants to duplicate a word from one wordlist into another. Not quite the same as SYNONYM. Nevertheless, that raises an interesting point in itself; One might consider, rather than just blindly copying the executable code into the new word, compiling a call to the original word instead. It saves space on constrained systems. |
|
|||
|
On Feb 8, 10:31*am, Mark Wills <markrobertwi...@yahoo.co.uk> wrote:
> On Feb 7, 5:59*pm, stephen...@mpeforth.com (Stephen Pelc) wrote: > > > > > > > > > > > On Tue, 7 Feb 2012 08:53:41 -0800 (PST), Brad <hwfw...@gmail.com> > > wrote: > > > >I want to copy existing words into a new wordlist. > > > >My first thought was to use: > > > >: & *( <w> -- ) *>IN @ ' SWAP >IN ! *CREATE , *DOES> @ EXECUTE; > > > ... > > > >Is there a simpler (but portable) way? Does 200x propose ALIAS? > > > SYNONYM <newname> <oldname> > > > Stephen > > > -- > > Stephen Pelc, stephen...@mpeforth.com > > MicroProcessor Engineering Ltd - More Real, Less Time > > 133 Hill Lane, Southampton SO15 5AF, England > > tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691 > > web:http://www.mpeforth.com-free VFX Forth downloads > > I thought Synonym would only create a synonym. It doesn't copy the > original code into a new word. > > The OP wants to duplicate a word from one wordlist into another. Not > quite the same as SYNONYM. > > Nevertheless, that raises an interesting point in itself; One might > consider, rather than just blindly copying the executable code into > the new word, compiling a call to the original word instead. It saves > space on constrained systems. Then (assuming you have VOCABULARY, and this can obviously be extended to wordlists); : OLDNAME .... ; VOCABULARY NEWVOC ALSO NEWVOC DEFINITIONS SYNONYM NEWNAME OLDNAME PREVIOUS DEFINITIONS |
|
|||
|
On 2/8/12 1:19 AM, Stephen Pelc wrote:
> On Wed, 8 Feb 2012 02:31:06 -0800 (PST), Mark Wills > <markrobertwills@yahoo.co.uk> wrote: > >>>> Is there a simpler (but portable) way? Does 200x propose ALIAS? >>> >>> SYNONYM<newname> <oldname> >> >> I thought Synonym would only create a synonym. It doesn't copy the >> original code into a new word. >> >> The OP wants to duplicate a word from one wordlist into another. Not >> quite the same as SYNONYM. > > What Brad's code does is to generate a new word of the form > : foo foo ; > which is not the same as copying the binary. Copying the binary is > actually quite hard to do on some implementations and CPUs. And why would one actually want to do that? Cheers, Elizabeth -- ================================================== Elizabeth D. Rather (US & Canada) 800-55-FORTH FORTH Inc. +1 310.999.6784 5959 West Century Blvd. Suite 700 Los Angeles, CA 90045 http://www.forth.com "Forth-based products and Services for real-time applications since 1973." ================================================== |
|
|||
|
On Feb 8, 5:11*pm, "Elizabeth D. Rather" <erat...@forth.com> wrote:
> On 2/8/12 1:19 AM, Stephen Pelc wrote: > > > > > > > > > > > On Wed, 8 Feb 2012 02:31:06 -0800 (PST), Mark Wills > > <markrobertwi...@yahoo.co.uk> *wrote: > > >>>> Is there a simpler (but portable) way? Does 200x propose ALIAS? > > >>> SYNONYM<newname> *<oldname> > > >> I thought Synonym would only create a synonym. It doesn't copy the > >> original code into a new word. > > >> The OP wants to duplicate a word from one wordlist into another. Not > >> quite the same as SYNONYM. > > > What Brad's code does is to generate a new word of the form > > * *: foo *foo *; > > which is not the same as copying the binary. Copying the binary is > > actually quite hard to do on some implementations and CPUs. > > And why would one actually want to do that? Inlining, dynamic loading (particularly of libraries), "sandpit" debugging, virtualisation, compilation out of line or off-processor, and so on. The usual technique is to either keep a static set of relocations that are applied when the code is loaded or moved; or dynamically generate them by disassembling the code. It's usually required for processors that utilise position dependent code. Many of these may not apply to Forth, although inlining is an exception. > > Cheers, > Elizabeth > > -- > ================================================== > Elizabeth D. Rather * (US & Canada) * 800-55-FORTH > FORTH Inc. * * * * * * * * * * * * +1 310.999.6784 > 5959 West Century Blvd. Suite 700 > Los Angeles, CA 90045http://www.forth.com > > "Forth-based products and Services for real-time > applications since 1973." > ================================================== |
|
|||
|
On Feb 8, 6:13*am, Alex McDonald <b...@rivadpm.com> wrote:
> On Feb 8, 10:31*am, Mark Wills <markrobertwi...@yahoo.co.uk> wrote: > > > > > > > > > > > On Feb 7, 5:59*pm, stephen...@mpeforth.com (Stephen Pelc) wrote: > > > > On Tue, 7 Feb 2012 08:53:41 -0800 (PST), Brad <hwfw...@gmail.com> > > > wrote: > > > > >I want to copy existing words into a new wordlist. > > > > >My first thought was to use: > > > > >: & *( <w> -- ) *>IN @ ' SWAP >IN ! *CREATE , *DOES> @ EXECUTE ; > > > > ... > > > > >Is there a simpler (but portable) way? Does 200x propose ALIAS? > > > > SYNONYM <newname> <oldname> > > > > Stephen > > > > -- > > > Stephen Pelc, stephen...@mpeforth.com > > > MicroProcessor Engineering Ltd - More Real, Less Time > > > 133 Hill Lane, Southampton SO15 5AF, England > > > tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691 > > > web:http://www.mpeforth.com-freeVFX Forth downloads > > > I thought Synonym would only create a synonym. It doesn't copy the > > original code into a new word. > > > The OP wants to duplicate a word from one wordlist into another. Not > > quite the same as SYNONYM. > > > Nevertheless, that raises an interesting point in itself; One might > > consider, rather than just blindly copying the executable code into > > the new word, compiling a call to the original word instead. It saves > > space on constrained systems. > > Then (assuming you have VOCABULARY, and this can obviously be extended > to wordlists); > > : OLDNAME .... ; > > VOCABULARY NEWVOC > ALSO NEWVOC DEFINITIONS > > SYNONYM NEWNAME OLDNAME > > PREVIOUS DEFINITIONS That does not, however, import the word under the same name as "&" is trying to do. DEFER and IS would do so, I think, by reusing the word in the input buffer. But if the extra semantics of DEFER and IS are not required, the does-@EXECUTE approach would be about as compact: : does-@EXECUTE DOES> @ EXECUTE ; : & ( "name" -- ) >IN @ BL WORD FIND ?DUP IF ROT >IN ! SWAP CREATE , does-@EXECUTE 1 = IF IMMEDIATE THEN ELSE CR COUNT TYPE SPACE ." ???" THEN ; : & ( "name" -- ) >IN @ BL WORD FIND ?DUP IF ROT DUP >IN ! DEFER >IN ! SWAP ['] IS EXECUTE 1 = IF IMMEDIATE THEN ELSE CR COUNT TYPE SPACE ." ???" THEN ; |
|
|||
|
On 2/8/12 8:26 AM, Alex McDonald wrote:
> On Feb 8, 5:11 pm, "Elizabeth D. Rather"<erat...@forth.com> wrote: >> On 2/8/12 1:19 AM, Stephen Pelc wrote: .... >>> What Brad's code does is to generate a new word of the form >>> : foo foo ; >>> which is not the same as copying the binary. Copying the binary is >>> actually quite hard to do on some implementations and CPUs. >> >> And why would one actually want to do that? > > Inlining, dynamic loading (particularly of libraries), "sandpit" > debugging, virtualisation, compilation out of line or off-processor, > and so on. The usual technique is to either keep a static set of > relocations that are applied when the code is loaded or moved; or > dynamically generate them by disassembling the code. It's usually > required for processors that utilise position dependent code. > > Many of these may not apply to Forth, although inlining is an > exception. Ok, but my understanding of the OP was that he wanted to access the word from a different wordlist. Stephen's SYNONYM does that nicely. Inlining is a compiler strategy in itself, not particularly related to getting something visible in a different wordlist. If wordlist visibility is the issue, I don't see why copying the code itself is relevant. Cheers, Elizabeth -- ================================================== Elizabeth D. Rather (US & Canada) 800-55-FORTH FORTH Inc. +1 310.999.6784 5959 West Century Blvd. Suite 700 Los Angeles, CA 90045 http://www.forth.com "Forth-based products and Services for real-time applications since 1973." ================================================== |
|
|||
|
On Feb 8, 6:30*pm, BruceMcF <agil...@netscape.net> wrote:
> On Feb 8, 6:13*am, Alex McDonald <b...@rivadpm.com> wrote: > > > > > > > > > > > On Feb 8, 10:31*am, Mark Wills <markrobertwi...@yahoo.co.uk> wrote: > > > > On Feb 7, 5:59*pm, stephen...@mpeforth.com (Stephen Pelc) wrote: > > > > > On Tue, 7 Feb 2012 08:53:41 -0800 (PST), Brad <hwfw...@gmail.com> > > > > wrote: > > > > > >I want to copy existing words into a new wordlist. > > > > > >My first thought was to use: > > > > > >: & *( <w> -- ) *>IN @ ' SWAP >IN ! *CREATE , *DOES> @ EXECUTE ; > > > > > ... > > > > > >Is there a simpler (but portable) way? Does 200x propose ALIAS? > > > > > SYNONYM <newname> <oldname> > > > > > Stephen > > > > > -- > > > > Stephen Pelc, stephen...@mpeforth.com > > > > MicroProcessor Engineering Ltd - More Real, Less Time > > > > 133 Hill Lane, Southampton SO15 5AF, England > > > > tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691 > > > > web:http://www.mpeforth.com-freeVFXForth downloads > > > > I thought Synonym would only create a synonym. It doesn't copy the > > > original code into a new word. > > > > The OP wants to duplicate a word from one wordlist into another. Not > > > quite the same as SYNONYM. > > > > Nevertheless, that raises an interesting point in itself; One might > > > consider, rather than just blindly copying the executable code into > > > the new word, compiling a call to the original word instead. It saves > > > space on constrained systems. > > > Then (assuming you have VOCABULARY, and this can obviously be extended > > to wordlists); > > > : OLDNAME .... ; > > > VOCABULARY NEWVOC > > ALSO NEWVOC DEFINITIONS > > > SYNONYM NEWNAME OLDNAME > > > PREVIOUS DEFINITIONS > > That does not, however, import the word under the same name as "&" is > trying to do. DEFER and IS would do so, I think, by reusing the word > in the input buffer. But if the extra semantics of DEFER and IS are > not required, the does-@EXECUTE approach would be about as compact: > > : does-@EXECUTE DOES> @ EXECUTE ; > : & ( "name" -- ) > * *>IN @ BL WORD FIND ?DUP IF > * * * ROT >IN ! SWAP CREATE , does-@EXECUTE > * * * 1 = IF IMMEDIATE THEN > * *ELSE CR COUNT TYPE SPACE ." ???" THEN ; > > : & ( "name" -- ) > * *>IN @ BL WORD FIND ?DUP IF > * * * ROT DUP >IN ! DEFER > * * * >IN ! SWAP ['] IS EXECUTE > * * * 1 = IF IMMEDIATE THEN > * *ELSE CR COUNT TYPE SPACE ." ???" THEN ; : THISNAME .... ; VOCABULARY NEWVOC ALSO NEWVOC DEFINITIONS SYNONYM THISNAME THISNAME PREVIOUS DEFINITIONS SYNONYM allows both names to be the same. Any system that declares and finds the new THISNAME as its own alias is in error. 15.6.2. SYNONYM TOOLS EXT For both strings skip leading space delimiters. Parse newname and oldname delimited by a space. Create a definition for newname with the semantics defined below. Newname may be the same as oldname; when looking up oldname, newname shall not be found . |
|
|||
|
On Feb 8, 5:19*pm, Alex McDonald <b...@rivadpm.com> wrote:
> SYNONYM allows both names to be the same. Yes, but the specified behavior was for the name to appear once. > Any system that declares and > finds the new THISNAME as its own alias is in error. Yes, that's why the original name was searched for and its xt found first, before executing DEFER and the interpreter semantics of IS. |
|
|||
|
On Feb 8, 5:19*pm, Alex McDonald <b...@rivadpm.com> wrote:
> SYNONYM allows both names to be the same. Any system that declares and > finds the new THISNAME as its own alias is in error. Is the SYNONYM of an immediate word defined to be immediate? |
|
|||
|
On 2/8/12 1:05 PM, BruceMcF wrote:
> On Feb 8, 5:19 pm, Alex McDonald<b...@rivadpm.com> wrote: >> SYNONYM allows both names to be the same. Any system that declares and >> finds the new THISNAME as its own alias is in error. > > Is the SYNONYM of an immediate word defined to be immediate? > I think not automatically. You would have to mark your synonym as immediate. It can conceivably be useful to define a non-immediate synonym of an immediate word. Cheers, Elizabeth -- ================================================== Elizabeth D. Rather (US & Canada) 800-55-FORTH FORTH Inc. +1 310.999.6784 5959 West Century Blvd. Suite 700 Los Angeles, CA 90045 http://www.forth.com "Forth-based products and Services for real-time applications since 1973." ================================================== |
|
|||
|
On Feb 9, 6:55*pm, "Elizabeth D. Rather" <erat...@forth.com> wrote:
> On 2/8/12 1:05 PM, BruceMcF wrote: > > > On Feb 8, 5:19 pm, Alex McDonald<b...@rivadpm.com> *wrote: > >> SYNONYM allows both names to be the same. Any system that declares and > >> finds the new THISNAME as its own alias is in error. > > > Is the SYNONYM of an immediate word defined to be immediate? > > I think not automatically. *You would have to mark your synonym as > immediate. It can conceivably be useful to define a non-immediate > synonym of an immediate word. According to the spec it's not portable. In the case of my Forth, the word can be marked immediate because the old word's definition is copied to newname. I can envisage dictionaries where the implementation has names and pointers to header structures; in which case, a shared header structure would result in also marking oldname as immediate. 15.6.2. SYNONYM TOOLS EXT ( “<spaces>newname” “<spaces>oldname” -- ) X:synonym For both strings skip leading space delimiters. Parse newname and oldname delimited by a space. Create a definition for newname with the semantics defined below. Newname may be the same as oldname; when looking up oldname, newname shall not be found. An ambiguous conditions exists if oldname can not be found or IMMEDIATE is applied to newname. > > Cheers, > Elizabeth > > -- > ================================================== > Elizabeth D. Rather * (US & Canada) * 800-55-FORTH > FORTH Inc. * * * * * * * * * * * * +1 310.999.6784 > 5959 West Century Blvd. Suite 700 > Los Angeles, CA 90045http://www.forth.com > > "Forth-based products and Services for real-time > applications since 1973." > ================================================== |
|
|||
|
On Feb 9, 1:55*pm, "Elizabeth D. Rather" <erat...@forth.com> wrote:
> > Is the SYNONYM of an immediate word defined to be immediate? > I think not automatically. *You would have to mark your synonym as > immediate. It can conceivably be useful to define a non-immediate > synonym of an immediate word. Then for the target application, where the desire is for the immediacy or not to be inherited, it wouldn't seem like much less trouble than the BL WORD FIND approach. |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|