6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 10:22 am

All times are UTC




Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: Thu Dec 02, 2021 12:32 am 
Offline

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

The general idea is to place the string ';COMMENT' in the editors find buffer and use SEEK , a component of F , the editor find word, to seek to that point. It would then copy the editors edit pointer R# to >IN
It should work like this:
Code:
0: // TEST OF COMMENT:
1: : SOMEWORD
2:    <SOME FORTH STUFF>  COMMENT:  THIS IS THE START OF A MULTI-LINE COMMENT
3: AND IT CONTINUES TO THIS LINE
4: AND THIS ONE
5: AND EVEN THIS ONE ;COMMENT
6:    <REST OF DEFINITION> ;
7:




I had not given this further thought as something had come up. I was just fleshing out an idea here.
Using SEEK from the editor vocabulary is not the best way to go. Using MATCH is the way to go. MATCH takes the address and length of a string, the main string, and the address and length of a sub-string to find in the main string. The non-standard word 'STREAM , address of stream, will provide the main string. This word returns the address of the current position in the text stream and the length of the stream remaining. It can be defined in Ans Forth like this:
Code:
: 'STREAM  ( ADR CNT -- )
   SOURCE >IN @ /STRING ;

Here is the definition for COMMENT:
Code:
: COMMENT:  ( -- )
   'STREAM " ;COMMENT" COUNT MATCH
   0= ABORT" NO ;COMMENT"
   >IN +! ; IMMEDIATE

