diff --git a/implementations/rust/preserves-schema/src/compiler/context.rs b/implementations/rust/preserves-schema/src/compiler/context.rs index 063fb5e..1bb89a1 100644 --- a/implementations/rust/preserves-schema/src/compiler/context.rs +++ b/implementations/rust/preserves-schema/src/compiler/context.rs @@ -15,11 +15,18 @@ use super::CompilerConfig; use super::names; use super::types; +#[derive(Clone, Copy)] +pub enum ModuleContextMode { + TargetIOValue, + TargetAny, +} + pub struct ModuleContext<'m> { pub config: &'m CompilerConfig, pub literals: Map<_Any, String>, pub typedefs: Vec, pub functiondefs: Vec, + pub mode: ModuleContextMode, } pub struct FunctionContext<'a, 'm> { @@ -45,6 +52,7 @@ impl<'m> ModuleContext<'m> { literals: Map::new(), typedefs: Vec::new(), functiondefs: Vec::new(), + mode: ModuleContextMode::TargetIOValue, } } @@ -58,7 +66,7 @@ impl<'m> ModuleContext<'m> { _ => prefix }; let next_id = next_id.to_case(Case::UpperSnake); - "&*".to_owned() + self.literals.entry(v.clone()).or_insert(next_id) + "&*".to_owned() + self.target_prefix() + "::" + self.literals.entry(v.clone()).or_insert(next_id) } pub fn define_type(&mut self, i: Item) { @@ -86,6 +94,20 @@ impl<'m> ModuleContext<'m> { item(name![s.to_owned(), r.name.to_owned()]) } } + + pub fn target(&self) -> &'static str { + match self.mode { + ModuleContextMode::TargetIOValue => "preserves::value::IOValue", + ModuleContextMode::TargetAny => "_Any", + } + } + + pub fn target_prefix(&self) -> &'static str { + match self.mode { + ModuleContextMode::TargetIOValue => "_io_", + ModuleContextMode::TargetAny => "_any_", + } + } } impl<'a, 'm> FunctionContext<'a, 'm> { diff --git a/implementations/rust/preserves-schema/src/compiler/mod.rs b/implementations/rust/preserves-schema/src/compiler/mod.rs index ec1ef54..c174e2f 100644 --- a/implementations/rust/preserves-schema/src/compiler/mod.rs +++ b/implementations/rust/preserves-schema/src/compiler/mod.rs @@ -92,6 +92,9 @@ pub fn expand_inputs(globs: &Vec) -> Result, Error> { } pub fn compile(config: &CompilerConfig) -> Result<(), std::io::Error> { + let modes: Vec = + vec![context::ModuleContextMode::TargetIOValue, context::ModuleContextMode::TargetAny]; + for (k, v) in config.bundle.iter() { let mut output_path = config.output_dir.clone(); output_path.extend(k); @@ -109,8 +112,11 @@ pub fn compile(config: &CompilerConfig) -> Result<(), std::io::Error> { for (n, d) in &v.definitions.0 { m.define_type(item(types::render_definition_type(&m, n, &types::definition_type(d)))); - parsers::gen_definition_parser(&mut m, n, d); - unparsers::gen_definition_unparser(&mut m, n, d); + for mode in &modes { + m.mode = *mode; + parsers::gen_definition_parser(&mut m, n, d); + unparsers::gen_definition_unparser(&mut m, n, d); + } } //--------------------------------------------------------------------------- @@ -126,16 +132,28 @@ pub fn compile(config: &CompilerConfig) -> Result<(), std::io::Error> { lines.push(format!("use {}::support as _support;", &config.support_crate)); lines.push("".to_owned()); - lines.push("_support::lazy_static! {".to_owned()); - for (value, name) in m.literals { - let bs = preserves::value::PackedWriter::encode(&value.to_io_value()).unwrap(); - lines.push(format!(" pub static ref {}: preserves::value::IOValue = /* {:?} */ preserves::value::packed::from_bytes(&vec!{:?}).unwrap();", - name, - value, - bs)); + for mode in &modes { + m.mode = *mode; + lines.push(format!("mod {} {{", m.target_prefix())); + lines.push(" use super::_Any;".to_owned()); + lines.push(" use preserves::value::NestedValue;".to_owned()); + lines.push(" use preserves::value::packed::from_bytes;".to_owned()); + lines.push(format!(" use {}::support as _support;", &config.support_crate)); + lines.push(" _support::lazy_static! {".to_owned()); + for (value, name) in &m.literals { + let bs = preserves::value::PackedWriter::encode(&value.to_io_value()).unwrap(); + lines.push(format!( + " pub static ref {}: {} = /* {:?} */ {}::from_io_value(&from_bytes(&vec!{:?}).unwrap()).unwrap();", + name, + m.target(), + value, + m.target(), + bs)); + } + lines.push(" }".to_owned()); + lines.push("}".to_owned()); + lines.push("".to_owned()); } - lines.push("}".to_owned()); - lines.push("".to_owned()); for i in m.typedefs { lines.push(Formatter::to_string(i)); diff --git a/implementations/rust/preserves-schema/src/compiler/parsers.rs b/implementations/rust/preserves-schema/src/compiler/parsers.rs index 6aa63a5..52df085 100644 --- a/implementations/rust/preserves-schema/src/compiler/parsers.rs +++ b/implementations/rust/preserves-schema/src/compiler/parsers.rs @@ -4,7 +4,7 @@ use crate::syntax::block::Item; use crate::syntax::block::constructors::*; use super::codegen::*; -use super::context::{ModuleContext, FunctionContext}; +use super::context::{ModuleContextMode, ModuleContext, FunctionContext}; use super::names; use super::types::*; @@ -18,7 +18,8 @@ pub fn gen_definition_parser(m: &mut ModuleContext, n: &str, d: &Definition) { let mut ps = vec![&**pattern_0, &**pattern_1]; ps.extend(pattern_n); for NamedAlternative { variant_label: name, pattern: pat } in ps { - let fname = seq!["_parse_", names::render_fieldname(n), "_", names::render_fieldname(name)]; + let fname = seq![ctxt.m.target_prefix(), "parse_", + names::render_fieldname(n), "_", names::render_fieldname(name)]; let ctorname = item(name![names::render_constructor(n), names::render_constructor(name)]); ctxt.m.define_function( |mut ctxt| { @@ -26,7 +27,7 @@ pub fn gen_definition_parser(m: &mut ModuleContext, n: &str, d: &Definition) { let dest = pattern_parser(&mut ctxt, pat, "value", None, &mut body); let dest = dest.as_ref().map(String::as_str); construct(&ctxt, ctorname, false, &pattern_type(pat), dest, &mut body); - item(seq!["fn ", fname.clone(), "(value: &preserves::value::IOValue) -> ", + item(seq!["fn ", fname.clone(), "(value: &", ctxt.m.target(), ") -> ", "std::result::Result<", names::render_constructor(n), ", _support::ParseError> ", block(body)]) }); @@ -49,10 +50,10 @@ pub fn gen_definition_parser(m: &mut ModuleContext, n: &str, d: &Definition) { } } - item(seq!["impl std::convert::TryFrom", anglebrackets!["preserves::value::IOValue"], " for ", + item(seq!["impl std::convert::TryFrom", anglebrackets![ctxt.m.target()], " for ", names::render_constructor(n), " ", block![ seq!["type Error = _support::ParseError;"], - seq!["fn try_from(value: preserves::value::IOValue) -> ", + seq!["fn try_from(value: ", ctxt.m.target(), ") -> ", "std::result::Result ", block(body)]]]) }); @@ -105,7 +106,12 @@ fn simple_pattern_parser( let dest = ctxt.gentempname(); match p { SimplePattern::Any => { - push_let(body, item(dest.to_owned()), item(seq!["_Any::from_io_value", parens![src.to_owned()], "?"])); + match ctxt.m.mode { + ModuleContextMode::TargetIOValue => + push_let(body, item(dest.to_owned()), item(seq!["_Any::from_io_value", parens![src.to_owned()], "?"])), + ModuleContextMode::TargetAny => + push_let(body, item(dest.to_owned()), item(src.to_owned())), + } dest }, SimplePattern::Atom { atom_kind: k } => { @@ -122,10 +128,16 @@ fn simple_pattern_parser( dest }, SimplePattern::Embedded { .. } => { - push_let(body, item(dest.to_owned()), item(seq![ - "_Ptr::from_preserves", - parens![seq![src.to_owned(), ".value().to_embedded()?", ".clone()"]], - "?"])); + match ctxt.m.mode { + ModuleContextMode::TargetIOValue => + push_let(body, item(dest.to_owned()), item(seq![ + "_Ptr::from_preserves", + parens![seq![src.to_owned(), ".value().to_embedded()?", ".clone()"]], + "?"])), + ModuleContextMode::TargetAny => + push_let(body, item(dest.to_owned()), item(seq![ + parens![seq![src.to_owned(), ".value().to_embedded()?"]]])), + } dest }, SimplePattern::Lit { value } => { diff --git a/implementations/rust/preserves-schema/src/compiler/unparsers.rs b/implementations/rust/preserves-schema/src/compiler/unparsers.rs index 9a7326f..0558b76 100644 --- a/implementations/rust/preserves-schema/src/compiler/unparsers.rs +++ b/implementations/rust/preserves-schema/src/compiler/unparsers.rs @@ -7,7 +7,7 @@ use std::cell::Cell; use std::rc::Rc; use super::codegen::*; -use super::context::{ModuleContext, FunctionContext}; +use super::context::{ModuleContextMode, ModuleContext, FunctionContext}; use super::names; use super::types::*; @@ -82,7 +82,7 @@ pub fn gen_definition_unparser(m: &mut ModuleContext, n: &str, d: &Definition) { } item(seq!["impl std::convert::From", anglebrackets![seq!["&", names::render_constructor(n)]], - " for preserves::value::IOValue ", block![ + " for ", ctxt.m.target(), " ", block![ seq!["fn from(value: &", names::render_constructor(n), ") -> Self ", block(body)]]]) }); @@ -120,8 +120,14 @@ fn simple_pattern_unparser( ) -> Item { let src = &vc.src; match p { - SimplePattern::Any => - item(seq![src.as_ref().unwrap().to_owned(), ".to_io_value()"]), + SimplePattern::Any => { + match ctxt.m.mode { + ModuleContextMode::TargetIOValue => + item(seq![src.as_ref().unwrap().to_owned(), ".to_io_value()"]), + ModuleContextMode::TargetAny => + item(seq![src.as_ref().unwrap().to_owned(), ".clone()"]), + } + } SimplePattern::Atom { atom_kind: k } => { match &**k { AtomKind::Symbol => @@ -132,8 +138,14 @@ fn simple_pattern_unparser( item(seq!["preserves::value::Value::from(", src.as_ref().unwrap().to_owned(), ").wrap()"]) } } - SimplePattern::Embedded { .. } => - item(seq!["preserves::value::Value::Domain(", src.as_ref().unwrap().to_owned(), ".as_preserves()).wrap()"]), + SimplePattern::Embedded { .. } => { + match ctxt.m.mode { + ModuleContextMode::TargetIOValue => + item(seq!["preserves::value::Value::Domain(", src.as_ref().unwrap().to_owned(), ".as_preserves()).wrap()"]), + ModuleContextMode::TargetAny => + item(seq!["preserves::value::Value::Domain(", src.as_ref().unwrap().to_owned(), ").wrap()"]), + } + } SimplePattern::Lit { value } => item(seq![parens![ctxt.m.define_literal(value)], ".clone()"]), SimplePattern::Seqof { pattern } => { @@ -166,7 +178,7 @@ fn simple_pattern_unparser( ").collect()).wrap()"]) } SimplePattern::Ref(_r) => - item(seq!["preserves::value::IOValue::from(", src.as_ref().unwrap().to_owned(), + item(seq![ctxt.m.target(), "::from(", src.as_ref().unwrap().to_owned(), if vc.is_struct { "" } else { ".as_ref()" }, ")"]), } diff --git a/implementations/rust/preserves-schema/src/gen/schema.rs b/implementations/rust/preserves-schema/src/gen/schema.rs index 7de7aae..cd33538 100644 --- a/implementations/rust/preserves-schema/src/gen/schema.rs +++ b/implementations/rust/preserves-schema/src/gen/schema.rs @@ -6,36 +6,80 @@ use preserves::value::Domain; use preserves::value::NestedValue; use crate::support as _support; -_support::lazy_static! { - pub static ref LIT_15_FALSE: preserves::value::IOValue = /* #f */ preserves::value::packed::from_bytes(&vec![128]).unwrap(); - pub static ref LIT_28_1: preserves::value::IOValue = /* 1 */ preserves::value::packed::from_bytes(&vec![145]).unwrap(); - pub static ref LIT_0_BOOLEAN: preserves::value::IOValue = /* Boolean */ preserves::value::packed::from_bytes(&vec![179, 7, 66, 111, 111, 108, 101, 97, 110]).unwrap(); - pub static ref LIT_5_BYTE_STRING: preserves::value::IOValue = /* ByteString */ preserves::value::packed::from_bytes(&vec![179, 10, 66, 121, 116, 101, 83, 116, 114, 105, 110, 103]).unwrap(); - pub static ref LIT_2_DOUBLE: preserves::value::IOValue = /* Double */ preserves::value::packed::from_bytes(&vec![179, 6, 68, 111, 117, 98, 108, 101]).unwrap(); - pub static ref LIT_1_FLOAT: preserves::value::IOValue = /* Float */ preserves::value::packed::from_bytes(&vec![179, 5, 70, 108, 111, 97, 116]).unwrap(); - pub static ref LIT_3_SIGNED_INTEGER: preserves::value::IOValue = /* SignedInteger */ preserves::value::packed::from_bytes(&vec![179, 13, 83, 105, 103, 110, 101, 100, 73, 110, 116, 101, 103, 101, 114]).unwrap(); - pub static ref LIT_4_STRING: preserves::value::IOValue = /* String */ preserves::value::packed::from_bytes(&vec![179, 6, 83, 116, 114, 105, 110, 103]).unwrap(); - pub static ref LIT_6_SYMBOL: preserves::value::IOValue = /* Symbol */ preserves::value::packed::from_bytes(&vec![179, 6, 83, 121, 109, 98, 111, 108]).unwrap(); - pub static ref LIT_14_AND: preserves::value::IOValue = /* and */ preserves::value::packed::from_bytes(&vec![179, 3, 97, 110, 100]).unwrap(); - pub static ref LIT_21_ANY: preserves::value::IOValue = /* any */ preserves::value::packed::from_bytes(&vec![179, 3, 97, 110, 121]).unwrap(); - pub static ref LIT_22_ATOM: preserves::value::IOValue = /* atom */ preserves::value::packed::from_bytes(&vec![179, 4, 97, 116, 111, 109]).unwrap(); - pub static ref LIT_8_BUNDLE: preserves::value::IOValue = /* bundle */ preserves::value::packed::from_bytes(&vec![179, 6, 98, 117, 110, 100, 108, 101]).unwrap(); - pub static ref LIT_18_DEFINITIONS: preserves::value::IOValue = /* definitions */ preserves::value::packed::from_bytes(&vec![179, 11, 100, 101, 102, 105, 110, 105, 116, 105, 111, 110, 115]).unwrap(); - pub static ref LIT_12_DICT: preserves::value::IOValue = /* dict */ preserves::value::packed::from_bytes(&vec![179, 4, 100, 105, 99, 116]).unwrap(); - pub static ref LIT_27_DICTOF: preserves::value::IOValue = /* dictof */ preserves::value::packed::from_bytes(&vec![179, 6, 100, 105, 99, 116, 111, 102]).unwrap(); - pub static ref LIT_23_EMBEDDED: preserves::value::IOValue = /* embedded */ preserves::value::packed::from_bytes(&vec![179, 8, 101, 109, 98, 101, 100, 100, 101, 100]).unwrap(); - pub static ref LIT_19_EMBEDDED_TYPE: preserves::value::IOValue = /* embeddedType */ preserves::value::packed::from_bytes(&vec![179, 12, 101, 109, 98, 101, 100, 100, 101, 100, 84, 121, 112, 101]).unwrap(); - pub static ref LIT_24_LIT: preserves::value::IOValue = /* lit */ preserves::value::packed::from_bytes(&vec![179, 3, 108, 105, 116]).unwrap(); - pub static ref LIT_7_NAMED: preserves::value::IOValue = /* named */ preserves::value::packed::from_bytes(&vec![179, 5, 110, 97, 109, 101, 100]).unwrap(); - pub static ref LIT_13_OR: preserves::value::IOValue = /* or */ preserves::value::packed::from_bytes(&vec![179, 2, 111, 114]).unwrap(); - pub static ref LIT_9_REC: preserves::value::IOValue = /* rec */ preserves::value::packed::from_bytes(&vec![179, 3, 114, 101, 99]).unwrap(); - pub static ref LIT_16_REF: preserves::value::IOValue = /* ref */ preserves::value::packed::from_bytes(&vec![179, 3, 114, 101, 102]).unwrap(); - pub static ref LIT_17_SCHEMA: preserves::value::IOValue = /* schema */ preserves::value::packed::from_bytes(&vec![179, 6, 115, 99, 104, 101, 109, 97]).unwrap(); - pub static ref LIT_25_SEQOF: preserves::value::IOValue = /* seqof */ preserves::value::packed::from_bytes(&vec![179, 5, 115, 101, 113, 111, 102]).unwrap(); - pub static ref LIT_26_SETOF: preserves::value::IOValue = /* setof */ preserves::value::packed::from_bytes(&vec![179, 5, 115, 101, 116, 111, 102]).unwrap(); - pub static ref LIT_10_TUPLE: preserves::value::IOValue = /* tuple */ preserves::value::packed::from_bytes(&vec![179, 5, 116, 117, 112, 108, 101]).unwrap(); - pub static ref LIT_11_TUPLE_PREFIX: preserves::value::IOValue = /* tuplePrefix */ preserves::value::packed::from_bytes(&vec![179, 11, 116, 117, 112, 108, 101, 80, 114, 101, 102, 105, 120]).unwrap(); - pub static ref LIT_20_VERSION: preserves::value::IOValue = /* version */ preserves::value::packed::from_bytes(&vec![179, 7, 118, 101, 114, 115, 105, 111, 110]).unwrap(); +mod _io_ { + use super::_Any; + use preserves::value::NestedValue; + use preserves::value::packed::from_bytes; + use crate::support as _support; + _support::lazy_static! { + pub static ref LIT_15_FALSE: preserves::value::IOValue = /* #f */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![128]).unwrap()).unwrap(); + pub static ref LIT_28_1: preserves::value::IOValue = /* 1 */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![145]).unwrap()).unwrap(); + pub static ref LIT_0_BOOLEAN: preserves::value::IOValue = /* Boolean */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 7, 66, 111, 111, 108, 101, 97, 110]).unwrap()).unwrap(); + pub static ref LIT_5_BYTE_STRING: preserves::value::IOValue = /* ByteString */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 10, 66, 121, 116, 101, 83, 116, 114, 105, 110, 103]).unwrap()).unwrap(); + pub static ref LIT_2_DOUBLE: preserves::value::IOValue = /* Double */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 6, 68, 111, 117, 98, 108, 101]).unwrap()).unwrap(); + pub static ref LIT_1_FLOAT: preserves::value::IOValue = /* Float */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 5, 70, 108, 111, 97, 116]).unwrap()).unwrap(); + pub static ref LIT_3_SIGNED_INTEGER: preserves::value::IOValue = /* SignedInteger */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 13, 83, 105, 103, 110, 101, 100, 73, 110, 116, 101, 103, 101, 114]).unwrap()).unwrap(); + pub static ref LIT_4_STRING: preserves::value::IOValue = /* String */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 6, 83, 116, 114, 105, 110, 103]).unwrap()).unwrap(); + pub static ref LIT_6_SYMBOL: preserves::value::IOValue = /* Symbol */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 6, 83, 121, 109, 98, 111, 108]).unwrap()).unwrap(); + pub static ref LIT_14_AND: preserves::value::IOValue = /* and */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 3, 97, 110, 100]).unwrap()).unwrap(); + pub static ref LIT_21_ANY: preserves::value::IOValue = /* any */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 3, 97, 110, 121]).unwrap()).unwrap(); + pub static ref LIT_22_ATOM: preserves::value::IOValue = /* atom */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 4, 97, 116, 111, 109]).unwrap()).unwrap(); + pub static ref LIT_8_BUNDLE: preserves::value::IOValue = /* bundle */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 6, 98, 117, 110, 100, 108, 101]).unwrap()).unwrap(); + pub static ref LIT_18_DEFINITIONS: preserves::value::IOValue = /* definitions */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 11, 100, 101, 102, 105, 110, 105, 116, 105, 111, 110, 115]).unwrap()).unwrap(); + pub static ref LIT_12_DICT: preserves::value::IOValue = /* dict */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 4, 100, 105, 99, 116]).unwrap()).unwrap(); + pub static ref LIT_27_DICTOF: preserves::value::IOValue = /* dictof */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 6, 100, 105, 99, 116, 111, 102]).unwrap()).unwrap(); + pub static ref LIT_23_EMBEDDED: preserves::value::IOValue = /* embedded */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 8, 101, 109, 98, 101, 100, 100, 101, 100]).unwrap()).unwrap(); + pub static ref LIT_19_EMBEDDED_TYPE: preserves::value::IOValue = /* embeddedType */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 12, 101, 109, 98, 101, 100, 100, 101, 100, 84, 121, 112, 101]).unwrap()).unwrap(); + pub static ref LIT_24_LIT: preserves::value::IOValue = /* lit */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 3, 108, 105, 116]).unwrap()).unwrap(); + pub static ref LIT_7_NAMED: preserves::value::IOValue = /* named */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 5, 110, 97, 109, 101, 100]).unwrap()).unwrap(); + pub static ref LIT_13_OR: preserves::value::IOValue = /* or */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 2, 111, 114]).unwrap()).unwrap(); + pub static ref LIT_9_REC: preserves::value::IOValue = /* rec */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 3, 114, 101, 99]).unwrap()).unwrap(); + pub static ref LIT_16_REF: preserves::value::IOValue = /* ref */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 3, 114, 101, 102]).unwrap()).unwrap(); + pub static ref LIT_17_SCHEMA: preserves::value::IOValue = /* schema */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 6, 115, 99, 104, 101, 109, 97]).unwrap()).unwrap(); + pub static ref LIT_25_SEQOF: preserves::value::IOValue = /* seqof */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 5, 115, 101, 113, 111, 102]).unwrap()).unwrap(); + pub static ref LIT_26_SETOF: preserves::value::IOValue = /* setof */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 5, 115, 101, 116, 111, 102]).unwrap()).unwrap(); + pub static ref LIT_10_TUPLE: preserves::value::IOValue = /* tuple */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 5, 116, 117, 112, 108, 101]).unwrap()).unwrap(); + pub static ref LIT_11_TUPLE_PREFIX: preserves::value::IOValue = /* tuplePrefix */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 11, 116, 117, 112, 108, 101, 80, 114, 101, 102, 105, 120]).unwrap()).unwrap(); + pub static ref LIT_20_VERSION: preserves::value::IOValue = /* version */ preserves::value::IOValue::from_io_value(&from_bytes(&vec![179, 7, 118, 101, 114, 115, 105, 111, 110]).unwrap()).unwrap(); + } +} + +mod _any_ { + use super::_Any; + use preserves::value::NestedValue; + use preserves::value::packed::from_bytes; + use crate::support as _support; + _support::lazy_static! { + pub static ref LIT_15_FALSE: _Any = /* #f */ _Any::from_io_value(&from_bytes(&vec![128]).unwrap()).unwrap(); + pub static ref LIT_28_1: _Any = /* 1 */ _Any::from_io_value(&from_bytes(&vec![145]).unwrap()).unwrap(); + pub static ref LIT_0_BOOLEAN: _Any = /* Boolean */ _Any::from_io_value(&from_bytes(&vec![179, 7, 66, 111, 111, 108, 101, 97, 110]).unwrap()).unwrap(); + pub static ref LIT_5_BYTE_STRING: _Any = /* ByteString */ _Any::from_io_value(&from_bytes(&vec![179, 10, 66, 121, 116, 101, 83, 116, 114, 105, 110, 103]).unwrap()).unwrap(); + pub static ref LIT_2_DOUBLE: _Any = /* Double */ _Any::from_io_value(&from_bytes(&vec![179, 6, 68, 111, 117, 98, 108, 101]).unwrap()).unwrap(); + pub static ref LIT_1_FLOAT: _Any = /* Float */ _Any::from_io_value(&from_bytes(&vec![179, 5, 70, 108, 111, 97, 116]).unwrap()).unwrap(); + pub static ref LIT_3_SIGNED_INTEGER: _Any = /* SignedInteger */ _Any::from_io_value(&from_bytes(&vec![179, 13, 83, 105, 103, 110, 101, 100, 73, 110, 116, 101, 103, 101, 114]).unwrap()).unwrap(); + pub static ref LIT_4_STRING: _Any = /* String */ _Any::from_io_value(&from_bytes(&vec![179, 6, 83, 116, 114, 105, 110, 103]).unwrap()).unwrap(); + pub static ref LIT_6_SYMBOL: _Any = /* Symbol */ _Any::from_io_value(&from_bytes(&vec![179, 6, 83, 121, 109, 98, 111, 108]).unwrap()).unwrap(); + pub static ref LIT_14_AND: _Any = /* and */ _Any::from_io_value(&from_bytes(&vec![179, 3, 97, 110, 100]).unwrap()).unwrap(); + pub static ref LIT_21_ANY: _Any = /* any */ _Any::from_io_value(&from_bytes(&vec![179, 3, 97, 110, 121]).unwrap()).unwrap(); + pub static ref LIT_22_ATOM: _Any = /* atom */ _Any::from_io_value(&from_bytes(&vec![179, 4, 97, 116, 111, 109]).unwrap()).unwrap(); + pub static ref LIT_8_BUNDLE: _Any = /* bundle */ _Any::from_io_value(&from_bytes(&vec![179, 6, 98, 117, 110, 100, 108, 101]).unwrap()).unwrap(); + pub static ref LIT_18_DEFINITIONS: _Any = /* definitions */ _Any::from_io_value(&from_bytes(&vec![179, 11, 100, 101, 102, 105, 110, 105, 116, 105, 111, 110, 115]).unwrap()).unwrap(); + pub static ref LIT_12_DICT: _Any = /* dict */ _Any::from_io_value(&from_bytes(&vec![179, 4, 100, 105, 99, 116]).unwrap()).unwrap(); + pub static ref LIT_27_DICTOF: _Any = /* dictof */ _Any::from_io_value(&from_bytes(&vec![179, 6, 100, 105, 99, 116, 111, 102]).unwrap()).unwrap(); + pub static ref LIT_23_EMBEDDED: _Any = /* embedded */ _Any::from_io_value(&from_bytes(&vec![179, 8, 101, 109, 98, 101, 100, 100, 101, 100]).unwrap()).unwrap(); + pub static ref LIT_19_EMBEDDED_TYPE: _Any = /* embeddedType */ _Any::from_io_value(&from_bytes(&vec![179, 12, 101, 109, 98, 101, 100, 100, 101, 100, 84, 121, 112, 101]).unwrap()).unwrap(); + pub static ref LIT_24_LIT: _Any = /* lit */ _Any::from_io_value(&from_bytes(&vec![179, 3, 108, 105, 116]).unwrap()).unwrap(); + pub static ref LIT_7_NAMED: _Any = /* named */ _Any::from_io_value(&from_bytes(&vec![179, 5, 110, 97, 109, 101, 100]).unwrap()).unwrap(); + pub static ref LIT_13_OR: _Any = /* or */ _Any::from_io_value(&from_bytes(&vec![179, 2, 111, 114]).unwrap()).unwrap(); + pub static ref LIT_9_REC: _Any = /* rec */ _Any::from_io_value(&from_bytes(&vec![179, 3, 114, 101, 99]).unwrap()).unwrap(); + pub static ref LIT_16_REF: _Any = /* ref */ _Any::from_io_value(&from_bytes(&vec![179, 3, 114, 101, 102]).unwrap()).unwrap(); + pub static ref LIT_17_SCHEMA: _Any = /* schema */ _Any::from_io_value(&from_bytes(&vec![179, 6, 115, 99, 104, 101, 109, 97]).unwrap()).unwrap(); + pub static ref LIT_25_SEQOF: _Any = /* seqof */ _Any::from_io_value(&from_bytes(&vec![179, 5, 115, 101, 113, 111, 102]).unwrap()).unwrap(); + pub static ref LIT_26_SETOF: _Any = /* setof */ _Any::from_io_value(&from_bytes(&vec![179, 5, 115, 101, 116, 111, 102]).unwrap()).unwrap(); + pub static ref LIT_10_TUPLE: _Any = /* tuple */ _Any::from_io_value(&from_bytes(&vec![179, 5, 116, 117, 112, 108, 101]).unwrap()).unwrap(); + pub static ref LIT_11_TUPLE_PREFIX: _Any = /* tuplePrefix */ _Any::from_io_value(&from_bytes(&vec![179, 11, 116, 117, 112, 108, 101, 80, 114, 101, 102, 105, 120]).unwrap()).unwrap(); + pub static ref LIT_20_VERSION: _Any = /* version */ _Any::from_io_value(&from_bytes(&vec![179, 7, 118, 101, 114, 115, 105, 111, 110]).unwrap()).unwrap(); + } } pub type _Ptr = preserves::value::IOValue; @@ -132,44 +176,44 @@ pub enum SimplePattern { #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub struct Version; -fn _parse_atom_kind_boolean(value: &preserves::value::IOValue) -> std::result::Result { - if value != &*LIT_0_BOOLEAN { return Err(_support::ParseError::ConformanceError); } +fn _io_parse_atom_kind_boolean(value: &preserves::value::IOValue) -> std::result::Result { + if value != &*_io_::LIT_0_BOOLEAN { return Err(_support::ParseError::ConformanceError); } let _tmp0 = (); Ok(AtomKind::Boolean) } -fn _parse_atom_kind_float(value: &preserves::value::IOValue) -> std::result::Result { - if value != &*LIT_1_FLOAT { return Err(_support::ParseError::ConformanceError); } +fn _io_parse_atom_kind_float(value: &preserves::value::IOValue) -> std::result::Result { + if value != &*_io_::LIT_1_FLOAT { return Err(_support::ParseError::ConformanceError); } let _tmp0 = (); Ok(AtomKind::Float) } -fn _parse_atom_kind_double(value: &preserves::value::IOValue) -> std::result::Result { - if value != &*LIT_2_DOUBLE { return Err(_support::ParseError::ConformanceError); } +fn _io_parse_atom_kind_double(value: &preserves::value::IOValue) -> std::result::Result { + if value != &*_io_::LIT_2_DOUBLE { return Err(_support::ParseError::ConformanceError); } let _tmp0 = (); Ok(AtomKind::Double) } -fn _parse_atom_kind_signed_integer(value: &preserves::value::IOValue) -> std::result::Result { - if value != &*LIT_3_SIGNED_INTEGER { return Err(_support::ParseError::ConformanceError); } +fn _io_parse_atom_kind_signed_integer(value: &preserves::value::IOValue) -> std::result::Result { + if value != &*_io_::LIT_3_SIGNED_INTEGER { return Err(_support::ParseError::ConformanceError); } let _tmp0 = (); Ok(AtomKind::SignedInteger) } -fn _parse_atom_kind_string(value: &preserves::value::IOValue) -> std::result::Result { - if value != &*LIT_4_STRING { return Err(_support::ParseError::ConformanceError); } +fn _io_parse_atom_kind_string(value: &preserves::value::IOValue) -> std::result::Result { + if value != &*_io_::LIT_4_STRING { return Err(_support::ParseError::ConformanceError); } let _tmp0 = (); Ok(AtomKind::String) } -fn _parse_atom_kind_byte_string(value: &preserves::value::IOValue) -> std::result::Result { - if value != &*LIT_5_BYTE_STRING { return Err(_support::ParseError::ConformanceError); } +fn _io_parse_atom_kind_byte_string(value: &preserves::value::IOValue) -> std::result::Result { + if value != &*_io_::LIT_5_BYTE_STRING { return Err(_support::ParseError::ConformanceError); } let _tmp0 = (); Ok(AtomKind::ByteString) } -fn _parse_atom_kind_symbol(value: &preserves::value::IOValue) -> std::result::Result { - if value != &*LIT_6_SYMBOL { return Err(_support::ParseError::ConformanceError); } +fn _io_parse_atom_kind_symbol(value: &preserves::value::IOValue) -> std::result::Result { + if value != &*_io_::LIT_6_SYMBOL { return Err(_support::ParseError::ConformanceError); } let _tmp0 = (); Ok(AtomKind::Symbol) } @@ -178,13 +222,13 @@ impl std::convert::TryFrom for AtomKind { type Error = _support::ParseError; fn try_from(value: preserves::value::IOValue) -> std::result::Result { let value = &value; - if let Ok(r) = _parse_atom_kind_boolean(value) { return Ok(r); } - if let Ok(r) = _parse_atom_kind_float(value) { return Ok(r); } - if let Ok(r) = _parse_atom_kind_double(value) { return Ok(r); } - if let Ok(r) = _parse_atom_kind_signed_integer(value) { return Ok(r); } - if let Ok(r) = _parse_atom_kind_string(value) { return Ok(r); } - if let Ok(r) = _parse_atom_kind_byte_string(value) { return Ok(r); } - if let Ok(r) = _parse_atom_kind_symbol(value) { return Ok(r); } + if let Ok(r) = _io_parse_atom_kind_boolean(value) { return Ok(r); } + if let Ok(r) = _io_parse_atom_kind_float(value) { return Ok(r); } + if let Ok(r) = _io_parse_atom_kind_double(value) { return Ok(r); } + if let Ok(r) = _io_parse_atom_kind_signed_integer(value) { return Ok(r); } + if let Ok(r) = _io_parse_atom_kind_string(value) { return Ok(r); } + if let Ok(r) = _io_parse_atom_kind_byte_string(value) { return Ok(r); } + if let Ok(r) = _io_parse_atom_kind_symbol(value) { return Ok(r); } Err(_support::ParseError::ConformanceError) } } @@ -192,13 +236,84 @@ impl std::convert::TryFrom for AtomKind { impl std::convert::From<&AtomKind> for preserves::value::IOValue { fn from(value: &AtomKind) -> Self { match value { - AtomKind::Boolean => (&*LIT_0_BOOLEAN).clone(), - AtomKind::Float => (&*LIT_1_FLOAT).clone(), - AtomKind::Double => (&*LIT_2_DOUBLE).clone(), - AtomKind::SignedInteger => (&*LIT_3_SIGNED_INTEGER).clone(), - AtomKind::String => (&*LIT_4_STRING).clone(), - AtomKind::ByteString => (&*LIT_5_BYTE_STRING).clone(), - AtomKind::Symbol => (&*LIT_6_SYMBOL).clone(), + AtomKind::Boolean => (&*_io_::LIT_0_BOOLEAN).clone(), + AtomKind::Float => (&*_io_::LIT_1_FLOAT).clone(), + AtomKind::Double => (&*_io_::LIT_2_DOUBLE).clone(), + AtomKind::SignedInteger => (&*_io_::LIT_3_SIGNED_INTEGER).clone(), + AtomKind::String => (&*_io_::LIT_4_STRING).clone(), + AtomKind::ByteString => (&*_io_::LIT_5_BYTE_STRING).clone(), + AtomKind::Symbol => (&*_io_::LIT_6_SYMBOL).clone(), + } + } +} + +fn _any_parse_atom_kind_boolean(value: &_Any) -> std::result::Result { + if value != &*_any_::LIT_0_BOOLEAN { return Err(_support::ParseError::ConformanceError); } + let _tmp0 = (); + Ok(AtomKind::Boolean) +} + +fn _any_parse_atom_kind_float(value: &_Any) -> std::result::Result { + if value != &*_any_::LIT_1_FLOAT { return Err(_support::ParseError::ConformanceError); } + let _tmp0 = (); + Ok(AtomKind::Float) +} + +fn _any_parse_atom_kind_double(value: &_Any) -> std::result::Result { + if value != &*_any_::LIT_2_DOUBLE { return Err(_support::ParseError::ConformanceError); } + let _tmp0 = (); + Ok(AtomKind::Double) +} + +fn _any_parse_atom_kind_signed_integer(value: &_Any) -> std::result::Result { + if value != &*_any_::LIT_3_SIGNED_INTEGER { return Err(_support::ParseError::ConformanceError); } + let _tmp0 = (); + Ok(AtomKind::SignedInteger) +} + +fn _any_parse_atom_kind_string(value: &_Any) -> std::result::Result { + if value != &*_any_::LIT_4_STRING { return Err(_support::ParseError::ConformanceError); } + let _tmp0 = (); + Ok(AtomKind::String) +} + +fn _any_parse_atom_kind_byte_string(value: &_Any) -> std::result::Result { + if value != &*_any_::LIT_5_BYTE_STRING { return Err(_support::ParseError::ConformanceError); } + let _tmp0 = (); + Ok(AtomKind::ByteString) +} + +fn _any_parse_atom_kind_symbol(value: &_Any) -> std::result::Result { + if value != &*_any_::LIT_6_SYMBOL { return Err(_support::ParseError::ConformanceError); } + let _tmp0 = (); + Ok(AtomKind::Symbol) +} + +impl std::convert::TryFrom<_Any> for AtomKind { + type Error = _support::ParseError; + fn try_from(value: _Any) -> std::result::Result { + let value = &value; + if let Ok(r) = _any_parse_atom_kind_boolean(value) { return Ok(r); } + if let Ok(r) = _any_parse_atom_kind_float(value) { return Ok(r); } + if let Ok(r) = _any_parse_atom_kind_double(value) { return Ok(r); } + if let Ok(r) = _any_parse_atom_kind_signed_integer(value) { return Ok(r); } + if let Ok(r) = _any_parse_atom_kind_string(value) { return Ok(r); } + if let Ok(r) = _any_parse_atom_kind_byte_string(value) { return Ok(r); } + if let Ok(r) = _any_parse_atom_kind_symbol(value) { return Ok(r); } + Err(_support::ParseError::ConformanceError) + } +} + +impl std::convert::From<&AtomKind> for _Any { + fn from(value: &AtomKind) -> Self { + match value { + AtomKind::Boolean => (&*_any_::LIT_0_BOOLEAN).clone(), + AtomKind::Float => (&*_any_::LIT_1_FLOAT).clone(), + AtomKind::Double => (&*_any_::LIT_2_DOUBLE).clone(), + AtomKind::SignedInteger => (&*_any_::LIT_3_SIGNED_INTEGER).clone(), + AtomKind::String => (&*_any_::LIT_4_STRING).clone(), + AtomKind::ByteString => (&*_any_::LIT_5_BYTE_STRING).clone(), + AtomKind::Symbol => (&*_any_::LIT_6_SYMBOL).clone(), } } } @@ -208,7 +323,7 @@ impl std::convert::TryFrom for Binding { fn try_from(value: preserves::value::IOValue) -> std::result::Result { let value = &value; let _tmp0 = value.value().to_record(None)?; - if _tmp0.label() != &*LIT_7_NAMED { return Err(_support::ParseError::ConformanceError); } + if _tmp0.label() != &*_io_::LIT_7_NAMED { return Err(_support::ParseError::ConformanceError); } let _tmp1 = (); if _tmp0.fields().len() < 2 { return Err(_support::ParseError::ConformanceError); } let _tmp2 = (&_tmp0.fields()[0]).value().to_symbol()?; @@ -221,7 +336,7 @@ impl std::convert::From<&Binding> for preserves::value::IOValue { fn from(value: &Binding) -> Self { let Binding {name: _tmp0, pattern: _tmp1} = value; { - let mut _tmp2 = preserves::value::Record(vec![(&*LIT_7_NAMED).clone()]); + let mut _tmp2 = preserves::value::Record(vec![(&*_io_::LIT_7_NAMED).clone()]); _tmp2.fields_vec_mut().push(preserves::value::Value::symbol(_tmp0).wrap()); _tmp2.fields_vec_mut().push(preserves::value::IOValue::from(_tmp1)); _tmp2.finish().wrap() @@ -229,12 +344,38 @@ impl std::convert::From<&Binding> for preserves::value::IOValue { } } +impl std::convert::TryFrom<_Any> for Binding { + type Error = _support::ParseError; + fn try_from(value: _Any) -> std::result::Result { + let value = &value; + let _tmp0 = value.value().to_record(None)?; + if _tmp0.label() != &*_any_::LIT_7_NAMED { return Err(_support::ParseError::ConformanceError); } + let _tmp1 = (); + if _tmp0.fields().len() < 2 { return Err(_support::ParseError::ConformanceError); } + let _tmp2 = (&_tmp0.fields()[0]).value().to_symbol()?; + let _tmp3 = SimplePattern::try_from((&_tmp0.fields()[1]).clone())?; + Ok(Binding {name: _tmp2.clone(), pattern: _tmp3}) + } +} + +impl std::convert::From<&Binding> for _Any { + fn from(value: &Binding) -> Self { + let Binding {name: _tmp0, pattern: _tmp1} = value; + { + let mut _tmp2 = preserves::value::Record(vec![(&*_any_::LIT_7_NAMED).clone()]); + _tmp2.fields_vec_mut().push(preserves::value::Value::symbol(_tmp0).wrap()); + _tmp2.fields_vec_mut().push(_Any::from(_tmp1)); + _tmp2.finish().wrap() + } + } +} + impl std::convert::TryFrom for Bundle { type Error = _support::ParseError; fn try_from(value: preserves::value::IOValue) -> std::result::Result { let value = &value; let _tmp0 = value.value().to_record(None)?; - if _tmp0.label() != &*LIT_8_BUNDLE { return Err(_support::ParseError::ConformanceError); } + if _tmp0.label() != &*_io_::LIT_8_BUNDLE { return Err(_support::ParseError::ConformanceError); } let _tmp1 = (); if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } let _tmp2 = Modules::try_from((&_tmp0.fields()[0]).clone())?; @@ -246,16 +387,40 @@ impl std::convert::From<&Bundle> for preserves::value::IOValue { fn from(value: &Bundle) -> Self { let Bundle {modules: _tmp0} = value; { - let mut _tmp1 = preserves::value::Record(vec![(&*LIT_8_BUNDLE).clone()]); + let mut _tmp1 = preserves::value::Record(vec![(&*_io_::LIT_8_BUNDLE).clone()]); _tmp1.fields_vec_mut().push(preserves::value::IOValue::from(_tmp0)); _tmp1.finish().wrap() } } } -fn _parse_compound_pattern_rec(value: &preserves::value::IOValue) -> std::result::Result { +impl std::convert::TryFrom<_Any> for Bundle { + type Error = _support::ParseError; + fn try_from(value: _Any) -> std::result::Result { + let value = &value; + let _tmp0 = value.value().to_record(None)?; + if _tmp0.label() != &*_any_::LIT_8_BUNDLE { return Err(_support::ParseError::ConformanceError); } + let _tmp1 = (); + if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } + let _tmp2 = Modules::try_from((&_tmp0.fields()[0]).clone())?; + Ok(Bundle {modules: _tmp2}) + } +} + +impl std::convert::From<&Bundle> for _Any { + fn from(value: &Bundle) -> Self { + let Bundle {modules: _tmp0} = value; + { + let mut _tmp1 = preserves::value::Record(vec![(&*_any_::LIT_8_BUNDLE).clone()]); + _tmp1.fields_vec_mut().push(_Any::from(_tmp0)); + _tmp1.finish().wrap() + } + } +} + +fn _io_parse_compound_pattern_rec(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = value.value().to_record(None)?; - if _tmp0.label() != &*LIT_9_REC { return Err(_support::ParseError::ConformanceError); } + if _tmp0.label() != &*_io_::LIT_9_REC { return Err(_support::ParseError::ConformanceError); } let _tmp1 = (); if _tmp0.fields().len() < 2 { return Err(_support::ParseError::ConformanceError); } let _tmp2 = NamedPattern::try_from((&_tmp0.fields()[0]).clone())?; @@ -263,9 +428,9 @@ fn _parse_compound_pattern_rec(value: &preserves::value::IOValue) -> std::result Ok(CompoundPattern::Rec {label: std::boxed::Box::new(_tmp2), fields: std::boxed::Box::new(_tmp3)}) } -fn _parse_compound_pattern_tuple(value: &preserves::value::IOValue) -> std::result::Result { +fn _io_parse_compound_pattern_tuple(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = value.value().to_record(None)?; - if _tmp0.label() != &*LIT_10_TUPLE { return Err(_support::ParseError::ConformanceError); } + if _tmp0.label() != &*_io_::LIT_10_TUPLE { return Err(_support::ParseError::ConformanceError); } let _tmp1 = (); if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } let _tmp3 = (&_tmp0.fields()[0]).value().to_sequence()?; @@ -274,9 +439,9 @@ fn _parse_compound_pattern_tuple(value: &preserves::value::IOValue) -> std::resu Ok(CompoundPattern::Tuple {patterns: _tmp2}) } -fn _parse_compound_pattern_tuple_prefix(value: &preserves::value::IOValue) -> std::result::Result { +fn _io_parse_compound_pattern_tuple_prefix(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = value.value().to_record(None)?; - if _tmp0.label() != &*LIT_11_TUPLE_PREFIX { return Err(_support::ParseError::ConformanceError); } + if _tmp0.label() != &*_io_::LIT_11_TUPLE_PREFIX { return Err(_support::ParseError::ConformanceError); } let _tmp1 = (); if _tmp0.fields().len() < 2 { return Err(_support::ParseError::ConformanceError); } let _tmp3 = (&_tmp0.fields()[0]).value().to_sequence()?; @@ -286,9 +451,9 @@ fn _parse_compound_pattern_tuple_prefix(value: &preserves::value::IOValue) -> st Ok(CompoundPattern::TuplePrefix {fixed: _tmp2, variable: std::boxed::Box::new(_tmp6)}) } -fn _parse_compound_pattern_dict(value: &preserves::value::IOValue) -> std::result::Result { +fn _io_parse_compound_pattern_dict(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = value.value().to_record(None)?; - if _tmp0.label() != &*LIT_12_DICT { return Err(_support::ParseError::ConformanceError); } + if _tmp0.label() != &*_io_::LIT_12_DICT { return Err(_support::ParseError::ConformanceError); } let _tmp1 = (); if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } let _tmp2 = DictionaryEntries::try_from((&_tmp0.fields()[0]).clone())?; @@ -299,10 +464,10 @@ impl std::convert::TryFrom for CompoundPattern { type Error = _support::ParseError; fn try_from(value: preserves::value::IOValue) -> std::result::Result { let value = &value; - if let Ok(r) = _parse_compound_pattern_rec(value) { return Ok(r); } - if let Ok(r) = _parse_compound_pattern_tuple(value) { return Ok(r); } - if let Ok(r) = _parse_compound_pattern_tuple_prefix(value) { return Ok(r); } - if let Ok(r) = _parse_compound_pattern_dict(value) { return Ok(r); } + if let Ok(r) = _io_parse_compound_pattern_rec(value) { return Ok(r); } + if let Ok(r) = _io_parse_compound_pattern_tuple(value) { return Ok(r); } + if let Ok(r) = _io_parse_compound_pattern_tuple_prefix(value) { return Ok(r); } + if let Ok(r) = _io_parse_compound_pattern_dict(value) { return Ok(r); } Err(_support::ParseError::ConformanceError) } } @@ -311,13 +476,13 @@ impl std::convert::From<&CompoundPattern> for preserves::value::IOValue { fn from(value: &CompoundPattern) -> Self { match value { CompoundPattern::Rec {label: _tmp0, fields: _tmp1} => { - let mut _tmp2 = preserves::value::Record(vec![(&*LIT_9_REC).clone()]); + let mut _tmp2 = preserves::value::Record(vec![(&*_io_::LIT_9_REC).clone()]); _tmp2.fields_vec_mut().push(preserves::value::IOValue::from(_tmp0.as_ref())); _tmp2.fields_vec_mut().push(preserves::value::IOValue::from(_tmp1.as_ref())); _tmp2.finish().wrap() }, CompoundPattern::Tuple {patterns: _tmp0} => { - let mut _tmp1 = preserves::value::Record(vec![(&*LIT_10_TUPLE).clone()]); + let mut _tmp1 = preserves::value::Record(vec![(&*_io_::LIT_10_TUPLE).clone()]); _tmp1.fields_vec_mut().push( { let mut _tmp2 = vec![]; @@ -328,7 +493,7 @@ impl std::convert::From<&CompoundPattern> for preserves::value::IOValue { _tmp1.finish().wrap() }, CompoundPattern::TuplePrefix {fixed: _tmp0, variable: _tmp1} => { - let mut _tmp2 = preserves::value::Record(vec![(&*LIT_11_TUPLE_PREFIX).clone()]); + let mut _tmp2 = preserves::value::Record(vec![(&*_io_::LIT_11_TUPLE_PREFIX).clone()]); _tmp2.fields_vec_mut().push( { let mut _tmp3 = vec![]; @@ -340,7 +505,7 @@ impl std::convert::From<&CompoundPattern> for preserves::value::IOValue { _tmp2.finish().wrap() }, CompoundPattern::Dict {entries: _tmp0} => { - let mut _tmp1 = preserves::value::Record(vec![(&*LIT_12_DICT).clone()]); + let mut _tmp1 = preserves::value::Record(vec![(&*_io_::LIT_12_DICT).clone()]); _tmp1.fields_vec_mut().push(preserves::value::IOValue::from(_tmp0.as_ref())); _tmp1.finish().wrap() }, @@ -348,9 +513,104 @@ impl std::convert::From<&CompoundPattern> for preserves::value::IOValue { } } -fn _parse_definition_or(value: &preserves::value::IOValue) -> std::result::Result { +fn _any_parse_compound_pattern_rec(value: &_Any) -> std::result::Result { let _tmp0 = value.value().to_record(None)?; - if _tmp0.label() != &*LIT_13_OR { return Err(_support::ParseError::ConformanceError); } + if _tmp0.label() != &*_any_::LIT_9_REC { return Err(_support::ParseError::ConformanceError); } + let _tmp1 = (); + if _tmp0.fields().len() < 2 { return Err(_support::ParseError::ConformanceError); } + let _tmp2 = NamedPattern::try_from((&_tmp0.fields()[0]).clone())?; + let _tmp3 = NamedPattern::try_from((&_tmp0.fields()[1]).clone())?; + Ok(CompoundPattern::Rec {label: std::boxed::Box::new(_tmp2), fields: std::boxed::Box::new(_tmp3)}) +} + +fn _any_parse_compound_pattern_tuple(value: &_Any) -> std::result::Result { + let _tmp0 = value.value().to_record(None)?; + if _tmp0.label() != &*_any_::LIT_10_TUPLE { return Err(_support::ParseError::ConformanceError); } + let _tmp1 = (); + if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } + let _tmp3 = (&_tmp0.fields()[0]).value().to_sequence()?; + let mut _tmp2 = std::vec::Vec::new(); + for _tmp4 in &_tmp3[0..] {let _tmp5 = NamedPattern::try_from(_tmp4.clone())?; _tmp2.push(_tmp5);} + Ok(CompoundPattern::Tuple {patterns: _tmp2}) +} + +fn _any_parse_compound_pattern_tuple_prefix(value: &_Any) -> std::result::Result { + let _tmp0 = value.value().to_record(None)?; + if _tmp0.label() != &*_any_::LIT_11_TUPLE_PREFIX { return Err(_support::ParseError::ConformanceError); } + let _tmp1 = (); + if _tmp0.fields().len() < 2 { return Err(_support::ParseError::ConformanceError); } + let _tmp3 = (&_tmp0.fields()[0]).value().to_sequence()?; + let mut _tmp2 = std::vec::Vec::new(); + for _tmp4 in &_tmp3[0..] {let _tmp5 = NamedPattern::try_from(_tmp4.clone())?; _tmp2.push(_tmp5);} + let _tmp6 = NamedSimplePattern::try_from((&_tmp0.fields()[1]).clone())?; + Ok(CompoundPattern::TuplePrefix {fixed: _tmp2, variable: std::boxed::Box::new(_tmp6)}) +} + +fn _any_parse_compound_pattern_dict(value: &_Any) -> std::result::Result { + let _tmp0 = value.value().to_record(None)?; + if _tmp0.label() != &*_any_::LIT_12_DICT { return Err(_support::ParseError::ConformanceError); } + let _tmp1 = (); + if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } + let _tmp2 = DictionaryEntries::try_from((&_tmp0.fields()[0]).clone())?; + Ok(CompoundPattern::Dict {entries: std::boxed::Box::new(_tmp2)}) +} + +impl std::convert::TryFrom<_Any> for CompoundPattern { + type Error = _support::ParseError; + fn try_from(value: _Any) -> std::result::Result { + let value = &value; + if let Ok(r) = _any_parse_compound_pattern_rec(value) { return Ok(r); } + if let Ok(r) = _any_parse_compound_pattern_tuple(value) { return Ok(r); } + if let Ok(r) = _any_parse_compound_pattern_tuple_prefix(value) { return Ok(r); } + if let Ok(r) = _any_parse_compound_pattern_dict(value) { return Ok(r); } + Err(_support::ParseError::ConformanceError) + } +} + +impl std::convert::From<&CompoundPattern> for _Any { + fn from(value: &CompoundPattern) -> Self { + match value { + CompoundPattern::Rec {label: _tmp0, fields: _tmp1} => { + let mut _tmp2 = preserves::value::Record(vec![(&*_any_::LIT_9_REC).clone()]); + _tmp2.fields_vec_mut().push(_Any::from(_tmp0.as_ref())); + _tmp2.fields_vec_mut().push(_Any::from(_tmp1.as_ref())); + _tmp2.finish().wrap() + }, + CompoundPattern::Tuple {patterns: _tmp0} => { + let mut _tmp1 = preserves::value::Record(vec![(&*_any_::LIT_10_TUPLE).clone()]); + _tmp1.fields_vec_mut().push( + { + let mut _tmp2 = vec![]; + for _tmp3 in _tmp0 {_tmp2.push(_Any::from(_tmp3));} + preserves::value::Value::Sequence(_tmp2).wrap() + } + ); + _tmp1.finish().wrap() + }, + CompoundPattern::TuplePrefix {fixed: _tmp0, variable: _tmp1} => { + let mut _tmp2 = preserves::value::Record(vec![(&*_any_::LIT_11_TUPLE_PREFIX).clone()]); + _tmp2.fields_vec_mut().push( + { + let mut _tmp3 = vec![]; + for _tmp4 in _tmp0 {_tmp3.push(_Any::from(_tmp4));} + preserves::value::Value::Sequence(_tmp3).wrap() + } + ); + _tmp2.fields_vec_mut().push(_Any::from(_tmp1.as_ref())); + _tmp2.finish().wrap() + }, + CompoundPattern::Dict {entries: _tmp0} => { + let mut _tmp1 = preserves::value::Record(vec![(&*_any_::LIT_12_DICT).clone()]); + _tmp1.fields_vec_mut().push(_Any::from(_tmp0.as_ref())); + _tmp1.finish().wrap() + }, + } + } +} + +fn _io_parse_definition_or(value: &preserves::value::IOValue) -> std::result::Result { + let _tmp0 = value.value().to_record(None)?; + if _tmp0.label() != &*_io_::LIT_13_OR { return Err(_support::ParseError::ConformanceError); } let _tmp1 = (); if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } let _tmp2 = (&_tmp0.fields()[0]).value().to_sequence()?; @@ -366,9 +626,9 @@ fn _parse_definition_or(value: &preserves::value::IOValue) -> std::result::Resul }) } -fn _parse_definition_and(value: &preserves::value::IOValue) -> std::result::Result { +fn _io_parse_definition_and(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = value.value().to_record(None)?; - if _tmp0.label() != &*LIT_14_AND { return Err(_support::ParseError::ConformanceError); } + if _tmp0.label() != &*_io_::LIT_14_AND { return Err(_support::ParseError::ConformanceError); } let _tmp1 = (); if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } let _tmp2 = (&_tmp0.fields()[0]).value().to_sequence()?; @@ -384,7 +644,7 @@ fn _parse_definition_and(value: &preserves::value::IOValue) -> std::result::Resu }) } -fn _parse_definition_pattern(value: &preserves::value::IOValue) -> std::result::Result { +fn _io_parse_definition_pattern(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = Pattern::try_from(value.clone())?; Ok(Definition::Pattern(std::boxed::Box::new(_tmp0))) } @@ -393,9 +653,9 @@ impl std::convert::TryFrom for Definition { type Error = _support::ParseError; fn try_from(value: preserves::value::IOValue) -> std::result::Result { let value = &value; - if let Ok(r) = _parse_definition_or(value) { return Ok(r); } - if let Ok(r) = _parse_definition_and(value) { return Ok(r); } - if let Ok(r) = _parse_definition_pattern(value) { return Ok(r); } + if let Ok(r) = _io_parse_definition_or(value) { return Ok(r); } + if let Ok(r) = _io_parse_definition_and(value) { return Ok(r); } + if let Ok(r) = _io_parse_definition_pattern(value) { return Ok(r); } Err(_support::ParseError::ConformanceError) } } @@ -404,7 +664,7 @@ impl std::convert::From<&Definition> for preserves::value::IOValue { fn from(value: &Definition) -> Self { match value { Definition::Or {pattern_0: _tmp0, pattern_1: _tmp1, pattern_n: _tmp2} => { - let mut _tmp3 = preserves::value::Record(vec![(&*LIT_13_OR).clone()]); + let mut _tmp3 = preserves::value::Record(vec![(&*_io_::LIT_13_OR).clone()]); _tmp3.fields_vec_mut().push( { let mut _tmp4 = vec![]; @@ -417,7 +677,7 @@ impl std::convert::From<&Definition> for preserves::value::IOValue { _tmp3.finish().wrap() }, Definition::And {pattern_0: _tmp0, pattern_1: _tmp1, pattern_n: _tmp2} => { - let mut _tmp3 = preserves::value::Record(vec![(&*LIT_14_AND).clone()]); + let mut _tmp3 = preserves::value::Record(vec![(&*_io_::LIT_14_AND).clone()]); _tmp3.fields_vec_mut().push( { let mut _tmp4 = vec![]; @@ -434,6 +694,92 @@ impl std::convert::From<&Definition> for preserves::value::IOValue { } } +fn _any_parse_definition_or(value: &_Any) -> std::result::Result { + let _tmp0 = value.value().to_record(None)?; + if _tmp0.label() != &*_any_::LIT_13_OR { return Err(_support::ParseError::ConformanceError); } + let _tmp1 = (); + if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } + let _tmp2 = (&_tmp0.fields()[0]).value().to_sequence()?; + if _tmp2.len() < 2 { return Err(_support::ParseError::ConformanceError); } + let _tmp3 = NamedAlternative::try_from((&_tmp2[0]).clone())?; + let _tmp4 = NamedAlternative::try_from((&_tmp2[1]).clone())?; + let mut _tmp5 = std::vec::Vec::new(); + for _tmp6 in &_tmp2[2..] {let _tmp7 = NamedAlternative::try_from(_tmp6.clone())?; _tmp5.push(_tmp7);} + Ok(Definition::Or { + pattern_0: std::boxed::Box::new(_tmp3), + pattern_1: std::boxed::Box::new(_tmp4), + pattern_n: _tmp5 + }) +} + +fn _any_parse_definition_and(value: &_Any) -> std::result::Result { + let _tmp0 = value.value().to_record(None)?; + if _tmp0.label() != &*_any_::LIT_14_AND { return Err(_support::ParseError::ConformanceError); } + let _tmp1 = (); + if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } + let _tmp2 = (&_tmp0.fields()[0]).value().to_sequence()?; + if _tmp2.len() < 2 { return Err(_support::ParseError::ConformanceError); } + let _tmp3 = NamedPattern::try_from((&_tmp2[0]).clone())?; + let _tmp4 = NamedPattern::try_from((&_tmp2[1]).clone())?; + let mut _tmp5 = std::vec::Vec::new(); + for _tmp6 in &_tmp2[2..] {let _tmp7 = NamedPattern::try_from(_tmp6.clone())?; _tmp5.push(_tmp7);} + Ok(Definition::And { + pattern_0: std::boxed::Box::new(_tmp3), + pattern_1: std::boxed::Box::new(_tmp4), + pattern_n: _tmp5 + }) +} + +fn _any_parse_definition_pattern(value: &_Any) -> std::result::Result { + let _tmp0 = Pattern::try_from(value.clone())?; + Ok(Definition::Pattern(std::boxed::Box::new(_tmp0))) +} + +impl std::convert::TryFrom<_Any> for Definition { + type Error = _support::ParseError; + fn try_from(value: _Any) -> std::result::Result { + let value = &value; + if let Ok(r) = _any_parse_definition_or(value) { return Ok(r); } + if let Ok(r) = _any_parse_definition_and(value) { return Ok(r); } + if let Ok(r) = _any_parse_definition_pattern(value) { return Ok(r); } + Err(_support::ParseError::ConformanceError) + } +} + +impl std::convert::From<&Definition> for _Any { + fn from(value: &Definition) -> Self { + match value { + Definition::Or {pattern_0: _tmp0, pattern_1: _tmp1, pattern_n: _tmp2} => { + let mut _tmp3 = preserves::value::Record(vec![(&*_any_::LIT_13_OR).clone()]); + _tmp3.fields_vec_mut().push( + { + let mut _tmp4 = vec![]; + _tmp4.push(_Any::from(_tmp0.as_ref())); + _tmp4.push(_Any::from(_tmp1.as_ref())); + for _tmp5 in _tmp2 {_tmp4.push(_Any::from(_tmp5));} + preserves::value::Value::Sequence(_tmp4).wrap() + } + ); + _tmp3.finish().wrap() + }, + Definition::And {pattern_0: _tmp0, pattern_1: _tmp1, pattern_n: _tmp2} => { + let mut _tmp3 = preserves::value::Record(vec![(&*_any_::LIT_14_AND).clone()]); + _tmp3.fields_vec_mut().push( + { + let mut _tmp4 = vec![]; + _tmp4.push(_Any::from(_tmp0.as_ref())); + _tmp4.push(_Any::from(_tmp1.as_ref())); + for _tmp5 in _tmp2 {_tmp4.push(_Any::from(_tmp5));} + preserves::value::Value::Sequence(_tmp4).wrap() + } + ); + _tmp3.finish().wrap() + }, + Definition::Pattern(_tmp0) => _Any::from(_tmp0.as_ref()), + } + } +} + impl std::convert::TryFrom for Definitions { type Error = _support::ParseError; fn try_from(value: preserves::value::IOValue) -> std::result::Result { @@ -458,6 +804,27 @@ impl std::convert::From<&Definitions> for preserves::value::IOValue { } } +impl std::convert::TryFrom<_Any> for Definitions { + type Error = _support::ParseError; + fn try_from(value: _Any) -> std::result::Result { + let value = &value; + let mut _tmp0 = preserves::value::Map::new(); + for (_tmp1, _tmp2) in value.value().to_dictionary()? { + let _tmp3 = _tmp1.value().to_symbol()?; + let _tmp4 = Definition::try_from(_tmp2.clone())?; + _tmp0.insert(_tmp3.clone(), _tmp4); + } + Ok(Definitions(_tmp0)) + } +} + +impl std::convert::From<&Definitions> for _Any { + fn from(value: &Definitions) -> Self { + let Definitions(_tmp0) = value; + preserves::value::Value::Dictionary(_tmp0.iter().map(|(_tmp1, _tmp2)| (preserves::value::Value::symbol(_tmp1).wrap(), _Any::from(_tmp2))).collect()).wrap() + } +} + impl std::convert::TryFrom for DictionaryEntries { type Error = _support::ParseError; fn try_from(value: preserves::value::IOValue) -> std::result::Result { @@ -479,13 +846,34 @@ impl std::convert::From<&DictionaryEntries> for preserves::value::IOValue { } } -fn _parse_embedded_type_name_ref(value: &preserves::value::IOValue) -> std::result::Result { +impl std::convert::TryFrom<_Any> for DictionaryEntries { + type Error = _support::ParseError; + fn try_from(value: _Any) -> std::result::Result { + let value = &value; + let mut _tmp0 = preserves::value::Map::new(); + for (_tmp1, _tmp2) in value.value().to_dictionary()? { + let _tmp3 = _tmp1; + let _tmp4 = NamedSimplePattern::try_from(_tmp2.clone())?; + _tmp0.insert(_tmp3.clone(), _tmp4); + } + Ok(DictionaryEntries(_tmp0)) + } +} + +impl std::convert::From<&DictionaryEntries> for _Any { + fn from(value: &DictionaryEntries) -> Self { + let DictionaryEntries(_tmp0) = value; + preserves::value::Value::Dictionary(_tmp0.iter().map(|(_tmp1, _tmp2)| (_tmp1.clone(), _Any::from(_tmp2))).collect()).wrap() + } +} + +fn _io_parse_embedded_type_name_ref(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = Ref::try_from(value.clone())?; Ok(EmbeddedTypeName::Ref(std::boxed::Box::new(_tmp0))) } -fn _parse_embedded_type_name_false(value: &preserves::value::IOValue) -> std::result::Result { - if value != &*LIT_15_FALSE { return Err(_support::ParseError::ConformanceError); } +fn _io_parse_embedded_type_name_false(value: &preserves::value::IOValue) -> std::result::Result { + if value != &*_io_::LIT_15_FALSE { return Err(_support::ParseError::ConformanceError); } let _tmp0 = (); Ok(EmbeddedTypeName::False) } @@ -494,8 +882,8 @@ impl std::convert::TryFrom for EmbeddedTypeName { type Error = _support::ParseError; fn try_from(value: preserves::value::IOValue) -> std::result::Result { let value = &value; - if let Ok(r) = _parse_embedded_type_name_ref(value) { return Ok(r); } - if let Ok(r) = _parse_embedded_type_name_false(value) { return Ok(r); } + if let Ok(r) = _io_parse_embedded_type_name_ref(value) { return Ok(r); } + if let Ok(r) = _io_parse_embedded_type_name_false(value) { return Ok(r); } Err(_support::ParseError::ConformanceError) } } @@ -504,7 +892,37 @@ impl std::convert::From<&EmbeddedTypeName> for preserves::value::IOValue { fn from(value: &EmbeddedTypeName) -> Self { match value { EmbeddedTypeName::Ref(_tmp0) => preserves::value::IOValue::from(_tmp0.as_ref()), - EmbeddedTypeName::False => (&*LIT_15_FALSE).clone(), + EmbeddedTypeName::False => (&*_io_::LIT_15_FALSE).clone(), + } + } +} + +fn _any_parse_embedded_type_name_ref(value: &_Any) -> std::result::Result { + let _tmp0 = Ref::try_from(value.clone())?; + Ok(EmbeddedTypeName::Ref(std::boxed::Box::new(_tmp0))) +} + +fn _any_parse_embedded_type_name_false(value: &_Any) -> std::result::Result { + if value != &*_any_::LIT_15_FALSE { return Err(_support::ParseError::ConformanceError); } + let _tmp0 = (); + Ok(EmbeddedTypeName::False) +} + +impl std::convert::TryFrom<_Any> for EmbeddedTypeName { + type Error = _support::ParseError; + fn try_from(value: _Any) -> std::result::Result { + let value = &value; + if let Ok(r) = _any_parse_embedded_type_name_ref(value) { return Ok(r); } + if let Ok(r) = _any_parse_embedded_type_name_false(value) { return Ok(r); } + Err(_support::ParseError::ConformanceError) + } +} + +impl std::convert::From<&EmbeddedTypeName> for _Any { + fn from(value: &EmbeddedTypeName) -> Self { + match value { + EmbeddedTypeName::Ref(_tmp0) => _Any::from(_tmp0.as_ref()), + EmbeddedTypeName::False => (&*_any_::LIT_15_FALSE).clone(), } } } @@ -531,6 +949,28 @@ impl std::convert::From<&ModulePath> for preserves::value::IOValue { } } +impl std::convert::TryFrom<_Any> for ModulePath { + type Error = _support::ParseError; + fn try_from(value: _Any) -> std::result::Result { + let value = &value; + let _tmp1 = value.value().to_sequence()?; + let mut _tmp0 = std::vec::Vec::new(); + for _tmp2 in &_tmp1[0..] {let _tmp3 = _tmp2.value().to_symbol()?; _tmp0.push(_tmp3.clone());} + Ok(ModulePath(_tmp0)) + } +} + +impl std::convert::From<&ModulePath> for _Any { + fn from(value: &ModulePath) -> Self { + let ModulePath(_tmp0) = value; + { + let mut _tmp1 = vec![]; + for _tmp2 in _tmp0 {_tmp1.push(preserves::value::Value::symbol(_tmp2).wrap());} + preserves::value::Value::Sequence(_tmp1).wrap() + } + } +} + impl std::convert::TryFrom for Modules { type Error = _support::ParseError; fn try_from(value: preserves::value::IOValue) -> std::result::Result { @@ -552,6 +992,27 @@ impl std::convert::From<&Modules> for preserves::value::IOValue { } } +impl std::convert::TryFrom<_Any> for Modules { + type Error = _support::ParseError; + fn try_from(value: _Any) -> std::result::Result { + let value = &value; + let mut _tmp0 = preserves::value::Map::new(); + for (_tmp1, _tmp2) in value.value().to_dictionary()? { + let _tmp3 = ModulePath::try_from(_tmp1.clone())?; + let _tmp4 = Schema::try_from(_tmp2.clone())?; + _tmp0.insert(_tmp3, _tmp4); + } + Ok(Modules(_tmp0)) + } +} + +impl std::convert::From<&Modules> for _Any { + fn from(value: &Modules) -> Self { + let Modules(_tmp0) = value; + preserves::value::Value::Dictionary(_tmp0.iter().map(|(_tmp1, _tmp2)| (_Any::from(_tmp1), _Any::from(_tmp2))).collect()).wrap() + } +} + impl std::convert::TryFrom for NamedAlternative { type Error = _support::ParseError; fn try_from(value: preserves::value::IOValue) -> std::result::Result { @@ -576,12 +1037,36 @@ impl std::convert::From<&NamedAlternative> for preserves::value::IOValue { } } -fn _parse_named_pattern_named(value: &preserves::value::IOValue) -> std::result::Result { +impl std::convert::TryFrom<_Any> for NamedAlternative { + type Error = _support::ParseError; + fn try_from(value: _Any) -> std::result::Result { + let value = &value; + let _tmp0 = value.value().to_sequence()?; + if _tmp0.len() < 2 { return Err(_support::ParseError::ConformanceError); } + let _tmp1 = (&_tmp0[0]).value().to_string()?; + let _tmp2 = Pattern::try_from((&_tmp0[1]).clone())?; + Ok(NamedAlternative {variant_label: _tmp1.clone(), pattern: _tmp2}) + } +} + +impl std::convert::From<&NamedAlternative> for _Any { + fn from(value: &NamedAlternative) -> Self { + let NamedAlternative {variant_label: _tmp0, pattern: _tmp1} = value; + { + let mut _tmp2 = vec![]; + _tmp2.push(preserves::value::Value::from(_tmp0).wrap()); + _tmp2.push(_Any::from(_tmp1)); + preserves::value::Value::Sequence(_tmp2).wrap() + } + } +} + +fn _io_parse_named_pattern_named(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = Binding::try_from(value.clone())?; Ok(NamedPattern::Named(std::boxed::Box::new(_tmp0))) } -fn _parse_named_pattern_anonymous(value: &preserves::value::IOValue) -> std::result::Result { +fn _io_parse_named_pattern_anonymous(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = Pattern::try_from(value.clone())?; Ok(NamedPattern::Anonymous(std::boxed::Box::new(_tmp0))) } @@ -590,8 +1075,8 @@ impl std::convert::TryFrom for NamedPattern { type Error = _support::ParseError; fn try_from(value: preserves::value::IOValue) -> std::result::Result { let value = &value; - if let Ok(r) = _parse_named_pattern_named(value) { return Ok(r); } - if let Ok(r) = _parse_named_pattern_anonymous(value) { return Ok(r); } + if let Ok(r) = _io_parse_named_pattern_named(value) { return Ok(r); } + if let Ok(r) = _io_parse_named_pattern_anonymous(value) { return Ok(r); } Err(_support::ParseError::ConformanceError) } } @@ -605,12 +1090,41 @@ impl std::convert::From<&NamedPattern> for preserves::value::IOValue { } } -fn _parse_named_simple_pattern_named(value: &preserves::value::IOValue) -> std::result::Result { +fn _any_parse_named_pattern_named(value: &_Any) -> std::result::Result { + let _tmp0 = Binding::try_from(value.clone())?; + Ok(NamedPattern::Named(std::boxed::Box::new(_tmp0))) +} + +fn _any_parse_named_pattern_anonymous(value: &_Any) -> std::result::Result { + let _tmp0 = Pattern::try_from(value.clone())?; + Ok(NamedPattern::Anonymous(std::boxed::Box::new(_tmp0))) +} + +impl std::convert::TryFrom<_Any> for NamedPattern { + type Error = _support::ParseError; + fn try_from(value: _Any) -> std::result::Result { + let value = &value; + if let Ok(r) = _any_parse_named_pattern_named(value) { return Ok(r); } + if let Ok(r) = _any_parse_named_pattern_anonymous(value) { return Ok(r); } + Err(_support::ParseError::ConformanceError) + } +} + +impl std::convert::From<&NamedPattern> for _Any { + fn from(value: &NamedPattern) -> Self { + match value { + NamedPattern::Named(_tmp0) => _Any::from(_tmp0.as_ref()), + NamedPattern::Anonymous(_tmp0) => _Any::from(_tmp0.as_ref()), + } + } +} + +fn _io_parse_named_simple_pattern_named(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = Binding::try_from(value.clone())?; Ok(NamedSimplePattern::Named(std::boxed::Box::new(_tmp0))) } -fn _parse_named_simple_pattern_anonymous(value: &preserves::value::IOValue) -> std::result::Result { +fn _io_parse_named_simple_pattern_anonymous(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = SimplePattern::try_from(value.clone())?; Ok(NamedSimplePattern::Anonymous(std::boxed::Box::new(_tmp0))) } @@ -619,8 +1133,8 @@ impl std::convert::TryFrom for NamedSimplePattern { type Error = _support::ParseError; fn try_from(value: preserves::value::IOValue) -> std::result::Result { let value = &value; - if let Ok(r) = _parse_named_simple_pattern_named(value) { return Ok(r); } - if let Ok(r) = _parse_named_simple_pattern_anonymous(value) { return Ok(r); } + if let Ok(r) = _io_parse_named_simple_pattern_named(value) { return Ok(r); } + if let Ok(r) = _io_parse_named_simple_pattern_anonymous(value) { return Ok(r); } Err(_support::ParseError::ConformanceError) } } @@ -634,12 +1148,41 @@ impl std::convert::From<&NamedSimplePattern> for preserves::value::IOValue { } } -fn _parse_pattern_simple_pattern(value: &preserves::value::IOValue) -> std::result::Result { +fn _any_parse_named_simple_pattern_named(value: &_Any) -> std::result::Result { + let _tmp0 = Binding::try_from(value.clone())?; + Ok(NamedSimplePattern::Named(std::boxed::Box::new(_tmp0))) +} + +fn _any_parse_named_simple_pattern_anonymous(value: &_Any) -> std::result::Result { + let _tmp0 = SimplePattern::try_from(value.clone())?; + Ok(NamedSimplePattern::Anonymous(std::boxed::Box::new(_tmp0))) +} + +impl std::convert::TryFrom<_Any> for NamedSimplePattern { + type Error = _support::ParseError; + fn try_from(value: _Any) -> std::result::Result { + let value = &value; + if let Ok(r) = _any_parse_named_simple_pattern_named(value) { return Ok(r); } + if let Ok(r) = _any_parse_named_simple_pattern_anonymous(value) { return Ok(r); } + Err(_support::ParseError::ConformanceError) + } +} + +impl std::convert::From<&NamedSimplePattern> for _Any { + fn from(value: &NamedSimplePattern) -> Self { + match value { + NamedSimplePattern::Named(_tmp0) => _Any::from(_tmp0.as_ref()), + NamedSimplePattern::Anonymous(_tmp0) => _Any::from(_tmp0.as_ref()), + } + } +} + +fn _io_parse_pattern_simple_pattern(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = SimplePattern::try_from(value.clone())?; Ok(Pattern::SimplePattern(std::boxed::Box::new(_tmp0))) } -fn _parse_pattern_compound_pattern(value: &preserves::value::IOValue) -> std::result::Result { +fn _io_parse_pattern_compound_pattern(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = CompoundPattern::try_from(value.clone())?; Ok(Pattern::CompoundPattern(std::boxed::Box::new(_tmp0))) } @@ -648,8 +1191,8 @@ impl std::convert::TryFrom for Pattern { type Error = _support::ParseError; fn try_from(value: preserves::value::IOValue) -> std::result::Result { let value = &value; - if let Ok(r) = _parse_pattern_simple_pattern(value) { return Ok(r); } - if let Ok(r) = _parse_pattern_compound_pattern(value) { return Ok(r); } + if let Ok(r) = _io_parse_pattern_simple_pattern(value) { return Ok(r); } + if let Ok(r) = _io_parse_pattern_compound_pattern(value) { return Ok(r); } Err(_support::ParseError::ConformanceError) } } @@ -663,12 +1206,41 @@ impl std::convert::From<&Pattern> for preserves::value::IOValue { } } +fn _any_parse_pattern_simple_pattern(value: &_Any) -> std::result::Result { + let _tmp0 = SimplePattern::try_from(value.clone())?; + Ok(Pattern::SimplePattern(std::boxed::Box::new(_tmp0))) +} + +fn _any_parse_pattern_compound_pattern(value: &_Any) -> std::result::Result { + let _tmp0 = CompoundPattern::try_from(value.clone())?; + Ok(Pattern::CompoundPattern(std::boxed::Box::new(_tmp0))) +} + +impl std::convert::TryFrom<_Any> for Pattern { + type Error = _support::ParseError; + fn try_from(value: _Any) -> std::result::Result { + let value = &value; + if let Ok(r) = _any_parse_pattern_simple_pattern(value) { return Ok(r); } + if let Ok(r) = _any_parse_pattern_compound_pattern(value) { return Ok(r); } + Err(_support::ParseError::ConformanceError) + } +} + +impl std::convert::From<&Pattern> for _Any { + fn from(value: &Pattern) -> Self { + match value { + Pattern::SimplePattern(_tmp0) => _Any::from(_tmp0.as_ref()), + Pattern::CompoundPattern(_tmp0) => _Any::from(_tmp0.as_ref()), + } + } +} + impl std::convert::TryFrom for Ref { type Error = _support::ParseError; fn try_from(value: preserves::value::IOValue) -> std::result::Result { let value = &value; let _tmp0 = value.value().to_record(None)?; - if _tmp0.label() != &*LIT_16_REF { return Err(_support::ParseError::ConformanceError); } + if _tmp0.label() != &*_io_::LIT_16_REF { return Err(_support::ParseError::ConformanceError); } let _tmp1 = (); if _tmp0.fields().len() < 2 { return Err(_support::ParseError::ConformanceError); } let _tmp2 = ModulePath::try_from((&_tmp0.fields()[0]).clone())?; @@ -681,7 +1253,7 @@ impl std::convert::From<&Ref> for preserves::value::IOValue { fn from(value: &Ref) -> Self { let Ref {module: _tmp0, name: _tmp1} = value; { - let mut _tmp2 = preserves::value::Record(vec![(&*LIT_16_REF).clone()]); + let mut _tmp2 = preserves::value::Record(vec![(&*_io_::LIT_16_REF).clone()]); _tmp2.fields_vec_mut().push(preserves::value::IOValue::from(_tmp0)); _tmp2.fields_vec_mut().push(preserves::value::Value::symbol(_tmp1).wrap()); _tmp2.finish().wrap() @@ -689,20 +1261,46 @@ impl std::convert::From<&Ref> for preserves::value::IOValue { } } +impl std::convert::TryFrom<_Any> for Ref { + type Error = _support::ParseError; + fn try_from(value: _Any) -> std::result::Result { + let value = &value; + let _tmp0 = value.value().to_record(None)?; + if _tmp0.label() != &*_any_::LIT_16_REF { return Err(_support::ParseError::ConformanceError); } + let _tmp1 = (); + if _tmp0.fields().len() < 2 { return Err(_support::ParseError::ConformanceError); } + let _tmp2 = ModulePath::try_from((&_tmp0.fields()[0]).clone())?; + let _tmp3 = (&_tmp0.fields()[1]).value().to_symbol()?; + Ok(Ref {module: _tmp2, name: _tmp3.clone()}) + } +} + +impl std::convert::From<&Ref> for _Any { + fn from(value: &Ref) -> Self { + let Ref {module: _tmp0, name: _tmp1} = value; + { + let mut _tmp2 = preserves::value::Record(vec![(&*_any_::LIT_16_REF).clone()]); + _tmp2.fields_vec_mut().push(_Any::from(_tmp0)); + _tmp2.fields_vec_mut().push(preserves::value::Value::symbol(_tmp1).wrap()); + _tmp2.finish().wrap() + } + } +} + impl std::convert::TryFrom for Schema { type Error = _support::ParseError; fn try_from(value: preserves::value::IOValue) -> std::result::Result { let value = &value; let _tmp0 = value.value().to_record(None)?; - if _tmp0.label() != &*LIT_17_SCHEMA { return Err(_support::ParseError::ConformanceError); } + if _tmp0.label() != &*_io_::LIT_17_SCHEMA { return Err(_support::ParseError::ConformanceError); } let _tmp1 = (); if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } let _tmp2 = (&_tmp0.fields()[0]).value().to_dictionary()?; - let _tmp3 = _tmp2.get(&*LIT_18_DEFINITIONS).ok_or(_support::ParseError::ConformanceError)?; + let _tmp3 = _tmp2.get(&*_io_::LIT_18_DEFINITIONS).ok_or(_support::ParseError::ConformanceError)?; let _tmp4 = Definitions::try_from(_tmp3.clone())?; - let _tmp5 = _tmp2.get(&*LIT_19_EMBEDDED_TYPE).ok_or(_support::ParseError::ConformanceError)?; + let _tmp5 = _tmp2.get(&*_io_::LIT_19_EMBEDDED_TYPE).ok_or(_support::ParseError::ConformanceError)?; let _tmp6 = EmbeddedTypeName::try_from(_tmp5.clone())?; - let _tmp7 = _tmp2.get(&*LIT_20_VERSION).ok_or(_support::ParseError::ConformanceError)?; + let _tmp7 = _tmp2.get(&*_io_::LIT_20_VERSION).ok_or(_support::ParseError::ConformanceError)?; let _tmp8 = Version::try_from(_tmp7.clone())?; Ok(Schema {definitions: _tmp4, embedded_type: _tmp6, version: _tmp8}) } @@ -712,13 +1310,13 @@ impl std::convert::From<&Schema> for preserves::value::IOValue { fn from(value: &Schema) -> Self { let Schema {definitions: _tmp0, embedded_type: _tmp1, version: _tmp2} = value; { - let mut _tmp3 = preserves::value::Record(vec![(&*LIT_17_SCHEMA).clone()]); + let mut _tmp3 = preserves::value::Record(vec![(&*_io_::LIT_17_SCHEMA).clone()]); _tmp3.fields_vec_mut().push( { let mut _tmp4 = preserves::value::Map::new(); - _tmp4.insert((&*LIT_18_DEFINITIONS).clone(), preserves::value::IOValue::from(_tmp0)); - _tmp4.insert((&*LIT_19_EMBEDDED_TYPE).clone(), preserves::value::IOValue::from(_tmp1)); - _tmp4.insert((&*LIT_20_VERSION).clone(), preserves::value::IOValue::from(_tmp2)); + _tmp4.insert((&*_io_::LIT_18_DEFINITIONS).clone(), preserves::value::IOValue::from(_tmp0)); + _tmp4.insert((&*_io_::LIT_19_EMBEDDED_TYPE).clone(), preserves::value::IOValue::from(_tmp1)); + _tmp4.insert((&*_io_::LIT_20_VERSION).clone(), preserves::value::IOValue::from(_tmp2)); preserves::value::Value::Dictionary(_tmp4).wrap() } ); @@ -727,60 +1325,98 @@ impl std::convert::From<&Schema> for preserves::value::IOValue { } } -fn _parse_simple_pattern_any(value: &preserves::value::IOValue) -> std::result::Result { - if value != &*LIT_21_ANY { return Err(_support::ParseError::ConformanceError); } +impl std::convert::TryFrom<_Any> for Schema { + type Error = _support::ParseError; + fn try_from(value: _Any) -> std::result::Result { + let value = &value; + let _tmp0 = value.value().to_record(None)?; + if _tmp0.label() != &*_any_::LIT_17_SCHEMA { return Err(_support::ParseError::ConformanceError); } + let _tmp1 = (); + if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } + let _tmp2 = (&_tmp0.fields()[0]).value().to_dictionary()?; + let _tmp3 = _tmp2.get(&*_any_::LIT_18_DEFINITIONS).ok_or(_support::ParseError::ConformanceError)?; + let _tmp4 = Definitions::try_from(_tmp3.clone())?; + let _tmp5 = _tmp2.get(&*_any_::LIT_19_EMBEDDED_TYPE).ok_or(_support::ParseError::ConformanceError)?; + let _tmp6 = EmbeddedTypeName::try_from(_tmp5.clone())?; + let _tmp7 = _tmp2.get(&*_any_::LIT_20_VERSION).ok_or(_support::ParseError::ConformanceError)?; + let _tmp8 = Version::try_from(_tmp7.clone())?; + Ok(Schema {definitions: _tmp4, embedded_type: _tmp6, version: _tmp8}) + } +} + +impl std::convert::From<&Schema> for _Any { + fn from(value: &Schema) -> Self { + let Schema {definitions: _tmp0, embedded_type: _tmp1, version: _tmp2} = value; + { + let mut _tmp3 = preserves::value::Record(vec![(&*_any_::LIT_17_SCHEMA).clone()]); + _tmp3.fields_vec_mut().push( + { + let mut _tmp4 = preserves::value::Map::new(); + _tmp4.insert((&*_any_::LIT_18_DEFINITIONS).clone(), _Any::from(_tmp0)); + _tmp4.insert((&*_any_::LIT_19_EMBEDDED_TYPE).clone(), _Any::from(_tmp1)); + _tmp4.insert((&*_any_::LIT_20_VERSION).clone(), _Any::from(_tmp2)); + preserves::value::Value::Dictionary(_tmp4).wrap() + } + ); + _tmp3.finish().wrap() + } + } +} + +fn _io_parse_simple_pattern_any(value: &preserves::value::IOValue) -> std::result::Result { + if value != &*_io_::LIT_21_ANY { return Err(_support::ParseError::ConformanceError); } let _tmp0 = (); Ok(SimplePattern::Any) } -fn _parse_simple_pattern_atom(value: &preserves::value::IOValue) -> std::result::Result { +fn _io_parse_simple_pattern_atom(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = value.value().to_record(None)?; - if _tmp0.label() != &*LIT_22_ATOM { return Err(_support::ParseError::ConformanceError); } + if _tmp0.label() != &*_io_::LIT_22_ATOM { return Err(_support::ParseError::ConformanceError); } let _tmp1 = (); if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } let _tmp2 = AtomKind::try_from((&_tmp0.fields()[0]).clone())?; Ok(SimplePattern::Atom {atom_kind: std::boxed::Box::new(_tmp2)}) } -fn _parse_simple_pattern_embedded(value: &preserves::value::IOValue) -> std::result::Result { +fn _io_parse_simple_pattern_embedded(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = value.value().to_record(None)?; - if _tmp0.label() != &*LIT_23_EMBEDDED { return Err(_support::ParseError::ConformanceError); } + if _tmp0.label() != &*_io_::LIT_23_EMBEDDED { return Err(_support::ParseError::ConformanceError); } let _tmp1 = (); if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } let _tmp2 = SimplePattern::try_from((&_tmp0.fields()[0]).clone())?; Ok(SimplePattern::Embedded {interface: std::boxed::Box::new(_tmp2)}) } -fn _parse_simple_pattern_lit(value: &preserves::value::IOValue) -> std::result::Result { +fn _io_parse_simple_pattern_lit(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = value.value().to_record(None)?; - if _tmp0.label() != &*LIT_24_LIT { return Err(_support::ParseError::ConformanceError); } + if _tmp0.label() != &*_io_::LIT_24_LIT { return Err(_support::ParseError::ConformanceError); } let _tmp1 = (); if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } let _tmp2 = _Any::from_io_value((&_tmp0.fields()[0]))?; Ok(SimplePattern::Lit {value: _tmp2.clone()}) } -fn _parse_simple_pattern_seqof(value: &preserves::value::IOValue) -> std::result::Result { +fn _io_parse_simple_pattern_seqof(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = value.value().to_record(None)?; - if _tmp0.label() != &*LIT_25_SEQOF { return Err(_support::ParseError::ConformanceError); } + if _tmp0.label() != &*_io_::LIT_25_SEQOF { return Err(_support::ParseError::ConformanceError); } let _tmp1 = (); if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } let _tmp2 = SimplePattern::try_from((&_tmp0.fields()[0]).clone())?; Ok(SimplePattern::Seqof {pattern: std::boxed::Box::new(_tmp2)}) } -fn _parse_simple_pattern_setof(value: &preserves::value::IOValue) -> std::result::Result { +fn _io_parse_simple_pattern_setof(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = value.value().to_record(None)?; - if _tmp0.label() != &*LIT_26_SETOF { return Err(_support::ParseError::ConformanceError); } + if _tmp0.label() != &*_io_::LIT_26_SETOF { return Err(_support::ParseError::ConformanceError); } let _tmp1 = (); if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } let _tmp2 = SimplePattern::try_from((&_tmp0.fields()[0]).clone())?; Ok(SimplePattern::Setof {pattern: std::boxed::Box::new(_tmp2)}) } -fn _parse_simple_pattern_dictof(value: &preserves::value::IOValue) -> std::result::Result { +fn _io_parse_simple_pattern_dictof(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = value.value().to_record(None)?; - if _tmp0.label() != &*LIT_27_DICTOF { return Err(_support::ParseError::ConformanceError); } + if _tmp0.label() != &*_io_::LIT_27_DICTOF { return Err(_support::ParseError::ConformanceError); } let _tmp1 = (); if _tmp0.fields().len() < 2 { return Err(_support::ParseError::ConformanceError); } let _tmp2 = SimplePattern::try_from((&_tmp0.fields()[0]).clone())?; @@ -788,7 +1424,7 @@ fn _parse_simple_pattern_dictof(value: &preserves::value::IOValue) -> std::resul Ok(SimplePattern::Dictof {key: std::boxed::Box::new(_tmp2), value: std::boxed::Box::new(_tmp3)}) } -fn _parse_simple_pattern_ref(value: &preserves::value::IOValue) -> std::result::Result { +fn _io_parse_simple_pattern_ref(value: &preserves::value::IOValue) -> std::result::Result { let _tmp0 = Ref::try_from(value.clone())?; Ok(SimplePattern::Ref(std::boxed::Box::new(_tmp0))) } @@ -797,14 +1433,14 @@ impl std::convert::TryFrom for SimplePattern { type Error = _support::ParseError; fn try_from(value: preserves::value::IOValue) -> std::result::Result { let value = &value; - if let Ok(r) = _parse_simple_pattern_any(value) { return Ok(r); } - if let Ok(r) = _parse_simple_pattern_atom(value) { return Ok(r); } - if let Ok(r) = _parse_simple_pattern_embedded(value) { return Ok(r); } - if let Ok(r) = _parse_simple_pattern_lit(value) { return Ok(r); } - if let Ok(r) = _parse_simple_pattern_seqof(value) { return Ok(r); } - if let Ok(r) = _parse_simple_pattern_setof(value) { return Ok(r); } - if let Ok(r) = _parse_simple_pattern_dictof(value) { return Ok(r); } - if let Ok(r) = _parse_simple_pattern_ref(value) { return Ok(r); } + if let Ok(r) = _io_parse_simple_pattern_any(value) { return Ok(r); } + if let Ok(r) = _io_parse_simple_pattern_atom(value) { return Ok(r); } + if let Ok(r) = _io_parse_simple_pattern_embedded(value) { return Ok(r); } + if let Ok(r) = _io_parse_simple_pattern_lit(value) { return Ok(r); } + if let Ok(r) = _io_parse_simple_pattern_seqof(value) { return Ok(r); } + if let Ok(r) = _io_parse_simple_pattern_setof(value) { return Ok(r); } + if let Ok(r) = _io_parse_simple_pattern_dictof(value) { return Ok(r); } + if let Ok(r) = _io_parse_simple_pattern_ref(value) { return Ok(r); } Err(_support::ParseError::ConformanceError) } } @@ -812,34 +1448,34 @@ impl std::convert::TryFrom for SimplePattern { impl std::convert::From<&SimplePattern> for preserves::value::IOValue { fn from(value: &SimplePattern) -> Self { match value { - SimplePattern::Any => (&*LIT_21_ANY).clone(), + SimplePattern::Any => (&*_io_::LIT_21_ANY).clone(), SimplePattern::Atom {atom_kind: _tmp0} => { - let mut _tmp1 = preserves::value::Record(vec![(&*LIT_22_ATOM).clone()]); + let mut _tmp1 = preserves::value::Record(vec![(&*_io_::LIT_22_ATOM).clone()]); _tmp1.fields_vec_mut().push(preserves::value::IOValue::from(_tmp0.as_ref())); _tmp1.finish().wrap() }, SimplePattern::Embedded {interface: _tmp0} => { - let mut _tmp1 = preserves::value::Record(vec![(&*LIT_23_EMBEDDED).clone()]); + let mut _tmp1 = preserves::value::Record(vec![(&*_io_::LIT_23_EMBEDDED).clone()]); _tmp1.fields_vec_mut().push(preserves::value::IOValue::from(_tmp0.as_ref())); _tmp1.finish().wrap() }, SimplePattern::Lit {value: _tmp0} => { - let mut _tmp1 = preserves::value::Record(vec![(&*LIT_24_LIT).clone()]); + let mut _tmp1 = preserves::value::Record(vec![(&*_io_::LIT_24_LIT).clone()]); _tmp1.fields_vec_mut().push(_tmp0.to_io_value()); _tmp1.finish().wrap() }, SimplePattern::Seqof {pattern: _tmp0} => { - let mut _tmp1 = preserves::value::Record(vec![(&*LIT_25_SEQOF).clone()]); + let mut _tmp1 = preserves::value::Record(vec![(&*_io_::LIT_25_SEQOF).clone()]); _tmp1.fields_vec_mut().push(preserves::value::IOValue::from(_tmp0.as_ref())); _tmp1.finish().wrap() }, SimplePattern::Setof {pattern: _tmp0} => { - let mut _tmp1 = preserves::value::Record(vec![(&*LIT_26_SETOF).clone()]); + let mut _tmp1 = preserves::value::Record(vec![(&*_io_::LIT_26_SETOF).clone()]); _tmp1.fields_vec_mut().push(preserves::value::IOValue::from(_tmp0.as_ref())); _tmp1.finish().wrap() }, SimplePattern::Dictof {key: _tmp0, value: _tmp1} => { - let mut _tmp2 = preserves::value::Record(vec![(&*LIT_27_DICTOF).clone()]); + let mut _tmp2 = preserves::value::Record(vec![(&*_io_::LIT_27_DICTOF).clone()]); _tmp2.fields_vec_mut().push(preserves::value::IOValue::from(_tmp0.as_ref())); _tmp2.fields_vec_mut().push(preserves::value::IOValue::from(_tmp1.as_ref())); _tmp2.finish().wrap() @@ -849,15 +1485,153 @@ impl std::convert::From<&SimplePattern> for preserves::value::IOValue { } } +fn _any_parse_simple_pattern_any(value: &_Any) -> std::result::Result { + if value != &*_any_::LIT_21_ANY { return Err(_support::ParseError::ConformanceError); } + let _tmp0 = (); + Ok(SimplePattern::Any) +} + +fn _any_parse_simple_pattern_atom(value: &_Any) -> std::result::Result { + let _tmp0 = value.value().to_record(None)?; + if _tmp0.label() != &*_any_::LIT_22_ATOM { return Err(_support::ParseError::ConformanceError); } + let _tmp1 = (); + if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } + let _tmp2 = AtomKind::try_from((&_tmp0.fields()[0]).clone())?; + Ok(SimplePattern::Atom {atom_kind: std::boxed::Box::new(_tmp2)}) +} + +fn _any_parse_simple_pattern_embedded(value: &_Any) -> std::result::Result { + let _tmp0 = value.value().to_record(None)?; + if _tmp0.label() != &*_any_::LIT_23_EMBEDDED { return Err(_support::ParseError::ConformanceError); } + let _tmp1 = (); + if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } + let _tmp2 = SimplePattern::try_from((&_tmp0.fields()[0]).clone())?; + Ok(SimplePattern::Embedded {interface: std::boxed::Box::new(_tmp2)}) +} + +fn _any_parse_simple_pattern_lit(value: &_Any) -> std::result::Result { + let _tmp0 = value.value().to_record(None)?; + if _tmp0.label() != &*_any_::LIT_24_LIT { return Err(_support::ParseError::ConformanceError); } + let _tmp1 = (); + if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } + let _tmp2 = (&_tmp0.fields()[0]); + Ok(SimplePattern::Lit {value: _tmp2.clone()}) +} + +fn _any_parse_simple_pattern_seqof(value: &_Any) -> std::result::Result { + let _tmp0 = value.value().to_record(None)?; + if _tmp0.label() != &*_any_::LIT_25_SEQOF { return Err(_support::ParseError::ConformanceError); } + let _tmp1 = (); + if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } + let _tmp2 = SimplePattern::try_from((&_tmp0.fields()[0]).clone())?; + Ok(SimplePattern::Seqof {pattern: std::boxed::Box::new(_tmp2)}) +} + +fn _any_parse_simple_pattern_setof(value: &_Any) -> std::result::Result { + let _tmp0 = value.value().to_record(None)?; + if _tmp0.label() != &*_any_::LIT_26_SETOF { return Err(_support::ParseError::ConformanceError); } + let _tmp1 = (); + if _tmp0.fields().len() < 1 { return Err(_support::ParseError::ConformanceError); } + let _tmp2 = SimplePattern::try_from((&_tmp0.fields()[0]).clone())?; + Ok(SimplePattern::Setof {pattern: std::boxed::Box::new(_tmp2)}) +} + +fn _any_parse_simple_pattern_dictof(value: &_Any) -> std::result::Result { + let _tmp0 = value.value().to_record(None)?; + if _tmp0.label() != &*_any_::LIT_27_DICTOF { return Err(_support::ParseError::ConformanceError); } + let _tmp1 = (); + if _tmp0.fields().len() < 2 { return Err(_support::ParseError::ConformanceError); } + let _tmp2 = SimplePattern::try_from((&_tmp0.fields()[0]).clone())?; + let _tmp3 = SimplePattern::try_from((&_tmp0.fields()[1]).clone())?; + Ok(SimplePattern::Dictof {key: std::boxed::Box::new(_tmp2), value: std::boxed::Box::new(_tmp3)}) +} + +fn _any_parse_simple_pattern_ref(value: &_Any) -> std::result::Result { + let _tmp0 = Ref::try_from(value.clone())?; + Ok(SimplePattern::Ref(std::boxed::Box::new(_tmp0))) +} + +impl std::convert::TryFrom<_Any> for SimplePattern { + type Error = _support::ParseError; + fn try_from(value: _Any) -> std::result::Result { + let value = &value; + if let Ok(r) = _any_parse_simple_pattern_any(value) { return Ok(r); } + if let Ok(r) = _any_parse_simple_pattern_atom(value) { return Ok(r); } + if let Ok(r) = _any_parse_simple_pattern_embedded(value) { return Ok(r); } + if let Ok(r) = _any_parse_simple_pattern_lit(value) { return Ok(r); } + if let Ok(r) = _any_parse_simple_pattern_seqof(value) { return Ok(r); } + if let Ok(r) = _any_parse_simple_pattern_setof(value) { return Ok(r); } + if let Ok(r) = _any_parse_simple_pattern_dictof(value) { return Ok(r); } + if let Ok(r) = _any_parse_simple_pattern_ref(value) { return Ok(r); } + Err(_support::ParseError::ConformanceError) + } +} + +impl std::convert::From<&SimplePattern> for _Any { + fn from(value: &SimplePattern) -> Self { + match value { + SimplePattern::Any => (&*_any_::LIT_21_ANY).clone(), + SimplePattern::Atom {atom_kind: _tmp0} => { + let mut _tmp1 = preserves::value::Record(vec![(&*_any_::LIT_22_ATOM).clone()]); + _tmp1.fields_vec_mut().push(_Any::from(_tmp0.as_ref())); + _tmp1.finish().wrap() + }, + SimplePattern::Embedded {interface: _tmp0} => { + let mut _tmp1 = preserves::value::Record(vec![(&*_any_::LIT_23_EMBEDDED).clone()]); + _tmp1.fields_vec_mut().push(_Any::from(_tmp0.as_ref())); + _tmp1.finish().wrap() + }, + SimplePattern::Lit {value: _tmp0} => { + let mut _tmp1 = preserves::value::Record(vec![(&*_any_::LIT_24_LIT).clone()]); + _tmp1.fields_vec_mut().push(_tmp0.clone()); + _tmp1.finish().wrap() + }, + SimplePattern::Seqof {pattern: _tmp0} => { + let mut _tmp1 = preserves::value::Record(vec![(&*_any_::LIT_25_SEQOF).clone()]); + _tmp1.fields_vec_mut().push(_Any::from(_tmp0.as_ref())); + _tmp1.finish().wrap() + }, + SimplePattern::Setof {pattern: _tmp0} => { + let mut _tmp1 = preserves::value::Record(vec![(&*_any_::LIT_26_SETOF).clone()]); + _tmp1.fields_vec_mut().push(_Any::from(_tmp0.as_ref())); + _tmp1.finish().wrap() + }, + SimplePattern::Dictof {key: _tmp0, value: _tmp1} => { + let mut _tmp2 = preserves::value::Record(vec![(&*_any_::LIT_27_DICTOF).clone()]); + _tmp2.fields_vec_mut().push(_Any::from(_tmp0.as_ref())); + _tmp2.fields_vec_mut().push(_Any::from(_tmp1.as_ref())); + _tmp2.finish().wrap() + }, + SimplePattern::Ref(_tmp0) => _Any::from(_tmp0.as_ref()), + } + } +} + impl std::convert::TryFrom for Version { type Error = _support::ParseError; fn try_from(value: preserves::value::IOValue) -> std::result::Result { let value = &value; - if value != &*LIT_28_1 { return Err(_support::ParseError::ConformanceError); } + if value != &*_io_::LIT_28_1 { return Err(_support::ParseError::ConformanceError); } let _tmp0 = (); Ok(Version) } } -impl std::convert::From<&Version> for preserves::value::IOValue {fn from(value: &Version) -> Self {let Version = value; (&*LIT_28_1).clone()}} +impl std::convert::From<&Version> for preserves::value::IOValue { + fn from(value: &Version) -> Self {let Version = value; (&*_io_::LIT_28_1).clone()} +} + +impl std::convert::TryFrom<_Any> for Version { + type Error = _support::ParseError; + fn try_from(value: _Any) -> std::result::Result { + let value = &value; + if value != &*_any_::LIT_28_1 { return Err(_support::ParseError::ConformanceError); } + let _tmp0 = (); + Ok(Version) + } +} + +impl std::convert::From<&Version> for _Any { + fn from(value: &Version) -> Self {let Version = value; (&*_any_::LIT_28_1).clone()} +}