-
-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rakudo]: Fix assignment metaoperators, add reduction operators (e.g.…
…, [+]). git-svn-id: http://svn.perl.org/parrot/trunk/languages/perl6@33611 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
- Loading branch information
Showing
7 changed files
with
149 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/perl | ||
# Copyright (C) 2008, The Perl Foundation. | ||
# $Id$ | ||
|
||
use strict; | ||
use warnings; | ||
|
||
my @ops = qw( | ||
** 1 | ||
* 1 | ||
/ 'fail' | ||
% 'fail' | ||
x 'fail' | ||
xx 'fail' | ||
+& -1 | ||
+< 'fail' | ||
+> 'fail' | ||
~& 'fail' | ||
~< 'fail' | ||
~> 'fail' | ||
?& 1 | ||
+ 0 | ||
- 0 | ||
~ '' | ||
+| 0 | ||
+^ 0 | ||
~| '' | ||
~^ '' | ||
?| 0 | ||
?^ 0 | ||
); | ||
|
||
|
||
my $output = $ARGV[0] || '-'; | ||
|
||
|
||
my $assignfmt = | ||
" optable.'newtok'('infix:%s=', 'equiv'=>'infix::=', 'lvalue'=>1)\n"; | ||
my $reducefmt = | ||
" optable.'newtok'('prefix:[%s]', 'equiv'=>'infix:=')\n"; | ||
|
||
my @gtokens = (); | ||
my @code = (); | ||
|
||
while (@ops) { | ||
my $opname = shift @ops; | ||
my $identity = shift @ops; | ||
|
||
push @gtokens, sprintf( $assignfmt, $opname ); | ||
push @gtokens, sprintf( $reducefmt, $opname ); | ||
|
||
push @code, qq( | ||
.sub 'infix:$opname=' | ||
.param pmc a | ||
.param pmc b | ||
.tailcall '!ASSIGNMETAOP'('$opname', a, b) | ||
.end | ||
.sub 'prefix:[$opname]' | ||
.param pmc args :slurpy | ||
.tailcall '!REDUCEMETAOP'('$opname', $identity, args) | ||
.end\n); | ||
} | ||
|
||
my $gtokens = join('', @gtokens); | ||
|
||
open my $fh, "> $output" or die "Could not write $output: $!"; | ||
print $fh qq( | ||
.namespace [] | ||
.sub '' :init :load | ||
.local pmc optable | ||
optable = get_hll_global ['Perl6';'Grammar'], '\$optable' | ||
$gtokens | ||
.end | ||
); | ||
|
||
print $fh @code; | ||
|
||
close $fh; | ||
0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.