Skip to content

Commit

Permalink
Merge pull request #464 from vsbogd/fix-stdlib-tokens
Browse files Browse the repository at this point in the history
Load Rust grounded tokens before stdlib is loaded
  • Loading branch information
luketpeterson authored Oct 20, 2023
2 parents 738e739 + 53023bf commit fad8565
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 @@ -171,6 +171,11 @@ impl Metta {
Ok(module_space)
},
None => {
// 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);
}

// Load the module to the new space
let runner = Metta::new_loading_runner(self, &path);
let program = match path.to_str() {
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 fad8565

Please sign in to comment.