diff --git a/implementations/rust/preserves-schema/src/compiler/mod.rs b/implementations/rust/preserves-schema/src/compiler/mod.rs index 2c8a394..c249d49 100644 --- a/implementations/rust/preserves-schema/src/compiler/mod.rs +++ b/implementations/rust/preserves-schema/src/compiler/mod.rs @@ -12,7 +12,6 @@ use crate::syntax::block::constructors::*; use glob::glob; use preserves::value::Map; -use preserves::value::NestedValue; use preserves::value::PackedReader; use preserves::value::Reader; use preserves::value::Set; @@ -92,9 +91,6 @@ 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); @@ -104,14 +100,28 @@ pub fn compile(config: &CompilerConfig) -> Result<(), std::io::Error> { DirBuilder::new().recursive(true).create(output_path.parent().unwrap())?; let mut m = context::ModuleContext::new(config); - m.define_type(item(seq!["pub type _Ptr = ", match &v.embedded_type { - EmbeddedTypeName::False => item("preserves::value::IOValue".to_owned()), - EmbeddedTypeName::Ref(r) => item(seq!["std::sync::Arc", anglebrackets![m.render_ref(&**r)]]), - }, ";"])); - m.define_type(item(seq!["pub type _Any = preserves::value::ArcValue<_Ptr>;"])); + let mut modes: Vec = + vec![context::ModuleContextMode::TargetAny]; + + match &v.embedded_type { + EmbeddedTypeName::False => { + m.define_type(item(seq!["pub type _Ptr = preserves::value::IOValue;"])); + m.define_type(item(seq!["pub type _Any = preserves::value::IOValue;"])); + } + EmbeddedTypeName::Ref(r) => { + modes.push(context::ModuleContextMode::TargetIOValue); + m.define_type(item(seq!["pub type _Dom = ", m.render_ref(&**r), ";"])); + m.define_type(item(seq!["pub type _Ptr = std::sync::Arc<_Dom>;"])); + m.define_type(item(seq!["pub type _Any = preserves::value::ArcValue<_Ptr>;"])); + } + } + + let modes = modes; // rebind as non-mutable for (n, d) in &v.definitions.0 { m.define_type(item(types::render_definition_type(&m, n, &types::definition_type(d)))); + m.define_type(item(seq!["impl preserves::value::Domain for ", + names::render_constructor(n), " {}"])); for mode in &modes { m.mode = *mode; parsers::gen_definition_parser(&mut m, n, d); @@ -136,18 +146,15 @@ pub fn compile(config: &CompilerConfig) -> Result<(), std::io::Error> { 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(); + let bs = preserves::value::PackedWriter::encode(&value).unwrap(); lines.push(format!( - " pub static ref {}: {} = /* {:?} */ {}::from_io_value(&from_bytes(&vec!{:?}).unwrap()).unwrap();", + " pub static ref {}: {} = /* {:?} */ _support::decode_lit(&vec!{:?}).unwrap();", name, m.target(), value, - m.target(), bs)); } lines.push(" }".to_owned()); diff --git a/implementations/rust/preserves-schema/src/compiler/parsers.rs b/implementations/rust/preserves-schema/src/compiler/parsers.rs index ed8dca4..92c110f 100644 --- a/implementations/rust/preserves-schema/src/compiler/parsers.rs +++ b/implementations/rust/preserves-schema/src/compiler/parsers.rs @@ -108,7 +108,7 @@ fn simple_pattern_parser( SimplePattern::Any => { match ctxt.m.mode { ModuleContextMode::TargetIOValue => - push_let(body, item(dest.to_owned()), item(seq!["_Any::from_io_value", parens![src.to_owned()], "?"])), + push_let(body, item(dest.to_owned()), item(seq!["_support::decode_embedded", parens![src.to_owned()], "?"])), ModuleContextMode::TargetAny => push_let(body, item(dest.to_owned()), item(src.to_owned())), } @@ -131,9 +131,9 @@ fn simple_pattern_parser( 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()"]], - "?"])), + "std::sync::Arc::new(_Dom::try_from", + parens![seq![src.to_owned(), ".value().to_embedded()?"]], + "?)"])), ModuleContextMode::TargetAny => push_let(body, item(dest.to_owned()), item(seq![ parens![seq![src.to_owned(), ".value().to_embedded()?"]]])), diff --git a/implementations/rust/preserves-schema/src/compiler/unparsers.rs b/implementations/rust/preserves-schema/src/compiler/unparsers.rs index a71ec18..36f7654 100644 --- a/implementations/rust/preserves-schema/src/compiler/unparsers.rs +++ b/implementations/rust/preserves-schema/src/compiler/unparsers.rs @@ -123,7 +123,7 @@ fn simple_pattern_unparser( SimplePattern::Any => { match ctxt.m.mode { ModuleContextMode::TargetIOValue => - item(seq![src.as_ref().unwrap().to_owned(), ".to_io_value()"]), + item(seq!["_support::encode_embedded", parens![src.as_ref().unwrap().to_owned()]]), ModuleContextMode::TargetAny => item(seq![src.as_ref().unwrap().to_owned(), ".clone()"]), } @@ -141,7 +141,7 @@ fn simple_pattern_unparser( SimplePattern::Embedded { .. } => { match ctxt.m.mode { ModuleContextMode::TargetIOValue => - item(seq!["preserves::value::Value::Embedded(", src.as_ref().unwrap().to_owned(), ".as_preserves()).wrap()"]), + item(seq!["preserves::value::Value::Embedded(preserves::value::IOValue::from(&**", src.as_ref().unwrap().to_owned(), ")).wrap()"]), ModuleContextMode::TargetAny => item(seq!["preserves::value::Value::Embedded(", src.as_ref().unwrap().to_owned(), ".clone()).wrap()"]), } diff --git a/implementations/rust/preserves-schema/src/gen/schema.rs b/implementations/rust/preserves-schema/src/gen/schema.rs index bd82a5c..4eea3d6 100644 --- a/implementations/rust/preserves-schema/src/gen/schema.rs +++ b/implementations/rust/preserves-schema/src/gen/schema.rs @@ -6,95 +6,61 @@ use preserves::value::Domain; use preserves::value::NestedValue; use crate::support as _support; -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 static ref LIT_15_FALSE: _Any = /* #f */ _support::decode_lit(&vec![128]).unwrap(); + pub static ref LIT_28_1: _Any = /* 1 */ _support::decode_lit(&vec![145]).unwrap(); + pub static ref LIT_0_BOOLEAN: _Any = /* Boolean */ _support::decode_lit(&vec![179, 7, 66, 111, 111, 108, 101, 97, 110]).unwrap(); + pub static ref LIT_5_BYTE_STRING: _Any = /* ByteString */ _support::decode_lit(&vec![179, 10, 66, 121, 116, 101, 83, 116, 114, 105, 110, 103]).unwrap(); + pub static ref LIT_2_DOUBLE: _Any = /* Double */ _support::decode_lit(&vec![179, 6, 68, 111, 117, 98, 108, 101]).unwrap(); + pub static ref LIT_1_FLOAT: _Any = /* Float */ _support::decode_lit(&vec![179, 5, 70, 108, 111, 97, 116]).unwrap(); + pub static ref LIT_3_SIGNED_INTEGER: _Any = /* SignedInteger */ _support::decode_lit(&vec![179, 13, 83, 105, 103, 110, 101, 100, 73, 110, 116, 101, 103, 101, 114]).unwrap(); + pub static ref LIT_4_STRING: _Any = /* String */ _support::decode_lit(&vec![179, 6, 83, 116, 114, 105, 110, 103]).unwrap(); + pub static ref LIT_6_SYMBOL: _Any = /* Symbol */ _support::decode_lit(&vec![179, 6, 83, 121, 109, 98, 111, 108]).unwrap(); + pub static ref LIT_14_AND: _Any = /* and */ _support::decode_lit(&vec![179, 3, 97, 110, 100]).unwrap(); + pub static ref LIT_21_ANY: _Any = /* any */ _support::decode_lit(&vec![179, 3, 97, 110, 121]).unwrap(); + pub static ref LIT_22_ATOM: _Any = /* atom */ _support::decode_lit(&vec![179, 4, 97, 116, 111, 109]).unwrap(); + pub static ref LIT_8_BUNDLE: _Any = /* bundle */ _support::decode_lit(&vec![179, 6, 98, 117, 110, 100, 108, 101]).unwrap(); + pub static ref LIT_18_DEFINITIONS: _Any = /* definitions */ _support::decode_lit(&vec![179, 11, 100, 101, 102, 105, 110, 105, 116, 105, 111, 110, 115]).unwrap(); + pub static ref LIT_12_DICT: _Any = /* dict */ _support::decode_lit(&vec![179, 4, 100, 105, 99, 116]).unwrap(); + pub static ref LIT_27_DICTOF: _Any = /* dictof */ _support::decode_lit(&vec![179, 6, 100, 105, 99, 116, 111, 102]).unwrap(); + pub static ref LIT_23_EMBEDDED: _Any = /* embedded */ _support::decode_lit(&vec![179, 8, 101, 109, 98, 101, 100, 100, 101, 100]).unwrap(); + pub static ref LIT_19_EMBEDDED_TYPE: _Any = /* embeddedType */ _support::decode_lit(&vec![179, 12, 101, 109, 98, 101, 100, 100, 101, 100, 84, 121, 112, 101]).unwrap(); + pub static ref LIT_24_LIT: _Any = /* lit */ _support::decode_lit(&vec![179, 3, 108, 105, 116]).unwrap(); + pub static ref LIT_7_NAMED: _Any = /* named */ _support::decode_lit(&vec![179, 5, 110, 97, 109, 101, 100]).unwrap(); + pub static ref LIT_13_OR: _Any = /* or */ _support::decode_lit(&vec![179, 2, 111, 114]).unwrap(); + pub static ref LIT_9_REC: _Any = /* rec */ _support::decode_lit(&vec![179, 3, 114, 101, 99]).unwrap(); + pub static ref LIT_16_REF: _Any = /* ref */ _support::decode_lit(&vec![179, 3, 114, 101, 102]).unwrap(); + pub static ref LIT_17_SCHEMA: _Any = /* schema */ _support::decode_lit(&vec![179, 6, 115, 99, 104, 101, 109, 97]).unwrap(); + pub static ref LIT_25_SEQOF: _Any = /* seqof */ _support::decode_lit(&vec![179, 5, 115, 101, 113, 111, 102]).unwrap(); + pub static ref LIT_26_SETOF: _Any = /* setof */ _support::decode_lit(&vec![179, 5, 115, 101, 116, 111, 102]).unwrap(); + pub static ref LIT_10_TUPLE: _Any = /* tuple */ _support::decode_lit(&vec![179, 5, 116, 117, 112, 108, 101]).unwrap(); + pub static ref LIT_11_TUPLE_PREFIX: _Any = /* tuplePrefix */ _support::decode_lit(&vec![179, 11, 116, 117, 112, 108, 101, 80, 114, 101, 102, 105, 120]).unwrap(); + pub static ref LIT_20_VERSION: _Any = /* version */ _support::decode_lit(&vec![179, 7, 118, 101, 114, 115, 105, 111, 110]).unwrap(); } } pub type _Ptr = preserves::value::IOValue; -pub type _Any = preserves::value::ArcValue<_Ptr>; +pub type _Any = preserves::value::IOValue; #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub enum AtomKind {Boolean, Float, Double, SignedInteger, String, ByteString, Symbol} +impl preserves::value::Domain for AtomKind {} + #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub struct Binding {pub name: std::string::String, pub pattern: SimplePattern} +impl preserves::value::Domain for Binding {} + #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub struct Bundle {pub modules: Modules} +impl preserves::value::Domain for Bundle {} + #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub enum CompoundPattern { Rec {label: std::boxed::Box, fields: std::boxed::Box}, @@ -106,6 +72,8 @@ pub enum CompoundPattern { Dict {entries: std::boxed::Box} } +impl preserves::value::Domain for CompoundPattern {} + #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub enum Definition { Or { @@ -121,39 +89,61 @@ pub enum Definition { Pattern(std::boxed::Box) } +impl preserves::value::Domain for Definition {} + #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub struct Definitions(pub preserves::value::Map); +impl preserves::value::Domain for Definitions {} + #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub struct DictionaryEntries(pub preserves::value::Map<_Any, NamedSimplePattern>); +impl preserves::value::Domain for DictionaryEntries {} + #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub enum EmbeddedTypeName {Ref(std::boxed::Box), False} +impl preserves::value::Domain for EmbeddedTypeName {} + #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub struct ModulePath(pub std::vec::Vec); +impl preserves::value::Domain for ModulePath {} + #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub struct Modules(pub preserves::value::Map); +impl preserves::value::Domain for Modules {} + #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub struct NamedAlternative {pub variant_label: std::string::String, pub pattern: Pattern} +impl preserves::value::Domain for NamedAlternative {} + #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub enum NamedPattern {Named(std::boxed::Box), Anonymous(std::boxed::Box)} +impl preserves::value::Domain for NamedPattern {} + #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub enum NamedSimplePattern {Named(std::boxed::Box), Anonymous(std::boxed::Box)} +impl preserves::value::Domain for NamedSimplePattern {} + #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub enum Pattern { SimplePattern(std::boxed::Box), CompoundPattern(std::boxed::Box) } +impl preserves::value::Domain for Pattern {} + #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub struct Ref {pub module: ModulePath, pub name: std::string::String} +impl preserves::value::Domain for Ref {} + #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub struct Schema { pub definitions: Definitions, @@ -161,6 +151,8 @@ pub struct Schema { pub version: Version } +impl preserves::value::Domain for Schema {} + #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub enum SimplePattern { Any, @@ -173,78 +165,12 @@ pub enum SimplePattern { Ref(std::boxed::Box) } +impl preserves::value::Domain for SimplePattern {} + #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Hash)] pub struct Version; -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 _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 _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 _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 _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 _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 _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) -} - -impl std::convert::TryFrom<&preserves::value::IOValue> for AtomKind { - type Error = _support::ParseError; - fn try_from(value: &preserves::value::IOValue) -> std::result::Result { - 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) - } -} - -impl std::convert::From<&AtomKind> for preserves::value::IOValue { - fn from(value: &AtomKind) -> Self { - match value { - 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(), - } - } -} +impl preserves::value::Domain for Version {} fn _any_parse_atom_kind_boolean(value: &_Any) -> std::result::Result { if value != &*_any_::LIT_0_BOOLEAN { return Err(_support::ParseError::ConformanceError); } @@ -316,31 +242,6 @@ impl std::convert::From<&AtomKind> for _Any { } } -impl std::convert::TryFrom<&preserves::value::IOValue> for Binding { - type Error = _support::ParseError; - fn try_from(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = value.value().to_record(None)?; - 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()?; - let _tmp3 = SimplePattern::try_from((&_tmp0.fields()[1]))?; - Ok(Binding {name: _tmp2.clone(), pattern: _tmp3}) - } -} - -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![(&*_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() - } - } -} - impl std::convert::TryFrom<&_Any> for Binding { type Error = _support::ParseError; fn try_from(value: &_Any) -> std::result::Result { @@ -366,29 +267,6 @@ impl std::convert::From<&Binding> for _Any { } } -impl std::convert::TryFrom<&preserves::value::IOValue> for Bundle { - type Error = _support::ParseError; - fn try_from(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = value.value().to_record(None)?; - 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]))?; - Ok(Bundle {modules: _tmp2}) - } -} - -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![(&*_io_::LIT_8_BUNDLE).clone()]); - _tmp1.fields_vec_mut().push(preserves::value::IOValue::from(_tmp0)); - _tmp1.finish().wrap() - } - } -} - impl std::convert::TryFrom<&_Any> for Bundle { type Error = _support::ParseError; fn try_from(value: &_Any) -> std::result::Result { @@ -412,100 +290,6 @@ impl std::convert::From<&Bundle> for _Any { } } -fn _io_parse_compound_pattern_rec(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = value.value().to_record(None)?; - 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]))?; - let _tmp3 = NamedPattern::try_from((&_tmp0.fields()[1]))?; - Ok(CompoundPattern::Rec {label: std::boxed::Box::new(_tmp2), fields: std::boxed::Box::new(_tmp3)}) -} - -fn _io_parse_compound_pattern_tuple(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = value.value().to_record(None)?; - 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()?; - let mut _tmp2 = std::vec::Vec::new(); - for _tmp4 in &_tmp3[0..] {let _tmp5 = NamedPattern::try_from(_tmp4)?; _tmp2.push(_tmp5);} - Ok(CompoundPattern::Tuple {patterns: _tmp2}) -} - -fn _io_parse_compound_pattern_tuple_prefix(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = value.value().to_record(None)?; - 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()?; - let mut _tmp2 = std::vec::Vec::new(); - for _tmp4 in &_tmp3[0..] {let _tmp5 = NamedPattern::try_from(_tmp4)?; _tmp2.push(_tmp5);} - let _tmp6 = NamedSimplePattern::try_from((&_tmp0.fields()[1]))?; - Ok(CompoundPattern::TuplePrefix {fixed: _tmp2, variable: std::boxed::Box::new(_tmp6)}) -} - -fn _io_parse_compound_pattern_dict(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = value.value().to_record(None)?; - 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]))?; - Ok(CompoundPattern::Dict {entries: std::boxed::Box::new(_tmp2)}) -} - -impl std::convert::TryFrom<&preserves::value::IOValue> for CompoundPattern { - type Error = _support::ParseError; - fn try_from(value: &preserves::value::IOValue) -> std::result::Result { - 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) - } -} - -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![(&*_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![(&*_io_::LIT_10_TUPLE).clone()]); - _tmp1.fields_vec_mut().push( - { - let mut _tmp2 = vec![]; - for _tmp3 in _tmp0 {_tmp2.push(preserves::value::IOValue::from(_tmp3));} - preserves::value::Value::Sequence(_tmp2).wrap() - } - ); - _tmp1.finish().wrap() - }, - CompoundPattern::TuplePrefix {fixed: _tmp0, variable: _tmp1} => { - let mut _tmp2 = preserves::value::Record(vec![(&*_io_::LIT_11_TUPLE_PREFIX).clone()]); - _tmp2.fields_vec_mut().push( - { - let mut _tmp3 = vec![]; - for _tmp4 in _tmp0 {_tmp3.push(preserves::value::IOValue::from(_tmp4));} - preserves::value::Value::Sequence(_tmp3).wrap() - } - ); - _tmp2.fields_vec_mut().push(preserves::value::IOValue::from(_tmp1.as_ref())); - _tmp2.finish().wrap() - }, - CompoundPattern::Dict {entries: _tmp0} => { - 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() - }, - } - } -} - fn _any_parse_compound_pattern_rec(value: &_Any) -> std::result::Result { let _tmp0 = value.value().to_record(None)?; if _tmp0.label() != &*_any_::LIT_9_REC { return Err(_support::ParseError::ConformanceError); } @@ -600,91 +384,6 @@ impl std::convert::From<&CompoundPattern> for _Any { } } -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()?; - if _tmp2.len() < 2 { return Err(_support::ParseError::ConformanceError); } - let _tmp3 = NamedAlternative::try_from((&_tmp2[0]))?; - let _tmp4 = NamedAlternative::try_from((&_tmp2[1]))?; - let mut _tmp5 = std::vec::Vec::new(); - for _tmp6 in &_tmp2[2..] {let _tmp7 = NamedAlternative::try_from(_tmp6)?; _tmp5.push(_tmp7);} - Ok(Definition::Or { - pattern_0: std::boxed::Box::new(_tmp3), - pattern_1: std::boxed::Box::new(_tmp4), - pattern_n: _tmp5 - }) -} - -fn _io_parse_definition_and(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = value.value().to_record(None)?; - 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()?; - if _tmp2.len() < 2 { return Err(_support::ParseError::ConformanceError); } - let _tmp3 = NamedPattern::try_from((&_tmp2[0]))?; - let _tmp4 = NamedPattern::try_from((&_tmp2[1]))?; - let mut _tmp5 = std::vec::Vec::new(); - for _tmp6 in &_tmp2[2..] {let _tmp7 = NamedPattern::try_from(_tmp6)?; _tmp5.push(_tmp7);} - Ok(Definition::And { - pattern_0: std::boxed::Box::new(_tmp3), - pattern_1: std::boxed::Box::new(_tmp4), - pattern_n: _tmp5 - }) -} - -fn _io_parse_definition_pattern(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = Pattern::try_from(value)?; - Ok(Definition::Pattern(std::boxed::Box::new(_tmp0))) -} - -impl std::convert::TryFrom<&preserves::value::IOValue> for Definition { - type Error = _support::ParseError; - fn try_from(value: &preserves::value::IOValue) -> std::result::Result { - 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) - } -} - -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![(&*_io_::LIT_13_OR).clone()]); - _tmp3.fields_vec_mut().push( - { - let mut _tmp4 = vec![]; - _tmp4.push(preserves::value::IOValue::from(_tmp0.as_ref())); - _tmp4.push(preserves::value::IOValue::from(_tmp1.as_ref())); - for _tmp5 in _tmp2 {_tmp4.push(preserves::value::IOValue::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![(&*_io_::LIT_14_AND).clone()]); - _tmp3.fields_vec_mut().push( - { - let mut _tmp4 = vec![]; - _tmp4.push(preserves::value::IOValue::from(_tmp0.as_ref())); - _tmp4.push(preserves::value::IOValue::from(_tmp1.as_ref())); - for _tmp5 in _tmp2 {_tmp4.push(preserves::value::IOValue::from(_tmp5));} - preserves::value::Value::Sequence(_tmp4).wrap() - } - ); - _tmp3.finish().wrap() - }, - Definition::Pattern(_tmp0) => preserves::value::IOValue::from(_tmp0.as_ref()), - } - } -} - 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); } @@ -770,29 +469,6 @@ impl std::convert::From<&Definition> for _Any { } } -impl std::convert::TryFrom<&preserves::value::IOValue> for Definitions { - type Error = _support::ParseError; - fn try_from(value: &preserves::value::IOValue) -> std::result::Result { - 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)?; - _tmp0.insert(_tmp3.clone(), _tmp4); - } - Ok(Definitions(_tmp0)) - } -} - -impl std::convert::From<&Definitions> for preserves::value::IOValue { - fn from(value: &Definitions) -> Self { - let Definitions(_tmp0) = value; - preserves::value::Value::Dictionary(_tmp0.iter().map(|(_tmp1, _tmp2)| ( - preserves::value::Value::symbol(_tmp1).wrap(), - preserves::value::IOValue::from(_tmp2) - )).collect()).wrap() - } -} - impl std::convert::TryFrom<&_Any> for Definitions { type Error = _support::ParseError; fn try_from(value: &_Any) -> std::result::Result { @@ -813,26 +489,6 @@ impl std::convert::From<&Definitions> for _Any { } } -impl std::convert::TryFrom<&preserves::value::IOValue> for DictionaryEntries { - type Error = _support::ParseError; - fn try_from(value: &preserves::value::IOValue) -> std::result::Result { - let mut _tmp0 = preserves::value::Map::new(); - for (_tmp1, _tmp2) in value.value().to_dictionary()? { - let _tmp3 = _Any::from_io_value(_tmp1)?; - let _tmp4 = NamedSimplePattern::try_from(_tmp2)?; - _tmp0.insert(_tmp3.clone(), _tmp4); - } - Ok(DictionaryEntries(_tmp0)) - } -} - -impl std::convert::From<&DictionaryEntries> for preserves::value::IOValue { - fn from(value: &DictionaryEntries) -> Self { - let DictionaryEntries(_tmp0) = value; - preserves::value::Value::Dictionary(_tmp0.iter().map(|(_tmp1, _tmp2)| (_tmp1.to_io_value(), preserves::value::IOValue::from(_tmp2))).collect()).wrap() - } -} - impl std::convert::TryFrom<&_Any> for DictionaryEntries { type Error = _support::ParseError; fn try_from(value: &_Any) -> std::result::Result { @@ -853,35 +509,6 @@ impl std::convert::From<&DictionaryEntries> for _Any { } } -fn _io_parse_embedded_type_name_ref(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = Ref::try_from(value)?; - Ok(EmbeddedTypeName::Ref(std::boxed::Box::new(_tmp0))) -} - -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) -} - -impl std::convert::TryFrom<&preserves::value::IOValue> for EmbeddedTypeName { - type Error = _support::ParseError; - fn try_from(value: &preserves::value::IOValue) -> std::result::Result { - 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) - } -} - -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 => (&*_io_::LIT_15_FALSE).clone(), - } - } -} - fn _any_parse_embedded_type_name_ref(value: &_Any) -> std::result::Result { let _tmp0 = Ref::try_from(value)?; Ok(EmbeddedTypeName::Ref(std::boxed::Box::new(_tmp0))) @@ -911,27 +538,6 @@ impl std::convert::From<&EmbeddedTypeName> for _Any { } } -impl std::convert::TryFrom<&preserves::value::IOValue> for ModulePath { - type Error = _support::ParseError; - fn try_from(value: &preserves::value::IOValue) -> std::result::Result { - 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 preserves::value::IOValue { - 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<&_Any> for ModulePath { type Error = _support::ParseError; fn try_from(value: &_Any) -> std::result::Result { @@ -953,26 +559,6 @@ impl std::convert::From<&ModulePath> for _Any { } } -impl std::convert::TryFrom<&preserves::value::IOValue> for Modules { - type Error = _support::ParseError; - fn try_from(value: &preserves::value::IOValue) -> std::result::Result { - let mut _tmp0 = preserves::value::Map::new(); - for (_tmp1, _tmp2) in value.value().to_dictionary()? { - let _tmp3 = ModulePath::try_from(_tmp1)?; - let _tmp4 = Schema::try_from(_tmp2)?; - _tmp0.insert(_tmp3, _tmp4); - } - Ok(Modules(_tmp0)) - } -} - -impl std::convert::From<&Modules> for preserves::value::IOValue { - fn from(value: &Modules) -> Self { - let Modules(_tmp0) = value; - preserves::value::Value::Dictionary(_tmp0.iter().map(|(_tmp1, _tmp2)| (preserves::value::IOValue::from(_tmp1), preserves::value::IOValue::from(_tmp2))).collect()).wrap() - } -} - impl std::convert::TryFrom<&_Any> for Modules { type Error = _support::ParseError; fn try_from(value: &_Any) -> std::result::Result { @@ -993,29 +579,6 @@ impl std::convert::From<&Modules> for _Any { } } -impl std::convert::TryFrom<&preserves::value::IOValue> for NamedAlternative { - type Error = _support::ParseError; - fn try_from(value: &preserves::value::IOValue) -> std::result::Result { - 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]))?; - Ok(NamedAlternative {variant_label: _tmp1.clone(), pattern: _tmp2}) - } -} - -impl std::convert::From<&NamedAlternative> for preserves::value::IOValue { - 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(preserves::value::IOValue::from(_tmp1)); - preserves::value::Value::Sequence(_tmp2).wrap() - } - } -} - impl std::convert::TryFrom<&_Any> for NamedAlternative { type Error = _support::ParseError; fn try_from(value: &_Any) -> std::result::Result { @@ -1039,34 +602,6 @@ impl std::convert::From<&NamedAlternative> for _Any { } } -fn _io_parse_named_pattern_named(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = Binding::try_from(value)?; - Ok(NamedPattern::Named(std::boxed::Box::new(_tmp0))) -} - -fn _io_parse_named_pattern_anonymous(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = Pattern::try_from(value)?; - Ok(NamedPattern::Anonymous(std::boxed::Box::new(_tmp0))) -} - -impl std::convert::TryFrom<&preserves::value::IOValue> for NamedPattern { - type Error = _support::ParseError; - fn try_from(value: &preserves::value::IOValue) -> std::result::Result { - 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) - } -} - -impl std::convert::From<&NamedPattern> for preserves::value::IOValue { - fn from(value: &NamedPattern) -> Self { - match value { - NamedPattern::Named(_tmp0) => preserves::value::IOValue::from(_tmp0.as_ref()), - NamedPattern::Anonymous(_tmp0) => preserves::value::IOValue::from(_tmp0.as_ref()), - } - } -} - fn _any_parse_named_pattern_named(value: &_Any) -> std::result::Result { let _tmp0 = Binding::try_from(value)?; Ok(NamedPattern::Named(std::boxed::Box::new(_tmp0))) @@ -1095,34 +630,6 @@ impl std::convert::From<&NamedPattern> for _Any { } } -fn _io_parse_named_simple_pattern_named(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = Binding::try_from(value)?; - Ok(NamedSimplePattern::Named(std::boxed::Box::new(_tmp0))) -} - -fn _io_parse_named_simple_pattern_anonymous(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = SimplePattern::try_from(value)?; - Ok(NamedSimplePattern::Anonymous(std::boxed::Box::new(_tmp0))) -} - -impl std::convert::TryFrom<&preserves::value::IOValue> for NamedSimplePattern { - type Error = _support::ParseError; - fn try_from(value: &preserves::value::IOValue) -> std::result::Result { - 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) - } -} - -impl std::convert::From<&NamedSimplePattern> for preserves::value::IOValue { - fn from(value: &NamedSimplePattern) -> Self { - match value { - NamedSimplePattern::Named(_tmp0) => preserves::value::IOValue::from(_tmp0.as_ref()), - NamedSimplePattern::Anonymous(_tmp0) => preserves::value::IOValue::from(_tmp0.as_ref()), - } - } -} - fn _any_parse_named_simple_pattern_named(value: &_Any) -> std::result::Result { let _tmp0 = Binding::try_from(value)?; Ok(NamedSimplePattern::Named(std::boxed::Box::new(_tmp0))) @@ -1151,34 +658,6 @@ impl std::convert::From<&NamedSimplePattern> for _Any { } } -fn _io_parse_pattern_simple_pattern(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = SimplePattern::try_from(value)?; - Ok(Pattern::SimplePattern(std::boxed::Box::new(_tmp0))) -} - -fn _io_parse_pattern_compound_pattern(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = CompoundPattern::try_from(value)?; - Ok(Pattern::CompoundPattern(std::boxed::Box::new(_tmp0))) -} - -impl std::convert::TryFrom<&preserves::value::IOValue> for Pattern { - type Error = _support::ParseError; - fn try_from(value: &preserves::value::IOValue) -> std::result::Result { - 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) - } -} - -impl std::convert::From<&Pattern> for preserves::value::IOValue { - fn from(value: &Pattern) -> Self { - match value { - Pattern::SimplePattern(_tmp0) => preserves::value::IOValue::from(_tmp0.as_ref()), - Pattern::CompoundPattern(_tmp0) => preserves::value::IOValue::from(_tmp0.as_ref()), - } - } -} - fn _any_parse_pattern_simple_pattern(value: &_Any) -> std::result::Result { let _tmp0 = SimplePattern::try_from(value)?; Ok(Pattern::SimplePattern(std::boxed::Box::new(_tmp0))) @@ -1207,31 +686,6 @@ impl std::convert::From<&Pattern> for _Any { } } -impl std::convert::TryFrom<&preserves::value::IOValue> for Ref { - type Error = _support::ParseError; - fn try_from(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = value.value().to_record(None)?; - 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]))?; - let _tmp3 = (&_tmp0.fields()[1]).value().to_symbol()?; - Ok(Ref {module: _tmp2, name: _tmp3.clone()}) - } -} - -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![(&*_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() - } - } -} - impl std::convert::TryFrom<&_Any> for Ref { type Error = _support::ParseError; fn try_from(value: &_Any) -> std::result::Result { @@ -1257,43 +711,6 @@ impl std::convert::From<&Ref> for _Any { } } -impl std::convert::TryFrom<&preserves::value::IOValue> for Schema { - type Error = _support::ParseError; - fn try_from(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = value.value().to_record(None)?; - 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(&*_io_::LIT_18_DEFINITIONS).ok_or(_support::ParseError::ConformanceError)?; - let _tmp4 = Definitions::try_from(_tmp3)?; - let _tmp5 = _tmp2.get(&*_io_::LIT_19_EMBEDDED_TYPE).ok_or(_support::ParseError::ConformanceError)?; - let _tmp6 = EmbeddedTypeName::try_from(_tmp5)?; - let _tmp7 = _tmp2.get(&*_io_::LIT_20_VERSION).ok_or(_support::ParseError::ConformanceError)?; - let _tmp8 = Version::try_from(_tmp7)?; - Ok(Schema {definitions: _tmp4, embedded_type: _tmp6, version: _tmp8}) - } -} - -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![(&*_io_::LIT_17_SCHEMA).clone()]); - _tmp3.fields_vec_mut().push( - { - let mut _tmp4 = preserves::value::Map::new(); - _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() - } - ); - _tmp3.finish().wrap() - } - } -} - impl std::convert::TryFrom<&_Any> for Schema { type Error = _support::ParseError; fn try_from(value: &_Any) -> std::result::Result { @@ -1331,127 +748,6 @@ impl std::convert::From<&Schema> for _Any { } } -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 _io_parse_simple_pattern_atom(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = value.value().to_record(None)?; - 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]))?; - Ok(SimplePattern::Atom {atom_kind: std::boxed::Box::new(_tmp2)}) -} - -fn _io_parse_simple_pattern_embedded(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = value.value().to_record(None)?; - 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]))?; - Ok(SimplePattern::Embedded {interface: std::boxed::Box::new(_tmp2)}) -} - -fn _io_parse_simple_pattern_lit(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = value.value().to_record(None)?; - 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 _io_parse_simple_pattern_seqof(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = value.value().to_record(None)?; - 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]))?; - Ok(SimplePattern::Seqof {pattern: std::boxed::Box::new(_tmp2)}) -} - -fn _io_parse_simple_pattern_setof(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = value.value().to_record(None)?; - 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]))?; - Ok(SimplePattern::Setof {pattern: std::boxed::Box::new(_tmp2)}) -} - -fn _io_parse_simple_pattern_dictof(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = value.value().to_record(None)?; - 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]))?; - let _tmp3 = SimplePattern::try_from((&_tmp0.fields()[1]))?; - Ok(SimplePattern::Dictof {key: std::boxed::Box::new(_tmp2), value: std::boxed::Box::new(_tmp3)}) -} - -fn _io_parse_simple_pattern_ref(value: &preserves::value::IOValue) -> std::result::Result { - let _tmp0 = Ref::try_from(value)?; - Ok(SimplePattern::Ref(std::boxed::Box::new(_tmp0))) -} - -impl std::convert::TryFrom<&preserves::value::IOValue> for SimplePattern { - type Error = _support::ParseError; - fn try_from(value: &preserves::value::IOValue) -> std::result::Result { - 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) - } -} - -impl std::convert::From<&SimplePattern> for preserves::value::IOValue { - fn from(value: &SimplePattern) -> Self { - match value { - SimplePattern::Any => (&*_io_::LIT_21_ANY).clone(), - SimplePattern::Atom {atom_kind: _tmp0} => { - 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![(&*_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![(&*_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![(&*_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![(&*_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![(&*_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() - }, - SimplePattern::Ref(_tmp0) => preserves::value::IOValue::from(_tmp0.as_ref()), - } - } -} - fn _any_parse_simple_pattern_any(value: &_Any) -> std::result::Result { if value != &*_any_::LIT_21_ANY { return Err(_support::ParseError::ConformanceError); } let _tmp0 = (); @@ -1573,19 +869,6 @@ impl std::convert::From<&SimplePattern> for _Any { } } -impl std::convert::TryFrom<&preserves::value::IOValue> for Version { - type Error = _support::ParseError; - fn try_from(value: &preserves::value::IOValue) -> std::result::Result { - 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; (&*_io_::LIT_28_1).clone()} -} - impl std::convert::TryFrom<&_Any> for Version { type Error = _support::ParseError; fn try_from(value: &_Any) -> std::result::Result { diff --git a/implementations/rust/preserves-schema/src/lib.rs b/implementations/rust/preserves-schema/src/lib.rs index c0c09e8..26d3a70 100644 --- a/implementations/rust/preserves-schema/src/lib.rs +++ b/implementations/rust/preserves-schema/src/lib.rs @@ -39,7 +39,7 @@ mod tests { let mut f = std::fs::File::open("../../../schema/schema.bin")?; let mut reader = preserves::value::PackedReader::decode_read(&mut f); let schema = reader.demand_next(false)?; - let parsed = Schema::try_from(schema.clone()).expect("successful parse"); + let parsed = Schema::try_from(&schema).expect("successful parse"); assert_eq!(schema, IOValue::from(&parsed)); Ok(()) } diff --git a/implementations/rust/preserves-schema/src/support/mod.rs b/implementations/rust/preserves-schema/src/support/mod.rs index 1083abb..430797f 100644 --- a/implementations/rust/preserves-schema/src/support/mod.rs +++ b/implementations/rust/preserves-schema/src/support/mod.rs @@ -1,7 +1,42 @@ -use std::convert::From; - pub use lazy_static::lazy_static; +use preserves::value::ArcValue; +use preserves::value::Domain; +use preserves::value::Embeddable; +use preserves::value::IOResult; +use preserves::value::IOValue; +use preserves::value::NestedValue; +use preserves::value::Value; + +use std::convert::From; +use std::convert::TryFrom; +use std::sync::Arc; + +pub fn decode_lit>(bs: &[u8]) -> IOResult { + preserves::value::packed::from_bytes(bs).unwrap().copy_via( + &mut |_| Err(std::io::Error::new(std::io::ErrorKind::Unsupported, + "Embedded values not supported in schema literals"))) +} + +pub fn decode_embedded( + v: &IOValue, +) -> Result>, ParseError> +where + for<'a> D: TryFrom<&'a IOValue, Error = ParseError> +{ + v.copy_via(&mut |d| Ok(Value::Embedded(Arc::new(D::try_from(d)?)))) +} + +pub fn encode_embedded( + v: &ArcValue>, +) -> IOValue +where + for<'a> IOValue: From<&'a D> +{ + v.copy_via::<_, _, _, std::convert::Infallible>( + &mut |d| Ok(Value::Embedded(IOValue::from(d)))).unwrap() +} + #[derive(Debug)] pub enum ParseError { ConformanceError,