Generate a complete WAT file based on the specified fragments.
(&self)
| 1507 | impl Declarations { |
| 1508 | /// Generate a complete WAT file based on the specified fragments. |
| 1509 | pub fn make_component(&self) -> Box<str> { |
| 1510 | let Self { |
| 1511 | types, |
| 1512 | type_instantiation_args, |
| 1513 | params, |
| 1514 | results, |
| 1515 | caller_module, |
| 1516 | callee_module, |
| 1517 | options, |
| 1518 | } = self; |
| 1519 | let mk_component = |name: &str, |
| 1520 | module: &str, |
| 1521 | import_async: bool, |
| 1522 | export_async: bool, |
| 1523 | encoding: StringEncoding, |
| 1524 | lift_abi: LiftAbi, |
| 1525 | lower_abi: LowerAbi| { |
| 1526 | let import_async = if import_async { "async" } else { "" }; |
| 1527 | let export_async = if export_async { "async" } else { "" }; |
| 1528 | let lower_async_option = match lower_abi { |
| 1529 | LowerAbi::Sync => "", |
| 1530 | LowerAbi::Async => "async", |
| 1531 | }; |
| 1532 | let lift_async_option = match lift_abi { |
| 1533 | LiftAbi::Sync => "", |
| 1534 | LiftAbi::AsyncStackful => "async", |
| 1535 | LiftAbi::AsyncCallback => "async (callback (func $i \"callback\"))", |
| 1536 | }; |
| 1537 | |
| 1538 | let mut intrinsic_defs = String::new(); |
| 1539 | let mut intrinsic_imports = String::new(); |
| 1540 | |
| 1541 | match lift_abi { |
| 1542 | LiftAbi::Sync => {} |
| 1543 | LiftAbi::AsyncCallback | LiftAbi::AsyncStackful => { |
| 1544 | intrinsic_defs.push_str(&format!( |
| 1545 | r#" |
| 1546 | (core func $task.return (canon task.return {results} |
| 1547 | (memory $libc "memory") string-encoding={encoding})) |
| 1548 | "#, |
| 1549 | )); |
| 1550 | intrinsic_imports.push_str( |
| 1551 | r#" |
| 1552 | (with "" (instance (export "task.return" (func $task.return)))) |
| 1553 | "#, |
| 1554 | ); |
| 1555 | } |
| 1556 | } |
| 1557 | |
| 1558 | format!( |
| 1559 | r#" |
| 1560 | (component ${name} |
| 1561 | {types} |
| 1562 | (type $import_sig (func {import_async} {params} {results})) |
| 1563 | (type $export_sig (func {export_async} {params} {results})) |
| 1564 | (import "{IMPORT_FUNCTION}" (func $f (type $import_sig))) |
| 1565 | |
| 1566 | (core instance $libc (instantiate $libc)) |