Skip to content

Forth#2947

Open
luginf wants to merge 10 commits into
nesbox:mainfrom
luginf:forth
Lines changed: 13315 additions & 0 deletions
Open

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

Conversation

@luginf
Copy link
Copy Markdown

@luginf luginf commented May 31, 2026

adding Forth langages to TIC-80 (using pforth)

@luginf
Copy link
Copy Markdown
Author

luginf commented May 31, 2026

(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.

Copy link
Copy Markdown
Contributor

@MineRobber9000 MineRobber9000 left a comment

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.

cmake/forth.cmake
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?

demos/forthdemo.fth
\ 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.

demos/forthdemo.fth
;

\ -- 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.

demos/forthdemo.fth

: BOOT
96 px ! 24 py !
S" Forth BOOT" 12 TRACE
Copy link
Copy Markdown
Contributor

@MineRobber9000 MineRobber9000 Jun 1, 2026

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.)

src/api/forth_io.c
@@ -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.

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.

None yet

3 participants