Created
October 25, 2010 13:52
-
-
Save bga/644983 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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