~lattis/muon

2aadae1be36d18dbceda739c14e899461872be28 — Stone Tickle 2 days ago 3723275 master
fix subproject variable scope
3 files changed, 11 insertions(+), 2 deletions(-)

M src/functions/subproject.c
M src/lang/eval.c
M src/lang/workspace.c
M src/functions/subproject.c => src/functions/subproject.c +5 -2
@@ 21,15 21,18 @@ subproject_get_variable(struct workspace *wk, uint32_t node, obj name_id, obj fa
		return false;
	}

	bool ok = true;
	stack_push(&wk->stack, wk->vm.scope_stack, ((struct project *)arr_get(&wk->projects, sub->id))->scope_stack);
	if (!wk->vm.behavior.get_variable(wk, name, res)) {
		if (!fallback) {
			return false;
			ok = false;
		} else {
			*res = fallback;
		}
	}
	stack_pop(&wk->stack, wk->vm.scope_stack);

	return true;
	return ok;
}

static bool

M src/lang/eval.c => src/lang/eval.c +4 -0
@@ 37,6 37,8 @@ eval_project(struct workspace *wk,
	make_project(wk, &wk->cur_project, subproject_name, cwd, build_dir);
	*proj_id = wk->cur_project;

	stack_push(&wk->stack, wk->vm.scope_stack, current_project(wk)->scope_stack);

	obj parent_eval_trace = wk->vm.dbg_state.eval_trace;

	const char *parent_prefix = log_get_prefix();


@@ 46,6 48,7 @@ eval_project(struct workspace *wk,
		snprintf(log_prefix, 255, "[%s%s%s]", clr, subproject_name, no_clr);
		log_set_prefix(log_prefix);
	}

	if (subproject_name) {
		LOG_I("entering subproject '%s'", subproject_name);
	}


@@ 70,6 73,7 @@ eval_project(struct workspace *wk,
cleanup:
	wk->vm.dbg_state.eval_trace = parent_eval_trace;
	wk->cur_project = parent_project;
	stack_pop(&wk->stack, wk->vm.scope_stack);

	log_set_prefix(parent_prefix);
	return ret;

M src/lang/workspace.c => src/lang/workspace.c +2 -0
@@ 47,6 47,8 @@ make_project(struct workspace *wk, uint32_t *id, const char *subproject_name, co
	proj->build_dir = make_str(wk, build_dir);
	proj->build_root = proj->build_dir;

	proj->scope_stack = wk->vm.behavior.scope_stack_dup(wk, wk->vm.default_scope_stack);

	return proj;
}