From e0d51c191f3b178739986e1b42d4d6f1ebe8cd31 Mon Sep 17 00:00:00 2001 From: CPunch Date: Sat, 5 Dec 2020 17:55:09 -0600 Subject: [PATCH] renamed cosmoV_makeObject --- src/cbaselib.c | 11 ++++++++--- src/cosmo.h | 1 - src/cvm.c | 6 +++--- src/cvm.h | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/cbaselib.c b/src/cbaselib.c index 51039a7..171c47d 100644 --- a/src/cbaselib.c +++ b/src/cbaselib.c @@ -42,11 +42,16 @@ CValue cosmoB_dgetProto(CState *state, int nargs, CValue *args) { } void cosmoB_loadDebug(CState *state) { - cosmoV_pushString(state, "getProto"); - cosmoV_pushCFunction(state, cosmoB_dgetProto); + cosmoV_pushString(state, "getProto"); // key + cosmoV_pushCFunction(state, cosmoB_dgetProto); // value + + // another key & value cosmoV_pushString(state, "setProto"); cosmoV_pushCFunction(state, cosmoB_dsetProto); - cosmoV_pushObject(state, 2); + // we call makeObject leting it know there are 2 sets of key & value pairs on the stack (4 values total) + cosmoV_makeObject(state, 2); + + // set debug proto to the debug object state->protoObj = cosmoV_readObject(*cosmoV_pop(state)); } \ No newline at end of file diff --git a/src/cosmo.h b/src/cosmo.h index fad59bc..7ee9b36 100644 --- a/src/cosmo.h +++ b/src/cosmo.h @@ -26,7 +26,6 @@ typedef struct CObjFunction CObjFunction; typedef struct CObjCFunction CObjCFunction; typedef struct CObjMethod CObjMethod; typedef struct CObjObject CObjObject; -typedef struct CObjClass CObjClass; typedef struct CObjClosure CObjClosure; typedef uint8_t INSTRUCTION; diff --git a/src/cvm.c b/src/cvm.c index a935654..633384d 100644 --- a/src/cvm.c +++ b/src/cvm.c @@ -182,7 +182,7 @@ COSMOVMRESULT cosmoV_call(CState *state, int args) { invokeMethod(state, method->obj, method->func, args); break; } - case COBJ_OBJECT: { + case COBJ_OBJECT: { // object is being instantiated, making another object CObjObject *protoObj = (CObjObject*)cosmoV_readObj(*val); CObjObject *newObj = cosmoO_newObject(state); newObj->proto = protoObj; @@ -221,7 +221,7 @@ static inline bool isFalsey(StkPtr val) { return IS_NIL(*val) || (IS_BOOLEAN(*val) && !cosmoV_readBoolean(*val)); } -COSMO_API void cosmoV_pushObject(CState *state, int pairs) { +COSMO_API void cosmoV_makeObject(CState *state, int pairs) { StkPtr key, val; CObjObject *newObj = cosmoO_newObject(state); cosmoV_pushValue(state, cosmoV_newObj(newObj)); // so our GC doesn't free our new object @@ -385,7 +385,7 @@ bool cosmoV_execute(CState *state) { } case OP_NEWOBJECT: { uint16_t pairs = READUINT(); - cosmoV_pushObject(state, pairs); + cosmoV_makeObject(state, pairs); break; } case OP_GETOBJECT: { diff --git a/src/cvm.h b/src/cvm.h index 4175b8c..9e43754 100644 --- a/src/cvm.h +++ b/src/cvm.h @@ -14,7 +14,7 @@ typedef enum { // args = # of pass parameters, nresults = # of expected results COSMO_API COSMOVMRESULT cosmoV_call(CState *state, int args); -COSMO_API void cosmoV_pushObject(CState *state, int pairs); +COSMO_API void cosmoV_makeObject(CState *state, int pairs); COSMO_API bool cosmoV_getObject(CState *state, CObjObject *object, CValue key, CValue *val); COSMO_API void cosmoV_error(CState *state, const char *format, ...);