1// Generated automatically from src/vm/wren_core.wren. Do not edit.
2static const char* coreModuleSource =
3"class Bool {}\n"
4"class Fiber {}\n"
5"class Fn {}\n"
6"class Null {}\n"
7"class Num {}\n"
8"\n"
9"class Sequence {\n"
10" all(f) {\n"
11" var result = true\n"
12" for (element in this) {\n"
13" result = f.call(element)\n"
14" if (!result) return result\n"
15" }\n"
16" return result\n"
17" }\n"
18"\n"
19" any(f) {\n"
20" var result = false\n"
21" for (element in this) {\n"
22" result = f.call(element)\n"
23" if (result) return result\n"
24" }\n"
25" return result\n"
26" }\n"
27"\n"
28" contains(element) {\n"
29" for (item in this) {\n"
30" if (element == item) return true\n"
31" }\n"
32" return false\n"
33" }\n"
34"\n"
35" count {\n"
36" var result = 0\n"
37" for (element in this) {\n"
38" result = result + 1\n"
39" }\n"
40" return result\n"
41" }\n"
42"\n"
43" count(f) {\n"
44" var result = 0\n"
45" for (element in this) {\n"
46" if (f.call(element)) result = result + 1\n"
47" }\n"
48" return result\n"
49" }\n"
50"\n"
51" each(f) {\n"
52" for (element in this) {\n"
53" f.call(element)\n"
54" }\n"
55" }\n"
56"\n"
57" isEmpty { iterate(null) ? false : true }\n"
58"\n"
59" map(transformation) { MapSequence.new(this, transformation) }\n"
60"\n"
61" skip(count) {\n"
62" if (!(count is Num) || !count.isInteger || count < 0) {\n"
63" Fiber.abort(\"Count must be a non-negative integer.\")\n"
64" }\n"
65"\n"
66" return SkipSequence.new(this, count)\n"
67" }\n"
68"\n"
69" take(count) {\n"
70" if (!(count is Num) || !count.isInteger || count < 0) {\n"
71" Fiber.abort(\"Count must be a non-negative integer.\")\n"
72" }\n"
73"\n"
74" return TakeSequence.new(this, count)\n"
75" }\n"
76"\n"
77" where(predicate) { WhereSequence.new(this, predicate) }\n"
78"\n"
79" reduce(acc, f) {\n"
80" for (element in this) {\n"
81" acc = f.call(acc, element)\n"
82" }\n"
83" return acc\n"
84" }\n"
85"\n"
86" reduce(f) {\n"
87" var iter = iterate(null)\n"
88" if (!iter) Fiber.abort(\"Can't reduce an empty sequence.\")\n"
89"\n"
90" // Seed with the first element.\n"
91" var result = iteratorValue(iter)\n"
92" while (iter = iterate(iter)) {\n"
93" result = f.call(result, iteratorValue(iter))\n"
94" }\n"
95"\n"
96" return result\n"
97" }\n"
98"\n"
99" join() { join(\"\") }\n"
100"\n"
101" join(sep) {\n"
102" var first = true\n"
103" var result = \"\"\n"
104"\n"
105" for (element in this) {\n"
106" if (!first) result = result + sep\n"
107" first = false\n"
108" result = result + element.toString\n"
109" }\n"
110"\n"
111" return result\n"
112" }\n"
113"\n"
114" toList {\n"
115" var result = List.new()\n"
116" for (element in this) {\n"
117" result.add(element)\n"
118" }\n"
119" return result\n"
120" }\n"
121"}\n"
122"\n"
123"class MapSequence is Sequence {\n"
124" construct new(sequence, fn) {\n"
125" _sequence = sequence\n"
126" _fn = fn\n"
127" }\n"
128"\n"
129" iterate(iterator) { _sequence.iterate(iterator) }\n"
130" iteratorValue(iterator) { _fn.call(_sequence.iteratorValue(iterator)) }\n"
131"}\n"
132"\n"
133"class SkipSequence is Sequence {\n"
134" construct new(sequence, count) {\n"
135" _sequence = sequence\n"
136" _count = count\n"
137" }\n"
138"\n"
139" iterate(iterator) {\n"
140" if (iterator) {\n"
141" return _sequence.iterate(iterator)\n"
142" } else {\n"
143" iterator = _sequence.iterate(iterator)\n"
144" var count = _count\n"
145" while (count > 0 && iterator) {\n"
146" iterator = _sequence.iterate(iterator)\n"
147" count = count - 1\n"
148" }\n"
149" return iterator\n"
150" }\n"
151" }\n"
152"\n"
153" iteratorValue(iterator) { _sequence.iteratorValue(iterator) }\n"
154"}\n"
155"\n"
156"class TakeSequence is Sequence {\n"
157" construct new(sequence, count) {\n"
158" _sequence = sequence\n"
159" _count = count\n"
160" }\n"
161"\n"
162" iterate(iterator) {\n"
163" if (!iterator) _taken = 1 else _taken = _taken + 1\n"
164" return _taken > _count ? null : _sequence.iterate(iterator)\n"
165" }\n"
166"\n"
167" iteratorValue(iterator) { _sequence.iteratorValue(iterator) }\n"
168"}\n"
169"\n"
170"class WhereSequence is Sequence {\n"
171" construct new(sequence, fn) {\n"
172" _sequence = sequence\n"
173" _fn = fn\n"
174" }\n"
175"\n"
176" iterate(iterator) {\n"
177" while (iterator = _sequence.iterate(iterator)) {\n"
178" if (_fn.call(_sequence.iteratorValue(iterator))) break\n"
179" }\n"
180" return iterator\n"
181" }\n"
182"\n"
183" iteratorValue(iterator) { _sequence.iteratorValue(iterator) }\n"
184"}\n"
185"\n"
186"class String is Sequence {\n"
187" bytes { StringByteSequence.new(this) }\n"
188" codePoints { StringCodePointSequence.new(this) }\n"
189"\n"
190" split(delimiter) {\n"
191" if (!(delimiter is String) || delimiter.isEmpty) {\n"
192" Fiber.abort(\"Delimiter must be a non-empty string.\")\n"
193" }\n"
194"\n"
195" var result = []\n"
196"\n"
197" var last = 0\n"
198" var index = 0\n"
199"\n"
200" var delimSize = delimiter.byteCount_\n"
201" var size = byteCount_\n"
202"\n"
203" while (last < size && (index = indexOf(delimiter, last)) != -1) {\n"
204" result.add(this[last...index])\n"
205" last = index + delimSize\n"
206" }\n"
207"\n"
208" if (last < size) {\n"
209" result.add(this[last..-1])\n"
210" } else {\n"
211" result.add(\"\")\n"
212" }\n"
213" return result\n"
214" }\n"
215"\n"
216" replace(from, to) {\n"
217" if (!(from is String) || from.isEmpty) {\n"
218" Fiber.abort(\"From must be a non-empty string.\")\n"
219" } else if (!(to is String)) {\n"
220" Fiber.abort(\"To must be a string.\")\n"
221" }\n"
222"\n"
223" var result = \"\"\n"
224"\n"
225" var last = 0\n"
226" var index = 0\n"
227"\n"
228" var fromSize = from.byteCount_\n"
229" var size = byteCount_\n"
230"\n"
231" while (last < size && (index = indexOf(from, last)) != -1) {\n"
232" result = result + this[last...index] + to\n"
233" last = index + fromSize\n"
234" }\n"
235"\n"
236" if (last < size) result = result + this[last..-1]\n"
237"\n"
238" return result\n"
239" }\n"
240"\n"
241" trim() { trim_(\"\t\r\n \", true, true) }\n"
242" trim(chars) { trim_(chars, true, true) }\n"
243" trimEnd() { trim_(\"\t\r\n \", false, true) }\n"
244" trimEnd(chars) { trim_(chars, false, true) }\n"
245" trimStart() { trim_(\"\t\r\n \", true, false) }\n"
246" trimStart(chars) { trim_(chars, true, false) }\n"
247"\n"
248" trim_(chars, trimStart, trimEnd) {\n"
249" if (!(chars is String)) {\n"
250" Fiber.abort(\"Characters must be a string.\")\n"
251" }\n"
252"\n"
253" var codePoints = chars.codePoints.toList\n"
254"\n"
255" var start\n"
256" if (trimStart) {\n"
257" while (start = iterate(start)) {\n"
258" if (!codePoints.contains(codePointAt_(start))) break\n"
259" }\n"
260"\n"
261" if (start == false) return \"\"\n"
262" } else {\n"
263" start = 0\n"
264" }\n"
265"\n"
266" var end\n"
267" if (trimEnd) {\n"
268" end = byteCount_ - 1\n"
269" while (end >= start) {\n"
270" var codePoint = codePointAt_(end)\n"
271" if (codePoint != -1 && !codePoints.contains(codePoint)) break\n"
272" end = end - 1\n"
273" }\n"
274"\n"
275" if (end < start) return \"\"\n"
276" } else {\n"
277" end = -1\n"
278" }\n"
279"\n"
280" return this[start..end]\n"
281" }\n"
282"\n"
283" *(count) {\n"
284" if (!(count is Num) || !count.isInteger || count < 0) {\n"
285" Fiber.abort(\"Count must be a non-negative integer.\")\n"
286" }\n"
287"\n"
288" var result = \"\"\n"
289" for (i in 0...count) {\n"
290" result = result + this\n"
291" }\n"
292" return result\n"
293" }\n"
294"}\n"
295"\n"
296"class StringByteSequence is Sequence {\n"
297" construct new(string) {\n"
298" _string = string\n"
299" }\n"
300"\n"
301" [index] { _string.byteAt_(index) }\n"
302" iterate(iterator) { _string.iterateByte_(iterator) }\n"
303" iteratorValue(iterator) { _string.byteAt_(iterator) }\n"
304"\n"
305" count { _string.byteCount_ }\n"
306"}\n"
307"\n"
308"class StringCodePointSequence is Sequence {\n"
309" construct new(string) {\n"
310" _string = string\n"
311" }\n"
312"\n"
313" [index] { _string.codePointAt_(index) }\n"
314" iterate(iterator) { _string.iterate(iterator) }\n"
315" iteratorValue(iterator) { _string.codePointAt_(iterator) }\n"
316"\n"
317" count { _string.count }\n"
318"}\n"
319"\n"
320"class List is Sequence {\n"
321" addAll(other) {\n"
322" for (element in other) {\n"
323" add(element)\n"
324" }\n"
325" return other\n"
326" }\n"
327"\n"
328" sort() { sort {|low, high| low < high } }\n"
329"\n"
330" sort(comparer) {\n"
331" if (!(comparer is Fn)) {\n"
332" Fiber.abort(\"Comparer must be a function.\")\n"
333" }\n"
334" quicksort_(0, count - 1, comparer)\n"
335" return this\n"
336" }\n"
337"\n"
338" quicksort_(low, high, comparer) {\n"
339" if (low < high) {\n"
340" var p = partition_(low, high, comparer)\n"
341" quicksort_(low, p - 1, comparer)\n"
342" quicksort_(p + 1, high, comparer)\n"
343" }\n"
344" }\n"
345"\n"
346" partition_(low, high, comparer) {\n"
347" var p = this[high]\n"
348" var i = low - 1\n"
349" for (j in low..(high-1)) {\n"
350" if (comparer.call(this[j], p)) { \n"
351" i = i + 1\n"
352" var t = this[i]\n"
353" this[i] = this[j]\n"
354" this[j] = t\n"
355" }\n"
356" }\n"
357" var t = this[i+1]\n"
358" this[i+1] = this[high]\n"
359" this[high] = t\n"
360" return i+1\n"
361" }\n"
362"\n"
363" toString { \"[%(join(\", \"))]\" }\n"
364"\n"
365" +(other) {\n"
366" var result = this[0..-1]\n"
367" for (element in other) {\n"
368" result.add(element)\n"
369" }\n"
370" return result\n"
371" }\n"
372"\n"
373" *(count) {\n"
374" if (!(count is Num) || !count.isInteger || count < 0) {\n"
375" Fiber.abort(\"Count must be a non-negative integer.\")\n"
376" }\n"
377"\n"
378" var result = []\n"
379" for (i in 0...count) {\n"
380" result.addAll(this)\n"
381" }\n"
382" return result\n"
383" }\n"
384"}\n"
385"\n"
386"class Map is Sequence {\n"
387" keys { MapKeySequence.new(this) }\n"
388" values { MapValueSequence.new(this) }\n"
389"\n"
390" toString {\n"
391" var first = true\n"
392" var result = \"{\"\n"
393"\n"
394" for (key in keys) {\n"
395" if (!first) result = result + \", \"\n"
396" first = false\n"
397" result = result + \"%(key): %(this[key])\"\n"
398" }\n"
399"\n"
400" return result + \"}\"\n"
401" }\n"
402"\n"
403" iteratorValue(iterator) {\n"
404" return MapEntry.new(\n"
405" keyIteratorValue_(iterator),\n"
406" valueIteratorValue_(iterator))\n"
407" }\n"
408"}\n"
409"\n"
410"class MapEntry {\n"
411" construct new(key, value) {\n"
412" _key = key\n"
413" _value = value\n"
414" }\n"
415"\n"
416" key { _key }\n"
417" value { _value }\n"
418"\n"
419" toString { \"%(_key):%(_value)\" }\n"
420"}\n"
421"\n"
422"class MapKeySequence is Sequence {\n"
423" construct new(map) {\n"
424" _map = map\n"
425" }\n"
426"\n"
427" iterate(n) { _map.iterate(n) }\n"
428" iteratorValue(iterator) { _map.keyIteratorValue_(iterator) }\n"
429"}\n"
430"\n"
431"class MapValueSequence is Sequence {\n"
432" construct new(map) {\n"
433" _map = map\n"
434" }\n"
435"\n"
436" iterate(n) { _map.iterate(n) }\n"
437" iteratorValue(iterator) { _map.valueIteratorValue_(iterator) }\n"
438"}\n"
439"\n"
440"class Range is Sequence {}\n"
441"\n"
442"class System {\n"
443" static print() {\n"
444" writeString_(\"\n\")\n"
445" }\n"
446"\n"
447" static print(obj) {\n"
448" writeObject_(obj)\n"
449" writeString_(\"\n\")\n"
450" return obj\n"
451" }\n"
452"\n"
453" static printAll(sequence) {\n"
454" for (object in sequence) writeObject_(object)\n"
455" writeString_(\"\n\")\n"
456" }\n"
457"\n"
458" static write(obj) {\n"
459" writeObject_(obj)\n"
460" return obj\n"
461" }\n"
462"\n"
463" static writeAll(sequence) {\n"
464" for (object in sequence) writeObject_(object)\n"
465" }\n"
466"\n"
467" static writeObject_(obj) {\n"
468" var string = obj.toString\n"
469" if (string is String) {\n"
470" writeString_(string)\n"
471" } else {\n"
472" writeString_(\"[invalid toString]\")\n"
473" }\n"
474" }\n"
475"}\n"
476"\n"
477"class ClassAttributes {\n"
478" self { _attributes }\n"
479" methods { _methods }\n"
480" construct new(attributes, methods) {\n"
481" _attributes = attributes\n"
482" _methods = methods\n"
483" }\n"
484" toString { \"attributes:%(_attributes) methods:%(_methods)\" }\n"
485"}\n";
486
487