Forth Machine Design Study: Win4k

An interactive forth programming environment with OpenGL bindings


Click to view screenshot

Introduction

Win4K is an interactive forth-based programming environment that comes up with its own console. You can write graphics effects in real-time and modify live variables.

This software was my first attempt to implement a forth machine. Although it has many limitations and bugs, is far away from being complete and currently not in active development stage, I decided to make this tiny computer art available to the public to stress the forth community with new ideas. On this site you'll find some general information on the design issues that made up this machine.

Features

Interpreter Design

The machine reads a text-line and parses it. The parser has support for int and float values, C-Strings and looksup identifiers in a word map. The evaluation parses the text elements, decodes the tokens to execution-words and writes them to a word buffer. When finished with the line, the word stream gets terminated. Then the word stream gets executed in the virtual machine.

Virtual Machine Design

The basic elements of the virtual machine: The basic 'word' unit in the vm is described below:
typedef void (exec_t)  (void*);

typedef struct _word word_t;
struct _word
{
  exec_t* exec;
  void*   data;
};
The machine is made up of several exec functions:
void code_call (void* wp       );
void code_btrue(void* dest     );
void code_push (void* imm32    );
void code_ret  (void* mark     );

void code_imm  (void* imm_exec );
void code_throw(void* excid    );
void code_exit (void* mark     );
void code_dump (void* strptr   );
The actual execution engine looks like this:
word_t* ip;

next:
  ip->exec(ip->data);
  ip++;
  goto next;

Download

Binary: win4k-0.5-bin.zip
Sources: win4k-0.5-src.zip

Links

If you are a forth/4k intro enthusiast, don't miss this link to our T!LT headquater.