mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-12-04 22:46:31 +00:00
Compare commits
2 Commits
9c5270124d
...
1d2ba217af
Author | SHA1 | Date | |
---|---|---|---|
1d2ba217af | |||
e28ffe1c6c |
@ -10,7 +10,9 @@
|
|||||||
// realloc wrapper
|
// realloc wrapper
|
||||||
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)
|
||||||
{
|
{
|
||||||
if (buf == NULL) oldSize = 0;
|
if (buf == NULL)
|
||||||
|
oldSize = 0;
|
||||||
|
|
||||||
#ifdef GC_DEBUG
|
#ifdef GC_DEBUG
|
||||||
printf("old allocated bytes: %ld\n", state->allocatedBytes);
|
printf("old allocated bytes: %ld\n", state->allocatedBytes);
|
||||||
if (buf) {
|
if (buf) {
|
||||||
|
25
src/cobj.c
25
src/cobj.c
@ -188,10 +188,10 @@ CObjObject *cosmoO_newObject(CState *state)
|
|||||||
obj->userP = NULL; // reserved for C API
|
obj->userP = NULL; // reserved for C API
|
||||||
obj->userT = 0;
|
obj->userT = 0;
|
||||||
obj->isLocked = false;
|
obj->isLocked = false;
|
||||||
|
|
||||||
cosmoV_pushRef(state, (CObj *)obj); // so our GC can keep track of it
|
cosmoV_pushRef(state, (CObj *)obj); // so our GC can keep track of it
|
||||||
cosmoT_initTable(state, &obj->tbl, ARRAY_START);
|
cosmoT_initTable(state, &obj->tbl, ARRAY_START);
|
||||||
cosmoV_pop(state);
|
cosmoV_pop(state);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -698,60 +698,61 @@ int cosmoO_count(CState *state, CObj *obj)
|
|||||||
|
|
||||||
void printObject(CObj *o)
|
void printObject(CObj *o)
|
||||||
{
|
{
|
||||||
|
printf("%s ", cosmoO_typeStr(o));
|
||||||
switch (o->type) {
|
switch (o->type) {
|
||||||
case COBJ_STRING: {
|
case COBJ_STRING: {
|
||||||
CObjString *objStr = (CObjString *)o;
|
CObjString *objStr = (CObjString *)o;
|
||||||
printf("<string> \"%.*s\"", objStr->length, objStr->str);
|
printf("\"%.*s\"", objStr->length, objStr->str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case COBJ_OBJECT: {
|
case COBJ_OBJECT: {
|
||||||
printf("<obj> %p", (void *)o);
|
printf("%p", (void *)o);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case COBJ_TABLE: {
|
case COBJ_TABLE: {
|
||||||
CObjTable *tbl = (CObjTable *)o;
|
CObjTable *tbl = (CObjTable *)o;
|
||||||
printf("<tbl> %p", (void *)tbl);
|
printf("%p", (void *)tbl);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case COBJ_FUNCTION: {
|
case COBJ_FUNCTION: {
|
||||||
CObjFunction *objFunc = (CObjFunction *)o;
|
CObjFunction *objFunc = (CObjFunction *)o;
|
||||||
if (objFunc->name != NULL)
|
if (objFunc->name != NULL)
|
||||||
printf("<function> %.*s", objFunc->name->length, objFunc->name->str);
|
printf("%.*s", objFunc->name->length, objFunc->name->str);
|
||||||
else
|
else
|
||||||
printf("<function> %s", UNNAMEDCHUNK);
|
printf("%s", UNNAMEDCHUNK);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case COBJ_CFUNCTION: {
|
case COBJ_CFUNCTION: {
|
||||||
CObjCFunction *objCFunc = (CObjCFunction *)o;
|
CObjCFunction *objCFunc = (CObjCFunction *)o;
|
||||||
printf("<c function> %p", (void *)objCFunc->cfunc);
|
printf("%p", (void *)objCFunc->cfunc);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case COBJ_ERROR: {
|
case COBJ_ERROR: {
|
||||||
CObjError *err = (CObjError *)o;
|
CObjError *err = (CObjError *)o;
|
||||||
printf("<error> %p -> ", (void *)o);
|
printf("%p -> ", (void *)o);
|
||||||
printValue(err->err);
|
printValue(err->err);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case COBJ_METHOD: {
|
case COBJ_METHOD: {
|
||||||
CObjMethod *method = (CObjMethod *)o;
|
CObjMethod *method = (CObjMethod *)o;
|
||||||
printf("<method> %p -> ", (void *)method);
|
printf("%p -> ", (void *)method);
|
||||||
printValue(method->func);
|
printValue(method->func);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case COBJ_CLOSURE: {
|
case COBJ_CLOSURE: {
|
||||||
CObjClosure *closure = (CObjClosure *)o;
|
CObjClosure *closure = (CObjClosure *)o;
|
||||||
printf("<closure> %p -> ", (void *)closure);
|
printf("%p -> ", (void *)closure);
|
||||||
printObject((CObj *)closure->function); // just print the function
|
printObject((CObj *)closure->function); // just print the function
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case COBJ_UPVALUE: {
|
case COBJ_UPVALUE: {
|
||||||
CObjUpval *upval = (CObjUpval *)o;
|
CObjUpval *upval = (CObjUpval *)o;
|
||||||
printf("<upvalue> %p -> ", (void *)upval->val);
|
printf("%p -> ", (void *)upval->val);
|
||||||
printValue(*upval->val);
|
printValue(*upval->val);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
printf("<unkn obj %p>", (void *)o);
|
printf("%p", (void *)o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user