@@ -2771,8 +2771,15 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
2771
2771
my $ reg := $ _ . value ;
2772
2772
my $ cuid := self . mangled_cuid($ _ . key );
2773
2773
2774
- @ clone_inners . push (" $ reg = $ cuid .closure" );
2775
- @ clone_inners . push (% * BLOCKS_DONE {$ _ . key });
2774
+ if % * BLOCKS_DONE {$ _ . key } {
2775
+ @ clone_inners . push (" $ reg = $ cuid .closure" );
2776
+ @ clone_inners . push (% * BLOCKS_DONE {$ _ . key });
2777
+ } elsif % * BLOCKS_DONE_CPS {$ _ . key } {
2778
+ @ clone_inners . push (" $ reg = $ cuid. onlyCPS ()" );
2779
+ } else {
2780
+ say (" //Broken block: { $ _ . key } " );
2781
+ }
2782
+
2776
2783
if % * BLOCKS_DONE_CPS {$ _ . key } {
2777
2784
@ clone_inners . push (" .CPS" );
2778
2785
@ clone_inners . push (% * BLOCKS_DONE_CPS {$ _ . key });
@@ -2817,21 +2824,41 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
2817
2824
2818
2825
my $ stmts := self . compile_all_the_statements($ node , $ body_want );
2819
2826
2820
- my $ sig := self . compile_sig($ * BLOCK . params);
2821
-
2822
- my @ function := [
2823
- " function({ $ sig . expr} ) \{\n " ,
2824
- self . setup_setting($ node ),
2825
- self . declare_js_vars($ * BLOCK . tmps),
2826
- self . declare_js_vars($ * BLOCK . js_lexicals),
2827
- $ create_ctx ,
2828
- $ sig ,
2829
- self . clone_inners($ * BLOCK ),
2830
- self . capture_inners($ * BLOCK ),
2831
- $ stmts ,
2832
- " return { $ stmts . expr} ;\n " ,
2833
- " \} "
2834
- ];
2827
+ if nqp ::istype($ stmts , ChunkCPS) {
2828
+ say (" //can't emit closure version of block" );
2829
+ } else {
2830
+ my $ sig := self . compile_sig($ * BLOCK . params);
2831
+
2832
+ my @ function := [
2833
+ " function({ $ sig . expr} ) \{\n " ,
2834
+ self . setup_setting($ node ),
2835
+ self . declare_js_vars($ * BLOCK . tmps),
2836
+ self . declare_js_vars($ * BLOCK . js_lexicals),
2837
+ $ create_ctx ,
2838
+ $ sig ,
2839
+ self . clone_inners($ * BLOCK ),
2840
+ self . capture_inners($ * BLOCK ),
2841
+ $ stmts ,
2842
+ " return { $ stmts . expr} ;\n " ,
2843
+ " \} "
2844
+ ];
2845
+ % * BLOCKS_DONE {$ node . cuid} := Chunk. void (" (" , | @ function , " )" );
2846
+
2847
+ if self . is_block_part_of_sc($ node ) {
2848
+ if $ node . blocktype eq ' immediate' {
2849
+ # TODO think about that, and find a way to test this
2850
+ # say("// it's an immediate one");
2851
+ } else {
2852
+ % ! serialized_code_ref_info {$ node . cuid} := SerializedCodeRefInfo. new (
2853
+ closure_template => Chunk. new ($ T_OBJ , " " , @ function ). join (),
2854
+ ctx => $ * CTX ,
2855
+ outer_ctx => (nqp :: defined ($ * BLOCK . outer) ?? $ * BLOCK . outer. ctx !! " " ),
2856
+ static_info => self . static_info_for_lexicals($ * BLOCK )
2857
+ );
2858
+ }
2859
+ }
2860
+ }
2861
+
2835
2862
2836
2863
# The CPS version
2837
2864
@@ -2847,7 +2874,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
2847
2874
self . declare_js_vars($ * BLOCK . tmps),
2848
2875
self . declare_js_vars($ * BLOCK . js_lexicals),
2849
2876
$ create_ctx ,
2850
- $ sig ,
2877
+ $ sig_cps ,
2851
2878
self . clone_inners($ * BLOCK ),
2852
2879
self . capture_inners($ * BLOCK ),
2853
2880
$ stmts_cps ,
@@ -2860,23 +2887,9 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
2860
2887
}
2861
2888
2862
2889
2863
- % * BLOCKS_DONE {$ node . cuid} := Chunk. void (" (" , | @ function , " )" );
2864
2890
2865
2891
2866
2892
2867
- if self . is_block_part_of_sc($ node ) {
2868
- if $ node . blocktype eq ' immediate' {
2869
- # TODO think about that, and find a way to test this
2870
- # say("// it's an immediate one");
2871
- } else {
2872
- % ! serialized_code_ref_info {$ node . cuid} := SerializedCodeRefInfo. new (
2873
- closure_template => Chunk. new ($ T_OBJ , " " , @ function ). join (),
2874
- ctx => $ * CTX ,
2875
- outer_ctx => (nqp :: defined ($ * BLOCK . outer) ?? $ * BLOCK . outer. ctx !! " " ),
2876
- static_info => self . static_info_for_lexicals($ * BLOCK )
2877
- );
2878
- }
2879
- }
2880
2893
2881
2894
}
2882
2895
0 commit comments