Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #10679 > unrolled thread
| Started by | "Rod Pemberton" <do_not_have@noavailemail.cmm> |
|---|---|
| First post | 2012-03-31 21:57 -0400 |
| Last post | 2012-04-03 03:00 -0700 |
| Articles | 20 on this page of 21 — 9 participants |
Back to article view | Back to comp.lang.forth
Is there a word to compile a sequence of words which follows into another word? "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2012-03-31 21:57 -0400
Re: Is there a word to compile a sequence of words which follows into another word? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-04-01 05:48 -0500
Re: Is there a word to compile a sequence of words which follows into another word? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-04-02 02:07 -0400
Re: Is there a word to compile a sequence of words which follows into another word? Mark Wills <markrobertwills@yahoo.co.uk> - 2012-04-02 09:29 -0700
Re: Is there a word to compile a sequence of words which follows into another word? Mark Wills <markrobertwills@yahoo.co.uk> - 2012-04-02 09:38 -0700
Re: Is there a word to compile a sequence of words which follows into another word? Mark Wills <markrobertwills@yahoo.co.uk> - 2012-04-02 09:40 -0700
Re: Is there a word to compile a sequence of words which follows into another word? "Elizabeth D. Rather" <erather@forth.com> - 2012-04-02 11:38 -1000
Re: Is there a word to compile a sequence of words which follows into another word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-04-03 10:31 +0000
Re: Is there a word to compile a sequence of words which follows into another word? Mark Wills <markrobertwills@yahoo.co.uk> - 2012-04-03 05:31 -0700
Re: Is there a word to compile a sequence of words which follows into another word? "Elizabeth D. Rather" <erather@forth.com> - 2012-04-03 08:31 -1000
Re: Is there a word to compile a sequence of words which follows into another word? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-04-03 06:36 -0400
Re: Is there a word to compile a sequence of words which follows into another word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-04-03 12:03 +0000
Re: Is there a word to compile a sequence of words which follows into another word? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-04-04 04:58 -0400
Re: Is there a word to compile a sequence of words which follows into another word? "A. K." <akk@nospam.org> - 2012-04-02 23:31 +0200
Re: Is there a word to compile a sequence of words which follows into another word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-04-02 11:04 +0000
Re: Is there a word to compile a sequence of words which follows into another word? BruceMcF <agila61@netscape.net> - 2012-03-31 19:30 -0700
Re: Is there a word to compile a sequence of words which follows into another word? Mark Wills <markrobertwills@yahoo.co.uk> - 2012-04-02 08:39 -0700
Re: Is there a word to compile a sequence of words which follows into another word? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-04-05 23:55 -0700
Re: Is there a word to compile a sequence of words which follows into another word? Mark Wills <markrobertwills@yahoo.co.uk> - 2012-04-03 01:02 -0700
Re: Is there a word to compile a sequence of words which follows into another word? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-04-03 12:58 +0000
Re: Is there a word to compile a sequence of words which follows into another word? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-04-03 03:00 -0700
Page 1 of 2 [1] 2 Next page →
| From | "Rod Pemberton" <do_not_have@noavailemail.cmm> |
|---|---|
| Date | 2012-03-31 21:57 -0400 |
| Subject | Is there a word to compile a sequence of words which follows into another word? |
| Message-ID | <jl8cma$gl6$1@speranza.aioe.org> |
What I'm seeing with some IMMEDIATE words is the following (or something similar): : zzz [COMPILE] aaaa COMPILE bbbb [COMPILE] cccc COMPILE dddd ... ; IMMEDIATE Or, for ANS: : zzz POSTPONE aaaa POSTPONE bbbb POSTPONE cccc POSTPONE dddd ... ; IMMEDIATE POSTPONE , or [COMPILE] and COMPILE , only compile one word at a time. I'd like a word to compile an entire sequence of words. DOES> allows you to execute an entire sequence of words which follows. So, I'd think something like DOES> could be done for compiling. Alternately, [ (lbrac) and ] (rbrac) switch the compiler's state. Is there a need for another compiler state? What'd I'd like to do is something like this: : zzz POST> aaaa bbbb cccc dddd ; That would compile "aaaa bbbb cccc dddd" without needing a POSTPONE for each, or either a [COMPILE] or COMPILE. Is there a word to compile a sequence of words which follows into another word? Rod Pemberton
[toc] | [next] | [standalone]
| From | Andrew Haley <andrew29@littlepinkcloud.invalid> |
|---|---|
| Date | 2012-04-01 05:48 -0500 |
| Message-ID | <Tpydndp60MQIr-XSnZ2dnUVZ_jKdnZ2d@supernews.com> |
| In reply to | #10679 |
Rod Pemberton <do_not_have@noavailemail.cmm> wrote: > > What I'm seeing with some IMMEDIATE words is the following (or something > similar): > > : zzz [COMPILE] aaaa COMPILE bbbb [COMPILE] cccc COMPILE dddd ... ; > IMMEDIATE > > Or, for ANS: > > : zzz POSTPONE aaaa POSTPONE bbbb POSTPONE cccc POSTPONE dddd ... ; > IMMEDIATE > > > POSTPONE , or [COMPILE] and COMPILE , only compile one word at a time. I'd > like a word to compile an entire sequence of words. > > DOES> allows you to execute an entire sequence of words which follows. So, > I'd think something like DOES> could be done for compiling. > > Alternately, [ (lbrac) and ] (rbrac) switch the compiler's state. Is there > a need for another compiler state? > > What'd I'd like to do is something like this: > > : zzz POST> aaaa bbbb cccc dddd ; > > That would compile "aaaa bbbb cccc dddd" without needing a POSTPONE for > each, or either a [COMPILE] or COMPILE. > > Is there a word to compile a sequence of words which follows into another > word? There's not a standard word to do it, but it's easy enough to write POST> with WORD and SAVE-INPUT. It's a good exercise. I think you'll eventually find you don't need it, though. Andrew.
[toc] | [prev] | [next] | [standalone]
| From | "Rod Pemberton" <do_not_have@notemailnot.cmm> |
|---|---|
| Date | 2012-04-02 02:07 -0400 |
| Message-ID | <jlbfnt$9su$1@speranza.aioe.org> |
| In reply to | #10687 |
"Andrew Haley" <andrew29@littlepinkcloud.invalid> wrote in message
news:Tpydndp60MQIr-XSnZ2dnUVZ_jKdnZ2d@supernews.com...
> Rod Pemberton <do_not_have@noavailemail.cmm> wrote:
> >
> > What I'm seeing with some IMMEDIATE words is the following (or something
> > similar):
> >
> > : zzz [COMPILE] aaaa COMPILE bbbb [COMPILE] cccc COMPILE dddd ... ;
> > IMMEDIATE
> >
> > Or, for ANS:
> >
> > : zzz POSTPONE aaaa POSTPONE bbbb POSTPONE cccc POSTPONE dddd ... ;
> > IMMEDIATE
> >
> >
> > POSTPONE , or [COMPILE] and COMPILE , only compile one word at a time.
> > I'd like a word to compile an entire sequence of words.
> >
> > DOES> allows you to execute an entire sequence of words which follows.
> > So, I'd think something like DOES> could be done for compiling.
> >
> > Alternately, [ (lbrac) and ] (rbrac) switch the compiler's state. Is
> > there a need for another compiler state?
> >
> > What'd I'd like to do is something like this:
> >
> > : zzz POST> aaaa bbbb cccc dddd ;
> >
> > That would compile "aaaa bbbb cccc dddd" without needing a
> > POSTPONE for each, or either a [COMPILE] or COMPILE.
> >
> > Is there a word to compile a sequence of words which follows into
> > another word?
>
> There's not a standard word to do it, but it's easy enough to write
> POST> with WORD and SAVE-INPUT. It's a good exercise. I think
> you'll eventually find you don't need it, though.
>
Perhaps not, but that seems to imply that Forth actually has three states,
not two: interactive, compile at compile-time, compile at run-time ...
Although, POST> probably isn't the best syntax for that. POST> would be
terminated by ; (semicol). It's probably better to use brackets to switch
states, like [ (lbrac) and ] (rbrac) . ( and ) are in use. Are { and } in
use? IIRC, those aren't.
If SAVE-INPUT does what it's name says, that wouldn't be what one would
want. You'd want the compiler to compile the words but not execute them,
and compile them at runtime.
The first word you'd want would be a non-immediate word which does
nothing during compilation at compile-time and switches the interpreter
from execute/interpret to compilation at run-time. That sounds alot like
] (rbrac), perhaps as:
COMPILE ]
[COMPILE] does for one word what [ (lbrac) and ] (rbrac) do for multiple
words, yes? POSTPONE does [COMPILE] or COMPILE appropriately.
So, maybe [ and ] could be extended to do the equivalent of POSTPONE,
i.e., both [COMPILE] and COMPILE instead of just [COMPILE] .
Now, I'm wondering if I can rewrite the compiler portion of the interpreter
in terms of [COMPILE] ... It compiles on a per word basis. I'll need to
review my definitions for restructuring.
Rod Pemberton
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <markrobertwills@yahoo.co.uk> |
|---|---|
| Date | 2012-04-02 09:29 -0700 |
| Message-ID | <3ce0d696-6c2c-4d17-ba6b-f76d66b02260@fw28g2000vbb.googlegroups.com> |
| In reply to | #10699 |
> [COMPILE] does for one word what [ (lbrac) and ] (rbrac) do for multiple > words, yes? POSTPONE does [COMPILE] or COMPILE appropriately. > So, maybe [ and ] could be extended to do the equivalent of POSTPONE, > i.e., both [COMPILE] and COMPILE instead of just [COMPILE] . > No, [ is kind of like an in-line escape. It suspends *compilation* (sets state to 0) such that anything following [ is executed immediately. ] resumes compilation. Example: : test 1 2 3 [ 4 5 6 ] ; .s 4 5 6 ok Test Ok .s 1 2 3
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <markrobertwills@yahoo.co.uk> |
|---|---|
| Date | 2012-04-02 09:38 -0700 |
| Message-ID | <4ea41be7-f0bf-4674-ab89-17b34979f646@db5g2000vbb.googlegroups.com> |
| In reply to | #10773 |
On Apr 2, 5:29 pm, Mark Wills <markrobertwi...@yahoo.co.uk> wrote: > > [COMPILE] does for one word what [ (lbrac) and ] (rbrac) do for multiple > > words, yes? POSTPONE does [COMPILE] or COMPILE appropriately. > > So, maybe [ and ] could be extended to do the equivalent of POSTPONE, > > i.e., both [COMPILE] and COMPILE instead of just [COMPILE] . > > No, [ is kind of like an in-line escape. It suspends *compilation* > (sets state to 0) such that anything following [ is executed > immediately. ] resumes compilation. > > Example: > > : test 1 2 3 [ 4 5 6 ] ; > .s > 4 5 6 ok > Test > Ok > .s > 1 2 3
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <markrobertwills@yahoo.co.uk> |
|---|---|
| Date | 2012-04-02 09:40 -0700 |
| Message-ID | <4548a85f-6c8d-45c0-aff6-2ecdbd3cdd23@l7g2000vbw.googlegroups.com> |
| In reply to | #10773 |
IOn Apr 2, 5:29 pm, Mark Wills <markrobertwi...@yahoo.co.uk> wrote: > > [COMPILE] does for one word what [ (lbrac) and ] (rbrac) do for multiple > > words, yes? POSTPONE does [COMPILE] or COMPILE appropriately. > > So, maybe [ and ] could be extended to do the equivalent of POSTPONE, > > i.e., both [COMPILE] and COMPILE instead of just [COMPILE] . > > No, [ is kind of like an in-line escape. It suspends *compilation* > (sets state to 0) such that anything following [ is executed > immediately. ] resumes compilation. > > Example: > > : test 1 2 3 [ 4 5 6 ] ; > .s > 4 5 6 ok > Test > Ok > .s > 1 2 3 I think my definitions for [ and ] are simply: : [ 0 state ! ; immediate : ] 1 state ! ; immediate
[toc] | [prev] | [next] | [standalone]
| From | "Elizabeth D. Rather" <erather@forth.com> |
|---|---|
| Date | 2012-04-02 11:38 -1000 |
| Message-ID | <Zc6dnc_BgLvegefSnZ2dnUVZ_sWdnZ2d@supernews.com> |
| In reply to | #10775 |
On 4/2/12 6:40 AM, Mark Wills wrote: > IOn Apr 2, 5:29 pm, Mark Wills<markrobertwi...@yahoo.co.uk> wrote: >>> [COMPILE] does for one word what [ (lbrac) and ] (rbrac) do for multiple >>> words, yes? POSTPONE does [COMPILE] or COMPILE appropriately. >>> So, maybe [ and ] could be extended to do the equivalent of POSTPONE, >>> i.e., both [COMPILE] and COMPILE instead of just [COMPILE] . >> >> No, [ is kind of like an in-line escape. It suspends *compilation* >> (sets state to 0) such that anything following [ is executed >> immediately. ] resumes compilation. >> >> Example: >> >> : test 1 2 3 [ 4 5 6 ] ; >> .s >> 4 5 6 ok >> Test >> Ok >> .s >> 1 2 3 > I think my definitions for [ and ] are simply: > > : [ 0 state ! ; immediate > : ] 1 state ! ; immediate It is not harmful for ] to be IMMEDIATE, but it's not necessary, either. It's a no-op in compilation state. 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." ==================================================
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2012-04-03 10:31 +0000 |
| Message-ID | <2012Apr3.123121@mips.complang.tuwien.ac.at> |
| In reply to | #10778 |
"Elizabeth D. Rather" <erather@forth.com> writes:
>> : ] 1 state ! ; immediate
>
>It is not harmful for ] to be IMMEDIATE
It's not standard-compliant, though.
E.g., consider:
: ]L ] postpone literal ;
: foo [ 5 ]L . ;
foo
FOO prints 5 on a standard system, but this does not work if ] is
immediate.
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2011: http://www.euroforth.org/ef11/
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <markrobertwills@yahoo.co.uk> |
|---|---|
| Date | 2012-04-03 05:31 -0700 |
| Message-ID | <f3e5ed4a-3679-4938-a0df-e7f02fd3ecf0@w5g2000vbv.googlegroups.com> |
| In reply to | #10810 |
On Apr 3, 11:31 am, an...@mips.complang.tuwien.ac.at (Anton Ertl) wrote: > "Elizabeth D. Rather" <erat...@forth.com> writes: > > >> : ] 1 state ! ; immediate > > >It is not harmful for ] to be IMMEDIATE > > It's not standard-compliant, though. > > E.g., consider: > > : ]L ] postpone literal ; > : foo [ 5 ]L . ; > foo > > FOO prints 5 on a standard system, but this does not work if ] is > immediate. > > - anton > -- > M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html > comp.lang.forth FAQs:http://www.complang.tuwien.ac.at/forth/faq/toc.html > New standard:http://www.forth200x.org/forth200x.html > EuroForth 2011:http://www.euroforth.org/ef11/ Indeed, you're right. I just checked my source. [ is immediate (obviously) but ] isn't. This agrees with the Forth 83 standard. THanks Mark
[toc] | [prev] | [next] | [standalone]
| From | "Elizabeth D. Rather" <erather@forth.com> |
|---|---|
| Date | 2012-04-03 08:31 -1000 |
| Message-ID | <Me6dnRJkGPti3ObSnZ2dnUVZ_gOdnZ2d@supernews.com> |
| In reply to | #10810 |
On 4/3/12 12:31 AM, Anton Ertl wrote: > "Elizabeth D. Rather"<erather@forth.com> writes: >>> : ] 1 state ! ; immediate >> >> It is not harmful for ] to be IMMEDIATE > > It's not standard-compliant, though. Yes. I was pointing out the illogic of it, and should have also mentioned the non-standardness. 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." ==================================================
[toc] | [prev] | [next] | [standalone]
| From | "Rod Pemberton" <do_not_have@notemailnot.cmm> |
|---|---|
| Date | 2012-04-03 06:36 -0400 |
| Message-ID | <jlejrd$4q0$1@speranza.aioe.org> |
| In reply to | #10775 |
"Mark Wills" <markrobertwills@yahoo.co.uk> wrote in message
news:4548a85f-6c8d-45c0-aff6-2ecdbd3cdd23@l7g2000vbw.googlegroups.com...
IOn Apr 2, 5:29 pm, Mark Wills <markrobertwi...@yahoo.co.uk> wrote:
> > [COMPILE] does for one word what [ (lbrac) and ] (rbrac) do for multiple
> > words, yes? POSTPONE does [COMPILE] or COMPILE appropriately.
> > So, maybe [ and ] could be extended to do the equivalent of POSTPONE,
> > i.e., both [COMPILE] and COMPILE instead of just [COMPILE] .
>
> No, [ is kind of like an in-line escape. It suspends *compilation*
> (sets state to 0) such that anything following [ is executed
> immediately. ] resumes compilation.
>
Ok. That's the exact opposite of the way I view it. I.e., state 0 is
interpret mode, and the interpreter switches state to compile mode for a
colon definition. However, as your example showed, we can switch the
intepreter back to interpret mode.
First, let's define OK :
: OK ." OK" ;
In interpret or interactive mode, this:
] OK [
Seems to work identically to this:
' OK ,
Both compile OK into the next dictionary space, after whatever is there, of
course. Effectively, ' <word> , is the same as COMPILE , so ] <word> [
works like COMPILE too.
However, this compiles one OK and executes two of them:
' OK OK OK ,
But, this compiles three OKs:
] OK OK OK [
Is that normal or standard operation? It works for my interpreter ...
However, if we make OK immediate:
: OKI OK ; IMMEDIATE
Then, ] [ won't compile them:
] OKI OKI OKI [ ( 3 OKs executed immediately )
So, what I was saying about extending ] and [ would be to allow
immediate words to be compiled also:
] OKI OKI OKI [ ( 3 OKs POSTPONED or [COMPILED] )
Does that make more sense?
Of course, ] and [ are used by : (colon) and ; (semicol) for compiling
definitions. Extending them to do that would block all use of IMMEDIATE
words. So, we wouldn't want to actually use ] and [ for this, which was why
I suggested { and } in my 2nd post. An alternate idea would be to extend ]
and [ to compile IMMEDIATEs but then and additional word would be needed to
allow IMMEDIATEs to execute immediately. In which case, you could eliminate
flagging of words as IMMEDIATE since the word to allow immediacy would
work for any word. You could think of it like a reverse POSTPONE ...
Anton Ertl posted a link to code with ]] and [[ to compat.zip with the
definitions in macros.fs.
There is also this older post which uses { and } to do it:
http://groups.google.com/group/comp.lang.forth/msg/220256b8becb3629
> I think my definitions for [ and ] are simply:
>
> : [ 0 state ! ; immediate
> : ] 1 state ! ; immediate
Mine are:
: [ 0 STATE ! ; IMMEDIATE
: ] 192 STATE ! ;
192 is C0h which is used in fig-Forth. You shouldn't need the immediate on
one of them. They're not state aware and so should work for both interpret
and compile modes. Well, I'm not sure what happens if I switch to compile
mode while in interpret mode ... Probably, it's nothing good.
Rod Pemberton
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2012-04-03 12:03 +0000 |
| Message-ID | <2012Apr3.140318@mips.complang.tuwien.ac.at> |
| In reply to | #10811 |
"Rod Pemberton" <do_not_have@notemailnot.cmm> writes:
>But, this compiles three OKs:
>
> ] OK OK OK [
>
>Is that normal or standard operation? It works for my interpreter ...
It's standard if there is a colon definition that has been started and
not yet ended, i.e., if you have
: foo
somewhere earlier (possibly with a "[").
>So, what I was saying about extending ] and [ would be to allow
>immediate words to be compiled also:
>
> ] OKI OKI OKI [ ( 3 OKs POSTPONED or [COMPILED] )
>
>Does that make more sense?
Somewhat. You were asking for a shorthands for the POSTPONEs, so you
would also want that to be equivalent to
postpone OKI postpone OKI postpone OKI
if OKI is not immediate. And that's the idea behind ]] ... [[.
]] ... [[ is not called ] ... [ because the standard ] has the
compilation semantics of compiling ], so it must not do what ]]
does.
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2011: http://www.euroforth.org/ef11/
[toc] | [prev] | [next] | [standalone]
| From | "Rod Pemberton" <do_not_have@notemailnot.cmm> |
|---|---|
| Date | 2012-04-04 04:58 -0400 |
| Message-ID | <jlh2f1$c2c$1@speranza.aioe.org> |
| In reply to | #10811 |
"Rod Pemberton" <do_not_have@notemailnot.cmm> wrote in message news:jlejrd$4q0$1@speranza.aioe.org... > "Mark Wills" <markrobertwills@yahoo.co.uk> wrote in message > news:4548a85f-6c8d-45c0-aff6-2ecdbd3cdd23@l7g2000vbw.googlegroups.com... ... > > I think my definitions for [ and ] are simply: > > > > : [ 0 state ! ; immediate > > : ] 1 state ! ; immediate > > Mine are: > > : [ 0 STATE ! ; IMMEDIATE > : ] 192 STATE ! ; > > 192 is C0h which is used in fig-Forth. You shouldn't need the immediate > on one of them. They're not state aware and so should work for both > interpret and compile modes. ... > Well, I'm not sure what happens if I switch to compile > mode while in interpret mode ... Probably, it's nothing good. Ooops... I forgot to cut that from the draft. They do work as demonstrated earlier in the post: compiling, in interactive or interpret mode, not part of a definition, and that is now snipped. Rod Pemberton
[toc] | [prev] | [next] | [standalone]
| From | "A. K." <akk@nospam.org> |
|---|---|
| Date | 2012-04-02 23:31 +0200 |
| Message-ID | <4f7a1a8c$0$6638$9b4e6d93@newsspool2.arcor-online.net> |
| In reply to | #10773 |
On 02.04.2012 18:29, Mark Wills wrote: > >> [COMPILE] does for one word what [ (lbrac) and ] (rbrac) do for multiple >> words, yes? POSTPONE does [COMPILE] or COMPILE appropriately. >> So, maybe [ and ] could be extended to do the equivalent of POSTPONE, >> i.e., both [COMPILE] and COMPILE instead of just [COMPILE] . >> > No, [ is kind of like an in-line escape. It suspends *compilation* > (sets state to 0) such that anything following [ is executed > immediately. ] resumes compilation. > > > Example: > > : test 1 2 3 [ 4 5 6 ] ; > .s > 4 5 6 ok > Test > Ok > .s > 1 2 3 This might not work in a standard system because : puts a colon-sys on the stack to be consumed by ;
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2012-04-02 11:04 +0000 |
| Message-ID | <2012Apr2.130446@mips.complang.tuwien.ac.at> |
| In reply to | #10679 |
"Rod Pemberton" <do_not_have@noavailemail.cmm> writes:
>
>What I'm seeing with some IMMEDIATE words is the following (or something
>similar):
>
> : zzz [COMPILE] aaaa COMPILE bbbb [COMPILE] cccc COMPILE dddd ... ;
>IMMEDIATE
>
>Or, for ANS:
>
> : zzz POSTPONE aaaa POSTPONE bbbb POSTPONE cccc POSTPONE dddd ... ;
>IMMEDIATE
>
>
>POSTPONE , or [COMPILE] and COMPILE , only compile one word at a time. I'd
>like a word to compile an entire sequence of words.
Gforth and some others have
: zzz ]] aaaa bbbb cccc dddd [[ ... ;
You can find a implementation of ]] ... [[ (and some more convenience
words) in Forth-94 in macros.fs in
http://www.complang.tuwien.ac.at/forth/compat.zip
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2011: http://www.euroforth.org/ef11/
[toc] | [prev] | [next] | [standalone]
| From | BruceMcF <agila61@netscape.net> |
|---|---|
| Date | 2012-03-31 19:30 -0700 |
| Message-ID | <7b9dd14f-7da2-4c1c-aeec-10c3f5f3b284@s27g2000yqd.googlegroups.com> |
| In reply to | #10679 |
On Mar 31, 9:57 pm, "Rod Pemberton" <do_not_h...@noavailemail.cmm> wrote: > What'd I'd like to do is something like this: > : zzz POST> aaaa bbbb cccc dddd ; > That would compile "aaaa bbbb cccc dddd" without needing a POSTPONE for > each, or either a [COMPILE] or COMPILE. > Is there a word to compile a sequence of words which > follows into another word? I've seen ` used as a shorthand for POSTPONE ... in your above, : zzz ` aaaa ` bbbb ` cccc ` dddd ; IMMEDIATE
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <markrobertwills@yahoo.co.uk> |
|---|---|
| Date | 2012-04-02 08:39 -0700 |
| Message-ID | <efddf7f9-71a9-4dec-baaf-a4b143937d51@l14g2000vbe.googlegroups.com> |
| In reply to | #10679 |
On Apr 1, 2:57 am, "Rod Pemberton" <do_not_h...@noavailemail.cmm>
wrote:
> What I'm seeing with some IMMEDIATE words is the following (or something
> similar):
>
> : zzz [COMPILE] aaaa COMPILE bbbb [COMPILE] cccc COMPILE dddd ... ;
> IMMEDIATE
>
> Or, for ANS:
>
> : zzz POSTPONE aaaa POSTPONE bbbb POSTPONE cccc POSTPONE dddd ... ;
> IMMEDIATE
>
> POSTPONE , or [COMPILE] and COMPILE , only compile one word at a time. I'd
> like a word to compile an entire sequence of words.
>
> DOES> allows you to execute an entire sequence of words which follows. So,
> I'd think something like DOES> could be done for compiling.
>
> Alternately, [ (lbrac) and ] (rbrac) switch the compiler's state. Is there
> a need for another compiler state?
>
> What'd I'd like to do is something like this:
>
> : zzz POST> aaaa bbbb cccc dddd ;
>
> That would compile "aaaa bbbb cccc dddd" without needing a POSTPONE for
> each, or either a [COMPILE] or COMPILE.
>
> Is there a word to compile a sequence of words which follows into another
> word?
>
> Rod Pemberton
To test:
: 0to99 COMPILE[ 100 0 DO I . LOOP ]COMPILE ;
: TEST 1to10 ;
TEST
Well, I decided to take a run at this.
I think my solution probably goes against the grain, however it works
and I think it's portable across ITC systems. It won't work on other
systems.
It works by writing code before the code-sequence that you want to
compile. The code that it writes actually does the compiling at run
time. It simply compiles a CMOVE to copy the desired code sequence
into the target definition, an ALLOT to allot the appropriate amount
of space in the target definition, and finally a BRANCH, to jump over
the code-sequence.
Use it like this:
: 0to99 COMPILE[ 100 0 DO I . LOOP ]COMPILE ;
: FRED 0to99 ;
FRED
0 1 2 3 4 5 6 7 8 ... ...
SEE FRED
: FRED LIT 100 LIT 0 (DO) I . (LOOP) ;
The magic happens in 0to99. I'll try and illustrate graphically:
SEE 0to99
: 0to99
+---- xxx HERE yyy CMOVE
| yyy ALLOT yyy
| BRANCH yyy -------------------+
+---> LIT 100 LIT 0 (DO) I . (LOOP) |
; <---------------------------------+
IMMEDIATE
Where xxx is the address of the start of the code-sequence that is to
be compiled into the target word, and yyy is the length of that code.
Note that 0to99 is made immediate, so that it has a chance to execute
and physically compile the code into the target definition.
As you can see, the BRANCH jumps over the target code that is to be
compiled when 0to99 executes. This allows further code to be placed
after ]COMPILE which will just execute normally, as in:
: 0to99 COMPILE[ 100 0 DO I . LOOP ]COMPILE ." Compiled code
sequence" ;
: TEST 0to99 ;
Compiled code sequence
OK
TEST
0 1 2 3 4 5 6 7 8 ... ...
Here's the code, which works on my system. Note that it does not have
to use WORD, FIND, etc etc, nor does it have to look at or manipulate
the terminal input buffer in any way. It simply inserts code before
the code-sequence to be compiled, with ]COMPILE back filling the
parameters for CMOVE ALLOT and BRANCH. The *compiler* does the
compiling, as it should do!
: COMPILE[
HERE
COMPILE LIT 0 , COMPILE HERE
COMPILE LIT 0 , COMPILE CMOVE
COMPILE LIT 0 , COMPILE ALLOT
COMPILE BRANCH 0 ,
\ the zero's will be back-filled by ]COMPILE
; IMMEDIATE
: ]COMPILE
HERE >R \ save end of compiled code address
\ back fill source field in CMOVE...
DUP 1 CELLS + \ point to source field
OVER 11 CELLS + SWAP ! \ fill source field
\ back fill count field in CMOVE...
DUP 4 CELLS + \ point to count field
OVER 11 CELLS + \ address of compiled code
R@ SWAP - DUP >R \ length of compiled code
SWAP ! \ write it to count field
\ and to ALLOT field...
DUP 7 CELLS + R@ SWAP !
\ and to BRANCH field...
10 CELLS + R> 1 CELLS + SWAP !
R> DROP
\ make the word under construction an IMMEDIATE word...
IMMEDIATE
; IMMEDIATE
Hey Hugh, do I get my "I posted code on CLF" T-shirt now? ;-)
Mark
[toc] | [prev] | [next] | [standalone]
| From | Hugh Aguilar <hughaguilar96@yahoo.com> |
|---|---|
| Date | 2012-04-05 23:55 -0700 |
| Message-ID | <6eb6aaad-a3ff-4ed4-b51d-dea271167cd2@2g2000yqk.googlegroups.com> |
| In reply to | #10772 |
On Apr 2, 9:39 am, Mark Wills <markrobertwi...@yahoo.co.uk> wrote: > Hey Hugh, do I get my "I posted code on CLF" T-shirt now? ;-) Not until you post ANS-Forth standard code! :-) The problem with using EVALUATE as I described earlier, is late- binding --- the definition might have changed since the time that the macro was written. For the most part, this isn't a problem for me as I don't redefine words very much --- that is confusing for a lot of reasons. When I originally wrote MACRO: I did not use EVALUATE, but rather I saved the xt values and gave them to COMPILE, (if they were non- immediate) or executed them (if they were immediate). This didn't work because in ANS-Forth some words don't have an xt value at all (!). Anton Ertl criticized me for not knowing this, although I found this fact to be quite surprising --- it didn't seem like something that a reasonable person would predict. Anyway, I switched over to saving the source-code and giving it to EVALUATE, and accepting the late-binding problem --- this was one of the many compromises I had to make in the novice package to get it to be ANS-Forth compliant. In Straight Forth I will have something similar to what you have. Compiled code will be guaranteed to be relocatable. Words smaller than a certain size will automatically be inlined. Also, it will be possible to inline words explicitly. Be aware that recursive words can't be inlined. Also, be aware that words that use jump-termination can't be inlined.
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <markrobertwills@yahoo.co.uk> |
|---|---|
| Date | 2012-04-03 01:02 -0700 |
| Message-ID | <3e008a24-1ed9-42fe-bbe0-1197d2f9a0ac@r9g2000yqd.googlegroups.com> |
| In reply to | #10679 |
On Apr 1, 2:57 am, "Rod Pemberton" <do_not_h...@noavailemail.cmm> wrote: > What I'm seeing with some IMMEDIATE words is the following (or something > similar): > > : zzz [COMPILE] aaaa COMPILE bbbb [COMPILE] cccc COMPILE dddd ... ; > IMMEDIATE > > Or, for ANS: > > : zzz POSTPONE aaaa POSTPONE bbbb POSTPONE cccc POSTPONE dddd ... ; > IMMEDIATE > > POSTPONE , or [COMPILE] and COMPILE , only compile one word at a time. I'd > like a word to compile an entire sequence of words. > > DOES> allows you to execute an entire sequence of words which follows. So, > I'd think something like DOES> could be done for compiling. > > Alternately, [ (lbrac) and ] (rbrac) switch the compiler's state. Is there > a need for another compiler state? > > What'd I'd like to do is something like this: > > : zzz POST> aaaa bbbb cccc dddd ; > > That would compile "aaaa bbbb cccc dddd" without needing a POSTPONE for > each, or either a [COMPILE] or COMPILE. > > Is there a word to compile a sequence of words which follows into another > word? > > Rod Pemberton Folks, I know I posted some code yesterday to address what Rod was asking, but it strikes me that one could achieve *effectively* the same result by simply using DOES>. To whit: If one wants the following code to be executed: 100 0 DO I . LOOP Then why not: : InheritsLoop CREATE DOES> DROP 100 0 DO I . LOOP ; FRED InheritsLoop Okay, the loop code hasn't been *injected* into FRED, it's a call (with a parameter, which is simply dropped) - but why would you want to inject the exact same code into multiple definitions anyway? Factor factor factor! Mark
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2012-04-03 12:58 +0000 |
| Subject | Re: Is there a word to compile a sequence of words which follows into another word? |
| Message-ID | <2012Apr3.145851@mips.complang.tuwien.ac.at> |
| In reply to | #10797 |
Mark Wills <markrobertwills@yahoo.co.uk> writes:
>Then why not:
>
>: InheritsLoop CREATE DOES> DROP 100 0 DO I . LOOP ;
>
>FRED InheritsLoop
Even simpler:
: InheritsLoop 100 0 DO I . LOOP ;
: FRED InheritsLoop ;
Yes, if an ordinary definition works, use an ordinary definition. It
has fewer restrictions than a macro. But there are cases where an
ordinary colon definition does not work, e.g.:
: repeat postpone again postpone then ; immediate
and there it gets a little more readable if you write
: repeat ]] again then [[ ; immediate
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2011: http://www.euroforth.org/ef11/
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.forth
csiph-web