r/Forth

My 500 bytes Forth that wants to be fun to read and hack on.
▲ 24 r/Forth+1 crossposts

My 500 bytes Forth that wants to be fun to read and hack on.

(Permalink as of this post.)

I present Nictoforth: a space-and-pedagogy-constrained art Forth. It's carefully crafted to be read top-to-bottom:

  • The repo README sets the stage. Boot sector, serial IO via BIOS.
  • The assembly source is packed with narrative, rationale, and cross-reference. Search for:
    • "[0]" architecture if you want to dig in.
    • "[5]" interpreter, the heart of a Forth.
    • "[7]" the lovely straightforward compiler.
    • "[8]" the extremely wacky bootstrap. It's full of character but damn dense!
  • If you clone the repo you can do make terse | bat -l nasm or | less to cut away all the asides and just read the code.
  • An example demo session log. See it working.

u/s1nical posted their Milliforth fork the other day so I figured why not post mine too. It was lots of fun to write and educational besides!

github.com
u/ekipan85 — 21 hours ago
▲ 19 r/Forth

Inspiration Forth, my view of AI

I was recently accused of using AI to make some of inspiration Forth, which isn’t true. The reason I was accused is that I didn’t completely edit the default README file created by gitlab when I made the repo. The README described what makes for a good README and had headers/sections pre made with instructions on what kind of things to add there. Both github and gitlab have had this sort of thing for years - I have maybe 50 or even 100 repos I made over the years. The README is a template, created by humans. They also have optional templates for issues to force people to add things like steps to reproduce and so on. I didn’t choose to use these.

I cannot stand the use of AI to make code, period. When I was working on the Console logic for Inspiration, it took several feature branches to move it along. The first being to just render individual characters on the screen, then colorized text, then cursor addressing, then (partial) ANSI escape sequence support, then ability to scroll back and view all the text printed to the console. These feature branches weren’t consecutive efforts. It took me a lot of thought to figure out the scroll back logic, and more than one aborted feature branch. So I worked on other things in the meanwhile.

The only time I used AI was a horrifying experience. I asked copilot to make a console with ANSI and scrollback support. It made it in seconds. When I looked at it, I saw someone else’s variable names. Logic that would take me days to get into before even trying to assess if it was even working code. I stopped looking at it after a few seconds. I felt like that code was lifted from someone else, without attribution. None of that code or any of its ideas has anything to do with Inspiration.

The Phred editor is something I worked on in my previous Forth implementations, and once in C++. Made from scratch, but patterned after vim. The Evade2 game is one I made 7 years ago for the company I worked for at the time. Originally in C++, I ported it in Forth to Inspiration.

Inspiration is a different animal as Forths go. It is graphics first, not console first. The concept of how C++ functions can be subroutine threaded is unique. The pthread ability is my own idea and creation. Every code word I made are either mine or from the 2012 Forth Standard.

I have no use for AI. The beauty of a desktop Forth is that my dictionary has thousands of words I already made and debugged to make new things from. And rapidly. I probably get more done in 2 days than I would with AI. It helps that I have been writing code since the early 1970s. I’ll let the features/issue board and over 800 commits to Inspiration speak for themselves.

Beyond this, I think AI slop is garbage and spam. It’s turning works of art into someone else’s trash. GitHub is becoming a landfill. Why GitHub? Because that’s where the chat bots tell people to upload their one day untested creations.

reddit.com
u/mykesx — 2 days ago
▲ 21 r/Forth

Inspiration on Raspberry Pi 4

It took about 2 hours to install a fresh Alpine Linux on the Pi 4, along with my dotfiles, neovim, g++, make, git, and the SDL2 libraries. It took 1-2 minutes, maybe, to compile. I didn’t time it.

I had to remove one CODEWORD so I could eliminate libbsd and it compiled. Ran first time!

What this video shows is performance on the Pi 4. It “feels” 80-90% as fast as on my MBP.

https://gitlab.com/mschwartz/inspiration

u/mykesx — 4 days ago
▲ 15 r/Forth

Most basic primitives for bootstrapping

Hello fellow friends of Forth!

I wondered as I was considering to restart some work on a long and forgotten
Forth interpreter of mine, which basically was incomplete to begin with, what do
people consider the most basic primitives to bootstrap a forth system from scratch?

