Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 184 lines (176 sloc) 7.522 kb
452cdbca »
2012-06-03 small typed exceptions refactor
1 my class X::Bind { ... }
2
26765495 »
2012-04-14 Start to sketch out a PseudoStash that will handle many of the pseudo…
3 my class PseudoStash is EnumMap {
4 has Mu $!ctx;
5 has int $!mode;
6
7 # Lookup modes.
8 my int constant PICK_CHAIN_BY_NAME = 0;
9 my int constant STATIC_CHAIN = 1;
10 my int constant DYNAMIC_CHAIN = 2;
11 my int constant PRECISE_SCOPE = 3;
12
13 method new() {
14 my $obj := nqp::create(self);
15 my $ctx := pir::getattribute__PPs(
16 nqp::atkey(pir::getinterp__P(), 'context'),
17 'caller_ctx');
18 nqp::bindattr($obj, PseudoStash, '$!ctx', $ctx);
19 nqp::bindattr($obj, EnumMap, '$!storage',
20 pir::getattribute__PPs($ctx, 'lex_pad'));
21 $obj
22 }
23
24 my %pseudoers =
25 'MY' => sub ($cur) {
26 my $stash := pir::repr_clone__PP($cur);
27 nqp::bindattr_i($stash, PseudoStash, '$!mode', PRECISE_SCOPE);
28 pir::set_who__0PP(
f740e376 »
2012-06-22 Fix a thinko that somehow wented undetected; guess we only cared abou…
29 Metamodel::ModuleHOW.new_type(:name('MY')),
26765495 »
2012-04-14 Start to sketch out a PseudoStash that will handle many of the pseudo…
30 $stash);
31 },
32 'CORE' => sub ($cur) {
ef6fe019 »
2012-04-16 CORE, SETTING and UNIT.
33 my Mu $ctx := nqp::getattr(nqp::p6decont($cur), PseudoStash, '$!ctx');
34 until nqp::existskey(pir::getattribute__PPs($ctx, 'lex_pad'), '!CORE_MARKER') {
35 $ctx := pir::getattribute__PPs($ctx, 'outer_ctx');
36 }
37 my $stash := nqp::create(PseudoStash);
38 nqp::bindattr($stash, EnumMap, '$!storage',
39 pir::getattribute__PPs($ctx, 'lex_pad'));
40 nqp::bindattr($stash, PseudoStash, '$!ctx', $ctx);
41 nqp::bindattr_i($stash, PseudoStash, '$!mode', PRECISE_SCOPE);
42 pir::set_who__0PP(
f740e376 »
2012-06-22 Fix a thinko that somehow wented undetected; guess we only cared abou…
43 Metamodel::ModuleHOW.new_type(:name('CORE')),
ef6fe019 »
2012-04-16 CORE, SETTING and UNIT.
44 $stash);
26765495 »
2012-04-14 Start to sketch out a PseudoStash that will handle many of the pseudo…
45 },
46 'CALLER' => sub ($cur) {
47 my Mu $ctx := pir::getattribute__PPs(
48 nqp::getattr(nqp::p6decont($cur), PseudoStash, '$!ctx'),
49 'caller_ctx');
50 my $stash := nqp::create(PseudoStash);
51 nqp::bindattr($stash, EnumMap, '$!storage',
52 pir::getattribute__PPs($ctx, 'lex_pad'));
53 nqp::bindattr($stash, PseudoStash, '$!ctx', $ctx);
54 nqp::bindattr_i($stash, PseudoStash, '$!mode', PRECISE_SCOPE);
55 pir::set_who__0PP(
f740e376 »
2012-06-22 Fix a thinko that somehow wented undetected; guess we only cared abou…
56 Metamodel::ModuleHOW.new_type(:name('CALLER')),
26765495 »
2012-04-14 Start to sketch out a PseudoStash that will handle many of the pseudo…
57 $stash);
58 },
59 'OUTER' => sub ($cur) {
60 my Mu $ctx := pir::getattribute__PPs(
61 nqp::getattr(nqp::p6decont($cur), PseudoStash, '$!ctx'),
62 'outer_ctx');
63 my $stash := nqp::create(PseudoStash);
64 nqp::bindattr($stash, EnumMap, '$!storage',
65 pir::getattribute__PPs($ctx, 'lex_pad'));
66 nqp::bindattr($stash, PseudoStash, '$!ctx', $ctx);
67 nqp::bindattr_i($stash, PseudoStash, '$!mode', PRECISE_SCOPE);
68 pir::set_who__0PP(
f740e376 »
2012-06-22 Fix a thinko that somehow wented undetected; guess we only cared abou…
69 Metamodel::ModuleHOW.new_type(:name('OUTER')),
26765495 »
2012-04-14 Start to sketch out a PseudoStash that will handle many of the pseudo…
70 $stash);
71 },
72 'DYNAMIC' => sub ($cur) {
9b4f785d »
2012-04-15 Fix DYNAMIC, so it now basically works.
73 my $stash := pir::repr_clone__PP($cur);
26765495 »
2012-04-14 Start to sketch out a PseudoStash that will handle many of the pseudo…
74 nqp::bindattr_i($stash, PseudoStash, '$!mode', DYNAMIC_CHAIN);
75 pir::set_who__0PP(
f740e376 »
2012-06-22 Fix a thinko that somehow wented undetected; guess we only cared abou…
76 Metamodel::ModuleHOW.new_type(:name('DYNAMIC')),
26765495 »
2012-04-14 Start to sketch out a PseudoStash that will handle many of the pseudo…
77 $stash);
78 },
79 'UNIT' => sub ($cur) {
ef6fe019 »
2012-04-16 CORE, SETTING and UNIT.
80 my Mu $ctx := nqp::getattr(nqp::p6decont($cur), PseudoStash, '$!ctx');
81 until nqp::existskey(pir::getattribute__PPs($ctx, 'lex_pad'), '!UNIT_MARKER') {
82 $ctx := pir::getattribute__PPs($ctx, 'outer_ctx');
83 }
84 my $stash := nqp::create(PseudoStash);
85 nqp::bindattr($stash, EnumMap, '$!storage',
86 pir::getattribute__PPs($ctx, 'lex_pad'));
87 nqp::bindattr($stash, PseudoStash, '$!ctx', $ctx);
88 nqp::bindattr_i($stash, PseudoStash, '$!mode', PRECISE_SCOPE);
89 pir::set_who__0PP(
f740e376 »
2012-06-22 Fix a thinko that somehow wented undetected; guess we only cared abou…
90 Metamodel::ModuleHOW.new_type(:name('UNIT')),
ef6fe019 »
2012-04-16 CORE, SETTING and UNIT.
91 $stash);
c384ab72 »
2012-04-15 First crack at OUR.
92 },
26765495 »
2012-04-14 Start to sketch out a PseudoStash that will handle many of the pseudo…
93 'SETTING' => sub ($cur) {
ef6fe019 »
2012-04-16 CORE, SETTING and UNIT.
94 # Same as UNIT, but go a little further out (two steps, for
95 # internals reasons).
96 my Mu $ctx := nqp::getattr(nqp::p6decont($cur), PseudoStash, '$!ctx');
97 until nqp::existskey(pir::getattribute__PPs($ctx, 'lex_pad'), '!UNIT_MARKER') {
98 $ctx := pir::getattribute__PPs($ctx, 'outer_ctx');
99 }
100 $ctx := pir::getattribute__PPs(pir::getattribute__PPs($ctx, 'outer_ctx'), 'outer_ctx');
101 my $stash := nqp::create(PseudoStash);
102 nqp::bindattr($stash, EnumMap, '$!storage',
103 pir::getattribute__PPs($ctx, 'lex_pad'));
104 nqp::bindattr($stash, PseudoStash, '$!ctx', $ctx);
105 nqp::bindattr_i($stash, PseudoStash, '$!mode', PRECISE_SCOPE);
106 pir::set_who__0PP(
f740e376 »
2012-06-22 Fix a thinko that somehow wented undetected; guess we only cared abou…
107 Metamodel::ModuleHOW.new_type(:name('UNIT')),
ef6fe019 »
2012-04-16 CORE, SETTING and UNIT.
108 $stash);
c384ab72 »
2012-04-15 First crack at OUR.
109 },
110 'OUR' => sub ($cur) {
111 pir::find_lex_relative__PPs(
112 nqp::getattr(nqp::p6decont($cur), PseudoStash, '$!ctx'),
113 '$?PACKAGE')
26765495 »
2012-04-14 Start to sketch out a PseudoStash that will handle many of the pseudo…
114 };
115
116 method at_key($key is copy) is rw {
117 $key = $key.Str;
118 if %pseudoers.exists($key) {
119 %pseudoers{$key}(self)
120 }
121 elsif $!mode == PRECISE_SCOPE {
122 my Mu $store := nqp::getattr(self, EnumMap, '$!storage');
123 nqp::existskey($store, nqp::unbox_s($key)) ??
124 nqp::atkey($store, nqp::unbox_s($key)) !!
125 Any
126 }
127 elsif $!mode == DYNAMIC_CHAIN || $!mode == PICK_CHAIN_BY_NAME && substr($key, 1, 1) eq '*' {
c59411ce »
2012-04-14 Flesh out pseudo-package handling a bit more. Now all of the interpol…
128 my $found := pir::find_dynamic_lex_relative__PPs(
129 nqp::getattr(self, PseudoStash, '$!ctx'),
130 nqp::unbox_s($key));
131 nqp::isnull($found) ?? Any !! $found
26765495 »
2012-04-14 Start to sketch out a PseudoStash that will handle many of the pseudo…
132 }
133 else {
c59411ce »
2012-04-14 Flesh out pseudo-package handling a bit more. Now all of the interpol…
134 my $found := pir::find_lex_relative__PPs(
135 nqp::getattr(self, PseudoStash, '$!ctx'),
136 nqp::unbox_s($key));
137 nqp::isnull($found) ?? Any !! $found
26765495 »
2012-04-14 Start to sketch out a PseudoStash that will handle many of the pseudo…
138 }
139 }
5a31737d »
2012-04-14 Get things like ::('MY::$a') and $::('OUTER::b') working.
140
c9417ca5 »
2012-08-14 switch IO, PseudoStash, traits, control.pm and stubs.pm to sigilless …
141 method bind_key($key is copy, \value) {
9df76e93 »
2012-04-15 Implement various cases of binding into pseudo-packages.
142 $key = $key.Str;
143 if %pseudoers.exists($key) {
452cdbca »
2012-06-03 small typed exceptions refactor
144 X::Bind.new(target => "pseudo-package $key").throw;
9df76e93 »
2012-04-15 Implement various cases of binding into pseudo-packages.
145 }
146 elsif $!mode == PRECISE_SCOPE {
147 my Mu $store := nqp::getattr(self, EnumMap, '$!storage');
c9417ca5 »
2012-08-14 switch IO, PseudoStash, traits, control.pm and stubs.pm to sigilless …
148 nqp::bindkey($store, nqp::unbox_s($key), value)
9df76e93 »
2012-04-15 Implement various cases of binding into pseudo-packages.
149 }
150 elsif $!mode == DYNAMIC_CHAIN || $!mode == PICK_CHAIN_BY_NAME && substr($key, 1, 1) eq '*' {
151 die "Binding to dynamic variables not yet implemented";
152 }
153 else {
154 die "This case of binding is not yet implemented";
155 }
156 }
157
5a31737d »
2012-04-14 Get things like ::('MY::$a') and $::('OUTER::b') working.
158 method exists($key is copy) {
159 $key = $key.Str;
160 if %pseudoers.exists($key) {
161 True
162 }
163 elsif $!mode == PRECISE_SCOPE {
ce9ae4e7 »
2012-07-31 Fix PseudoStash.exists to always return a Bool.
164 nqp::p6bool(nqp::existskey(
5a31737d »
2012-04-14 Get things like ::('MY::$a') and $::('OUTER::b') working.
165 nqp::getattr(self, EnumMap, '$!storage'),
ce9ae4e7 »
2012-07-31 Fix PseudoStash.exists to always return a Bool.
166 nqp::unbox_s($key)))
5a31737d »
2012-04-14 Get things like ::('MY::$a') and $::('OUTER::b') working.
167 }
168 elsif $!mode == DYNAMIC_CHAIN || $!mode == PICK_CHAIN_BY_NAME && substr($key, 1, 1) eq '*' {
c59411ce »
2012-04-14 Flesh out pseudo-package handling a bit more. Now all of the interpol…
169 nqp::isnull(
170 pir::find_dynamic_lex_relative__PPs(
171 nqp::getattr(self, PseudoStash, '$!ctx'),
172 nqp::unbox_s($key)))
173 ?? False !! True
5a31737d »
2012-04-14 Get things like ::('MY::$a') and $::('OUTER::b') working.
174 }
175 else {
c59411ce »
2012-04-14 Flesh out pseudo-package handling a bit more. Now all of the interpol…
176 nqp::isnull(
177 pir::find_lex_relative__PPs(
178 nqp::getattr(self, PseudoStash, '$!ctx'),
179 nqp::unbox_s($key)))
180 ?? False !! True
5a31737d »
2012-04-14 Get things like ::('MY::$a') and $::('OUTER::b') working.
181 }
182 }
26765495 »
2012-04-14 Start to sketch out a PseudoStash that will handle many of the pseudo…
183 }
Something went wrong with that request. Please try again.