@@ -470,8 +470,7 @@ impl Continuation<'_> {
470
470
fn to_inline ( & mut self ) -> & mut Src {
471
471
if let Code :: Label ( ref label) = self . code {
472
472
self . code = Code :: Inline ( quote ! (
473
- c. code = #label;
474
- p. threads. spawn( c, _range) ;
473
+ p. spawn( #label) ;
475
474
) ) ;
476
475
}
477
476
@@ -584,7 +583,8 @@ macro_rules! thunk {
584
583
}
585
584
586
585
fn pop_saved < F : ContFn > ( f : impl FnOnce ( Src ) -> Thunk < F > ) -> Thunk < impl ContFn > {
587
- f ( quote ! ( c. saved. unwrap( ) ) )
586
+ thunk ! ( let saved = p. take_saved( ) ; )
587
+ + f ( quote ! ( saved) )
588
588
+ Thunk :: new ( |mut cont| {
589
589
if let Some ( & None ) = cont. nested_frames . last ( ) {
590
590
* cont. nested_frames . last_mut ( ) . unwrap ( ) =
@@ -599,8 +599,8 @@ fn pop_saved<F: ContFn>(f: impl FnOnce(Src) -> Thunk<F>) -> Thunk<impl ContFn> {
599
599
} )
600
600
}
601
601
602
- fn push_saved ( saved : Src ) -> Thunk < impl ContFn > {
603
- thunk ! ( c . saved = Some ( #saved ) ; )
602
+ fn push_saved ( parse_node_kind : ParseNodeKind ) -> Thunk < impl ContFn > {
603
+ thunk ! ( p . save ( #parse_node_kind ) ; )
604
604
+ Thunk :: new ( move |mut cont| {
605
605
if let Some ( ( ret_label, outer_fn_label) ) = cont. nested_frames . pop ( ) . unwrap ( ) {
606
606
let inner_fn_label = mem:: replace ( cont. fn_code_label , outer_fn_label) ;
@@ -627,15 +627,14 @@ fn call(callee: Rc<CodeLabel>) -> Thunk<impl ContFn> {
627
627
Thunk :: new ( move |mut cont| {
628
628
let label = cont. to_label ( ) . clone ( ) ;
629
629
cont. code = Code :: Inline ( quote ! (
630
- c. code = #label;
631
- p. call( Call { callee: #callee, range: _range } , c) ;
630
+ p. call( #callee, #label) ;
632
631
) ) ;
633
632
cont
634
633
} )
635
634
}
636
635
637
636
fn ret ( ) -> Thunk < impl ContFn > {
638
- thunk ! ( p. ret( c , _range ) ; )
637
+ thunk ! ( p. ret( ) ; )
639
638
+ Thunk :: new ( |mut cont| {
640
639
assert ! ( cont. to_inline( ) . is_empty( ) ) ;
641
640
cont
@@ -749,7 +748,7 @@ fn reify_as(label: Rc<CodeLabel>) -> Thunk<impl ContFn> {
749
748
}
750
749
751
750
fn forest_add_choice ( parse_node_kind : & ParseNodeKind , choice : ParseNodeKind ) -> Thunk < impl ContFn > {
752
- thunk ! ( p. forest_add_choice( #parse_node_kind, c . fn_input . subtract_suffix ( _range ) , #choice) ; )
751
+ thunk ! ( p. forest_add_choice( #parse_node_kind, #choice) ; )
753
752
}
754
753
755
754
fn concat_and_forest_add (
@@ -758,18 +757,12 @@ fn concat_and_forest_add(
758
757
right : Thunk < impl ContFn > ,
759
758
parse_node_kind : ParseNodeKind ,
760
759
) -> Thunk < impl ContFn > {
761
- thunk ! ( assert_eq!( _range. start( ) , c. fn_input. start( ) ) ; )
762
- + left
763
- + push_saved ( quote ! ( ParseNode {
764
- kind: #left_parse_node_kind,
765
- range: c. fn_input. subtract_suffix( _range) ,
766
- } ) )
760
+ left + push_saved ( left_parse_node_kind)
767
761
+ right
768
762
+ pop_saved ( move |saved| {
769
763
thunk ! ( p. forest_add_split(
770
764
#parse_node_kind,
771
- c. fn_input. subtract_suffix( _range) ,
772
- #saved. range. len( ) ,
765
+ #saved,
773
766
) ; )
774
767
} )
775
768
}
@@ -799,7 +792,7 @@ impl<Pat: Ord + Hash + RustInputPat> RuleGenerateMethods<Pat> for Rule<Pat> {
799
792
( Rule :: Empty , _) => cont,
800
793
( Rule :: Eat ( pat) , _) => {
801
794
let pat = pat. rust_matcher ( ) ;
802
- check ( quote ! ( let Some ( _range ) = p. input_consume_left( _range , & ( #pat) ) ) ) . apply ( cont)
795
+ check ( quote ! ( let Some ( mut p ) = p. input_consume_left( & ( #pat) ) ) ) . apply ( cont)
803
796
}
804
797
( Rule :: Call ( r) , _) => call ( Rc :: new ( CodeLabel :: NamedRule ( r. clone ( ) ) ) ) . apply ( cont) ,
805
798
( Rule :: Concat ( [ left, right] ) , None ) => {
@@ -817,12 +810,11 @@ impl<Pat: Ord + Hash + RustInputPat> RuleGenerateMethods<Pat> for Rule<Pat> {
817
810
) )
818
811
. apply ( cont) ,
819
812
( Rule :: Or ( cases) , Some ( ( rc_self, rules) ) ) => {
820
- ( thunk ! ( assert_eq!( _range. start( ) , c. fn_input. start( ) ) ; )
821
- + parallel ( ThunkIter ( cases. iter ( ) . map ( |rule| {
822
- let parse_node_kind = rule. parse_node_kind ( rules) ;
823
- rule. generate_parse ( Some ( ( rule, rules) ) )
824
- + forest_add_choice ( & rc_self. parse_node_kind ( rules) , parse_node_kind)
825
- } ) ) ) )
813
+ ( parallel ( ThunkIter ( cases. iter ( ) . map ( |rule| {
814
+ let parse_node_kind = rule. parse_node_kind ( rules) ;
815
+ rule. generate_parse ( Some ( ( rule, rules) ) )
816
+ + forest_add_choice ( & rc_self. parse_node_kind ( rules) , parse_node_kind)
817
+ } ) ) ) )
826
818
. apply ( cont)
827
819
}
828
820
( Rule :: Opt ( rule) , _) => {
@@ -1395,12 +1387,8 @@ where
1395
1387
quote ! ( impl <I > gll:: runtime:: CodeStep <I > for _C
1396
1388
where I : gll:: runtime:: Input <Slice = #rust_slice_ty>,
1397
1389
{
1398
- fn step<' i>(
1399
- p: & mut gll:: runtime:: Parser <' i, _C, I >,
1400
- mut c: gll:: runtime:: Continuation <' i, _C>,
1401
- _range: gll:: runtime:: Range <' i>,
1402
- ) {
1403
- match c. code {
1390
+ fn step<' i>( self , mut p: gll:: runtime:: Parser <' _, ' i, _C, I >) {
1391
+ match self {
1404
1392
#( #code_label_arms) *
1405
1393
}
1406
1394
}
0 commit comments