Complete demos for my article Threaded code explained in C at https://dram.page/p/threaded-code/
Some demonstrations of threaded code techniques
bytecode.c: Bytecode (Not technically threaded)direct.c: Direct threaded codeindirect.c: Indirect threaded codepctc.c: Primitive-centric threaded codepctc_opt.c: Primitive-centric threaded code (Optimized to encourage the compiler to use registers)
Primitive-centric threaded code is described in Direct or Indirect Threaded? in the Gforth manual.
Each of the demo files needs to be compiled along with / linked to main.c such as:
$ gcc -o direct direct.c main.c
$ ./direct # Run the demoOr equivalently, using the convenience Makefile:
$ make direct # Build one demo
$ make # Build everythingEach demo simply prints a number to show that it will run. The expected outputs are:
bytecode:2direct:2indirect:4pctc:6pctc_opt:6