diff --git a/src/constants.rs b/src/constants.rs index 7b1583c9..99ead56c 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -69,55 +69,53 @@ pub(crate) mod v1_1 { "macro_table", // $14 "symbol_table", // $15 "module", // $16 - "", // $17 (see: ion-docs#345) - "export", // $18 - "", // $19 (see: ion-docs#345) - "import", // $20 - "", // $21 (empty text) - "literal", // $22 - "if_none", // $23 - "if_some", // $24 - "if_single", // $25 - "if_multi", // $26 - "for", // $27 - "default", // $28 - "values", // $29 - "annotate", // $30 - "make_string", // $31 - "make_symbol", // $32 - "make_blob", // $33 - "make_decimal", // $34 - "make_timestamp", // $35 - "make_list", // $36 - "make_sexp", // $37 - "make_struct", // $38 - "parse_ion", // $39 - "repeat", // $40 - "delta", // $41 - "flatten", // $42 - "sum", // $43 - "set_symbols", // $44 - "add_symbols", // $45 - "set_macros", // $46 - "add_macros", // $47 - "use", // $48 - "meta", // $49 - "flex_symbol", // $50 - "flex_int", // $51 - "flex_uint", // $52 - "uint8", // $53 - "uint16", // $54 - "uint32", // $55 - "uint64", // $56 - "int8", // $57 - "int16", // $58 - "int32", // $59 - "int64", // $60 - "float16", // $61 - "float32", // $62 - "float64", // $63 - "none", // $64 - "make_field", // $65 + "export", // $17 + "import", // $18 + "flex_symbol", // $19 + "flex_int", // $20 + "flex_uint", // $21 + "uint8", // $22 + "uint16", // $23 + "uint32", // $24 + "uint64", // $25 + "int8", // $26 + "int16", // $27 + "int32", // $28 + "int64", // $29 + "float16", // $30 + "float32", // $31 + "float64", // $32 + "", // $33 (empty text) + "for", // $34 + "literal", // $35 + "if_none", // $36 + "if_some", // $37 + "if_single", // $38 + "if_multi", // $39 + "none", // $40 + "values", // $41 + "default", // $42 + "meta", // $43 + "repeat", // $44 + "flatten", // $45 + "delta", // $46 + "sum", // $47 + "annotate", // $48 + "make_string", // $49 + "make_symbol", // $50 + "make_decimal", // $51 + "make_timestamp", // $52 + "make_blob", // $53 + "make_list", // $54 + "make_sexp", // $55 + "make_field", // $56 + "make_struct", // $57 + "parse_ion", // $58 + "set_symbols", // $59 + "add_symbols", // $60 + "set_macros", // $61 + "add_macros", // $62 + "use", // $63 ]; pub mod system_symbols { @@ -127,80 +125,78 @@ pub(crate) mod v1_1 { pub const ENCODING: SystemSymbol_1_1 = SystemSymbol_1_1::new_unchecked(10); pub const SYMBOL_TABLE: SystemSymbol_1_1 = SystemSymbol_1_1::new_unchecked(15); pub const MODULE: SystemSymbol_1_1 = SystemSymbol_1_1::new_unchecked(16); - pub const EMPTY_TEXT: SystemSymbol_1_1 = SystemSymbol_1_1::new_unchecked(21); - pub const ADD_SYMBOLS: SystemSymbol_1_1 = SystemSymbol_1_1::new_unchecked(45); - pub const ADD_MACROS: SystemSymbol_1_1 = SystemSymbol_1_1::new_unchecked(47); + pub const EMPTY_TEXT: SystemSymbol_1_1 = SystemSymbol_1_1::new_unchecked(33); + pub const ADD_SYMBOLS: SystemSymbol_1_1 = SystemSymbol_1_1::new_unchecked(60); + pub const ADD_MACROS: SystemSymbol_1_1 = SystemSymbol_1_1::new_unchecked(62); } /// A static, read-only map of text to Ion v1.1 system symbol addresses. /// Because the set of string keys is known at compile time, this map is able to use a /// perfect hashing function (PHF) to optimize lookup operations for those keys. pub(crate) static SYSTEM_SYMBOL_TEXT_TO_ID: phf::Map<&str, usize> = phf_map! { - "$ion" => 1, - "$ion_1_0" => 2, - "$ion_symbol_table" => 3, - "name" => 4, - "version" => 5, - "imports" => 6, - "symbols" => 7, - "max_id" => 8, - "$ion_shared_symbol_table" => 9, - "$ion_encoding" => 10, + "$ion" => 1, + "$ion_1_0" => 2, + "$ion_symbol_table" => 3, + "name" => 4, + "version" => 5, + "imports" => 6, + "symbols" => 7, + "max_id" => 8, + "$ion_shared_symbol_table" => 9, + "encoding" => 10, "$ion_literal" => 11, "$ion_shared_module" => 12, "macro" => 13, "macro_table" => 14, "symbol_table" => 15, "module" => 16, - // ion-docs#345 => 17, - "export" => 18, - // ion-docs#345 => 19, - "import" => 20, - "" => 21, - "literal" => 22, - "if_none" => 23, - "if_some" => 24, - "if_single" => 25, - "if_multi" => 26, - "for" => 27, - "default" => 28, - "values" => 29, - "annotate" => 30, - "make_string" => 31, - "make_symbol" => 32, - "make_blob" => 33, - "make_decimal" => 34, - "make_timestamp" => 35, - "make_list" => 36, - "make_sexp" => 37, - "make_struct" => 38, - "parse_ion" => 39, - "repeat" => 40, - "delta" => 41, - "flatten" => 42, - "sum" => 43, - "set_symbols" => 44, - "add_symbols" => 45, - "set_macros" => 46, - "add_macros" => 47, - "use" => 48, - "meta" => 49, - "flex_symbol" => 50, - "flex_int" => 51, - "flex_uint" => 52, - "uint8" => 53, - "uint16" => 54, - "uint32" => 55, - "uint64" => 56, - "int8" => 57, - "int16" => 58, - "int32" => 59, - "int64" => 60, - "float16" => 61, - "float32" => 62, - "float64" => 63, - "none" => 64, - "make_field" => 65, + "export" => 17, + "import" => 18, + "flex_symbol" => 19, + "flex_int" => 20, + "flex_uint" => 21, + "uint8" => 22, + "uint16" => 23, + "uint32" => 24, + "uint64" => 25, + "int8" => 26, + "int16" => 27, + "int32" => 28, + "int64" => 29, + "float16" => 30, + "float32" => 31, + "float64" => 32, + "" => 33, + "for" => 34, + "literal" => 35, + "if_none" => 36, + "if_some" => 37, + "if_single" => 38, + "if_multi" => 39, + "none" => 40, + "values" => 41, + "default" => 42, + "meta" => 43, + "repeat" => 44, + "flatten" => 45, + "delta" => 46, + "sum" => 47, + "annotate" => 48, + "make_string" => 49, + "make_symbol" => 50, + "make_decimal" => 51, + "make_timestamp" => 52, + "make_blob" => 53, + "make_list" => 54, + "make_sexp" => 55, + "make_field" => 56, + "make_struct" => 57, + "parse_ion" => 58, + "set_symbols" => 59, + "add_symbols" => 60, + "set_macros" => 61, + "add_macros" => 62, + "use" => 63, }; pub fn address_for_text(text: &str) -> Option { diff --git a/src/lazy/binary/raw/v1_1/immutable_buffer.rs b/src/lazy/binary/raw/v1_1/immutable_buffer.rs index d14643fd..5bdc1291 100644 --- a/src/lazy/binary/raw/v1_1/immutable_buffer.rs +++ b/src/lazy/binary/raw/v1_1/immutable_buffer.rs @@ -1275,7 +1275,7 @@ mod tests { RawSymbolRef::SymbolId(0), RawSymbolRef::Text("encoding"), ])] - #[case::three_flex_syms_with_system_symbols(AnnotationsEncoding::FlexSym, &[0xE9, 0x0D, 0x01, 0x60, 0x01, 0x6A, 0x01, 0xA1], 2, 6, &[ + #[case::three_flex_syms_with_system_symbols(AnnotationsEncoding::FlexSym, &[0xE9, 0x0D, 0x01, 0x60, 0x01, 0x6A, 0x01, 0x98], 2, 6, &[ RawSymbolRef::SymbolId(0), RawSymbolRef::Text("encoding"), RawSymbolRef::Text("make_field"), diff --git a/src/lazy/binary/raw/v1_1/reader.rs b/src/lazy/binary/raw/v1_1/reader.rs index b684a79f..a69ec37c 100644 --- a/src/lazy/binary/raw/v1_1/reader.rs +++ b/src/lazy/binary/raw/v1_1/reader.rs @@ -349,8 +349,8 @@ mod tests { // System symbols 0xEE, 0x0A, // encoding 0xEE, 0x0E, // macro_table - 0xEE, 0x15, // empty text - 0xEE, 0x41, // make_field + 0xEE, 0x21, // empty text + 0xEE, 0x38, // make_field ]; let empty_context = EncodingContext::empty(); let context = empty_context.get_ref(); diff --git a/src/lazy/encoder/binary/v1_1/value_writer.rs b/src/lazy/encoder/binary/v1_1/value_writer.rs index 5a8ec5d2..12149a66 100644 --- a/src/lazy/encoder/binary/v1_1/value_writer.rs +++ b/src/lazy/encoder/binary/v1_1/value_writer.rs @@ -2931,7 +2931,7 @@ mod tests { args.close() }, &[ - 0xEF, 0x03, // Invoke system macro address 3 + 0xEF, 0x09, // Invoke system macro address 3 0xA3, 0x66, 0x6f, 0x6f, // foo 0xA3, 0x62, 0x61, 0x72, // bar 0xA3, 0x62, 0x61, 0x7a, // baz diff --git a/src/lazy/encoder/writer.rs b/src/lazy/encoder/writer.rs index 04b0a335..6f945135 100644 --- a/src/lazy/encoder/writer.rs +++ b/src/lazy/encoder/writer.rs @@ -833,7 +833,7 @@ mod tests { (Text("$ion_symbol_table"), &[0xE1, 0x03]), (Text("name"), &[0xE1, 0x04]), (SymbolId(6), &[0xE1, 0x06]), // SIDs are written as-is - (Text("foo"), &[0xE1, 0x42]), // Text is added to the symbol table and encoded as a SID + (Text("foo"), &[0xE1, 0x40]), // Text is added to the symbol table and encoded as a SID ], ) } @@ -916,7 +916,7 @@ mod tests { 0x07, // FlexSym SID $3 0x09, // FlexSym SID $4 0x0D, // FlexSym SID $6 - 0x0A, 0x01, // FlexSym SID $66 + 0x02, 0x01, // FlexSym SID $64 ], ) } @@ -1010,12 +1010,12 @@ mod tests { FieldNameEncoding::WriteAsSymbolIds, &[ // New symbols - (RawSymbolRef::Text("foo"), &[0x85]), // FlexUInt SID $66, - (RawSymbolRef::Text("bar"), &[0x87]), // FlexUInt SID $67, - (RawSymbolRef::Text("baz"), &[0x89]), // FlexUInt SID $68, + (RawSymbolRef::Text("foo"), &[0x81]), // FlexUInt SID $64, + (RawSymbolRef::Text("bar"), &[0x83]), // FlexUInt SID $65, + (RawSymbolRef::Text("baz"), &[0x85]), // FlexUInt SID $66, // Symbols that are already in the symbol table (RawSymbolRef::Text("name"), &[0x09]), // FlexUInt SID $4, - (RawSymbolRef::Text("foo"), &[0x85]), // FlexUInt SID $66, + (RawSymbolRef::Text("foo"), &[0x81]), // FlexUInt SID $64, ], ) } diff --git a/src/lazy/expanded/macro_evaluator.rs b/src/lazy/expanded/macro_evaluator.rs index 9afe3686..a51244d0 100644 --- a/src/lazy/expanded/macro_evaluator.rs +++ b/src/lazy/expanded/macro_evaluator.rs @@ -1606,7 +1606,7 @@ mod tests { bin_stream_eq( &[ 0xEF, // System macro, address follows as 1-byte FixedUInt - 0x03, // make_string + 0x09, // make_string 0x02, // Argument group 0x11, // FlexUInt 8: 8-byte group 0x93, // Opcode: 3-byte string follows @@ -1624,7 +1624,7 @@ mod tests { bin_stream_eq( &[ 0xEF, // System macro, address follows as 1-byte FixedUInt - 0x03, // make_string + 0x09, // make_string 0x02, // Argument group 0x01, // FlexUInt 0: delimited group 0xF0, // Delimited END @@ -1635,7 +1635,7 @@ mod tests { bin_stream_eq( &[ 0xEF, // System macro, address follows as 1-byte FixedUInt - 0x03, // make_string + 0x09, // make_string 0x02, // Argument group 0x01, // FlexUInt 0: delimited group 0x93, // Opcode: 3-byte string follows diff --git a/src/lazy/expanded/macro_table.rs b/src/lazy/expanded/macro_table.rs index 479a8288..a6c23a13 100644 --- a/src/lazy/expanded/macro_table.rs +++ b/src/lazy/expanded/macro_table.rs @@ -268,6 +268,29 @@ impl MacroTable { ExpansionAnalysis::application_value_stream(), ), template("(macro values (x*) (%x))"), + template( + "(macro default (expr* default_expr*) (.if_none (%expr) (%default_expr) (%expr) ))", + ), + template("(macro meta (expr*) (.none))"), + builtin( + "repeat", + "(n expr*)", + MacroKind::ToDo, + ExpansionAnalysis::no_assertions_made(), + ), + flatten_macro_definition, + builtin( + "delta", + "(deltas*)", + MacroKind::ToDo, + ExpansionAnalysis::application_value_stream(), + ), + builtin( + "sum", + "(a b)", + MacroKind::ToDo, + ExpansionAnalysis::single_application_value(IonType::Int), + ), builtin( "annotate", "(annotations* value_to_annotate)", @@ -286,12 +309,6 @@ impl MacroTable { MacroKind::MakeSymbol, ExpansionAnalysis::single_application_value(IonType::Symbol), ), - builtin( - "make_blob", - "(lob_values*)", - MacroKind::ToDo, - ExpansionAnalysis::single_application_value(IonType::Blob), - ), builtin( "make_decimal", "(coefficient exponent)", @@ -304,6 +321,12 @@ impl MacroTable { MacroKind::ToDo, ExpansionAnalysis::single_application_value(IonType::Timestamp), ), + builtin( + "make_blob", + "(lob_values*)", + MacroKind::ToDo, + ExpansionAnalysis::single_application_value(IonType::Blob), + ), template( r#" (macro make_list (sequences*) @@ -316,12 +339,24 @@ impl MacroTable { ((.flatten (%sequences)))) "#, ), + builtin( + "make_field", + "(name value)", + MacroKind::MakeField, + ExpansionAnalysis::single_application_value(IonType::Struct), + ), builtin( "make_struct", "(fields*)", MacroKind::MakeStruct, ExpansionAnalysis::single_application_value(IonType::Struct), ), + builtin( + "parse_ion", + "(data*)", + MacroKind::ToDo, + ExpansionAnalysis::application_value_stream(), + ), template( r#" (macro set_symbols (symbols*) @@ -380,41 +415,6 @@ impl MacroTable { MacroKind::ToDo, ExpansionAnalysis::directive(), ), - builtin( - "parse_ion", - "(data*)", - MacroKind::ToDo, - ExpansionAnalysis::application_value_stream(), - ), - builtin( - "repeat", - "(n expr*)", - MacroKind::ToDo, - ExpansionAnalysis::no_assertions_made(), - ), - builtin( - "delta", - "(deltas*)", - MacroKind::ToDo, - ExpansionAnalysis::application_value_stream(), - ), - flatten_macro_definition, - builtin( - "sum", - "(a b)", - MacroKind::ToDo, - ExpansionAnalysis::single_application_value(IonType::Int), - ), - template("(macro meta (expr*) (.none))"), - builtin( - "make_field", - "(name value)", - MacroKind::MakeField, - ExpansionAnalysis::single_application_value(IonType::Struct), - ), - template( - "(macro default (expr* default_expr*) (.if_none (%expr) (%default_expr) (%expr) ))", - ), ] } diff --git a/src/lazy/expanded/struct.rs b/src/lazy/expanded/struct.rs index 6871d796..e45f4538 100644 --- a/src/lazy/expanded/struct.rs +++ b/src/lazy/expanded/struct.rs @@ -251,10 +251,11 @@ impl<'top, D: Decoder> LazyExpandedStruct<'top, D> { } pub fn find(&self, name: &str) -> IonResult>> { + use ExpandedStructSource::*; match &self.source { // If we're reading from a struct in a template, consult its field index to see if one or // more fields with the requested name exist. - ExpandedStructSource::Template(environment, element, index) => { + Template(environment, element, index) => { let Some(value_expr_addresses) = index.get(name) else { // If the field name is not in the index, it's not in the struct. return Ok(None); @@ -284,7 +285,7 @@ impl<'top, D: Decoder> LazyExpandedStruct<'top, D> { } // For any other kind of struct, do a linear scan over its fields until we encounter // one with the requested name. - _ => { + ValueLiteral(..) | MakeField(..) | MakeStruct(..) => { for field_result in self.iter() { let field = field_result?; if field.name().read()?.text() == Some(name) { diff --git a/src/lazy/text/raw/v1_1/reader.rs b/src/lazy/text/raw/v1_1/reader.rs index ba899f78..7ca801a5 100644 --- a/src/lazy/text/raw/v1_1/reader.rs +++ b/src/lazy/text/raw/v1_1/reader.rs @@ -144,28 +144,28 @@ pub(crate) mod system_macros { pub const NONE: SystemMacroAddress = SystemMacroAddress(0x00); pub const VALUES: SystemMacroAddress = SystemMacroAddress(0x01); - pub const ANNOTATE: SystemMacroAddress = SystemMacroAddress(0x02); - pub const MAKE_STRING: SystemMacroAddress = SystemMacroAddress(0x03); - pub const MAKE_SYMBOL: SystemMacroAddress = SystemMacroAddress(0x04); - pub const MAKE_BLOB: SystemMacroAddress = SystemMacroAddress(0x05); - pub const MAKE_DECIMAL: SystemMacroAddress = SystemMacroAddress(0x06); - pub const MAKE_TIMESTAMP: SystemMacroAddress = SystemMacroAddress(0x07); - pub const MAKE_LIST: SystemMacroAddress = SystemMacroAddress(0x08); - pub const MAKE_SEXP: SystemMacroAddress = SystemMacroAddress(0x09); - pub const MAKE_STRUCT: SystemMacroAddress = SystemMacroAddress(0x0A); - pub const SET_SYMBOLS: SystemMacroAddress = SystemMacroAddress(0x0B); - pub const ADD_SYMBOLS: SystemMacroAddress = SystemMacroAddress(0x0C); - pub const SET_MACROS: SystemMacroAddress = SystemMacroAddress(0x0D); - pub const ADD_MACROS: SystemMacroAddress = SystemMacroAddress(0x0E); - pub const USE: SystemMacroAddress = SystemMacroAddress(0x0F); - pub const PARSE_ION: SystemMacroAddress = SystemMacroAddress(0x10); - pub const REPEAT: SystemMacroAddress = SystemMacroAddress(0x11); - pub const DELTA: SystemMacroAddress = SystemMacroAddress(0x12); - pub const FLATTEN: SystemMacroAddress = SystemMacroAddress(0x13); - pub const SUM: SystemMacroAddress = SystemMacroAddress(0x14); - pub const META: SystemMacroAddress = SystemMacroAddress(0x15); - pub const MAKE_FIELD: SystemMacroAddress = SystemMacroAddress(0x16); - pub const DEFAULT: SystemMacroAddress = SystemMacroAddress(0x17); + pub const DEFAULT: SystemMacroAddress = SystemMacroAddress(0x02); + pub const META: SystemMacroAddress = SystemMacroAddress(0x03); + pub const REPEAT: SystemMacroAddress = SystemMacroAddress(0x04); + pub const FLATTEN: SystemMacroAddress = SystemMacroAddress(0x05); + pub const DELTA: SystemMacroAddress = SystemMacroAddress(0x06); + pub const SUM: SystemMacroAddress = SystemMacroAddress(0x07); + pub const ANNOTATE: SystemMacroAddress = SystemMacroAddress(0x08); + pub const MAKE_STRING: SystemMacroAddress = SystemMacroAddress(0x09); + pub const MAKE_SYMBOL: SystemMacroAddress = SystemMacroAddress(0x0A); + pub const MAKE_DECIMAL: SystemMacroAddress = SystemMacroAddress(0x0B); + pub const MAKE_TIMESTAMP: SystemMacroAddress = SystemMacroAddress(0x0C); + pub const MAKE_BLOB: SystemMacroAddress = SystemMacroAddress(0x0D); + pub const MAKE_LIST: SystemMacroAddress = SystemMacroAddress(0x0E); + pub const MAKE_SEXP: SystemMacroAddress = SystemMacroAddress(0x0F); + pub const MAKE_FIELD: SystemMacroAddress = SystemMacroAddress(0x10); + pub const MAKE_STRUCT: SystemMacroAddress = SystemMacroAddress(0x11); + pub const PARSE_ION: SystemMacroAddress = SystemMacroAddress(0x12); + pub const SET_SYMBOLS: SystemMacroAddress = SystemMacroAddress(0x13); + pub const ADD_SYMBOLS: SystemMacroAddress = SystemMacroAddress(0x14); + pub const SET_MACROS: SystemMacroAddress = SystemMacroAddress(0x15); + pub const ADD_MACROS: SystemMacroAddress = SystemMacroAddress(0x16); + pub const USE: SystemMacroAddress = SystemMacroAddress(0x17); } /// The index at which a value expression can be found within a template's body.