Skip to content
Open

Forth #2947

Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@
[submodule "vendor/lpeg"]
path = vendor/lpeg
url = https://github.com/roberto-ieru/LPeg.git
[submodule "vendor/pforth"]
path = vendor/pforth
url = https://github.com/philburk/pforth.git
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ include(cmake/squirrel.cmake)
include(cmake/pocketpy.cmake)
include(cmake/quickjs.cmake)
include(cmake/janet.cmake)
include(cmake/forth.cmake)

include(cmake/core.cmake)
include(cmake/wave.cmake)
Expand Down
2 changes: 2 additions & 0 deletions assets.bat
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ build\bin\prj2cart demos\schemedemo.scm build\schemedemo.tic
build\bin\prj2cart demos\sfx.lua build\sfx.tic
build\bin\prj2cart demos\squirreldemo.nut build\squirreldemo.tic
build\bin\prj2cart demos\tetris.lua build\tetris.tic
build\bin\prj2cart demos\forthdemo.fth build\forthdemo.tic
build\bin\prj2cart demos\wrendemo.wren build\wrendemo.tic
build\bin\prj2cart demos\yuedemo.yue build\yuedemo.tic

Expand Down Expand Up @@ -59,6 +60,7 @@ build\bin\bin2txt build\schemedemo.tic build\assets\schemedemo.tic.dat -z
build\bin\bin2txt build\sfx.tic build\assets\sfx.tic.dat -z
build\bin\bin2txt build\squirreldemo.tic build\assets\squirreldemo.tic.dat -z
build\bin\bin2txt build\tetris.tic build\assets\tetris.tic.dat -z
build\bin\bin2txt build\forthdemo.tic build\assets\forthdemo.tic.dat -z
build\bin\bin2txt build\wrendemo.tic build\assets\wrendemo.tic.dat -z
build\bin\bin2txt build\janetmark.tic build\assets\janetmark.tic.dat -z
Comment thread
luginf marked this conversation as resolved.
build\bin\bin2txt build\jsmark.tic build\assets\jsmark.tic.dat -z
Expand Down
1 change: 1 addition & 0 deletions build/assets/forthdemo.tic.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x78, 0xda, 0xed, 0x57, 0xdd, 0x6e, 0xe2, 0x56, 0x10, 0x66, 0xfb, 0x73, 0x51, 0x2e, 0x56, 0xea, 0x1b, 0x4c, 0xb2, 0x52, 0xb5, 0xab, 0x6c, 0x24, 0x6c, 0x20, 0x3f, 0xb4, 0x89, 0x16, 0x88, 0xe9, 0x5a, 0x01, 0x82, 0x80, 0x5d, 0xed, 0x4a, 0xb9, 0x71, 0xec, 0x03, 0xb6, 0x62, 0x6c, 0xcb, 0x36, 0xc1, 0xf4, 0x09, 0x72, 0xd1, 0x87, 0xe8, 0x65, 0x15, 0xf1, 0x10, 0x5c, 0x57, 0xd6, 0x3e, 0xc9, 0x8a, 0x67, 0xe8, 0xcc, 0x39, 0x36, 0xd8, 0xf9, 0x6d, 0xb7, 0x95, 0x7a, 0x53, 0x03, 0x36, 0x9e, 0x99, 0x6f, 0xfe, 0xcf, 0xf8, 0xf8, 0xfb, 0x42, 0xa1, 0xf0, 0xec, 0xb7, 0xaf, 0x0a, 0x4f, 0x1d, 0x9f, 0x62, 0x3c, 0xae, 0xaf, 0xaf, 0x17, 0x37, 0x37, 0x37, 0x0b, 0xba, 0xe2, 0xed, 0x22, 0x5e, 0xae, 0x7f, 0x71, 0xfc, 0x79, 0x75, 0x7d, 0x1d, 0xaf, 0x6e, 0x6e, 0x96, 0xab, 0xeb, 0xdf, 0x97, 0xab, 0x78, 0xb1, 0x8c, 0x97, 0x8b, 0xe5, 0x32, 0xfd, 0xdd, 0x8f, 0x8f, 0x1f, 0xc5, 0xc7, 0x19, 0x7c, 0xe1, 0xff, 0xe3, 0x3f, 0x3d, 0x78, 0xad, 0xa8, 0x76, 0xfc, 0xf3, 0x07, 0xff, 0xff, 0x2b, 0xd6, 0x31, 0x2e, 0x2c, 0x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, 0xf4, 0x57, 0x10, 0x45, 0x5d, 0x26, 0xe3, 0x07, 0xf7, 0x30, 0x22, 0x13, 0x99, 0x97, 0x99, 0xad, 0x6d, 0x38, 0xa8, 0xd0, 0xf7, 0x91, 0x25, 0x95, 0x4f, 0x54, 0x19, 0x13, 0x95, 0x1b, 0x20, 0xf0, 0x05, 0x6b, 0xa3, 0x9c, 0x59, 0x1b, 0xa9, 0x43, 0xaf, 0xb3, 0x1e, 0x55, 0x0e, 0x36, 0x1e, 0xc9, 0x77, 0x3d, 0x12, 0x1d, 0x27, 0x66, 0x8b, 0x24, 0xed, 0xc1, 0xa1, 0x4c, 0xa1, 0x3e, 0x19, 0x40, 0xf3, 0xfe, 0x37, 0x32, 0x93, 0xf9, 0x2c, 0xf3, 0x3e, 0x26, 0x5e, 0xdf, 0x1e, 0x0c, 0x00, 0x5f, 0xbc, 0x8a, 0x34, 0x0c, 0xd7, 0x8b, 0x7c, 0x53, 0xfb, 0xf3, 0x4d, 0x74, 0x8e, 0xa8, 0x90, 0x83, 0x43, 0x07, 0xad, 0xff, 0x09, 0x5d, 0x54, 0x59, 0xe4,
1 change: 1 addition & 0 deletions build/baremetalpi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CFLAGS += -I "$(NEWLIBDIR)/include" -I $(STDDEF_INCPATH) -I $(CIRCLESTDLIB)/incl
LIBS := \
$(TIC80LIB)/libtic80studio.a \
$(TIC80LIB)/libtic80core.a \
$(TIC80LIB)/libforth.a \
$(TIC80LIB)/libgiflib.a \
$(TIC80LIB)/liblpeg.a \
$(TIC80LIB)/libluaapi.a \
Expand Down
4 changes: 4 additions & 0 deletions cmake/core.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ if(BUILD_STATIC)
target_link_libraries(tic80core PRIVATE wasm)
endif()

if(BUILD_WITH_FORTH)
target_link_libraries(tic80core PRIVATE forth)
endif()

target_link_libraries(tic80core PRIVATE runtime)

endif()
Expand Down
139 changes: 139 additions & 0 deletions cmake/forth.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
################################
# Forth (pForth)
################################

option(BUILD_WITH_FORTH "Forth Enabled" ${BUILD_WITH_ALL})
message("BUILD_WITH_FORTH: ${BUILD_WITH_FORTH}")

if(BUILD_WITH_FORTH)

set(PFORTH_DIR ${THIRDPARTY_DIR}/pforth/csrc)
set(PFORTH_FTH_DIR ${THIRDPARTY_DIR}/pforth/fth)

# -------------------------------------------------------------------------
# pforth C sources — all files from sources.cmake, excluding the default
# pfcustom.c (our forth.c serves as the replacement).
# -------------------------------------------------------------------------
set(PFORTH_KERNEL_SOURCES
${PFORTH_DIR}/pf_cglue.c
${PFORTH_DIR}/pf_clib.c
${PFORTH_DIR}/pf_core.c
${PFORTH_DIR}/pf_inner.c
${PFORTH_DIR}/pf_io.c
${PFORTH_DIR}/pf_io_none.c
${PFORTH_DIR}/pf_mem.c
${PFORTH_DIR}/pf_save.c
${PFORTH_DIR}/pf_text.c
${PFORTH_DIR}/pf_words.c
${PFORTH_DIR}/pfcompil.c
${PFORTH_DIR}/paging/pagedmem.c
${PFORTH_DIR}/paging/lockpage.c
${PFORTH_DIR}/paging/qadmpage.c
)

# -------------------------------------------------------------------------
# pfdicdat.h — pre-compiled standard dictionary for pforth.
# Cell size (32 vs 64 bit) must match the target platform:
# cmake/pfdicdat.h — 64-bit (x86-64, ARM64, …)
# cmake/pfdicdat_32.h — 32-bit (WASM/Emscripten, 32-bit ARM, …)
# To regenerate after updating pforth:
# 64-bit: cd vendor/pforth && cmake . && make pforth_dic_header
# cp vendor/pforth/csrc/pfdicdat.h cmake/pfdicdat.h
# 32-bit: cmake -DCMAKE_C_COMPILER=gcc-13 -DCMAKE_C_FLAGS=-m32 \
# -DCMAKE_CXX_COMPILER_WORKS=TRUE \
# -S vendor/pforth -B /tmp/pf32 && \
# cmake --build /tmp/pf32 --target pforth_dic_header && \
# cp vendor/pforth/csrc/pfdicdat.h cmake/pfdicdat_32.h
# -------------------------------------------------------------------------
set(PFORTH_DICDAT ${PFORTH_DIR}/pfdicdat.h)

# Use the 32-bit dictionary only for Emscripten/WASM; all other targets
# (including 32-bit ARM like 3DS or RPI) use the 64-bit dictionary as
# a fallback — those builds were already broken before this change.
if(EMSCRIPTEN)
set(_PFORTH_DICDAT_BUNDLED "${CMAKE_SOURCE_DIR}/cmake/pfdicdat_32.h")
else()
set(_PFORTH_DICDAT_BUNDLED "${CMAKE_SOURCE_DIR}/cmake/pfdicdat.h")
endif()

if(NOT EXISTS ${PFORTH_DICDAT})
if(EXISTS ${_PFORTH_DICDAT_BUNDLED})
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

set(_PFORTH_BOOTSTRAP_DIR "${CMAKE_BINARY_DIR}/pforth_bootstrap")
execute_process(
COMMAND ${CMAKE_COMMAND} -G "Unix Makefiles"
-DCMAKE_CXX_COMPILER_WORKS=TRUE
-S "${THIRDPARTY_DIR}/pforth" -B "${_PFORTH_BOOTSTRAP_DIR}"
RESULT_VARIABLE _pforth_cfg_result
)
execute_process(
COMMAND ${CMAKE_COMMAND} --build "${_PFORTH_BOOTSTRAP_DIR}"
--target pforth_dic_header
RESULT_VARIABLE _pforth_build_result
)
if(NOT EXISTS ${PFORTH_DICDAT})
message(FATAL_ERROR
"Forth: failed to generate pfdicdat.h at ${PFORTH_DICDAT}.\n"
"Try manually: cd ${THIRDPARTY_DIR}/pforth && cmake . && make pforth_dic_header\n"
"Then: cp ${THIRDPARTY_DIR}/pforth/csrc/pfdicdat.h ${_PFORTH_DICDAT_BUNDLED}")
endif()
message(STATUS "Forth: pfdicdat.h generated successfully")
endif()
endif()

# -------------------------------------------------------------------------
# forthdemo.tic.dat — demo cartridge for 'new forth' command.
# Source: demos/forthdemo.fth
# Regenerate (after building prj2cart and bin2txt):
# prj2cart demos/forthdemo.fth /tmp/forthdemo.tic
# bin2txt /tmp/forthdemo.tic build/assets/forthdemo.tic.dat -z
# -------------------------------------------------------------------------

# -------------------------------------------------------------------------
# TIC-80 forth library
# -------------------------------------------------------------------------
set(FORTH_SRC
${PFORTH_KERNEL_SOURCES}
${CMAKE_SOURCE_DIR}/src/api/forth.c
${CMAKE_SOURCE_DIR}/src/api/forth_io.c
${CMAKE_SOURCE_DIR}/src/api/parse_note.c
)

add_library(forth ${TIC_RUNTIME} ${FORTH_SRC})

if(NOT BUILD_STATIC)
set_target_properties(forth PROPERTIES PREFIX "")
endif()

target_compile_definitions(forth INTERFACE TIC_BUILD_WITH_FORTH=1)

target_compile_definitions(forth PRIVATE
PF_STATIC_DIC # load the pre-compiled dictionary from pfdicdat.h
PF_SUPPORT_FP # enable floating-point word set
PF_NO_FILEIO # stub out file I/O (no filesystem in cartridges)
PF_DEMAND_PAGING=0
)


target_link_libraries(forth PRIVATE runtime)

target_include_directories(forth
PRIVATE
# pfdicdat.h lives here; must come before any other include that
# could shadow it.
${PFORTH_DIR}
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/src
)

# Suppress warnings from pforth's own C files to avoid noise in TIC-80
# build logs (pforth was not written to match TIC-80's warning flags).
foreach(SRC ${PFORTH_KERNEL_SOURCES})
set_source_files_properties(${SRC} PROPERTIES COMPILE_FLAGS
"-w")
endforeach()

endif(BUILD_WITH_FORTH)
Loading
Loading