/
oplib.t
143 lines (120 loc) · 3.05 KB
/
oplib.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
#!./parrot
# Copyright (C) 2001-2010, Parrot Foundation.
# $Id$
=head1 NAME
t/pmc/oplib.t - OpLib PMC
=head1 SYNOPSIS
% prove t/pmc/oplib.t
=cut
# Hardcoded assumptions for tests:
# * We have an op called end
# * It has no arguments
# * Is the only member of its familiy
.const string TESTED_OP = 'end'
.const int TESTED_OP_ELEMS = 0
.const int TESTED_OP_FAMILIY_ELEMS = 1
# Never have an op with this name:
.const string TESTED_NOSUCHOP = 'hopeweneverhaveopcodesnamedlikethis'
.include 'except_types.pasm'
.sub main :main
.include 'test_more.pir'
plan(13)
new_oplib()
check_elements()
getint_end()
getint_no_opcode()
getop_end()
family_end()
family_no_opcode()
.end
.sub new_oplib
$P0 = box "core_ops"
$P1 = new ['OpLib'], $P0
$I0 = isnull $P1
nok($I0, "new OpLib")
.end
.sub check_elements
.local pmc oplib, op, eh
.local int n, i
$P0 = box "core_ops"
oplib = new ['OpLib'], $P0
n = elements oplib
i = n - 1
op = oplib[i]
i = isnull op
is(i, 0, 'last opcode exists')
eh = new ['ExceptionHandler']
eh.'handle_types'(.EXCEPTION_OUT_OF_BOUNDS)
set_addr eh, catch
push_eh eh
op = oplib[n]
nok(1, 'out of bounds opcode number should throw')
goto end
catch:
finalize eh
pop_eh
ok(1, 'out of bounds opcode number throws')
end:
.end
.sub getint_end
$P0 = box 'core_ops'
$P0 = new ['OpLib'], $P0
$I1 = $P0[TESTED_OP]
$I0 = isne $I1, -1
ok($I0, "got end opcode")
.end
.sub getint_no_opcode
$P0 = box 'core_ops'
$P0 = new ['OpLib'], $P0
$I1 = $P0[TESTED_NOSUCHOP]
$I0 = iseq $I1, -1
ok($I0, "get non existent opcode fails")
.end
.sub getop_end
.local pmc oplib, op, op2, name
$P0 = box 'core_ops'
oplib = new ['OpLib'], $P0
# Using a string constant
op = oplib[TESTED_OP]
$I0 = isnull op
is($I0, 0, "got end opcode data")
$I0 = elements op
is($I0, TESTED_OP_ELEMS, "the opcode tested has the expected lenght")
# Using a String PMC
name = new ['String']
name = TESTED_OP
op2 = oplib[name]
$I0 = isnull op2
is($I0, 0, "got end opcode data keyed pmc")
$I0 = issame op, op2
$S0 = "Implement cacheing, Opcode.is_same, or change comparison"
todo($I0, "got same result from both ways", $S0)
$I1 = op
$I0 = oplib[TESTED_OP]
is($I0, $I1, 'opcode number from Opcode and from OpLib is the same')
$S0 = op
is($S0, TESTED_OP, 'name from Opcode matches name searched for')
.end
.sub family_end
$P0 = box 'core_ops'
$P0 = new ['OpLib'], $P0
$P1 = $P0.'op_family'(TESTED_OP)
$I0 = isnull $P1
dec $I0
unless $I0 goto done
$I0 = elements $P1
done:
is($I0, TESTED_OP_FAMILIY_ELEMS, "'end' family is not null and has 1 element")
.end
.sub family_no_opcode
$P0 = box 'core_ops'
$P0 = new ['OpLib'], $P0
$P1 = $P0.'op_family'(TESTED_NOSUCHOP)
$I0 = isnull $P1
ok($I0, "non existent opcode family is null")
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: