-
Notifications
You must be signed in to change notification settings - Fork 131
/
qast.t
74 lines (65 loc) · 1.42 KB
/
qast.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
use QRegex;
plan(5);
sub compile_qast($qast) {
my $post := QAST::Compiler.as_post($qast);
my $pir := QAST::Compiler.pir($post);
QAST::Compiler.evalpmc($pir);
}
sub is_qast($qast, $value, $desc) {
try {
my $code := compile_qast($qast);
ok($code() eq $value, $desc);
CATCH { ok(0, $desc) }
}
}
is_qast(
QAST::Block.new(
QAST::IVal.new( :value(42) )
),
42,
'IVal node');
is_qast(
QAST::Block.new(
QAST::NVal.new( :value(6.9) )
),
6.9,
'NVal node');
is_qast(
QAST::Block.new(
QAST::SVal.new( :value('Gorillas just love pizza') )
),
'Gorillas just love pizza',
'SVal node');
is_qast(
QAST::Block.new(
QAST::Op.new(
:op('add_i'),
QAST::IVal.new(:value(10)),
QAST::IVal.new(:value(95))
)
),
105,
'add_i operation with two IVal nodes');
is_qast(
QAST::Block.new(
QAST::Op.new(
:op('add_i'),
QAST::IVal.new(:value(10)),
QAST::Op.new(
:op('add_i'),
QAST::IVal.new(:value(20)),
QAST::IVal.new(:value(30))
)
)
),
60,
'an add_i op inside an add_i op');
is_qast(
QAST::Block.new(
QAST::Op.new(
:op('neg_i'),
QAST::IVal.new(:value(206))
)
),
-206,
'neg_i operation with one IVal node');