Re: The IMMEDIATE mess (Andrew Haley)




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.

.



Relevant Pages

  • Re: CASE...OF
    ... That'd be a reason you can't read the standard. ... Of course yours is a *compiler* word. ... The same trick would work with a classic DTC Forth. ... you'd want to make an immediate ...
    (comp.lang.forth)
  • Re: Is C99 the final C? (some suggestions)
    ... > that someone will try compile their stuff on an old compiler. ... > because the ANSI standard obsoleted them, and everyone picked up the ANSI ... fixed by using another language. ... >>are multiplying two expressions of the widest type supported by your ...
    (comp.lang.c)
  • Re: Statement on Schildt submitted to wikipedia today
    ... to working programmers and more with being "right all the time, ... so that compiler developers could be shed ... The major corporate interests were compiler developers, ... processors, committed to standard division semantics, and otherwise ...
    (comp.lang.c.moderated)
  • Re: #define and (brackets)
    ... Minor compiler vendors are free to join if they are so inclined, ... analysis hasn't changed between the two versions of the standard. ... This bug is a minor bug in an obscure ...
    (microsoft.public.vc.language)
  • Re: interesting use of NEXT SENTENCE vs. CONTINUE
    ... Program name in quotes (allowed in '02 Standard) ... > If J can be made an independent item which the compiler can put wherever it ... > has to be associated with a hardware device in SPECIAL-NAMES. ... > that ALTER *always* modifies the address parameter of the hardware branch ...
    (comp.lang.cobol)