diff --git a/src/cbaselib.c b/src/cbaselib.c index 0f0f09c..a9d5a2c 100644 --- a/src/cbaselib.c +++ b/src/cbaselib.c @@ -146,4 +146,4 @@ void cosmoB_loadDebug(CState *state) { // set debug proto to the debug object state->protoObj = cosmoV_readObject(*cosmoV_pop(state)); -} \ No newline at end of file +} diff --git a/src/cbaselib.h b/src/cbaselib.h index 9f6acb4..ce4ce0d 100644 --- a/src/cbaselib.h +++ b/src/cbaselib.h @@ -8,4 +8,4 @@ COSMO_API void cosmoB_loadDebug(CState *state); COSMO_API int cosmoB_print(CState *state, int nargs, CValue *args); COSMO_API int cosmoB_assert(CState *state, int nargs, CValue *args); -#endif \ No newline at end of file +#endif diff --git a/src/cchunk.c b/src/cchunk.c index 9da1e6f..858e4e7 100644 --- a/src/cchunk.c +++ b/src/cchunk.c @@ -37,7 +37,7 @@ void freeChunk(CState* state, CChunk *chunk) { int addConstant(CState* state, CChunk *chunk, CValue value) { // before adding the constant, check if we already have it - for (int i = 0; i < chunk->constants.count; i++) { + for (size_t i = 0; i < chunk->constants.count; i++) { if (cosmoV_equal(value, chunk->constants.values[i])) return i; // we already have a matching constant! } diff --git a/src/cchunk.h b/src/cchunk.h index 92ee9d0..e4b42f8 100644 --- a/src/cchunk.h +++ b/src/cchunk.h @@ -36,4 +36,4 @@ static inline uint16_t readu16Chunk(CChunk *chunk, int offset) { return *((uint16_t*)(&chunk->buf[offset])); } -#endif \ No newline at end of file +#endif diff --git a/src/cdebug.c b/src/cdebug.c index 97cc066..459c602 100644 --- a/src/cdebug.c +++ b/src/cdebug.c @@ -32,7 +32,7 @@ int u8u16OperandInstruction(const char *name, CChunk *chunk, int offset) { return offset + 4; // op + u8 + u16 } -int constInstruction(const char *name, CChunk *chunk, int offset, int indent) { +int constInstruction(const char *name, CChunk *chunk, int offset) { int index = readu16Chunk(chunk, offset + 1); printf("%-16s [%05d] - ", name, index); CValue val = chunk->constants.values[index]; @@ -48,7 +48,7 @@ void disasmChunk(CChunk *chunk, const char *name, int indent) { printIndent(indent); printf("===[[ %s ]]===\n", name); - for (int offset = 0; offset < chunk->count;) { + for (size_t offset = 0; offset < chunk->count;) { offset = disasmInstr(chunk, offset, indent); printf("\n"); } @@ -69,11 +69,11 @@ int disasmInstr(CChunk *chunk, int offset, int indent) { switch (i) { case OP_LOADCONST: - return constInstruction("OP_LOADCONST", chunk, offset, indent); + return constInstruction("OP_LOADCONST", chunk, offset); case OP_SETGLOBAL: - return constInstruction("OP_SETGLOBAL", chunk, offset, indent); + return constInstruction("OP_SETGLOBAL", chunk, offset); case OP_GETGLOBAL: - return constInstruction("OP_GETGLOBAL", chunk, offset, indent); + return constInstruction("OP_GETGLOBAL", chunk, offset); case OP_SETLOCAL: return u8OperandInstruction("OP_SETLOCAL", chunk, offset); case OP_GETLOCAL: @@ -189,4 +189,4 @@ int disasmInstr(CChunk *chunk, int offset, int indent) { return 1; -} \ No newline at end of file +} diff --git a/src/cdebug.h b/src/cdebug.h index 829fc03..00f63dc 100644 --- a/src/cdebug.h +++ b/src/cdebug.h @@ -6,4 +6,4 @@ COSMO_API void disasmChunk(CChunk *chunk, const char *name, int indent); COSMO_API int disasmInstr(CChunk *chunk, int offset, int indent); -#endif \ No newline at end of file +#endif diff --git a/src/clex.c b/src/clex.c index ad063b8..0cd8c5e 100644 --- a/src/clex.c +++ b/src/clex.c @@ -155,7 +155,7 @@ CTokenType identifierType(CLexState *state) { int length = state->currentChar - state->startChar; // check against reserved word list - for (int i = 0; i < sizeof(reservedWords) / sizeof(CReservedWord); i++) { + for (size_t i = 0; i < sizeof(reservedWords) / sizeof(CReservedWord); i++) { // it matches the reserved word if (reservedWords[i].len == length && memcmp(state->startChar, reservedWords[i].word, length) == 0) return reservedWords[i].type; @@ -336,4 +336,4 @@ CToken cosmoL_scanToken(CLexState *state) { } return makeError(state, "Unknown symbol!"); -} \ No newline at end of file +} diff --git a/src/clex.h b/src/clex.h index 67fe084..23e4728 100644 --- a/src/clex.h +++ b/src/clex.h @@ -100,4 +100,4 @@ void cosmoL_freeLexState(CState *state, CLexState *lstate); CToken cosmoL_scanToken(CLexState *state); -#endif \ No newline at end of file +#endif diff --git a/src/cmem.c b/src/cmem.c index 8ba4712..9ca929e 100644 --- a/src/cmem.c +++ b/src/cmem.c @@ -78,7 +78,7 @@ void tableRemoveWhite(CState *state, CTable *tbl) { } void markArray(CState *state, CValueArray *array) { - for (int i = 0; i < array->count; i++) { + for (size_t i = 0; i < array->count; i++) { markValue(state, array->values[i]); } } @@ -132,7 +132,9 @@ void blackenObject(CState *state, CObj *obj) { break; } default: - printf("Unknown type in blackenObject with %p, type %d\n", obj, obj->type); +#ifdef GC_DEBUG + printf("Unknown type in blackenObject with %p, type %d\n", (void*)obj, obj->type); +#endif break; } } @@ -300,4 +302,4 @@ COSMO_API void cosmoM_removeRoot(CState *state, CObj *oldRoot) { prev = root; root = root->nextRoot; } -} \ No newline at end of file +} diff --git a/src/cmem.h b/src/cmem.h index 9fb3c6b..616f7fb 100644 --- a/src/cmem.h +++ b/src/cmem.h @@ -67,4 +67,4 @@ static inline void *cosmoM_xmalloc(CState *state, size_t sz) { return cosmoM_reallocate(state, NULL, 0, sz); } -#endif \ No newline at end of file +#endif diff --git a/src/cobj.c b/src/cobj.c index 05cd2b1..8053be7 100644 --- a/src/cobj.c +++ b/src/cobj.c @@ -11,7 +11,7 @@ uint32_t hashString(const char *str, size_t sz) { uint32_t hash = sz; size_t step = (sz>>5)+1; - for (int i = sz; i >= step; i-=step) + for (size_t i = sz; i >= step; i-=step) hash = ((hash << 5) + (hash>>2)) + str[i-1]; return hash; @@ -394,12 +394,12 @@ CObjString *cosmoO_toString(CState *state, CObj *obj) { } case COBJ_OBJECT: { // TODO: maybe not safe?? char buf[64]; - int sz = sprintf(buf, " %p", obj) + 1; // +1 for the null character + int sz = sprintf(buf, " %p", (void*)obj) + 1; // +1 for the null character return cosmoO_copyString(state, buf, sz); } case COBJ_DICT: { char buf[64]; - int sz = sprintf(buf, " %p", obj) + 1; // +1 for the null character + int sz = sprintf(buf, " %p", (void*)obj) + 1; // +1 for the null character return cosmoO_copyString(state, buf, sz); } default: @@ -415,17 +415,17 @@ void printObject(CObj *o) { break; } case COBJ_OBJECT: { - printf(" %p", o); + printf(" %p", (void*)o); break; } case COBJ_DICT: { CObjDict *dict = (CObjDict*)o; - printf(" %p", dict); + printf(" %p", (void*)dict); break; } case COBJ_UPVALUE: { CObjUpval *upval = (CObjUpval*)o; - printf(" -> ", upval->val); + printf(" -> ", (void*)upval->val); printValue(*upval->val); break; } @@ -444,17 +444,17 @@ void printObject(CObj *o) { } case COBJ_CFUNCTION: { CObjCFunction *objCFunc = (CObjCFunction*)o; - printf(" %p", objCFunc->cfunc); + printf(" %p", (void*)objCFunc->cfunc); break; } case COBJ_METHOD: { CObjMethod *method = (CObjMethod*)o; - printf(" %p : ", method->obj); + printf(" %p : ", (void*)method->obj); printValue(method->func); break; } default: - printf("", o); + printf("", (void*)o); } } @@ -472,4 +472,4 @@ const char *cosmoO_typeStr(CObj* obj) { default: return ""; // TODO: maybe panic? could be a malformed object :eyes: } -} \ No newline at end of file +} diff --git a/src/cobj.h b/src/cobj.h index 840d28d..ccdd21a 100644 --- a/src/cobj.h +++ b/src/cobj.h @@ -22,7 +22,7 @@ typedef enum { COBJ_UPVALUE, } CObjType; -#define CommonHeader CObj _obj; +#define CommonHeader CObj _obj #define readFlag(x, flag) (x & (1u << flag)) #define setFlagOn(x, flag) (x |= (1u << flag)) @@ -169,4 +169,4 @@ const char *cosmoO_typeStr(CObj* obj); #define cosmoO_readCString(x) ((CObjString*)x)->str -#endif \ No newline at end of file +#endif diff --git a/src/coperators.c b/src/coperators.c index 9a7ec46..fd7bb2e 100644 --- a/src/coperators.c +++ b/src/coperators.c @@ -1 +1 @@ -#include "coperators.h" \ No newline at end of file +#include "coperators.h" diff --git a/src/coperators.h b/src/coperators.h index a1f0603..1b82e24 100644 --- a/src/coperators.h +++ b/src/coperators.h @@ -63,4 +63,4 @@ typedef enum { OP_RETURN } COPCODE; // there can be a max of 256 instructions -#endif \ No newline at end of file +#endif diff --git a/src/cosmo.h b/src/cosmo.h index 67b9185..f07f510 100644 --- a/src/cosmo.h +++ b/src/cosmo.h @@ -44,4 +44,4 @@ typedef uint8_t INSTRUCTION; #define CERROR(err) \ printf("%s : %s\n", "[ERROR]", err) -#endif \ No newline at end of file +#endif diff --git a/src/cparse.c b/src/cparse.c index 0ffd159..dabb29b 100644 --- a/src/cparse.c +++ b/src/cparse.c @@ -287,8 +287,10 @@ static uint16_t identifierConstant(CParseState *pstate, CToken *name) { } static void addLocal(CParseState *pstate, CToken name) { - if (pstate->compiler->localCount > UINT8_MAX) - return error(pstate, "UInt overflow! Too many locals in scope!"); + if (pstate->compiler->localCount > UINT8_MAX) { + error(pstate, "UInt overflow! Too many locals in scope!"); + return; + } Local *local = &pstate->compiler->locals[pstate->compiler->localCount++]; local->name = name; @@ -1494,4 +1496,4 @@ CObjFunction* cosmoP_compileString(CState *state, const char *source, const char freeParseState(&parser); cosmoM_unfreezeGC(state); return resFunc; -} \ No newline at end of file +} diff --git a/src/cparse.h b/src/cparse.h index 88a5cbc..2185821 100644 --- a/src/cparse.h +++ b/src/cparse.h @@ -7,4 +7,4 @@ // compiles source into CChunk, if NULL is returned, a syntaxical error has occurred and pushed onto the stack CObjFunction* cosmoP_compileString(CState *state, const char *source, const char *module); -#endif \ No newline at end of file +#endif diff --git a/src/cstate.c b/src/cstate.c index 4b34eaa..8af581f 100644 --- a/src/cstate.c +++ b/src/cstate.c @@ -108,4 +108,4 @@ void cosmoV_printStack(CState *state) { printValue(*top); printf("\n"); } -} \ No newline at end of file +} diff --git a/src/cstate.h b/src/cstate.h index 3509518..e271a3c 100644 --- a/src/cstate.h +++ b/src/cstate.h @@ -58,4 +58,4 @@ COSMO_API void cosmoV_register(CState *state, int pairs); COSMO_API void cosmoV_freeState(CState *state); COSMO_API void cosmoV_printStack(CState *state); -#endif \ No newline at end of file +#endif diff --git a/src/ctable.c b/src/ctable.c index e6f0010..794948a 100644 --- a/src/ctable.c +++ b/src/ctable.c @@ -73,7 +73,7 @@ uint32_t getValueHash(CValue *val) { return 0; memcpy(buf, &num, sizeof(buf)); - for (int i = 0; i < sizeof(cosmo_Number)/sizeof(uint32_t); i++) buf[0] += buf[i]; + for (size_t i = 0; i < sizeof(cosmo_Number)/sizeof(uint32_t); i++) buf[0] += buf[i]; return buf[0]; } // TODO: add support for other types @@ -216,7 +216,7 @@ COSMO_API int cosmoT_count(CTable *tbl) { return tbl->count - tbl->tombstones; } -CObjString *cosmoT_lookupString(CTable *tbl, const char *str, size_t length, uint32_t hash) { +CObjString *cosmoT_lookupString(CTable *tbl, const char *str, int length, uint32_t hash) { if (tbl->count == 0) return 0; // sanity check uint32_t indx = hash & (tbl->capacity - 1); // since we know the capacity will *always* be a power of 2, we can use bitwise & to perform a MUCH faster mod operation @@ -248,4 +248,4 @@ void cosmoT_printTable(CTable *tbl, const char *name) { printf("\n"); } } -} \ No newline at end of file +} diff --git a/src/ctable.h b/src/ctable.h index 66eaeb3..5a88b17 100644 --- a/src/ctable.h +++ b/src/ctable.h @@ -22,11 +22,11 @@ COSMO_API void cosmoT_addTable(CState *state, CTable *from, CTable *to); COSMO_API CValue *cosmoT_insert(CState *state, CTable *tbl, CValue key); COSMO_API int cosmoT_count(CTable *tbl); -CObjString *cosmoT_lookupString(CTable *tbl, const char *str, size_t length, uint32_t hash); +CObjString *cosmoT_lookupString(CTable *tbl, const char *str, int length, uint32_t hash); bool cosmoT_checkShrink(CState *state, CTable *tbl); bool cosmoT_get(CTable *tbl, CValue key, CValue *val); bool cosmoT_remove(CState *state, CTable *tbl, CValue key); void cosmoT_printTable(CTable *tbl, const char *name); -#endif \ No newline at end of file +#endif diff --git a/src/cvalue.c b/src/cvalue.c index 46d2b42..46e8e84 100644 --- a/src/cvalue.c +++ b/src/cvalue.c @@ -85,4 +85,4 @@ void printValue(CValue val) { default: printf(""); } -} \ No newline at end of file +} diff --git a/src/cvalue.h b/src/cvalue.h index aad5dc8..9d8d001 100644 --- a/src/cvalue.h +++ b/src/cvalue.h @@ -116,4 +116,4 @@ COSMO_API bool cosmoV_equal(CValue valA, CValue valB); COSMO_API CObjString *cosmoV_toString(CState *state, CValue val); COSMO_API const char *cosmoV_typeStr(CValue val); // return constant char array for corresponding type -#endif \ No newline at end of file +#endif diff --git a/src/cvm.c b/src/cvm.c index 4b2dea5..a70279c 100644 --- a/src/cvm.c +++ b/src/cvm.c @@ -1059,4 +1059,4 @@ int cosmoV_execute(CState *state) { return -1; } -#undef NUMBEROP \ No newline at end of file +#undef NUMBEROP diff --git a/src/cvm.h b/src/cvm.h index a1093d9..fadd70b 100644 --- a/src/cvm.h +++ b/src/cvm.h @@ -92,4 +92,4 @@ static inline void cosmoV_pushString(CState *state, const char *str) { cosmoV_pushLString(state, str, strlen(str)); } -#endif \ No newline at end of file +#endif diff --git a/src/main.c b/src/main.c index 7cd5fd2..f2ceced 100644 --- a/src/main.c +++ b/src/main.c @@ -134,4 +134,4 @@ int main(int argc, const char *argv[]) { } return 0; -} \ No newline at end of file +}