[svn:parrot] r46906 - in trunk: compilers/imcc t/compilers/imcc/syn
plobsing at svn.parrot.org
plobsing at svn.parrot.org
Sun May 23 03:48:41 UTC 2010
Author: plobsing
Date: Sun May 23 03:48:40 2010
New Revision: 46906
URL: https://trac.parrot.org/parrot/changeset/46906
Log:
properly expand symbolic constants in constant propagation (TT #1652)
Modified:
trunk/compilers/imcc/optimizer.c
trunk/t/compilers/imcc/syn/regressions.t
Modified: trunk/compilers/imcc/optimizer.c
==============================================================================
--- trunk/compilers/imcc/optimizer.c Sun May 23 03:12:08 2010 (r46905)
+++ trunk/compilers/imcc/optimizer.c Sun May 23 03:48:40 2010 (r46906)
@@ -824,18 +824,19 @@
case PARROT_ARG_S:
eval[i + 1] = i; /* regs used are I0, I1, I2 */
if (ops <= 2 || i) { /* fill source regs */
+ SymReg *r_ = r[i]->type & VT_CONSTP ? r[i]->reg : r[i];
switch (r[i]->set) {
case 'I':
- REG_INT(interp, i) = IMCC_int_from_reg(interp, r[i]);
+ REG_INT(interp, i) = IMCC_int_from_reg(interp, r_);
break;
case 'N':
{
- STRING * const s = Parrot_str_new(interp, r[i]->name, 0);
+ STRING * const s = Parrot_str_new(interp, r_->name, 0);
REG_NUM(interp, i) = Parrot_str_to_num(interp, s);
}
break;
case 'S':
- REG_STR(interp, i) = IMCC_string_from_reg(interp, r[i]);
+ REG_STR(interp, i) = IMCC_string_from_reg(interp, r_);
break;
default:
break;
Modified: trunk/t/compilers/imcc/syn/regressions.t
==============================================================================
--- trunk/t/compilers/imcc/syn/regressions.t Sun May 23 03:12:08 2010 (r46905)
+++ trunk/t/compilers/imcc/syn/regressions.t Sun May 23 03:48:40 2010 (r46906)
@@ -6,7 +6,7 @@
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 21;
+use Parrot::Test tests => 22;
pir_error_output_like( <<'CODE', <<'OUT', 'invalid get_results syntax');
.sub main :main
@@ -37,6 +37,33 @@
ok 2 - caught div_n_nc_nc exception
OUT
+pir_output_is( <<'CODE', <<'OUT', 'fold symbolic constants (TT #1652)');
+.sub main :main
+ .const int SECONDS_PER_MINUTE = 60
+ $I0 = 30 * SECONDS_PER_MINUTE
+ say $I0
+
+ .const num DAYS_PER_YEAR = 365.24e0
+ $N0 = DAYS_PER_YEAR * 2.96460137564761618e-03
+ 'printf'("%f\n", $N0)
+
+ .const string HI = "Hello "
+ $S0 = concat HI, "World!"
+ say $S0
+.end
+
+.sub 'printf'
+ .param string fmt
+ .param pmc data :slurpy
+ $S0 = sprintf fmt, data
+ print $S0
+.end
+CODE
+1800
+1.082791
+Hello World!
+OUT
+
pir_output_is( <<'CODE', <<'OUT', 'comments before .param(TT #1035)');
.sub main :main
comments(1,2)
More information about the parrot-commits
mailing list