Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #13407 > unrolled thread
| Started by | teammember0x01@gmail.com |
|---|---|
| First post | 2012-06-30 16:21 -0700 |
| Last post | 2012-07-02 20:46 -0700 |
| Articles | 20 on this page of 28 — 11 participants |
Back to article view | Back to comp.lang.forth
How to use the "compile," word teammember0x01@gmail.com - 2012-06-30 16:21 -0700
Re: How to use the "compile," word BruceMcF <agila61@netscape.net> - 2012-06-30 16:53 -0700
Re: How to use the "compile," word Coos Haak <chforth@hccnet.nl> - 2012-07-01 02:06 +0200
Re: How to use the "compile," word BruceMcF <agila61@netscape.net> - 2012-06-30 19:11 -0700
Re: How to use the "compile," word Bernd Paysan <bernd.paysan@gmx.de> - 2012-07-01 19:50 +0200
Re: How to use the "compile," word "Elizabeth D. Rather" <erather@forth.com> - 2012-07-01 08:40 -1000
Re: How to use the "compile," word Bernd Paysan <bernd.paysan@gmx.de> - 2012-07-01 23:14 +0200
Re: How to use the "compile," word BruceMcF <agila61@netscape.net> - 2012-07-01 15:38 -0700
Re: How to use the "compile," word Bernd Paysan <bernd.paysan@gmx.de> - 2012-07-02 01:18 +0200
Re: How to use the "compile," word anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-07-02 17:03 +0000
Re: How to use the "compile," word Bernd Paysan <bernd.paysan@gmx.de> - 2012-07-02 21:39 +0200
Re: How to use the "compile," word anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-07-03 16:55 +0000
Re: How to use the "compile," word Bernd Paysan <bernd.paysan@gmx.de> - 2012-07-03 23:09 +0200
Re: How to use the "compile," word BruceMcF <agila61@netscape.net> - 2012-07-02 12:00 -0700
Re: How to use the "compile," word Bernd Paysan <bernd.paysan@gmx.de> - 2012-07-02 22:44 +0200
Re: How to use the "compile," word Josh Grams <josh@qualdan.com> - 2012-07-02 20:18 +0000
Re: How to use the "compile," word Bernd Paysan <bernd.paysan@gmx.de> - 2012-07-02 22:53 +0200
Re: How to use the "compile," word anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-07-02 16:54 +0000
Re: How to use the "compile," word Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-07-02 13:05 -0500
Re: How to use the "compile," word anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-07-03 16:08 +0000
Re: How to use the "compile," word Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-07-03 14:35 -0500
Re: How to use the "compile," word Bernd Paysan <bernd.paysan@gmx.de> - 2012-07-02 21:03 +0200
Re: How to use the "compile," word anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-07-03 16:09 +0000
Re: How to use the "compile," word Bernd Paysan <bernd.paysan@gmx.de> - 2012-07-03 22:42 +0200
Re: How to use the "compile," word "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-07-01 04:39 -0400
Re: How to use the "compile," word Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-07-01 04:03 -0500
Re: How to use the "compile," word Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-07-01 11:48 +0000
Re: How to use the "compile," word Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-07-02 20:46 -0700
Page 1 of 2 [1] 2 Next page →
| From | teammember0x01@gmail.com |
|---|---|
| Date | 2012-06-30 16:21 -0700 |
| Subject | How to use the "compile," word |
| Message-ID | <fb4d99b3-a0ad-4417-b703-d9809a662b1e@googlegroups.com> |
I'm trying to learn how to use the "compile," word. Would anybody know how to use it? I am interested in example source code. Thanks.
[toc] | [next] | [standalone]
| From | BruceMcF <agila61@netscape.net> |
|---|---|
| Date | 2012-06-30 16:53 -0700 |
| Message-ID | <7f1f48a4-8c78-43e1-8c5f-92b185382564@f16g2000yqg.googlegroups.com> |
| In reply to | #13407 |
On Jun 30, 7:21 pm, teammember0...@gmail.com wrote: > I'm trying to learn how to use the "compile," word. Would anybody know how to use it? I am interested in example source code. Thanks. Suppose you want to use the file version of S" in a word ~ that is, compile from the input into a buffer, terminated by 0. S" while compiling embeds the string at compile time, but ['] S" should get the file-S" xt, and compiling it with compile, should give the file-S" behavior at runtime: : file-S" ( cccc" -- ca u ) ['] S" COMPILE, ; IMMEDIATE 2VARIABLE tbuff : test" ( cccc" -- ) file-S" tbuff 2! ; test" this is a test" sbuff 2@ TYPE ... should give: this is a test OK
[toc] | [prev] | [next] | [standalone]
| From | Coos Haak <chforth@hccnet.nl> |
|---|---|
| Date | 2012-07-01 02:06 +0200 |
| Message-ID | <jcw6h2o37xna.961xxfmtr041$.dlg@40tude.net> |
| In reply to | #13408 |
Op Sat, 30 Jun 2012 16:53:55 -0700 (PDT) schreef BruceMcF: > On Jun 30, 7:21 pm, teammember0...@gmail.com wrote: >> I'm trying to learn how to use the "compile," word. Would anybody know how to use it? I am interested in example source code. Thanks. > > Suppose you want to use the file version of S" in a word ~ that is, > compile from the input into a buffer, terminated by 0. S" while > compiling embeds the string at compile time, but ['] S" should get the > file-S" xt, and compiling it with compile, should give the file-S" > behavior at runtime: > >: file-S" ( cccc" -- ca u ) ['] S" COMPILE, ; IMMEDIATE > > 2VARIABLE tbuff > >: test" ( cccc" -- ) file-S" tbuff 2! ; > > test" this is a test" > > sbuff 2@ TYPE > > ... should give: this is a test OK How can you be sure the string stays in the same place? Another S" is allowed to overwrite it. -- Coos CHForth, 16 bit DOS applications http://home.hccnet.nl/j.j.haak/forth.html
[toc] | [prev] | [next] | [standalone]
| From | BruceMcF <agila61@netscape.net> |
|---|---|
| Date | 2012-06-30 19:11 -0700 |
| Message-ID | <777ba4d4-be7f-4c36-a314-5a01e2e71014@b13g2000yql.googlegroups.com> |
| In reply to | #13409 |
On Jun 30, 8:06 pm, Coos Haak <chfo...@hccnet.nl> wrote: > Op Sat, 30 Jun 2012 16:53:55 -0700 (PDT) schreef BruceMcF: > > > > > > > > > > > On Jun 30, 7:21 pm, teammember0...@gmail.com wrote: > >> I'm trying to learn how to use the "compile," word. Would anybody know how to use it? I am interested in example source code. Thanks. > > > Suppose you want to use the file version of S" in a word ~ that is, > > compile from the input into a buffer, terminated by 0. S" while > > compiling embeds the string at compile time, but ['] S" should get the > > file-S" xt, and compiling it with compile, should give the file-S" > > behavior at runtime: > > >: file-S" ( cccc" -- ca u ) ['] S" COMPILE, ; IMMEDIATE > > > 2VARIABLE tbuff > > >: test" ( cccc" -- ) file-S" tbuff 2! ; > > > test" this is a test" > > > sbuff 2@ TYPE > > > ... should give: this is a test OK > How can you be sure the string stays in the same place? Why do you care whether the string "stays in the same place" when you are using a transitory string function? You use it and abandon it. > Another S" is allowed to overwrite it. Yes, that's the point of the transitory string operation named S" in interpret mode, as opposed to the permanent string compilation operation named S" in compilation mode. If you want a transitory string in the already-existing S" buffer, the compile-S" operation doesn't give it to you.
[toc] | [prev] | [next] | [standalone]
| From | Bernd Paysan <bernd.paysan@gmx.de> |
|---|---|
| Date | 2012-07-01 19:50 +0200 |
| Message-ID | <jsq2lo$s0m$1@online.de> |
| In reply to | #13408 |
BruceMcF wrote: > On Jun 30, 7:21 pm, teammember0...@gmail.com wrote: >> I'm trying to learn how to use the "compile," word. Would anybody >> know how to use it? I am interested in example source code. Thanks. > > Suppose you want to use the file version of S" in a word ~ that is, > compile from the input into a buffer, terminated by 0. S" while > compiling embeds the string at compile time, but ['] S" should get the > file-S" xt, and compiling it with compile, should give the file-S" > behavior at runtime: > > : file-S" ( cccc" -- ca u ) ['] S" COMPILE, ; IMMEDIATE Don't do this. In Gforth, you get what you read by the letters of the standard (this). In VFX Forth, you get the compilation semantics by doing so, and in many other Forths, you just get a state-smart word compiled into your code. As the letters of the standard don't describe reality, it's probably wiser to adjust the letters instead of adjusting reality. COMPILE, is there to allow you to write a user-written compiler. : interpret-word ( "name" -- ) bl word find dup 0= IF -13 throw THEN 0< state @ and IF compile, ELSE execute THEN ; will do so (if you don't find it, you probably can do other things like interpret it as literal instead of -13 throw). Another useful example is in Mino-OOF, to provide early binding to a particular class with "::": : >vt ( class "name" -- slot ) ' >body @ + ; : defines ( xt class "name" -- ) >vt ! ; : :: ( class "name" -- ) >vt @ compile, ; -- Bernd Paysan "If you want it done right, you have to do it yourself" http://bernd-paysan.de/
[toc] | [prev] | [next] | [standalone]
| From | "Elizabeth D. Rather" <erather@forth.com> |
|---|---|
| Date | 2012-07-01 08:40 -1000 |
| Message-ID | <ptOdnTBGnYgGBG3SnZ2dnUVZ_uWdnZ2d@supernews.com> |
| In reply to | #13422 |
On 7/1/12 7:50 AM, Bernd Paysan wrote: ... > > COMPILE, is there to allow you to write a user-written compiler. > > : interpret-word ( "name" -- ) > bl word find dup 0= IF -13 throw THEN > 0< state @ and IF compile, ELSE execute THEN ; > > will do so (if you don't find it, you probably can do other things like > interpret it as literal instead of -13 throw). This is the only realistic example. COMPILE, is intended as the basic word that compiles a reference to a word in a colon definition. It is the replacement for , (comma) used in traditional ITC Forths to compile the address of a word in a colon definition. By giving it the name COMPILE, the Forth94 committee provided "information hiding" that enabled compiler writers to expand their compilers to do various kinds of optimization, and as a result many modern Forths are significantly faster than the traditional ones. Unless you are trying to write a custom compiler, it is unlikely that you will ever need this word in ordinary application programming. 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 | Bernd Paysan <bernd.paysan@gmx.de> |
|---|---|
| Date | 2012-07-01 23:14 +0200 |
| Message-ID | <jsqeiu$pf6$1@online.de> |
| In reply to | #13423 |
Elizabeth D. Rather wrote: > This is the only realistic example. COMPILE, is intended as the basic > word that compiles a reference to a word in a colon definition. It is > the replacement for , (comma) used in traditional ITC Forths to > compile the address of a word in a colon definition. By giving it the > name COMPILE, the Forth94 committee provided "information hiding" that > enabled compiler writers to expand their compilers to do various kinds > of optimization, and as a result many modern Forths are significantly > faster than the traditional ones. > > Unless you are trying to write a custom compiler, it is unlikely that > you will ever need this word in ordinary application programming. This is a toolbox maker word. The Mini-OOF example will apply COMPILE, on words created by :NONAME (i.e. words that don't have a name, just an xt). I've found three different kinds of compile, in Gforth's sources. a) in the text interpreter itself or user-written special purpose text interpreters (like in BerndOOF, where objects are parsing words, and interpret the method in their own context) b) applied to :NONAME-defined words c) parametrized compilation, where factoring is better when you pass some xt's of pretty ordinary words (or primitives) obtained by [']. -- Bernd Paysan "If you want it done right, you have to do it yourself" http://bernd-paysan.de/
[toc] | [prev] | [next] | [standalone]
| From | BruceMcF <agila61@netscape.net> |
|---|---|
| Date | 2012-07-01 15:38 -0700 |
| Message-ID | <c576a3b2-b02a-4190-a4ef-90744d22fefe@t8g2000yqd.googlegroups.com> |
| In reply to | #13422 |
On Jul 1, 1:50 pm, Bernd Paysan <bernd.pay...@gmx.de> wrote: > In VFX Forth, you get the compilation semantics by > doing so, ... Wait a minute ~ what is the point of having a supposed "smart" compiler if it gives the wrong result when ['] ticks the interpretation semantics of S"
[toc] | [prev] | [next] | [standalone]
| From | Bernd Paysan <bernd.paysan@gmx.de> |
|---|---|
| Date | 2012-07-02 01:18 +0200 |
| Message-ID | <jsqlru$rpp$1@online.de> |
| In reply to | #13435 |
BruceMcF wrote: > On Jul 1, 1:50 pm, Bernd Paysan <bernd.pay...@gmx.de> wrote: >>In VFX Forth, you get the compilation semantics by >> doing so, ... > > Wait a minute ~ what is the point of having a supposed "smart" > compiler if it gives the wrong result when ['] ticks the > interpretation semantics of S" You get the interpretation semantics of S" with ['] S" EXECUTE. You get the compilation semantics with ['] S" COMPILE,. Just like with any other non-immediate word (S" is not immediate in VFX, same with IF, TO, and many other words). If we follow the ANS Forth standard literally, like Anton does, we have to come to the conclusion that the only standard-compliant system is the one where FIND returns two different tokes depending on STATE. 1994, this was existing (cmForth), but not very common. The point of a "smart" COMPILE, is to have one xt for both interpretation and compilation state, and use EXECUTE and COMPILE, to access the two semantics. IMHO what we should specify is: ' foo execute is equivalent to foo in interpretation state ' foo compile, is equivalent to foo in compilation state if foo is non-immediate, while ' foo execute is equivalent to foo in compilation state if it is immediate -- Bernd Paysan "If you want it done right, you have to do it yourself" http://bernd-paysan.de/
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2012-07-02 17:03 +0000 |
| Message-ID | <2012Jul2.190352@mips.complang.tuwien.ac.at> |
| In reply to | #13436 |
Bernd Paysan <bernd.paysan@gmx.de> writes:
>BruceMcF wrote:
>
>> On Jul 1, 1:50 pm, Bernd Paysan <bernd.pay...@gmx.de> wrote:
>>>In VFX Forth, you get the compilation semantics by
>>> doing so, ...
>>
>> Wait a minute ~ what is the point of having a supposed "smart"
>> compiler if it gives the wrong result when ['] ticks the
>> interpretation semantics of S"
>
>You get the interpretation semantics of S" with ['] S" EXECUTE. You get
>the compilation semantics with ['] S" COMPILE,. Just like with any
>other non-immediate word (S" is not immediate in VFX, same with IF, TO,
>and many other words).
That's a bug. VFX's COMPILE, does the right thing for words with
default compilation semantics and for immediate words (for immediate
words VFX's COMPILE, does not give you the compilation semantics, and
there it behaves as specified by COMPILE,).
>If we follow the ANS Forth standard literally, like Anton does, we have
>to come to the conclusion that the only standard-compliant system is the
>one where FIND returns two different tokes depending on STATE. 1994,
>this was existing (cmForth), but not very common.
That's certainly a possibility indicated in the description of FIND.
So you would ruin "COMPILE,", which has a very clear specification,
which has also been reconfirmed by the "deities" you would like to use
to override the specification, in order to avoid an implementation
option in FIND which was explicitly allowed in the description of
FIND?
>The point of a "smart" COMPILE, is to have one xt for both
>interpretation and compilation state, and use EXECUTE and COMPILE, to
>access the two semantics. IMHO what we should specify is:
>
>' foo execute is equivalent to foo in interpretation state
>' foo compile, is equivalent to foo in compilation state if foo is
>non-immediate, while
>' foo execute is equivalent to foo in compilation state if it is
>immediate
Only over my dead body. If you want a word that does something other
than "COMPILE,", call it differently. You should have learned the
lesson with Forth-83 (which changed NOT, among others). And even with
a different name, I don't see the point of such a word.
While I was looking for an example of COMPILE, usage, I came across
this piece of code from Gray:
: generate-nt \ -- )
exec dup @ if
@ compile,
else
postpone literal
postpone @
postpone execute
endif ;
Here the fact that EXECUTE and COMPILE, eventually lead to performing
the same emantics is directly used: If we already know which xt will
eventually be performed, we COMPILE, it, otherwise we compile the
address of the place where the xt will be stored, a "@" an an EXECUTE.
This works only correctly if COMPILE, compiles the same semantics that
EXECUTE performs.
BTW, while "smart COMPILE," may give the right association with
"STATE-smart", it might also be confused with "intelligent COMPILE,",
which is a completely different concept.
- 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 2012: http://www.euroforth.org/ef12/
[toc] | [prev] | [next] | [standalone]
| From | Bernd Paysan <bernd.paysan@gmx.de> |
|---|---|
| Date | 2012-07-02 21:39 +0200 |
| Message-ID | <jsstee$c0d$1@online.de> |
| In reply to | #13443 |
Anton Ertl wrote: > That's a bug. VFX's COMPILE, does the right thing for words with > default compilation semantics and for immediate words (for immediate > words VFX's COMPILE, does not give you the compilation semantics, and > there it behaves as specified by COMPILE,). And how would you describe VFX's behavior of ['] IF COMPILE, ? Hint: It performs the compilation semantics of IF, and IF is not an immediate word. > That's certainly a possibility indicated in the description of FIND. Anton, the standard is *not* a divine text. The specification of FIND comes through observation, not to hint you into guessing what the right implementation probably could be. A FIND is both correct if it does return different xts for different states as well if it returns the same xt for the same name all the time. > So you would ruin "COMPILE,", which has a very clear specification, Clear, but wrong. And it is only wrong in corner-cases. > which has also been reconfirmed by the "deities" you would like to use > to override the specification, in order to avoid an implementation > option in FIND which was explicitly allowed in the description of > FIND? No, FIND is still allowed to give different xts depending on state, I just don't want to force anybody to implement it as such. And I don't want *my* FIND to do that. > While I was looking for an example of COMPILE, usage, I came across > this piece of code from Gray: > > : generate-nt \ -- ) > exec dup @ if > @ compile, > else > postpone literal > postpone @ > postpone execute > endif ; This code is perfectly ok, since the xt you compile can only come from :NONAME, which you would have seen if you would have looked up a little, to the definition above: : code-nt \ -- ) \ generates the code for a rule ) :noname get-body generate postpone ; exec ! ; That's the only place where exec is set. A :noname word has default compilation semantics, so your assumption (lit+execute equals compile,) is correct. The main point is: you can't make assumptions about words with non- default compilation semantics, because the way to implement them is not specified by the standard (and if it was, it would be IMMEDIATE + STATE if the interpretation semantics is different). You can't assume that IF, LEAVE, or EXIT are immediate or not, and you can asume even less about S" and TO. They can be state-smart, they can have two different xts depending on state or they can have a different behavior with COMPILE,. That's reality. The way how COMPILE, was envisioned and how it is actually used IMHO leaves no other choice for an intelligent COMPILE, but to be done the way MPE does - you still need to have an immediate flag in the header (for immediate user words and the few standard words which are expicitly specified as immediate), but for all non-immediate words, COMPILE, does the compilation semantics. If you want another word for that purpose, you break the user-written compiler. I'm not sure how much code you really break. Looking at the COMPILE, places in Gforth, *all* of them are applied to words created fully under the control of the program that does COMPILE, - even in those places where the user-written text interpreter is used (my OOF e.g.). I haven't yet rewritten my BerndOOF port to VFX to use the new intelligent COMPILE, yet, but it probably would be a good idea to do so, to get rid of all the state-smartness stuff. I actually don't think writing your own text interpreter is a good idea to solve problems in Forth where you currently need to do that. Recognizers are a much better way to extend (or redefine) the interpreter - you can plug them in where you want, and they work transparently on all input sources, while leaving the rest of the interpreter as is. And the intelligent COMPILE, system fits much nicer into the way I do my recognizers than Gforth's name tokens. I don't want to stop progress by "academic" concerns for which no real evidence that it is problematic has been found, while the strict interpretation of COMPILE, makes it impossible to use COMPILE, for the purpose it originally was envisioned, which seems to be a much stronger concern for me. Specification bugs are the most expensive bugs (IIRC, this is Brooks), and it is because some people insist in that the specification is always right, no matter how bad the consequences are. The broken part in the standard is the term "execution semantics", which is overused. -- Bernd Paysan "If you want it done right, you have to do it yourself" http://bernd-paysan.de/
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2012-07-03 16:55 +0000 |
| Message-ID | <2012Jul3.185548@mips.complang.tuwien.ac.at> |
| In reply to | #13448 |
Bernd Paysan <bernd.paysan@gmx.de> writes:
>Anton Ertl wrote:
>> That's a bug. VFX's COMPILE, does the right thing for words with
>> default compilation semantics and for immediate words (for immediate
>> words VFX's COMPILE, does not give you the compilation semantics, and
>> there it behaves as specified by COMPILE,).
>
>And how would you describe VFX's behavior of ['] IF COMPILE, ? Hint: It
>performs the compilation semantics of IF, and IF is not an immediate
>word.
Well, "['] IF" makes it a non-standard program. However, I would
expect a high-quality system to behave the same way with the built-in
COMPILE, and with
: compile, ( xt -- ) postpone literal postpone execute ;
>> That's certainly a possibility indicated in the description of FIND.
>
>Anton, the standard is *not* a divine text. The specification of FIND
>comes through observation, not to hint you into guessing what the right
>implementation probably could be. A FIND is both correct if it does
>return different xts for different states as well if it returns the same
>xt for the same name all the time.
And your point is?
>> So you would ruin "COMPILE,", which has a very clear specification,
>
>Clear, but wrong. And it is only wrong in corner-cases.
What makes you think it is wrong? It works for the text interpreter
that was the original usage case.
>> which has also been reconfirmed by the "deities" you would like to use
>> to override the specification, in order to avoid an implementation
>> option in FIND which was explicitly allowed in the description of
>> FIND?
>
>No, FIND is still allowed to give different xts depending on state, I
>just don't want to force anybody to implement it as such. And I don't
>want *my* FIND to do that.
So that's what this ado is about.
I don't want my FIND to do that, either, but I bit the bullet and did
it, because it makes the user-written text interpreter work (not
because of the specification of FIND, which is too unclear for that).
Beyond that, I am hoping that we can eventually find consensus on a
FIND replacement (possibly consisting of several words) that
1) is clearly specified
2) takes a c-addr u string
3) does not need to check STATE on some implementations
>> While I was looking for an example of COMPILE, usage, I came across
>> this piece of code from Gray:
>>
>> : generate-nt \ -- )
>> exec dup @ if
>> @ compile,
>> else
>> postpone literal
>> postpone @
>> postpone execute
>> endif ;
>
>This code is perfectly ok, since the xt you compile can only come from
>:NONAME
Sure, but if I came across that code using this equivalence while
looking for something else, I expect that there is code out there that
uses that equivalence and to which you can pass any xt.
>The main point is: you can't make assumptions about words with non-
>default compilation semantics, because the way to implement them is not
>specified by the standard (and if it was, it would be IMMEDIATE + STATE
>if the interpretation semantics is different). You can't assume that
>IF, LEAVE, or EXIT are immediate or not, and you can asume even less
>about S" and TO. They can be state-smart, they can have two different
>xts depending on state or they can have a different behavior with
>COMPILE,. That's reality.
The first option (STATE-smart) was probably intended by the TC,
although the specification does not allow it. The second option is
clearly compatible with the specification. The third option is
neither compatible with the specification nor was it intended by the
TC (because such systems did not exist nor were envisioned then); it's
just a bug.
>The way how COMPILE, was envisioned and how it is actually used IMHO
>leaves no other choice for an intelligent COMPILE, but to be done the
>way MPE does
Gforth has an intelligent COMPILE, that behaves correctly, so this
demonstrates that there is an alternative choice.
Also, the idea behind the "intelligent COMPILE," is that it is an
implementation technique; a correct intelligent COMPILE, implements
the same behaviour as "," does on a simple threaded-code system. If
you want something different, don't call it "intelligent COMPILE,".
Actually, don't call it COMPILE, at all.
> - you still need to have an immediate flag in the header
>(for immediate user words and the few standard words which are expicitly
>specified as immediate), but for all non-immediate words, COMPILE, does
>the compilation semantics. If you want another word for that purpose,
>you break the user-written compiler.
I don't want it, you want it. But you want to call it "COMPILE,", and
that's a no-no.
>I don't want to stop progress by "academic" concerns for which no real
>evidence that it is problematic has been found, while the strict
>interpretation of COMPILE, makes it impossible to use COMPILE, for the
>purpose it originally was envisioned, which seems to be a much stronger
>concern for me.
It doesn't, as is demonstrated by the fact that the user-written
interpreter works on systems that implement COMPILE, according to the
specification.
> The broken part in the
>standard is the term "execution semantics", which is overused.
There is certainly a problem somewhere between the definition of terms
of that and some of the uses (in particular in "execution token"),
which leads to an inconsistency.
- 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 2012: http://www.euroforth.org/ef12/
[toc] | [prev] | [next] | [standalone]
| From | Bernd Paysan <bernd.paysan@gmx.de> |
|---|---|
| Date | 2012-07-03 23:09 +0200 |
| Message-ID | <jsvn1u$9nb$1@online.de> |
| In reply to | #13479 |
Anton Ertl wrote: > I don't want it, you want it. But you want to call it "COMPILE,", and > that's a no-no. *Not* calling it COMPILE, is a no-no, because it means that the envisioned standard user-written text interpreters won't work on such a system. I don't think we should find a new name for a word that already exists, that was envisioned for this purpose, and that has been misspecified, because the situation that breaks the specification didn't exist in 1994. Let people make errors and allow other people to correct them. You constantly ignore Mitch Bradley, and I don't know why. His COMPILE, has a purpose, and the purpose is more important than the exact wording of the specification. A program that ticks S" should be made as non-standard as a program that ticks IF. Problem solved, the case you insist on does no longer exist. User-defined immediate words are legacy, and should be treated as they always have been (that's how VFX does it), which means that you can't define : immediate ['] execute last-xt >comp ! ; (with : compile, ( xt -- ) dup >comp @ execute ; ) I would like to do this, but this is far more likely to break code, so I can't. -- Bernd Paysan "If you want it done right, you have to do it yourself" http://bernd-paysan.de/
[toc] | [prev] | [next] | [standalone]
| From | BruceMcF <agila61@netscape.net> |
|---|---|
| Date | 2012-07-02 12:00 -0700 |
| Message-ID | <536bde94-fe78-438c-a3b0-e367ffd5c6e6@d6g2000vbe.googlegroups.com> |
| In reply to | #13436 |
On Jul 1, 7:18 pm, Bernd Paysan <bernd.pay...@gmx.de> wrote: > BruceMcF wrote: > > On Jul 1, 1:50 pm, Bernd Paysan <bernd.pay...@gmx.de> wrote: > >>In VFX Forth, you get the compilation semantics by > >> doing so, ... > > Wait a minute ~ what is the point of having a supposed "smart" > > compiler if it gives the wrong result when ['] ticks the > > interpretation semantics of S" > You get the interpretation semantics of S" with ['] S" EXECUTE. You get > the compilation semantics with ['] S" COMPILE,. So IOW, what you get is wrong. ['] S" should certainly give the same behavior whether executed immediately or compiled for later execution. > If we follow the ANS Forth standard literally, like Anton does, we have > to come to the conclusion that the only standard-compliant system is the > one where FIND returns two different tokes depending on STATE. When it tried the code in gforth it worked. On my netbook, that's the most convenient one to use for bench testing a small snippet of code. For ' and ['] what FIND returns is neither here nor there ~ ' and ['] should return something that gives the interpretation behavior.
[toc] | [prev] | [next] | [standalone]
| From | Bernd Paysan <bernd.paysan@gmx.de> |
|---|---|
| Date | 2012-07-02 22:44 +0200 |
| Message-ID | <jst16t$i30$1@online.de> |
| In reply to | #13446 |
BruceMcF wrote: >> You get the interpretation semantics of S" with ['] S" EXECUTE. You >> get the compilation semantics with ['] S" COMPILE,. > > So IOW, what you get is wrong. ['] S" should certainly give the same > behavior whether executed immediately or compiled for later execution. Which leaves, as implementation options, one choice: dual-xt FIND. As state-smart is ruled out, too. >> If we follow the ANS Forth standard literally, like Anton does, we >> have to come to the conclusion that the only standard-compliant >> system is the one where FIND returns two different tokes depending on >> STATE. > > When it tried the code in gforth it worked. Yes, because Gforth's way to solve this particular problem is implemented by Anton, and therefore follows Anton's interpretation. I'd rather like to go the intelligent COMPILE, way, but that would result in a fork of Gforth - and since we use CVS, forking is not a good option (ok, I could use git for the fork). I prefer to find a consense with Anton, even when it is difficult. In the long run, this is a much better way to collaboratively develop software. And trust me, Gforth is a long-running project, it is about to celebrate it's 20th birthday. > For ' and ['] what FIND returns is neither here nor there ~ ' and ['] > should return something that gives the interpretation behavior. With EXECUTE. ' foo EXECUTE is equal to foo in interpretation state. The execution semantics in the standard is defined so inconsistently that *this* is the thing you can actually trust. I'd say if a word has default compilation semantics, you can trust in COMPILE, to result in the behavior you actually expect. So far, I've not seen any real-world examples of COMPILE, except the definition of POSTPONE which violate this rule (they all apply to words with default compilation semantics). -- Bernd Paysan "If you want it done right, you have to do it yourself" http://bernd-paysan.de/
[toc] | [prev] | [next] | [standalone]
| From | Josh Grams <josh@qualdan.com> |
|---|---|
| Date | 2012-07-02 20:18 +0000 |
| Message-ID | <4ff20230$0$14014$882e7ee2@usenet-news.net> |
| In reply to | #13436 |
Bernd Paysan wrote: <jsqlru$rpp$1@online.de> > S" is not immediate in VFX, same with IF, TO, and many other words. How does that work? I can understand how you can get around it for TO, but surely S" and IF need to have special compilation semantics? Or by "not immediate" do you just mean that the compilation and interpretation semantics are not the same? --Josh
[toc] | [prev] | [next] | [standalone]
| From | Bernd Paysan <bernd.paysan@gmx.de> |
|---|---|
| Date | 2012-07-02 22:53 +0200 |
| Message-ID | <jst1nt$523$1@online.de> |
| In reply to | #13449 |
Josh Grams wrote: > Bernd Paysan wrote: <jsqlru$rpp$1@online.de> >> S" is not immediate in VFX, same with IF, TO, and many other words. > > How does that work? I can understand how you can get around it for > TO, but surely S" and IF need to have special compilation semantics? All special compilation semantics is done through the intelligent COMPILE, - which is a field similar to the code field (I would put it into the header, MPE decided to let the header as is and put it somewhere else). > Or by "not immediate" do you just mean that the compilation and > interpretation semantics are not the same? By "not immediate" I mean it has no immediate bit set in the header. It has special compilation semantics by setting the COMPILE, field to something different than the default. -- Bernd Paysan "If you want it done right, you have to do it yourself" http://bernd-paysan.de/
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2012-07-02 16:54 +0000 |
| Message-ID | <2012Jul2.185409@mips.complang.tuwien.ac.at> |
| In reply to | #13422 |
Bernd Paysan <bernd.paysan@gmx.de> writes:
>BruceMcF wrote:
>
>> On Jun 30, 7:21 pm, teammember0...@gmail.com wrote:
>>> I'm trying to learn how to use the "compile," word. Would anybody
>>> know how to use it? I am interested in example source code. Thanks.
>>
>> Suppose you want to use the file version of S" in a word ~ that is,
>> compile from the input into a buffer, terminated by 0. S" while
>> compiling embeds the string at compile time, but ['] S" should get the
>> file-S" xt, and compiling it with compile, should give the file-S"
>> behavior at runtime:
>>
>> : file-S" ( cccc" -- ca u ) ['] S" COMPILE, ; IMMEDIATE
>
>Don't do this. In Gforth, you get what you read by the letters of the
>standard (this). In VFX Forth, you get the compilation semantics by
>doing so,
Just another bug to fix.
> and in many other Forths, you just get a state-smart word
>compiled into your code.
Which will work in the expected way for his code.
>As the letters of the standard don't describe
>reality, it's probably wiser to adjust the letters instead of adjusting
>reality.
A Forth system has a bug, so let's not fix the bug, but fix the
standard?
>COMPILE, is there to allow you to write a user-written compiler.
A pretty useless exercise, because there are no standard holes (in,
e.g., INCLUDED or EVALUATE) into which you can plug the compiler.
But COMPILE, is useful for other things, e.g., for writing
parameterized code generators. An example is the parser generator
Gray <http://www.complang.tuwien.ac.at/forth/gray.zip>, which contains
several occurences of "COMPILE,". E.g.:
: generate-nt \ -- )
\ generates a call to the code for the rule )
\ since the code needs not be generated yet, an indirect call may be used )
exec dup @ if
@ compile,
else
postpone literal
postpone @
postpone execute
endif ;
- 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 2012: http://www.euroforth.org/ef12/
[toc] | [prev] | [next] | [standalone]
| From | Andrew Haley <andrew29@littlepinkcloud.invalid> |
|---|---|
| Date | 2012-07-02 13:05 -0500 |
| Message-ID | <MaSdnTTd1dlgf2zSnZ2dnUVZ8uydnZ2d@supernews.com> |
| In reply to | #13442 |
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote: > A Forth system has a bug, so let's not fix the bug, but fix the > standard? > >>COMPILE, is there to allow you to write a user-written compiler. > > A pretty useless exercise, because there are no standard holes (in, > e.g., INCLUDED or EVALUATE) into which you can plug the compiler. I don't agree it's useless. You can call a user-written compiler directly. Andrew.
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2012-07-03 16:08 +0000 |
| Message-ID | <2012Jul3.180812@mips.complang.tuwien.ac.at> |
| In reply to | #13444 |
Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
[Someone:]
>>>COMPILE, is there to allow you to write a user-written compiler.
>>
>> A pretty useless exercise, because there are no standard holes (in,
>> e.g., INCLUDED or EVALUATE) into which you can plug the compiler.
>
>I don't agree it's useless. You can call a user-written compiler
>directly.
How often have you done that in production code?
- 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 2012: http://www.euroforth.org/ef12/
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.forth
csiph-web