Ticket #745: try.pir

File try.pir, 1.3 KB (added by Austin_Hastings, 6 years ago)

Shows inconsistent behavior between newclass <STR> and <PMC>

Line 
1.namespace [ 'Foo' ; 'Bar' ; 'Dog' ]
2.sub 'burble' :method
3        say "burble, burble"
4.end
5
6.namespace []
7.sub list_methods
8        .param pmc obj
9
10        $P0 = typeof obj
11        $P0 = get_class $P0
12        $P0 = $P0.'methods'()
13
14        print "Here are the methods of class "
15        $S0 = typeof obj
16        say $S0
17
18        .local pmc iter
19        iter = new 'Iterator', $P0
20        while:
21        unless iter, done
22        $S0 = shift iter
23        print " - "
24        print $S0
25        print ": "
26        $S0 = iter[$S0]
27        say $S0
28        goto while
29        done:
30        say "That's all"
31.end
32
33.sub main :main
34
35        .local pmc clas
36        say "Creating Foo::Bar::Dog by hash"
37        .local pmc class_info
38        class_info = new 'Hash'
39
40        .local pmc ns
41        $P0 = split "::", "Foo::Bar::Dog"
42        $P1 = get_hll_namespace
43        ns = $P1.'make_namespace'($P0)
44        class_info['name'] = ns
45
46        $P0 = new 'Hash'
47        class_info['methods'] = $P0
48        $P1 = get_hll_global [ 'Foo';'Bar';'Dog'], 'burble'
49        $P0['bark'] = $P1
50        #class_info['roles'] =
51
52        $P0 = new 'ResizableStringArray'
53        class_info['attributes'] = $P0
54        push $P0, "alpha"
55        push $P0, "beta"
56        push $P0, "omega"
57
58        clas = newclass class_info
59        $P0 = new clas
60
61        'list_methods'($P0)
62
63        $P0.'bark'()
64        $P0.'burble'()
65
66        clas = newclass "Foo;Bar;Dog"
67
68        say "Creating Foo::Bar::Dog by name"
69
70        $P0 = new clas
71        'list_methods'($P0)
72
73        push_eh step2
74        $P0.'burble'()
75        $P0.'bark'()
76        say "Done with dog-by-name"
77
78        step2:
79        pop_eh
80        say "So much for that"
81
82.end