1 // labels as values (computed goto)
4 // implement a small dispatch table of instructions for a mini
5 // state machine, to test computed goto
8 int instruction_0_state = 0;
9 int instruction_1_state = 0;
10 int instruction_2_state = 0;
12 unsigned char bytecode[] = {0x01, 0x05, 0x01, 0x02, 0x02, 0x03};
13 unsigned char *pc = bytecode;
22 #define DISPATCH(INDEX) \
25 goto *dispatch[*pc]; \
32 instruction_0_state += *(pc + 1);
36 instruction_1_state ++;
40 instruction_2_state --;
45 expecti(instruction_0_state, 7);
46 expecti(instruction_1_state, 1);
47 expecti(instruction_2_state, -1);