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
|
#! parrot
# Copyright (C) 2009, Parrot Foundation.
# Common functions for various Packfile* PMCs tests.
# Return test filename
# Currently parrot doesn't support system independent PBCs. So, cross your
# fingers and try different filename for binary-dependent tests...
.sub '_filename'
.local string filename
filename = 't/pmc/testlib/number.pbc'
.return (filename)
.end
# common pbc loading function
.sub '_pbc'
.include "stat.pasm"
.include "interpinfo.pasm"
.local pmc pf, pio
pf = new ['Packfile']
$S0 = '_filename'()
pio = new ['FileHandle']
pio.'open'($S0, 'rb')
$S0 = pio.'readall'()
pio.'close'()
pf = $S0
.return(pf)
.end
.sub '_find_segment_by_type'
.param pmc pf
.param string type
.local pmc pfdir, it
pfdir = pf.'get_directory'()
it = iter pfdir
loop:
unless it goto done
$S0 = shift it
$P0 = pfdir[$S0]
$I0 = isa $P0, type
unless $I0 goto loop
.return ($P0)
done:
.return ()
.end
.sub '_find_segment_by_prefix'
.param pmc pf
.param string prefix
.local pmc pfdir, it
pfdir = pf.'get_directory'()
it = iter pfdir
loop:
unless it goto done
$S0 = shift it
$I0 = index $S0, prefix
if $I0 != 0 goto loop
$P0 = pfdir[$S0]
.return ($P0)
done:
.return ()
.end
# Report no ok for loading packfile failures
.sub report_load_error
.param pmc except
.param string desc
.local string msg, aux
msg = concat desc, ' - error loading packfile: '
aux = except['message']
msg = concat msg, aux
ok(0, msg)
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir:
|