Skip to content

Instantly share code, notes, and snippets.

@amorri40
Created March 20, 2012 21:52
Show Gist options
  • Save amorri40/2141678 to your computer and use it in GitHub Desktop.
Save amorri40/2141678 to your computer and use it in GitHub Desktop.
Interpreters101_Thegccway
/*
The gcc way
*/
#define DISPATCH() \
{ goto *op_table[*((stringOfBytecode)++) - 'a']; }
static void interpreter_the_gcc_way(const char* stringOfBytecode) {
static void* op_table[] = {
&&op_a, &&op_b, &&op_c, &&op_d, &&op_e
};
DISPATCH();
op_a: printf("Hell"); DISPATCH();
op_b: printf("o"); DISPATCH();
op_c: printf(" w"); DISPATCH();
op_d: printf("rld!\n"); DISPATCH();
op_e: return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment