6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 12:08 am

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Thu Dec 17, 2020 6:40 pm 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
I am a little baffled by how IMMEDIATE works.

My understanding is that when a new word is created, and any word that is marked as IMMEDIATE will automatically execute during compiling.

Here is an example of my expectation of what IMMEDIATE should do.

: INVERSE F EMIT ; IMMEDIATE
: TEST INVERSE ;
OK

When TEST is being compiled, INVERSE should be executed and therefore OK should be printed in inverse text. But it doesn't.

Typing F EMIT at the prompt will put OK in inverse.


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 17, 2020 9:11 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
Should work. If you use SEE to view what got compiled in TEST, it should look like a do-nothing word, because F EMIT was executed rather than compiled.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 18, 2020 12:15 am 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895

I noticed in your example that OK is on the next line. I don't know about the Apple but on the C64 a carriage return clears the reverse video.


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 18, 2020 3:22 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
GARTHWILSON wrote:
Should work. If you use SEE to view what got compiled in TEST, it should look like a do-nothing word, because F EMIT was executed rather than compiled.


I am using an ITC Forth.
The indirect link for INVERSE got compiled. If I run TEST then it works and OK is in inverse.


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 18, 2020 3:29 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
JimBoyd wrote:

I noticed in your example that OK is on the next line. I don't know about the Apple but on the C64 a carriage return clears the reverse video.


INVERSE stays on till it gets turned off with E EMIT which is the description for NORMAL.

: TEST INVERSE ." Hello World" NORMAL ;
OK


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 18, 2020 4:13 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
IamRob wrote:
GARTHWILSON wrote:
Should work. If you use SEE to view what got compiled in TEST, it should look like a do-nothing word, because F EMIT was executed rather than compiled.

I am using an ITC Forth.
The indirect link for INVERSE got compiled. If I run TEST then it works and OK is in inverse.

So it sounds like COMPILER, which is called by INTERPRET if STATE is ON, is not looking up and responding to the IMMEDIATE bit in the header correctly. (It may be a bit different in your ITC Forth, but the result should be the same.)

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 18, 2020 5:49 pm 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
Quote:
So it sounds like COMPILER, which is called by INTERPRET if STATE is ON, is not looking up and responding to the IMMEDIATE bit in the header correctly. (It may be a bit different in your ITC Forth, but the result should be the same.)[/color]


Ok. got it figured out.


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 18, 2020 9:58 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895
GARTHWILSON wrote:

So it sounds like COMPILER, which is called by INTERPRET if STATE is ON, is not looking up and responding to the IMMEDIATE bit in the header correctly. (It may be a bit different in your ITC Forth, but the result should be the same.)


Fleet Forth's INTERPRET does not check the header, (FIND) does. (FIND) returns a tri-state flag. true (-1) if found and not immediate, one if immediate, and zero if not found. State is either TRUE (-1) or FALSE (0).
The only test INTERPRET does if it determines that a word is found is the following:
Code:
         STATE @ =
         IF
            ,
         ELSE
            EXECUTE
            ?STACK
         THEN



Top
 Profile  
Reply with quote  
PostPosted: Sat Dec 19, 2020 12:57 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
Quote:
The only test INTERPRET does if it determines that a word is found is the following:
Code:
         STATE @ =
         IF
            ,
         ELSE
            EXECUTE
            ?STACK
         THEN

[/color]

The FIG interpreter has this for INTERPRET which checks the current STATE against a word's STATE. (which is part of the word length byte)

: INTERPRET -FIND IF STATE @ < IF CFA , ELSE CFA EXECUTE THEN ?STACK ELSE HERE NUMBER DPL @ 1+ IF [COMPILE] DLITERAL ELSE DROP [COMPILE] LITERAL THEN ?STACK THEN AGAIN ;

-FIND, when it finds a word, returns with the length byte, which also includes the IMMEDIATE bit and SMUDGE bit. The current STATE is set at $C0 and compared with the word length byte. A word's length byte has the hi-bit set for TRAVERSE, so the length byte will be at least $C0 plus the word length for an IMMEDIATE word (always > $C0). This is when the CFA EXECUTE happens in INTERPRET.


Top
 Profile  
Reply with quote  
PostPosted: Sat Dec 19, 2020 10:02 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895
IamRob wrote:
Quote:
The only test INTERPRET does if it determines that a word is found is the following:
Code:
         STATE @ =
         IF
            ,
         ELSE
            EXECUTE
            ?STACK
         THEN


The FIG interpreter has this for INTERPRET which checks the current STATE against a word's STATE. (which is part of the word length byte)

: INTERPRET -FIND IF STATE @ < IF CFA , ELSE CFA EXECUTE THEN ?STACK ELSE HERE NUMBER DPL @ 1+ IF [COMPILE] DLITERAL ELSE DROP [COMPILE] LITERAL THEN ?STACK THEN AGAIN ;

-FIND, when it finds a word, returns with the length byte, which also includes the IMMEDIATE bit and SMUDGE bit. The current STATE is set at $C0 and compared with the word length byte. A word's length byte has the hi-bit set for TRAVERSE, so the length byte will be at least $C0 plus the word length for an IMMEDIATE word (always > $C0). This is when the CFA EXECUTE happens in INTERPRET.


The first Forth I used was 64Forth for the C64 which was a superset of FIG Forth. Fleet Forth is a Forth-83 Standard Forth. The Forth-83 standard does things a little differently. Rather than -FIND there is FIND . FIND takes the address of a counted string and returns the tri-state flag I already mentioned.


Top
 Profile  
Reply with quote  
PostPosted: Sun Dec 20, 2020 8:46 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895

To be clear, the Forth-83 word FIND returns two items. Here is the stack effect for each type of result.
Code:
ADDR -- CFA  1   \ FOUND AND IMMEDIATE
ADDR -- CFA -1   \ FOUND AND NOT IMMEDIATE
ADDR -- ADDR 0   \ NOT FOUND



Top
 Profile  
Reply with quote  
PostPosted: Mon Dec 21, 2020 5:32 pm 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
JimBoyd wrote:

To be clear, the Forth-83 word FIND returns two items. Here is the stack effect for each type of result.
Code:
ADDR -- CFA  1   \ FOUND AND IMMEDIATE
ADDR -- CFA -1   \ FOUND AND NOT IMMEDIATE
ADDR -- ADDR 0   \ NOT FOUND

I will have to keep track of how often -FIND is called when disassembling ProForth to see if it can benefit from this method. It definitely has possibilities, especially if it gets called often.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: