Skip to content

Commit

Permalink
Load Rust grounded tokens before stdlib is loaded
Browse files Browse the repository at this point in the history
Otherwise grounded values and function in stdlib code are not resolved
and stay pure symbols.
  • Loading branch information
vsbogd committed Oct 20, 2023
1 parent 738e739 commit 9bc4331
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/src/metta/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ impl Metta {
log::debug!("Metta::load_module_space: load module space {}", path.display());
let loaded_module = self.0.modules.borrow().get(&path).cloned();

// TODO: This is a hack. We need a way to register tokens at module-load-time, for any module
if path.to_str().unwrap() == "stdlib" {
register_rust_tokens(self);
}

// Loading the module only once
// TODO: force_reload?
match loaded_module {
Expand All @@ -184,11 +189,6 @@ impl Metta {
runner.run(SExprParser::new(program.as_str()))
.map_err(|err| format!("Cannot import module, path: {}, error: {}", path.display(), err))?;

// TODO: This is a hack. We need a way to register tokens at module-load-time, for any module
if path.to_str().unwrap() == "stdlib" {
register_rust_tokens(self);
}

Ok(runner.space().clone())
}
}
Expand Down
5 changes: 5 additions & 0 deletions lib/src/metta/runner/stdlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1592,4 +1592,9 @@ mod tests {
let result = GetStateOp{}.execute(&mut vec![new_state.clone()]);
assert_eq!(result, Ok(vec![expr!("C" "D")]))
}

#[test]
fn test_stdlib_uses_rust_grounded_tokens() {
assert_eq!(run_program("!(if True ok nok)"), Ok(vec![vec![Atom::sym("ok")]]));
}
}

0 comments on commit 9bc4331

Please sign in to comment.