fixed typos

This commit is contained in:
CPunch 2020-12-19 13:32:43 -06:00
parent 0beeee0fdf
commit f6aaeb3417
13 changed files with 34 additions and 41 deletions

View File

@ -37,7 +37,7 @@ int cosmoB_foreach(CState *state, int nargs, CValue *args) {
return 0; return 0;
} }
// loop through dictonary table, calling args[1] on active entries // loop through dictionary table, calling args[1] on active entries
CObjDict *dict = (CObjDict*)cosmoV_readObj(args[0]); CObjDict *dict = (CObjDict*)cosmoV_readObj(args[0]);
for (int i = 0; i < dict->tbl.capacity; i++) { for (int i = 0; i < dict->tbl.capacity; i++) {

View File

@ -9,7 +9,7 @@
typedef struct CValueArray CValueArray; typedef struct CValueArray CValueArray;
typedef struct CChunk { typedef struct CChunk {
size_t capacity; // the ammount of space we've allocated for size_t capacity; // the amount of space we've allocated for
size_t count; // the space we're currently using size_t count; // the space we're currently using
INSTRUCTION *buf; // whole chunk INSTRUCTION *buf; // whole chunk
CValueArray constants; // holds constants CValueArray constants; // holds constants
@ -19,8 +19,8 @@ typedef struct CChunk {
CChunk *newChunk(CState* state, size_t startCapacity); CChunk *newChunk(CState* state, size_t startCapacity);
void initChunk(CState* state, CChunk *chunk, size_t startCapacity); void initChunk(CState* state, CChunk *chunk, size_t startCapacity);
void cleanChunk(CState* state, CChunk *chunk); // free's everything but the struct void cleanChunk(CState* state, CChunk *chunk); // frees everything but the struct
void freeChunk(CState* state, CChunk *chunk); // free's everything including the struct void freeChunk(CState* state, CChunk *chunk); // frees everything including the struct
int addConstant(CState* state, CChunk *chunk, CValue value); int addConstant(CState* state, CChunk *chunk, CValue value);
// write to chunk // write to chunk

View File

@ -173,7 +173,7 @@ int disasmInstr(CChunk *chunk, int offset, int indent) {
case OP_INCGLOBAL: case OP_INCGLOBAL:
return u8u16OperandInstruction("OP_INCGLOBAL", chunk, offset); return u8u16OperandInstruction("OP_INCGLOBAL", chunk, offset);
case OP_INCUPVAL: case OP_INCUPVAL:
return u8u8OperandInstruction("OP_INCLOCAL", chunk, offset); return u8u8OperandInstruction("OP_INCUPVAL", chunk, offset);
case OP_INCINDEX: case OP_INCINDEX:
return u8OperandInstruction("OP_INCINDEX", chunk, offset); return u8OperandInstruction("OP_INCINDEX", chunk, offset);
case OP_INCOBJECT: case OP_INCOBJECT:

View File

@ -44,7 +44,7 @@ static void resetBuffer(CLexState *state) {
state->bufCap = 0; state->bufCap = 0;
} }
// cancels the token heap buffer and free's it // cancels the token heap buffer and frees it
static void freeBuffer(CLexState *state) { static void freeBuffer(CLexState *state) {
cosmoM_freearray(state->cstate, char, state->buffer, state->bufCap); cosmoM_freearray(state->cstate, char, state->buffer, state->bufCap);

View File

@ -10,7 +10,7 @@
void *cosmoM_reallocate(CState* state, void *buf, size_t oldSize, size_t newSize) { void *cosmoM_reallocate(CState* state, void *buf, size_t oldSize, size_t newSize) {
state->allocatedBytes += newSize - oldSize; state->allocatedBytes += newSize - oldSize;
if (newSize == 0) { // it needs to be free'd if (newSize == 0) { // it needs to be freed
free(buf); free(buf);
return NULL; return NULL;
} }
@ -62,7 +62,7 @@ void markTable(CState *state, CTable *tbl) {
} }
} }
// free's white members from the table // frees white members from the table
void tableRemoveWhite(CState *state, CTable *tbl) { void tableRemoveWhite(CState *state, CTable *tbl) {
if (tbl->table == NULL) // table is still being initialized if (tbl->table == NULL) // table is still being initialized
return; return;
@ -153,7 +153,7 @@ void markObject(CState *state, CObj *obj) {
if (obj->type == COBJ_CFUNCTION || obj->type == COBJ_STRING) if (obj->type == COBJ_CFUNCTION || obj->type == COBJ_STRING)
return; return;
// we can use cosmoM_growaraay because we lock the GC when we entered in cosmoM_collectGarbage // we can use cosmoM_growarray because we lock the GC when we entered in cosmoM_collectGarbage
cosmoM_growarray(state, CObj*, state->grayStack.array, state->grayStack.count, state->grayStack.capacity); cosmoM_growarray(state, CObj*, state->grayStack.array, state->grayStack.count, state->grayStack.capacity);
state->grayStack.array[state->grayStack.count++] = obj; state->grayStack.array[state->grayStack.count++] = obj;
@ -244,7 +244,7 @@ COSMO_API void cosmoM_collectGarbage(CState *state) {
markRoots(state); markRoots(state);
tableRemoveWhite(state, &state->strings); // make sure we aren't referencing any strings that are about to be free'd tableRemoveWhite(state, &state->strings); // make sure we aren't referencing any strings that are about to be freed
// now finally, free all the unmarked objects // now finally, free all the unmarked objects
sweep(state); sweep(state);

View File

@ -59,7 +59,7 @@ COSMO_API void cosmoM_updateThreshhold(CState *state);
// lets the VM know you are holding a reference to a CObj and to not free it // lets the VM know you are holding a reference to a CObj and to not free it
COSMO_API void cosmoM_addRoot(CState *state, CObj *newRoot); COSMO_API void cosmoM_addRoot(CState *state, CObj *newRoot);
// lets the VM know this root is no longer held in a reference and is able to be free'd // lets the VM know this root is no longer held in a reference and is able to be freed
COSMO_API void cosmoM_removeRoot(CState *state, CObj *oldRoot); COSMO_API void cosmoM_removeRoot(CState *state, CObj *oldRoot);
// wrapper for cosmoM_reallocate so we can track our memory usage (it's also safer :P) // wrapper for cosmoM_reallocate so we can track our memory usage (it's also safer :P)

View File

@ -156,7 +156,7 @@ CObjMethod *cosmoO_newMethod(CState *state, CObjClosure *func, CObjObject *obj)
} }
CObjClosure *cosmoO_newClosure(CState *state, CObjFunction *func) { CObjClosure *cosmoO_newClosure(CState *state, CObjFunction *func) {
// intialize array of pointers // initialize array of pointers
CObjUpval **upvalues = cosmoM_xmalloc(state, sizeof(CObjUpval*) * func->upvals); CObjUpval **upvalues = cosmoM_xmalloc(state, sizeof(CObjUpval*) * func->upvals);
for (int i = 0; i < func->upvals; i++) { for (int i = 0; i < func->upvals; i++) {
@ -236,7 +236,7 @@ bool cosmoO_getObject(CState *state, CObjObject *object, CValue key, CValue *val
if (object->proto != NULL && cosmoO_getObject(state, object->proto, key, val)) if (object->proto != NULL && cosmoO_getObject(state, object->proto, key, val))
return true; return true;
return false; // no protoobject to check against / key not founc return false; // no protoobject to check against / key not found
} }
return true; return true;

View File

@ -3,13 +3,6 @@
#include "cosmo.h" #include "cosmo.h"
// instruction types
typedef enum {
I_O, // just the operand (uint8_t)
I_OBYTE, // operand (uint8_t) + uint8_t
I_OSHORT, // operand (uint8_t) + uint16_t
} InstructionType;
// instructions // instructions
typedef enum { typedef enum {

View File

@ -103,7 +103,7 @@ static void initCompilerState(CParseState* pstate, CCompilerState *ccstate, Func
else else
ccstate->function->name = cosmoO_copyString(pstate->state, UNNAMEDCHUNK, strlen(UNNAMEDCHUNK)); ccstate->function->name = cosmoO_copyString(pstate->state, UNNAMEDCHUNK, strlen(UNNAMEDCHUNK));
// mark first local slot as used (this'll hold the CObjFunction of the current function, or if it's a method it'll hold the currently bounded object) // mark first local slot as used (this will hold the CObjFunction of the current function, or if it's a method it'll hold the currently bounded object)
Local *local = &ccstate->locals[ccstate->localCount++]; Local *local = &ccstate->locals[ccstate->localCount++];
local->depth = 0; local->depth = 0;
local->isCaptured = false; local->isCaptured = false;
@ -461,7 +461,7 @@ static void namedVariable(CParseState *pstate, CToken name, bool canAssign, bool
opSet = OP_SETUPVAL; opSet = OP_SETUPVAL;
inc = OP_INCUPVAL; inc = OP_INCUPVAL;
} else { } else {
// local & upvalue wasnt' found, assume it's a global! // local & upvalue wasn't found, assume it's a global!
arg = identifierConstant(pstate, &name); arg = identifierConstant(pstate, &name);
opGet = OP_GETGLOBAL; opGet = OP_GETGLOBAL;
opSet = OP_SETGLOBAL; opSet = OP_SETGLOBAL;
@ -668,7 +668,7 @@ static void increment(CParseState *pstate, int val) {
} else if ((arg = getUpvalue(pstate->compiler, &name)) != -1) { } else if ((arg = getUpvalue(pstate->compiler, &name)) != -1) {
op = OP_INCUPVAL; op = OP_INCUPVAL;
} else { } else {
// local & upvalue wasnt' found, assume it's a global! // local & upvalue wasn't found, assume it's a global!
arg = identifierConstant(pstate, &name); arg = identifierConstant(pstate, &name);
op = OP_INCGLOBAL; op = OP_INCGLOBAL;
} }
@ -1164,10 +1164,10 @@ static void forLoop(CParseState *pstate) {
consume(pstate, TOKEN_LEFT_PAREN, "Expected '(' after 'for'"); consume(pstate, TOKEN_LEFT_PAREN, "Expected '(' after 'for'");
// parse initalizer // parse initializer
if (!match(pstate, TOKEN_EOS)) { if (!match(pstate, TOKEN_EOS)) {
expressionStatement(pstate); expressionStatement(pstate);
consume(pstate, TOKEN_EOS, "Expected ';' after initalizer!"); consume(pstate, TOKEN_EOS, "Expected ';' after initializer!");
} }
int loopStart = getChunk(pstate)->count; int loopStart = getChunk(pstate)->count;

View File

@ -4,7 +4,7 @@
#include "cosmo.h" #include "cosmo.h"
#include "clex.h" #include "clex.h"
// compiles source into CChunk, if NULL is returned, a syntaxical error has occured and pushed onto the stack // 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); CObjFunction* cosmoP_compileString(CState *state, const char *source, const char *module);
#endif #endif

View File

@ -65,7 +65,7 @@ CState *cosmoV_newState() {
void cosmoV_freeState(CState *state) { void cosmoV_freeState(CState *state) {
#ifdef GC_DEBUG #ifdef GC_DEBUG
printf("state %p is being free'd!\n", state); printf("state %p is being freed!\n", state);
#endif #endif
// frees all the objects // frees all the objects
CObj *objs = state->objects; CObj *objs = state->objects;

View File

@ -205,7 +205,7 @@ bool cosmoT_remove(CState* state, CTable *tbl, CValue key) {
// crafts tombstone // crafts tombstone
entry->key = cosmoV_newNil(); // this has to be nil entry->key = cosmoV_newNil(); // this has to be nil
entry->val = cosmoV_newBoolean(false); // doesn't reall matter what this is, as long as it isn't nil entry->val = cosmoV_newBoolean(false); // doesn't really matter what this is, as long as it isn't nil
tbl->tombstones++; tbl->tombstones++;
return true; return true;

View File

@ -213,11 +213,11 @@ COSMOVMRESULT cosmoV_call(CState *state, int args, int nresults) {
newObj->proto = protoObj; newObj->proto = protoObj;
CValue ret; CValue ret;
// check if they defined an initalizer // check if they defined an initializer
if (cosmoO_getIString(state, protoObj, ISTRING_INIT, &ret)) { if (cosmoO_getIString(state, protoObj, ISTRING_INIT, &ret)) {
invokeMethod(state, newObj, ret, args, nresults, 1); invokeMethod(state, newObj, ret, args, nresults, 1);
} else { } else {
// no default initalizer // no default initializer
if (args != 0) { if (args != 0) {
cosmoV_error(state, "Expected 0 parameters, got %d!", args); cosmoV_error(state, "Expected 0 parameters, got %d!", args);
return COSMOVM_RUNTIME_ERR; return COSMOVM_RUNTIME_ERR;
@ -638,16 +638,16 @@ int cosmoV_execute(CState *state) {
cosmoV_pushValue(state, cosmoV_newObj(obj)); cosmoV_pushValue(state, cosmoV_newObj(obj));
cosmoV_call(state, 1, 1); // we expect 1 return value on the stack, the iterable object cosmoV_call(state, 1, 1); // we expect 1 return value on the stack, the iterable object
StkPtr iobj = cosmoV_getTop(state, 0); StkPtr iObj = cosmoV_getTop(state, 0);
if (!IS_OBJECT(*iobj)) { if (!IS_OBJECT(*iObj)) {
cosmoV_error(state, "Expected iterable object! '__iter' returned %s, expected object!", cosmoV_typeStr(*iobj)); cosmoV_error(state, "Expected iterable object! '__iter' returned %s, expected object!", cosmoV_typeStr(*iObj));
break; break;
} }
CObjObject *obj = (CObjObject*)cosmoV_readObj(*iobj); CObjObject *obj = (CObjObject*)cosmoV_readObj(*iObj);
cosmoV_getObject(state, obj, cosmoV_newObj(state->iStrings[ISTRING_NEXT]), iobj); cosmoV_getObject(state, obj, cosmoV_newObj(state->iStrings[ISTRING_NEXT]), iObj);
} else { } else {
cosmoV_error(state, "Expected iterable object! '__iter' not defined!"); cosmoV_error(state, "Expected iterable object! '__iter' not defined!");
} }
@ -711,7 +711,7 @@ int cosmoV_execute(CState *state) {
} }
break; break;
} }
case OP_COUNT: { // pop 1 value off the stack & if it's a dictionary return the ammount of active entries it has case OP_COUNT: { // pop 1 value off the stack & if it's a dictionary return the amount of active entries it has
StkPtr temp = cosmoV_getTop(state, 0); StkPtr temp = cosmoV_getTop(state, 0);
if (!IS_OBJ(*temp) || cosmoV_readObj(*temp)->type != COBJ_DICT) { if (!IS_OBJ(*temp) || cosmoV_readObj(*temp)->type != COBJ_DICT) {
@ -744,7 +744,7 @@ int cosmoV_execute(CState *state) {
break; break;
} }
case OP_INCLOCAL: { // this leaves the value on the stack case OP_INCLOCAL: { // this leaves the value on the stack
int8_t inc = READBYTE() - 128; // ammount we're incrementing by int8_t inc = READBYTE() - 128; // amount we're incrementing by
uint8_t indx = READBYTE(); uint8_t indx = READBYTE();
StkPtr val = &frame->base[indx]; StkPtr val = &frame->base[indx];
@ -759,7 +759,7 @@ int cosmoV_execute(CState *state) {
break; break;
} }
case OP_INCGLOBAL: { case OP_INCGLOBAL: {
int8_t inc = READBYTE() - 128; // ammount we're incrementing by int8_t inc = READBYTE() - 128; // amount we're incrementing by
uint16_t indx = READUINT(); uint16_t indx = READUINT();
CValue ident = constants[indx]; // grabs identifier CValue ident = constants[indx]; // grabs identifier
CValue *val = cosmoT_insert(state, &state->globals, ident); CValue *val = cosmoT_insert(state, &state->globals, ident);
@ -775,7 +775,7 @@ int cosmoV_execute(CState *state) {
break; break;
} }
case OP_INCUPVAL: { case OP_INCUPVAL: {
int8_t inc = READBYTE() - 128; // ammount we're incrementing by int8_t inc = READBYTE() - 128; // amount we're incrementing by
uint8_t indx = READBYTE(); uint8_t indx = READBYTE();
CValue *val = frame->closure->upvalues[indx]->val; CValue *val = frame->closure->upvalues[indx]->val;
@ -790,7 +790,7 @@ int cosmoV_execute(CState *state) {
break; break;
} }
case OP_INCINDEX: { case OP_INCINDEX: {
int8_t inc = READBYTE() - 128; // ammount we're incrementing by int8_t inc = READBYTE() - 128; // amount we're incrementing by
StkPtr temp = cosmoV_getTop(state, 1); // object should be above the key StkPtr temp = cosmoV_getTop(state, 1); // object should be above the key
StkPtr key = cosmoV_getTop(state, 0); // grabs key StkPtr key = cosmoV_getTop(state, 0); // grabs key
@ -836,7 +836,7 @@ int cosmoV_execute(CState *state) {
break; break;
} }
case OP_INCOBJECT: { case OP_INCOBJECT: {
int8_t inc = READBYTE() - 128; // ammount we're incrementing by int8_t inc = READBYTE() - 128; // amount we're incrementing by
uint16_t indx = READUINT(); uint16_t indx = READUINT();
StkPtr temp = cosmoV_getTop(state, 0); // object should be at the top of the stack StkPtr temp = cosmoV_getTop(state, 0); // object should be at the top of the stack
CValue ident = constants[indx]; // grabs identifier CValue ident = constants[indx]; // grabs identifier