[virtmach] First VM

Tom Fjellstrom tfjellstrom@home.com
Tue, 14 Nov 2000 00:13:49 -0700

Michael Wolf wrote:
> On Mon, Nov 13, 2000 at 06:49:47PM -0700, Tom Fjellstrom wrote:
> > I just finished ripping out that massive switch statement and put in
> > place
> > a direct threaded implementation using a table of labels and goto.
> > but now the new version is irreversibly GCC only...
> If the old and new are sufficiently similar, I bet you could do something
> portable to GCC and ANSI C.

the only deference between the two are the vm_exec() function.
But right now the makefile compiles both versions.

> Due to the nature of code which relies on a lot of static tables with a lot
> of related data in each, the code probably lends itself well to being
> automatically generated based on 1 file with definitions and several
> template .c files.
> So, for example, in chip.h you have
>     enum chipop {
>         NOOP = 0,
>         MUL,
>         DIV,
>         ...
>     };
> and in chip.c you have
>     OPDEF opargs[MAXOP] = {
>         { NOOP, 0},
>         ...
>     }
> and
>     switch (vm->vm_chip.ir) {
>         case (NOOP):
>             ...
>         ...
>     }
> and so on.  It's redundant, but that's bad only because the files are
> written and generated by hand.  You could automatically generate all of this
> stuff all at once when you build Chip.
> I think with a bit of effort, you could support both the label pointer table
> and the switch statement.
> A definition language might look like:
>     opcode, num_args, switch_func, switch_c_operator, label
>     MUL, 2, 8BIT, *=, mul_label
>     MULL, 2, 32BIT, *=, mull_label
> or something similar -- I've probably got the exact details quite wrong.
> When generating code, use that data and fill in the templates.

also an optional (or not :) element would be 'code' just in case
the templates aren't what are needed.

> I would probably do this in perl, and I've heard m4 is suitable for this
> sort of thing, but I don't know m4, so take that advice with a grain of
> salt.  :)
> Does this make sense?  Let me know how it turns out.

Yes, quite a lot of sense, especially sense I discovered that CHIP nor
the compiler supports OPs that I thought I added at the start.
(i.e.: SHL SHR etc...)

> mike

Now that is a nice idea. And I can do it perl :)
Hmmm, while I'm doing that I might as well put together
the perl script for generating the lexer too...
(I've been meaning to do that for a while.)

Tom Fjellstrom