develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r34581 - in trunk: . languages/pipp/src/common languages/pipp/t/in_php languages/pipp/t/php

From:
bernhard
Date:
December 29, 2008 08:15
Subject:
[svn:parrot] r34581 - in trunk: . languages/pipp/src/common languages/pipp/t/in_php languages/pipp/t/php
Message ID:
20081229161542.4C707CB9FA@x12.develooper.com
Author: bernhard
Date: Mon Dec 29 08:15:40 2008
New Revision: 34581

Added:
   trunk/languages/pipp/t/php/array.t   (contents, props changed)
Modified:
   trunk/MANIFEST
   trunk/languages/pipp/src/common/builtins.pir
   trunk/languages/pipp/src/common/php_array.pir
   trunk/languages/pipp/t/in_php/array.t

Log:
RT #61800: [PATCH] implement array_fill() within pipp.
Courtesy of Daniel Keane.


Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST	(original)
+++ trunk/MANIFEST	Mon Dec 29 08:15:40 2008
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Sun Dec 28 19:14:47 2008 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Mon Dec 29 08:34:09 2008 UT
 #
 # See tools/dev/install_files.pl for documentation on the
 # format of this file.
@@ -2395,6 +2395,7 @@
 languages/pipp/t/in_php/array.t                             [pipp]
 languages/pipp/t/in_php/ops.t                               [pipp]
 languages/pipp/t/php/arithmetics.t                          [pipp]
+languages/pipp/t/php/array.t                                [pipp]
 languages/pipp/t/php/base64.t                               [pipp]
 languages/pipp/t/php/basic.t                                [pipp]
 languages/pipp/t/php/builtin.t                              [pipp]

Modified: trunk/languages/pipp/src/common/builtins.pir
==============================================================================
--- trunk/languages/pipp/src/common/builtins.pir	(original)
+++ trunk/languages/pipp/src/common/builtins.pir	Mon Dec 29 08:15:40 2008
@@ -71,7 +71,7 @@
 
 ## symbolic unary
 .sub 'prefix:-' :multi(_)
-    .param num a
+    .param pmc a
 
     neg a
 

Modified: trunk/languages/pipp/src/common/php_array.pir
==============================================================================
--- trunk/languages/pipp/src/common/php_array.pir	(original)
+++ trunk/languages/pipp/src/common/php_array.pir	Mon Dec 29 08:15:40 2008
@@ -61,6 +61,12 @@
     .REGISTER_LONG_CONSTANT(cst, 'COUNT_RECURSIVE', COUNT_RECURSIVE)
 .end
 
+=item C<array array([mixed $...])>
+
+Creates an array
+
+=cut
+
 .sub 'array'
     .param pmc args :slurpy
     .local pmc array, iter
@@ -199,12 +205,34 @@
 
 Create an array containing num elements starting with index start_key each initialized to val
 
-NOT IMPLEMENTED.
-
 =cut
 
 .sub 'array_fill'
-    not_implemented()
+    .param pmc args :slurpy
+    .local pmc array, index, value
+    .local int count
+    array = new 'PhpArray'
+    ($I0, index, count, value) = parse_parameters('llz', args :flat)
+    unless $I0 goto L4
+    unless count >= 0 goto L3
+    #set start index then continue from 0
+    unless index < 0 goto L1
+    array[index] = value
+    index = 0
+    $I0 = 1
+    goto L2
+  L1:
+    $I0 = 0
+  L2:
+    inc $I0
+    unless $I0 <= count goto L4
+    array[index] = value
+    inc index
+    goto L2
+  L3:
+    error(E_WARNING, "Warning: array_fill(): Number of elements must be positive")
+  L4:
+    .return(array)
 .end
 
 =item C<array array_fill_keys(array keys, mixed val)>

Modified: trunk/languages/pipp/t/in_php/array.t
==============================================================================
--- trunk/languages/pipp/t/in_php/array.t	(original)
+++ trunk/languages/pipp/t/in_php/array.t	Mon Dec 29 08:15:40 2008
@@ -27,7 +27,7 @@
 
 require_once 'Test.php';
 
-plan(11);
+plan(8);
 $count = 1;
 
 $hello['world'] = 'hi';
@@ -61,18 +61,5 @@
 is( count($thrice), 2, 'count of $thrice', $count );
 $count++;
 
-#test array() function
-
-$arrayfunc = array(0, "key" => "key", 1);
-
-is( $arrayfunc[0], 0, 'arrayfunc[0]', $count );
-$count++;
-is( $arrayfunc[1], 1, 'arrayfunc[1]', $count );
-$count++;
-is( $arrayfunc["key"], 'key', 'arrayfunc[key]', $count );
-$count++;
-
-
-
 # vim: expandtab shiftwidth=4 ft=php:
 ?>

Added: trunk/languages/pipp/t/php/array.t
==============================================================================
--- (empty file)
+++ trunk/languages/pipp/t/php/array.t	Mon Dec 29 08:15:40 2008
@@ -0,0 +1,71 @@
+# Copyright (C) 2008, The Perl Foundation.
+
+=head1 NAME
+
+t/php/array.t - test array functions
+
+=head1 SYNOPSIS
+
+    % perl t/harness t/php/array.t
+
+=head1 DESCRIPTION
+
+Tests array functions
+
+See L<http://www.php.net/manual/en/ref.array.php>
+
+=cut
+
+use strict;
+use warnings;
+use FindBin;
+use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
+
+use Parrot::Test tests => 3;
+
+language_output_is( 'Pipp', <<'CODE', <<'OUT', 'Instantiate array with array() function' );
+<?php
+$arrayfunc = array(0, "key" => "key", 1);
+echo $arrayfunc[0], "\n";
+echo $arrayfunc[1], "\n";
+echo $arrayfunc["key"], "\n";
+CODE
+0
+1
+key
+OUT
+
+language_output_is( 'Pipp', <<'CODE', <<'OUT', 'Fill array starting with positive index' );
+<?php
+$array = array_fill(2, 2, 'test-val');
+echo $array[1], "\n";
+echo $array[2], "\n";
+echo $array[3], "\n";
+echo $array[4], "\n";
+CODE
+
+test-val
+test-val
+
+OUT
+
+language_output_is( 'Pipp', <<'CODE', <<'OUT', 'Fill array starting at negative index' );
+<?php
+$array = array_fill(-2, 2, 'test-val');
+echo $array[-2], "\n";
+echo $array[-1], "\n";
+echo $array[0], "\n";
+echo $array[1], "\n";
+CODE
+test-val
+
+test-val
+
+OUT
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About