mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-21 23:10:05 +00:00
fixed typos
This commit is contained in:
parent
0beeee0fdf
commit
f6aaeb3417
@ -37,7 +37,7 @@ int cosmoB_foreach(CState *state, int nargs, CValue *args) {
|
||||
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]);
|
||||
|
||||
for (int i = 0; i < dict->tbl.capacity; i++) {
|
||||
|
@ -9,7 +9,7 @@
|
||||
typedef struct CValueArray CValueArray;
|
||||
|
||||
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
|
||||
INSTRUCTION *buf; // whole chunk
|
||||
CValueArray constants; // holds constants
|
||||
@ -19,8 +19,8 @@ typedef struct CChunk {
|
||||
|
||||
CChunk *newChunk(CState* state, 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 freeChunk(CState* state, CChunk *chunk); // free's everything including the struct
|
||||
void cleanChunk(CState* state, CChunk *chunk); // frees everything but the struct
|
||||
void freeChunk(CState* state, CChunk *chunk); // frees everything including the struct
|
||||
int addConstant(CState* state, CChunk *chunk, CValue value);
|
||||
|
||||
// write to chunk
|
||||
|
@ -173,7 +173,7 @@ int disasmInstr(CChunk *chunk, int offset, int indent) {
|
||||
case OP_INCGLOBAL:
|
||||
return u8u16OperandInstruction("OP_INCGLOBAL", chunk, offset);
|
||||
case OP_INCUPVAL:
|
||||
return u8u8OperandInstruction("OP_INCLOCAL", chunk, offset);
|
||||
return u8u8OperandInstruction("OP_INCUPVAL", chunk, offset);
|
||||
case OP_INCINDEX:
|
||||
return u8OperandInstruction("OP_INCINDEX", chunk, offset);
|
||||
case OP_INCOBJECT:
|
||||
|
@ -44,7 +44,7 @@ static void resetBuffer(CLexState *state) {
|
||||
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) {
|
||||
cosmoM_freearray(state->cstate, char, state->buffer, state->bufCap);
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
void *cosmoM_reallocate(CState* state, void *buf, size_t oldSize, size_t newSize) {
|
||||
state->allocatedBytes += newSize - oldSize;
|
||||
|
||||
if (newSize == 0) { // it needs to be free'd
|
||||
if (newSize == 0) { // it needs to be freed
|
||||
free(buf);
|
||||
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) {
|
||||
if (tbl->table == NULL) // table is still being initialized
|
||||
return;
|
||||
@ -153,7 +153,7 @@ void markObject(CState *state, CObj *obj) {
|
||||
if (obj->type == COBJ_CFUNCTION || obj->type == COBJ_STRING)
|
||||
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);
|
||||
|
||||
state->grayStack.array[state->grayStack.count++] = obj;
|
||||
@ -244,7 +244,7 @@ COSMO_API void cosmoM_collectGarbage(CState *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
|
||||
sweep(state);
|
||||
|
||||
|
@ -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
|
||||
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);
|
||||
|
||||
// wrapper for cosmoM_reallocate so we can track our memory usage (it's also safer :P)
|
||||
|
@ -156,7 +156,7 @@ CObjMethod *cosmoO_newMethod(CState *state, CObjClosure *func, CObjObject *obj)
|
||||
}
|
||||
|
||||
CObjClosure *cosmoO_newClosure(CState *state, CObjFunction *func) {
|
||||
// intialize array of pointers
|
||||
// initialize array of pointers
|
||||
CObjUpval **upvalues = cosmoM_xmalloc(state, sizeof(CObjUpval*) * func->upvals);
|
||||
|
||||
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))
|
||||
return true;
|
||||
return false; // no protoobject to check against / key not founc
|
||||
return false; // no protoobject to check against / key not found
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -3,13 +3,6 @@
|
||||
|
||||
#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
|
||||
|
||||
typedef enum {
|
||||
|
10
src/cparse.c
10
src/cparse.c
@ -103,7 +103,7 @@ static void initCompilerState(CParseState* pstate, CCompilerState *ccstate, Func
|
||||
else
|
||||
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->depth = 0;
|
||||
local->isCaptured = false;
|
||||
@ -461,7 +461,7 @@ static void namedVariable(CParseState *pstate, CToken name, bool canAssign, bool
|
||||
opSet = OP_SETUPVAL;
|
||||
inc = OP_INCUPVAL;
|
||||
} else {
|
||||
// local & upvalue wasnt' found, assume it's a global!
|
||||
// local & upvalue wasn't found, assume it's a global!
|
||||
arg = identifierConstant(pstate, &name);
|
||||
opGet = OP_GETGLOBAL;
|
||||
opSet = OP_SETGLOBAL;
|
||||
@ -668,7 +668,7 @@ static void increment(CParseState *pstate, int val) {
|
||||
} else if ((arg = getUpvalue(pstate->compiler, &name)) != -1) {
|
||||
op = OP_INCUPVAL;
|
||||
} else {
|
||||
// local & upvalue wasnt' found, assume it's a global!
|
||||
// local & upvalue wasn't found, assume it's a global!
|
||||
arg = identifierConstant(pstate, &name);
|
||||
op = OP_INCGLOBAL;
|
||||
}
|
||||
@ -1164,10 +1164,10 @@ static void forLoop(CParseState *pstate) {
|
||||
|
||||
consume(pstate, TOKEN_LEFT_PAREN, "Expected '(' after 'for'");
|
||||
|
||||
// parse initalizer
|
||||
// parse initializer
|
||||
if (!match(pstate, TOKEN_EOS)) {
|
||||
expressionStatement(pstate);
|
||||
consume(pstate, TOKEN_EOS, "Expected ';' after initalizer!");
|
||||
consume(pstate, TOKEN_EOS, "Expected ';' after initializer!");
|
||||
}
|
||||
|
||||
int loopStart = getChunk(pstate)->count;
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "cosmo.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);
|
||||
|
||||
#endif
|
@ -65,7 +65,7 @@ CState *cosmoV_newState() {
|
||||
|
||||
void cosmoV_freeState(CState *state) {
|
||||
#ifdef GC_DEBUG
|
||||
printf("state %p is being free'd!\n", state);
|
||||
printf("state %p is being freed!\n", state);
|
||||
#endif
|
||||
// frees all the objects
|
||||
CObj *objs = state->objects;
|
||||
|
@ -205,7 +205,7 @@ bool cosmoT_remove(CState* state, CTable *tbl, CValue key) {
|
||||
|
||||
// crafts tombstone
|
||||
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++;
|
||||
|
||||
return true;
|
||||
|
26
src/cvm.c
26
src/cvm.c
@ -213,11 +213,11 @@ COSMOVMRESULT cosmoV_call(CState *state, int args, int nresults) {
|
||||
newObj->proto = protoObj;
|
||||
CValue ret;
|
||||
|
||||
// check if they defined an initalizer
|
||||
// check if they defined an initializer
|
||||
if (cosmoO_getIString(state, protoObj, ISTRING_INIT, &ret)) {
|
||||
invokeMethod(state, newObj, ret, args, nresults, 1);
|
||||
} else {
|
||||
// no default initalizer
|
||||
// no default initializer
|
||||
if (args != 0) {
|
||||
cosmoV_error(state, "Expected 0 parameters, got %d!", args);
|
||||
return COSMOVM_RUNTIME_ERR;
|
||||
@ -638,16 +638,16 @@ int cosmoV_execute(CState *state) {
|
||||
cosmoV_pushValue(state, cosmoV_newObj(obj));
|
||||
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)) {
|
||||
cosmoV_error(state, "Expected iterable object! '__iter' returned %s, expected object!", cosmoV_typeStr(*iobj));
|
||||
if (!IS_OBJECT(*iObj)) {
|
||||
cosmoV_error(state, "Expected iterable object! '__iter' returned %s, expected object!", cosmoV_typeStr(*iObj));
|
||||
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 {
|
||||
cosmoV_error(state, "Expected iterable object! '__iter' not defined!");
|
||||
}
|
||||
@ -711,7 +711,7 @@ int cosmoV_execute(CState *state) {
|
||||
}
|
||||
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);
|
||||
|
||||
if (!IS_OBJ(*temp) || cosmoV_readObj(*temp)->type != COBJ_DICT) {
|
||||
@ -744,7 +744,7 @@ int cosmoV_execute(CState *state) {
|
||||
break;
|
||||
}
|
||||
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();
|
||||
StkPtr val = &frame->base[indx];
|
||||
|
||||
@ -759,7 +759,7 @@ int cosmoV_execute(CState *state) {
|
||||
break;
|
||||
}
|
||||
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();
|
||||
CValue ident = constants[indx]; // grabs identifier
|
||||
CValue *val = cosmoT_insert(state, &state->globals, ident);
|
||||
@ -775,7 +775,7 @@ int cosmoV_execute(CState *state) {
|
||||
break;
|
||||
}
|
||||
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();
|
||||
CValue *val = frame->closure->upvalues[indx]->val;
|
||||
|
||||
@ -790,7 +790,7 @@ int cosmoV_execute(CState *state) {
|
||||
break;
|
||||
}
|
||||
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 key = cosmoV_getTop(state, 0); // grabs key
|
||||
|
||||
@ -836,7 +836,7 @@ int cosmoV_execute(CState *state) {
|
||||
break;
|
||||
}
|
||||
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();
|
||||
StkPtr temp = cosmoV_getTop(state, 0); // object should be at the top of the stack
|
||||
CValue ident = constants[indx]; // grabs identifier
|
||||
|
Loading…
Reference in New Issue
Block a user