Skip to content

Instantly share code, notes, and snippets.

@bga
Created October 25, 2010 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bga/644983 to your computer and use it in GitHub Desktop.
Save bga/644983 to your computer and use it in GitHub Desktop.
enum ValueType
{
NULL,
UNDEFINED,
NUMBER_INT,
NUMBER_DOUBLE,
STRING,
BOOLEAN,
FUNCTION,
OBJECT,
TYPED_ARRAY // new in es6
};
struct StringBuffer
{
wchar *begin; // js strings is 2 bytes ie wide char
int length;
int refCount; // ref counter garbadge collection possible because string primitive is mutable type ie
// var a = b in a we will have new string with same buffer, begin and length. buffer.refCount++
};
struct String
{
StringBuffer *buffer;
wchar *begin;
int length;
};
struct HashTableEntry // 32 bytes
{
int hash;
String key; // string because key is used in for in loop
Value value;
};
struct HashTable // Open addressing Hash Table with linear probing
{
HashTableEntry *entries;
int entriesCount;
};
struct Object
{
HashTable ownProperties;
Object *prototype;
};
struct Function
{
void (*codeBegin)();
int argumentsCount;
Object *object;
};
struct TypedArrayBuffer
{
void *begin;
int length;
};
struct TypedArray
{
TypedArrayBuffer *buffer;
void *begin;
int length;
};
struct Value // 16 bytes
{
VarableType varableType; // 4 bytes, not 1 to aligined memory
union // 12 bytes
{
int numberIntValue; // 4 bytes
double numberDoubleValue; // 8 bytes
int booleanValue; // 4 bytes
String stringValue; // 12 bytes
Function functionValue; // 12 bytes
Object objectValue; // 12 bytes
TypedArray typedArrayValue; // 12 bytes
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment