hated the styling of this

consistency is nice to have
This commit is contained in:
cpunch 2023-11-03 22:36:59 -05:00
parent 1a7d6caec6
commit 7a54230cb9
7 changed files with 35 additions and 19 deletions

View File

@ -699,8 +699,9 @@ int cosmoB_sRep(CState *state, int nargs, CValue *args)
char *newStr = cosmoM_xmalloc(state, length + 1); // + 1 for the NULL terminator
// copy the string over the new buffer
for (int i = 0; i < times; i++)
for (int i = 0; i < times; i++) {
memcpy(&newStr[i * str->length], str->str, str->length);
}
// write the NULL terminator
newStr[length] = '\0';

View File

@ -5,8 +5,9 @@
void printIndent(int indent)
{
for (int i = 0; i < indent; i++)
for (int i = 0; i < indent; i++) {
printf("\t");
}
}
static int simpleInstruction(const char *name, int offset)

View File

@ -165,8 +165,9 @@ static void blackenObject(CState *state, CObj *obj)
markValue(state, err->err);
// mark callframes
for (int i = 0; i < err->frameCount; i++)
for (int i = 0; i < err->frameCount; i++) {
markObject(state, (CObj *)err->frames[i].closure);
}
break;
}
@ -284,13 +285,15 @@ static void markRoots(CState *state)
markObject(state, (CObj *)state->globals);
// mark all internal strings
for (int i = 0; i < ISTRING_MAX; i++)
for (int i = 0; i < ISTRING_MAX; i++) {
markObject(state, (CObj *)state->iStrings[i]);
}
markTable(state, &state->registry);
for (int i = 0; i < COBJ_MAX; i++)
for (int i = 0; i < COBJ_MAX; i++) {
markObject(state, (CObj *)state->protoObjects[i]);
}
traceGrays(state);
}

View File

@ -15,8 +15,9 @@ uint32_t hashString(const char *str, size_t sz)
uint32_t hash = sz;
size_t step = (sz >> 5) + 1;
for (size_t 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;
}
@ -236,8 +237,9 @@ CObjError *cosmoO_newError(CState *state, CValue err)
cerror->parserError = false;
// clone the call frame
for (int i = 0; i < state->frameCount; i++)
for (int i = 0; i < state->frameCount; i++) {
cerror->frames[i] = state->callFrame[i];
}
return cerror;
}

View File

@ -54,11 +54,13 @@ CState *cosmoV_newState()
state->openUpvalues = NULL;
// set default proto objects
for (int i = 0; i < COBJ_MAX; i++)
for (int i = 0; i < COBJ_MAX; i++) {
state->protoObjects[i] = NULL;
}
for (int i = 0; i < ISTRING_MAX; i++)
for (int i = 0; i < ISTRING_MAX; i++) {
state->iStrings[i] = NULL;
}
cosmoT_initTable(state, &state->strings, 16); // init string table
cosmoT_initTable(state, &state->registry, 16);
@ -87,8 +89,9 @@ CState *cosmoV_newState()
state->iStrings[ISTRING_RESERVED] = cosmoO_copyString(state, "__reserved", 10);
// set the IString flags
for (int i = 0; i < ISTRING_MAX; i++)
for (int i = 0; i < ISTRING_MAX; i++) {
state->iStrings[i]->isIString = true;
}
state->freezeGC = 0; // unfreeze the state
return state;
@ -115,8 +118,9 @@ void cosmoV_freeState(CState *state)
}
// mark our internal VM strings NULL
for (int i = 0; i < ISTRING_MAX; i++)
for (int i = 0; i < ISTRING_MAX; i++) {
state->iStrings[i] = NULL;
}
// free our string table (the string table includes the internal VM strings)
cosmoT_clearTable(state, &state->strings);

View File

@ -87,8 +87,9 @@ static uint32_t getValueHash(CValue *val)
return 0;
memcpy(buf, &num, sizeof(buf));
for (size_t i = 0; i < sizeof(cosmo_Number) / sizeof(uint32_t); 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

View File

@ -26,8 +26,9 @@ void cosmoV_insert(CState *state, int indx, CValue val)
StkPtr tmp = cosmoV_getTop(state, indx);
// moves everything up
for (StkPtr i = state->top; i > tmp; i--)
for (StkPtr i = state->top; i > tmp; i--) {
*i = *(i - 1);
}
*tmp = val;
state->top++;
@ -268,8 +269,9 @@ static void callCFunction(CState *state, CosmoCFunction cfunc, int args, int nre
state->top += nres; // and make sure to move state->top to match
// now, if the caller function expected more return values, push nils onto the stack
for (int i = nres; i < nresults; i++)
for (int i = nres; i < nresults; i++) {
cosmoV_pushValue(state, cosmoV_newNil());
}
}
/*
@ -327,8 +329,9 @@ static void rawCall(CState *state, CObjClosure *closure, int args, int nresults,
state->top += nres; // and make sure to move state->top to match
// now, if the caller function expected more return values, push nils onto the stack
for (int i = nres; i < nresults; i++)
for (int i = nres; i < nresults; i++) {
cosmoV_pushValue(state, cosmoV_newNil());
}
}
// returns true if successful, false if error
@ -377,9 +380,9 @@ void callCValue(CState *state, CValue func, int args, int nresults, int offset)
if (nresults > 0) {
cosmoV_pushRef(state, (CObj *)newObj);
// push the nils to fill up the expected return values
for (int i = 0; i < nresults - 1;
i++) { // -1 since the we already pushed the important value
// push the nils to fill up the expected return values.
// -1 since the we already pushed the important value
for (int i = 0; i < nresults - 1;i++) {
cosmoV_pushValue(state, cosmoV_newNil());
}
}
@ -415,9 +418,10 @@ bool cosmoV_pcall(CState *state, int args, int nresults)
if (nresults > 0) {
// push other expected results onto the stack
for (int i = 0; i < nresults - 1; i++)
for (int i = 0; i < nresults - 1; i++) {
cosmoV_pushValue(state, cosmoV_newNil());
}
}
cosmoV_freePanic(state);
return false;