Skip to content

Commit

Permalink
hated the styling of this
Browse files Browse the repository at this point in the history
consistency is nice to have
  • Loading branch information
CPunch committed Nov 4, 2023
1 parent 3ce0989 commit 8c5e80c
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/cbaselib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 2 additions & 1 deletion src/cdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions src/cmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions src/cobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 8 additions & 4 deletions src/cstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/ctable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions src/cvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down Expand Up @@ -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());
}
}

/*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -415,8 +418,9 @@ 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);
Expand Down

0 comments on commit 8c5e80c

Please sign in to comment.