Cosmo/src/cstate.h

62 lines
2.0 KiB
C
Raw Normal View History

2020-10-28 05:16:30 +00:00
#ifndef CSTATE_H
#define CSTATE_H
#include "cosmo.h"
#include "cvalue.h"
#include "cobj.h"
#include "ctable.h"
typedef struct CCallFrame {
CObjClosure *closure;
INSTRUCTION *pc;
CValue* base;
} CCallFrame;
typedef enum IStringEnum {
ISTRING_INIT, // __init
ISTRING_INDEX, // __index
ISTRING_NEWINDEX, // __newindex
ISTRING_GETTER, // __getter
ISTRING_SETTER, // __setter
ISTRING_ITER, // __iter
ISTRING_NEXT, // __next
ISTRING_RESERVED, // __reserved
ISTRING_MAX
} IStringEnum;
2020-11-12 22:52:56 +00:00
2020-12-07 20:35:14 +00:00
typedef struct ArrayCObj {
CObj **array;
int count;
int capacity;
} ArrayCObj;
2020-10-28 05:16:30 +00:00
typedef struct CState {
bool panic;
int freezeGC; // when > 0, GC events will be ignored (for internal use)
2021-01-02 01:20:24 +00:00
int frameCount;
CObjObject *protoObj; // start met obj for all objects (NULL by default)
2020-10-28 05:16:30 +00:00
CObj *objects; // tracks all of our allocated objects
CObj *userRoots; // user definable roots, this holds CObjs that should be considered "roots", lets the VM know you are holding a reference to a CObj in your code
2020-12-07 20:35:14 +00:00
ArrayCObj grayStack; // keeps track of which objects *haven't yet* been traversed in our GC, but *have been* found
2020-10-28 05:16:30 +00:00
size_t allocatedBytes;
size_t nextGC; // when allocatedBytes reaches this threshhold, trigger a GC event
CObjUpval *openUpvalues; // tracks all of our still open (meaning still on the stack) upvalues
CTable strings;
CTable globals;
CValue *top; // top of the stack
CObjString *iStrings[ISTRING_MAX]; // strings used internally by the VM, eg. __init, __index & friends
2021-01-02 01:20:24 +00:00
CCallFrame callFrame[FRAME_MAX]; // call frames
CValue stack[STACK_MAX]; // stack
2020-10-28 05:16:30 +00:00
} CState;
COSMO_API CState *cosmoV_newState();
// expects 2*pairs values on the stack, each pair should consist of 1 key and 1 value
COSMO_API void cosmoV_register(CState *state, int pairs);
2020-10-28 05:16:30 +00:00
COSMO_API void cosmoV_freeState(CState *state);
COSMO_API void cosmoV_printStack(CState *state);
2021-01-02 05:06:24 +00:00
#endif