Skip to content

Commit

Permalink
[test] Added LexInfo.declare_lex_preg and more imcc/syn/clash.t tests
Browse files Browse the repository at this point in the history
For GH #1095

global names do work fine, only lexicals not.
Note I do not know how to reliable get the correct target register index for
declare_lex_preg in pure pir, and how to initialize it.
Setting it crashes the ctx.
  • Loading branch information
Reini Urban committed Oct 8, 2014
1 parent 2947443 commit 234386d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -17,6 +17,7 @@
- Tests
+ Run fulltests with the runcore=fast,-O1,-O2 fast, without -D040, --gc-debug
[GH #1086]
+ Added tests for LexInfo.declare_lex_preg and .lex quoting roundtrips [GH #1095]
+ Simplify smolder resend usage
+ Fix mingw issues with \r\n
- Community
Expand Down
5 changes: 3 additions & 2 deletions src/pmc/lexinfo.pmc
Expand Up @@ -58,8 +58,9 @@ The C<sub> argument is currently ignored.

=item C<void declare_lex_preg(STRING *name, INTVAL preg)>

Declare a lexical variable that is an alias for a PMC register. The PIR
compiler calls this method in response to a ".lex STRING, PREG" directive.
Declare a lexical variable that is an alias for a PMC register. This is
the dynamic version of a ".lex STRING, PREG" directive.
Note that the second argument is just an integer, i.e. C<0> for C<$P0>.

=cut

Expand Down
30 changes: 28 additions & 2 deletions t/compilers/imcc/syn/clash.t
Expand Up @@ -7,7 +7,7 @@ use lib qw( . lib ../lib ../../lib );

use Test::More;
use Parrot::Config;
use Parrot::Test tests => 14;
use Parrot::Test tests => 15;

pir_output_is( <<'CODE', <<'OUT', "if/unless" );
.sub test :main
Expand Down Expand Up @@ -233,7 +233,7 @@ CODE
OUT

# perl6 has a similar issue but there testcase 2 failed. RT #116643
pir_output_is( <<'CODE', <<'OUT', 'double-quoted .lex names', todo => 'GH #1095');
pir_output_is( <<'CODE', <<'OUT', 'single+double double-quoted .lex names', todo => 'GH #1095');
.sub 'main' :main
.lex 'bar\o', $P0
$P1 = box 'ok 1'
Expand All @@ -259,6 +259,32 @@ ok 2
ok 3
OUT

pir_output_is( <<'CODE', <<'OUT', 'single+double quoted global names');
.sub 'main' :main
$S0 = 'bar\o'
$P1 = box 'ok 1'
set_global $S0, $P1
$P2 = get_global 'bar\o'
say $P2
$S1 = "foo\\o"
$P1 = box 'ok 2'
set_global "foo\\o", $P1
$P2 = get_global "foo\\o"
say $P2
$S2 = "foo\o"
$P1 = box 'ok 3'
set_global "foo\o", $P1
$P2 = get_global "foo\o"
say $P2
.end
CODE
ok 1
ok 2
ok 3
OUT

# Local Variables:
# mode: cperl
# cperl-indent-level: 4
Expand Down
27 changes: 25 additions & 2 deletions t/pmc/lexinfo.t
@@ -1,5 +1,5 @@
#!./parrot
# Copyright (C) 2006-2010, Parrot Foundation.
# Copyright (C) 2006-2014 Parrot Foundation.

=head1 NAME

Expand All @@ -20,10 +20,11 @@ Tests the LexInfo PMC.

.sub main :main
.include 'test_more.pir'
plan(4)
plan(6)

inspect_test()
inspect_invalid_test()
declare_lex_preg_test()
.end

.sub inspect_test
Expand Down Expand Up @@ -76,6 +77,28 @@ Tests the LexInfo PMC.
ok(r, 'invalid introspection key throws as expected')
.end

.sub declare_lex_preg_test
.local pmc li, in, ex, pad
li = new ['LexInfo']
pad = new ['LexPad'], li

$S0 = "$foo"
# dynamic version of .lex "$foo", $P4
li.'declare_lex_preg'($S0, 4)

in = inspect li, 'symbols'
$I0 = elements in
is($I0, 1, "one lex stored in lex hash")

$S1 = in[0]
is($S1, "$foo", "and it is $foo")

# But this does not work yet
#$P4 = box 'pants'
#$P1 = pad["$foo"]
#is($P1, "pants", "changed the lex value")
.end

# Local Variables:
# mode: pir
# fill-column: 100
Expand Down

0 comments on commit 234386d

Please sign in to comment.