[t][TT #1610] Add tests for Parrot_compile_string
[parrot.git] / examples / namespace / namespace_dump.pir
blob82e9f42ebeaae0db5695c63d2f06fd7214d08705
1 # Copyright (C) 2006-2009, Parrot Foundation.
2 # $Id$
5 # dump all namespaces and the contents recursively
7 .sub main :main
8     .include "interpinfo.pasm"
9     .include "iterator.pasm"
10     .local pmc ns
11     ns = get_root_namespace
12     dump(ns, 0)
13 .end
15 # dump one namespace
16 .sub dump
17     .param pmc ns
18     .param int lev
19     .local pmc it
20     .local string spac
22     it = iter ns
23     it = .ITERATE_FROM_START
24     $I2 = lev * 4
25     spac = repeat " ", $I2
26 lp:
27     unless it goto ex
28     $S0 = shift it
29     $P0 = it[$S0]
30     # there might be a smy with the same name as a namespace
31     $P1 = ns.'get_sym'($S0)
32     if null $P1 goto no_sym
33     eq_addr $P0, $P1, no_sym
34     print spac
35     print $S0
36     print " => "
37     print $P1
38     print "\n"
39 no_sym:
40     $I0 = isa $P0, 'NCI'
41     unless $I0 goto no_nci
42     $P0 = new 'String'
43     $P0 = "NCI"
44 no_nci:
45     print spac
46     print $S0
47     print " => "
48     $I0 = isa $P0, 'MultiSub'
49     unless $I0 goto no_multi
50     $I1 = lev + 1
51     print " Multi [\n"
52     dump_multi($P0, $I1)
53     print spac
54     print "]\n"
55     goto lp
56 no_multi:
57     print $P0
58     print "\n"
59     $I0 = isa $P0, 'NameSpace'
60     unless $I0 goto no_ns
61     $I1 = lev + 1
62     dump($P0, $I1)
63 no_ns:
64     goto lp
65 ex:
66 .end
68 # dump the types of a MultiSub
69 .sub dump_multi
70     .param pmc multi
71     .param int lev
72     .local int i, n, j, m
73     .local string spac
74     n = elements multi
75     null i
76     $I2 = lev * 4
77     spac = repeat " ", $I2
79 loop:
80     print spac
81     $P0 = multi[i]
82     $P1 = $P0."get_multisig"()
83     if null $P1 goto next_loop
84     m = elements $P1
85     j = 0
86 lp2:
87     $I0 = $P1[j]
88     print $I0
89     print " "
90     inc j
91     if j < m goto lp2
93     print "\n"
94 next_loop:
95     inc i
96     if i < n goto loop
97 .end
99 # Local Variables:
100 #   mode: pir
101 #   fill-column: 100
102 # End:
103 # vim: expandtab shiftwidth=4 ft=pir: