Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #13018 > unrolled thread

?EXEC

Started byAlbert van der Horst <albert@spenarnc.xs4all.nl>
First post2012-06-15 20:40 +0000
Last post2012-06-22 15:43 -0700
Articles 20 on this page of 96 — 13 participants

Back to article view | Back to comp.lang.forth


Contents

  ?EXEC Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-15 20:40 +0000
    Re: ?EXEC "Ed" <invalid@nospam.com> - 2012-06-16 11:14 +1000
    Re: ?EXEC BruceMcF <agila61@netscape.net> - 2012-06-16 07:10 -0700
      Re: ?EXEC Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-17 03:01 +0000
        Re: ?EXEC "Ed" <invalid@nospam.com> - 2012-06-17 13:36 +1000
        Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-17 12:27 +0000
          Re: ?EXEC Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-17 20:45 +0000
            Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-18 13:31 +0000
              Re: ?EXEC Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-18 18:29 +0000
                Re: ?EXEC "Elizabeth D. Rather" <erather@forth.com> - 2012-06-18 08:01 -1000
                Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-19 14:09 +0000
                  Re: ?EXEC Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-19 10:51 -0500
                    Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-19 16:04 +0000
                      Re: ?EXEC Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-19 12:45 -0500
                        Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-20 10:50 +0000
                          Re: ?EXEC Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-20 07:10 -0500
                            Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-20 12:47 +0000
                  Re: ?EXEC Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-19 22:52 +0000
                    Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-20 10:59 +0000
                  Defining Compilation Behaviour - was Re: ?EXEC JennyB <jennybrien@googlemail.com> - 2012-06-21 04:58 -0700
                    Re: Defining Compilation Behaviour - was Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-21 15:44 +0000
              Re: ?EXEC Bernd Paysan <bernd.paysan@gmx.de> - 2012-06-19 02:11 +0200
                Re: ?EXEC "Elizabeth D. Rather" <erather@forth.com> - 2012-06-18 14:45 -1000
                  Re: ?EXEC Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-19 10:48 +0000
                    Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-19 15:53 +0000
                      Re: ?EXEC Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-19 23:00 +0000
                        Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-20 11:09 +0000
                          Re: ?EXEC BruceMcF <agila61@netscape.net> - 2012-06-20 07:39 -0700
                            Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-20 15:32 +0000
                              Re: ?EXEC BruceMcF <agila61@netscape.net> - 2012-06-21 11:24 -0700
                          Re: ?EXEC Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-20 22:43 +0000
                          Re: ?EXEC Bernd Paysan <bernd.paysan@gmx.de> - 2012-06-21 21:39 +0200
                          Re: ?EXEC Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-22 02:33 -0500
                            Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-22 11:12 +0000
                              Re: ?EXEC Bernd Paysan <bernd.paysan@gmx.de> - 2012-06-22 21:34 +0200
                                Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-24 14:58 +0000
                                  Re: ?EXEC Bernd Paysan <bernd.paysan@gmx.de> - 2012-06-24 23:53 +0200
                  Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-19 15:43 +0000
                Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-19 14:52 +0000
                  Re: ?EXEC Bernd Paysan <bernd.paysan@gmx.de> - 2012-06-21 22:15 +0200
                    Re: ?EXEC stephenXXX@mpeforth.com (Stephen Pelc) - 2012-06-22 10:32 +0000
                      Re: ?EXEC Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-22 05:49 -0500
                        Alternatives to S" and TO (was: ?EXEC) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-22 15:19 +0000
                          Re: Alternatives to S'' and TO mhx@iae.nl (Marcel Hendrix) - 2012-06-22 20:37 +0200
                            Re: Alternatives to S'' and TO anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-23 14:46 +0000
                          Re: Alternatives to S" and TO (was: ?EXEC) BruceMcF <agila61@netscape.net> - 2012-06-22 12:32 -0700
                          Re: Alternatives to S" and TO Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-23 03:07 -0500
                            Re: Alternatives to S" and TO anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-23 13:32 +0000
                              Re: Alternatives to S" and TO Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-24 08:50 -0500
                                Re: Alternatives to S" and TO anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-24 15:39 +0000
                                  Re: Alternatives to S" and TO Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-25 04:49 -0500
                                    Re: Alternatives to S" and TO BruceMcF <agila61@netscape.net> - 2012-06-25 07:17 -0700
                                      Re: Alternatives to S" and TO Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-25 10:13 -0500
                          Re: Alternatives to S" and TO (was: ?EXEC) Alex McDonald <blog@rivadpm.com> - 2012-06-23 16:01 -0700
                            Re: Alternatives to S" and TO (was: ?EXEC) Bernd Paysan <bernd.paysan@gmx.de> - 2012-06-24 01:59 +0200
                              Re: Alternatives to S" and TO (was: ?EXEC) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-24 13:21 +0000
                              Re: Alternatives to S" and TO (was: ?EXEC) Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-24 16:50 +0000
                              Re: Alternatives to S" and TO (was: ?EXEC) Bernd Paysan <bernd.paysan@gmx.de> - 2012-06-27 23:30 +0200
                            Re: Alternatives to S" and TO (was: ?EXEC) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-24 13:15 +0000
                            Re: Alternatives to S" and TO (was: ?EXEC) Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-24 16:47 +0000
                        Re: ?EXEC Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-22 20:34 +0000
                      Re: ?EXEC Bernd Paysan <bernd.paysan@gmx.de> - 2012-06-22 21:46 +0200
                        Re: ?EXEC "Elizabeth D. Rather" <erather@forth.com> - 2012-06-22 10:16 -1000
                          Re: ?EXEC Bernd Paysan <bernd.paysan@gmx.de> - 2012-06-22 22:43 +0200
                            Re: ?EXEC "Elizabeth D. Rather" <erather@forth.com> - 2012-06-22 11:18 -1000
                            Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-23 13:50 +0000
        Re: ?EXEC BruceMcF <agila61@netscape.net> - 2012-06-17 10:41 -0700
    Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-17 12:52 +0000
      Re: ?EXEC "Elizabeth D. Rather" <erather@forth.com> - 2012-06-17 08:03 -1000
        Re: ?EXEC "Ed" <invalid@nospam.com> - 2012-06-18 15:06 +1000
          Re: ?EXEC "Elizabeth D. Rather" <erather@forth.com> - 2012-06-17 20:31 -1000
            Re: ?EXEC "Ed" <invalid@nospam.com> - 2012-06-21 13:07 +1000
              Re: ?EXEC Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-21 14:00 +0000
                Re: ?EXEC BruceMcF <agila61@netscape.net> - 2012-06-21 07:51 -0700
                Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-21 15:39 +0000
                  Re: ?EXEC Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-21 20:28 +0000
                    Re: ?EXEC "Ed" <invalid@nospam.com> - 2012-06-28 14:22 +1000
                      Re: ?EXEC Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-28 04:00 -0500
              Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-21 16:09 +0000
              Re: ?EXEC Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-21 11:51 -0500
                Re: ?EXEC BruceMcF <agila61@netscape.net> - 2012-06-21 11:21 -0700
                  Re: ?EXEC Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-22 01:42 -0500
                    Re: ?EXEC "Elizabeth D. Rather" <erather@forth.com> - 2012-06-21 21:47 -1000
                      Re: ?EXEC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-22 15:10 +0000
                        Re: ?EXEC Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-22 20:39 +0000
                      Re: ?EXEC BruceMcF <agila61@netscape.net> - 2012-06-22 12:47 -0700
                    Re: ?EXEC BruceMcF <agila61@netscape.net> - 2012-06-22 12:53 -0700
          Re: ?EXEC stephenXXX@mpeforth.com (Stephen Pelc) - 2012-06-21 08:39 +0000
            Re: ?EXEC "Ed" <invalid@nospam.com> - 2012-06-23 15:36 +1000
              Re: ?EXEC stephenXXX@mpeforth.com (Stephen Pelc) - 2012-06-23 10:58 +0000
                Re: ?EXEC "Ed" <invalid@nospam.com> - 2012-06-25 14:26 +1000
                  Re: ?EXEC stephenXXX@mpeforth.com (Stephen Pelc) - 2012-06-25 08:37 +0000
        Re: ?EXEC Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-18 10:34 +0000
    Re: ?EXEC Coos Haak <chforth@hccnet.nl> - 2012-06-18 17:47 +0200
      Re: ?EXEC Coos Haak <chforth@hccnet.nl> - 2012-06-18 17:49 +0200
    Re: ?EXEC jacko <jackokring@gmail.com> - 2012-06-22 15:43 -0700

Page 1 of 5  [1] 2 3 4 5  Next page →


#13018 — ?EXEC

FromAlbert van der Horst <albert@spenarnc.xs4all.nl>
Date2012-06-15 20:40 +0000
Subject?EXEC
Message-ID<m5oer1.l31@spenarnc.xs4all.nl>
I find places where ?EXEC is used. This gives an error because a word
if a word is executed while it never should.

Examples are CODE and END-CODE in an assembler, but does this make
sense?

: CODE ?EXEC .... ;
: END-CODE ?EXEC .... ;

By analogy I see I defined my classes like this:
: class ?EXEC ... ;
: end-class ?EXEC ... ;

I find it hard to wrap my head around this. In what kind of situation
would this error trigger?
I would be equally happy with some other realistic example.

Groetjes Albert


--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

[toc] | [next] | [standalone]


#13022

From"Ed" <invalid@nospam.com>
Date2012-06-16 11:14 +1000
Message-ID<jrgmmj$k2c$1@speranza.aioe.org>
In reply to#13018
Albert van der Horst wrote:
> I find places where ?EXEC is used. This gives an error because a word
> if a word is executed while it never should.
>
> Examples are CODE and END-CODE in an assembler, but does this make
> sense?
>
> : CODE ?EXEC .... ;
> : END-CODE ?EXEC .... ;
>
> By analogy I see I defined my classes like this:
> : class ?EXEC ... ;
> : end-class ?EXEC ... ;
>
> I find it hard to wrap my head around this. In what kind of situation
> would this error trigger?
> I would be equally happy with some other realistic example.

Possibly there is none.

?EXEC was a companion function to ?COMP.  These were part
of the "compiler security" package introduced by Fig-Forth and
copied by just about everyone (except notably Forth Inc.)

Whether Forth needed the level compiler security provided by
Fig-Forth was questioned in the article "Compiler Security"
G.Shaw, FD 3/1.

I note in my own sources I use ?EXEC in  CODE END-CODE
LABEL - which were all IMMEDIATE.  I can't recall ever using or
needing this feature.


[toc] | [prev] | [next] | [standalone]


#13027

FromBruceMcF <agila61@netscape.net>
Date2012-06-16 07:10 -0700
Message-ID<b445b94c-64c5-4773-be56-ee8c75f24f4d@h10g2000yqn.googlegroups.com>
In reply to#13018
On Jun 15, 4:40 pm, Albert van der Horst <alb...@spenarnc.xs4all.nl>
wrote:
> I find places where ?EXEC is used. This gives an error because a word
> if a word is executed while it never should.

"because a word if a word is executed while it never should." ?

... seems to be mangled. What is the actual condition that is supposed
to trigger the error? Ed notes that its a fig-Forthism, and its been
several decades since I knew the fig Forth model in any detail.

>
> Examples are CODE and END-CODE in an assembler, but does this make
> sense?
>
> : CODE ?EXEC .... ;
> : END-CODE ?EXEC .... ;
>
> By analogy I see I defined my classes like this:
> : class ?EXEC ... ;
> : end-class ?EXEC ... ;
>
> I find it hard to wrap my head around this. In what kind of situation
> would this error trigger?
> I would be equally happy with some other realistic example.

[toc] | [prev] | [next] | [standalone]


#13030

FromAlbert van der Horst <albert@spenarnc.xs4all.nl>
Date2012-06-17 03:01 +0000
Message-ID<m5qr30.n40@spenarnc.xs4all.nl>
In reply to#13027
In article <b445b94c-64c5-4773-be56-ee8c75f24f4d@h10g2000yqn.googlegroups.com>,
BruceMcF  <agila61@netscape.net> wrote:
>On Jun 15, 4:40=A0pm, Albert van der Horst <alb...@spenarnc.xs4all.nl>
>wrote:
>> I find places where ?EXEC is used. This gives an error because a word
>> if a word is executed while it never should.
>
>"because a word if a word is executed while it never should." ?
>
>... seems to be mangled. What is the actual condition that is supposed
>to trigger the error? Ed notes that its a fig-Forthism, and its been
>several decades since I knew the fig Forth model in any detail.

Sorry. I put too much trust in my spell checker ;-)
Maybe just this:
"
SEE ?EXEC

: ?EXEC
STATE   @   12 ?ERROR
;
"
?ERROR is THROW with some decoration.

>
>>
>> Examples are CODE and END-CODE in an assembler, but does this make
>> sense?
>>
>> : CODE ?EXEC .... ;
>> : END-CODE ?EXEC .... ;
>>
>> By analogy I see I defined my classes like this:
>> : class ?EXEC ... ;
>> : end-class ?EXEC ... ;
>>
>> I find it hard to wrap my head around this. In what kind of situation
>> would this error trigger?
>> I would be equally happy with some other realistic example.
>
>

I just discovered that having ?COMP in IF and DO is useful.

I had a bug in a class definition because I forgot that the build
code is run in interpret mode. Took me an hour to realize what
was going on. Maybe I should load the interpreted IF's and DO's
standard with the class tool, but certainly I will add the ?COMP.

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

[toc] | [prev] | [next] | [standalone]


#13031

From"Ed" <invalid@nospam.com>
Date2012-06-17 13:36 +1000
Message-ID<jrjjbk$39a$1@speranza.aioe.org>
In reply to#13030
Albert van der Horst wrote:
> ...
> I just discovered that having ?COMP in IF and DO is useful.
>
> I had a bug in a class definition because I forgot that the build
> code is run in interpret mode. Took me an hour to realize what
> was going on. Maybe I should load the interpreted IF's and DO's
> standard with the class tool, but certainly I will add the ?COMP.

How often do you make such errors :)

?COMP is a convenience that can alert one to silly errors
sooner, but like ?EXEC the times it is useful will be rare.
To this day SwiftForth has no ?COMP.

OTOH providing ?COMP is cheap and it turns out only 4
are necessary to cover all the standard structures IF ELSE
THEN AHEAD BEGIN WHILE REPEAT UNTIL DO LOOP
CASE etc.


[toc] | [prev] | [next] | [standalone]


#13033

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2012-06-17 12:27 +0000
Message-ID<2012Jun17.142751@mips.complang.tuwien.ac.at>
In reply to#13030
Albert van der Horst <albert@spenarnc.xs4all.nl> writes:
>I just discovered that having ?COMP in IF and DO is useful.

No, it's the plague.  It turns nicely working words into STATE-smart
crap.  ?COMP (like all STATE-smart words) tests STATE at run-time,
whereas what is wanted is to have a check at parsing time (and that's
the same for all STATE-smart words).

If you want to protect against using IF and DO interpretively, add a
compile-only flag to the header, and let the text interpreter check
it.  For more complicated cases (words that can be used
interpretively, but behave differently), there are a number of good
implementation approaches (checking STATE at run-time is not one of
them).

- 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]


#13040

FromAlbert van der Horst <albert@spenarnc.xs4all.nl>
Date2012-06-17 20:45 +0000
Message-ID<m5s4bd.5r0@spenarnc.xs4all.nl>
In reply to#13033
In article <2012Jun17.142751@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>Albert van der Horst <albert@spenarnc.xs4all.nl> writes:
>>I just discovered that having ?COMP in IF and DO is useful.
>
>No, it's the plague.  It turns nicely working words into STATE-smart
>crap.  ?COMP (like all STATE-smart words) tests STATE at run-time,
>whereas what is wanted is to have a check at parsing time (and that's
>the same for all STATE-smart words).

In this case the problem happens at parsing time, so the check is
done at the right time, i.e. while interpreting. Think about it.
?EXEC can never be a proper error message. ?COMP can never hinder
postponing something. Has nothing to do with state smartness.

When was the last time you did
: aaap .... [ IF ] .... ;
while you could have done
: aaap ....  IF  .... ;

>
>If you want to protect against using IF and DO interpretively, add a
>compile-only flag to the header, and let the text interpreter check
>it.  For more complicated cases (words that can be used
>interpretively, but behave differently), there are a number of good
>implementation approaches (checking STATE at run-time is not one of
>them).

I have a better solution: I can use IF and DO interpretively,
after I say WANT NEW-IF .

Making the text interpreter smarter is the opposite way from where
I want to go.
Remember, ciforth's interpreter doesn't know about numbers, only
prefixes. It is simpler and more flexible that way.

But ?LOADING and ?EXEC I have removed. So I have the luxury that
2 words may go in the kernel to replace them. Maybe I'll finally add
NIP .  68 of my 199 euler Forth files contain WANT NIP.


>
>- anton

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

[toc] | [prev] | [next] | [standalone]


#13045

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2012-06-18 13:31 +0000
Message-ID<2012Jun18.153125@mips.complang.tuwien.ac.at>
In reply to#13040
Albert van der Horst <albert@spenarnc.xs4all.nl> writes:
>In article <2012Jun17.142751@mips.complang.tuwien.ac.at>,
>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>Albert van der Horst <albert@spenarnc.xs4all.nl> writes:
>>>I just discovered that having ?COMP in IF and DO is useful.
>>
>>No, it's the plague.  It turns nicely working words into STATE-smart
>>crap.  ?COMP (like all STATE-smart words) tests STATE at run-time,
>>whereas what is wanted is to have a check at parsing time (and that's
>>the same for all STATE-smart words).
>
>In this case the problem happens at parsing time, so the check is
>done at the right time, i.e. while interpreting. Think about it.
>?EXEC can never be a proper error message. ?COMP can never hinder
>postponing something. Has nothing to do with state smartness.

Try <http://www.complang.tuwien.ac.at/forth/postponetest.fs> and see
how IF and DO with ?COMP are broken.

>When was the last time you did
>: aaap .... [ IF ] .... ;
>while you could have done
>: aaap ....  IF  .... ;

In a compiler where the text interpreter checks for compile-only words
(like Gforth) the first version would fail because IF is compile-only
and thus can only be compiled.

However, the issue is not 

: aaap ... [ IF ] ... ;

but

: baz ... [ 3 5 gen-foo s" bla" gen-bar ] ... ;

where GEN-FOO contains, e.g., a "POSTPONE IF".

Yes, the ?COMP does not hinder POSTPONEing the IF, it just fails when
GEN-FOO runs.  And it has everything to do with STATE-smartness: It
checks STATE at run-time, like any other STATE-smart word.

And yes, I have written production code where a code generator is
invoked in interpret state.

>>If you want to protect against using IF and DO interpretively, add a
>>compile-only flag to the header, and let the text interpreter check
>>it.  For more complicated cases (words that can be used
>>interpretively, but behave differently), there are a number of good
>>implementation approaches (checking STATE at run-time is not one of
>>them).
...
>Making the text interpreter smarter is the opposite way from where
>I want to go.

If you don't want to go there, then don't.  Just live without
recognizing interpretive uses of IF and DO.  But if you want to
recognize them, do it properly.  STATE-smartness (including ?COMP) is
both broken and more complicated than not checking at all, i.e., it's
a lose-lose solution.

- 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]


#13048

FromAlbert van der Horst <albert@spenarnc.xs4all.nl>
Date2012-06-18 18:29 +0000
Message-ID<m5tspw.8zy@spenarnc.xs4all.nl>
In reply to#13045
In article <2012Jun18.153125@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>Albert van der Horst <albert@spenarnc.xs4all.nl> writes:
>>In article <2012Jun17.142751@mips.complang.tuwien.ac.at>,
>>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>>Albert van der Horst <albert@spenarnc.xs4all.nl> writes:
>>>>I just discovered that having ?COMP in IF and DO is useful.
>>>
>>>No, it's the plague.  It turns nicely working words into STATE-smart
>>>crap.  ?COMP (like all STATE-smart words) tests STATE at run-time,
>>>whereas what is wanted is to have a check at parsing time (and that's
>>>the same for all STATE-smart words).
>>
>>In this case the problem happens at parsing time, so the check is
>>done at the right time, i.e. while interpreting. Think about it.
>>?EXEC can never be a proper error message. ?COMP can never hinder
>>postponing something. Has nothing to do with state smartness.
>
>Try <http://www.complang.tuwien.ac.at/forth/postponetest.fs> and see
>how IF and DO with ?COMP are broken.
>
>>When was the last time you did
>>: aaap .... [ IF ] .... ;
>>while you could have done
>>: aaap ....  IF  .... ;
>
>In a compiler where the text interpreter checks for compile-only words
>(like Gforth) the first version would fail because IF is compile-only
>and thus can only be compiled.
>
>However, the issue is not
>
>: aaap ... [ IF ] ... ;
>
>but
>
>: baz ... [ 3 5 gen-foo s" bla" gen-bar ] ... ;
>
>where GEN-FOO contains, e.g., a "POSTPONE IF".
>
>Yes, the ?COMP does not hinder POSTPONEing the IF, it just fails when
>GEN-FOO runs.  And it has everything to do with STATE-smartness: It
>checks STATE at run-time, like any other STATE-smart word.

That would actually be nice, because one concludes that we have
an advanced tool at our hands and I would insert
WANT NO-SECURITY    NO-SECURITY
before including the file. This is a similar situation with
  BEGIN .. WHILE .. WHILE .. REPEAT ..THEN
that triggers an error too.

Helas, that is not what happens.
What is much worse that I *do* have an interpreting IF and DO
that are state smart and can e.g. generate a table interpretively.
A cut and paste of my CRC screen:

5 \ Auxiliary table with values for single bytes.
6 CREATE CRCTable
7 100 0 DO   I 8 0 DO
8     DUP >R   1 RSHIFT   R> 1 AND IF CRC32_POLYNOMIAL XOR THEN
9 LOOP ,   LOOP

>
>And yes, I have written production code where a code generator is
>invoked in interpret state.

That sets me thinking.

>
>>>If you want to protect against using IF and DO interpretively, add a
>>>compile-only flag to the header, and let the text interpreter check
>>>it.  For more complicated cases (words that can be used
>>>interpretively, but behave differently), there are a number of good
>>>implementation approaches (checking STATE at run-time is not one of
>>>them).
>...
>>Making the text interpreter smarter is the opposite way from where
>>I want to go.
>
>If you don't want to go there, then don't.  Just live without
>recognizing interpretive uses of IF and DO.  But if you want to
>recognize them, do it properly.  STATE-smartness (including ?COMP) is
>both broken and more complicated than not checking at all, i.e., it's
>a lose-lose solution.

I feel that adding interpreted use of IF and DO is much more useful
then other smartness. I use &A instead of CHAR/[CHAR] A
and "AAAP" TYPE instead of ." AAAP" and .( AAAP)
but looking up whether to use CHAR or [CHAR] is an inconvenience
whereas IF and DO I find harder to dispense with.

Maybe I'm just an ISO-heretic. (What would Chuck Moore say?)

>
>- 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/


--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

[toc] | [prev] | [next] | [standalone]


#13049

From"Elizabeth D. Rather" <erather@forth.com>
Date2012-06-18 08:01 -1000
Message-ID<EuWdnZkIe8mJ8ELSnZ2dnUVZ_qednZ2d@supernews.com>
In reply to#13048
On 6/18/12 8:29 AM, Albert van der Horst wrote:
> In article<2012Jun18.153125@mips.complang.tuwien.ac.at>,
...

>> If you don't want to go there, then don't.  Just live without
>> recognizing interpretive uses of IF and DO.  But if you want to
>> recognize them, do it properly.  STATE-smartness (including ?COMP) is
>> both broken and more complicated than not checking at all, i.e., it's
>> a lose-lose solution.
>
> I feel that adding interpreted use of IF and DO is much more useful
> then other smartness. I use&A instead of CHAR/[CHAR] A
> and "AAAP" TYPE instead of ." AAAP" and .( AAAP)
> but looking up whether to use CHAR or [CHAR] is an inconvenience
> whereas IF and DO I find harder to dispense with.
>
> Maybe I'm just an ISO-heretic. (What would Chuck Moore say?)

Chuck Moore would say do whatever the job at hand requires and don't 
bother with nagging nanny compilers.

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]


#13062

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2012-06-19 14:09 +0000
Message-ID<2012Jun19.160944@mips.complang.tuwien.ac.at>
In reply to#13048
Albert van der Horst <albert@spenarnc.xs4all.nl> writes:
>I feel that adding interpreted use of IF and DO is much more useful
>then other smartness.

If you want to add interpretation semantics for IF and DO, then go
ahead.  But don't produce STATE-smart IF and DO; for simple cases they
work as desired, but for more complex cases they sometimes fail.
Instead, if you want that stuff, bite the bullet and implement one of
the schemes for doing that properly.

My feeling, though, is that in the balance it's a bad idea to have
such words.  Not only do you have to implement one of the schemes
above, but you also have repercussions elsewhere (like the meaning of
xts and how to reify the interpretation and compilation semantics).

Your approach of using prefixes appears to be a very good alternative
for the two standard words (S" and TO) that have independent
interpretation and compilation semantics (one might have a prefix like
"->" instead of "TO", i.e., instead of "TO zoing" have "->zoing"); and
also for most other cases where people want such things.  Now you want
to ruin it by complicating IF and DO.  Sigh.

>Maybe I'm just an ISO-heretic. (What would Chuck Moore say?)

Ask him.  However, we can also look at his Forth systems: If he ever
used STATE-smartness, it was a very long time ago.  cmForth (late
1980s) used the separate compilation wordlist wordlist approach, which
could implement independent interpretation and compilation semantics
properly, but AFAIK he did not use it for that (certainly not for IF
and DO).

I am not very familiar with colorForth, but AFAIK it works like this:
you can use colours to execute the word right away (interpretation and
what would be immediate words in a conventional system), compile it,
or postpone it.  But AFAIK IF is a word that you use in a definition
and that you execute right away.

- 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]


#13069

FromAndrew Haley <andrew29@littlepinkcloud.invalid>
Date2012-06-19 10:51 -0500
Message-ID<EYKdnYt80INnAn3SnZ2dnUVZ8h2dnZ2d@supernews.com>
In reply to#13062
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:

> However, we can also look at [Chuck Moore's] Forth systems: If he
> ever used STATE-smartness, it was a very long time ago.  cmForth
> (late 1980s) used the separate compilation wordlist wordlist
> approach, which could implement independent interpretation and
> compilation semantics properly, but AFAIK he did not use it for that
> (certainly not for IF and DO).

cmFORTH did use the wordlists for independent interpretation and
compilation semantics, but indeed not for IF and DO.  There were
compiling versions of a bunch of things, like this:

FORTH : BINARY ( n)   CREATE ,  DOES  R> @  ?CODE @ DUP  
   ... lots ... ;

COMPILER  A840 BINARY +  AA40 BINARY XOR  A640 BINARY OR
          AC40 BINARY -  A240 BINARY AND  A440 BINARY SWAP-

FORTH

... much later ...

: SWAP   SWAP ;   : OVER   OVER ;
: DUP   DUP ;     : DROP   DROP ;
: XOR   XOR ;     : AND   AND ;
: OR   OR ;
: +   + ;         : -   - ;

Andrew.

[toc] | [prev] | [next] | [standalone]


#13072

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2012-06-19 16:04 +0000
Message-ID<2012Jun19.180440@mips.complang.tuwien.ac.at>
In reply to#13069
Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>cmFORTH did use the wordlists for independent interpretation and
>compilation semantics, but indeed not for IF and DO.  There were
>compiling versions of a bunch of things, like this:
>
>FORTH : BINARY ( n)   CREATE ,  DOES  R> @  ?CODE @ DUP  
>   ... lots ... ;
>
>COMPILER  A840 BINARY +  AA40 BINARY XOR  A640 BINARY OR
>          AC40 BINARY -  A240 BINARY AND  A440 BINARY SWAP-
>
>FORTH
>
>... much later ...
>
>: SWAP   SWAP ;   : OVER   OVER ;
>: DUP   DUP ;     : DROP   DROP ;
>: XOR   XOR ;     : AND   AND ;
>: OR   OR ;
>: +   + ;         : -   - ;

That's just an unusual implementation of default compilation
semantics, but it's not really independent interpretation and
compilation semantics.

Which reinforces my conclusion: Even if you have the capability to
implement independent interpretation and compilation semantics, it's
probably better to just have default and compile-only words; and
immediate words, for comments (what does cmForth do for comments?).

- 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]


#13075

FromAndrew Haley <andrew29@littlepinkcloud.invalid>
Date2012-06-19 12:45 -0500
Message-ID<ZeadnXXO7dc0J33SnZ2dnUVZ8iudnZ2d@supernews.com>
In reply to#13072
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
> Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>>cmFORTH did use the wordlists for independent interpretation and
>>compilation semantics, but indeed not for IF and DO.  There were
>>compiling versions of a bunch of things, like this:
>>
>>FORTH : BINARY ( n)   CREATE ,  DOES  R> @  ?CODE @ DUP  
>>   ... lots ... ;
>>
>>COMPILER  A840 BINARY +  AA40 BINARY XOR  A640 BINARY OR
>>          AC40 BINARY -  A240 BINARY AND  A440 BINARY SWAP-
>>
>>FORTH
>>
>>... much later ...
>>
>>: SWAP   SWAP ;   : OVER   OVER ;
>>: DUP   DUP ;     : DROP   DROP ;
>>: XOR   XOR ;     : AND   AND ;
>>: OR   OR ;
>>: +   + ;         : -   - ;
> 
> That's just an unusual implementation of default compilation
> semantics, but it's not really independent interpretation and
> compilation semantics.

I don't understand what you mean.

> Which reinforces my conclusion: Even if you have the capability to
> implement independent interpretation and compilation semantics, it's
> probably better to just have default and compile-only words; and
> immediate words, for comments (what does cmForth do for comments?).

COMPILER : (   29 WORD DROP ;     
FORTH    : (   \ ( ;

\ means [COMPILE]

As you'd expect, surely.

Andrew.

[toc] | [prev] | [next] | [standalone]


#13103

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2012-06-20 10:50 +0000
Message-ID<2012Jun20.125058@mips.complang.tuwien.ac.at>
In reply to#13075
Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>> Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>>>cmFORTH did use the wordlists for independent interpretation and
>>>compilation semantics, but indeed not for IF and DO.  There were
>>>compiling versions of a bunch of things, like this:
>>>
>>>FORTH : BINARY ( n)   CREATE ,  DOES  R> @  ?CODE @ DUP  
>>>   ... lots ... ;
>>>
>>>COMPILER  A840 BINARY +  AA40 BINARY XOR  A640 BINARY OR
>>>          AC40 BINARY -  A240 BINARY AND  A440 BINARY SWAP-
>>>
>>>FORTH
>>>
>>>... much later ...
>>>
>>>: SWAP   SWAP ;   : OVER   OVER ;
>>>: DUP   DUP ;     : DROP   DROP ;
>>>: XOR   XOR ;     : AND   AND ;
>>>: OR   OR ;
>>>: +   + ;         : -   - ;
>> 
>> That's just an unusual implementation of default compilation
>> semantics, but it's not really independent interpretation and
>> compilation semantics.
>
>I don't understand what you mean.

These are normal Forth words (words with default compilation
semantics).  With "independent interpretation and compilation
semantics" I mean things like S", where the interpretation semantics
puts the string in a buffer, and the compilation semantics compiles it
as string literal.

Of course, the separate compilation wordlist is capable of
implementing both, but apparently Chuck Moore chose not to do the
"independent interpretation and compilation semantics" thing.  And
given all the complications that follow from that, I think he was
right.

- 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]


#13106

FromAndrew Haley <andrew29@littlepinkcloud.invalid>
Date2012-06-20 07:10 -0500
Message-ID<1cKdndGs7e46IHzSnZ2dnUVZ7oWdnZ2d@supernews.com>
In reply to#13103
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
> Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>> Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>>>>cmFORTH did use the wordlists for independent interpretation and
>>>>compilation semantics, but indeed not for IF and DO.  There were
>>>>compiling versions of a bunch of things, like this:
>>>>
>>>>FORTH : BINARY ( n)   CREATE ,  DOES  R> @  ?CODE @ DUP  
>>>>   ... lots ... ;
>>>>
>>>>COMPILER  A840 BINARY +  AA40 BINARY XOR  A640 BINARY OR
>>>>          AC40 BINARY -  A240 BINARY AND  A440 BINARY SWAP-
>>>>
>>>>FORTH
>>>>
>>>>... much later ...
>>>>
>>>>: SWAP   SWAP ;   : OVER   OVER ;
>>>>: DUP   DUP ;     : DROP   DROP ;
>>>>: XOR   XOR ;     : AND   AND ;
>>>>: OR   OR ;
>>>>: +   + ;         : -   - ;
>>> 
>>> That's just an unusual implementation of default compilation
>>> semantics, but it's not really independent interpretation and
>>> compilation semantics.
>>
>>I don't understand what you mean.
> 
> These are normal Forth words (words with default compilation
> semantics).

In what sense?  The COMPILER versions lay down instructions, the FORTH
versions call them.  They are different words, with different
semantics, i.e. they do different things.

> With "independent interpretation and compilation semantics" I mean
> things like S", where the interpretation semantics puts the string
> in a buffer, and the compilation semantics compiles it as string
> literal.

How is the above different?  I really don't understand what point
you're making.

Andrew.

[toc] | [prev] | [next] | [standalone]


#13110

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2012-06-20 12:47 +0000
Message-ID<2012Jun20.144747@mips.complang.tuwien.ac.at>
In reply to#13106
Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>> Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>>>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>>> Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>>>>>cmFORTH did use the wordlists for independent interpretation and
>>>>>compilation semantics, but indeed not for IF and DO.  There were
>>>>>compiling versions of a bunch of things, like this:
>>>>>
>>>>>FORTH : BINARY ( n)   CREATE ,  DOES  R> @  ?CODE @ DUP  
>>>>>   ... lots ... ;
>>>>>
>>>>>COMPILER  A840 BINARY +  AA40 BINARY XOR  A640 BINARY OR
>>>>>          AC40 BINARY -  A240 BINARY AND  A440 BINARY SWAP-
>>>>>
>>>>>FORTH
>>>>>
>>>>>... much later ...
>>>>>
>>>>>: SWAP   SWAP ;   : OVER   OVER ;
>>>>>: DUP   DUP ;     : DROP   DROP ;
>>>>>: XOR   XOR ;     : AND   AND ;
>>>>>: OR   OR ;
>>>>>: +   + ;         : -   - ;
>>>> 
>>>> That's just an unusual implementation of default compilation
>>>> semantics, but it's not really independent interpretation and
>>>> compilation semantics.
>>>
>>>I don't understand what you mean.
>> 
>> These are normal Forth words (words with default compilation
>> semantics).
>
>In what sense?  The COMPILER versions lay down instructions, the FORTH
>versions call them.  They are different words, with different
>semantics, i.e. they do different things.

Sure, the default compilation semantics of a normal Forth word are
different from the default interpretation semantics (the default
compilation semantics compiles the execution semantics, the default
interpretation semantics performs it; in a more conventional
implementation the default compilation semantics COMPILE,s the xt of
the word, whereas the default interpretation semantics EXECUTEs the
xt.

The point is that these words implement the default semantics.  +
behaves like a normal Forth word; no immediacy, no other non-default
compilation semantics.  This normality is also reflected in the
definition

: +   + ;

He doesn't define compile-only words like IF or immediate words like (
like this, nor would that work for S" and TO.

>> With "independent interpretation and compilation semantics" I mean
>> things like S", where the interpretation semantics puts the string
>> in a buffer, and the compilation semantics compiles it as string
>> literal.
>
>How is the above different?  I really don't understand what point
>you're making.

The definition of + etc. above is just an unusual *implementation* of
the default semantics.  + behaves as specified in the standard (even
though cmForth does not aspire to being a standard system), and + in
the standard is a normal word (i.e., only default compilation and
interpretation semantics).

One difference is that

: S" S" ;

is not a valid implementation of the interpretation semantics of S".

If I still have not made myself clear: Implementation is not
semantics.  Semantics is what is visible from the outside (black-box
view).  Implementation is how it is done (white-box view).  The same
semantics can (and often does) have several different implementations.
E.g.:

: 2* 2 * ;
: 2* 1 lshift ;
: 2* dup + ;

On a 2s-complement system all these definitions implement the same
semantics (those specified in the standard for 2*).

- 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]


#13083

FromAlbert van der Horst <albert@spenarnc.xs4all.nl>
Date2012-06-19 22:52 +0000
Message-ID<m5vzjq.mtf@spenarnc.xs4all.nl>
In reply to#13062
In article <2012Jun19.160944@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>Albert van der Horst <albert@spenarnc.xs4all.nl> writes:
>>I feel that adding interpreted use of IF and DO is much more useful
>>then other smartness.
>
>If you want to add interpretation semantics for IF and DO, then go
>ahead.  But don't produce STATE-smart IF and DO; for simple cases they
>work as desired, but for more complex cases they sometimes fail.
>Instead, if you want that stuff, bite the bullet and implement one of
>the schemes for doing that properly.
>
>My feeling, though, is that in the balance it's a bad idea to have
>such words.  Not only do you have to implement one of the schemes
>above, but you also have repercussions elsewhere (like the meaning of
>xts and how to reify the interpretation and compilation semantics).
>
>Your approach of using prefixes appears to be a very good alternative
>for the two standard words (S" and TO) that have independent
>interpretation and compilation semantics (one might have a prefix like
>"->" instead of "TO", i.e., instead of "TO zoing" have "->zoing"); and
>also for most other cases where people want such things.  Now you want
>to ruin it by complicating IF and DO.  Sigh.

Remember interpreted-DO is just a loadable extension. I'm going to run
your testpostpone.fs and draw my conclusions. I will add some heavy or
less heavy warnings for those who use it. It is just that my class
extension doesn't work properly without it.

>
>
>- anton

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

[toc] | [prev] | [next] | [standalone]


#13104

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2012-06-20 10:59 +0000
Message-ID<2012Jun20.125943@mips.complang.tuwien.ac.at>
In reply to#13083
Albert van der Horst <albert@spenarnc.xs4all.nl> writes:
[interpretation semantics for DO]

>It is just that my class
>extension doesn't work properly without it.

Why not?  What's so bad about defining a :NONAME word and running it
(maybe with some code-memory management wrapped around that)?
Especially given that you claim that even a simple compile-only flag
(and the check for it in the text interpreter) adds too much
complexity for your taste.

- 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]


#13126 — Defining Compilation Behaviour - was Re: ?EXEC

FromJennyB <jennybrien@googlemail.com>
Date2012-06-21 04:58 -0700
SubjectDefining Compilation Behaviour - was Re: ?EXEC
Message-ID<9a8b70d7-1621-45c0-9d88-dfb1aa30f1a9@googlegroups.com>
In reply to#13062
On Tuesday, 19 June 2012 15:09:44 UTC+1, Anton Ertl  wrote:
> Albert van der Horst <albert@spenarnc.xs4all.nl> writes:
> >I feel that adding interpreted use of IF and DO is much more useful
> >then other smartness.
> 
> If you want to add interpretation semantics for IF and DO, then go
> ahead.  But don't produce STATE-smart IF and DO; for simple cases they
> work as desired, but for more complex cases they sometimes fail.
> Instead, if you want that stuff, bite the bullet and implement one of
> the schemes for doing that properly.
> 
> My feeling, though, is that in the balance it's a bad idea to have
> such words.  Not only do you have to implement one of the schemes
> above, but you also have repercussions elsewhere (like the meaning of
> xts and how to reify the interpretation and compilation semantics).
> 

It may be a bad idea, but it's even worse to have a bad idea, badly executed. Since people insist doing such things, shouldn't there be a clear way of showing their meaning without mixing up interpretation and compilation behaviour in the one definition?

The simplest way I can think of is:

  COMPILES  xt -- set most recent definition to perform xt 
                  at compile-time

IMMEDIATE may (or may not) be defined as LATESTXT COMPILES 

COMPILES may be implemented either by extending FIND when compiling to return the compiling xt and an immediate flag, or by a smart COMPILE, to perform the appropriate action for the given xt. In the latter case, IMMEDIATE should be defined so that immediate words return an immediate flag, but that is mainly of historical interest.  Consider for example this definition of POSTPONE :

  FIND DUP IF  immediate? IF COMPILE, ELSE 
               postpone LITERAL ['] COMPILE, COMPILE, THEN
           ELSE

will still work as expected with a smart compiler if IMMEDIATE is defined as above, whichever flag is returned.

When interpreting, the xt returned by FIND must represent interpretation behaviour, and the flag is irrelevant. When compiling, an immediate flag indicates that the xt represents compiling behaviour, otherwise it represents interpreting behaviour. ' and ['] always return the interpreting behaviour.

There is a simple, portable way to get an xt that represents the compiling behaviour of any particular word:

  : 'COMP  :NONAME POSTPONE POSTPONE  POSTPONE ; ;

STATE-checking words return the appropriate behaviour, but only if the xt returned is finally executed in the appropriate state.
                  

  : THROWS   CREATE , DOES> @ THROW ;

   -14 THROWS COMP-ONLY
   -29 THROWS CAN'T-NEST

  : CODE  interpretation behaviour ; compiles can't-nest
  
  : compDO compilation behaviour of DO ;
  : DO  comp-only ; compiles compDO

  Or, later
   
    'comp DO
    : DO interpretation-version ; compiles 

[toc] | [prev] | [next] | [standalone]


Page 1 of 5  [1] 2 3 4 5  Next page →

Back to top | Article view | comp.lang.forth


csiph-web