Development Environment for Forth?

I believe that Forth like any other programming language benefits from a well organised project development environment.

This article is a work in progress because although my own forth development environment is mostly finished and does pretty much what I want, it’s going to take a while to describe it here.

A Forth Project Build Script With Libraries

Exerpt from a post made by Julian Foundran (Nov2017) in comp.lang.forth which makes a lot of sense to me.

My point is just that if you care about Forth having a library platform, that you shouldn't worry too much about the technical requirements of the old loose-leaf library systems. A much more popular target today is, at a unix prompt:

 * $ forthbuild new my-cool-app
 * $ cd my-cool-app
 * $ forthbuild install a-long list-of libraries
 * $ vi my-app.fs

Which creates a workspace and then populates it with some libraries that are unique to that workspace.

Those libraries might be, as in , right under my-cool-app/forth-packages/

Essential Features

This is a list of all the attributes I consider essential in any development environment, not just Forth

FAST project creation

When I start a new project, I create its directory then run a project builder shell script. The new project directory will then be populated with the sub-directories, templates, shell scripts and files, I typically use in all my projects. The scriopt is finished 0.3 seconds later and I can begin coding.

  • Code Versioning System: set up and running, with the initial project files already committed. I use Fossil for this.
  • Schematic Capture: with a various templates ready for me to begin testing and documenting. Usually I start with a STM32F0 Discovery Board, so that’s my main schematic template. gEDA is what I use.
  • Directories: ready to receive files as I create them, i.e. pdf, flowchart, pics, text, misc
  • A library symlink to my versioned STM32F Mecrisp-Stellaris library so I can pull them in as needed
  • Sphinx Documentation system: (Sphinx is used to create this site) ready to start adding documents.
  • e4thcom Serial Terminal: which automatically opens in the new project directory.
  • Editor: which will open with several files, pre-created and pre-named by the project builder shell script. I use Gvim.
  • Svd2forth files to suit the MCU. These are used to generate Memory Mapped Register words, preloaded before the actual project files and controlled by a Makefile.
  • Finally, a shell script that will remove every project file, the Fossil repository and finally the project directory itself. This has a “are you sure” confirmation before proceeding. Once a project is underway and I’m happy with it, I may manually delete the shell script just to be on the safe side. It’s saved in the Fossil Code Repo anyway if I need it later.

The project builder shell script also refuses to dump all these files into a non-empty directory.

Project Builder Shell Script

Not quite ready for release yet, and it may never be as it’s tailored for my use, which is bound to be quite different to what you want. In any event, it’s not hard to do this with a SH script and make exactly what you want. My SH script that does this is only 173 lines of code.


I create a directory and type ‘forthme’ in it and 0.3 of a second later, the directory looks like the test-project directory listing below.

That 0.3 seconds includes populating the new project directory and versioning it. All the files have the directory name (the project name) and they’re all added to Fossil and commited before I enter a line of code. In fact it’s all done before my heart has had time for one beat.

I can now start typing Forth code into a automagically opened terminal onto the actual hardware I’ll be using and editing the project templates to suit. This includes the memory mapped Forth Register words for the MCU, a Schematic Diagram, possibly a Sphinx Ebook for the product.

Because it’s versioned with Fossil, I can generate a release Tarball instantly via the Fossil project webpage as shown in this picture.


It’s all done with one SH script, no Java, no Eclipse, no delay.

Test-Project Directory Listing

test-project% tree -a
|-- .README-test-project.txt.swp
|-- .fossil-settings
|   |-- binary-glob
|   |-- crnl-glob
|   |-- ignore-glob
|   `--
|-- .fslckout
|-- Makefile
|-- README-test-project.txt
|-- STM32F051K8.txt
|-- STM32F0xx.svd
|-- STM32F0xx.svd.uf.svd
|-- edit-README-test-project.txt
|-- edit-test-project.fs
|-- edit-test-project.preload.fs
|-- f051-legends.fs
|-- flowcharts
|-- gafrc
|-- lib -> /home/tp/projects/programming-languages/forth/mecrisp-stellaris/library
|-- memmap.fs
|-- misc-files
|-- mk.template.xsl
|-- pdf
|-- pics
|-- register-reference.fs
|-- registers.xsl
|-- schematics
|   `-- test-project.sch
|-- sphinx
|-- svdcutter.xsl
|-- svduf.xsl
|-- template.xml
|-- test-project.fs
|-- test-project.preload.fs
|-- test-project.txt
|-- text


A similar technique is used with CrystalScad

CrystalSCAD comes with a generator that generates project stubs automatically for you. Run this command from a terminal in the directory that you want to create a project: # crystalgen new [my_project_name]

Change [my_project_name] to the name of your project

A project named “my_project” will create those files and directories:

my_project/my_project.rb - the controller
my_project/lib/assemblies - for putting together assemblies of individual parts
my_project/lib/electronics - put electronics here
my_project/lib/hardware - put hardware parts in here
my_project/lib/printed - put parts that you want to print in here
my_project/lib/lasercut - put sheets that need to be cut (by laser or other) in here
my_project/lib/assemblies/my_project_assembly.rb - dummy assembly
my_project/lib/printed/testcube.rb - dummy printed part
my_project/my_project.observr - observer file

Open up the controller (here my_project/my_project.rb ) in the text editor of your choice. It contains the information on how to start the observer.