foco65
foco65 copied to clipboard
"cell+" and "[include]" words, "hello world" example
Hi Piotr,
thanks for making FOCO65 available.
I've written an article about FOCO65 for the upcoming ABBUC Magazine. After writing the article, I wanted to improve a little on FOCO65. I've changed "cell" (which was the same function as "cells" == 2 *) to "cell+" which is implemented as "2 +". This is in compliance with the latest Forth 200x standards.
I've also implemented a simple "include" word that can be used to include other source files. It can be used to split FOCO65 source into multiple files, and to create a "standard library" of common or standard Forth words.
The "hello world" example still has German comments, I will change that in the next days.
Greetings
Carsten
Thanks!
Some remarks:
- Could you add filename & line number tracking when including files? Without it almost all error messages will contain incorrect line number when
[include]is used. E.g.:
$ cat -n test1.fth
1 [text-section] init
2
3 [code]
4 org $2000
5 [end-code]
6
7 [text-section] text
8
9 [include] "lib/core.foc"
10
11 : main
12 i-dont-exist
13 dos
14 ;
15
16 [code]
17 run boot
18 [end-code]
19
$ ./foco65 test1.fth
error: unknown word 'i-dont-exist' at line 73 column 3
-
In
core.focchoutandgetkeyroutines can be moved to the ends of the respective words - simpler code & less bytes. -
Could you change the formatting to be uniform and consistent with the original? See https://git-scm.com/book/gr/v2/Distributed-Git-Contributing-to-a-Project.
-
Please use imperative present tense in commit messages.
-
Waiting for english comments in
hello.foc.
- Piotr
Hello Piotr,
all valid points.
As for 1: I've missed this, good error messages are important. I will need to think about a good solution and will post my idea here before implementing to get your feedback.
As for 2: Yes, there is room for optimization. The current implementation was driven by the publishing deadline for the magazine.
As for 3: Sure, I'll look into it.
As for 4: OK
As for 5: I'm pretty much a weekend coder these days, I will need some time to find free time.
Thanks for your comments.
Carsten
I've worked on 5, hello.foc and lib/core.foc now have all comments in english.
is using ".foc" as the extension for FOCO65 source code OK, or should I use ".f" or ".fth" or ".4th" or ".fs" (more traditional filename extensions for Forth source)?
Hello Piotr,
here is my initial idea on how to support line numbers in error messages with the "include" feature
-
augment the class "Input" with a String variable "filename" which contains the path/filename of the file containing the source text being parsed
-
replace the [include] statement while reading the source in with a new token [include-start:filename] and [include-end:filename]
-
create a stack for Input objects
-
while parsing the source, [include-start:filename] will cause the current "Input" object to be pushed on the stack and a new input object to be created and attached to parse_input
-
while parsing the source, [include-end:filename] will cause the current "Input" object to be discarded and the topmost object on the Input-Stack will be taken from the stack and re-assigned the current Input object
Does this sound reasonable?
Best regards
Carsten
It does seem reasonable - please give it a try.
As for the source file extensions - ".forth", ".fth" and ".4th" are fine.
Some further improvements in comments: s/start address of program/program start address/, s/the printable text/printable text/, s/Hauptprogramm/main program/ (?), s/set the RUNVEC to start program/set RUNVEC to program start/, s/naechstes Forth-Wort/next Forth word/.
- Piotr