[svn:parrot] r44572 - in branches/ops_pct/compilers/opsc: src/Ops t
bacek at svn.parrot.org
bacek at svn.parrot.org
Mon Mar 1 12:34:06 UTC 2010
Author: bacek
Date: Mon Mar 1 12:34:06 2010
New Revision: 44572
URL: https://trac.parrot.org/parrot/changeset/44572
Log:
Stole expand_args from ops2c
Modified:
branches/ops_pct/compilers/opsc/src/Ops/Compiler.pm
branches/ops_pct/compilers/opsc/t/03-past.t
Modified: branches/ops_pct/compilers/opsc/src/Ops/Compiler.pm
==============================================================================
--- branches/ops_pct/compilers/opsc/src/Ops/Compiler.pm Mon Mar 1 12:33:38 2010 (r44571)
+++ branches/ops_pct/compilers/opsc/src/Ops/Compiler.pm Mon Mar 1 12:34:06 2010 (r44572)
@@ -7,3 +7,40 @@
Ops::Compiler.parseactions(Ops::Compiler::Actions);
}
+=begin
+
+=item C<expand_args(@args)>
+
+Given an argument list, returns a list of all the possible argument
+combinations.
+
+=end
+sub expand_args(@args) {
+
+ return list() unless + at args;
+
+ my $arg := @args.shift;
+
+ my @var := list($arg<type>);
+ if $arg<variant> {
+ @var.push($arg<variant>);
+ }
+
+ my @list := expand_args(@args);
+ unless + at list {
+ return @var;
+ }
+
+ my @results;
+ for @list -> $l {
+ for @var -> $v {
+ # NQP can't handle it automagically. So wrap $l into list.
+ my @l := pir::does__IPS($l, 'array') ?? $l !! list($l);
+ @results.push(list($v, |@l));
+ }
+ }
+
+ @results;
+}
+
+# vim: ft=perl6 expandtab shiftwidth=4:
Modified: branches/ops_pct/compilers/opsc/t/03-past.t
==============================================================================
--- branches/ops_pct/compilers/opsc/t/03-past.t Mon Mar 1 12:33:38 2010 (r44571)
+++ branches/ops_pct/compilers/opsc/t/03-past.t Mon Mar 1 12:34:06 2010 (r44572)
@@ -4,6 +4,7 @@
# Parse single op and check various aspects of created PAST.
pir::load_bytecode('compilers/opsc/opsc.pbc');
+pir::load_bytecode('nqp-settings.pbc');
pir::load_bytecode('dumper.pbc');
plan(14);
@@ -81,7 +82,11 @@
ok($arg<type> eq 'nc', 'Third type is correct');
ok(!($arg<variant>), 'Third arg without variant');
+my @expanded := Ops::Compiler::expand_args(@args);
+#_dumper(@expanded);
+ok( @expanded[0].join('_') eq 'i_p_nc', "First variant correct");
+ok( @expanded[1].join('_') eq 'i_pc_nc', "Second variant correct");
# Don't forget to update plan!
More information about the parrot-commits
mailing list