Skip to content

Instantly share code, notes, and snippets.

@amorri40
Created March 20, 2012 19:18
Show Gist options
  • Save amorri40/2140090 to your computer and use it in GitHub Desktop.
Save amorri40/2140090 to your computer and use it in GitHub Desktop.
Interpreter101_simple
/*
Google I/O 2008 - Dalvik Virtual Machine Internals
Interpreters 101, toy interpreter
This is a simple toy bytecode interpreter
*/
#include <cstdio>
static void interpreter(const char* stringOfBytecode);
int main(int argc, char *argv[]) {
interpreter("abcbbbbde");
}
static void interpreter(const char* stringOfBytecode) {
for (;;) {
switch (*(stringOfBytecode++)) {
case 'a': printf("Hell"); break;
case 'b': printf("o"); break;
case 'c': printf(" w"); break;
case 'd': printf("rld!\n"); break;
case 'e': return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment