From 3efee51224c3cf0e39e198f9ace0d13431435244 Mon Sep 17 00:00:00 2001 From: CPunch Date: Thu, 25 May 2023 19:40:15 -0500 Subject: [PATCH] minor refactoring and typos --- src/cobj.c | 2 +- src/cobj.h | 3 ++- src/cparse.c | 2 +- src/cstate.h | 6 +++--- src/cvalue.h | 3 +-- src/cvm.c | 4 ---- 6 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/cobj.c b/src/cobj.c index 57881c2..cedb812 100644 --- a/src/cobj.c +++ b/src/cobj.c @@ -705,7 +705,7 @@ void printObject(CObj *o) switch (o->type) { case COBJ_STRING: { CObjString *objStr = (CObjString *)o; - printf("%.*s", objStr->length, objStr->str); + printf(" \"%.*s\"", objStr->length, objStr->str); break; } case COBJ_OBJECT: { diff --git a/src/cobj.h b/src/cobj.h index 8cb70e7..6bcbfa4 100644 --- a/src/cobj.h +++ b/src/cobj.h @@ -41,7 +41,7 @@ struct CObj struct CObjString { CommonHeader; // "is a" CObj - char *str; // NULL termincated string + char *str; // NULL terminated string uint32_t hash; // for hashtable lookup int length; bool isIString; @@ -138,6 +138,7 @@ struct CObjUpval #define cosmoV_readClosure(x) ((CObjClosure *)cosmoV_readRef(x)) #define cosmoO_readCString(x) ((CObjString *)x)->str +#define cosmoO_readType(x) ((CObj *)x)->type static inline bool isObjType(CValue val, CObjType type) { diff --git a/src/cparse.c b/src/cparse.c index f731664..dc578c3 100644 --- a/src/cparse.c +++ b/src/cparse.c @@ -59,10 +59,10 @@ typedef struct CCompilerState typedef struct { + CState *state; CLexState *lex; CCompilerState *compiler; CObjString *module; // name of the module - CState *state; CToken current; CToken previous; // token right after the current token bool hadError; diff --git a/src/cstate.h b/src/cstate.h index a52ed32..711d62f 100644 --- a/src/cstate.h +++ b/src/cstate.h @@ -59,9 +59,9 @@ struct CState CValue *top; // top of the stack CObjObject *protoObjects[COBJ_MAX]; // proto object for each COBJ type [NULL = no default proto] - CObjString *iStrings[ISTRING_MAX]; // strings used internally by the VM, eg. __init, __index - CCallFrame callFrame[FRAME_MAX]; // call frames - CValue stack[STACK_MAX]; // stack + CObjString *iStrings[ISTRING_MAX]; // strings used internally by the VM, eg. __init, __index + CCallFrame callFrame[FRAME_MAX]; // call frames + CValue stack[STACK_MAX]; // stack }; COSMO_API CState *cosmoV_newState(); diff --git a/src/cvalue.h b/src/cvalue.h index aa46abf..f08ccd1 100644 --- a/src/cvalue.h +++ b/src/cvalue.h @@ -123,7 +123,6 @@ void printValue(CValue val); COSMO_API bool cosmoV_equal(CState *state, CValue valA, CValue valB); COSMO_API CObjString *cosmoV_toString(CState *state, CValue val); COSMO_API cosmo_Number cosmoV_toNumber(CState *state, CValue val); -COSMO_API const char * -cosmoV_typeStr(CValue val); // return constant char array for corresponding type +COSMO_API const char *cosmoV_typeStr(CValue val); #endif diff --git a/src/cvm.c b/src/cvm.c index accb818..b3735ff 100644 --- a/src/cvm.c +++ b/src/cvm.c @@ -229,11 +229,7 @@ static bool callCFunction(CState *state, CosmoCFunction cfunc, int args, int nre { StkPtr savedBase = cosmoV_getTop(state, args); - // we don't want a GC event during c api because we don't actually trust the user to know how to - // evade the GC - cosmoM_freezeGC(state); int nres = cfunc(state, args, savedBase + 1); - cosmoM_unfreezeGC(state); // caller function wasn't expecting this many return values, cap it if (nres > nresults)