From 8848ad8a546627e1e935c46950c7a9df759b320e Mon Sep 17 00:00:00 2001 From: Kimplul Date: Thu, 13 Mar 2025 19:38:52 +0200 Subject: increase priority for loops --- deps/ejit | 2 +- examples/global-loop.ph | 9 +++++++++ examples/local-loop.ph | 12 ++++++++++++ examples/ok-loop-huge.ph | 9 --------- src/lower.c | 3 +++ 5 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 examples/global-loop.ph create mode 100644 examples/local-loop.ph delete mode 100644 examples/ok-loop-huge.ph diff --git a/deps/ejit b/deps/ejit index ba9145b..57f6b41 160000 --- a/deps/ejit +++ b/deps/ejit @@ -1 +1 @@ -Subproject commit ba9145b0b7af2a82c62f8dfa28807958af5d0c8d +Subproject commit 57f6b41047e95374701ee276248f0f8615168450 diff --git a/examples/global-loop.ph b/examples/global-loop.ph new file mode 100644 index 0000000..2381537 --- /dev/null +++ b/examples/global-loop.ph @@ -0,0 +1,9 @@ +var sum = 0 +var idx = 0 + +do + sum = sum + idx, + idx = idx + 1 +until idx = 1000000001, + +print sum diff --git a/examples/local-loop.ph b/examples/local-loop.ph new file mode 100644 index 0000000..2b7d870 --- /dev/null +++ b/examples/local-loop.ph @@ -0,0 +1,12 @@ +procedure SUM{num[int]} return int +var sum = 0 +var idx = 0 +is + do + sum = sum + idx, + idx = idx + 1 + until idx = num, + return sum +end procedure + +print SUM(1000000001) diff --git a/examples/ok-loop-huge.ph b/examples/ok-loop-huge.ph deleted file mode 100644 index 2381537..0000000 --- a/examples/ok-loop-huge.ph +++ /dev/null @@ -1,9 +0,0 @@ -var sum = 0 -var idx = 0 - -do - sum = sum + idx, - idx = idx + 1 -until idx = 1000000001, - -print sum diff --git a/src/lower.c b/src/lower.c index 7f74a50..f08d5a0 100644 --- a/src/lower.c +++ b/src/lower.c @@ -907,12 +907,15 @@ static struct ejit_reloc branch_if(struct fn *f, struct ast *cond, bool branch) static void lower_until(struct fn *f, struct ast *n) { struct ejit_label l = ejit_label(f->f); + ejit_inc_prio(f->f, 100); /* completely arbitrary */ lower_list(f, until_body(n)); struct ast *cond = until_cond(n); struct ejit_reloc branch = branch_if(f, cond, false); ejit_patch(f->f, branch, l); + ejit_dec_prio(f->f, 100); + n->l = null_loc(); } -- cgit v1.2.3