From 85e7deae7bf25306e2e5c000b1fa09b6bf52e08c Mon Sep 17 00:00:00 2001 From: CPunch Date: Fri, 20 Nov 2020 14:50:43 -0600 Subject: [PATCH] better support for OP_INCOBJECT --- src/cmem.h | 2 +- src/cparse.c | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/cmem.h b/src/cmem.h index 58b7734..459a28b 100644 --- a/src/cmem.h +++ b/src/cmem.h @@ -42,7 +42,7 @@ #define cosmoM_freezeGC(state) \ state->freezeGC++ -#define cosmoM_unfreezeGC(state) \ +#define cosmoM_unfreezeGC(state) \ state->freezeGC--; \ cosmoM_checkGarbage(state, 0) diff --git a/src/cparse.c b/src/cparse.c index 56dbe73..8710125 100644 --- a/src/cparse.c +++ b/src/cparse.c @@ -644,13 +644,22 @@ static void increment(CParseState *pstate, int val) { CToken name = pstate->previous; if (match(pstate, TOKEN_DOT)) { // object? namedVariable(pstate, name, false, false); // just get the object - consume(pstate, TOKEN_IDENTIFIER, "Expected property name after '.'."); - uint16_t name = identifierConstant(pstate, &pstate->previous); + 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 '.'."); + ident = identifierConstant(pstate, &pstate->previous); + } writeu8(pstate, OP_INCOBJECT); 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 } else { uint8_t op;