Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dramforever/threaded-code-demo

Some demonstrations of threaded code techniques
https://github.com/dramforever/threaded-code-demo

Last synced: about 1 month ago
JSON representation

Some demonstrations of threaded code techniques

Awesome Lists containing this project

README

        

# Threaded code demo

Complete demos for my article Threaded code explained in C at

Some demonstrations of threaded code techniques

- `bytecode.c`: Bytecode (Not technically threaded)
- `direct.c`: Direct threaded code
- `indirect.c`: Indirect threaded code
- `pctc.c`: Primitive-centric threaded code
- `pctc_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?][gforth-pctc] in the Gforth manual.

[gforth-pctc]: https://gforth.org/manual/Direct-or-Indirect-Threaded_003f.html

Each of the demo files needs to be compiled along with / linked to `main.c` such as:

```console
$ gcc -o direct direct.c main.c
$ ./direct # Run the demo
```

Or equivalently, using the convenience `Makefile`:

```console
$ 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`