Skip to content

Commit

Permalink
PCT: PAST.Compiler.escape in Winxed
Browse files Browse the repository at this point in the history
  • Loading branch information
Benabik committed Apr 26, 2012
1 parent b23a097 commit 0dd4cbb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
23 changes: 0 additions & 23 deletions compilers/pct/src/PAST/Compiler.pir
Expand Up @@ -24,29 +24,6 @@ PAST::Compiler - PAST Compiler

.namespace [ 'PAST';'Compiler' ]

=item escape(str)

Return C<str> as a PIR constant string.

=cut

.sub 'escape' :method
.param string str
.local string estr
estr = escape str
$I0 = index estr, "\\x"
if $I0 >= 0 goto unicode_prefix
$I0 = index estr, "\\u"
if $I0 >= 0 goto unicode_prefix
estr = concat '"', estr
goto done
unicode_prefix:
estr = concat 'unicode:"', estr
done:
estr = concat estr, '"'
.return (estr)
.end

=item unique([STR fmt])

Generate a unique number that can be used as an identifier.
Expand Down
21 changes: 21 additions & 0 deletions compilers/pct/src/PAST/Compiler.winxed
Expand Up @@ -211,6 +211,27 @@ Compile the abstract syntax tree given by C<past> into POST.
var ret = self.as_post(past, 'v':[named('rtype')]);
return ret;
}

/*
=item escape(str)

Return C<str> as a PIR constant string.

=cut

*/

function escape[method](string str) {
string estr = Winxed_Builtins.escape(str);
if (indexof(estr, "\\x") >= 0 || indexof(estr, "\\u") >= 0)
estr = 'unicode:"' + estr;
else
estr = '"' + estr;
estr += '"';
return estr;
}


}

/*
Expand Down

0 comments on commit 0dd4cbb

Please sign in to comment.