Browse Source

Optimized uasm.c:popScope()

remotes/origin/HEAD
Seth Stubbs 5 months ago
parent
commit
b6403825f9
  1. 2
      src/main.c
  2. 10
      src/uasm.c
  3. 2
      src/ulex.h

2
src/main.c

@ -5,7 +5,7 @@ int main() {
UASTRootNode *tree = UP_parseSource(
"int i = 0;\n"
"while (i != 10) {\n"
" prntint i;"
" prntint i;\n"
" i = i + 1;\n"
"}\n"
);

10
src/uasm.c

@ -143,9 +143,13 @@ void pushScope(UCompState *state, UScope *scope) {
void popScope(UCompState *state) {
UScope *scope = state->scopes[--state->sCount];
writeIntLit(state, getScopeSize(state, scope));
fwrite(";dealloc-uxncle JSR2\n", 21, 1, state->out);
state->pushed -= SIZE_INT;
int scopeSize = getScopeSize(state, scope);
if (scopeSize != 0) {
writeIntLit(state, scopeSize);
fwrite(";dealloc-uxncle JSR2\n", 21, 1, state->out);
state->pushed -= SIZE_INT;
}
}
uint16_t getOffset(UCompState *state, int scope, int var) {

2
src/ulex.h

@ -7,10 +7,10 @@ typedef enum {
TOKEN_INT,
TOKEN_VOID,
TOKEN_BOOL,
TOKEN_WHILE,
TOKEN_PRINTINT,
TOKEN_IF,
TOKEN_ELSE,
TOKEN_WHILE,
/* literals */
TOKEN_IDENT,

Loading…
Cancel
Save