Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"cell+" and "[include]" words, "hello world" example #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

cstrotm
Copy link

@cstrotm cstrotm commented Feb 26, 2017

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

@piotr-wiszowaty
Copy link
Owner

Thanks!

Some remarks:

  1. 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
  1. In core.foc chout and getkey routines can be moved to the ends of the respective words - simpler code & less bytes.

  2. 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.

  3. Please use imperative present tense in commit messages.

  4. Waiting for english comments in hello.foc.

  • Piotr

@cstrotm
Copy link
Author

cstrotm commented Feb 27, 2017

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

@cstrotm
Copy link
Author

cstrotm commented Feb 28, 2017

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)?

@cstrotm
Copy link
Author

cstrotm commented Feb 28, 2017

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

@piotr-wiszowaty
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants