public
Created

  • Download Gist
gistfile1.c
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
 
 
 
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
};
};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.