Re: The IMMEDIATE mess (Andrew Haley)
- From: "J Thomas" <jethomas5@xxxxxxxxx>
- Date: 29 Aug 2006 07:12:48 -0700
Tessa Celine Bonting wrote:
I'm wondering if there is still anabody who know that there
is a comment on using STATE in the "old'' ANS.
It say's don't change the value of STATE.
Yes. The idea is that the system might not be using STATE to determine
whether it's interpreting or compiling. You can *read* STATE to find
out, but it isn't clear what happens if you write to STATE .
So one way to write an interpreter involves (written crudely and
quickly)
..... BL WORD FIND DUP -1 = STATE @ AND IF DROP COMPILE, ELSE ....
Change STATE and it changes the behavior.
Another way is
DEFER HANDLE-WORD
: ]
['] COMPILE-BEHAVIOR IS HANDLE-WORD
TRUE STATE ! ;
: [
['] INTERPRET-BEHAVIOR IS HANDLE-WORD
FALSE STATE ! ; IMMEDIATE
..... BL WORD FIND DUP IF HANDLE-WORD ELSE ....
STATE tells you whether you're compiling or not. But if you change
STATE yourself it doesn't actually change the state, it only makes
STATE lie to you.
They avoided that problem with SOURCE . Instead of paying attention to
TIB and #TIB and changing the input buffer at any time by writing those
variables, you can change the input buffer by doing LOAD or INCLUDED or
EVALUATE . You can make your own input buffer and ACCEPT into it and
then EVALUATE the contents. But you can't write into SOURCE . SOURCE
might be a double variable, or it might be a colon definition that
returns two values, or whatever. They didn't have to say it was
read-only.
So why is IMMIDATE so importend that it ceeps on popping up so many times?
IMMEDIATE gives the only standard way to extend the compiler. If we got
rid of IMMEDIATE then standard code would all have to be written
roughly the same way. No new control structures. No new parsing words,
except for new defining words and others that can be done while
interpreting.
But IMMEDIATE is a blunt tool. Lots of things people would like to do
to extend the compiler are hard to do in standard ways. If you just
want to get your work done and don't care about extending the compiler
then it doesn't matter. But we have long involved tricky arguments
about the problems we run into extending the compiler, because it's
something we want to be able to do and it's hard to do portably.
It's possible that some minor changes would make that much easier. Then
we could enjoy ourselves extending the compiler in wonderful new ways
and arguing which of them are worth doing, instead of arguing about
whether the standard is worth having and why our inspirations aren't
portable.
.
- Prev by Date: Re: The IMMEDIATE mess
- Next by Date: Re: The IMMEDIATE mess
- Previous by thread: RfD - 2VALUE
- Next by thread: RfD: Front Matter (long)
- Index(es):
Relevant Pages
|