and what it compiles to:
Code:
SEE COMMENT:
COMMENT: IMMEDIATE
 31486  6915 'STREAM
 31488  6746 (") ;COMMENT
 31499  5139 COUNT
 31501 13960 MATCH
 31503  4348 0=
 31505  7734 (ABORT") NO ;COMMENT
 31519  2113 >IN
 31521  4859 +!
 31523  2930 EXIT
39
 OK

The word " , when compiling, will compile the word (") and an inline counted string. If the string ';COMMENT' is not found, COMMENT: aborts with an error message. If the string is found, the text position pointer, >IN is adjusted to point to the first character after the string.
Note that ';COMMENT' does not need to be defined. It is just a text string to be sought.
Here is an example of using COMMENT:
Code:
// TEST OF MULTI LINE COMMENTS
: POINTLESS
   CR .S
COMMENT:
   THIS DEFINITION IS, AS IT'S NAME
   INDICATES, QUITE POINTLESS.
   IT ONLY EXISTS TO DEMONSTRATE
   MULTI LINE COMMENTS.
;COMMENT
   CR .AS ;

and what POINTLESS compiles to:
Code:
SEE POINTLESS
POINTLESS
 31558  7024 CR
 31560 16278 .S
 31562  7024 CR
 31564 16349 .AS
 31566  2930 EXIT
10
 OK

I said that ';COMMENT' did not need to be defined. It can be defined as a no-op for convenience. Here is an example of a multi-line comment keeping a word from being defined.
Code:
SCR# 8473  2 281
0: // ANOTHER MULTI LINE COMMENT TEST
1: // COMMENT OUT THE FOLLOWING WORD
2: COMMENT:
3: CODE NUTATE  ( N1 N2 N3 -- N3 N2 N1 )
4:    0 ,X LDA  4 ,X LDY
5:    0 ,X STY  4 ,X STA
6:    1 ,X LDA  5 ,X LDY
7:    1 ,X STY  5 ,X STA
8:    NEXT JMP  END-CODE
9: ;COMMENT
A:
B:
C:
D:
E:
F:

Suppose I want to compile NUTATE and test it. Since I defined the word ;COMMENT as a no-op and Fleet Forth has LINELOAD , I can.
Code:
0 FH LOAD  OK
LATEST ID. POINTLESS OK
3 0 FH LINELOAD  OK
LATEST ID. NUTATE OK

3 0 FH LINELOAD begins loading the current screen at line 3. This skips over COMMENT: .

IamRob wrote:
I don't know if that would work, as how would the interpreter know if ;COMMENT itself is not part of the comment, since commented words are skipped over and not interpreted.


The string ';COMMENT' is not interpreted. The interpreter does not care because the interpreter takes no part in this except for finding and executing the immediate word COMMENT: . It is COMMENT: which searches for the string ';COMMENT' in the text stream and repositions the text stream pointer >IN . After COMMENT: executes, the interpreter resumes with the current position in the text stream pointing just past the string ';COMMENT' . Any string could have been used. I could have made the search string 'MANTICORE' in the definition of COMMENT: and that is the string it would have used for the end of a multi-line comment.

Quote:
How about this instead. The same as the parenthesis works, the interpreter searches for the ending parenthesis to signal the end of a comment, one can use the backslash or dbl-forward-slash to signify the end of the comment as well. But there would be no need to use an ending back-slash as that is the same as using the parenthesis.


In the Forth-83 standard, and possibly others, the words which parse the text stream take a single ASCII character as a delimiter. WORD usually takes a blank (ASCII code $20), the word " takes the ASCII character " , and the words ( and .( take the ASCII character ) for their delimiters.
If you are going to use more than one character for your delimiter, that still involves a string search.

Quote:
Some computers have the ability to use the backslash character, so a backslash can signify to ignore all text to the end of the line and a dbl-forward-slash can signify to ignore all comments until another dbl-forward-slash is encountered, even across multiple lines.


Some computers, but not all. My Fleet Forth for the Commodore 64 is not the only Forth for the Commodore 64 to use the double forward slash // for end of line comments. Scott Ballantyne's Blazin' Forth for the Commodore 64 released in 1985 also used the double forward slash for an end of line comment.
Since the double forward slash is used in some Forths as an alias for the backslash, how about using a different double character for multi-line comments, such as the double carat '^^'?
Having said that, I think that having the same token for the start of a multi-line comment as the end of a multi-line comment is problematic. They are not visually distinct. If there is only one multi-line comment in a screen, this would not be a problem. With the possibility of larger screens (32 lines? maybe more?) there is the possibility of more than one multi-line comment. If the same tokens were used for multi-line comments in source in plain old text files, the problem could be worse. There would be no block boundaries and the file size could be large enough that there may be several multi-line comments.


Top
 Profile  
Reply with quote  
PostPosted: Tue Dec 07, 2021 12:57 am 
Offline

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

I should mention two caveats with my definition for COMMENT: .
Although Fleet Forth is case insensitive, that only applies to the interpreter. String handling words, such as MATCH are case sensitive. The case used when the string ';COMMENT' is compiled into COMMENT: needs to be used when using ';COMMENT' to mark the end of a multi-line comment.
Fleet Forth's MATCH returns the flag on top of the offset. The version of MATCH from the fig-FORTH Installation Manual returns the offset on top.


Top
 Profile  
Reply with quote  
PostPosted: Sat Feb 26, 2022 8:46 am 
Offline

Joined: Wed Aug 21, 2019 6:10 pm
Posts: 217
One approach used for extensive comments are shadow blocks. A shadow screen is based on a set of blocks for source and an equal number for comments, so that a single offset value allows you to "flip" between the source and the shadow block. In the day, this would often be tied to a function key, where the block display function would have the offset built in and the function key would XOR the value of the offset with the stored value, so toggle between an offset of 0 and the shadow screen offset.

A useful word in that context is \\ which is "end of source in file" when interpreting a file, and and "end of source in block" when interpreting a block. Starting the index line of a shadow block with \\ rather than \ (or in a C64th, /// rather than //) ensures that the comments are never accidentally interpreted.

When I was working on the "no function key text file editor" BMW (Bruce McFarling's Writer), I would put the \\ at the start of a decorative line:

\\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //

... where everything but the first pair of character is just decoration, since the \\ ends interpretation of the file.

I very much like the 64 character wide block versus a 128 character or (to fit a C64 display) a 40 or 32 character wide block, and adopted 63 character plus a return key as the width of my text files, for easier porting of individual sets of words to blocks if need be. As far as the "problem" of losing useful space when indenting, I would indent by three spaces, which worked for me.

However, my C64 Forth back in the day used 40 wide blocks, and for 64 wide blocks, I would want a bitmapped text display with a 5 bit wide font.

However, I could see using a 32 character wide block in a context where of using a small enough LCD display for a target board that 32x8 is substantially easier to read than anything more ... to avoid left-write scrolling. If you use the bottom line for entering commands, scroll up at the second line except when at the top of the block, and down at the sixth line except when at the bottom of the block, it is reasonably easy to have a feel for where you are in the block, and the command prompt can be X> where "X" is the base 32 of the row number.


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 01, 2022 12:40 am 
Offline

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

My Forth for the Commodore 64, Fleet Forth, uses the traditional source screen formatting of 64 characters per line and 16 lines. This is mostly for compatibility with other Forths for the C64 which have source in screens.
As for shadow screens, With the 1541 drive I have 166 blocks available ( counting block zero). With a dual disk unit compatible with the 1541, I have 332 blocks available. With the 1571 drive in double sided mode, I also have 332 blocks available. If there is a dual disk unit compatible with the 1571, I would have 664 blocks available. Fleet Forth also has support for blocks in a 1581 drive with 799 blocks available. What should the offset for shadow screens be?
Each drive is allotted 4096 blocks because the different C64 drives have different capacities, so I could make the offset for shadow screens 4096 ( $1000) but then how would I copy blocks from one drive to another if one drive is for source screens and another is for shadow screens?
One more thing to consider is Fleet Forth has the capability to load source from screens in blocks with LOAD and friends; however, it also has the ability to load source from C64 sequential files ( C64 version of text files) with INCLUDE . I do not mean blocks in a source file. I mean plain free formatted source in a sequential file where each line is stored in the file with a terminating carriage return character.
I wrote // (double slash, Fleet Forth's name for \ (backslash)) so that when used in a screen it increments >IN to a the next higher multiple of 64; however, when interpreting from the text input buffer or evaluating a string it increments >IN to the end of the text stream. Since Fleet Forth loads a sequential file one line at a time, this allows // to skip to the end of a line.
Likewise, COMMENT: and ;COMMENT work equally well when loading screens or loading source from a sequential file.


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 02, 2022 12:13 am 
Offline

Joined: Wed Aug 21, 2019 6:10 pm
Posts: 217
JimBoyd wrote:
[color=#000000] ...
As for shadow screens, With the 1541 drive I have 166 blocks available ( counting block zero). With a dual disk unit compatible with the 1541, I have 332 blocks available. With the 1571 drive in double sided mode, I also have 332 blocks available. If there is a dual disk unit compatible with the 1571, I would have 664 blocks available. Fleet Forth also has support for blocks in a 1581 drive with 799 blocks available. What should the offset for shadow screens be?


In that context, if I was using shadow screens, I would have a load screen that loads the offset into a variable. However, IIRC, shadow screens really became popular when hard drives and their "massive" 10MB or 20MB capacity came into use ... IOW, my guess is they tended to be from a slightly later vintage than the pure floppy disk based systems. I am not sure I would try them with anything smaller than a 1581 (or SD2IEC with 1581 images), so I'd go with an offset of 400.

Quote:
One more thing to consider is Fleet Forth has the capability to load source from screens in blocks with LOAD and friends; however, it also has the ability to load source from C64 sequential files ( C64 version of text files) with INCLUDE . I do not mean blocks in a source file. I mean plain free formatted source in a sequential file where each line is stored in the file with a terminating carriage return character. ...


Yes, that is also an objective of xForth ... indeed, until I got so busy with the new job, I was planning to tackle the INCLUDE system first.

But I do now intend to have // as a synonym of \ and /// as a synonym of \\


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 25, 2022 1:19 am 
Offline

Joined: Mon Jun 24, 2019 1:13 pm
Posts: 34
I've have been reading some of these posts and found some of the comments interesting as I had written a screen editor a couple of years ago that used the ANSI terminal. More recently however I enhanced it greatly to allow full ANSI key operation, highlighting, and multiple file tabs etc. At present this version operates with my Tachyon extensions including the filesystem running on top of Mecrisp on the RP2040 chip. I am using this editor to develop a full suite of dev tools to run on any Forth system that has maybe about 8k of RAM or more (the RP2040 has 264kB internally). Power to the Forth!

The editor has become more of an IDE since I can compile and run code and invoke the logic analyzer module etc. I still need to finish a multipass macroassembler which will produce a clean and flat listing and output file. While this is geared for the RP2040 I see no reason why I can't backport it to some of my older 65xx systems including the M37702 etc where I had lots of RAM.

BTW, rather than raw blocks, I handle a standard FAT32 file in pages of 32 lines of 128 characters and terminate each line with a CR. This makes the file compatible with PC text editors but makes it possible to edit the file in 4k pages although the page length can be adjusted up to 64 lines. The clipboard is in RAM but I may make it hybrid with a file to allow for systems to use less RAM. ^F10 will compile code from the clipboard or if empty then from the current page rather than F10 which compiles the whole file. A null terminator(s) marks the logical end of a file.

Normally I use VScode but I am loving the ease of use of this editor with intuitive controls. Plug my board in, type ED and it restores the last multi-tab session complete with cursor position and theme etc.


Attachments:
HELP.TXT [9.46 KiB]
Downloaded 62 times
FRED 2022-07-25 10-21-13.png
FRED 2022-07-25 10-21-13.png [ 194.86 KiB | Viewed 6472 times ]
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC


Who is online

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