Skip to content

Commit

Permalink
Restacked the macro table
Browse files Browse the repository at this point in the history
  • Loading branch information
zslayton committed Dec 11, 2024
1 parent 6db49c5 commit d0df476
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 67 deletions.
2 changes: 1 addition & 1 deletion src/lazy/encoder/binary/v1_1/value_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/lazy/expanded/macro_evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
82 changes: 41 additions & 41 deletions src/lazy/expanded/macro_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -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)",
Expand All @@ -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*)
Expand All @@ -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*)
Expand Down Expand Up @@ -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) ))",
),
]
}

Expand Down
44 changes: 22 additions & 22 deletions src/lazy/text/raw/v1_1/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d0df476

Please sign in to comment.