Repository navigation
Forth - #2947
Forth#2947
Conversation
|
(made with the help of Claude code) |
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
|
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
left a comment
There was a problem hiding this comment.
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.
| 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...") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
@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.
| \ license: MIT License | ||
| \ script: forth | ||
| \ | ||
| \ -- TIC-80 Forth API -------------------------------------------------- |
There was a problem hiding this comment.
You don't need to leave this API reference in the code.
| ; | ||
|
|
||
| \ -- Demo 2 : sprite + arrow keys ------------------------------------- | ||
| : demo02 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
|
||
| : BOOT | ||
| 96 px ! 24 py ! | ||
| S" Forth BOOT" 12 TRACE |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
| @@ -0,0 +1,129 @@ | |||
| // MIT License | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
it has been merged into the forth.c
removing cmake/pfdicdat.h and cmake/pfdicdat_32.h from tree updating cmake/forth.cmake for bootstraping pfdicdat
|
How did you manage to |
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. |
|
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
| : 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 | ||
| ; |
There was a problem hiding this comment.
| : 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.
|
Also, you forgot to install |
fix mac os build by limiting the number of parallel processes
- 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>
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>
… clash with FORTH standard words
MiniScript arrived first, so the conflicts were adjacency again: the language list in src/script.c, the sources in core.cmake, the includes in CMakeLists, and the submodule list, which now carries both runtimes. Both sides are kept everywhere.
The merge left the two additions nested inside one another, which the compiler read as an unterminated conditional. The file is main's again with the Forth blocks beside MiniScript's, in both the extern list and the script array; a native build of the merge links.
|
Merged |
nesbox
left a comment
There was a problem hiding this comment.
Read the binding and the wiring. The runtime arrives as a submodule of upstream pforth, cmake/forth.cmake names the kernel sources and takes the no-IO build with TIC-80's own shim, and the script registers as forth with .fth — the release lists are ours to grow, as with MiniScript. Worth saying plainly: the tick has no time bound, so a runaway Forth loop hangs the client exactly as a runaway Lua or JS loop does; that is the house behaviour and MiniScript is the exception, not Forth the deficiency. The two build.yml changes are unrelated to languages and both check out.
Why: the table lists every runtime the build carries, and the two languages #2992 and #2947 added were simply absent from it — nothing else in the client was told what version they are. Neither vendor keeps its version where the older ten keep theirs, which is why this was left out of the stub-list pass: MiniScript's is in the map its own `version` intrinsic returns (vendor/miniscript2/generated/CoreIntrinsics.g.cpp; `hostVersion` beside it is the embedding application's, not the runtime's) and pForth's is PFORTH_VERSION_NAME in vendor/pforth/csrc/pf_guts.h. The name column grows to ten characters for "miniscript", which was the one name wider than the field — without it that row's version lands a column to the right of every other. Verified by running it: `tic80 --cli --cmd="help version"` prints "forth pForth 2.2.0" and "miniscript MiniScript 2.0" among the rest. Co-authored-by: Claude Code <noreply@anthropic.com>
|
@nesbox thank you very much, and also to @MineRobber9000 for the assistance! |
Collapses the fork's 54 commits since the upstream/main merge-base into one. Note: the actual Forth work is already in upstream/main (nesbox#2947, squash-merged as bbb0e012), so this commit's real diff is small: fork-local additions that never went upstream (CLAUDE.md project docs, .claude/skills.md, .gitignore, a vendor/miniscript2 bump, a build/html/index.html tweak). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
adding Forth langages to TIC-80 (using pforth)