mirror of
https://github.com/CPunch/Cosmo.git
synced 2026-06-24 18:30:05 +00:00
better GC debugging, added base object for tables
This commit is contained in:
28
src/cobj.h
28
src/cobj.h
@@ -4,15 +4,18 @@
|
||||
#include "cosmo.h"
|
||||
#include "cchunk.h"
|
||||
#include "cvalue.h"
|
||||
#include "ctable.h"
|
||||
|
||||
typedef struct CState CState;
|
||||
|
||||
typedef enum {
|
||||
COBJ_STRING,
|
||||
COBJ_UPVALUE,
|
||||
COBJ_TABLE,
|
||||
COBJ_FUNCTION,
|
||||
COBJ_CFUNCTION,
|
||||
COBJ_CLOSURE
|
||||
// internal use
|
||||
COBJ_CLOSURE,
|
||||
COBJ_UPVALUE,
|
||||
} CObjType;
|
||||
|
||||
#define CommonHeader CObj obj;
|
||||
@@ -32,12 +35,11 @@ typedef struct CObjString {
|
||||
uint32_t hash; // for hashtable lookup
|
||||
} CObjString;
|
||||
|
||||
typedef struct CObjUpval {
|
||||
typedef struct CObjTable {
|
||||
CommonHeader; // "is a" CObj
|
||||
CValue *val;
|
||||
CValue closed;
|
||||
struct CObjUpval *next;
|
||||
} CObjUpval;
|
||||
CTable tbl;
|
||||
//struct CObjTable *meta; // metatable, used to describe table behavior
|
||||
} CObjTable;
|
||||
|
||||
typedef struct CObjFunction {
|
||||
CommonHeader; // "is a" CObj
|
||||
@@ -53,18 +55,27 @@ typedef struct CObjCFunction {
|
||||
} CObjCFunction;
|
||||
|
||||
typedef struct CObjClosure {
|
||||
CommonHeader;
|
||||
CommonHeader; // "is a" CObj
|
||||
CObjFunction *function;
|
||||
CObjUpval **upvalues;
|
||||
int upvalueCount;
|
||||
} CObjClosure;
|
||||
|
||||
typedef struct CObjUpval {
|
||||
CommonHeader; // "is a" CObj
|
||||
CValue *val;
|
||||
CValue closed;
|
||||
struct CObjUpval *next;
|
||||
} CObjUpval;
|
||||
|
||||
#define IS_STRING(x) isObjType(x, COBJ_STRING)
|
||||
#define IS_TABLE(x) isObjType(x, COBJ_TABLE)
|
||||
#define IS_FUNCTION(x) isObjType(x, COBJ_FUNCTION)
|
||||
#define IS_CFUNCTION(x) isObjType(x, COBJ_CFUNCTION)
|
||||
#define IS_CLOSURE(x) isObjType(x, COBJ_CLOSURE)
|
||||
|
||||
#define cosmoV_readString(x) ((CObjString*)cosmoV_readObj(x))
|
||||
#define cosmoV_readTable(x) ((CObjTable*)cosmoV_readObj(x))
|
||||
#define cosmoV_readFunction(x) ((CObjFunction*)cosmoV_readObj(x))
|
||||
#define cosmoV_readCFunction(x) (((CObjCFunction*)cosmoV_readObj(x))->cfunc)
|
||||
#define cosmoV_readClosure(x) ((CObjClosure*)cosmoV_readObj(x))
|
||||
@@ -78,6 +89,7 @@ void cosmoO_freeObject(CState *state, CObj* obj);
|
||||
|
||||
bool cosmoO_equalObject(CObj* obj1, CObj* obj2);
|
||||
|
||||
CObjTable *cosmoO_newTable(CState *state);
|
||||
CObjFunction *cosmoO_newFunction(CState *state);
|
||||
CObjCFunction *cosmoO_newCFunction(CState *state, CosmoCFunction func);
|
||||
CObjClosure *cosmoO_newClosure(CState *state, CObjFunction *func);
|
||||
|
||||
Reference in New Issue
Block a user