New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
handle Junction threading in dispatch code #377
Comments
From @bacekHello. I've (slightly) refactor Junction.pir. 1. Get rid of "junction_comparision_helper". Use "infix_junction_helper" -- |
From @bacekjunction.patchdiff --git a/languages/perl6/src/classes/Junction.pir b/languages/perl6/src/classes/Junction.pir
index 9e5baca..bdbf01d 100644
--- a/languages/perl6/src/classes/Junction.pir
+++ b/languages/perl6/src/classes/Junction.pir
@@ -153,6 +153,10 @@ Clone v-table method.
.return(junc)
.end
+.sub 'VTABLE_get_string' :method :vtable('get_string')
+ $S0 = self.'perl'()
+ .return ($S0)
+.end
=item perl()
@@ -1080,21 +1084,21 @@ Override numerical equality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:=="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:==' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:=="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:==' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:=="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1108,21 +1112,21 @@ Override numerical inequality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:!="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:!=' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:!="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:!=' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:!="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1136,21 +1140,21 @@ Override numerical greater than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:>"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:>' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:>"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:>' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:>"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1164,21 +1168,21 @@ Override numerical less than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:<"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:<' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:<"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:<' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:<"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1192,21 +1196,21 @@ Override numerical greater than or equal to for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:>="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:>=' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:>="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:>=' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:>="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1220,21 +1224,21 @@ Override numerical less than or equal to for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:<="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:<=' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:<="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:<=' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:<="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1248,21 +1252,21 @@ Override string equality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:eq"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:eq' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:eq"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:eq' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:eq"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1276,21 +1280,21 @@ Override string inequality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:ne"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:ne' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:ne"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:ne' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:ne"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1304,21 +1308,21 @@ Override string less than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:lt"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:lt' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:lt"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:lt' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:lt"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1332,21 +1336,21 @@ Override string greater than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:gt"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:gt' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:gt"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:gt' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:gt"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1360,21 +1364,21 @@ Override string less than or equal for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:le"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:le' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:le"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:le' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:le"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1388,21 +1392,21 @@ Override string greater than or equal for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:ge"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:ge' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:ge"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:ge' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:ge"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1436,7 +1440,7 @@ loop:
sa:
$P0 = op_sub(x, cur_elem)
nsa:
- ResultHash[$P0] = 1
+ ResultHash[$P0] = $P0
inc i
goto loop
loop_end:
@@ -1456,6 +1460,7 @@ loop_end:
nv_loop:
unless iterator goto nv_loop_end
$P0 = shift iterator
+ $P0 = ResultHash[$P0]
push new_values, $P0
goto nv_loop
nv_loop_end:
@@ -1464,65 +1469,6 @@ nv_loop_end:
.return(new_junc)
.end
-# Helper sub for junction comparrisons.
-.sub junction_comparrison_helper :anon
- .param pmc op_func
- .param pmc j
- .param pmc x
- .param int second_arg
-
- # We need to find how many values are equal.
- .local pmc values
- .local int num_equal
- .local int count
- .local int i
- values = j.'values'()
- count = elements values
- i = 0
- num_equal = 0
-loop:
- if i >= count goto end_loop
- $P0 = values[i]
- if second_arg goto sa
- $I0 = op_func($P0, x)
- goto not_sa
-sa:
- $I0 = op_func(x, $P0)
-not_sa:
- num_equal += $I0
- inc i
- goto loop
-end_loop:
-
- # Now go by juction type.
- .local int type
- type = j.'!type'()
- if type == JUNCTION_TYPE_ALL goto all
- if type == JUNCTION_TYPE_ANY goto any
- if type == JUNCTION_TYPE_ONE goto one
- if type == JUNCTION_TYPE_NONE goto none
-
-all:
- if num_equal == count goto ret_true
- goto ret_false
-any:
- if num_equal > 0 goto ret_true
- goto ret_false
-one:
- if num_equal == 1 goto ret_true
- goto ret_false
-none:
- if num_equal == 0 goto ret_true
- goto ret_false
-
-ret_true:
- $P0 = get_hll_global ['Bool'], 'True'
- .return($P0)
-ret_false:
- $P0 = get_hll_global ['Bool'], 'False'
- .return($P0)
-.end
-
# Helper sub for implementing unary operators.
.sub unary_junction_helper :anon
@@ -1548,7 +1494,7 @@ loop:
if i >= count goto loop_end
cur_elem = values[i]
$P0 = op_sub(cur_elem)
- ResultHash[$P0] = 1
+ ResultHash[$P0] = $P0
inc i
goto loop
loop_end:
@@ -1568,6 +1514,7 @@ loop_end:
nv_loop:
unless iterator goto nv_loop_end
$P0 = shift iterator
+ $P0 = ResultHash[$P0]
push new_values, $P0
goto nv_loop
nv_loop_end:
|
From @pmichaudOn Mon, Oct 27, 2008 at 03:47:50AM -0700, Vasily Chekalkin wrote:
Okay to apply patch as long as spectest_regression still passes. I would prefer to eliminate the 'ResultHash' altogether -- Note that all of this effectively disappears when we have Pm |
The RT System itself - Status changed from 'new' to 'open' |
From @bacekPatrick R. Michaud via RT wrote:
Yes, it still passing.
I tried this varian before submitting patch, but hit some parrot's bug
Indeed. But current state of MMD doesn't allow to implement -- |
From @pmichaudOn Tue, Oct 28, 2008 at 07:10:15PM +1100, Vasily Chekalkin wrote:
I'm not too worried about throw_from_c right now, because it's Pm |
From @jnthnPatrick R. Michaud wrote:
Yup, and I don't plan to spend any more time on those functions inside Meta: Back into Rakudo stuff proper within the next week...being Jonathan |
From @moritzPatrick R. Michaud wrote:
It does, even with a few passing TODO tests. So applied yesterday, but Moritz -- |
@moritz - Status changed from 'open' to 'resolved' |
From @moritzOpening again, shouldn't have closed in the first place as per Patrick's |
@moritz - Status changed from 'resolved' to 'open' |
From @bacekHello. After some breakages and discussions on #perl6 and #parrot I've remade 1. Refactor 'junction_comparision_helper' to 'get_bool' vtable. It now passed 6 of 8 recently added tests in -- |
From @bacekjunction2.patchcommit f15089f62abd7478573ad4145589153b5465ae92
Author: Vasily Chekalkin <bacek@bacek.com>
Date: Wed Nov 5 05:23:47 2008 +1100
Refactor junctions
diff --git a/languages/perl6/src/classes/Junction.pir b/languages/perl6/src/classes/Junction.pir
index 9e5baca..9e1b09d 100644
--- a/languages/perl6/src/classes/Junction.pir
+++ b/languages/perl6/src/classes/Junction.pir
@@ -208,6 +208,60 @@ Returns a Perl representation of a junction.
.return (res)
.end
+=item
+
+Override get_bool for Junction
+
+=cut
+
+.sub 'get_bool' :method :vtable
+ # We need to find how many values are equal.
+ .local pmc values
+ .local int num_equal
+ .local int count
+ .local int i
+
+ values = self.'values'()
+ count = elements values
+ i = 0
+ num_equal = 0
+ loop:
+ if i >= count goto end_loop
+ $P0 = values[i]
+ $I0 = 'prefix:?'($P0)
+ num_equal += $I0
+ inc i
+ goto loop
+ end_loop:
+
+ # Now go by juction type.
+ .local int type
+ type = self.'!type'()
+ if type == JUNCTION_TYPE_ALL goto all
+ if type == JUNCTION_TYPE_ANY goto any
+ if type == JUNCTION_TYPE_ONE goto one
+ if type == JUNCTION_TYPE_NONE goto none
+
+ all:
+ if num_equal == count goto ret_true
+ goto ret_false
+ any:
+ if num_equal > 0 goto ret_true
+ goto ret_false
+ one:
+ if num_equal == 1 goto ret_true
+ goto ret_false
+ none:
+ if num_equal == 0 goto ret_true
+ goto ret_false
+
+ ret_true:
+ $P0 = get_hll_global ['Bool'], 'True'
+ .return($P0)
+ ret_false:
+ $P0 = get_hll_global ['Bool'], 'False'
+ .return($P0)
+.end
=back
@@ -449,18 +503,6 @@ Override prefix decrement for junctions.
.end
-=item C<prefix:!(...)>
-
-Override not for junctions.
-
-=cut
-
-.sub 'prefix:!' :multi('Junction')
- .param pmc j
- $P0 = find_global 'prefix:!'
- .return unary_junction_helper($P0, j)
-.end
-
=item C<prefix:+(...)>
@@ -500,20 +542,6 @@ Override stringification for junctions.
.return unary_junction_helper($P0, j)
.end
-
-=item C<prefix:?(...)>
-
-Override boolification for junctions.
-
-=cut
-
-.sub 'prefix:?' :multi('Junction')
- .param pmc j
- $P0 = find_global 'prefix:?'
- .return unary_junction_helper($P0, j)
-.end
-
-
=item C<prefix:=(...)>
Override iteration for junctions.
@@ -1080,21 +1108,21 @@ Override numerical equality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:=="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:==' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:=="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:==' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:=="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1108,21 +1136,21 @@ Override numerical inequality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:!="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:!=' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:!="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:!=' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:!="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1136,21 +1164,21 @@ Override numerical greater than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:>"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:>' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:>"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:>' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:>"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1164,21 +1192,21 @@ Override numerical less than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:<"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:<' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:<"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:<' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:<"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1192,21 +1220,21 @@ Override numerical greater than or equal to for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:>="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:>=' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:>="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:>=' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:>="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1220,21 +1248,21 @@ Override numerical less than or equal to for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:<="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:<=' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:<="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:<=' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:<="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1248,21 +1276,21 @@ Override string equality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:eq"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:eq' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:eq"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:eq' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:eq"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1276,21 +1304,21 @@ Override string inequality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:ne"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:ne' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:ne"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:ne' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:ne"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1304,21 +1332,21 @@ Override string less than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:lt"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:lt' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:lt"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:lt' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:lt"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1332,21 +1360,21 @@ Override string greater than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:gt"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:gt' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:gt"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:gt' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:gt"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1360,21 +1388,21 @@ Override string less than or equal for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:le"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:le' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:le"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:le' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:le"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1388,21 +1416,21 @@ Override string greater than or equal for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:ge"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:ge' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:ge"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:ge' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:ge"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1436,7 +1464,7 @@ loop:
sa:
$P0 = op_sub(x, cur_elem)
nsa:
- ResultHash[$P0] = 1
+ ResultHash[$P0] = $P0
inc i
goto loop
loop_end:
@@ -1456,6 +1484,7 @@ loop_end:
nv_loop:
unless iterator goto nv_loop_end
$P0 = shift iterator
+ $P0 = ResultHash[$P0]
push new_values, $P0
goto nv_loop
nv_loop_end:
@@ -1464,66 +1493,6 @@ nv_loop_end:
.return(new_junc)
.end
-# Helper sub for junction comparrisons.
-.sub junction_comparrison_helper :anon
- .param pmc op_func
- .param pmc j
- .param pmc x
- .param int second_arg
-
- # We need to find how many values are equal.
- .local pmc values
- .local int num_equal
- .local int count
- .local int i
- values = j.'values'()
- count = elements values
- i = 0
- num_equal = 0
-loop:
- if i >= count goto end_loop
- $P0 = values[i]
- if second_arg goto sa
- $I0 = op_func($P0, x)
- goto not_sa
-sa:
- $I0 = op_func(x, $P0)
-not_sa:
- num_equal += $I0
- inc i
- goto loop
-end_loop:
-
- # Now go by juction type.
- .local int type
- type = j.'!type'()
- if type == JUNCTION_TYPE_ALL goto all
- if type == JUNCTION_TYPE_ANY goto any
- if type == JUNCTION_TYPE_ONE goto one
- if type == JUNCTION_TYPE_NONE goto none
-
-all:
- if num_equal == count goto ret_true
- goto ret_false
-any:
- if num_equal > 0 goto ret_true
- goto ret_false
-one:
- if num_equal == 1 goto ret_true
- goto ret_false
-none:
- if num_equal == 0 goto ret_true
- goto ret_false
-
-ret_true:
- $P0 = get_hll_global ['Bool'], 'True'
- .return($P0)
-ret_false:
- $P0 = get_hll_global ['Bool'], 'False'
- .return($P0)
-.end
-
-
# Helper sub for implementing unary operators.
.sub unary_junction_helper :anon
.param pmc op_sub
@@ -1548,7 +1517,7 @@ loop:
if i >= count goto loop_end
cur_elem = values[i]
$P0 = op_sub(cur_elem)
- ResultHash[$P0] = 1
+ ResultHash[$P0] = $P0
inc i
goto loop
loop_end:
@@ -1568,6 +1537,7 @@ loop_end:
nv_loop:
unless iterator goto nv_loop_end
$P0 = shift iterator
+ $P0 = ResultHash[$P0]
push new_values, $P0
goto nv_loop
nv_loop_end:
@@ -1576,7 +1546,7 @@ nv_loop_end:
.return(new_junc)
.end
-
+
=back
=cut
|
From @bacekHello. After some breakages and discussions on #perl6 and #parrot I've remade 1. Refactor 'junction_comparision_helper' to 'get_bool' vtable. -- |
From @bacekjunction2.patchcommit f15089f62abd7478573ad4145589153b5465ae92
Author: Vasily Chekalkin <bacek@bacek.com>
Date: Wed Nov 5 05:23:47 2008 +1100
Refactor junctions
diff --git a/languages/perl6/src/classes/Junction.pir b/languages/perl6/src/classes/Junction.pir
index 9e5baca..9e1b09d 100644
--- a/languages/perl6/src/classes/Junction.pir
+++ b/languages/perl6/src/classes/Junction.pir
@@ -208,6 +208,60 @@ Returns a Perl representation of a junction.
.return (res)
.end
+=item
+
+Override get_bool for Junction
+
+=cut
+
+.sub 'get_bool' :method :vtable
+ # We need to find how many values are equal.
+ .local pmc values
+ .local int num_equal
+ .local int count
+ .local int i
+
+ values = self.'values'()
+ count = elements values
+ i = 0
+ num_equal = 0
+ loop:
+ if i >= count goto end_loop
+ $P0 = values[i]
+ $I0 = 'prefix:?'($P0)
+ num_equal += $I0
+ inc i
+ goto loop
+ end_loop:
+
+ # Now go by juction type.
+ .local int type
+ type = self.'!type'()
+ if type == JUNCTION_TYPE_ALL goto all
+ if type == JUNCTION_TYPE_ANY goto any
+ if type == JUNCTION_TYPE_ONE goto one
+ if type == JUNCTION_TYPE_NONE goto none
+
+ all:
+ if num_equal == count goto ret_true
+ goto ret_false
+ any:
+ if num_equal > 0 goto ret_true
+ goto ret_false
+ one:
+ if num_equal == 1 goto ret_true
+ goto ret_false
+ none:
+ if num_equal == 0 goto ret_true
+ goto ret_false
+
+ ret_true:
+ $P0 = get_hll_global ['Bool'], 'True'
+ .return($P0)
+ ret_false:
+ $P0 = get_hll_global ['Bool'], 'False'
+ .return($P0)
+.end
=back
@@ -449,18 +503,6 @@ Override prefix decrement for junctions.
.end
-=item C<prefix:!(...)>
-
-Override not for junctions.
-
-=cut
-
-.sub 'prefix:!' :multi('Junction')
- .param pmc j
- $P0 = find_global 'prefix:!'
- .return unary_junction_helper($P0, j)
-.end
-
=item C<prefix:+(...)>
@@ -500,20 +542,6 @@ Override stringification for junctions.
.return unary_junction_helper($P0, j)
.end
-
-=item C<prefix:?(...)>
-
-Override boolification for junctions.
-
-=cut
-
-.sub 'prefix:?' :multi('Junction')
- .param pmc j
- $P0 = find_global 'prefix:?'
- .return unary_junction_helper($P0, j)
-.end
-
-
=item C<prefix:=(...)>
Override iteration for junctions.
@@ -1080,21 +1108,21 @@ Override numerical equality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:=="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:==' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:=="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:==' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:=="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1108,21 +1136,21 @@ Override numerical inequality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:!="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:!=' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:!="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:!=' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:!="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1136,21 +1164,21 @@ Override numerical greater than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:>"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:>' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:>"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:>' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:>"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1164,21 +1192,21 @@ Override numerical less than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:<"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:<' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:<"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:<' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:<"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1192,21 +1220,21 @@ Override numerical greater than or equal to for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:>="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:>=' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:>="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:>=' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:>="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1220,21 +1248,21 @@ Override numerical less than or equal to for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:<="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:<=' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:<="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:<=' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:<="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1248,21 +1276,21 @@ Override string equality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:eq"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:eq' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:eq"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:eq' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:eq"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1276,21 +1304,21 @@ Override string inequality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:ne"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:ne' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:ne"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:ne' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:ne"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1304,21 +1332,21 @@ Override string less than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:lt"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:lt' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:lt"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:lt' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:lt"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1332,21 +1360,21 @@ Override string greater than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:gt"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:gt' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:gt"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:gt' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:gt"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1360,21 +1388,21 @@ Override string less than or equal for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:le"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:le' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:le"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:le' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:le"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1388,21 +1416,21 @@ Override string greater than or equal for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:ge"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:ge' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:ge"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:ge' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:ge"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1436,7 +1464,7 @@ loop:
sa:
$P0 = op_sub(x, cur_elem)
nsa:
- ResultHash[$P0] = 1
+ ResultHash[$P0] = $P0
inc i
goto loop
loop_end:
@@ -1456,6 +1484,7 @@ loop_end:
nv_loop:
unless iterator goto nv_loop_end
$P0 = shift iterator
+ $P0 = ResultHash[$P0]
push new_values, $P0
goto nv_loop
nv_loop_end:
@@ -1464,66 +1493,6 @@ nv_loop_end:
.return(new_junc)
.end
-# Helper sub for junction comparrisons.
-.sub junction_comparrison_helper :anon
- .param pmc op_func
- .param pmc j
- .param pmc x
- .param int second_arg
-
- # We need to find how many values are equal.
- .local pmc values
- .local int num_equal
- .local int count
- .local int i
- values = j.'values'()
- count = elements values
- i = 0
- num_equal = 0
-loop:
- if i >= count goto end_loop
- $P0 = values[i]
- if second_arg goto sa
- $I0 = op_func($P0, x)
- goto not_sa
-sa:
- $I0 = op_func(x, $P0)
-not_sa:
- num_equal += $I0
- inc i
- goto loop
-end_loop:
-
- # Now go by juction type.
- .local int type
- type = j.'!type'()
- if type == JUNCTION_TYPE_ALL goto all
- if type == JUNCTION_TYPE_ANY goto any
- if type == JUNCTION_TYPE_ONE goto one
- if type == JUNCTION_TYPE_NONE goto none
-
-all:
- if num_equal == count goto ret_true
- goto ret_false
-any:
- if num_equal > 0 goto ret_true
- goto ret_false
-one:
- if num_equal == 1 goto ret_true
- goto ret_false
-none:
- if num_equal == 0 goto ret_true
- goto ret_false
-
-ret_true:
- $P0 = get_hll_global ['Bool'], 'True'
- .return($P0)
-ret_false:
- $P0 = get_hll_global ['Bool'], 'False'
- .return($P0)
-.end
-
-
# Helper sub for implementing unary operators.
.sub unary_junction_helper :anon
.param pmc op_sub
@@ -1548,7 +1517,7 @@ loop:
if i >= count goto loop_end
cur_elem = values[i]
$P0 = op_sub(cur_elem)
- ResultHash[$P0] = 1
+ ResultHash[$P0] = $P0
inc i
goto loop
loop_end:
@@ -1568,6 +1537,7 @@ loop_end:
nv_loop:
unless iterator goto nv_loop_end
$P0 = shift iterator
+ $P0 = ResultHash[$P0]
push new_values, $P0
goto nv_loop
nv_loop_end:
@@ -1576,7 +1546,7 @@ nv_loop_end:
.return(new_junc)
.end
-
+
=back
=cut
|
From @bacekAnother attempt. Now with short-circuit version of get_bool. -- |
From @bacekjunction3.patchcommit e6661598b0f481003a46a54bf49287f252b2a32f
Author: Vasily Chekalkin <bacek@bacek.com>
Date: Wed Nov 5 05:23:47 2008 +1100
Refactor junctions
diff --git a/languages/perl6/src/classes/Junction.pir b/languages/perl6/src/classes/Junction.pir
index 0b5379a..af36be1 100644
--- a/languages/perl6/src/classes/Junction.pir
+++ b/languages/perl6/src/classes/Junction.pir
@@ -219,6 +219,77 @@ Returns a Perl representation of a junction.
.return (res)
.end
+=item
+
+Override get_bool for Junction
+
+=cut
+
+.sub 'get_bool' :method :vtable
+ # We need to find how many values are equal.
+ .local pmc values
+ .local pmc it
+
+ values = self.'values'()
+ it = iter values
+
+ # Now go by juction type.
+ .local int type
+ type = self.'!type'()
+ if type == JUNCTION_TYPE_ALL goto all
+ if type == JUNCTION_TYPE_ANY goto any
+ if type == JUNCTION_TYPE_ONE goto one
+ if type == JUNCTION_TYPE_NONE goto none
+
+ all:
+ # check values while True.
+ all_loop:
+ unless it goto ret_true
+ $P0 = shift it
+ $I0 = 'prefix:?'($P0)
+ unless $I0 goto ret_false
+ goto all_loop
+
+ any:
+ # check values while False.
+ any_loop:
+ unless it goto ret_false
+ $P0 = shift it
+ $I0 = 'prefix:?'($P0)
+ if $I0 goto ret_true
+ goto any_loop
+
+ one:
+ # check values while count < 1.
+ .local int count
+ count = 0
+ one_loop:
+ unless it goto check_count
+ $P0 = shift it
+ $I0 = 'prefix:?'($P0)
+ count += $I0
+ if count > 1 goto ret_false
+ goto one_loop
+ check_count:
+ if count == 1 goto ret_true
+ goto ret_false
+
+ none:
+ # check values while False.
+ none_loop:
+ unless it goto ret_true
+ $P0 = shift it
+ $I0 = 'prefix:?'($P0)
+ if $I0 goto ret_false
+ goto none_loop
+
+ ret_true:
+ $P0 = get_hll_global ['Bool'], 'True'
+ .return($P0)
+ ret_false:
+ $P0 = get_hll_global ['Bool'], 'False'
+ .return($P0)
+.end
=back
@@ -460,18 +531,6 @@ Override prefix decrement for junctions.
.end
-=item C<prefix:!(...)>
-
-Override not for junctions.
-
-=cut
-
-.sub 'prefix:!' :multi('Junction')
- .param pmc j
- $P0 = find_global 'prefix:!'
- .return unary_junction_helper($P0, j)
-.end
-
=item C<prefix:+(...)>
@@ -511,20 +570,6 @@ Override stringification for junctions.
.return unary_junction_helper($P0, j)
.end
-
-=item C<prefix:?(...)>
-
-Override boolification for junctions.
-
-=cut
-
-.sub 'prefix:?' :multi('Junction')
- .param pmc j
- $P0 = find_global 'prefix:?'
- .return unary_junction_helper($P0, j)
-.end
-
-
=item C<prefix:=(...)>
Override iteration for junctions.
@@ -1091,21 +1136,21 @@ Override numerical equality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:=="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:==' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:=="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:==' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:=="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1119,21 +1164,21 @@ Override numerical inequality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:!="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:!=' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:!="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:!=' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:!="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1147,21 +1192,21 @@ Override numerical greater than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:>"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:>' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:>"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:>' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:>"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1175,21 +1220,21 @@ Override numerical less than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:<"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:<' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:<"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:<' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:<"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1203,21 +1248,21 @@ Override numerical greater than or equal to for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:>="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:>=' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:>="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:>=' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:>="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1231,21 +1276,21 @@ Override numerical less than or equal to for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:<="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:<=' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:<="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:<=' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:<="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1259,21 +1304,21 @@ Override string equality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:eq"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:eq' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:eq"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:eq' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:eq"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1287,21 +1332,21 @@ Override string inequality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:ne"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:ne' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:ne"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:ne' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:ne"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1315,21 +1360,21 @@ Override string less than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:lt"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:lt' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:lt"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:lt' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:lt"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1343,21 +1388,21 @@ Override string greater than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:gt"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:gt' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:gt"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:gt' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:gt"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1371,21 +1416,21 @@ Override string less than or equal for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:le"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:le' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:le"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:le' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:le"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1399,21 +1444,21 @@ Override string greater than or equal for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:ge"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:ge' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:ge"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:ge' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:ge"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1447,7 +1492,7 @@ loop:
sa:
$P0 = op_sub(x, cur_elem)
nsa:
- ResultHash[$P0] = 1
+ ResultHash[$P0] = $P0
inc i
goto loop
loop_end:
@@ -1467,6 +1512,7 @@ loop_end:
nv_loop:
unless iterator goto nv_loop_end
$P0 = shift iterator
+ $P0 = ResultHash[$P0]
push new_values, $P0
goto nv_loop
nv_loop_end:
@@ -1475,66 +1521,6 @@ nv_loop_end:
.return(new_junc)
.end
-# Helper sub for junction comparrisons.
-.sub junction_comparrison_helper :anon
- .param pmc op_func
- .param pmc j
- .param pmc x
- .param int second_arg
-
- # We need to find how many values are equal.
- .local pmc values
- .local int num_equal
- .local int count
- .local int i
- values = j.'values'()
- count = elements values
- i = 0
- num_equal = 0
-loop:
- if i >= count goto end_loop
- $P0 = values[i]
- if second_arg goto sa
- $I0 = op_func($P0, x)
- goto not_sa
-sa:
- $I0 = op_func(x, $P0)
-not_sa:
- num_equal += $I0
- inc i
- goto loop
-end_loop:
-
- # Now go by juction type.
- .local int type
- type = j.'!type'()
- if type == JUNCTION_TYPE_ALL goto all
- if type == JUNCTION_TYPE_ANY goto any
- if type == JUNCTION_TYPE_ONE goto one
- if type == JUNCTION_TYPE_NONE goto none
-
-all:
- if num_equal == count goto ret_true
- goto ret_false
-any:
- if num_equal > 0 goto ret_true
- goto ret_false
-one:
- if num_equal == 1 goto ret_true
- goto ret_false
-none:
- if num_equal == 0 goto ret_true
- goto ret_false
-
-ret_true:
- $P0 = get_hll_global ['Bool'], 'True'
- .return($P0)
-ret_false:
- $P0 = get_hll_global ['Bool'], 'False'
- .return($P0)
-.end
-
-
# Helper sub for implementing unary operators.
.sub unary_junction_helper :anon
.param pmc op_sub
@@ -1559,7 +1545,7 @@ loop:
if i >= count goto loop_end
cur_elem = values[i]
$P0 = op_sub(cur_elem)
- ResultHash[$P0] = 1
+ ResultHash[$P0] = $P0
inc i
goto loop
loop_end:
@@ -1579,6 +1565,7 @@ loop_end:
nv_loop:
unless iterator goto nv_loop_end
$P0 = shift iterator
+ $P0 = ResultHash[$P0]
push new_values, $P0
goto nv_loop
nv_loop_end:
@@ -1587,7 +1574,7 @@ nv_loop_end:
.return(new_junc)
.end
-
+
=back
=cut
|
From @bacekVasily Chekalkin wrote:
And again. After comments from Pm I remade 'get_bool' to short-circuit -- |
From @bacekjunction3.patchdiff --git a/languages/perl6/src/classes/Junction.pir b/languages/perl6/src/classes/Junction.pir
index 9e5baca..d18b14e 100644
--- a/languages/perl6/src/classes/Junction.pir
+++ b/languages/perl6/src/classes/Junction.pir
@@ -154,6 +154,10 @@ Clone v-table method.
.end
+.sub 'get_string' :method :vtable
+ .return self.'perl'()
+.end
+
=item perl()
Returns a Perl representation of a junction.
@@ -208,6 +212,80 @@ Returns a Perl representation of a junction.
.return (res)
.end
+=item
+
+Override get_bool for Junction
+
+=cut
+
+.sub 'get_bool' :method :vtable
+ # We need to find how many values are equal.
+ .local pmc values
+ .local pmc it
+
+ # get values
+ values = self.'values'()
+ it = iter values
+
+ # Now go by juction type to short-circuited version.
+ .local int type
+ type = self.'!type'()
+ if type == JUNCTION_TYPE_ALL goto all
+ if type == JUNCTION_TYPE_ANY goto any
+ if type == JUNCTION_TYPE_ONE goto one
+ if type == JUNCTION_TYPE_NONE goto none
+
+ all:
+ # Check iter while prefix:? is True.
+ all_loop:
+ unless it goto ret_true
+ $P0 = shift it
+ $I0 = 'prefix:?'($P0)
+ if $I0 goto all_loop
+ goto ret_false
+
+ any:
+ # Check iter while prefix:? is False.
+ any_loop:
+ unless it goto ret_false
+ $P0 = shift it
+ $I0 = 'prefix:?'($P0)
+ unless $I0 goto any_loop
+ goto ret_true
+
+ one:
+ # Check iter while count of True less than one.
+ .local int count
+ count = 0
+ one_loop:
+ unless it goto check_count
+ $P0 = shift it
+ $I0 = 'prefix:?'($P0)
+ count += $I0
+ if count > 1 goto ret_false
+ goto one_loop
+
+ check_count:
+ if count == 1 goto ret_true
+ goto ret_false
+
+ none:
+ # Check iter while prefix:? is False.
+ none_loop:
+ unless it goto ret_true
+ $P0 = shift it
+ $I0 = 'prefix:?'($P0)
+ unless $I0 goto none_loop
+ goto ret_true
+
+
+ ret_true:
+ $P0 = get_hll_global ['Bool'], 'True'
+ .return($P0)
+ ret_false:
+ $P0 = get_hll_global ['Bool'], 'False'
+ .return($P0)
+.end
=back
@@ -457,8 +535,8 @@ Override not for junctions.
.sub 'prefix:!' :multi('Junction')
.param pmc j
- $P0 = find_global 'prefix:!'
- .return unary_junction_helper($P0, j)
+ $P0 = j.'get_bool'()
+ .return 'prefix:!'($P0)
.end
@@ -509,8 +587,8 @@ Override boolification for junctions.
.sub 'prefix:?' :multi('Junction')
.param pmc j
- $P0 = find_global 'prefix:?'
- .return unary_junction_helper($P0, j)
+ $P0 = j.'get_bool'()
+ .return ($P0)
.end
@@ -1080,21 +1158,21 @@ Override numerical equality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:=="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:==' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:=="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:==' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:=="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1108,21 +1186,21 @@ Override numerical inequality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:!="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:!=' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:!="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:!=' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:!="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1136,21 +1214,21 @@ Override numerical greater than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:>"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:>' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:>"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:>' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:>"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1164,21 +1242,21 @@ Override numerical less than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:<"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:<' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:<"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:<' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:<"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1192,21 +1270,21 @@ Override numerical greater than or equal to for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:>="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:>=' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:>="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:>=' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:>="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1220,21 +1298,21 @@ Override numerical less than or equal to for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:<="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:<=' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:<="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:<=' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:<="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1248,21 +1326,21 @@ Override string equality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:eq"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:eq' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:eq"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:eq' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:eq"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1276,21 +1354,21 @@ Override string inequality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:ne"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:ne' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:ne"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:ne' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:ne"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1304,21 +1382,21 @@ Override string less than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:lt"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:lt' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:lt"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:lt' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:lt"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1332,21 +1410,21 @@ Override string greater than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:gt"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:gt' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:gt"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:gt' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:gt"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1360,21 +1438,21 @@ Override string less than or equal for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:le"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:le' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:le"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:le' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:le"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1388,21 +1466,21 @@ Override string greater than or equal for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:ge"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:ge' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:ge"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:ge' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:ge"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1436,7 +1514,7 @@ loop:
sa:
$P0 = op_sub(x, cur_elem)
nsa:
- ResultHash[$P0] = 1
+ ResultHash[$P0] = $P0
inc i
goto loop
loop_end:
@@ -1456,6 +1534,7 @@ loop_end:
nv_loop:
unless iterator goto nv_loop_end
$P0 = shift iterator
+ $P0 = ResultHash[$P0]
push new_values, $P0
goto nv_loop
nv_loop_end:
@@ -1464,66 +1543,6 @@ nv_loop_end:
.return(new_junc)
.end
-# Helper sub for junction comparrisons.
-.sub junction_comparrison_helper :anon
- .param pmc op_func
- .param pmc j
- .param pmc x
- .param int second_arg
-
- # We need to find how many values are equal.
- .local pmc values
- .local int num_equal
- .local int count
- .local int i
- values = j.'values'()
- count = elements values
- i = 0
- num_equal = 0
-loop:
- if i >= count goto end_loop
- $P0 = values[i]
- if second_arg goto sa
- $I0 = op_func($P0, x)
- goto not_sa
-sa:
- $I0 = op_func(x, $P0)
-not_sa:
- num_equal += $I0
- inc i
- goto loop
-end_loop:
-
- # Now go by juction type.
- .local int type
- type = j.'!type'()
- if type == JUNCTION_TYPE_ALL goto all
- if type == JUNCTION_TYPE_ANY goto any
- if type == JUNCTION_TYPE_ONE goto one
- if type == JUNCTION_TYPE_NONE goto none
-
-all:
- if num_equal == count goto ret_true
- goto ret_false
-any:
- if num_equal > 0 goto ret_true
- goto ret_false
-one:
- if num_equal == 1 goto ret_true
- goto ret_false
-none:
- if num_equal == 0 goto ret_true
- goto ret_false
-
-ret_true:
- $P0 = get_hll_global ['Bool'], 'True'
- .return($P0)
-ret_false:
- $P0 = get_hll_global ['Bool'], 'False'
- .return($P0)
-.end
-
-
# Helper sub for implementing unary operators.
.sub unary_junction_helper :anon
.param pmc op_sub
@@ -1548,7 +1567,7 @@ loop:
if i >= count goto loop_end
cur_elem = values[i]
$P0 = op_sub(cur_elem)
- ResultHash[$P0] = 1
+ ResultHash[$P0] = $P0
inc i
goto loop
loop_end:
@@ -1568,6 +1587,7 @@ loop_end:
nv_loop:
unless iterator goto nv_loop_end
$P0 = shift iterator
+ $P0 = ResultHash[$P0]
push new_values, $P0
goto nv_loop
nv_loop_end:
@@ -1576,7 +1596,7 @@ nv_loop_end:
.return(new_junc)
.end
-
+
=back
=cut
|
From @bacekVasily Chekalkin via RT wrote:
And refactored version once again. Now with short-circuit version of -- |
From @bacekjunction3.patchdiff --git a/languages/perl6/src/classes/Junction.pir b/languages/perl6/src/classes/Junction.pir
index 9e5baca..d18b14e 100644
--- a/languages/perl6/src/classes/Junction.pir
+++ b/languages/perl6/src/classes/Junction.pir
@@ -154,6 +154,10 @@ Clone v-table method.
.end
+.sub 'get_string' :method :vtable
+ .return self.'perl'()
+.end
+
=item perl()
Returns a Perl representation of a junction.
@@ -208,6 +212,80 @@ Returns a Perl representation of a junction.
.return (res)
.end
+=item
+
+Override get_bool for Junction
+
+=cut
+
+.sub 'get_bool' :method :vtable
+ # We need to find how many values are equal.
+ .local pmc values
+ .local pmc it
+
+ # get values
+ values = self.'values'()
+ it = iter values
+
+ # Now go by juction type to short-circuited version.
+ .local int type
+ type = self.'!type'()
+ if type == JUNCTION_TYPE_ALL goto all
+ if type == JUNCTION_TYPE_ANY goto any
+ if type == JUNCTION_TYPE_ONE goto one
+ if type == JUNCTION_TYPE_NONE goto none
+
+ all:
+ # Check iter while prefix:? is True.
+ all_loop:
+ unless it goto ret_true
+ $P0 = shift it
+ $I0 = 'prefix:?'($P0)
+ if $I0 goto all_loop
+ goto ret_false
+
+ any:
+ # Check iter while prefix:? is False.
+ any_loop:
+ unless it goto ret_false
+ $P0 = shift it
+ $I0 = 'prefix:?'($P0)
+ unless $I0 goto any_loop
+ goto ret_true
+
+ one:
+ # Check iter while count of True less than one.
+ .local int count
+ count = 0
+ one_loop:
+ unless it goto check_count
+ $P0 = shift it
+ $I0 = 'prefix:?'($P0)
+ count += $I0
+ if count > 1 goto ret_false
+ goto one_loop
+
+ check_count:
+ if count == 1 goto ret_true
+ goto ret_false
+
+ none:
+ # Check iter while prefix:? is False.
+ none_loop:
+ unless it goto ret_true
+ $P0 = shift it
+ $I0 = 'prefix:?'($P0)
+ unless $I0 goto none_loop
+ goto ret_true
+
+
+ ret_true:
+ $P0 = get_hll_global ['Bool'], 'True'
+ .return($P0)
+ ret_false:
+ $P0 = get_hll_global ['Bool'], 'False'
+ .return($P0)
+.end
=back
@@ -457,8 +535,8 @@ Override not for junctions.
.sub 'prefix:!' :multi('Junction')
.param pmc j
- $P0 = find_global 'prefix:!'
- .return unary_junction_helper($P0, j)
+ $P0 = j.'get_bool'()
+ .return 'prefix:!'($P0)
.end
@@ -509,8 +587,8 @@ Override boolification for junctions.
.sub 'prefix:?' :multi('Junction')
.param pmc j
- $P0 = find_global 'prefix:?'
- .return unary_junction_helper($P0, j)
+ $P0 = j.'get_bool'()
+ .return ($P0)
.end
@@ -1080,21 +1158,21 @@ Override numerical equality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:=="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:==' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:=="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:==' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:=="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1108,21 +1186,21 @@ Override numerical inequality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:!="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:!=' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:!="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:!=' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:!="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1136,21 +1214,21 @@ Override numerical greater than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:>"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:>' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:>"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:>' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:>"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1164,21 +1242,21 @@ Override numerical less than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:<"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:<' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:<"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:<' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:<"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1192,21 +1270,21 @@ Override numerical greater than or equal to for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:>="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:>=' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:>="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:>=' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:>="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1220,21 +1298,21 @@ Override numerical less than or equal to for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:<="
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:<=' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:<="
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:<=' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:<="
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1248,21 +1326,21 @@ Override string equality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:eq"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:eq' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:eq"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:eq' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:eq"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1276,21 +1354,21 @@ Override string inequality for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:ne"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:ne' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:ne"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:ne' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:ne"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1304,21 +1382,21 @@ Override string less than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:lt"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:lt' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:lt"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:lt' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:lt"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1332,21 +1410,21 @@ Override string greater than for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:gt"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:gt' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:gt"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:gt' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:gt"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1360,21 +1438,21 @@ Override string less than or equal for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:le"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:le' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:le"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:le' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:le"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1388,21 +1466,21 @@ Override string greater than or equal for junctions.
.param pmc j1
.param pmc j2
$P0 = find_global "infix:ge"
- .return junction_comparrison_helper($P0, j1, j2, 0)
+ .return infix_junction_helper($P0, j1, j2, 0)
.end
.sub 'infix:ge' :multi('Junction',_)
.param pmc j
.param pmc x
$P0 = find_global "infix:ge"
- .return junction_comparrison_helper($P0, j, x, 0)
+ .return infix_junction_helper($P0, j, x, 0)
.end
.sub 'infix:ge' :multi(_,'Junction')
.param pmc x
.param pmc j
$P0 = find_global "infix:ge"
- .return junction_comparrison_helper($P0, j, x, 1)
+ .return infix_junction_helper($P0, j, x, 1)
.end
@@ -1436,7 +1514,7 @@ loop:
sa:
$P0 = op_sub(x, cur_elem)
nsa:
- ResultHash[$P0] = 1
+ ResultHash[$P0] = $P0
inc i
goto loop
loop_end:
@@ -1456,6 +1534,7 @@ loop_end:
nv_loop:
unless iterator goto nv_loop_end
$P0 = shift iterator
+ $P0 = ResultHash[$P0]
push new_values, $P0
goto nv_loop
nv_loop_end:
@@ -1464,66 +1543,6 @@ nv_loop_end:
.return(new_junc)
.end
-# Helper sub for junction comparrisons.
-.sub junction_comparrison_helper :anon
- .param pmc op_func
- .param pmc j
- .param pmc x
- .param int second_arg
-
- # We need to find how many values are equal.
- .local pmc values
- .local int num_equal
- .local int count
- .local int i
- values = j.'values'()
- count = elements values
- i = 0
- num_equal = 0
-loop:
- if i >= count goto end_loop
- $P0 = values[i]
- if second_arg goto sa
- $I0 = op_func($P0, x)
- goto not_sa
-sa:
- $I0 = op_func(x, $P0)
-not_sa:
- num_equal += $I0
- inc i
- goto loop
-end_loop:
-
- # Now go by juction type.
- .local int type
- type = j.'!type'()
- if type == JUNCTION_TYPE_ALL goto all
- if type == JUNCTION_TYPE_ANY goto any
- if type == JUNCTION_TYPE_ONE goto one
- if type == JUNCTION_TYPE_NONE goto none
-
-all:
- if num_equal == count goto ret_true
- goto ret_false
-any:
- if num_equal > 0 goto ret_true
- goto ret_false
-one:
- if num_equal == 1 goto ret_true
- goto ret_false
-none:
- if num_equal == 0 goto ret_true
- goto ret_false
-
-ret_true:
- $P0 = get_hll_global ['Bool'], 'True'
- .return($P0)
-ret_false:
- $P0 = get_hll_global ['Bool'], 'False'
- .return($P0)
-.end
-
-
# Helper sub for implementing unary operators.
.sub unary_junction_helper :anon
.param pmc op_sub
@@ -1548,7 +1567,7 @@ loop:
if i >= count goto loop_end
cur_elem = values[i]
$P0 = op_sub(cur_elem)
- ResultHash[$P0] = 1
+ ResultHash[$P0] = $P0
inc i
goto loop
loop_end:
@@ -1568,6 +1587,7 @@ loop_end:
nv_loop:
unless iterator goto nv_loop_end
$P0 = shift iterator
+ $P0 = ResultHash[$P0]
push new_values, $P0
goto nv_loop
nv_loop_end:
@@ -1576,7 +1596,7 @@ nv_loop_end:
.return(new_junc)
.end
-
+
=back
=cut
|
@bacek - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#60168 (status was 'resolved')
Searchable as RT60168$
The text was updated successfully, but these errors were encountered: