/
namespace_dump.pir
96 lines (91 loc) · 1.66 KB
/
namespace_dump.pir
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
#
# dump all namespaces and the contents recursively
#
.sub main :main
.include "interpinfo.pasm"
.include "iterator.pasm"
.local pmc ns
ns = get_root_namespace
dump(ns, 0)
.end
# dump one namespace
.sub dump
.param pmc ns
.param int lev
.local pmc it
.local string spac
it = iter ns
it = .ITERATE_FROM_START
$I2 = lev * 4
spac = repeat " ", $I2
lp:
unless it goto ex
$S0 = shift it
$P0 = it[$S0]
# there might be a smy with the same name as a namespace
$P1 = ns.'get_sym'($S0)
if null $P1 goto no_sym
eq_addr $P0, $P1, no_sym
print spac
print $S0
print " => "
print $P1
print "\n"
no_sym:
$I0 = typeof $P0
if $I0 != .NCI goto no_nci
$P0 = new 'String'
$P0 = "NCI"
no_nci:
print spac
print $S0
print " => "
if $I0 != .MultiSub goto no_multi
$I1 = lev + 1
print " Multi [\n"
dump_multi($P0, $I1)
print spac
print "]\n"
goto lp
no_multi:
print $P0
print "\n"
if $I0 != .NameSpace goto no_ns
$I1 = lev + 1
dump($P0, $I1)
no_ns:
goto lp
ex:
.end
# dump the types of a MultiSub
.sub dump_multi
.param pmc multi
.param int lev
.local int i, n, j, m
.local string spac
n = elements multi
null i
$I2 = lev * 4
spac = repeat " ", $I2
loop:
print spac
$P0 = multi[i]
$P1 = $P0."get_multisig"()
m = elements $P1
j = 0
lp2:
$I0 = $P1[j]
typeof $S0, $I0
print $S0
print " "
inc j
if j < m goto lp2
print "\n"
inc i
if i < n goto loop
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: