Skip to content

Instantly share code, notes, and snippets.

Created January 25, 2014 18:54
Show Gist options
  • Save anonymous/65db7aa834b5bda36d30 to your computer and use it in GitHub Desktop.
Save anonymous/65db7aa834b5bda36d30 to your computer and use it in GitHub Desktop.
#include <algorithm>
#include "codegen.hpp"
#include "interpretation.hpp"
#include <iterator>
#include <sys/mman.h>
#include <vector>
int main() {
std::vector<unsigned char> code;
translate(opcode::yield, std::back_inserter(code));
translate(opcode::yield, std::back_inserter(code));
translate(opcode::yield, std::back_inserter(code));
translate(opcode::yield, std::back_inserter(code));
translate(opcode::yield, std::back_inserter(code));
auto executable_code = static_cast<char*>(
mmap(nullptr, code.size(), PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANON, -1, 0));
std::copy(code.begin(), code.end(), executable_code);
interpreter interpreter(executable_code);
interpreter.resume();
interpreter.resume();
interpreter.resume();
interpreter.resume();
interpreter.resume();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment