@@ -9,7 +9,7 @@ use crate::lazy::expanded::template::{
9
9
TemplateBodyMacroInvocation , TemplateBodyValueExpr , TemplateMacro , TemplateStructIndex ,
10
10
TemplateValue ,
11
11
} ;
12
- use crate :: lazy:: expanded:: EncodingContext ;
12
+ use crate :: lazy:: expanded:: EncodingContextRef ;
13
13
use crate :: lazy:: r#struct:: LazyStruct ;
14
14
use crate :: lazy:: reader:: LazyTextReader_1_1 ;
15
15
use crate :: lazy:: sequence:: { LazyList , LazySExp } ;
@@ -61,7 +61,7 @@ impl TemplateCompiler {
61
61
/// to the template without interpretation. `(quote ...)` does not appear in the compiled
62
62
/// template as there is nothing more for it to do at expansion time.
63
63
pub fn compile_from_text (
64
- context : EncodingContext ,
64
+ context : EncodingContextRef ,
65
65
expression : & str ,
66
66
) -> IonResult < TemplateMacro > {
67
67
// TODO: This is a rudimentary implementation that panics instead of performing thorough
@@ -137,7 +137,7 @@ impl TemplateCompiler {
137
137
///
138
138
/// If `is_quoted` is true, nested symbols and s-expressions will not be interpreted.
139
139
fn compile_value < ' top , D : LazyDecoder > (
140
- context : EncodingContext < ' top > ,
140
+ context : EncodingContextRef < ' top > ,
141
141
signature : & MacroSignature ,
142
142
definition : & mut TemplateBody ,
143
143
is_quoted : bool ,
@@ -210,7 +210,7 @@ impl TemplateCompiler {
210
210
211
211
/// Helper method for visiting all of the child expressions in a list.
212
212
fn compile_list < ' top , D : LazyDecoder > (
213
- context : EncodingContext < ' top > ,
213
+ context : EncodingContextRef < ' top > ,
214
214
signature : & MacroSignature ,
215
215
definition : & mut TemplateBody ,
216
216
is_quoted : bool ,
@@ -238,7 +238,7 @@ impl TemplateCompiler {
238
238
239
239
/// Helper method for visiting all of the child expressions in a sexp.
240
240
fn compile_sexp < ' top , D : LazyDecoder > (
241
- context : EncodingContext < ' top > ,
241
+ context : EncodingContextRef < ' top > ,
242
242
signature : & MacroSignature ,
243
243
definition : & mut TemplateBody ,
244
244
is_quoted : bool ,
@@ -272,7 +272,7 @@ impl TemplateCompiler {
272
272
/// Adds a `lazy_sexp` that has been determined to represent a macro invocation to the
273
273
/// TemplateBody.
274
274
fn compile_macro < ' top , D : LazyDecoder > (
275
- context : EncodingContext < ' top > ,
275
+ context : EncodingContextRef < ' top > ,
276
276
signature : & MacroSignature ,
277
277
definition : & mut TemplateBody ,
278
278
lazy_sexp : LazySExp < ' top , D > ,
@@ -311,7 +311,7 @@ impl TemplateCompiler {
311
311
/// Given a `LazyValue` that represents a macro ID (name or address), attempts to resolve the
312
312
/// ID to a macro address.
313
313
fn name_and_address_from_id_expr < ' top , D : LazyDecoder > (
314
- context : EncodingContext < ' top > ,
314
+ context : EncodingContextRef < ' top > ,
315
315
id_expr : Option < IonResult < LazyValue < ' top , D > > > ,
316
316
) -> IonResult < ( Option < String > , usize ) > {
317
317
match id_expr {
@@ -352,7 +352,7 @@ impl TemplateCompiler {
352
352
/// without interpretation. `lazy_sexp` itself is the `quote` macro, and does not get added
353
353
/// to the template body as there is nothing more for it to do at evaluation time.
354
354
fn compile_quoted_elements < ' top , D : LazyDecoder > (
355
- context : EncodingContext < ' top > ,
355
+ context : EncodingContextRef < ' top > ,
356
356
signature : & MacroSignature ,
357
357
definition : & mut TemplateBody ,
358
358
lazy_sexp : LazySExp < ' top , D > ,
@@ -375,7 +375,7 @@ impl TemplateCompiler {
375
375
376
376
/// Adds `lazy_sexp` to the template body without interpretation.
377
377
fn compile_quoted_sexp < ' top , D : LazyDecoder > (
378
- context : EncodingContext < ' top > ,
378
+ context : EncodingContextRef < ' top > ,
379
379
signature : & MacroSignature ,
380
380
definition : & mut TemplateBody ,
381
381
annotations_range : Range < usize > ,
@@ -419,7 +419,7 @@ impl TemplateCompiler {
419
419
420
420
/// Recursively adds all of the expressions in `lazy_struct` to the `TemplateBody`.
421
421
fn compile_struct < ' top , D : LazyDecoder > (
422
- context : EncodingContext < ' top > ,
422
+ context : EncodingContextRef < ' top > ,
423
423
signature : & MacroSignature ,
424
424
definition : & mut TemplateBody ,
425
425
is_quoted : bool ,
@@ -476,7 +476,7 @@ impl TemplateCompiler {
476
476
/// Resolves `variable` to a parameter in the macro signature and adds a corresponding
477
477
/// `TemplateExpansionStep` to the `TemplateBody`.
478
478
fn compile_variable_reference (
479
- _context : EncodingContext ,
479
+ _context : EncodingContextRef ,
480
480
signature : & MacroSignature ,
481
481
definition : & mut TemplateBody ,
482
482
annotations_range : Range < usize > ,
@@ -497,7 +497,10 @@ impl TemplateCompiler {
497
497
. ok_or_else ( || {
498
498
IonError :: decoding_error ( format ! ( "variable '{name}' is not recognized" ) )
499
499
} ) ?;
500
- definition. push_variable ( signature_index) ;
500
+ if signature_index > u16:: MAX as usize {
501
+ return IonResult :: decoding_error ( "this implementation supports up to 65K parameters" ) ;
502
+ }
503
+ definition. push_variable ( signature_index as u16 ) ;
501
504
Ok ( ( ) )
502
505
}
503
506
}
@@ -558,7 +561,7 @@ mod tests {
558
561
definition,
559
562
index,
560
563
TemplateBodyValueExpr :: Variable ( TemplateBodyVariableReference :: new (
561
- expected_signature_index,
564
+ expected_signature_index as u16 ,
562
565
) ) ,
563
566
)
564
567
}
@@ -630,7 +633,7 @@ mod tests {
630
633
631
634
let expression = "(macro foo () 42)" ;
632
635
633
- let template = TemplateCompiler :: compile_from_text ( context, expression) ?;
636
+ let template = TemplateCompiler :: compile_from_text ( context. get_ref ( ) , expression) ?;
634
637
assert_eq ! ( template. name( ) , "foo" ) ;
635
638
assert_eq ! ( template. signature( ) . parameters( ) . len( ) , 0 ) ;
636
639
expect_value ( & template, 0 , TemplateValue :: Int ( 42 . into ( ) ) ) ?;
@@ -644,7 +647,7 @@ mod tests {
644
647
645
648
let expression = "(macro foo () [1, 2, 3])" ;
646
649
647
- let template = TemplateCompiler :: compile_from_text ( context, expression) ?;
650
+ let template = TemplateCompiler :: compile_from_text ( context. get_ref ( ) , expression) ?;
648
651
assert_eq ! ( template. name( ) , "foo" ) ;
649
652
assert_eq ! ( template. signature( ) . parameters( ) . len( ) , 0 ) ;
650
653
expect_value ( & template, 0 , TemplateValue :: List ( ExprRange :: new ( 1 ..4 ) ) ) ?;
@@ -661,7 +664,7 @@ mod tests {
661
664
662
665
let expression = r#"(macro foo () (values 42 "hello" false))"# ;
663
666
664
- let template = TemplateCompiler :: compile_from_text ( context, expression) ?;
667
+ let template = TemplateCompiler :: compile_from_text ( context. get_ref ( ) , expression) ?;
665
668
assert_eq ! ( template. name( ) , "foo" ) ;
666
669
assert_eq ! ( template. signature( ) . parameters( ) . len( ) , 0 ) ;
667
670
expect_macro (
@@ -683,7 +686,7 @@ mod tests {
683
686
684
687
let expression = "(macro foo (x y z) [100, [200, a::b::300], x, {y: [true, false, z]}])" ;
685
688
686
- let template = TemplateCompiler :: compile_from_text ( context, expression) ?;
689
+ let template = TemplateCompiler :: compile_from_text ( context. get_ref ( ) , expression) ?;
687
690
expect_value ( & template, 0 , TemplateValue :: List ( ExprRange :: new ( 1 ..12 ) ) ) ?;
688
691
expect_value ( & template, 1 , TemplateValue :: Int ( Int :: from ( 100 ) ) ) ?;
689
692
expect_value ( & template, 2 , TemplateValue :: List ( ExprRange :: new ( 3 ..5 ) ) ) ?;
@@ -713,7 +716,7 @@ mod tests {
713
716
714
717
let expression = "(macro identity (x) x)" ;
715
718
716
- let template = TemplateCompiler :: compile_from_text ( context, expression) ?;
719
+ let template = TemplateCompiler :: compile_from_text ( context. get_ref ( ) , expression) ?;
717
720
assert_eq ! ( template. name( ) , "identity" ) ;
718
721
assert_eq ! ( template. signature( ) . parameters( ) . len( ) , 1 ) ;
719
722
expect_variable ( & template, 0 , 0 ) ?;
@@ -736,7 +739,7 @@ mod tests {
736
739
(values x))))
737
740
"# ;
738
741
739
- let template = TemplateCompiler :: compile_from_text ( context, expression) ?;
742
+ let template = TemplateCompiler :: compile_from_text ( context. get_ref ( ) , expression) ?;
740
743
assert_eq ! ( template. name( ) , "foo" ) ;
741
744
assert_eq ! ( template. signature( ) . parameters( ) . len( ) , 1 ) ;
742
745
// Outer `values`
0 commit comments