perl.cvs.parrot
[Top] [All Lists]

[svn:parrot] r29899 - in trunk/languages/tcl: runtime runtime/builtin sr

Subject: [svn:parrot] r29899 - in trunk/languages/tcl: runtime runtime/builtin src/pmc
From: coke@xxxxxxxxxxxx
Date: Wed, 30 Jul 2008 20:31:35 -0700 (PDT)
Newsgroups: perl.cvs.parrot

Author: coke
Date: Wed Jul 30 20:31:35 2008
New Revision: 29899

Modified:
   trunk/languages/tcl/runtime/builtin/lreverse.pir
   trunk/languages/tcl/runtime/builtin/lsort.pir
   trunk/languages/tcl/runtime/conversions.pir
   trunk/languages/tcl/src/pmc/tcllist.pmc

Log:
[tcl] migrate the list reverse utility sub into a pmc METHOD


Modified: trunk/languages/tcl/runtime/builtin/lreverse.pir
==============================================================================
--- trunk/languages/tcl/runtime/builtin/lreverse.pir    (original)
+++ trunk/languages/tcl/runtime/builtin/lreverse.pir    Wed Jul 30 20:31:35 2008
@@ -10,14 +10,13 @@
 
   .local pmc toList
   toList = get_root_global ['_tcl'], 'toList'
-  .local pmc reverse
-  reverse = get_root_global ['_tcl'], 'reverse'
 
   $P0 = argv[0]
   $P0 = toList($P0)
-  $P0 = reverse($P0)
-  .return ($P0)
+  $P0 = clone $P0
+  $P0.'reverse'()
 
+  .return ($P0)
 bad_args:
   tcl_error 'wrong # args: should be "lreverse list"'
 .end

Modified: trunk/languages/tcl/runtime/builtin/lsort.pir
==============================================================================
--- trunk/languages/tcl/runtime/builtin/lsort.pir       (original)
+++ trunk/languages/tcl/runtime/builtin/lsort.pir       Wed Jul 30 20:31:35 2008
@@ -88,9 +88,8 @@
 skip_unique:
   unless decr goto ordered
 
-  .local pmc reverse
-  reverse = get_root_global ['_tcl'], 'reverse'
-  reverse($P0)
+  $P0 = clone $P0
+  $P0.'reverse'()
 
 ordered:
   .return ($P0)

Modified: trunk/languages/tcl/runtime/conversions.pir
==============================================================================
--- trunk/languages/tcl/runtime/conversions.pir (original)
+++ trunk/languages/tcl/runtime/conversions.pir Wed Jul 30 20:31:35 2008
@@ -689,35 +689,6 @@
   .return (contents)
 .end
 
-# Given a list, reverse the elements in the list.
-# Might make sense to make this a method on one of the parrot types we
-# inherit from.
-.sub 'reverse'
-  .param pmc value
-
-  .local int high
-  .local int low
-  .local pmc swap_one
-  .local pmc swap_two
-
-  high = value
-  dec high # need index, not count
-  low = 0
-
- loop:
-  if high <= low goto loop_end
-  swap_one    = value[low]
-  swap_two    = value[high]
-  value[low]  = swap_two
-  value[high] = swap_one
-  inc low
-  dec high
-  goto loop
- loop_end:
-
- .return()
-.end
-
 # Local Variables:
 #   mode: pir
 #   fill-column: 100

Modified: trunk/languages/tcl/src/pmc/tcllist.pmc
==============================================================================
--- trunk/languages/tcl/src/pmc/tcllist.pmc     (original)
+++ trunk/languages/tcl/src/pmc/tcllist.pmc     Wed Jul 30 20:31:35 2008
@@ -253,9 +253,38 @@
 */
 
     METHOD get_list() {
-      RETURN(PMC *SELF);
+        RETURN(PMC *SELF);
+    }
+
+/*
+
+=item METHOD reverse
+
+Reverse ourselves.
+
+This algorithm is very generic and could easily be
+moved back into parrot core where we'd be happy to inherit it.
+
+=cut
+
+*/
+
+    METHOD reverse() {
+        INTVAL low  = 0;
+        INTVAL high = SELF.get_integer() - 1;
+        PMC*  swap;
+
+        while (low < high) {
+            swap = SELF.get_pmc_keyed_int(high);
+            SELF.set_pmc_keyed_int(high, SELF.get_pmc_keyed_int(low)) ;
+            SELF.set_pmc_keyed_int(low, swap);
+
+            low++;
+            high--;
+        }
+
+        RETURN(PMC *SELF);
     }
-}
 
 /*
 
@@ -263,6 +292,8 @@
 
 */
 
+}
+
 /*
  * Local variables:
  *   c-file-style: "parrot"

<Prev in Thread] Current Thread [Next in Thread>
  • [svn:parrot] r29899 - in trunk/languages/tcl: runtime runtime/builtin src/pmc, coke <=