Skip to content

Commit

Permalink
fix global var
Browse files Browse the repository at this point in the history
  • Loading branch information
boomyl committed Oct 12, 2021
1 parent b9d54aa commit fb4c984
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions compiler/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ add_global_variable(Compiler *compiler, SVM_Executable *exe)
}

int var_index = get_label(ob);
dl->variable_index = var_index;
set_label(ob, var_index);
var_count++;
}
Expand Down Expand Up @@ -544,18 +545,20 @@ generate_identifier(SVM_Executable *cf, IdentifierExpression *identifier_expr,
Declaration *decl = identifier_expr->u.declaration;
if (!decl->is_local) {
OpcodeBuf *ob_alt = cf->ob_alt;
for(int i = 0; i <= ob_alt->pc - identifier_pc; i++) {
for(int i = 0; i < ob_alt->pc - decl->variable_index; i++) {
generate_code(ob, OP_FROMALTSTACK);
ob->pc--;
}
generate_code(ob, OP_DUP);
for(int i = 0; i <= ob_alt->pc - identifier_pc; i++) {
for(int i = 0; i < ob_alt->pc - decl->variable_index; i++) {
generate_code(ob, OP_SWAP);
generate_code(ob, OP_TOALTSTACK);
ob->pc -= 2;
}
return;
}

int depth = ob->pc - identifier_pc - 1;
int depth = ob->pc - decl->pc - 1;
switch (depth) {
case -1:
break;
Expand Down

0 comments on commit fb4c984

Please sign in to comment.