0:00
/
0:00
Transcript

DIY Forth - Forth Haiku Analysis Part 2

2026-02-07

[This is part 2 of a short, ongoing exploration of the 2-stage compilation technique, exemplified by the Forth Haiku code. For part 1 go here.]

In this video, we examine how Forth Haiku generates Javascript code based on (Forth Haiku) forth source code.

Basic Operation

A set of code templates is stored in a dictionary as arrays of strings, each representing a line of JavaScript code.

Forth is based on the concatenative programming paradigm rather than the currently popular functional paradigm. This property makes it particularly easy to concatenate code templates to generate code.

The Forth Haiku source code is parsed into separate words. These words are used to index into the dictionary of code templates. The code strings are then concatenated together to form the final generated code from the first pass.

Numbers, in this case floats, are not stored in the dictionary but are simply emitted as JavaScript code that pushes numbers onto the shared data stack.

The code generated by the first pass, using this concatenative technique, appears verbose and inefficient, but is semantically true to the Forth Haiku source code.

A second pass is used to improve the code.

This video concerns itself only with the first pass.

This code generation technique is straightforward and could be manually implemented using virtually any modern programming language.

In my opinion, a majority of most application code and games could be implemented this way using a simple, lightweight optimization step, leaving heavy optimization for the few parts in an application where it is truly needed.

Slide Deck

Slides Part 2
8.55MB ∙ PDF file
Download
Download

See Also

Email: ptcomputingsimplicity@gmail.com

Substack: paultarvydas.substack.com

Videos: https://www.youtube.com/@programmingsimplicity2980

Discord: https://discord.gg/65YZUh6Jpq

Leanpub: [WIP] https://leanpub.com/u/paul-tarvydas

Twitter: @paul_tarvydas

Bluesky: @paultarvydas.bsky.social

Mastodon: @paultarvydas

(earlier) Blog: guitarvydas.github.io

References: https://guitarvydas.github.io/2024/01/06/References.html

Leave a comment

Share

Discussion about this video

User's avatar

Ready for more?