MCPcopy Index your code
hub / github.com/explodingcamera/tinywasm / encode_quote_wat

Function encode_quote_wat

crates/cli/src/wast_runner.rs:692–711  ·  view source on GitHub ↗
(module: QuoteWat)

Source from the content-addressed store, hash-verified

690}
691
692fn encode_quote_wat(module: QuoteWat) -> (Option<String>, Vec<u8>) {
693 match module {
694 QuoteWat::QuoteModule(_, quoted_wat) => {
695 let wat = quoted_wat
696 .iter()
697 .map(|(_, s)| std::str::from_utf8(s).expect("failed to convert wast to utf8"))
698 .collect::<Vec<_>>()
699 .join("\n");
700 let lexer = wast::lexer::Lexer::new(&wat);
701 let buf = wast::parser::ParseBuffer::new_with_lexer(lexer).expect("failed to create parse buffer");
702 let mut wat_data = wast::parser::parse::<wast::Wat>(&buf).expect("failed to parse wat");
703 (None, wat_data.encode().expect("failed to encode module"))
704 }
705 QuoteWat::Wat(mut wat) => {
706 let wast::Wat::Module(ref module) = wat else { unimplemented!("Not supported") };
707 (module.id.map(|id| id.name().to_string()), wat.encode().expect("failed to encode module"))
708 }
709 QuoteWat::QuoteComponent(..) => unimplemented!("components are not supported"),
710 }
711}
712
713fn parse_module_bytes(bytes: &[u8]) -> Result<Module> {
714 Ok(tinywasm::parse_bytes(bytes)?)

Callers 1

run_fileMethod · 0.85

Calls 2

mapMethod · 0.80
nameMethod · 0.80

Tested by

no test coverage detected