Skip to content

Instantly share code, notes, and snippets.

@rightfold
Last active August 29, 2015 14:24
Show Gist options
  • Save rightfold/da99068a2d8946575ed3 to your computer and use it in GitHub Desktop.
Save rightfold/da99068a2d8946575ed3 to your computer and use it in GitHub Desktop.

See https://gist.github.com/rightfold/a4122970bb4587d3bd01 for C++ data structures.

nil

type nil_type;
nil_type.size = 8;
nil_type.alignment = 8;
nil_type.fields = [];
nil_type.move = no-op;
bytes 1..8
&nil_type

(cons 1 2)

type cons_type;
cons_type.size = 24;
cons_type.alignment = 8;
cons_type.fields = [
    car: { size = 8; alignment = 8 },
    cdr: { size = 8; alignment = 8 },
];
cons_type.move = memmove;
bytes 1..8 bytes 9..16 bytes 17..24
&cons_type &1 &2

"hello"

type string_type;
string_type.size = 24;
string_type.alignment = 8;
string_type.fields = [];
string_type.move = [] (void* fromp, void* top) {
    std::string* from = (std::string*)((char*)fromp + 8);
    std::string* to = (std::string*)((char*)fromp + 8);
    std::string temp(std::move(*from));
    *to = std::move(temp);
};
bytes 1..8 bytes 9..9+sizeof(std::string)
&string_type std::string data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment