Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 550 lines (481 sloc) 13.552 kb
3e7ec36 Jonathan Worthington A little setting re-ordering; put NQPStr first, since we need strings ea...
authored
1 knowhow NQPStr is repr('P6str') {
2f806d3 Jonathan Worthington Here starteth the NQP setting.
authored
2 method new() {
3 nqp::instance_of(self.WHAT);
4 }
5e82e89 Jonathan Worthington Fill out the setting with some more coercioin methods and a few equality...
authored
5 method Bool() {
3881965 Jonathan Worthington Turns out that the always pass ops type object for result type stratergy...
authored
6 nqp::logical_not_int(nqp::equal_strs(self, "")) &&
7 nqp::logical_not_int(nqp::equal_strs(self, "0"))
5e82e89 Jonathan Worthington Fill out the setting with some more coercioin methods and a few equality...
authored
8 }
ebb368a Jonathan Worthington [common] NQPArray.bind_pos plus some missing coercion methods.
authored
9 method Int() {
10 nqp::coerce_str_to_int(self, NQPInt)
11 }
12 method Num() {
13 nqp::coerce_str_to_num(self, NQPNum)
14 }
cf07e79 Jonathan Worthington [common] Some initial cuts of prefix + and ~, Stringy and Numeric in the...
authored
15 method Numeric() {
16 nqp::coerce_str_to_num(self, NQPNum)
17 }
8c6b5ae Jonathan Worthington Add Str methods to setting for NQPNum and NQPInt.
authored
18 method Str() {
3e7ec36 Jonathan Worthington A little setting re-ordering; put NQPStr first, since we need strings ea...
authored
19 self
8c6b5ae Jonathan Worthington Add Str methods to setting for NQPNum and NQPInt.
authored
20 }
cf07e79 Jonathan Worthington [common] Some initial cuts of prefix + and ~, Stringy and Numeric in the...
authored
21 method Stringy() {
22 self
23 }
ac08da5 Jonathan Worthington [common] Add .defined methods to the various built-in types.
authored
24 method defined() {
25 nqp::repr_defined(self)
26 }
2f806d3 Jonathan Worthington Here starteth the NQP setting.
authored
27 }
28
3e7ec36 Jonathan Worthington A little setting re-ordering; put NQPStr first, since we need strings ea...
authored
29 knowhow NQPInt is repr('P6int') {
2f806d3 Jonathan Worthington Here starteth the NQP setting.
authored
30 method new() {
31 nqp::instance_of(self.WHAT);
32 }
5e82e89 Jonathan Worthington Fill out the setting with some more coercioin methods and a few equality...
authored
33 method Bool() {
3881965 Jonathan Worthington Turns out that the always pass ops type object for result type stratergy...
authored
34 nqp::logical_not_int(nqp::equal_ints(self, 0))
5e82e89 Jonathan Worthington Fill out the setting with some more coercioin methods and a few equality...
authored
35 }
3e7ec36 Jonathan Worthington A little setting re-ordering; put NQPStr first, since we need strings ea...
authored
36 method Int() {
2f806d3 Jonathan Worthington Here starteth the NQP setting.
authored
37 self
38 }
3e7ec36 Jonathan Worthington A little setting re-ordering; put NQPStr first, since we need strings ea...
authored
39 method Num() {
40 nqp::coerce_int_to_num(self, NQPNum)
41 }
cf07e79 Jonathan Worthington [common] Some initial cuts of prefix + and ~, Stringy and Numeric in the...
authored
42 method Numeric() {
43 self
44 }
3e7ec36 Jonathan Worthington A little setting re-ordering; put NQPStr first, since we need strings ea...
authored
45 method Str() {
46 nqp::coerce_int_to_str(self, NQPStr)
47 }
cf07e79 Jonathan Worthington [common] Some initial cuts of prefix + and ~, Stringy and Numeric in the...
authored
48 method Stringy() {
49 nqp::coerce_int_to_str(self, NQPStr)
50 }
ac08da5 Jonathan Worthington [common] Add .defined methods to the various built-in types.
authored
51 method defined() {
52 nqp::repr_defined(self)
53 }
2f806d3 Jonathan Worthington Here starteth the NQP setting.
authored
54 }
55
56 knowhow NQPNum is repr('P6num') {
57 method new() {
58 nqp::instance_of(self.WHAT);
59 }
5e82e89 Jonathan Worthington Fill out the setting with some more coercioin methods and a few equality...
authored
60 method Bool() {
3881965 Jonathan Worthington Turns out that the always pass ops type object for result type stratergy...
authored
61 nqp::logical_not_int(nqp::equal_nums(self, 0.0))
5e82e89 Jonathan Worthington Fill out the setting with some more coercioin methods and a few equality...
authored
62 }
63 method Int() {
64 nqp::coerce_num_to_int(self, NQPStr)
65 }
2f806d3 Jonathan Worthington Here starteth the NQP setting.
authored
66 method Num() {
67 self
68 }
cf07e79 Jonathan Worthington [common] Some initial cuts of prefix + and ~, Stringy and Numeric in the...
authored
69 method Numeric() {
70 self
71 }
8c6b5ae Jonathan Worthington Add Str methods to setting for NQPNum and NQPInt.
authored
72 method Str() {
73 nqp::coerce_num_to_str(self, NQPStr)
74 }
cf07e79 Jonathan Worthington [common] Some initial cuts of prefix + and ~, Stringy and Numeric in the...
authored
75 method Stringy() {
76 nqp::coerce_num_to_str(self, NQPStr)
77 }
ac08da5 Jonathan Worthington [common] Add .defined methods to the various built-in types.
authored
78 method defined() {
79 nqp::repr_defined(self)
80 }
2f806d3 Jonathan Worthington Here starteth the NQP setting.
authored
81 }
5e82e89 Jonathan Worthington Fill out the setting with some more coercioin methods and a few equality...
authored
82
2fd812d Jonathan Worthington [dotnet] Make sure at_pos and at_key never return null, but rather somet...
authored
83 # XXX Bad hack, we'll replace this later.
84 knowhow Any {
85 method defined() { 0 }
86 }
87
eae223f Jonathan Worthington Add a first cut of a P6list representation and a list sub that makes one...
authored
88 knowhow NQPList is repr('P6list') {
7e36dac Jonathan Worthington Give NQPList a .new method.
authored
89 method new() {
90 nqp::instance_of(self.WHAT)
91 }
d88a87b Jonathan Worthington Flesh out NQPList a little bit.
authored
92 method elems() {
93 nqp::lllist_elems(self)
94 }
ea3a9cb Jonathan Worthington [common] Lists and arrays numify to number of elements.
authored
95 method Numeric() {
96 self.elems
97 }
d88a87b Jonathan Worthington Flesh out NQPList a little bit.
authored
98 method at_pos($idx) {
2fd812d Jonathan Worthington [dotnet] Make sure at_pos and at_key never return null, but rather somet...
authored
99 nqp::vivify(nqp::lllist_get_at_pos(self, $idx.Int), Any)
d88a87b Jonathan Worthington Flesh out NQPList a little bit.
authored
100 }
ac08da5 Jonathan Worthington [common] Add .defined methods to the various built-in types.
authored
101 method defined() {
102 nqp::repr_defined(self)
103 }
eae223f Jonathan Worthington Add a first cut of a P6list representation and a list sub that makes one...
authored
104 }
105
106 knowhow NQPArray is repr('P6list') {
7e36dac Jonathan Worthington Give NQPList a .new method.
authored
107 method new() {
108 nqp::instance_of(self.WHAT)
109 }
ea3a9cb Jonathan Worthington [common] Lists and arrays numify to number of elements.
authored
110 method Numeric() {
111 self.elems
112 }
7e36dac Jonathan Worthington Give NQPList a .new method.
authored
113 method elems() {
114 nqp::lllist_elems(self)
115 }
116 method at_pos($idx) {
2fd812d Jonathan Worthington [dotnet] Make sure at_pos and at_key never return null, but rather somet...
authored
117 nqp::vivify(nqp::lllist_get_at_pos(self, $idx.Int), Any)
7e36dac Jonathan Worthington Give NQPList a .new method.
authored
118 }
ebb368a Jonathan Worthington [common] NQPArray.bind_pos plus some missing coercion methods.
authored
119 method bind_pos($idx, $value) {
120 nqp::lllist_bind_at_pos(self, $idx.Int, $value)
121 }
ac08da5 Jonathan Worthington [common] Add .defined methods to the various built-in types.
authored
122 method defined() {
123 nqp::repr_defined(self)
124 }
eae223f Jonathan Worthington Add a first cut of a P6list representation and a list sub that makes one...
authored
125 }
126
435bd24 Jonathan Worthington [common] Stub in NQPHash. Doesn't do anything yet other that .new.
authored
127 knowhow NQPHash is repr('P6mapping') {
128 method new() {
129 nqp::instance_of(self.WHAT)
130 }
88190a8 Jonathan Worthington [common] Fill out NQPHash a bit and...we have basically functioning hash...
authored
131 method Numeric() {
132 self.elems
133 }
134 method elems() {
135 nqp::llmapping_elems(self)
136 }
137 method at_key($key) {
2fd812d Jonathan Worthington [dotnet] Make sure at_pos and at_key never return null, but rather somet...
authored
138 nqp::vivify(nqp::llmapping_get_at_key(self, $key.Str), Any)
88190a8 Jonathan Worthington [common] Fill out NQPHash a bit and...we have basically functioning hash...
authored
139 }
140 method bind_key($key, $value) {
141 nqp::llmapping_bind_at_key(self, $key.Str, $value)
142 }
ac08da5 Jonathan Worthington [common] Add .defined methods to the various built-in types.
authored
143 method defined() {
144 nqp::repr_defined(self)
145 }
435bd24 Jonathan Worthington [common] Stub in NQPHash. Doesn't do anything yet other that .new.
authored
146 }
147
3c156f0 Jonathan Worthington [common] Add a NQPCode with a leave method.
authored
148 knowhow NQPCode is repr('RakudoCodeRef') {
149 method leave($with) {
150 nqp::leave_block(self, $with)
151 }
ac08da5 Jonathan Worthington [common] Add .defined methods to the various built-in types.
authored
152 method defined() {
153 nqp::repr_defined(self)
154 }
3c156f0 Jonathan Worthington [common] Add a NQPCode with a leave method.
authored
155 }
156
10019ac Jonathan Worthington Start to add multi variants to the NQPSetting. Seems that even though we...
authored
157 ## XXX Need coercive Any fallbacks too.
5e82e89 Jonathan Worthington Fill out the setting with some more coercioin methods and a few equality...
authored
158
413bae8 Jonathan Worthington [common] Replace explicit multi-dispatcher ops with a proto with a plain...
authored
159 proto sub &infix:<==>($x, $y) { * }
10019ac Jonathan Worthington Start to add multi variants to the NQPSetting. Seems that even though we...
authored
160 multi sub &infix:<==>(NQPInt $x, NQPInt $y) {
161 nqp::equal_ints($x, $y)
162 }
163 multi sub &infix:<==>(NQPNum $x, NQPNum $y) {
164 nqp::equal_nums($x, $y)
5e82e89 Jonathan Worthington Fill out the setting with some more coercioin methods and a few equality...
authored
165 }
166
413bae8 Jonathan Worthington [common] Replace explicit multi-dispatcher ops with a proto with a plain...
authored
167 proto sub &infix:<!=>($x, $y) { * }
10019ac Jonathan Worthington Start to add multi variants to the NQPSetting. Seems that even though we...
authored
168 multi sub &infix:<!=>(NQPInt $x, NQPInt $y) {
dcf5ee5 Jonathan Worthington Make our != rather more efficient.
authored
169 nqp::logical_not_int(nqp::equal_ints($x, $y))
10019ac Jonathan Worthington Start to add multi variants to the NQPSetting. Seems that even though we...
authored
170 }
171 multi sub &infix:<!=>(NQPNum $x, NQPNum $y) {
dcf5ee5 Jonathan Worthington Make our != rather more efficient.
authored
172 nqp::logical_not_int(nqp::equal_nums($x, $y))
5e82e89 Jonathan Worthington Fill out the setting with some more coercioin methods and a few equality...
authored
173 }
174
175 sub &infix:<eq>($x, $y) {
3881965 Jonathan Worthington Turns out that the always pass ops type object for result type stratergy...
authored
176 nqp::equal_strs($x.Str, $y.Str)
5e82e89 Jonathan Worthington Fill out the setting with some more coercioin methods and a few equality...
authored
177 }
178
179 sub &infix:<ne>($x, $y) {
3881965 Jonathan Worthington Turns out that the always pass ops type object for result type stratergy...
authored
180 !nqp::equal_strs($x.Str, $y.Str)
5e82e89 Jonathan Worthington Fill out the setting with some more coercioin methods and a few equality...
authored
181 }
182
98e707b Jonathan Worthington [common] =:=
authored
183 sub &infix:<=:=>($x, $y) {
184 nqp::equal_refs($x, $y)
185 }
186
5e82e89 Jonathan Worthington Fill out the setting with some more coercioin methods and a few equality...
authored
187 sub &prefix:<!>($x) {
3881965 Jonathan Worthington Turns out that the always pass ops type object for result type stratergy...
authored
188 nqp::logical_not_int($x.Bool)
5e82e89 Jonathan Worthington Fill out the setting with some more coercioin methods and a few equality...
authored
189 }
190
191 sub &prefix:<?>($x) {
192 $x.Bool
193 }
d3865c1 Jonathan Worthington Add some more operators to the NQP setting.
authored
194
cf07e79 Jonathan Worthington [common] Some initial cuts of prefix + and ~, Stringy and Numeric in the...
authored
195 sub &prefix:<~>($x) {
196 $x.Stringy
197 }
198
199 sub &prefix:<+>($x) {
200 $x.Numeric
201 }
202
413bae8 Jonathan Worthington [common] Replace explicit multi-dispatcher ops with a proto with a plain...
authored
203 proto sub &infix:<+>($x, $y) { * }
10019ac Jonathan Worthington Start to add multi variants to the NQPSetting. Seems that even though we...
authored
204 multi sub &infix:<+>(NQPInt $x, NQPInt $y) {
205 nqp::add_int($x, $y);
d3865c1 Jonathan Worthington Add some more operators to the NQP setting.
authored
206 }
207
413bae8 Jonathan Worthington [common] Replace explicit multi-dispatcher ops with a proto with a plain...
authored
208 proto sub &infix:<->($x, $y) { * }
10019ac Jonathan Worthington Start to add multi variants to the NQPSetting. Seems that even though we...
authored
209 multi sub &infix:<->(NQPInt $x, NQPInt $y) {
210 nqp::sub_int($x, $y);
d3865c1 Jonathan Worthington Add some more operators to the NQP setting.
authored
211 }
212
413bae8 Jonathan Worthington [common] Replace explicit multi-dispatcher ops with a proto with a plain...
authored
213 proto sub &infix:<*>($x, $y) { * }
10019ac Jonathan Worthington Start to add multi variants to the NQPSetting. Seems that even though we...
authored
214 multi sub &infix:<*>(NQPInt $x, NQPInt $y) {
215 nqp::mul_int($x, $y);
d3865c1 Jonathan Worthington Add some more operators to the NQP setting.
authored
216 }
217
413bae8 Jonathan Worthington [common] Replace explicit multi-dispatcher ops with a proto with a plain...
authored
218 proto sub &infix:</>($x, $y) { * }
10019ac Jonathan Worthington Start to add multi variants to the NQPSetting. Seems that even though we...
authored
219 multi sub &infix:</>(NQPInt $x, NQPInt $y) {
220 nqp::div_int($x, $y);
d3865c1 Jonathan Worthington Add some more operators to the NQP setting.
authored
221 }
222
413bae8 Jonathan Worthington [common] Replace explicit multi-dispatcher ops with a proto with a plain...
authored
223 proto sub &infix:<%>($x, $y) { * }
10019ac Jonathan Worthington Start to add multi variants to the NQPSetting. Seems that even though we...
authored
224 multi sub &infix:<%>(NQPInt $x, NQPInt $y) {
225 nqp::mod_int($x, $y);
d3865c1 Jonathan Worthington Add some more operators to the NQP setting.
authored
226 }
227
228 sub &infix:<~>($x, $y) {
3881965 Jonathan Worthington Turns out that the always pass ops type object for result type stratergy...
authored
229 nqp::concat($x.Str, $y.Str);
d3865c1 Jonathan Worthington Add some more operators to the NQP setting.
authored
230 }
a64ea75 Jonathan Worthington Implement plan and ok for getting us more tests.
authored
231
6a07cb2 Jonathan Worthington [common] Stub in a simple NQPException exception object and a die sub.
authored
232 # A basic, fairly bare-bones exception object.
233 knowhow NQPException {
234 has $!message;
235 has $!resumable;
236
237 method new($message) {
238 nqp::instance_of(self.WHAT).BUILD(:message($message))
239 }
240
241 method BUILD(:$message) {
242 $!message := $message;
243 $!resumable := 0;
244 self;
245 }
246
ac08da5 Jonathan Worthington [common] Add .defined methods to the various built-in types.
authored
247 method defined() {
248 nqp::repr_defined(self)
249 }
250
6a07cb2 Jonathan Worthington [common] Stub in a simple NQPException exception object and a die sub.
authored
251 method resumable() {
252 $!resumable
253 }
254
255 method resume() {
256 $!resumable := 1;
257 }
258
259 method Str() {
260 $!message
261 }
262 }
263
264 sub die($message) {
265 nqp::throw_dynamic(NQPException.new($message), 0)
266 }
267
a64ea75 Jonathan Worthington Implement plan and ok for getting us more tests.
authored
268 # For tests.
269 my $count := NQPInt.new();
270 sub plan($n) {
271 print("1..");
272 say($n);
273 }
7e9d2b8 Jonathan Worthington [common] $diag arg of ok should be optional.
authored
274 sub ok($check, $diag?) {
a64ea75 Jonathan Worthington Implement plan and ok for getting us more tests.
authored
275 $count := $count + 1;
276 unless $check { print("not ") }
277 print("ok ");
278 say($count);
279 }
cbdd49b Jonathan Worthington [dotnet] Out with one bad hack, in with a slightly less bad one for unde...
authored
280
06d78a2 Jonathan Worthington [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
281 # Here comes the start of a heavily under construction ClassHOW.
282 knowhow NQPClassHOW {
283 ##
284 ## Attributes
285 ##
286
287 # Name of the class.
288 has $!name;
289
290 # Attributes, methods, parents and roles directly added.
3c4309f Jonathan Worthington [common] Much more filling out of NQPClassHOW, plus add a very basic NQP...
authored
291 has @!attributes;
06d78a2 Jonathan Worthington [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
292 has %!methods;
6e2fb41 Jonathan Worthington [dotnet] First cut of multi-methods in NQPClassHOW. At the moment, only ...
authored
293 has @!multi_methods_to_incorporate;
06d78a2 Jonathan Worthington [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
294 has @!parents;
295 has @!roles;
296
297 # Vtable and mapping of method names to slots.
298 has @!vtable;
299 has %!method-vtable-slots;
300
301 # Have we been composed?
302 has $!composed;
303
304 # Cached MRO (list of the type objects).
305 has @!mro;
306
307 # Full list of roles that we do.
308 has @!done;
309
310 ##
311 ## Declarative.
312 ##
313
314 # Creates a new instance of this meta-class.
b76e080 Jonathan Worthington [common] Allow NQPClassHOW to take and store the name of the class, and ...
authored
315 method new(:$name) {
316 nqp::instance_of(self).BUILD(:name($name))
06d78a2 Jonathan Worthington [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
317 }
318
3c4309f Jonathan Worthington [common] Much more filling out of NQPClassHOW, plus add a very basic NQP...
authored
319 method CREATE($obj) {
320 nqp::instance_of($obj)
321 }
322
b76e080 Jonathan Worthington [common] Allow NQPClassHOW to take and store the name of the class, and ...
authored
323 method BUILD(:$name) {
324 $!name := $name;
06d78a2 Jonathan Worthington [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
325 $!composed := 0;
4356d78 Jonathan Worthington [common] Add a VERY hacky but working version of method addition and dis...
authored
326 %!methods := NQPHash.new;
6e2fb41 Jonathan Worthington [dotnet] First cut of multi-methods in NQPClassHOW. At the moment, only ...
authored
327 @!multi_methods_to_incorporate := NQPArray.new;
3c4309f Jonathan Worthington [common] Much more filling out of NQPClassHOW, plus add a very basic NQP...
authored
328 @!attributes := NQPArray.new;
329 @!parents := NQPArray.new;
06d78a2 Jonathan Worthington [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
330 self;
331 }
332
333 # Create a new meta-class instance, and then a new type object
334 # to go with it, and return that.
335 # XXX TODO :$repr named parameter defaulting to P6opaque (don't
336 # have default values yet implemented).
b76e080 Jonathan Worthington [common] Allow NQPClassHOW to take and store the name of the class, and ...
authored
337 method new_type(:$name = '<anon>', :$repr = 'P6opaque') {
338 my $metaclass := self.new(:name($name));
06d78a2 Jonathan Worthington [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
339 nqp::type_object_for($metaclass, 'P6opaque');
340 }
341
4356d78 Jonathan Worthington [common] Add a VERY hacky but working version of method addition and dis...
authored
342 method add_method($obj, $name, $code_obj) {
2fd812d Jonathan Worthington [dotnet] Make sure at_pos and at_key never return null, but rather somet...
authored
343 if %!methods{$name}.defined {
344 die("This class already has a method named " ~ $name);
345 }
4356d78 Jonathan Worthington [common] Add a VERY hacky but working version of method addition and dis...
authored
346 %!methods{$name} := $code_obj;
347 }
348
6e2fb41 Jonathan Worthington [dotnet] First cut of multi-methods in NQPClassHOW. At the moment, only ...
authored
349 method add_multi_method($obj, $name, $code_obj) {
350 # We can't incorporate these right away as we don't know all
351 # parents yet, maybe, which influences whether we even can
352 # have multis, need to generate a proto or worreva. So just
353 # queue them up in a todo list and we handle it at class
354 # composition time.
355 my %todo;
356 %todo<name> := $name;
357 %todo<code> := $code_obj;
358 @!multi_methods_to_incorporate[+@!multi_methods_to_incorporate] := %todo;
359 $code_obj;
360 }
361
3c4309f Jonathan Worthington [common] Much more filling out of NQPClassHOW, plus add a very basic NQP...
authored
362 method add_attribute($obj, $meta_attr) {
363 if $!composed {
364 die("NQPClassHOW does not support adding attributes after being composed.");
365 }
366 my $i := 0;
367 while $i != +@!attributes {
368 if @!attributes[$i].name eq $meta_attr.name {
369 die("Already have an attribute named " ~ $meta_attr.name);
370 }
371 $i := $i + 1;
372 }
373 @!attributes[+@!attributes] := $meta_attr;
374 }
375
376 method add_parent($obj, $parent) {
377 if $!composed {
378 pir::die("NQPClassHOW does not support adding parents after being composed.");
379 }
380 my $i := 0;
381 while $i != +@!parents {
382 if @!parents[$i] =:= $parent {
383 die("Already have " ~ $parent ~ " as a parent class.");
384 }
385 $i := $i + 1;
386 }
387 @!parents[+@!parents] := $parent;
388 }
389
06d78a2 Jonathan Worthington [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
390 method compose($obj) {
6e2fb41 Jonathan Worthington [dotnet] First cut of multi-methods in NQPClassHOW. At the moment, only ...
authored
391 # XXX TODO: Compose roles (must come before we make MRO,
392 # and may provide multi candidates.)
393
06d78a2 Jonathan Worthington [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
394 # Some things we only do if we weren't already composed once, like
395 # building the MRO.
396 unless $!composed {
397 @!mro := compute_c3_mro($obj);
398 $!composed := 1;
399 }
400
6e2fb41 Jonathan Worthington [dotnet] First cut of multi-methods in NQPClassHOW. At the moment, only ...
authored
401 # Incorporate any new multi candidates (needs MRO built).
402 self.incorporate_multi_candidates($obj);
403
404 # XXX TODO: Compose attributes.
405
06d78a2 Jonathan Worthington [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
406 $obj
407 }
408
6e2fb41 Jonathan Worthington [dotnet] First cut of multi-methods in NQPClassHOW. At the moment, only ...
authored
409 method incorporate_multi_candidates($obj) {
410 my $num_todo := +@!multi_methods_to_incorporate;
411 my $i := 0;
412 while $i != $num_todo {
413 # Get method name and code.
414 my $name := @!multi_methods_to_incorporate[$i]<name>;
415 my $code := @!multi_methods_to_incorporate[$i]<code>;
416
417 # Do we have anything in the methods table already in
418 # this class?
419 my $dispatcher := %!methods{$name};
420 if $dispatcher.defined {
421 # Yes. Only or dispatcher, though? If only, error. If
422 # dispatcher, simply add new dispatchee.
423 if nqp::is_dispatcher($dispatcher) {
424 nqp::push_dispatchee($dispatcher, $code);
425 }
426 else {
427 die("Cannot have a multi candidate for $name when an only method is also in the class");
428 }
429 }
430 else {
dc36346 Jonathan Worthington [common] Implement searching for a proto in parent classes too, and inst...
authored
431 # Go hunting in the MRO for a proto.
432 my $j := 1;
433 my $found := 0;
434 while $j != +@!mro && !$found {
435 my $parent := @!mro[$j];
436 my %meths := $parent.HOW.method_table($parent);
437 my $dispatcher := %meths{$name};
438 if $dispatcher.defined {
439 # Found a possible - make sure it's a dispatcher, not
440 # an only.
441 if nqp::is_dispatcher($dispatcher) {
442 # Clone it and install it in our method table.
443 my @new_dispatchees;
444 @new_dispatchees[0] := $code;
445 %!methods{$name} := nqp::create_dispatch_and_add_candidates($dispatcher, @new_dispatchees);
446 $found := 1;
447 }
448 else {
449 die("Could not find a proto for multi $name (it may exist, but an only is hiding it if so)");
450 }
451 }
452 }
453 unless $found {
454 die("Could not find a proto for multi $name, and proto generation is NYI");
455 }
6e2fb41 Jonathan Worthington [dotnet] First cut of multi-methods in NQPClassHOW. At the moment, only ...
authored
456 }
457 $i := $i + 1;
458 }
459 }
460
06d78a2 Jonathan Worthington [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
461 # XXX TODO: Get enough working to bring over the C3 implementation that
3c4309f Jonathan Worthington [common] Much more filling out of NQPClassHOW, plus add a very basic NQP...
authored
462 # we run on 6model on Parrot. For now, we only build it for single
463 # inheritance since it's obvious how to do it.
06d78a2 Jonathan Worthington [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
464 sub compute_c3_mro($obj) {
3c4309f Jonathan Worthington [common] Much more filling out of NQPClassHOW, plus add a very basic NQP...
authored
465 # MRO starts with this object.
06d78a2 Jonathan Worthington [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
466 my @mro;
467 @mro[0] := $obj;
3c4309f Jonathan Worthington [common] Much more filling out of NQPClassHOW, plus add a very basic NQP...
authored
468
469 # Now add all parents until we have none.
470 my $cur_obj := $obj;
471 my @parents := $cur_obj.HOW.parents($cur_obj, :local(1));
472 while +@parents {
473 if +@parents == 1 {
474 @mro[+@mro] := $cur_obj := @parents[0];
475 @parents := $cur_obj.HOW.parents($cur_obj, :local(1));
476 }
477 else {
478 die("Sorry, multiple inheritance is not yet implemented.");
479 }
480 }
481
482 # Return MRO.
06d78a2 Jonathan Worthington [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
483 @mro;
484 }
4356d78 Jonathan Worthington [common] Add a VERY hacky but working version of method addition and dis...
authored
485
486 ##
487 ## Introspecty
488 ##
489
3c4309f Jonathan Worthington [common] Much more filling out of NQPClassHOW, plus add a very basic NQP...
authored
490 method attributes($obj, :$local!) {
491 @!attributes
492 }
493
4356d78 Jonathan Worthington [common] Add a VERY hacky but working version of method addition and dis...
authored
494 method method_table($obj) {
495 %!methods
496 }
497
b76e080 Jonathan Worthington [common] Allow NQPClassHOW to take and store the name of the class, and ...
authored
498 method name($obj) {
499 $!name
500 }
501
3c4309f Jonathan Worthington [common] Much more filling out of NQPClassHOW, plus add a very basic NQP...
authored
502 method parents($obj, :$local!) {
503 @!parents
504 }
505
ac08da5 Jonathan Worthington [common] Add .defined methods to the various built-in types.
authored
506 method defined() {
507 nqp::repr_defined(self)
508 }
509
4356d78 Jonathan Worthington [common] Add a VERY hacky but working version of method addition and dis...
authored
510 ##
511 ## Dispatchy
512 ##
513
514 method find_method($obj, $name) {
3c4309f Jonathan Worthington [common] Much more filling out of NQPClassHOW, plus add a very basic NQP...
authored
515 my $i := 0;
516 my $mro_length := +@!mro;
517 while $i != $mro_length {
518 my %meths := @!mro[$i].HOW.method_table($obj);
519 my $found := %meths{$name};
520 if $found.defined {
521 return $found;
522 }
523 $i := $i + 1;
524 }
525 die("Could not find method " ~ $name);
526 }
527 }
528
529 # A simple attribute meta-object.
530 knowhow NQPAttribute {
531 has $!name;
532 method new(:$name) {
533 my $obj := nqp::instance_of(self);
534 $obj.BUILD(:name($name));
535 $obj
536 }
537 method BUILD(:$name) {
538 $!name := $name
539 }
540 method name() {
541 $!name
4356d78 Jonathan Worthington [common] Add a VERY hacky but working version of method addition and dis...
authored
542 }
06d78a2 Jonathan Worthington [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
543 }
544
4f3c7e0 Jonathan Worthington [common] Set up a GLOBAL.
authored
545 # GLOBAL stash.
546 # (XXX Really want one per compilation unit and unify, but this will get us
547 # started. Also really want a stash type that knows its name rather than just
548 # a hash, I guess.)
549 ::GLOBAL := NQPHash.new();
Something went wrong with that request. Please try again.