Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 211 lines (188 sloc) 4.373 kB
3e7ec36 @jnthn A little setting re-ordering; put NQPStr first, since we need strings…
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 equal…
authored
5 method Bool() {
3881965 @jnthn Turns out that the always pass ops type object for result type strate…
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 equal…
authored
8 }
cf07e79 @jnthn [common] Some initial cuts of prefix + and ~, Stringy and Numeric in …
authored
9 method Numeric() {
10 nqp::coerce_str_to_num(self, NQPNum)
11 }
8c6b5ae @jnthn Add Str methods to setting for NQPNum and NQPInt.
authored
12 method Str() {
3e7ec36 @jnthn A little setting re-ordering; put NQPStr first, since we need strings…
authored
13 self
8c6b5ae @jnthn Add Str methods to setting for NQPNum and NQPInt.
authored
14 }
cf07e79 @jnthn [common] Some initial cuts of prefix + and ~, Stringy and Numeric in …
authored
15 method Stringy() {
16 self
17 }
2f806d3 @jnthn Here starteth the NQP setting.
authored
18 }
19
3e7ec36 @jnthn A little setting re-ordering; put NQPStr first, since we need strings…
authored
20 knowhow NQPInt is repr('P6int') {
2f806d3 @jnthn Here starteth the NQP setting.
authored
21 method new() {
22 nqp::instance_of(self.WHAT);
23 }
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equal…
authored
24 method Bool() {
3881965 @jnthn Turns out that the always pass ops type object for result type strate…
authored
25 nqp::logical_not_int(nqp::equal_ints(self, 0))
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equal…
authored
26 }
3e7ec36 @jnthn A little setting re-ordering; put NQPStr first, since we need strings…
authored
27 method Int() {
2f806d3 @jnthn Here starteth the NQP setting.
authored
28 self
29 }
3e7ec36 @jnthn A little setting re-ordering; put NQPStr first, since we need strings…
authored
30 method Num() {
31 nqp::coerce_int_to_num(self, NQPNum)
32 }
cf07e79 @jnthn [common] Some initial cuts of prefix + and ~, Stringy and Numeric in …
authored
33 method Numeric() {
34 self
35 }
3e7ec36 @jnthn A little setting re-ordering; put NQPStr first, since we need strings…
authored
36 method Str() {
37 nqp::coerce_int_to_str(self, NQPStr)
38 }
cf07e79 @jnthn [common] Some initial cuts of prefix + and ~, Stringy and Numeric in …
authored
39 method Stringy() {
40 nqp::coerce_int_to_str(self, NQPStr)
41 }
2f806d3 @jnthn Here starteth the NQP setting.
authored
42 }
43
44 knowhow NQPNum is repr('P6num') {
45 method new() {
46 nqp::instance_of(self.WHAT);
47 }
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equal…
authored
48 method Bool() {
3881965 @jnthn Turns out that the always pass ops type object for result type strate…
authored
49 nqp::logical_not_int(nqp::equal_nums(self, 0.0))
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equal…
authored
50 }
51 method Int() {
52 nqp::coerce_num_to_int(self, NQPStr)
53 }
2f806d3 @jnthn Here starteth the NQP setting.
authored
54 method Num() {
55 self
56 }
cf07e79 @jnthn [common] Some initial cuts of prefix + and ~, Stringy and Numeric in …
authored
57 method Numeric() {
58 self
59 }
8c6b5ae @jnthn Add Str methods to setting for NQPNum and NQPInt.
authored
60 method Str() {
61 nqp::coerce_num_to_str(self, NQPStr)
62 }
cf07e79 @jnthn [common] Some initial cuts of prefix + and ~, Stringy and Numeric in …
authored
63 method Stringy() {
64 nqp::coerce_num_to_str(self, NQPStr)
65 }
2f806d3 @jnthn Here starteth the NQP setting.
authored
66 }
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equal…
authored
67
eae223f @jnthn Add a first cut of a P6list representation and a list sub that makes …
authored
68 knowhow NQPList is repr('P6list') {
7e36dac @jnthn Give NQPList a .new method.
authored
69 method new() {
70 nqp::instance_of(self.WHAT)
71 }
d88a87b @jnthn Flesh out NQPList a little bit.
authored
72 method elems() {
73 nqp::lllist_elems(self)
74 }
ea3a9cb @jnthn [common] Lists and arrays numify to number of elements.
authored
75 method Numeric() {
76 self.elems
77 }
d88a87b @jnthn Flesh out NQPList a little bit.
authored
78 method at_pos($idx) {
79 nqp::lllist_get_at_pos(self, $idx.Int)
80 }
eae223f @jnthn Add a first cut of a P6list representation and a list sub that makes …
authored
81 }
82
83 knowhow NQPArray is repr('P6list') {
7e36dac @jnthn Give NQPList a .new method.
authored
84 method new() {
85 nqp::instance_of(self.WHAT)
86 }
ea3a9cb @jnthn [common] Lists and arrays numify to number of elements.
authored
87 method Numeric() {
88 self.elems
89 }
7e36dac @jnthn Give NQPList a .new method.
authored
90 method elems() {
91 nqp::lllist_elems(self)
92 }
93 method at_pos($idx) {
94 nqp::lllist_get_at_pos(self, $idx.Int)
95 }
eae223f @jnthn Add a first cut of a P6list representation and a list sub that makes …
authored
96 }
97
b2f3bac @jnthn Add a (very primitive) KnowHOWAttribute knowhow to the setting, so we…
authored
98 # This is a little bit of a cheat. We only really need to keep
99 # hold of a name for the most basic attribute class, so we just
100 # use the string representation.
101 knowhow KnowHOWAttribute is repr('P6str') {
102 method new(:$name) {
103 nqp::box_str(nqp::unbox_str($name), KnowHOWAttribute)
104 }
105 method name() {
106 nqp::box_str(nqp::unbox_str(self), NQPStr)
107 }
108 }
109
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though…
authored
110 ## XXX Need coercive Any fallbacks too.
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equal…
authored
111
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though…
authored
112 proto sub &infix:<==>($x, $y) {
113 nqp::multi_dispatch_over_lexical_candidates("&infix:<==>");
114 }
115 multi sub &infix:<==>(NQPInt $x, NQPInt $y) {
116 nqp::equal_ints($x, $y)
117 }
118 multi sub &infix:<==>(NQPNum $x, NQPNum $y) {
119 nqp::equal_nums($x, $y)
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equal…
authored
120 }
121
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though…
authored
122 proto sub &infix:<!=>($x, $y) {
123 nqp::multi_dispatch_over_lexical_candidates("&infix:<!=>");
124 }
125 multi sub &infix:<!=>(NQPInt $x, NQPInt $y) {
dcf5ee5 @jnthn Make our != rather more efficient.
authored
126 nqp::logical_not_int(nqp::equal_ints($x, $y))
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though…
authored
127 }
128 multi sub &infix:<!=>(NQPNum $x, NQPNum $y) {
dcf5ee5 @jnthn Make our != rather more efficient.
authored
129 nqp::logical_not_int(nqp::equal_nums($x, $y))
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equal…
authored
130 }
131
132 sub &infix:<eq>($x, $y) {
3881965 @jnthn Turns out that the always pass ops type object for result type strate…
authored
133 nqp::equal_strs($x.Str, $y.Str)
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equal…
authored
134 }
135
136 sub &infix:<ne>($x, $y) {
3881965 @jnthn Turns out that the always pass ops type object for result type strate…
authored
137 !nqp::equal_strs($x.Str, $y.Str)
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equal…
authored
138 }
139
98e707b @jnthn [common] =:=
authored
140 sub &infix:<=:=>($x, $y) {
141 nqp::equal_refs($x, $y)
142 }
143
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equal…
authored
144 sub &prefix:<!>($x) {
3881965 @jnthn Turns out that the always pass ops type object for result type strate…
authored
145 nqp::logical_not_int($x.Bool)
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equal…
authored
146 }
147
148 sub &prefix:<?>($x) {
149 $x.Bool
150 }
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
151
cf07e79 @jnthn [common] Some initial cuts of prefix + and ~, Stringy and Numeric in …
authored
152 sub &prefix:<~>($x) {
153 $x.Stringy
154 }
155
156 sub &prefix:<+>($x) {
157 $x.Numeric
158 }
159
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though…
authored
160 proto sub &infix:<+>($x, $y) {
161 nqp::multi_dispatch_over_lexical_candidates("&infix:<+>");
162 }
163 multi sub &infix:<+>(NQPInt $x, NQPInt $y) {
164 nqp::add_int($x, $y);
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
165 }
166
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though…
authored
167 proto sub &infix:<->($x, $y) {
168 nqp::multi_dispatch_over_lexical_candidates("&infix:<->");
169 }
170 multi sub &infix:<->(NQPInt $x, NQPInt $y) {
171 nqp::sub_int($x, $y);
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
172 }
173
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though…
authored
174 proto sub &infix:<*>($x, $y) {
175 nqp::multi_dispatch_over_lexical_candidates("&infix:<*>");
176 }
177 multi sub &infix:<*>(NQPInt $x, NQPInt $y) {
178 nqp::mul_int($x, $y);
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
179 }
180
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though…
authored
181 proto sub &infix:</>($x, $y) {
182 nqp::multi_dispatch_over_lexical_candidates("&infix:</>");
183 }
184 multi sub &infix:</>(NQPInt $x, NQPInt $y) {
185 nqp::div_int($x, $y);
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
186 }
187
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though…
authored
188 proto sub &infix:<%>($x, $y) {
189 nqp::multi_dispatch_over_lexical_candidates("&infix:<%>");
190 }
191 multi sub &infix:<%>(NQPInt $x, NQPInt $y) {
192 nqp::mod_int($x, $y);
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
193 }
194
195 sub &infix:<~>($x, $y) {
3881965 @jnthn Turns out that the always pass ops type object for result type strate…
authored
196 nqp::concat($x.Str, $y.Str);
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
197 }
a64ea75 @jnthn Implement plan and ok for getting us more tests.
authored
198
199 # For tests.
200 my $count := NQPInt.new();
201 sub plan($n) {
202 print("1..");
203 say($n);
204 }
3396e97 @jnthn Couple of fixes - ok needs a $diag arg and '0' should be false.
authored
205 sub ok($check, $diag) {
a64ea75 @jnthn Implement plan and ok for getting us more tests.
authored
206 $count := $count + 1;
207 unless $check { print("not ") }
208 print("ok ");
209 say($count);
210 }
Something went wrong with that request. Please try again.