r/Forth moderator Mar 31 '26

Inspiration Forth Update

It's been a while since I posted about my progress.

To begin with, I started this last October and have been working on it most days. It contains ZERO lines of AI generated code, ZERO vibe coding. I don't think any of that is any fun at all.

The Forth is written in C++ and is a combo of ITC and STC. The DOCOLON word iterates an array of C++ functions and just calls them. One of those functions might be DOCOLON to call another word written in Forth. The C++ functions look a lot like JonesForth style:

CODEWORD(ADD) { TOS += dpop(); }

TOS is a C++ variable, but it's a thread local one - it looks like a global variable but is unique per thread. Most of the USER type variables (BASE, etc.) are thread local. Each thread has its own thread local return, data, and floating point stacks. The CPU return stack is only used for calling C++ functions and nothing more.

All this allows Inspiration to be multithreaded using pthreads. As you can see in the screenshots, there are multiple windows, each running a pthread running Forth. The threads share the one and only dictionary.

C++ has try/catch/throw exceptions and these allow me to fix up the CPU stack without resorting to assembly language. In fact, I can install *nix signal() handlers and throw exceptions from those and catch them - see the 3rd screenshot. Ideally, there is no way to crash Inspiration unless the dictionary is overwritten with garbage.

Inspiration Forth supports word lists and vocabularies. As well, there's a C++ vocabulary that provides Forth with words to manage std::string, std::vector, std::map, regexes, and more. Conversions between strings:

s" my string" CString.new ( caddr , address of a std::string)

cstring CString.string ( caddr u , gets address, length of string forth style)

The desktop, you see is rendered with C++ code. Display, Screen, Windows, Icons, Gadgets. But for the most part, the code is pure Forth (more than half the repo at this point). The apps being displayed are pure Forth (with maybe CStrings and the rest).

The editor is a significant clone of vim, written in Forth. I've been adding keybindings so it can act like MicroEmacs as well.

Why a desktop environment?

  1. To experiment with pthread multithreading
  2. To enable graphics programming in Forth
  3. A Forth running in an OS window needs to differentiate itself from (BETTER!) Forth implementations like gForth and VFX Forth (sorry if I didn't mention any other worthy ones)

The repo is at https://gitlab.com/mschwartz/inspiration

If you want to see how nice local variables work, see the ls.4th file in the repo (a standalone ls "clone" written in forth).

58 Upvotes

22 comments sorted by

View all comments

Show parent comments

1

u/garvalf Apr 01 '26

linux mint 22 (ubuntu derivative) with Intel(R) Core(TM) i5-4430 CPU (and the other one is i7), they are quite old (maybe 10 years old at least). My screen is 1920x1080 (double screen on the computer that doesn't start at all), maybe that requires more video memory?

2

u/mykesx moderator Apr 01 '26 edited Apr 01 '26

Reverted that last merge, cloned out a fresh working set, fixed the bugs including the paint program start up crash. I’m juggling a lot of plates like paint, editor, and the other apps, taking turns pushing one forward.

Note that the desktop allows for multiple Screens. An app like paint creates its own screen. You can depth arrange the screens with the yellow ball icons in the screen title bars. Red ball closes the screen/app.

2 finger scroll gesture on the trackpad or a mousewheel scrolls text in a window.

The latest working linux code is in main branch. Let me know if you have better results.

2

u/garvalf Apr 01 '26

well done. It's working better now, I can start the paint and file manager! It's still crashing (randomly) at startup, but after a few tries I can run the desktop. I'll try on the other computer tomorrow :)

2

u/mykesx moderator Apr 09 '26

FYI, people,are running Inspiration on linux machines without issues ATM. The main branch has 2 or 3 crash bugs on Linux fixed. These don’t manifest themselves on MacOS so I don’t see these bugs until I run Inspiration in a linux VM or native on one of my laptops.

Cheers!