mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-05 00:00:10 +00:00
optimized OP_INVOKE, embedded the identifier in the instruction
This commit is contained in:
parent
1351ff63b1
commit
c5ee704317
@ -32,6 +32,11 @@ int u8u16OperandInstruction(const char *name, CChunk *chunk, int offset) {
|
||||
return offset + 4; // op + u8 + u16
|
||||
}
|
||||
|
||||
int u8u8u16OperandInstruction(const char *name, CChunk *chunk, int offset) {
|
||||
printf("%-16s [%03d] [%03d] [%05d]", name, readu8Chunk(chunk, offset + 1), readu8Chunk(chunk, offset + 2), readu16Chunk(chunk, offset + 3));
|
||||
return offset + 5; // op + u8 + u8 + u16
|
||||
}
|
||||
|
||||
int constInstruction(const char *name, CChunk *chunk, int offset) {
|
||||
int index = readu16Chunk(chunk, offset + 1);
|
||||
printf("%-16s [%05d] - ", name, index);
|
||||
@ -131,7 +136,7 @@ int disasmInstr(CChunk *chunk, int offset, int indent) {
|
||||
case OP_SETOBJECT:
|
||||
return constInstruction("OP_SETOBJECT", chunk, offset);
|
||||
case OP_INVOKE:
|
||||
return u8u8OperandInstruction("OP_INVOKE", chunk, offset);
|
||||
return u8u8u16OperandInstruction("OP_INVOKE", chunk, offset);
|
||||
case OP_ITER:
|
||||
return simpleInstruction("OP_ITER", offset);
|
||||
case OP_NEXT:
|
||||
|
@ -667,12 +667,11 @@ static void dot(CParseState *pstate, bool canAssign, Precedence prec) {
|
||||
writeu8(pstate, 128 - 1);
|
||||
writeu16(pstate, name);
|
||||
} else if (match(pstate, TOKEN_LEFT_PAREN)) { // it's an invoked call
|
||||
writeu8(pstate, OP_LOADCONST);
|
||||
writeu16(pstate, name);
|
||||
uint8_t args = parseArguments(pstate);
|
||||
writeu8(pstate, OP_INVOKE);
|
||||
writeu8(pstate, args);
|
||||
writeu8(pstate, pstate->compiler->expectedValues);
|
||||
writeu16(pstate, name);
|
||||
valuePopped(pstate, args+1); // args + function
|
||||
valuePushed(pstate, pstate->compiler->expectedValues);
|
||||
} else {
|
||||
|
10
src/cvm.c
10
src/cvm.c
@ -760,8 +760,8 @@ int cosmoV_execute(CState *state) {
|
||||
CValue val; // to hold our value
|
||||
uint8_t args = READBYTE();
|
||||
uint8_t nres = READBYTE();
|
||||
StkPtr key = cosmoV_getTop(state, args); // grabs key from stack
|
||||
StkPtr temp = cosmoV_getTop(state, args+1); // grabs object from stack
|
||||
uint16_t ident = READUINT();
|
||||
StkPtr temp = cosmoV_getTop(state, args); // grabs object from stack
|
||||
|
||||
// sanity check
|
||||
if (IS_OBJ(*temp)) {
|
||||
@ -769,7 +769,7 @@ int cosmoV_execute(CState *state) {
|
||||
case COBJ_DICT: { // again, syntax sugar ("""""namespaces""""")
|
||||
CObjDict *dict = (CObjDict*)cosmoV_readObj(*temp);
|
||||
|
||||
cosmoT_get(&dict->tbl, *key, &val);
|
||||
cosmoT_get(&dict->tbl, constants[ident], &val);
|
||||
|
||||
// call closure/cfunction
|
||||
if (!callCValue(state, val, args, nres, -1))
|
||||
@ -784,10 +784,10 @@ int cosmoV_execute(CState *state) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cosmoO_getRawObject(state, object, *key, &val); // we use cosmoO_getRawObject instead of the wrapper so we get the raw value from the object instead of the CObjMethod wrapper
|
||||
cosmoO_getRawObject(state, object, constants[ident], &val); // we use cosmoO_getRawObject instead of the wrapper so we get the raw value from the object instead of the CObjMethod wrapper
|
||||
|
||||
// now invoke the method!
|
||||
invokeMethod(state, cosmoV_readObj(*temp), val, args, nres, 0);
|
||||
invokeMethod(state, cosmoV_readObj(*temp), val, args, nres, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user