On Mon Jul 22 08:53:09 2019, PEVANS wrote:
Show quoted text> This should make its way to perl 5.31.3. At this point now we should
> be able to rely on that, and can begin some backporting effort to
> implementing it on older perls; 5.30 back to 5.20. Recent perls should
> be relatively easy to add because we can just emit optrees with the
> OP_ARG* operations in them, but progressively older perls might become
> more difficult, having to basically rebuild the entire `@_` unpack
> operation manually.
The attached patch works for latest bleadperl.
The task now will be to backport this; I'll start at 5.30 and see how far back I can get.
--
Paul Evans
=== modified file 'lib/Future/AsyncAwait.xs'
--- lib/Future/AsyncAwait.xs 2019-07-05 14:51:55 +0000
+++ lib/Future/AsyncAwait.xs 2019-07-22 13:54:24 +0000
@@ -15,6 +15,10 @@
#define HAVE_PERL_VERSION(R, V, S) \
(PERL_REVISION > (R) || (PERL_REVISION == (R) && (PERL_VERSION > (V) || (PERL_VERSION == (V) && (PERL_SUBVERSION >= (S))))))
+#if HAVE_PERL_VERSION(5, 31, 3)
+# define HAVE_PARSE_SUBSIGNATURE
+#endif
+
#if !HAVE_PERL_VERSION(5, 24, 0)
/* On perls before 5.24 we have to do some extra work to save the itervar
* from being thrown away */
@@ -2088,6 +2092,21 @@
}
}
+#ifdef HAVE_PARSE_SUBSIGNATURE
+ OP *sigop = NULL;
+ if(lex_peek_unichar(0) == '(') {
+ lex_read_unichar(0);
+
+ sigop = parse_subsignature(0);
+ lex_read_space(0);
+
+ if(lex_peek_unichar(0) != ')')
+ croak("Expected ')'");
+ lex_read_unichar(0);
+ lex_read_space(0);
+ }
+#endif
+
if(lex_peek_unichar(0) != '{')
croak("Expected async sub %sto be followed by '{'", name ? "NAME " : "");
@@ -2109,6 +2128,11 @@
SvREFCNT_inc(PL_compcv);
body = block_end(save_ix, body);
+#ifdef HAVE_PARSE_SUBSIGNATURE
+ if(sigop)
+ body = op_append_list(OP_LINESEQ, sigop, body);
+#endif
+
/* turn block into
* NEXTSTATE; PUSHMARK; eval { BLOCK }; LEAVEASYNC
*/