Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

More list ops #42

Closed
wants to merge 2 commits into from

3 participants

@kboga
Collaborator

fix: plan
refactor: making code for list generation
add: list_(n,s) ops

just an experiment :)

@kboga
Collaborator

It should be trivial to add the Fixed(PMC|Integer|Float|String)Array forms as well.
Not sure how their ops should be named though.

@pmichaud
Owner

Unless we really think we need Resizable{Integer|Float|String}Array types, I'd be against including them. The point is to come up with the smallest set of operations we need, not to interface to everything that happens to be in Parrot.

Pm

@kboga
Collaborator

You are absolutely right of course :)
Seeing the list & list_i I thought there was some code duplication.
So refactored that and then I got too excited and added them all.
Anyways was just experimenting here.

Feel free to close instead of merging

@jnthn jnthn closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 31, 2012
  1. @kboga

    fix plan

    kboga authored
  2. @kboga
This page is out of date. Refresh to see the latest.
Showing with 20 additions and 31 deletions.
  1. +19 −30 src/QAST/Operations.nqp
  2. +1 −1  t/qast/qast.t
View
49 src/QAST/Operations.nqp
@@ -111,37 +111,26 @@ class QAST::Operations {
}
# Data structures
-QAST::Operations.add_core_op('list', -> $qastcomp, $op {
- # Create register for the resulting list and make an empty one.
- my $list_reg := $*REGALLOC.fresh_p();
- my $ops := $qastcomp.post_new('Ops', :result($list_reg));
- $ops.push_pirop('new', $list_reg, "'ResizablePMCArray'");
-
- # Push all the things.
- for $op.list {
- my $post := $qastcomp.coerce($qastcomp.as_post($_), 'P');
- $ops.push($post);
- $ops.push_pirop('push', $list_reg, $post.result);
- }
-
- $ops
-});
-
-QAST::Operations.add_core_op('list_i', -> $qastcomp, $op {
- # Create register for the resulting list and make an empty one.
- my $list_reg := $*REGALLOC.fresh_p();
- my $ops := $qastcomp.post_new('Ops', :result($list_reg));
- $ops.push_pirop('new', $list_reg, "'ResizableIntegerArray'");
-
- # Push all the things.
- for $op.list {
- my $post := $qastcomp.coerce($qastcomp.as_post($_), 'i');
- $ops.push($post);
- $ops.push_pirop('push', $list_reg, $post.result);
+sub make_listgen_code($rpa_name, $rpa_type) {
+ -> $qastcomp, $op {
+ # Create register for the resulting list and make an empty one.
+ my $list_reg := $*REGALLOC.fresh_p();
+ my $ops := $qastcomp.post_new('Ops', :result($list_reg));
+ $ops.push_pirop('new', $list_reg, $rpa_name);
+
+ # Push all the things.
+ for $op.list {
+ my $post := $qastcomp.coerce($qastcomp.as_post($_), $rpa_type);
+ $ops.push($post);
+ $ops.push_pirop('push', $list_reg, $post.result);
+ }
+ $ops
}
-
- $ops
-});
+}
+QAST::Operations.add_core_op('list', make_listgen_code("'ResizablePMCArray'", 'P'));
+QAST::Operations.add_core_op('list_i', make_listgen_code("'ResizableIntegerArray'", 'i'));
+QAST::Operations.add_core_op('list_n', make_listgen_code("'ResizableFloatArray'", 'n'));
+QAST::Operations.add_core_op('list_s', make_listgen_code("'ResizableStringArray'", 's'));
QAST::Operations.add_core_op('hash', -> $qastcomp, $op {
# Create register for the resulting hash and make an empty one.
View
2  t/qast/qast.t
@@ -1,6 +1,6 @@
use QRegex;
-plan(46);
+plan(59);
# Following a test infrastructure.
sub compile_qast($qast) {
Something went wrong with that request. Please try again.