[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[COMMITTED] pkl: trans: for-loops introduce a lexical level for function
From: |
Jose E. Marchesi |
Subject: |
[COMMITTED] pkl: trans: for-loops introduce a lexical level for function_back computation |
Date: |
Mon, 17 Jan 2022 03:26:45 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
2022-01-17 Jose E. Marchesi <jemarch@gnu.org>
* libpoke/pkl-trans.c (pkl_trans1_pr_loop_stmt): New handler.
(pkl_phase_trans1): Register handler.
(pkl_trans1_ps_loop_stmt): for-loops with decl heads also
introduce a lexical scope.
* testsuite/poke.pkl/struct-method-18.pk: New test.
* testsuite/poke.pkl/struct-method-19.pk: Likewise.
* testsuite/Makefile.am (EXTRA_DIST): Add new tests.
---
ChangeLog | 10 ++++++++++
libpoke/pkl-trans.c | 20 ++++++++++++++++----
testsuite/Makefile.am | 2 ++
testsuite/poke.pkl/struct-method-18.pk | 21 +++++++++++++++++++++
testsuite/poke.pkl/struct-method-19.pk | 22 ++++++++++++++++++++++
5 files changed, 71 insertions(+), 4 deletions(-)
create mode 100644 testsuite/poke.pkl/struct-method-18.pk
create mode 100644 testsuite/poke.pkl/struct-method-19.pk
diff --git a/ChangeLog b/ChangeLog
index 3b34ece5..578221fd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2022-01-17 Jose E. Marchesi <jemarch@gnu.org>
+ * libpoke/pkl-trans.c (pkl_trans1_pr_loop_stmt): New handler.
+ (pkl_phase_trans1): Register handler.
+ (pkl_trans1_ps_loop_stmt): for-loops with decl heads also
+ introduce a lexical scope.
+ * testsuite/poke.pkl/struct-method-18.pk: New test.
+ * testsuite/poke.pkl/struct-method-19.pk: Likewise.
+ * testsuite/Makefile.am (EXTRA_DIST): Add new tests.
+
+2022-01-17 Jose E. Marchesi <jemarch@gnu.org>
+
* poke/pk-help.pk: Support a synopsis entry for "settings" help
entries.
* poke/pk-settings.pk: Set the synopsis of help entries to
diff --git a/libpoke/pkl-trans.c b/libpoke/pkl-trans.c
index 2a46f6bb..edcd697e 100644
--- a/libpoke/pkl-trans.c
+++ b/libpoke/pkl-trans.c
@@ -1086,8 +1086,8 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans1_pr_comp_stmt)
}
PKL_PHASE_END_HANDLER
-/* FOR-IN statements introduce a lexical level if they use an
- iterator. Update the function back. */
+/* FOR-IN statements introduce a lexical level if they use an iterator
+ or have a head of declarations. Update the function back accordingly. */
PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_loop_stmt_iterator)
{
@@ -1095,12 +1095,23 @@ PKL_PHASE_BEGIN_HANDLER
(pkl_trans1_ps_loop_stmt_iterator)
}
PKL_PHASE_END_HANDLER
-PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_loop_stmt)
+PKL_PHASE_BEGIN_HANDLER (pkl_trans1_pr_loop_stmt)
{
pkl_ast_node stmt = PKL_PASS_NODE;
+ if (PKL_AST_LOOP_STMT_HEAD (stmt))
+ {
+ assert (!PKL_AST_LOOP_STMT_ITERATOR (stmt));
+ PKL_TRANS_INCR_FUNCTION_BACK;
+ }
+}
+PKL_PHASE_END_HANDLER
+
+PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_loop_stmt)
+{
+ pkl_ast_node stmt = PKL_PASS_NODE;
- if (PKL_AST_LOOP_STMT_ITERATOR (stmt))
+ if (PKL_AST_LOOP_STMT_ITERATOR (stmt) || PKL_AST_LOOP_STMT_HEAD (stmt))
PKL_TRANS_DECR_FUNCTION_BACK;
}
PKL_PHASE_END_HANDLER
@@ -1176,6 +1187,7 @@ struct pkl_phase pkl_phase_trans1 =
PKL_PHASE_PR_HANDLER (PKL_AST_COMP_STMT, pkl_trans1_pr_comp_stmt),
PKL_PHASE_PS_HANDLER (PKL_AST_COMP_STMT, pkl_trans1_ps_comp_stmt),
PKL_PHASE_PS_HANDLER (PKL_AST_LOOP_STMT_ITERATOR,
pkl_trans1_ps_loop_stmt_iterator),
+ PKL_PHASE_PR_HANDLER (PKL_AST_LOOP_STMT, pkl_trans1_pr_loop_stmt),
PKL_PHASE_PS_HANDLER (PKL_AST_LOOP_STMT, pkl_trans1_ps_loop_stmt),
PKL_PHASE_PR_HANDLER (PKL_AST_STRUCT_TYPE_FIELD,
pkl_trans1_pr_struct_type_field),
PKL_PHASE_PS_HANDLER (PKL_AST_STRUCT_TYPE_FIELD,
pkl_trans1_ps_struct_type_field),
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 339ce004..4a0b632d 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -1906,6 +1906,8 @@ EXTRA_DIST = \
poke.pkl/struct-method-15.pk \
poke.pkl/struct-method-16.pk \
poke.pkl/struct-method-17.pk \
+ poke.pkl/struct-method-18.pk \
+ poke.pkl/struct-method-19.pk \
poke.pkl/struct-method-diag-1.pk \
poke.pkl/struct-method-diag-2.pk \
poke.pkl/struct-method-diag-3.pk \
diff --git a/testsuite/poke.pkl/struct-method-18.pk
b/testsuite/poke.pkl/struct-method-18.pk
new file mode 100644
index 00000000..648ab398
--- /dev/null
+++ b/testsuite/poke.pkl/struct-method-18.pk
@@ -0,0 +1,21 @@
+/* { dg-do run } */
+
+type Foo =
+ struct
+ {
+ int i;
+
+ method lala = int:
+ {
+ var res = 0;
+
+ for (var a = 0; a < i; ++a)
+ for (var b = 0; b < i; ++b)
+ res++;
+
+ return res;
+ }
+ };
+
+/* { dg-command { (Foo { i = 3 }).lala } } */
+/* { dg-output "9" } */
diff --git a/testsuite/poke.pkl/struct-method-19.pk
b/testsuite/poke.pkl/struct-method-19.pk
new file mode 100644
index 00000000..ba719cce
--- /dev/null
+++ b/testsuite/poke.pkl/struct-method-19.pk
@@ -0,0 +1,22 @@
+/* { dg-do run } */
+
+type Foo =
+ struct
+ {
+ int i;
+ byte[i] b;
+
+ method lala = int:
+ {
+ var res = 0;
+
+ for (var a = 0; a < i; ++a)
+ for (e in b)
+ res++;
+
+ return res;
+ }
+ };
+
+/* { dg-command { (Foo { i = 3 }).lala } } */
+/* { dg-output "9" } */
--
2.11.0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [COMMITTED] pkl: trans: for-loops introduce a lexical level for function_back computation,
Jose E. Marchesi <=