Skip to content

Forth#2947

Open
luginf wants to merge 26 commits into
nesbox:mainfrom
luginf:forth
Open

Forth#2947
luginf wants to merge 26 commits into
nesbox:mainfrom
luginf:forth

Conversation

@luginf

@luginf luginf commented May 31, 2026

Copy link
Copy Markdown

adding Forth langages to TIC-80 (using pforth)

@luginf

luginf commented May 31, 2026

Copy link
Copy Markdown
Author

(made with the help of Claude code)

luginf added 6 commits May 31, 2026 18:43
pforth cell_t = uintptr_t, so the pre-compiled dictionary is
cell-size-dependent (64-bit on x86-64, 32-bit on WASM). Loading a
64-bit dictionary in a 32-bit runtime corrupts all addresses and
freezes the HTML player.

- cmake/pfdicdat_32.h: new 32-bit dictionary (generated with gcc -m32)
- cmake/forth.cmake: select pfdicdat_32.h when CMAKE_SIZEOF_VOID_P == 4
@ddelemeny

Copy link
Copy Markdown
Contributor

Note: OP had the courtesy to open a discussion (#2938) regarding the project's AI contribution policy before vibe-coding this payload.

Resolving the policy matter should probably be considered a prerequisite to reviewing this PR.

@MineRobber9000 MineRobber9000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know enough about pforth to critique the actual implementation of the API, but there are definitely some spots in here that I am concerned about.

Comment thread cmake/forth.cmake Outdated
message(STATUS "Forth: copying bundled ${_PFORTH_DICDAT_BUNDLED} to ${PFORTH_DICDAT}")
configure_file(${_PFORTH_DICDAT_BUNDLED} ${PFORTH_DICDAT} COPYONLY)
else()
message(STATUS "Forth: pfdicdat.h not found — bootstrapping pforth to generate it...")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can use pforth to bootstrap the pfdicdat.h generation, why are we bundling a version of this data anyways? What happens if pforth updates in a way that adds more stuff to the dictionary, and now our bundled data is out of date?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MineRobber9000 that's a good question. I've initially let it generate the pfdicdat.h and pfdicdat_32.h from pforth but there was a problem with some targets (nintendo3D and rpi) do I've included those headers but it's not ideal.

It should be fixed now. I've tested the nintendo 3DS build and it's working fine.

image

Comment thread demos/forthdemo.fth Outdated
\ license: MIT License
\ script: forth
\
\ -- TIC-80 Forth API --------------------------------------------------

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to leave this API reference in the code.

Comment thread demos/forthdemo.fth Outdated
;

\ -- Demo 2 : sprite + arrow keys -------------------------------------
: demo02

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only one you actually need to have. The others are all just clutter that a user would have to delete before starting their own game.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. I've removed all that, including the API references and additional examples. Do you think it should be better to include such informations in an additional file in the demos/ folder under a new name, or leave this to the wiki, or even somewhere else? I see in the demos folder some lua samples like fire.lua or tetris.lua so I don't know

Comment thread demos/forthdemo.fth Outdated

: BOOT
96 px ! 24 py !
S" Forth BOOT" 12 TRACE

@MineRobber9000 MineRobber9000 Jun 1, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this, no other language does this. (EDIT: to clarify, since GH shows a seemingly random collection of lines and not the one you explicitly select in the interface, this is referring to tracing "Forth BOOT" in the BOOT callback.)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. I've just kept the BOOT procedure for initialising the variables, and kept the "demo01" word outside of the TIC loop, so people can just comment the demo and start creating new words.

Comment thread src/api/forth_io.c Outdated
@@ -0,0 +1,129 @@
// MIT License

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also go in forth.c. In general, all languages should be one C file apiece; the only exception are the Lua languages (Lua, MoonScript, Yue, and Fennel), since they all share the same plumbing underneath and only differ in how they're initialized.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has been merged into the forth.c

luginf added 4 commits June 2, 2026 18:37
removing cmake/pfdicdat.h and cmake/pfdicdat_32.h from tree
updating cmake/forth.cmake for bootstraping pfdicdat
@luginf luginf requested a review from MineRobber9000 June 2, 2026 19:03
@MineRobber9000

Copy link
Copy Markdown
Contributor

How did you manage to chmod +x the whole repo?

@luginf

luginf commented Jun 2, 2026

Copy link
Copy Markdown
Author

How did you manage to chmod +x the whole repo?

oops, long story short I needed to edit some files from another (local) account (on my computer). I can try to revert the 755 to 644 if you wish, but that will trigger a new build for nothing.

@MineRobber9000

MineRobber9000 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

You definitely should undo it. I can't review the PR in this state since I'd have to scroll through basically every file in the repo just to see what you actually changed.

@luginf

luginf commented Jun 3, 2026

Copy link
Copy Markdown
Author

You definitely should undo it. I can't review the PR in this state since I'd have to scroll through basically every file in the repo just to see what you actually changed.

Ok, i've fixed it, I'm just working on another problem (wrong/misleading message during a stack underflow) and I'll commit that ASAP

fix "stack underflow" message
Comment thread demos/forthdemo.fth Outdated
Comment on lines +16 to +28
: demo01
0 BTN IF py @ 1- py ! THEN
1 BTN IF py @ 1+ py ! THEN
2 BTN IF px @ 1- px ! THEN
3 BTN IF px @ 1+ px ! THEN
13 CLS
1 px @ py @ 14 3 0 0 2 2 SPR
S" Hello Forth!" 84 84 15 FALSE 1 FALSE PRINT DROP
;

: TIC
demo01
;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: demo01
0 BTN IF py @ 1- py ! THEN
1 BTN IF py @ 1+ py ! THEN
2 BTN IF px @ 1- px ! THEN
3 BTN IF px @ 1+ px ! THEN
13 CLS
1 px @ py @ 14 3 0 0 2 2 SPR
S" Hello Forth!" 84 84 15 FALSE 1 FALSE PRINT DROP
;
: TIC
demo01
;
: TIC
0 BTN IF py @ 1- py ! THEN
1 BTN IF py @ 1+ py ! THEN
2 BTN IF px @ 1- px ! THEN
3 BTN IF px @ 1+ px ! THEN
13 CLS
1 px @ py @ 14 3 0 0 2 2 SPR
S" Hello Forth!" 84 84 15 FALSE 1 FALSE PRINT DROP
;

If the user wants to write their own code, they'll probably want to just delete the whole demo code, so having it be a separate word is just clutter.

Comment thread src/api/forth.c Outdated
@MineRobber9000

Copy link
Copy Markdown
Contributor

Also, you forgot to install gcc-multilib in the Android task, which is why that build is failing.

luginf pushed a commit to luginf/TIC-80 that referenced this pull request Jun 4, 2026
- Remove references to committed cmake/pfdicdat.h and pfdicdat_32.h
  (deleted in PR nesbox#2947 forth branch)
- Document that cmake/forth.cmake now always regenerates pfdicdat.h at
  configure time via file(REMOVE) + bootstrap
- Add critical warning: a stale 32-bit dict in a 64-bit binary causes
  a silent segfault when selecting "new forth" (root cause documented)
- Update platform/cell-size matrix (WASM/3DS/RPI = 32-bit)
- Remove now-outdated manual regeneration instructions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@luginf luginf requested a review from MineRobber9000 June 4, 2026 20:53
Comment thread src/api/forth.c Outdated
Comment thread src/api/forth.c Outdated
Comment thread assets.bat
Comment thread assets.bat
luginf and others added 5 commits June 5, 2026 08:25
Co-authored-by: minerobber <milesrobert374@gmail.com>
Co-authored-by: minerobber <milesrobert374@gmail.com>
Co-authored-by: minerobber <milesrobert374@gmail.com>
Co-authored-by: minerobber <milesrobert374@gmail.com>

@MineRobber9000 MineRobber9000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

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.

3 participants