Skip to content

Commit

Permalink
[imcc] fix -d8 dump_instructions, fix double unescaping
Browse files Browse the repository at this point in the history
string_from_reg may not unescape the const again. fixes t/op/basic_6.pasm
change t/op/basic_9.pasm to catch the new Unknown escape sequence \i in Parrot fl\ies
  • Loading branch information
Reini Urban committed Oct 15, 2014
1 parent 257b033 commit 3096f88
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
4 changes: 2 additions & 2 deletions compilers/imcc/debug.c
Expand Up @@ -299,7 +299,7 @@ dump_instructions(ARGMOD(imc_info_t * imcc), ARGIN(const IMC_Unit *unit))
Parrot_io_eprintf(imcc->interp,
"%4i %4d %4d %4d\t%x\t%8x %4d %4d %4d ",
ins->index, ins->line, bb->index, bb->loop_depth,
ins->flags, ins->type, ins->op ? OP_INFO_OPNUM(ins->op) : 0,
ins->flags, ins->type, ins->op ? OP_INFO_OPNUM(ins->op):0,
ins->opsize, pc);
}
else {
Expand All @@ -318,7 +318,7 @@ dump_instructions(ARGMOD(imc_info_t * imcc), ARGIN(const IMC_Unit *unit))
=item C<void dump_cfg(const IMC_Unit *unit)>
Dumps the current IMCC config data, with -d10.
Dumps the current IMCC config data, with -d10
=cut
Expand Down
25 changes: 16 additions & 9 deletions compilers/imcc/pbc.c
Expand Up @@ -1058,7 +1058,7 @@ IMCC_string_from_reg(ARGMOD(imc_info_t * imcc), ARGIN(SymReg *r))
if (Interp_trace_TEST(imcc->interp, 8))
fprintf(stderr, "# string_from_reg '%s'\n", buf);
if (!p) {
r->type -= VT_ENCODED; /* FIXME! Whose fault is this? */
r->type -= VT_ENCODED; /* FIXME! Whose fault is this? fixup_globals */
goto bare;
}
PARROT_ASSERT(p && p[-1] == ':');
Expand All @@ -1071,22 +1071,28 @@ IMCC_string_from_reg(ARGMOD(imc_info_t * imcc), ARGIN(SymReg *r))

return Parrot_str_unescape(imcc->interp, p+1, '"', encoding_name);
}
#if 0
/* mk_const already stripped the quotes.
don't strip valid quotes from the string again. t/op/basic_6.pasm */
else if (*buf == '"') {
buf++;
return *buf
? Parrot_str_unescape(imcc->interp, buf, '"', NULL)
: Parrot_str_new_init(imcc->interp, "", 0,
Parrot_ascii_encoding_ptr, PObj_constant_FLAG);
: STRINGNULL; //Parrot_str_new_init(imcc->interp, "", 0,
//Parrot_ascii_encoding_ptr, PObj_constant_FLAG);
}
else if (*buf == '\'') {
buf++;
return Parrot_str_new_init(imcc->interp, buf, *buf ? strlen(buf) - 1 : 0,
Parrot_ascii_encoding_ptr, PObj_constant_FLAG);
return *buf ? Parrot_str_new_init(imcc->interp, buf, strlen(buf) - 1,
Parrot_ascii_encoding_ptr, PObj_constant_FLAG)
: STRINGNULL;
}
#endif
bare:
/* unquoted bare name - ASCII only don't unescape it */
return Parrot_str_new_init(imcc->interp, buf, *buf ? strlen(buf) : 0,
Parrot_ascii_encoding_ptr, PObj_constant_FLAG);
return *buf ? Parrot_str_new_init(imcc->interp, buf, strlen(buf),
Parrot_ascii_encoding_ptr, PObj_constant_FLAG)
: STRINGNULL;
}

/*
Expand Down Expand Up @@ -1134,8 +1140,9 @@ IMCC_string_from__STRINGC(ARGMOD(imc_info_t * imcc), ARGIN(char *buf))
}
else if (*buf == '\'') {
buf++;
return Parrot_str_new_init(imcc->interp, buf, *buf ? strlen(buf) - 1 : 0,
Parrot_ascii_encoding_ptr, PObj_constant_FLAG);
return *buf ? Parrot_str_new_init(imcc->interp, buf, strlen(buf) - 1,
Parrot_ascii_encoding_ptr, PObj_constant_FLAG)
: STRINGNULL;
}
else {
IMCC_fataly(imcc, EXCEPTION_SYNTAX_ERROR,
Expand Down
3 changes: 2 additions & 1 deletion compilers/imcc/symreg.c
Expand Up @@ -833,7 +833,7 @@ int_overflows(ARGIN(const SymReg *r))
=item C<SymReg * mk_const(imc_info_t * imcc, const char *name, int t)>
Makes a new constant (and populates the cache of global symbols).
Makes a new constant and populates the cache of global symbols.
=cut
Expand Down Expand Up @@ -913,6 +913,7 @@ add_ns(ARGMOD(imc_info_t * imcc), ARGIN(const char *name))
strcat(ns_name, "@@@");
strcat(ns_name, name);

/* Note that only double-quotes are detected here */
p = strstr(ns_name, "\";\""); /* Foo";"Bar -> Foo@@@Bar */

while (p) {
Expand Down
4 changes: 2 additions & 2 deletions t/op/basic.t
@@ -1,5 +1,5 @@
#!perl
# Copyright (C) 2001-2014, Parrot Foundation.
# Copyright (C) 2001-2007,2014, Parrot Foundation.

use strict;
use warnings;
Expand Down Expand Up @@ -76,7 +76,7 @@ pasm_error_output_is( <<'CODE', qq(Illegal escape sequence \\i in 'Parrot fl\\ie
end
CODE

pasm_output_is( <<'CODE', <<OUTPUT, "print string with embedded newline" );
pasm_output_is( <<'CODE', <<OUTPUT, "print string with embedded newline, known escape" );
.pcc_sub :main main:
print "Parrot flies\n"
end
Expand Down

0 comments on commit 3096f88

Please sign in to comment.