diff --git a/crates/steel-core/src/compiler/modules.rs b/crates/steel-core/src/compiler/modules.rs index 095d6dbf5..80117dae9 100644 --- a/crates/steel-core/src/compiler/modules.rs +++ b/crates/steel-core/src/compiler/modules.rs @@ -497,6 +497,8 @@ impl ModuleManager { // TODO: If there is a prefix applied, use it here? if let Some(prefix) = &require_object.prefix { + // println!("Found prefix: {}", prefix); + if let Some(existing) = owned_provide.atom_identifier_mut() { let mut prefixed_identifier = prefix.clone(); prefixed_identifier.push_str(existing.resolve()); @@ -512,6 +514,8 @@ impl ModuleManager { SyntaxObject::default(TokenType::Define), ))); + // println!("{}", define); + require_defines.push(define); } _ => { @@ -1120,6 +1124,7 @@ impl CompiledModule { // Mangle with a prefix if necessary let mut provide = provide.clone(); + let mut raw_provide = provide.clone(); // If we have the alias listed, we should use it if !explicit_requires.is_empty() { @@ -1155,13 +1160,17 @@ impl CompiledModule { ExprKind::ident("%proto-hash-get%"), ExprKind::atom("__module-".to_string() + &other_module_prefix), ExprKind::Quote(Box::new(Quote::new( - provide.clone(), + raw_provide.clone(), SyntaxObject::default(TokenType::Quote) ))) ], SyntaxObject::default(TokenType::Define), ))); + // if require_object.prefix.is_some() { + // println!("{}", define); + // } + provide_definitions.push(define); } _ => { diff --git a/crates/steel-core/src/primitives/hashmaps.rs b/crates/steel-core/src/primitives/hashmaps.rs index f92252b1e..7cfde8ff9 100644 --- a/crates/steel-core/src/primitives/hashmaps.rs +++ b/crates/steel-core/src/primitives/hashmaps.rs @@ -154,7 +154,7 @@ pub fn hash_ref(map: &Gc>, key: &SteelVal) -> Result if key.is_hashable() { match map.get(key) { Some(value) => Ok(value.clone()), - None => stop!(Generic => "key not found in hash map: {}", key), + None => stop!(Generic => "key not found in hash map: {} - map: {:?}", key, map), } } else { stop!(TypeMismatch => "key not hashable: {}", key) diff --git a/crates/steel-core/src/steel_vm/engine.rs b/crates/steel-core/src/steel_vm/engine.rs index d287cff9d..f26d3dc00 100644 --- a/crates/steel-core/src/steel_vm/engine.rs +++ b/crates/steel-core/src/steel_vm/engine.rs @@ -1029,11 +1029,11 @@ impl Engine { self.with_mut_reference(obj).consume(|engine, args| { let mut args = args.into_iter(); - engine.register_value(bind_to, args.next().unwrap()); + engine.update_value(bind_to, args.next().unwrap()); let res = engine.compile_and_run_raw_program(script); - engine.register_value(bind_to, SteelVal::Void); + engine.update_value(bind_to, SteelVal::Void); res.map(|x| x.into_iter().next().unwrap()) }) @@ -1057,11 +1057,11 @@ impl Engine { self.with_mut_reference(obj).consume(move |engine, args| { let mut args = args.into_iter(); - engine.register_value(bind_to, args.next().unwrap()); + engine.update_value(bind_to, args.next().unwrap()); let res = engine.compile_and_run_raw_program_with_path(script, path.clone()); - engine.register_value(bind_to, SteelVal::Void); + engine.update_value(bind_to, SteelVal::Void); res.map(|x| x.into_iter().next().unwrap()) }) @@ -1573,6 +1573,12 @@ impl Engine { // self } + pub fn update_value(&mut self, name: &str, value: SteelVal) -> Option<&mut Self> { + let idx = self.compiler.get_idx(name)?; + self.virtual_machine.global_env.repl_set_idx(idx, value); + Some(self) + } + /// Registers multiple values at once pub fn register_values( &mut self, @@ -2092,6 +2098,7 @@ mod engine_api_tests { let mut engine = Engine::new(); let mut external_object = ReferenceStruct { value: 10 }; + engine.register_value("*external*", SteelVal::Void); engine.register_fn("external-get-value", ReferenceStruct::get_value); { @@ -2112,6 +2119,7 @@ mod engine_api_tests { let mut engine = Engine::new(); let mut external_object = ReferenceStruct { value: 10 }; + engine.register_value("*external*", SteelVal::Void); engine.register_fn("external-get-value", ReferenceStruct::get_value); let res = engine