I can remember, that people did things with `c,`, `,`, so by bit-banging definitions into memory and then starting from there. But also implementing `CREATE`, `:` and `;` or more words to get things off the ground.

Lisp boils often down to other things like to be able to `eval` things and a couple of other 7 primitives I think with which the system then gets off the ground.

So what do you consider to be most basic stuff for bootstrapping Forth systems?

reddit.com
u/aphantasus — 5 days ago
▲ 0 r/Forth

AI prompt for stack balancing

"Treat stack depth and r stack depth like bank accounts and each word in a definition like a financial transaction." After that, gemini (thinking mode) started creating words that actually worked.

reddit.com
u/Niveauverleih — 9 days ago
▲ 20 r/Forth

Another Game Engine Demo for Inspiration Forth

Inspiration's game engine is general purpose. The last update, I posted a 2D x/y scrolling space game with planets you could fly to.

This update, I'm using the same game engine to show this 2.5D FPS type game.

It's not quite ready to beta test, I just thought the game looks neat.

Repo is at https://gitlab.com/mschwartz/inspiration. Tested on Mac and Linux.

ZERO AI used to make any of part of Inspiration or its Forth implementation.

To give you an idea of what the Forth source looks like, here's the entirety of the Bullet logic.

require Games/img/bullet.4ti

private{

2f 2f + 2f + CONSTANT BULLET-ROTATE

: Bullet.Run { me | spr -- , Move Bullet }
    me s@ Process.sprite -> spr
    spr s@ Sprite.rz BULLET-ROTATE + spr s! Sprite.rz
    spr s@ Sprite.z CameraZ - fixed>int 512 > if 
        spr Sprite.Free
        nullptr me s! Process.sprite
        me Process.Suicide
    then
    ;

}private

: Bullet.New { | p spr -- , Fire bullet }
    0 PTYPE-USER Process.New -> p
    ['] Bullet.Run p Process.SetState
    1 p s! Process.timer

    STYPE-PBULLET bullet_img   VectorSprite.New -> spr
    STYPE-ENEMY spr s! Sprite.cmask

    bullet_img 1+ c@ spr s! Sprite.height
    bullet_img c@ spr s! Sprite.width
    bullet_img c@ spr s! Sprite.depth

    spr p s! Process.Sprite
    $ ffff0000 spr s! Sprite.color

    p
    ;

privatize

And this is the player controls logic that handles firing the bullet:

: Player.FireBullet { pf me | p spr -- , fire bullet }
    Bullet.New -> p
    p s@ Process.sprite -> spr


    // alternate bullets fired from left then right
    me s@ Process.user-data 1 and if
        pf s@ Playfield.worldX BULLETDX + spr s! Sprite.x
    else
        pf s@ Playfield.worldX BULLETDX - spr s! Sprite.x
    then
    me s@ Process.user-data 1+ me s! Process.user-data


    CameraY spr s! Sprite.y
    CameraZ 1f + spr s! Sprite.z


    pf s@ Playfield.worldVZ BULLET-VELOCITY + spr s! Sprite.vz


    p GameEngine.Birth
    ;


: Player.Run { me | ch pf p spr -- , Player logic }
    GameEngine.playfield @ -> pf
    KEY_QUIT    Controls.KeyPressed? if Evade2.Quit then
    ascii q     Controls.KeyPressed? if Evade2.Quit then


    KEY_LEFT Controls.KeyDown? if pf me Player.ControlLeft then
    KEY_RIGHT Controls.KeyDown? if pf me Player.ControlRight then
    KEY_UP Controls.keyDown? if pf me Player.ControlUp then
    KEY_DOWN Controls.KeyDown? if pf me Player.ControlDown then
    BL Controls.KeyPressed? if pf me Player.FireBullet then
    KEY_ESC Controls.KeyPressed? if GameOver then


    Player.RenderCrosshairs
    ;
u/mykesx — 8 days ago
▲ 11 r/Forth

BoxLambda: The File System Stack

A new Blog post about BoxLambda OS's File System Stack:

https://epsilon537.github.io/boxlambda/the-file-system-stack/

BoxLambda OS now supports file system access within its Forth environment. A layered stack of Forth modules provides the abstraction required for convenient, shell-level file operations.

https://preview.redd.it/73uveg9fpo0h1.png?width=940&format=png&auto=webp&s=aef81d843b95b6ff555d8828a328bce4829b8793

reddit.com
u/rlysens — 10 days ago
▲ 38 r/Forth

More Inspiration, in progress

I've been working on some game demos. As you can see in the video, I have a good start on a game engine in Forth, with physics and sprite engine and state machine for controls/enemy intelligence.

The video shows a huge universe with 3 sprites, 2 positioned far off screen. The arrow keys apply thrust in the direction. If no key is pressed, friction is applied to bring the speeds to a stop.

The starfield is rendered at 1/2 world velocity for a parallax effect.

I started on this yesterday and this is how far I got by this morning. I wrote only Forth code for this. Downloaded the planet sprites from a free clip art site.

Zero AI assist used in any of Inspiration development.

I can't add photos and video for some reason. I can start another thread if people want to see more.

Or you can look for screenshots in the repo:

https://gitlab.com/mschwartz/inspiration

u/mykesx — 14 days ago
▲ 41 r/Forth

An interesting potential niche for Forth: programming on the move with a chorded keyboard.

This has already mostly been explored in the form of things like M5CardForth and BANDIT but I wanted to add on a potential major reduction of form factor onto that.

If you've never heard of it, a chorded keyboard is a keyboard where combinations of keys are used instead of individual labeled keys. Despite having no labels, it takes just a few hours to memorize the combinations, and despite having fewer keys, the lack of finger travel means accuracy and max typing speeds are much higher. Here's the homemade one pictured, which I believe would have 60 combinations. They can easily be handheld or worn, and used one-handed without looking. If you replaced one or all of the buttons with joysticks like a CharaChorder or added a second chorder for your other hand you could get even crazier.

Chorded keyboards with fewer buttons can be limited in the number of keyboard characters that can be used without introducing double taps or finger travel, but Forth uses very few characters, and the number of characters can be cut down further through use of words. 2 2 + vs 2 2 ADD is a very small change compared to 2 + 2 vs add(2, 2) in other languages. I believe the standard set of characters required for Forth would just barely fit in 60, but would go well over if using Python and maybe over if using BASIC.

I think optimally it would be combined with a pair of glasses with display like ElevenLabs G1 or Brilliant Labs Frame so you don't have to hold something up to your face to see what you're typing, but a little screen is good enough for grinding out a few lines of Forth while taking a shit.

Bubbly may be a good option for trying this out.

u/TooKoolaidForSkool — 14 days ago
▲ 17 r/Forth

Debugging terminal TUI for RISC-V microcontroller forth

I've been working on a forth for RISC-V microcontrollers, and made this special TUI application for debugging. The forth is fully useable with a normal serial comms tool like minicom but this is supposed to augment it's useability with debugging features, sending and parsing the plain-text response from certain forth words in the background.

It first needs to read the startup message from the serial port, then, knowing the microcontroller is present and initialized it sends the "showWords" word which prints the memory contents of all words, which the forth_shell application parses and annotates with what certain pointers point to.

Then when a new word is added it will send "showLastWord" which will print the memory of only the last word created, which is parsed and added to the list. This is imperfect - right now it just detects when an ";" is included in the last line when enter is pressed, but for some instances like "42 const bar" in the video I need to press f5 to manually add the new word.

Eventually I will add the ability to set breakpoints (at least on words in RAM and not flash).

My first attempt at rust, which I still don't understand too well, It's a lot of libraries hacked together that allocate memory all over the place.

youtube.com
u/Jimmy-M-420 — 13 days ago
▲ 22 r/Forth

Notepad clone for Inspiration

I made this Notepad.exe (windows-like) app for Inspiration. It's written in Forth, including the Menu system. It's not 100% complete, but close. The only remaining task is to implement selection and cut/copy/paste. The selection logic is in progress, but you can see what it's going to look like.

It does feature undo/redo.

Time spent making this app was about 2 days.

No AI ever used to make any of Inspiration. None ever will.

The License is MIT Non-AI

The repo:

https://gitlab.com/mschwartz/inspiration

u/mykesx — 13 days ago