pforth icon indicating copy to clipboard operation
pforth copied to clipboard

Example of adding custom C functions

Open guberathome opened this issue 1 year ago • 4 comments

One short demonstration how to compile custom code with PForth for the "unix" build. Custom code resides in separate "custom" folder. Setup, compilation and cleanup are handled by one shell script.

Tested with MSYS2-Cygwin, Linux, FreeBSD and NetBSD.

Edit: Changes from #184 seem to have crept in here, these still need to be fixed. Apologies.

guberathome avatar Dec 31 '24 22:12 guberathome

Changes from https://github.com/philburk/pforth/pull/184 seem to have crept in here,

there have been several recent changes. You will need to rebase to clear the merge conflicts.

philburk avatar Jan 01 '25 01:01 philburk

there have been several recent changes. You will need to rebase to clear the merge conflicts.

Done, changes are merged.

guberathome avatar Jan 01 '25 11:01 guberathome

done:

  • The "custom" folder should be in an "examples" folder.
  • in cf_helpers.h: We should not encourage calling exit() or assert() in production code.
  • in Makefile: CF_ is a bit cryptic. We should use CUSTOM_SOURCES
  • in cf_demo1.c: Deleting files is a bit dangerous for a demo replaced BE-GONE with FILE-INFO
  • go-v1.sh: Why v0 and v1?
  • in go-v0.sh: Why overwrite the file? removed since we changed the Makefile

open:

  • in demo.fth: Just need one "passing" Sorry to disagree: passing more than just one value helps to ensure proper function. Also you can guess (by inductive reasoning) what F4711 and FILE-INFO are meant to do just by looking at the output (not the source):
---------------------------
show that custom code works
---------------------------
f4711( 0, 1, 10, 100, 1000 ) = ( 11 , 58 , 481 , 4711 , 47011 )
FILE-INFO:
   file{ size=5459, path='Makefile' }
   directory{ path='../../examples' }
   error{ id=2, desc='No such file or directory', path='fileNotHere' }

guberathome avatar Jan 02 '25 09:01 guberathome

Just need one "passing"

Please consider if these changes are relevant to be merged (discussion on #188 contains my pitch in favour). My preference would be to contribute to this repo rather than putting example elsewhere.

I can removed the last offending passages from custom/01-be-gone/demo.fth if that settles it.

guberathome avatar Jan 05 '25 10:01 guberathome