pure-dango 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,371 @@
1
+ class process
2
+ {
3
+ exit(code)
4
+ kill(code ? code : 0)
5
+
6
+ cwd()
7
+ return getcwd();
8
+
9
+ argv()
10
+ return getargv();
11
+
12
+ env(x)
13
+ return getenv(x);
14
+
15
+ pid()
16
+ return getpid();
17
+ }
18
+
19
+ class Cursor
20
+ {
21
+ moveTo(row, column)
22
+ out("\x1B[", row, ";", column, "H")
23
+
24
+ hide()
25
+ out("\x1B[?25l")
26
+
27
+ show()
28
+ out("\x1B[?25h")
29
+
30
+ save()
31
+ out("\x1B[s")
32
+
33
+ restore()
34
+ out("\x1B[u")
35
+ }
36
+
37
+ class io
38
+ {
39
+ constructor()
40
+ {
41
+ this.timer = {};
42
+ this.counted = {};
43
+ }
44
+
45
+ write(...message)
46
+ out(...message)
47
+
48
+ writeln(...message)
49
+ print(...message)
50
+
51
+ writeClr(color, style, ...message)
52
+ {
53
+ if (style == undefined || style == null)
54
+ out("\x1B[", color, "m", ...message, "\x1B[0m");
55
+ else
56
+ out("\x1B[", style, "m\x1B[", color, "m", ...message, "\x1B[0m");
57
+ }
58
+
59
+ writeClrln(color, style, ...message)
60
+ {
61
+ if (style == undefined || style == null)
62
+ out("\x1B[", color, "m", ...message, "\x1B[0m\n");
63
+ else
64
+ out("\x1B[", style, "m\x1B[", color, "m", ...message, "\x1B[0m\n");
65
+ }
66
+
67
+ writeDir(directory, options)
68
+ dir(directory, options)
69
+
70
+ error(...message)
71
+ regularerror(...message)
72
+
73
+ clear()
74
+ out("\x1B[2J\x1B[3J\x1B[H")
75
+
76
+ clearln()
77
+ out("\x1B[2K\x1B[G")
78
+
79
+ clearToEnd()
80
+ out("\x1B[0K")
81
+
82
+ clearToStart()
83
+ out("\x1B[1K")
84
+
85
+ prompt(...question)
86
+ return input(...question);
87
+
88
+ bell()
89
+ out("\x07")
90
+
91
+ rule(character, width)
92
+ {
93
+ new i = 0;
94
+ new line = "";
95
+ for (i = 0; i < width; i++)
96
+ line = concat(line, character);
97
+ print(line);
98
+ }
99
+
100
+ timerStart(label)
101
+ {
102
+ if (typeof(label) != "string")
103
+ TypeError.throw(concat('Parameter "name" in function "timerStart" can only be type String. But got "', label, '"'));
104
+ this.timer[label] = now();
105
+ }
106
+
107
+ timerEnd(label)
108
+ {
109
+ new currentTimer = now();
110
+ new nameTimer = this.timer[label];
111
+
112
+ if (nameTimer == undefined || nameTimer == null)
113
+ {
114
+ regularerror('Timer "', label, '" ', "does not exist");
115
+ return;
116
+ }
117
+
118
+ new elapsed = currentTimer - nameTimer;
119
+ if (elapsed >= 1000)
120
+ print(label, ": ", elapsed / 1000, "s")
121
+ else
122
+ print(label, ":", elapsed, "ms");
123
+ }
124
+
125
+ count(label)
126
+ {
127
+ if (!this.counted[label])
128
+ this.counted[label] = 0;
129
+ print(label, ": ", ++this.counted[label]);
130
+ }
131
+
132
+ countReset(label)
133
+ this.counted[label] = 0
134
+ }
135
+
136
+ Cursor = inst Cursor();
137
+ io = inst io();
138
+ process = inst process();
139
+
140
+ class cmd
141
+ {
142
+ constructor()
143
+ {
144
+ this.BOLD = 1;
145
+ this.DIM = 2;
146
+ this.ITALIC = 3;
147
+ this.UNDERLINE = 4;
148
+ this.BLINK = 5;
149
+ this.INVERSE = 7;
150
+ this.STRIKETHROUGH = 9;
151
+
152
+ this.BLACK = 30;
153
+ this.RED = 31;
154
+ this.GREEN = 32;
155
+ this.YELLOW = 33;
156
+ this.BLUE = 34;
157
+ this.MAGENTA = 35;
158
+ this.CYAN = 36;
159
+ this.WHITE = 37;
160
+ this.DEFAULT = 39;
161
+
162
+ this.BG_BLACK = 40
163
+ this.BG_RED = 41;
164
+ this.BG_GREEN = 42
165
+ this.BG_YELLOW = 43;
166
+ this.BG_BLUE = 44;
167
+ this.BG_MAGENTA = 45;
168
+ this.BG_CYAN = 46;
169
+ this.BG_WHITE = 47;
170
+
171
+ this.BG_DEFAULT = 49; # resets cmd bg to default
172
+
173
+ this.GRAY = 90;
174
+ this.BRIGHT_BLACK = this.GRAY;
175
+ this.BRIGHT_RED = 91;
176
+ this.BRIGHT_GREEN = 92;
177
+ this.BRIGHT_YELLOW = 93;
178
+ this.BRIGHT_BLUE = 94;
179
+ this.BRIGHT_MAGENTA = 95
180
+ this.BRIGHT_CYAN = 96;
181
+ this.BRIGHT_WHITE = 97;
182
+ }
183
+
184
+ log(...message)
185
+ this.prototype.stdout.write(...message)
186
+
187
+ error(...message)
188
+ this.prototype.stdout.error(...message)
189
+
190
+ warn(...message)
191
+ this.prototype.stdout.writeClrln(this.YELLOW, null, ...message)
192
+
193
+ success(...message)
194
+ this.prototype.stdout.writeClrln(this.GREEN, null, ...message)
195
+
196
+ clr(color, style, ...args)
197
+ this.prototype.stdout.writeClrln(color, style, ...args)
198
+
199
+ info(...message)
200
+ this.prototype.stdout.writeClrln(this.CYAN, null, ...message)
201
+
202
+ debug(...message)
203
+ this.prototype.stdout.writeClrln(this.GRAY, null, ...message)
204
+ }
205
+
206
+ cmd = inst cmd();
207
+
208
+ cmd.prototype = {};
209
+ cmd.prototype.stdout = io;
210
+
211
+ class f
212
+ {
213
+ constructor(filepath, i)
214
+ this.__INIT__ = i ? ifp(filepath) : filepath
215
+
216
+ read()
217
+ return rf(this.__INIT__);
218
+
219
+ rwrite(content)
220
+ wfraw(this.__INIT__, content)
221
+
222
+ write(content)
223
+ wf(this.__INIT__, content)
224
+
225
+ append(content)
226
+ af(this.__INIT__, content)
227
+
228
+ delete()
229
+ df(this.__INIT__)
230
+
231
+ exists()
232
+ return fe(this.__INIT__);
233
+
234
+ library()
235
+ return ifp(this.__INIT__);
236
+
237
+ copy(destination)
238
+ wf(destination, rf(this.__INIT__))
239
+
240
+ move(destination)
241
+ {
242
+ wf(destination, rf(this.__INIT__));
243
+ df(this.__INIT__);
244
+ this.__INIT__ = destination;
245
+ }
246
+
247
+ clear()
248
+ wf(this.__INIT__, "")
249
+
250
+ isEmpty()
251
+ return len(rf(this.__INIT__)) == 0;
252
+
253
+ size()
254
+ return len(rf(this.__INIT__));
255
+
256
+ extension()
257
+ {
258
+ new lastDot = undefined;
259
+ new length = len(this.__INIT__);
260
+
261
+ new i = 0;
262
+ for (i = 0; i < length; i++)
263
+ if (this.__INIT__[i] == ".")
264
+ lastDot = i;
265
+
266
+ if (lastDot == undefined)
267
+ return null;
268
+
269
+ return String.slice(this.__INIT__, lastDot, length);
270
+ }
271
+
272
+ stem()
273
+ {
274
+ new length = len(this.__INIT__);
275
+ new lastSlash = 0;
276
+ new lastDot = 0;
277
+
278
+ new i = 0;
279
+ for (i = 0; i < length; i++)
280
+ {
281
+ if (this.__INIT__[i] == "/" || this.__INIT__[i] == "\\")
282
+ lastSlash = i;
283
+ if (this.__INIT__[i] == ".")
284
+ lastDot = i;
285
+ }
286
+
287
+ new start = lastSlash ? lastSlash + 1 : 0;
288
+ return String.slice(this.__INIT__, start, lastDot);
289
+ }
290
+
291
+ name()
292
+ {
293
+ new lastSlash = 0;
294
+ new length = len(this.__INIT__);
295
+
296
+ new i = 0;
297
+ for (i = 0; i < length; i++)
298
+ if (this.__INIT__[i] == "/" || this.__INIT__[i] == "\\")
299
+ lastSlash = i;
300
+
301
+ new start = lastSlash ? lastSlash + 1 : 0;
302
+ return String.slice(this.__INIT__, start, length);
303
+ }
304
+
305
+ dread(fallback)
306
+ {
307
+ if (fe(this.__INIT__))
308
+ return rf(this.__INIT__);
309
+ return fallback;
310
+ }
311
+
312
+ writeIfChanged(content)
313
+ {
314
+ if (rf(this.__INIT__) != content)
315
+ wf(this.__INIT__, content);
316
+ }
317
+
318
+ rename(newname)
319
+ {
320
+ new length = len(this.__INIT__);
321
+ new lastSlash = 0;
322
+
323
+ new i = 0;
324
+ for (i = 0; i < length; i++)
325
+ if (this.__INIT__[i] == "/" || this.__INIT__[i] == "\\")
326
+ lastSlash = i;
327
+
328
+ new directory = String.slice(this.__INIT__, 0, lastSlash);
329
+ new destination = concat(directory, newname);
330
+
331
+ wf(destination, rf(this.__INIT__));
332
+ df(this.__INIT__);
333
+ this.__INIT__ = destination;
334
+ }
335
+
336
+ lines()
337
+ return String.split(rf(this.__INIT__), "\n");
338
+
339
+ create()
340
+ {
341
+ if (!fe(this.__INIT__))
342
+ wf(this.__INIT__, "");
343
+ }
344
+
345
+ path()
346
+ return this.__INIT__;
347
+
348
+ parent()
349
+ {
350
+ new length = len(this.__INIT__);
351
+ new lastSlash = 0;
352
+
353
+ new i = 0;
354
+ for (i = 0; i < length; i++)
355
+ if (this.__INIT__[i] == "/" || this.__INIT__[i] == "\\")
356
+ lastSlash = i;
357
+
358
+ new par = String.slice(this.__INIT__, 0, lastSlash);
359
+ if (par == "")
360
+ print("Warning: Directories don't have parents. Use a file path with a file extension at the end (e.g. C:\\Users\\Downloads\\test.pds)");
361
+
362
+ return par;
363
+ }
364
+ }
365
+
366
+ function fw(path, content)
367
+ {
368
+ new file = inst f(path);
369
+ file.create();
370
+ file.write(content);
371
+ }
@@ -0,0 +1,86 @@
1
+ import "std.pds";
2
+ function maxArguments(maxArgs, args, name)
3
+ {
4
+ new plural = maxArgs == 1
5
+ ? " argument"
6
+ : " arguments";
7
+
8
+ if (maxArgs < 1 && len(args) > 0)
9
+ throwerror("Error", concat('Function "', name, '" ', "does not take any arguments"));
10
+ else if (len(args) > maxArgs)
11
+ throwerror("Error", concat('Function "', name, '" ', "only takes ", maxArgs, plural));
12
+ }
13
+
14
+ new CACHE =
15
+ {
16
+ pi: []
17
+ }
18
+
19
+ function ChudnovskySeries(precision)
20
+ {
21
+ new terms = ceil(precision / 14) + 10;
22
+
23
+ new t1 = now();
24
+ new result = chudnovsky(terms);
25
+ new t2 = now();
26
+
27
+ new Q = result[1];
28
+ new T = result[2];
29
+
30
+ new den = 13591409 * Q + T;
31
+ new ratio = bigintdiv(Q, den);
32
+ new c = tofloat("426880") * sqrt(tofloat("10005"));
33
+ return c * ratio;
34
+ }
35
+
36
+ function truncatePi(π, precision)
37
+ {
38
+ new str = tostr(π);
39
+ new result = "";
40
+ new i = 0;
41
+ for (; i < precision + 1; i++)
42
+ result = concat(result, str[i]);
43
+
44
+ return tofloat(result);
45
+ }
46
+
47
+ function getPi(precision)
48
+ {
49
+ new workingPrecision = ceil(precision * 3.6) + 500;
50
+ new savedPrecision = getPrecision();
51
+ setPrecision(workingPrecision);
52
+
53
+ new index = precision;
54
+
55
+ if (!CACHE.pi[index])
56
+ {
57
+ new π_float = ChudnovskySeries(workingPrecision);
58
+ CACHE.pi[index] = tostr(π_float);
59
+ }
60
+
61
+ new result = String.slice(CACHE.pi[index], 0, precision + 2);
62
+
63
+ setPrecision(savedPrecision);
64
+ return result;
65
+ }
66
+
67
+ function getE(precision)
68
+ {
69
+ new workingPrecision = ceil(precision * 3.32) + 200000;
70
+ new savedPrecision = getPrecision();
71
+ setPrecision(workingPrecision);
72
+
73
+ new terms = precision + 10;
74
+ new computed = ecompute(terms);
75
+
76
+ new P = computed[0];
77
+ new Q = computed[1];
78
+
79
+ new denominator = Q;
80
+ new numerator = P + Q;
81
+ new e_float = bigintdiv(numerator, denominator);
82
+ new str = floattostr(e_float, precision + 2000);
83
+ new result = String.slice(str, 0, precision + 2);
84
+ setPrecision(savedPrecision);
85
+ return result;
86
+ }
@@ -0,0 +1,2 @@
1
+ import "types.pds";
2
+ import "io.pds";