mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-22 07:20:05 +00:00
Minor refactoring, fixed 'or' and 'and' logical operators
This commit is contained in:
parent
e699005a74
commit
c82a01c968
@ -9,8 +9,8 @@ typedef enum {
|
|||||||
COBJ_TABLE,
|
COBJ_TABLE,
|
||||||
COBJ_FUNCTION,
|
COBJ_FUNCTION,
|
||||||
COBJ_CFUNCTION,
|
COBJ_CFUNCTION,
|
||||||
COBJ_ERROR,
|
|
||||||
// internal use
|
// internal use
|
||||||
|
COBJ_ERROR,
|
||||||
COBJ_METHOD,
|
COBJ_METHOD,
|
||||||
COBJ_CLOSURE,
|
COBJ_CLOSURE,
|
||||||
COBJ_UPVALUE,
|
COBJ_UPVALUE,
|
||||||
@ -152,12 +152,7 @@ CObjUpval *cosmoO_newUpvalue(CState *state, CValue *val);
|
|||||||
|
|
||||||
// grabs the base proto of the CObj* (if CObj is a CObjObject, that is returned)
|
// grabs the base proto of the CObj* (if CObj is a CObjObject, that is returned)
|
||||||
static inline CObjObject *cosmoO_grabProto(CObj *obj) {
|
static inline CObjObject *cosmoO_grabProto(CObj *obj) {
|
||||||
CObjObject *object = obj->proto;
|
return obj->type == COBJ_OBJECT ? (CObjObject*)obj : obj->proto;
|
||||||
|
|
||||||
if (obj->type == COBJ_OBJECT)
|
|
||||||
object = (CObjObject*)obj;
|
|
||||||
|
|
||||||
return object;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cosmoO_getRawObject(CState *state, CObjObject *proto, CValue key, CValue *val, CObj *obj);
|
bool cosmoO_getRawObject(CState *state, CObjObject *proto, CValue key, CValue *val, CObj *obj);
|
||||||
|
@ -573,6 +573,7 @@ static void and_(CParseState *pstate, bool canAssign, Precedence prec) {
|
|||||||
int jump = writeJmp(pstate, OP_EJMP); // conditional jump without popping
|
int jump = writeJmp(pstate, OP_EJMP); // conditional jump without popping
|
||||||
|
|
||||||
writePop(pstate, 1);
|
writePop(pstate, 1);
|
||||||
|
valuePopped(pstate, 1);
|
||||||
expressionPrecedence(pstate, 1, PREC_AND, true);
|
expressionPrecedence(pstate, 1, PREC_AND, true);
|
||||||
|
|
||||||
patchJmp(pstate, jump);
|
patchJmp(pstate, jump);
|
||||||
@ -584,6 +585,7 @@ static void or_(CParseState *pstate, bool canAssign, Precedence prec) {
|
|||||||
|
|
||||||
patchJmp(pstate, elseJump);
|
patchJmp(pstate, elseJump);
|
||||||
writePop(pstate, 1);
|
writePop(pstate, 1);
|
||||||
|
valuePopped(pstate, 1);
|
||||||
|
|
||||||
expressionPrecedence(pstate, 1, PREC_OR, true);
|
expressionPrecedence(pstate, 1, PREC_OR, true);
|
||||||
|
|
||||||
|
@ -286,7 +286,9 @@ static bool rawCall(CState *state, CObjClosure *closure, int args, int nresults,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// push the return values back onto the stack
|
// push the return values back onto the stack
|
||||||
memmove(state->top, results, sizeof(CValue) * nres); // copies the return values to the top of the stack
|
for (int i = 0; i < nres; i++) {
|
||||||
|
state->top[i] = results[i];
|
||||||
|
}
|
||||||
state->top += nres; // and make sure to move state->top to match
|
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
|
// now, if the caller function expected more return values, push nils onto the stack
|
||||||
@ -304,7 +306,7 @@ bool callCValue(CState *state, CValue func, int args, int nresults, int offset)
|
|||||||
printf("()\n");
|
printf("()\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (GET_TYPE(func) != COSMO_TOBJ) {
|
if (!IS_OBJ(func)) {
|
||||||
cosmoV_error(state, "Cannot call non-function type %s!", cosmoV_typeStr(func));
|
cosmoV_error(state, "Cannot call non-function type %s!", cosmoV_typeStr(func));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -348,7 +350,7 @@ bool callCValue(CState *state, CValue func, int args, int nresults, int offset)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
cosmoV_error(state, "Cannot call non-function value %s!", cosmoV_typeStr(func));
|
cosmoV_error(state, "Cannot call non-function type %s!", cosmoV_typeStr(func));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user