-
Notifications
You must be signed in to change notification settings - Fork 135
/
03-past-declarator.t
91 lines (71 loc) · 2.04 KB
/
03-past-declarator.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
#! ./parrot-nqp
# Copyright (C) 2010, Parrot Foundation.
# "Comprehensive" test for creating PAST for op.
# Parse single op and check various aspects of created PAST.
pir::load_bytecode('opsc.pbc');
pir::load_bytecode('dumper.pbc');
Q:PIR{ .include "test_more.pir" };
my $buf := q|
inline op foo(inconst NUM) {
PMC *foo;
foo();
foo(bar);
foo(bar, baz);
if (answer != 42) {
answer = 42;
}
else {
question = "what?";
}
}
|;
my $compiler := pir::compreg__Ps('Ops');
my $past := $compiler.compile($buf, target => 'past');
ok(1, "PAST::Node created");
my $op := @($past<ops>)[0][0];
my $var := $op[0];
ok( $var ~~ PAST::Var, "PAST::Var created" );
ok( $var.isdecl, ".. as declaration" );
is( $var.name, "foo", ".. with proper name" );
is( $var.vivibase, "PMC *", ".. with proper type" );
my $call := $op[1];
ok( $call ~~ PAST::Op, "PAST::op for call created" );
is( $call.pasttype, "call", ".. with pasttype call" );
is( $call.name, "foo", ".. with name 'foo'" );
is( +@($call), 0, ".. with 0 args" );
$call := $op[2];
is( +@($call), 1, ".. with 1 arg" );
$call := $op[3];
is( +@($call), 2, ".. with 2 args" );
my $if := $op[4];
ok( $if ~~ PAST::Op, "PAST::op for if created" );
is( $if.pasttype, "if", ".. with pasttype call" );
is( +@($if), 3, ".. with 3 children" );
# test while pasttype
$buf := q|
inline op bar(out PMC, in INT) {
while (1) {
foo();
}
}|;
$past := $compiler.compile($buf, target => 'past');
$op := $past<ops>[0];
is( $op[0][0]<pasttype>, 'while', "while loop generates right pasttype");
# test for pasttype
$buf := q|
inline op bar(out PMC, in INT) {
for (i = 0; i < 111; quux($2)) {
foo($1);
}
}|;
$past := $compiler.compile($buf, target => 'past');
$op := $past<ops>[0];
is( $op[0][0]<pasttype>, 'for', "for loop generates right pasttype");
done_testing();
# Don't forget to update plan!
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=perl6: