/
dynlexpad.t
205 lines (184 loc) · 3.34 KB
/
dynlexpad.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#! perl
# Copyright (C) 2005, The Perl Foundation.
# $Id$
use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
use Parrot::Test tests => 6;
use Parrot::Config;
=head1 NAME
t/dynpmc/dynlexpad.t - test the DynLexPad PMC
=head1 SYNOPSIS
% prove t/dynpmc/dynlexpad.t
=head1 DESCRIPTION
Tests the C<DynLexPad> PMC.
=cut
pir_output_is(<< 'CODE', << 'OUTPUT', "loadlib");
.sub main :main
.local pmc lib
lib = loadlib "dynlexpad"
unless lib goto not_loaded
print "ok\n"
end
not_loaded:
print "not loaded\n"
.end
CODE
ok
OUTPUT
my $loadlib = <<'EOC';
#
# the .loadlib directive gets run, before the .HLL_map below
# is parsed, therefore the .DynLexPad constant is already
# available
#
.loadlib "dynlexpad"
.HLL "Some", "dynlexpad"
.HLL_map .LexPad, .DynLexPad
EOC
pir_output_is($loadlib . << 'CODE', << 'OUTPUT', "store_lex");
# see loadlib
.sub 'test' :main
foo()
.end
.sub foo :lex
$P1 = new .Integer
$P1 = 13013
store_lex 'a', $P1
print "ok 1\n"
$P2 = find_lex 'a'
print "ok 2\n"
print $P2
print "\n"
end
.end
CODE
ok 1
ok 2
13013
OUTPUT
pir_output_is($loadlib . << 'CODE', << 'OUTPUT', "check :outer");
.sub 'test' :main
foo()
.end
.sub foo :lex
$P1 = new .Integer
$P1 = 13013
store_lex 'a', $P1
$P2 = find_lex 'a'
print $P2
print "\n"
.const .Sub bar_sub = "bar"
$P0 = newclosure bar_sub
$P0()
.end
.sub bar :outer(foo)
.const .Sub baz_sub = "baz"
$P0 = newclosure baz_sub
$P0()
.end
.sub baz :lex :outer(bar)
$P1 = find_lex 'a'
print $P1
print "\n"
.end
CODE
13013
13013
OUTPUT
pir_output_is($loadlib . << 'CODE', << 'OUTPUT', "tcl-ish upvar");
.sub 'test' :main
foo()
.end
.sub foo :lex
$P1 = new .Integer
$P1 = 13013
store_lex 'a', $P1
$P2 = find_lex 'a'
print $P2
print "\n"
.const .Sub bar_sub = "bar"
$P0 = newclosure bar_sub
$P0()
# check the upvar
$P2 = find_lex 'b'
print $P2
print "\n"
.end
.sub bar :outer(foo)
.const .Sub baz_sub = "baz"
$P0 = newclosure baz_sub
$P0()
.end
.sub baz :lex :outer(bar)
$P1 = find_lex 'a'
print $P1
print "\n"
# upvar 2 'b', 55
.local pmc pad, interp
interp = getinterp
pad = interp["lexpad"; 2]
$P2 = new .Integer
$P2 = 55
pad['b'] = $P2
.return()
err:
print "outer not found\n"
.end
CODE
13013
13013
55
OUTPUT
pir_output_is($loadlib . << 'CODE', << 'OUTPUT', "check that dynlexpad honors hll");
.sub 'test' :main
foo()
bar()
.end
.sub foo :lex
.local pmc pad, interp
interp = getinterp
pad = interp["lexpad"]
$S0 = typeof pad
print $S0
print "\n"
.end
.HLL "parrot",""
.sub bar :lex
.local pmc pad, interp
interp = getinterp
pad = interp["lexpad"]
$S0 = typeof pad
print $S0
print "\n"
.end
CODE
DynLexPad
LexPad
OUTPUT
pir_output_is($loadlib . << 'CODE', << 'OUTPUT', "dynlexpad - lexpad interop");
.sub 'test' :main
foo()
.end
.sub foo
.lex 'a', $P0 # statix lexical
$P0 = new .String
$P0 = "ok 1\n"
$P1 = find_lex 'a'
print $P1
$P2 = new .String
$P2 = "ok 2\n"
store_lex 'a', $P2
print $P0 # sic!
$P3 = new .String
$P3 = "ok 3\n"
store_lex 'b', $P3 # and a dynamic one
$P4 = find_lex 'b'
print $P4
.end
CODE
ok 1
ok 2
ok 3
OUTPUT