Change so that var definitions can be a module's return value (#6504)

* Change so that var definitions can be a module's return value

* Change car wheel assembly to use the new return mechanism

* Add sim test

* Update output

* Update module docs

* Add safety check to only work with modules

* Fix to use updated keyword args
This commit is contained in:
Jonathan Tran
2025-04-25 17:55:54 -04:00
committed by GitHub
parent 717a2039cb
commit f8e53d941d
18 changed files with 669 additions and 20 deletions

View File

@ -278,7 +278,7 @@ impl ExecutorContext {
let annotations = &variable_declaration.outer_attrs;
let memory_item = self
let value = self
.execute_expr(
&variable_declaration.declaration.init,
exec_state,
@ -289,13 +289,14 @@ impl ExecutorContext {
.await?;
exec_state
.mut_stack()
.add(var_name.clone(), memory_item, source_range)?;
.add(var_name.clone(), value.clone(), source_range)?;
// Track exports.
if let ItemVisibility::Export = variable_declaration.visibility {
exec_state.mod_local.module_exports.push(var_name);
}
last_expr = None;
// Variable declaration can be the return value of a module.
last_expr = matches!(body_type, BodyType::Root).then_some(value);
}
BodyItem::TypeDeclaration(ty) => {
let metadata = Metadata::from(&**ty);