xo-interpreter2: global variable refs working in utest

This commit is contained in:
Roland Conybeare 2026-02-17 15:01:46 -05:00
commit 6bf4378132
2 changed files with 20 additions and 9 deletions

View file

@ -113,6 +113,8 @@ namespace xo {
return VsmResultExt();
}
reader_.reset_result();
auto [expr, remaining, error1]
= reader_.read_expr(input, eof);
@ -392,12 +394,21 @@ namespace xo {
Binding b = var->path();
if (!local_env_) {
// need lookup on global_env_
assert(false);
if (local_env_) {
auto value = local_env_->lookup_value(b);
if (value) {
this->value_ = VsmResult(value);
this->pc_ = this->cont_;
this->cont_ = VsmInstr::c_sentinel;
return;
}
}
auto value = local_env_->lookup_value(b);
// no local binding. perhaps there's a global binding
auto value = global_env_->lookup_value(b);
if (value) {
this->value_ = VsmResult(value);
@ -407,7 +418,7 @@ namespace xo {
return;
}
// no binding
// no local or global binding
auto error = DRuntimeError::make(mm_.to_op(),
"_do_eval_varref_op",

View file

@ -391,9 +391,11 @@ namespace xo {
vsm.begin_interactive_session();
span_type input = span_type::from_cstr("def foo = 3.14159; foo");
span_type input = span_type::from_cstr("def foo = 3.14159; foo;");
for (int i_expr = 0; i_expr < 2; ++i_expr) {
log && log(xtag("input", input));
VsmResultExt res
= vsm.read_eval_print(input, eof_flag);
@ -414,14 +416,12 @@ namespace xo {
} else if (i_expr == 1) {
auto x = obj<AGCObject,DFloat>::from(*res.value());
REQUIRE(x);
REQUIRE(x->value() == 3.14159);
REQUIRE_THAT(x->value(), WithinAbs(3.14159, 1e-6));
REQUIRE(res.remaining_.size() == 1);
REQUIRE(*res.remaining_.lo() == '\n');
input = res.remaining_;
}
++i_expr;
}
log && vsm_fixture.log_memory_layout(&log);