From d0df47684dd78f21d4881e309a10a5aefc5c1f88 Mon Sep 17 00:00:00 2001 From: Zack Slayton Date: Wed, 11 Dec 2024 15:36:30 -0500 Subject: [PATCH] Restacked the macro table --- src/lazy/encoder/binary/v1_1/value_writer.rs | 2 +- src/lazy/expanded/macro_evaluator.rs | 6 +- src/lazy/expanded/macro_table.rs | 82 ++++++++++---------- src/lazy/text/raw/v1_1/reader.rs | 44 +++++------ 4 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/lazy/encoder/binary/v1_1/value_writer.rs b/src/lazy/encoder/binary/v1_1/value_writer.rs index 5a8ec5d24..12149a66f 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/expanded/macro_evaluator.rs b/src/lazy/expanded/macro_evaluator.rs index 9afe36869..a51244d0d 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 479a82882..a6c23a137 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/text/raw/v1_1/reader.rs b/src/lazy/text/raw/v1_1/reader.rs index ba899f785..7ca801a5f 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.