mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-22 15:30:06 +00:00
better support for OP_INCOBJECT
This commit is contained in:
parent
46b99ab390
commit
85e7deae7b
13
src/cparse.c
13
src/cparse.c
@ -644,13 +644,22 @@ static void increment(CParseState *pstate, int val) {
|
|||||||
CToken name = pstate->previous;
|
CToken name = pstate->previous;
|
||||||
if (match(pstate, TOKEN_DOT)) { // object?
|
if (match(pstate, TOKEN_DOT)) { // object?
|
||||||
namedVariable(pstate, name, false, false); // just get the object
|
namedVariable(pstate, name, false, false); // just get the object
|
||||||
|
consume(pstate, TOKEN_IDENTIFIER, "Expected property name after '.'.");
|
||||||
|
uint16_t ident = identifierConstant(pstate, &pstate->previous);
|
||||||
|
|
||||||
|
while (match(pstate, TOKEN_DOT)) {
|
||||||
|
// grab the field from the object
|
||||||
|
writeu8(pstate, OP_LOADCONST); // pushes ident to stack
|
||||||
|
writeu16(pstate, ident);
|
||||||
|
writeu8(pstate, OP_GETOBJECT);
|
||||||
|
|
||||||
consume(pstate, TOKEN_IDENTIFIER, "Expected property name after '.'.");
|
consume(pstate, TOKEN_IDENTIFIER, "Expected property name after '.'.");
|
||||||
uint16_t name = identifierConstant(pstate, &pstate->previous);
|
ident = identifierConstant(pstate, &pstate->previous);
|
||||||
|
}
|
||||||
|
|
||||||
writeu8(pstate, OP_INCOBJECT);
|
writeu8(pstate, OP_INCOBJECT);
|
||||||
writeu8(pstate, 128 + val); // setting signed values in an unsigned int
|
writeu8(pstate, 128 + val); // setting signed values in an unsigned int
|
||||||
writeu16(pstate, name);
|
writeu16(pstate, ident);
|
||||||
valuePopped(pstate, 1); // popped the object off the stack
|
valuePopped(pstate, 1); // popped the object off the stack
|
||||||
} else {
|
} else {
|
||||||
uint8_t op;
|
uint8_t op;
|
||||||
|
Loading…
Reference in New Issue
Block a user