6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu May 09, 2024 4:50 pm

All times are UTC




Post new topic Reply to topic  [ 29 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Sat Feb 25, 2017 7:09 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8432
Location: Southern California
Mike, I've never heard of it. What's the general construction and operation? I have no problem with DO...LOOP & friends; but if can add another tool to the box that I hadn't thought of, why not.

_________________
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: Sat Feb 25, 2017 8:14 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1928
Location: Sacramento, CA, USA
Well, I can't say that I can do them any justice, but Dr. Ting describes them in his eForth literature.
I have some sample code, copied and roughly translated, but untested and not fully understood:
Code:
: COMPILE ( -- ) R> DUP @ , CELL+ >R ; COMPILE-ONLY

: [COMPILE] ( -- \ <string> ) ' , ; IMMEDIATE  \ ??? What's that '\' doing in the stack comment ???

: <MARK ( -- a ) HERE ;

: >MARK ( -- A ) HERE 0 , ;

: <RESOLVE ( a -- ) , ;

: >RESOLVE ( A -- ) <MARK SWAP ! ;

: BEGIN ( -- a ) \ Start an infinite or indefinite loop structure
    <MARK ; IMMEDIATE

: FOR ( -- a ) \ Start a FOR-NEXT loop structure
    COMPILE >R <MARK ; IMMEDIATE

: AHEAD ( -- A ) \ Compile a forward branch instruction
    COMPILE branch >MARK ; IMMEDIATE

: AFT ( a -- a A ) \ Jump to THEN in FOR-AFT-THEN-NEXT loop 1st time through
    DROP [COMPILE] AHEAD [COMPILE] BEGIN SWAP ; IMMEDIATE

: THEN ( A -- ) \ Terminate a conditional branch structure
    >RESOLVE ; IMMEDIATE

: NEXT ( a -- ) \ Terminate a FOR-NEXT loop structure
    COMPILE next <RESOLVE ; IMMEDIATE

In the above, "next" is not the threaded interpreter, but a code word that decrements the index on the return stack and branches until it hits -1, then does an RDROP and proceeds. As I understand it, FOR NEXT is a simplified DO LOOP which counts down to zero by one, and AFT appears to be a clever internal modifier whose usefulness has so far eluded me. Here are a couple of examples of AFT being put to use ... maybe you can help me figure out what they're doing:
Code:
: _TYPE ( b u -- )
    FOR AFT DUP C@ >CHAR EMIT 1 + THEN
    NEXT DROP ;

: .S ( -- )
    CR DEPTH
    FOR AFT R@ PICK . THEN
    NEXT ." <sp" ;


Mike B.


Last edited by barrym95838 on Sun Feb 26, 2017 4:14 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Sat Feb 25, 2017 9:07 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8432
Location: Southern California
It's a mystery to me.

_________________
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: Sat Feb 25, 2017 2:55 pm 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
I read Dr. Ting with great interest and remember seeing FOR, but it's sort of off on its own non-ANSI-branch, so I didn't dig too deep. Gforth (which for me as sort of become the standard implementation, though it's a "maximal Forth" with the kitchen sink thrown in) has FOR and defines it as
Code:
: FOR 
  6394184 compile,  POSTPONE BEGIN drop do-dest ;
latestxt
interpret/compile: FOR  ok
(The address before COMPILE, is a hard-coded xt) and NEXT is
Code:
: NEXT 
  6394104 6394112 loop-like ;
latestxt
interpret/compile: NEXT
with loop-like as
Code:
: loop-like 
  >r >r 0 CS-PICK swap cell - swap 1 CS-ROLL r> r> rot do-dest? until-like  POSTPONE DONE 6394032 compile, ;
which is too much for my brain at the moment. Strangely enough, the Gforth documentation website is down today (https://www.complang.tuwien.ac.at/forth ... Word-Index), we might want to check their explanation once it's running again.

It's annoying that pre-ANSI and ANSI DO-loops have different functionality - the new version never made sense to me - but I've seen a lot of DO/LOOP and no FOR/NEXT in the wild.


Top
 Profile  
Reply with quote  
PostPosted: Sun Feb 26, 2017 7:01 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10800
Location: England
So, a FOR NEXT loop has an optional AFT which modifies the behaviour? Is it perhaps that a normal FOR NEXT is obliged to pass through the body at least once, but with AFT it's possible to loop zero times?


Top
 Profile  
Reply with quote  
PostPosted: Sun Feb 26, 2017 12:39 pm 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
So, Gforth docs are back up. This is what it has to say about FOR/NEXT https://www.complang.tuwien.ac.at/forth ... nted-Loops):
Code:
Another counted loop is:

     n
     FOR
       body
     NEXT
This is the preferred loop of native code compiler writers who are too lazy to optimize ?DO loops properly. This loop structure is not defined in ANS Forth. In Gforth, this loop iterates n+1 times; i produces values starting with n and ending with 0. Other Forth systems may behave differently, even if they support FOR loops. To avoid problems, don't use FOR loops.
Gee, don't hold back, guys ...


Top
 Profile  
Reply with quote  
PostPosted: Sun Feb 26, 2017 4:20 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1928
Location: Sacramento, CA, USA
Ed may be on to something here. I have tried to find examples of definitions where there are words between FOR and AFT or between THEN and NEXT but have come up empty. I have a full day ahead of me, but maybe I'll try to hand-simulate the .S definition above with something like SP! 1 2 3 .S and see what happens with no AFT ... THEN . I would expect the correct response for a properly functioning .S to be:
1 2 3 <sp ok

Mike B.

[Edit: I am not a greedy person! If any of you would like to jump in and rescue me from the detective work, I would be thankful]


Top
 Profile  
Reply with quote  
PostPosted: Sun Feb 26, 2017 7:28 pm 
Offline

Joined: Thu Sep 15, 2016 1:52 pm
Posts: 60
Location: UK
whartung wrote:
Have you tried typing (pasting) that initial transcript back in to see if you duplicated the bug? It's a great transcript, but it doesn't show the entire history of the session that actually had the bug.

I think it would be helpful to see if it replicates from the cold start of the image.

(I assume the "compiled" message are from Tali Forth...)

jgroth wrote:
Cool.
The reason I'm so interested in Tali Forth is that I'm building a 65C02 SBC and I want Tali Forth to be the OS so to speak, if that makes any sense. So the SBC will have a VT100 terminal serial interface, so no graphics, just plain 80x24 text display (the project is called Micromite and the url is http://www.siliconchip.com.au/Issue/2014/July/Micromite%2C+Pt.3%3A+Build+An+ASCII+Video+Display+Terminal) and an IDE interface.
The inspiration for this project is an 80s computer called Jupiter ACE and I wanted to build something similar to that. Tali Forth is the first Forth I've come across that is 6502 based and platform independent and easily ported to an SBC.
Hence my interest in Tali Forth.
Tali needs some extras though like IO words so you can read, write files and directories. Store and load word definitions (not sure how to do that though, but this is early days in the project).


What were you planning to use for the IDE interface? If it's a raw block device, then implementing file support will be more difficult, as you have to implement a filesystem. But I'm pretty sure I've seen interfaces that let you interact with a DOS formatted flash cards using a high level serial protocol (SPI I think?). That, obviously, would be much easier. If you simply have the IDE drive as a block device, then initially you could just use the basic BLOCK I/O provided in early Forths.

Well I do intend to put a file system on the IDE-device (CF cards with an CF->IDE adapter) so I want the Forth system to be file based as well and not block based.
I know Tali Forth doesn't have anything like that yet but shouldn't be impossible to implement, Durexforth for C64 for example is file based. That together with a IDE64 and you got a very nice 8-bit system.
I wanted to build my own computer though.
Perhaps I start with block based system and then implement the file system and add support for that later. There are so many options available :)
The computer for example isn't done yet, still waiting for some parts and after that I need solder everything together.

Will also try to replicate the bug from the very beginning.


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 27, 2017 6:49 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1928
Location: Sacramento, CA, USA
I asked about FOR AFT THEN NEXT on comp.lang.forth, and got at least one instructive response. Here's the thread:

https://groups.google.com/forum/#!topic ... FQlRQHYyPQ

Mike B.


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 27, 2017 6:57 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8432
Location: Southern California
Thankyou for checking. From what I read there, it sounds like it's just as well to leave it alone, ie, not use it.

_________________
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: Mon Feb 27, 2017 10:39 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
barrym95838 wrote:
I asked about FOR AFT THEN NEXT on comp.lang.forth, and got at least one instructive response. Here's the thread:

https://groups.google.com/forum/#!topic ... FQlRQHYyPQ


I like the way that thread went from 0 to 11 on what could have been perhaps better dealt with privately.


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 27, 2017 11:16 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1928
Location: Sacramento, CA, USA
Sheesh, what a nightmare! My apologies to everyone for casually following a search link that was better left untraveled.

Mike B.


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 27, 2017 11:46 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8177
Location: Midwestern USA
barrym95838 wrote:
Sheesh, what a nightmare! My apologies to everyone for casually following a search link that was better left untraveled.

Mike B.

Pugnacious bunch on that forum, eh?

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Tue Feb 28, 2017 5:34 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1928
Location: Sacramento, CA, USA
I am a "blue collar" kind of guy at the core, but I try to adjust my demeanor to suit the surroundings in which I find myself. I have participated in numerous forum activities over the last several years, but (as I sometimes joke with my wife) "being the center of the universe can be a frustrating job at times, especially when others refuse to recognize you as such".

Mike B.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 29 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 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: