Skip to content

Instantly share code, notes, and snippets.

@crides
Created August 1, 2018 06:04
Show Gist options
  • Save crides/486db7171b43c312146fa4bb95cf7af4 to your computer and use it in GitHub Desktop.
Save crides/486db7171b43c312146fa4bb95cf7af4 to your computer and use it in GitHub Desktop.
diff --git a/src/vm/wren_value.h b/src/vm/wren_value.h
index bdc6ed1..b32a815 100644
--- a/src/vm/wren_value.h
+++ b/src/vm/wren_value.h
@@ -106,14 +106,14 @@ typedef struct sObjClass ObjClass;
typedef struct sObj Obj;
struct sObj
{
- ObjType type;
- bool isDark;
-
// The object's class.
ObjClass* classObj;
// The next object in the linked list of all currently allocated objects.
struct sObj* next;
+
+ unsigned char isDark : 4;
+ ObjType type : 4;
};
#if WREN_NAN_TAGGING
@@ -253,15 +253,15 @@ typedef struct
ObjModule* module;
// The maximum number of stack slots this function may use.
- int maxSlots;
+ uint16_t maxSlots;
// The number of upvalues this function closes over.
- int numUpvalues;
+ uint16_t numUpvalues;
// The number of parameters this function expects. Used to ensure that .call
// handles a mismatch between number of parameters and arguments. This will
// only be set for fns, and not ObjFns that represent methods or scripts.
- int arity;
+ uint8_t arity;
FnDebug* debug;
} ObjFn;
@@ -324,17 +324,17 @@ typedef struct sObjFiber
Value* stackTop;
// The number of allocated slots in the stack array.
- int stackCapacity;
+ uint16_t stackCapacity;
// The stack of call frames. This is a dynamic array that grows as needed but
// never shrinks.
CallFrame* frames;
// The number of frames currently in use in [frames].
- int numFrames;
+ uint16_t numFrames;
// The number of [frames] allocated.
- int frameCapacity;
+ uint16_t frameCapacity;
// Pointer to the first node in the linked list of open upvalues that are
// pointing to values still on the stack. The head of the list will be the
@@ -349,7 +349,7 @@ typedef struct sObjFiber
// error object. Otherwise, it will be null.
Value error;
- FiberState state;
+ FiberState state:2;
} ObjFiber;
typedef enum
@@ -370,7 +370,7 @@ typedef enum
typedef struct
{
- MethodType type;
+ MethodType type:4;
// The method function itself. The [type] determines which field of the union
// is used.
@@ -391,7 +391,7 @@ struct sObjClass
// The number of fields needed for an instance of this class, including all
// of its superclass fields.
- int numFields;
+ int16_t numFields;
// The table of methods that are defined in or inherited by this class.
// Methods are called by symbol, and the symbol directly maps to an index in
@@ -460,10 +460,10 @@ typedef struct
Obj obj;
// The number of entries allocated.
- uint32_t capacity;
+ uint16_t capacity;
// The number of entries in the map.
- uint32_t count;
+ uint16_t count;
// Pointer to a contiguous array of [capacity] entries.
MapEntry* entries;
@crides
Copy link
Author

crides commented Aug 1, 2018

Actually, in line 32, the type of numUpValues can be uint8_t, as shown here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment