Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 189 lines (167 sloc) 3.959 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 }
cf07e79 @jnthn [common] Some initial cuts of prefix + and ~, Stringy and Numeric in the...
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 ea...
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 the...
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 ea...
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 equality...
authored
24 method Bool() {
3881965 @jnthn Turns out that the always pass ops type object for result type stratergy...
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 equality...
authored
26 }
3e7ec36 @jnthn A little setting re-ordering; put NQPStr first, since we need strings ea...
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 ea...
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 the...
authored
33 method Numeric() {
34 self
35 }
3e7ec36 @jnthn A little setting re-ordering; put NQPStr first, since we need strings ea...
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 the...
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 equality...
authored
48 method Bool() {
3881965 @jnthn Turns out that the always pass ops type object for result type stratergy...
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 equality...
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 the...
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 the...
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 equality...
authored
67
eae223f @jnthn Add a first cut of a P6list representation and a list sub that makes one...
authored
68 knowhow NQPList is repr('P6list') {
d88a87b @jnthn Flesh out NQPList a little bit.
authored
69 method elems() {
70 nqp::lllist_elems(self)
71 }
72 method at_pos($idx) {
73 nqp::lllist_get_at_pos(self, $idx.Int)
74 }
eae223f @jnthn Add a first cut of a P6list representation and a list sub that makes one...
authored
75 }
76
77 knowhow NQPArray is repr('P6list') {
78 }
79
b2f3bac @jnthn Add a (very primitive) KnowHOWAttribute knowhow to the setting, so we ca...
authored
80 # This is a little bit of a cheat. We only really need to keep
81 # hold of a name for the most basic attribute class, so we just
82 # use the string representation.
83 knowhow KnowHOWAttribute is repr('P6str') {
84 method new(:$name) {
85 nqp::box_str(nqp::unbox_str($name), KnowHOWAttribute)
86 }
87 method name() {
88 nqp::box_str(nqp::unbox_str(self), NQPStr)
89 }
90 }
91
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though we...
authored
92 ## XXX Need coercive Any fallbacks too.
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equality...
authored
93
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though we...
authored
94 proto sub &infix:<==>($x, $y) {
95 nqp::multi_dispatch_over_lexical_candidates("&infix:<==>");
96 }
97 multi sub &infix:<==>(NQPInt $x, NQPInt $y) {
98 nqp::equal_ints($x, $y)
99 }
100 multi sub &infix:<==>(NQPNum $x, NQPNum $y) {
101 nqp::equal_nums($x, $y)
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equality...
authored
102 }
103
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though we...
authored
104 proto sub &infix:<!=>($x, $y) {
105 nqp::multi_dispatch_over_lexical_candidates("&infix:<!=>");
106 }
107 multi sub &infix:<!=>(NQPInt $x, NQPInt $y) {
dcf5ee5 @jnthn Make our != rather more efficient.
authored
108 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
109 }
110 multi sub &infix:<!=>(NQPNum $x, NQPNum $y) {
dcf5ee5 @jnthn Make our != rather more efficient.
authored
111 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
112 }
113
114 sub &infix:<eq>($x, $y) {
3881965 @jnthn Turns out that the always pass ops type object for result type stratergy...
authored
115 nqp::equal_strs($x.Str, $y.Str)
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equality...
authored
116 }
117
118 sub &infix:<ne>($x, $y) {
3881965 @jnthn Turns out that the always pass ops type object for result type stratergy...
authored
119 !nqp::equal_strs($x.Str, $y.Str)
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equality...
authored
120 }
121
122 sub &prefix:<!>($x) {
3881965 @jnthn Turns out that the always pass ops type object for result type stratergy...
authored
123 nqp::logical_not_int($x.Bool)
5e82e89 @jnthn Fill out the setting with some more coercioin methods and a few equality...
authored
124 }
125
126 sub &prefix:<?>($x) {
127 $x.Bool
128 }
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
129
cf07e79 @jnthn [common] Some initial cuts of prefix + and ~, Stringy and Numeric in the...
authored
130 sub &prefix:<~>($x) {
131 $x.Stringy
132 }
133
134 sub &prefix:<+>($x) {
135 $x.Numeric
136 }
137
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though we...
authored
138 proto sub &infix:<+>($x, $y) {
139 nqp::multi_dispatch_over_lexical_candidates("&infix:<+>");
140 }
141 multi sub &infix:<+>(NQPInt $x, NQPInt $y) {
142 nqp::add_int($x, $y);
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
143 }
144
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though we...
authored
145 proto sub &infix:<->($x, $y) {
146 nqp::multi_dispatch_over_lexical_candidates("&infix:<->");
147 }
148 multi sub &infix:<->(NQPInt $x, NQPInt $y) {
149 nqp::sub_int($x, $y);
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
150 }
151
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though we...
authored
152 proto sub &infix:<*>($x, $y) {
153 nqp::multi_dispatch_over_lexical_candidates("&infix:<*>");
154 }
155 multi sub &infix:<*>(NQPInt $x, NQPInt $y) {
156 nqp::mul_int($x, $y);
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
157 }
158
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though we...
authored
159 proto sub &infix:</>($x, $y) {
160 nqp::multi_dispatch_over_lexical_candidates("&infix:</>");
161 }
162 multi sub &infix:</>(NQPInt $x, NQPInt $y) {
163 nqp::div_int($x, $y);
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
164 }
165
10019ac @jnthn Start to add multi variants to the NQPSetting. Seems that even though we...
authored
166 proto sub &infix:<%>($x, $y) {
167 nqp::multi_dispatch_over_lexical_candidates("&infix:<%>");
168 }
169 multi sub &infix:<%>(NQPInt $x, NQPInt $y) {
170 nqp::mod_int($x, $y);
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
171 }
172
173 sub &infix:<~>($x, $y) {
3881965 @jnthn Turns out that the always pass ops type object for result type stratergy...
authored
174 nqp::concat($x.Str, $y.Str);
d3865c1 @jnthn Add some more operators to the NQP setting.
authored
175 }
a64ea75 @jnthn Implement plan and ok for getting us more tests.
authored
176
177 # For tests.
178 my $count := NQPInt.new();
179 sub plan($n) {
180 print("1..");
181 say($n);
182 }
3396e97 @jnthn Couple of fixes - ok needs a $diag arg and '0' should be false.
authored
183 sub ok($check, $diag) {
a64ea75 @jnthn Implement plan and ok for getting us more tests.
authored
184 $count := $count + 1;
185 unless $check { print("not ") }
186 print("ok ");
187 say($count);
188 }
Something went wrong with that request. Please try again.