Author: bernhard
Date: Fri Nov 28 06:32:36 2008
New Revision: 33309
Modified:
trunk/languages/pipp/src/common/php_API.pir
trunk/languages/pipp/src/common/php_builtin.pir
trunk/languages/pipp/src/common/php_info.pir
trunk/languages/pipp/t/php/constant.t
trunk/languages/pipp/t/php/null.t
Log:
[Pipp] Start with implementation of error_reporting()
Register the constant NULL.
Add a TODO test, for redefinition of a constant.
Modified: trunk/languages/pipp/src/common/php_API.pir
==============================================================================
--- trunk/languages/pipp/src/common/php_API.pir (original)
+++ trunk/languages/pipp/src/common/php_API.pir Fri Nov 28 06:32:36 2008
@@ -16,9 +16,23 @@
.include 'languages/pipp/src/common/php_MACRO.pir'
.sub '__onload' :anon :load :init
+
# symbol table for constants
new $P0, 'Hash'
set_hll_global 'php_constants', $P0
+
+ # set up error codes
+ .local pmc cst
+ .GET_CONSTANTS(cst)
+ .REGISTER_LONG_CONSTANT(cst, 'E_ERROR', E_ERROR)
+ .REGISTER_LONG_CONSTANT(cst, 'E_WARNING', E_WARNING)
+ .REGISTER_LONG_CONSTANT(cst, 'E_CORE', E_CORE)
+
+ # set up default error_reporting
+ $P1 = new 'PhpInteger'
+ $I1 = E_ERROR | E_WARNING
+ $P1 = $I1
+ error_reporting( $P1 )
.end
=item C<error>
@@ -28,10 +42,18 @@
.sub 'error'
.param int level
.param pmc args :slurpy
- .local string msg
- msg = join '', args
- msg .= "\n"
- printerr msg
+
+ ($P0) = error_reporting()
+ $P1 = new 'PhpInteger'
+ $P1 = level
+ $P2 = $P0 & $P1 # check the mask for error reporting
+ unless $P2 goto L1
+ .local string msg
+ msg = join '', args
+ msg .= "\n"
+
+ printerr msg
+ L1: # print no message
.end
@@ -42,6 +64,7 @@
.sub 'fetch_resource'
.param pmc val
.param string type
+
$I0 = isa val, 'PhpResource'
if $I0 goto L1
$P0 = getinterp
@@ -71,6 +94,7 @@
.sub 'get_module_version'
.param string ext
+
.return ('')
.end
@@ -82,8 +106,9 @@
=cut
.sub 'parse_parameters'
- .param string fmt
- .param pmc args :slurpy
+ .param string fmt
+ .param pmc args :slurpy
+
.local int num_args
.local int min_num_args
.local int max_num_args
Modified: trunk/languages/pipp/src/common/php_builtin.pir
==============================================================================
--- trunk/languages/pipp/src/common/php_builtin.pir (original)
+++ trunk/languages/pipp/src/common/php_builtin.pir Fri Nov 28 06:32:36 2008
@@ -168,7 +168,15 @@
=cut
.sub 'error_reporting'
- .RETURN_LONG(0)
+ .param pmc level :optional
+ .param int has_level :opt_flag
+
+ unless has_level goto L1
+ set_hll_global 'php_errorreporting', level
+ L1:
+ get_hll_global $P0, 'php_errorreporting'
+
+ .return($P0)
.end
=item C<bool extension_loaded(string extension_name)>
Modified: trunk/languages/pipp/src/common/php_info.pir
==============================================================================
--- trunk/languages/pipp/src/common/php_info.pir (original)
+++ trunk/languages/pipp/src/common/php_info.pir Fri Nov 28 06:32:36 2008
@@ -35,6 +35,11 @@
.REGISTER_LONG_CONSTANT(cst, 'PHP_ZTS', 0)
.REGISTER_STRING_CONSTANT(cst, 'DEFAULT_INCLUDE_PATH', '.')
+
+ # register NULL
+ new $P0, 'PhpNull'
+ cst['NULL'] = $P0
+
.end
.sub 'logo_guid' :anon
Modified: trunk/languages/pipp/t/php/constant.t
==============================================================================
--- trunk/languages/pipp/t/php/constant.t (original)
+++ trunk/languages/pipp/t/php/constant.t Fri Nov 28 06:32:36 2008
@@ -19,11 +19,10 @@
use strict;
use warnings;
-
use FindBin;
use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
-use Parrot::Test tests => 22;
+use Parrot::Test tests => 23;
use Parrot::Config qw( %PConfig );
language_output_is( 'Pipp', <<'CODE', <<'OUT', 'define() and constant(),
string' );
@@ -180,6 +179,13 @@
echo constant("PHP_ZTS");
CODE
+language_output_like( 'Pipp', <<'CODE', <<'OUT', 'NOT_DEFINED' );
+<?php
+echo constant("NOT_DEFINED");
+CODE
+/Couldn't find constant NOT_DEFINED/
+OUT
+
language_output_is( 'Pipp', <<'CODE', '5', 'PHP_MAJOR_VERSION' );
<?php
echo PHP_MAJOR_VERSION;
Modified: trunk/languages/pipp/t/php/null.t
==============================================================================
--- trunk/languages/pipp/t/php/null.t (original)
+++ trunk/languages/pipp/t/php/null.t Fri Nov 28 06:32:36 2008
@@ -22,7 +22,7 @@
use FindBin;
use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
-use Parrot::Test tests => 1;
+use Parrot::Test tests => 2;
language_output_is( 'Pipp', <<'CODE', <<'OUT', 'Stringification of an
undefined var' );
@@ -33,6 +33,25 @@
OUT
+language_output_is( 'Pipp', <<'CODE', <<'OUT', 'redefinition of NULL', todo =>
'implemented incorrectly' );
+<?php
+error_reporting(E_ERROR);
+echo NULL;
+echo "\n";
+echo constant('NULL');
+echo "\n";
+define('NULL','NULL was redefined' );
+echo NULL;
+echo "\n";
+echo constant('NULL');
+echo "\n";
+CODE
+
+
+
+NULL was redefined
+OUT
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4