Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/steel-core/src/compiler/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,10 @@ impl CompiledModule {
}
}

pub fn dependent_modules(&self) -> &[PathBuf] {
&self.downstream
}

// TODO: Should cache this
pub fn prefix(&self) -> CompactString {
self.cached_prefix.clone()
Expand Down
2 changes: 1 addition & 1 deletion crates/steel-core/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct Env {
#[cfg(not(feature = "sync"))]
pub(crate) bindings_vec: Vec<SteelVal>,
#[cfg(feature = "sync")]
bindings: SharedVectorWrapper,
pub(crate) bindings: SharedVectorWrapper,
}

#[cfg(feature = "sync")]
Expand Down
46 changes: 46 additions & 0 deletions crates/steel-core/src/steel_vm/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use crate::{
values::{
closed::GlobalSlotRecycler,
functions::{BoxedDynFunction, ByteCodeLambda},
reachable::GlobalSlotReacher,
},
SteelErr,
};
Expand Down Expand Up @@ -2749,6 +2750,51 @@ fn test_raw_engine() {
}

#[test]
fn namespace_querying() {
let mut engine = Engine::new();

let module = PathBuf::from("#%private/steel/contract");

let guard = engine.virtual_machine.compiler.read();
let compiled_module = guard.module_manager.modules().get(&module).unwrap();
let module_name: InternedString = format!("__module-{}", compiled_module.prefix()).into();
let index = guard.symbol_map.get(&module_name).unwrap();
let value = engine
.virtual_machine
.global_env
.repl_maybe_lookup_idx(index)
.unwrap();

if let SteelVal::HashMapV(h) = value {
let mut roots = Vec::new();

for (key, value) in h.iter() {
roots.push(value.clone());
}

let reachable_globals = GlobalSlotReacher::find_reachable(
engine.virtual_machine.global_env.roots(),
&mut roots,
);

// Module -> Set<GlobalIndex>
//
// GlobalIndex (old) -> GlobalIndex (new)
//
// Patch old values into new environment
//
// Global Slot Renamer
//
// Iterates over everything, renames the indexes to the new spots.

println!("{:#?}", reachable_globals);

// None
} else {
// return None;
}
}

fn test_ctx_func() {
let mut engine = Engine::new();

Expand Down
9 changes: 7 additions & 2 deletions crates/steel-core/src/steel_vm/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ use crate::{
steel_vm::{
builtin::{get_function_metadata, get_function_name, BuiltInFunctionType},
vm::{
threads::threading_module, GET_MODULE_CONTEXT_DEFINITION,
threads::threading_module, EVAL_WITH_NAMESPACE_DEFINITION,
GET_MODULE_CONTEXT_DEFINITION, MAKE_NAMESPACE_DEFINITION, NAMESPACE_REQUIRE_DEFINITION,
POP_MODULE_CONTEXT_DEFINITION, PUSH_MODULE_CONTEXT_DEFINITION,
},
},
Expand Down Expand Up @@ -2344,7 +2345,11 @@ fn meta_module() -> BuiltInModule {
module
.register_native_fn_definition(WILL_EXECUTE_DEFINITION)
.register_native_fn_definition(WILL_REGISTER_DEFINITION)
.register_native_fn_definition(MAKE_WILL_EXECUTOR_DEFINITION);
.register_native_fn_definition(MAKE_WILL_EXECUTOR_DEFINITION)
// EVAL WITH NAMESPACE STUFF
.register_native_fn_definition(MAKE_NAMESPACE_DEFINITION)
.register_native_fn_definition(NAMESPACE_REQUIRE_DEFINITION)
.register_native_fn_definition(EVAL_WITH_NAMESPACE_DEFINITION);

#[cfg(not(feature = "dylibs"))]
module.register_native_fn_definition(super::engine::LOAD_MODULE_NOOP_DEFINITION);
Expand Down
Loading
Loading