Author: kjs
Date: Sat Jan 3 04:27:51 2009
New Revision: 34872
Modified:
trunk/compilers/pirc/new/bcgen.c
trunk/compilers/pirc/new/bcgen.h
trunk/compilers/pirc/new/pir.l
trunk/compilers/pirc/new/pircompunit.h
trunk/compilers/pirc/new/piremit.c
Log:
[pirc] add unicode string handling in bcgen and emitter.
Modified: trunk/compilers/pirc/new/bcgen.c
==============================================================================
--- trunk/compilers/pirc/new/bcgen.c (original)
+++ trunk/compilers/pirc/new/bcgen.c Sat Jan 3 04:27:51 2009
@@ -163,19 +163,16 @@
Add the string constant C<str> to the constant table. This function
returns the index in the constant table where C<str> is stored.
-XXX what to do with encoding-thingy "ascii"? Probably should be an extra
parameter?
-Or should it be a STRING at this point already?
-
=cut
*/
int
-add_string_const(bytecode * const bc, char const * const str) {
+add_string_const(bytecode * const bc, char const * const str, char const *
charset) {
int index = new_pbc_const(bc);
PackFile_Constant *constant =
bc->interp->code->const_table->constants[index];
constant->type = PFC_STRING;
- constant->u.string = string_make(bc->interp, str, strlen(str), "ascii",
PObj_constant_FLAG);
+ constant->u.string = string_make(bc->interp, str, strlen(str), charset,
PObj_constant_FLAG);
return index;
}
@@ -463,7 +460,7 @@
*/
static STRING *
add_string_const_from_cstring(bytecode * const bc, char const * const str) {
- int index = add_string_const(bc, str);
+ int index = add_string_const(bc, str, "ascii");
return bc->interp->code->const_table->constants[index]->u.string;
}
@@ -747,7 +744,7 @@
sub_pmc = create_sub_pmc(bc, info->iscoroutine,
info->instanceof);
sub = PMC_sub(sub_pmc);
- subname_index = add_string_const(bc, info->subname);
+ subname_index = add_string_const(bc, info->subname, "ascii");
subname_const =
bc->interp->code->const_table->constants[subname_index];
/* set start and end offset of this sub in the bytecode.
Modified: trunk/compilers/pirc/new/bcgen.h
==============================================================================
--- trunk/compilers/pirc/new/bcgen.h (original)
+++ trunk/compilers/pirc/new/bcgen.h Sat Jan 3 04:27:51 2009
@@ -106,7 +106,7 @@
int add_num_const(bytecode * const bc, double f);
-int add_string_const(bytecode * const bc, char const * const str);
+int add_string_const(bytecode * const bc, char const * const str, char const *
charset);
int add_pmc_const(bytecode * const bc, PMC * pmc) ;
Modified: trunk/compilers/pirc/new/pir.l
==============================================================================
--- trunk/compilers/pirc/new/pir.l (original)
+++ trunk/compilers/pirc/new/pir.l Sat Jan 3 04:27:51 2009
@@ -409,7 +409,7 @@
ustr->encoding = NULL;
- fprintf(stderr, "ucstring: [%s]:[%s]\n", ustr->charset,
ustr->contents);
+ /* fprintf(stderr, "ucstring: [%s]:[%s]\n", ustr->charset,
ustr->contents); */
yylval->ustr = ustr;
return TK_USTRINGC;
@@ -437,7 +437,7 @@
*
/* copy the encoding part */
- ustr->encoding = dupstrn(lexer, yytext, colon1 -
yytext);
+ ustr->encoding = dupstrn(lexer, yytext, colon1 - yytext);
/* look for the second colon after this one */
colon2 = strchr(colon1 + 1, ':');
Modified: trunk/compilers/pirc/new/pircompunit.h
==============================================================================
--- trunk/compilers/pirc/new/pircompunit.h (original)
+++ trunk/compilers/pirc/new/pircompunit.h Sat Jan 3 04:27:51 2009
@@ -119,10 +119,12 @@
#define NOT(X) !(X)
-/* selector for the value union. Use explicit values to distinguish them
+/* Selectors for the value union. Use explicit values to distinguish them
* from the pir_type enumeration, this makes it easier to find bugs, where
* a pir_type value is used where a value_type should be used. These
- * value_types continue where pir_type values end.
+ * value_types continue where pir_type values end, as value_types are used
+ * for indexing the same array containing signature characters (for
+ * calculating full-signatured ops, such as set_i_ic).
*/
typedef enum value_types {
INT_VAL = 5,
Modified: trunk/compilers/pirc/new/piremit.c
==============================================================================
--- trunk/compilers/pirc/new/piremit.c (original)
+++ trunk/compilers/pirc/new/piremit.c Sat Jan 3 04:27:51 2009
@@ -474,8 +474,7 @@
break;
}
case STRING_VAL: {
- int index = add_string_const(lexer->bc, c->val.sval);
- fprintf(stderr, "index of string const: %d\n", index);
+ int index = add_string_const(lexer->bc, c->val.sval, "ascii");
emit_int_arg(lexer->bc, index);
break;
}
@@ -492,9 +491,11 @@
fprintf(stderr, "emit_pbc_const_arg: pmc type\n");
break;
}
- case USTRING_VAL:
- /* XXX */
+ case USTRING_VAL: {
+ int index = add_string_const(lexer->bc, c->val.ustr->contents,
c->val.ustr->charset);
+ emit_int_arg(lexer->bc, index);
break;
+ }
default:
break;
}
@@ -569,7 +570,7 @@
break;
case STRING_VAL:
*pc++ = PARROT_ARG_SC;
- *pc++ = add_string_const(lexer->bc, c->val.sval);
+ *pc++ = add_string_const(lexer->bc, c->val.sval,
"ascii");
break;
default:
panic(lexer, "wrong type of key");