fix scope resolution
This commit is contained in:
@@ -32509,13 +32509,25 @@ static cJSON *mach_gen_program (MachGenState *s, cJSON *ast) {
|
||||
mach_scan_vars (s, stmt);
|
||||
}
|
||||
|
||||
/* Pre-register function names as local variables (hoisting) */
|
||||
cJSON *functions = cJSON_GetObjectItem (ast, "functions");
|
||||
cJSON *func_node;
|
||||
cJSON_ArrayForEach (func_node, functions) {
|
||||
cJSON *name_obj = cJSON_GetObjectItem (func_node, "name");
|
||||
if (name_obj && cJSON_IsString (name_obj)) {
|
||||
const char *name = cJSON_GetStringValue (name_obj);
|
||||
if (!mach_find_var_info (s, name)) {
|
||||
int slot = 1 + s->nr_args + s->nr_local_slots++;
|
||||
mach_add_var (s, name, slot, MACH_VAR_LOCAL, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Adjust temp slot start after all locals are allocated */
|
||||
s->next_temp_slot = 1 + s->nr_local_slots;
|
||||
if (s->next_temp_slot > s->max_slot) s->max_slot = s->next_temp_slot;
|
||||
|
||||
/* Process top-level function declarations */
|
||||
cJSON *functions = cJSON_GetObjectItem (ast, "functions");
|
||||
cJSON *func_node;
|
||||
cJSON_ArrayForEach (func_node, functions) {
|
||||
cJSON *name_obj = cJSON_GetObjectItem (func_node, "name");
|
||||
if (name_obj && cJSON_IsString (name_obj)) {
|
||||
|
||||
Reference in New Issue
Block a user