Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 390 lines (335 sloc) 8.012 kb
3e7ec36 @jnthn A little setting re-ordering; put NQPStr first, since we need strings ea...
authored
1 knowhow NQPStr is repr('P6str') {
2f806d3 @jnthn Here starteth the NQP setting.
authored
2 method new() {
3 nqp::instance_of(self.WHAT);
4 }
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equality...
authored
5 method Bool() {
3881965 @jnthn 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 @jnthn Fill out the setting with some more coercioin methods and a few equality...
authored
8 }
ebb368a @jnthn [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 @jnthn [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 @jnthn Add Str methods to setting for NQPNum and NQPInt.
authored
18 method Str() {
3e7ec36 @jnthn A little setting re-ordering; put NQPStr first, since we need strings ea...
authored
19 self
8c6b5ae @jnthn Add Str methods to setting for NQPNum and NQPInt.
authored
20 }
cf07e79 @jnthn [common] Some initial cuts of prefix + and ~, Stringy and Numeric in the...
authored
21 method Stringy() {
22 self
23 }
ac08da5 @jnthn [common] Add .defined methods to the various built-in types.
authored
24 method defined() {
25 nqp::repr_defined(self)
26 }
2f806d3 @jnthn Here starteth the NQP setting.
authored
27 }
28
3e7ec36 @jnthn A little setting re-ordering; put NQPStr first, since we need strings ea...
authored
29 knowhow NQPInt is repr('P6int') {
2f806d3 @jnthn Here starteth the NQP setting.
authored
30 method new() {
31 nqp::instance_of(self.WHAT);
32 }
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equality...
authored
33 method Bool() {
3881965 @jnthn 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 @jnthn Fill out the setting with some more coercioin methods and a few equality...
authored
35 }
3e7ec36 @jnthn A little setting re-ordering; put NQPStr first, since we need strings ea...
authored
36 method Int() {
2f806d3 @jnthn Here starteth the NQP setting.
authored
37 self
38 }
3e7ec36 @jnthn 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 @jnthn [common] Some initial cuts of prefix + and ~, Stringy and Numeric in the...
authored
42 method Numeric() {
43 self
44 }
3e7ec36 @jnthn 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 @jnthn [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 @jnthn [common] Add .defined methods to the various built-in types.
authored
51 method defined() {
52 nqp::repr_defined(self)
53 }
2f806d3 @jnthn 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 @jnthn Fill out the setting with some more coercioin methods and a few equality...
authored
60 method Bool() {
3881965 @jnthn 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 @jnthn 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 @jnthn Here starteth the NQP setting.
authored
66 method Num() {
67 self
68 }
cf07e79 @jnthn [common] Some initial cuts of prefix + and ~, Stringy and Numeric in the...
authored
69 method Numeric() {
70 self
71 }
8c6b5ae @jnthn Add Str methods to setting for NQPNum and NQPInt.
authored
72 method Str() {
73 nqp::coerce_num_to_str(self, NQPStr)
74 }
cf07e79 @jnthn [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 @jnthn [common] Add .defined methods to the various built-in types.
authored
78 method defined() {
79 nqp::repr_defined(self)
80 }
2f806d3 @jnthn Here starteth the NQP setting.
authored
81 }
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equality...
authored
82
eae223f @jnthn Add a first cut of a P6list representation and a list sub that makes one...
authored
83 knowhow NQPList is repr('P6list') {
7e36dac @jnthn Give NQPList a .new method.
authored
84 method new() {
85 nqp::instance_of(self.WHAT)
86 }
d88a87b @jnthn Flesh out NQPList a little bit.
authored
87 method elems() {
88 nqp::lllist_elems(self)
89 }
ea3a9cb @jnthn [common] Lists and arrays numify to number of elements.
authored
90 method Numeric() {
91 self.elems
92 }
d88a87b @jnthn Flesh out NQPList a little bit.
authored
93 method at_pos($idx) {
94 nqp::lllist_get_at_pos(self, $idx.Int)
95 }
ac08da5 @jnthn [common] Add .defined methods to the various built-in types.
authored
96 method defined() {
97 nqp::repr_defined(self)
98 }
eae223f @jnthn Add a first cut of a P6list representation and a list sub that makes one...
authored
99 }
100
101 knowhow NQPArray is repr('P6list') {
7e36dac @jnthn Give NQPList a .new method.
authored
102 method new() {
103 nqp::instance_of(self.WHAT)
104 }
ea3a9cb @jnthn [common] Lists and arrays numify to number of elements.
authored
105 method Numeric() {
106 self.elems
107 }
7e36dac @jnthn Give NQPList a .new method.
authored
108 method elems() {
109 nqp::lllist_elems(self)
110 }
111 method at_pos($idx) {
112 nqp::lllist_get_at_pos(self, $idx.Int)
113 }
ebb368a @jnthn [common] NQPArray.bind_pos plus some missing coercion methods.
authored
114 method bind_pos($idx, $value) {
115 nqp::lllist_bind_at_pos(self, $idx.Int, $value)
116 }
ac08da5 @jnthn [common] Add .defined methods to the various built-in types.
authored
117 method defined() {
118 nqp::repr_defined(self)
119 }
eae223f @jnthn Add a first cut of a P6list representation and a list sub that makes one...
authored
120 }
121
435bd24 @jnthn [common] Stub in NQPHash. Doesn't do anything yet other that .new.
authored
122 knowhow NQPHash is repr('P6mapping') {
123 method new() {
124 nqp::instance_of(self.WHAT)
125 }
88190a8 @jnthn [common] Fill out NQPHash a bit and...we have basically functioning hash...
authored
126 method Numeric() {
127 self.elems
128 }
129 method elems() {
130 nqp::llmapping_elems(self)
131 }
132 method at_key($key) {
133 nqp::llmapping_get_at_key(self, $key.Str)
134 }
135 method bind_key($key, $value) {
136 nqp::llmapping_bind_at_key(self, $key.Str, $value)
137 }
ac08da5 @jnthn [common] Add .defined methods to the various built-in types.
authored
138 method defined() {
139 nqp::repr_defined(self)
140 }
435bd24 @jnthn [common] Stub in NQPHash. Doesn't do anything yet other that .new.
authored
141 }
142
3c156f0 @jnthn [common] Add a NQPCode with a leave method.
authored
143 knowhow NQPCode is repr('RakudoCodeRef') {
144 method leave($with) {
145 nqp::leave_block(self, $with)
146 }
ac08da5 @jnthn [common] Add .defined methods to the various built-in types.
authored
147 method defined() {
148 nqp::repr_defined(self)
149 }
3c156f0 @jnthn [common] Add a NQPCode with a leave method.
authored
150 }
151
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though we...
authored
152 ## XXX Need coercive Any fallbacks too.
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equality...
authored
153
413bae8 @jnthn [common] Replace explicit multi-dispatcher ops with a proto with a plain...
authored
154 proto sub &infix:<==>($x, $y) { * }
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though we...
authored
155 multi sub &infix:<==>(NQPInt $x, NQPInt $y) {
156 nqp::equal_ints($x, $y)
157 }
158 multi sub &infix:<==>(NQPNum $x, NQPNum $y) {
159 nqp::equal_nums($x, $y)
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equality...
authored
160 }
161
413bae8 @jnthn [common] Replace explicit multi-dispatcher ops with a proto with a plain...
authored
162 proto sub &infix:<!=>($x, $y) { * }
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though we...
authored
163 multi sub &infix:<!=>(NQPInt $x, NQPInt $y) {
dcf5ee5 @jnthn Make our != rather more efficient.
authored
164 nqp::logical_not_int(nqp::equal_ints($x, $y))
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though we...
authored
165 }
166 multi sub &infix:<!=>(NQPNum $x, NQPNum $y) {
dcf5ee5 @jnthn Make our != rather more efficient.
authored
167 nqp::logical_not_int(nqp::equal_nums($x, $y))
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equality...
authored
168 }
169
170 sub &infix:<eq>($x, $y) {
3881965 @jnthn Turns out that the always pass ops type object for result type stratergy...
authored
171 nqp::equal_strs($x.Str, $y.Str)
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equality...
authored
172 }
173
174 sub &infix:<ne>($x, $y) {
3881965 @jnthn Turns out that the always pass ops type object for result type stratergy...
authored
175 !nqp::equal_strs($x.Str, $y.Str)
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equality...
authored
176 }
177
98e707b @jnthn [common] =:=
authored
178 sub &infix:<=:=>($x, $y) {
179 nqp::equal_refs($x, $y)
180 }
181
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equality...
authored
182 sub &prefix:<!>($x) {
3881965 @jnthn Turns out that the always pass ops type object for result type stratergy...
authored
183 nqp::logical_not_int($x.Bool)
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equality...
authored
184 }
185
186 sub &prefix:<?>($x) {
187 $x.Bool
188 }
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
189
cf07e79 @jnthn [common] Some initial cuts of prefix + and ~, Stringy and Numeric in the...
authored
190 sub &prefix:<~>($x) {
191 $x.Stringy
192 }
193
194 sub &prefix:<+>($x) {
195 $x.Numeric
196 }
197
413bae8 @jnthn [common] Replace explicit multi-dispatcher ops with a proto with a plain...
authored
198 proto sub &infix:<+>($x, $y) { * }
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though we...
authored
199 multi sub &infix:<+>(NQPInt $x, NQPInt $y) {
200 nqp::add_int($x, $y);
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
201 }
202
413bae8 @jnthn [common] Replace explicit multi-dispatcher ops with a proto with a plain...
authored
203 proto sub &infix:<->($x, $y) { * }
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though we...
authored
204 multi sub &infix:<->(NQPInt $x, NQPInt $y) {
205 nqp::sub_int($x, $y);
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
206 }
207
413bae8 @jnthn [common] Replace explicit multi-dispatcher ops with a proto with a plain...
authored
208 proto sub &infix:<*>($x, $y) { * }
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though we...
authored
209 multi sub &infix:<*>(NQPInt $x, NQPInt $y) {
210 nqp::mul_int($x, $y);
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
211 }
212
413bae8 @jnthn [common] Replace explicit multi-dispatcher ops with a proto with a plain...
authored
213 proto sub &infix:</>($x, $y) { * }
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though we...
authored
214 multi sub &infix:</>(NQPInt $x, NQPInt $y) {
215 nqp::div_int($x, $y);
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
216 }
217
413bae8 @jnthn [common] Replace explicit multi-dispatcher ops with a proto with a plain...
authored
218 proto sub &infix:<%>($x, $y) { * }
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though we...
authored
219 multi sub &infix:<%>(NQPInt $x, NQPInt $y) {
220 nqp::mod_int($x, $y);
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
221 }
222
223 sub &infix:<~>($x, $y) {
3881965 @jnthn Turns out that the always pass ops type object for result type stratergy...
authored
224 nqp::concat($x.Str, $y.Str);
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
225 }
a64ea75 @jnthn Implement plan and ok for getting us more tests.
authored
226
6a07cb2 @jnthn [common] Stub in a simple NQPException exception object and a die sub.
authored
227 # A basic, fairly bare-bones exception object.
228 knowhow NQPException {
229 has $!message;
230 has $!resumable;
231
232 method new($message) {
233 nqp::instance_of(self.WHAT).BUILD(:message($message))
234 }
235
236 method BUILD(:$message) {
237 $!message := $message;
238 $!resumable := 0;
239 self;
240 }
241
ac08da5 @jnthn [common] Add .defined methods to the various built-in types.
authored
242 method defined() {
243 nqp::repr_defined(self)
244 }
245
6a07cb2 @jnthn [common] Stub in a simple NQPException exception object and a die sub.
authored
246 method resumable() {
247 $!resumable
248 }
249
250 method resume() {
251 $!resumable := 1;
252 }
253
254 method Str() {
255 $!message
256 }
257 }
258
259 sub die($message) {
260 nqp::throw_dynamic(NQPException.new($message), 0)
261 }
262
a64ea75 @jnthn Implement plan and ok for getting us more tests.
authored
263 # For tests.
264 my $count := NQPInt.new();
265 sub plan($n) {
266 print("1..");
267 say($n);
268 }
7e9d2b8 @jnthn [common] $diag arg of ok should be optional.
authored
269 sub ok($check, $diag?) {
a64ea75 @jnthn Implement plan and ok for getting us more tests.
authored
270 $count := $count + 1;
271 unless $check { print("not ") }
272 print("ok ");
273 say($count);
274 }
cbdd49b @jnthn [dotnet] Out with one bad hack, in with a slightly less bad one for unde...
authored
275
06d78a2 @jnthn [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
276 # Here comes the start of a heavily under construction ClassHOW.
277 knowhow NQPClassHOW {
278 ##
279 ## Attributes
280 ##
281
282 # Name of the class.
283 has $!name;
284
285 # Attributes, methods, parents and roles directly added.
286 has %!attributes;
287 has %!methods;
288 has @!parents;
289 has @!roles;
290
291 # Vtable and mapping of method names to slots.
292 has @!vtable;
293 has %!method-vtable-slots;
294
295 # Have we been composed?
296 has $!composed;
297
298 # Cached MRO (list of the type objects).
299 has @!mro;
300
301 # Full list of roles that we do.
302 has @!done;
303
304 ##
305 ## Declarative.
306 ##
307
308 # Creates a new instance of this meta-class.
309 method new() {
310 nqp::instance_of(self).BUILD()
311 }
312
313 method BUILD() {
314 $!composed := 0;
4356d78 @jnthn [common] Add a VERY hacky but working version of method addition and dis...
authored
315 %!methods := NQPHash.new;
06d78a2 @jnthn [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
316 self;
317 }
318
319 # Create a new meta-class instance, and then a new type object
320 # to go with it, and return that.
321 # XXX TODO :$repr named parameter defaulting to P6opaque (don't
322 # have default values yet implemented).
323 method new_type() {
324 my $metaclass := self.new();
325 nqp::type_object_for($metaclass, 'P6opaque');
326 }
327
4356d78 @jnthn [common] Add a VERY hacky but working version of method addition and dis...
authored
328 method add_method($obj, $name, $code_obj) {
329 # XXX TODO This crashes due to lack of auto-viv. :/
330 #if %!methods{$name} {
331 # die("This class already has a method named " ~ $name);
332 #}
333 %!methods{$name} := $code_obj;
334 }
335
06d78a2 @jnthn [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
336 method compose($obj) {
337 # XXX TODO: Compose roles, compose attributes.
338
339 # Some things we only do if we weren't already composed once, like
340 # building the MRO.
341 unless $!composed {
342 @!mro := compute_c3_mro($obj);
343 $!composed := 1;
344 }
345
346 $obj
347 }
348
349 # XXX TODO: Get enough working to bring over the C3 implementation that
350 # we run on 6model on Parrot.
351 sub compute_c3_mro($obj) {
352 my @mro;
353 @mro[0] := $obj;
354 @mro;
355 }
4356d78 @jnthn [common] Add a VERY hacky but working version of method addition and dis...
authored
356
357 ##
358 ## Introspecty
359 ##
360
361 method method_table($obj) {
362 %!methods
363 }
364
ac08da5 @jnthn [common] Add .defined methods to the various built-in types.
authored
365 method defined() {
366 nqp::repr_defined(self)
367 }
368
4356d78 @jnthn [common] Add a VERY hacky but working version of method addition and dis...
authored
369 ##
370 ## Dispatchy
371 ##
372
373 method find_method($obj, $name) {
374 # XXX TODO Epic cheat, replace with that's in the ClassHOW that we
375 # run on Parrot. Needs auto-viv, .defined, return.
376 my %meths := @!mro[0].HOW.method_table($obj);
377 %meths{$name}
378 }
06d78a2 @jnthn [common] Start to stub in a very barebones ClassHOW. This is enough that...
authored
379 }
380
cbdd49b @jnthn [dotnet] Out with one bad hack, in with a slightly less bad one for unde...
authored
381 # XXX Bad hack, we'll replace this later.
382 knowhow Any {
383 }
4f3c7e0 @jnthn [common] Set up a GLOBAL.
authored
384
385 # GLOBAL stash.
386 # (XXX Really want one per compilation unit and unify, but this will get us
387 # started. Also really want a stash type that knows its name rather than just
388 # a hash, I guess.)
389 ::GLOBAL := NQPHash.new();
Something went wrong with that request. Please try again.