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 demo
Or equivalently, using the convenience Makefile
:
$ make direct # Build one demo
$ make # Build everything
Each demo simply prints a number to show that it will run. The expected outputs are:
bytecode
:2
direct
:2
indirect
:4
pctc
:6
pctc_opt
:6