Author: leo
Date: Sat Apr 16 05:16:46 2005
New Revision: 7852
Modified:
trunk/imcc/symreg.c
trunk/imcc/t/syn/const.t
trunk/src/string.c
Log:
resolve #34984; return binary, if one string is binary
Modified: trunk/imcc/symreg.c
==============================================================================
--- trunk/imcc/symreg.c (original)
+++ trunk/imcc/symreg.c Sat Apr 16 05:16:46 2005
@@ -307,6 +307,7 @@
INS(interp, unit, "set_p_pc", "", r, 2, 0, 1);
return NULL;
}
+
/* Makes a new identifier constant with value val */
SymReg *
mk_const_ident(Interp *interp,
@@ -314,6 +315,19 @@
{
SymReg *r;
+ /*
+ * Forbid assigning a string to anything other than a string
+ * or PMC constant
+ */
+ if (t == 'N' || t == 'I') {
+ if (val->set == 'S') {
+ IMCC_fataly(interp, E_TypeError,
+ "bad const initialisation");
+ }
+ /* Cast value to const type */
+ val->set = t;
+ }
+
if (global) {
if (t == 'P') {
IMCC_fataly(interp, E_SyntaxError,
Modified: trunk/imcc/t/syn/const.t
==============================================================================
--- trunk/imcc/t/syn/const.t (original)
+++ trunk/imcc/t/syn/const.t Sat Apr 16 05:16:46 2005
@@ -3,7 +3,7 @@
# $Id$
use strict;
-use Parrot::Test tests => 7;
+use Parrot::Test tests => 9;
pir_output_is(<<'CODE', <<'OUT', "globalconst 1");
@@ -148,3 +148,37 @@
ok 2
ok 3
OUT
+
+output_is(<<'CODE', <<'OUT', "const I/N mismatch");
+ set I0, 2.0
+ print I0
+ print "\n"
+ set N0, 2
+ print N0
+ print "\nok\n"
+ end
+CODE
+2
+2.000000
+ok
+OUT
+
+pir_output_is(<<'CODE', <<'OUT', "const I/N mismatch 2");
+.sub main
+ .const int i = 2.0
+ print i
+ print "\n"
+ .const float n = 2
+ print n
+ print "\nok\n"
+ .const string s = ascii:"ok 2\n"
+ print s
+ end
+.end
+CODE
+2
+2.000000
+ok
+ok 2
+OUT
+
Modified: trunk/src/string.c
==============================================================================
--- trunk/src/string.c (original)
+++ trunk/src/string.c Sat Apr 16 05:16:46 2005
@@ -413,6 +413,10 @@
return a->charset;
if (a->charset == Parrot_ascii_charset_ptr)
return b->charset;
+ if (a->charset == Parrot_binary_charset_ptr)
+ return a->charset;
+ if (b->charset == Parrot_binary_charset_ptr)
+ return b->charset;
return NULL;
}