porffor 0.2.0-eaee2da → 0.2.0-ef043de
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.
- package/LICENSE +20 -20
- package/README.md +159 -88
- package/asur/README.md +2 -0
- package/asur/index.js +1262 -0
- package/byg/index.js +237 -0
- package/compiler/2c.js +317 -72
- package/compiler/{sections.js → assemble.js} +63 -15
- package/compiler/builtins/annexb_string.js +72 -0
- package/compiler/builtins/annexb_string.ts +19 -0
- package/compiler/builtins/array.ts +145 -0
- package/compiler/builtins/base64.ts +151 -0
- package/compiler/builtins/crypto.ts +120 -0
- package/compiler/builtins/date.ts +1370 -0
- package/compiler/builtins/escape.ts +141 -0
- package/compiler/builtins/int.ts +147 -0
- package/compiler/builtins/number.ts +527 -0
- package/compiler/builtins/porffor.d.ts +42 -0
- package/compiler/builtins/string.ts +1055 -0
- package/compiler/builtins/tostring.ts +45 -0
- package/compiler/builtins.js +470 -269
- package/compiler/{codeGen.js → codegen.js} +999 -378
- package/compiler/embedding.js +22 -22
- package/compiler/encoding.js +108 -10
- package/compiler/generated_builtins.js +1262 -0
- package/compiler/index.js +36 -34
- package/compiler/log.js +6 -3
- package/compiler/opt.js +51 -36
- package/compiler/parse.js +35 -27
- package/compiler/precompile.js +123 -0
- package/compiler/prefs.js +26 -0
- package/compiler/prototype.js +13 -28
- package/compiler/types.js +37 -0
- package/compiler/wasmSpec.js +28 -8
- package/compiler/wrap.js +54 -46
- package/fib.js +7 -0
- package/package.json +9 -5
- package/porf +4 -0
- package/rhemyn/compile.js +5 -3
- package/rhemyn/parse.js +323 -320
- package/rhemyn/test/parse.js +58 -58
- package/runner/compare.js +34 -34
- package/runner/debug.js +122 -0
- package/runner/index.js +62 -10
- package/runner/profiler.js +102 -0
- package/runner/repl.js +40 -7
- package/runner/sizes.js +37 -37
- package/compiler/builtins/base64.js +0 -92
- package/runner/info.js +0 -89
- package/runner/profile.js +0 -46
- package/runner/results.json +0 -1
- package/runner/transform.js +0 -15
- package/util/enum.js +0 -20
package/byg/index.js
ADDED
@@ -0,0 +1,237 @@
|
|
1
|
+
import fs from 'node:fs';
|
2
|
+
|
3
|
+
const noAnsi = s => s.replace(/\u001b\[[0-9]+m/g, '');
|
4
|
+
const printLine = (line, number, breakpoint = false, current = false, selected = false) => {
|
5
|
+
// console.log(`\x1b[${breakpoint ? (selected ? '106' : '46') : (selected ? '47' : '100')}m\x1b[${selected ? '30' : '97'}m${number.toFixed(0).padStart(4, ' ')}\x1b[${breakpoint ? (selected ? '96' : '36') : (selected ? '37' : '90')}m\x1b[${current ? '47' : '40'}m▌ \x1b[${current ? '47' : '40'}m\x1b[${current ? '30' : '37'}m${current ? noAnsi(line) : line}\x1b[0K`);
|
6
|
+
console.log(`\x1b[${breakpoint ? (selected ? '43' : '103') : (selected ? '47' : '100')}m\x1b[${selected || breakpoint ? '30' : '97'}m${number.toFixed(0).padStart(4, ' ')}\x1b[${breakpoint ? (selected ? '33' : '93') : (selected ? '37' : '90')}m\x1b[${current ? '47' : '40'}m▌ \x1b[${current ? '47' : '40'}m\x1b[${current ? '30' : '37'}m${current ? noAnsi(line) : line}\x1b[0K`);
|
7
|
+
};
|
8
|
+
|
9
|
+
const box = (x, y, width, height, title = '', content = [], color = ['90', '100', '37', '35', '45'], padding = true) => {
|
10
|
+
if (padding) {
|
11
|
+
width += 1;
|
12
|
+
height += 1;
|
13
|
+
|
14
|
+
// top
|
15
|
+
process.stdout.write(`\x1b[48m\x1b[${y + 1};${x + 1}H\x1b[${color[0]}m` + '▄'.repeat(width));
|
16
|
+
|
17
|
+
// bottom
|
18
|
+
process.stdout.write(`\x1b[${y + height + 1};${x + 1}H▝` + '▀'.repeat(width - 1) + '▘');
|
19
|
+
|
20
|
+
// left
|
21
|
+
process.stdout.write(`\x1b[${y + 1};${x + 1}H▗` + '\x1b[1B\x1b[1D▐'.repeat(height - 1));
|
22
|
+
|
23
|
+
// right
|
24
|
+
process.stdout.write(`\x1b[${y + 1};${x + width + 1}H▖` + '\x1b[1B\x1b[1D▌'.repeat(height - 1));
|
25
|
+
|
26
|
+
x += 1;
|
27
|
+
y += 1;
|
28
|
+
width -= 1;
|
29
|
+
height -= 1;
|
30
|
+
}
|
31
|
+
|
32
|
+
// bg
|
33
|
+
process.stdout.write(`\x1b[${y + 1};${x + 1}H\x1b[${color[1]}m` + ' '.repeat(width) + (`\x1b[1B\x1b[${width}D` + ' '.repeat(width)).repeat(Math.max(0, height - 1)));
|
34
|
+
|
35
|
+
// title
|
36
|
+
// if (title) process.stdout.write(`\x1b[${y + 1};${x + ((width - title.length) / 2 | 0) + 1}H\x1b[${color[1]}m\x1b[${color[2]}m\x1b[1m${title}\x1b[22m`);
|
37
|
+
// if (title) process.stdout.write(`\x1b[${y};${x}H\x1b[${color[3]}▗\x1b[${color[4]}m\x1b[${color[2]}m\x1b[1m${' '.repeat((width - title.length) / 2 | 0)}${title}${' '.repeat(width - (((width - title.length) / 2 | 0)) - title.length)}\x1b[0m\x1b[${color[4]}m▖`);
|
38
|
+
if (title) process.stdout.write(`\x1b[${y};${x}H\x1b[0m\x1b[${color[3]}m▐\x1b[${color[4]}m\x1b[${color[2]}m\x1b[1m${' '.repeat((width - title.length) / 2 | 0)}${title}${' '.repeat(width - (((width - title.length) / 2 | 0)) - title.length)}\x1b[0m\x1b[${color[3]}m▌`);
|
39
|
+
|
40
|
+
// content
|
41
|
+
process.stdout.write(`\x1b[${y + (title ? 1 : 1)};${x + 1}H\x1b[${color[1]}m\x1b[${color[2]}m${content.join(`\x1b[1B\x1b[${x + 1}G`)}`);
|
42
|
+
};
|
43
|
+
|
44
|
+
const controls = {
|
45
|
+
'ret': 'resume ',
|
46
|
+
'b': 'breakpoint ',
|
47
|
+
's': 'step over',
|
48
|
+
'i': 'step in',
|
49
|
+
'o': 'step out ',
|
50
|
+
};
|
51
|
+
|
52
|
+
const controlInfo = Object.keys(controls).reduce((acc, x, i) => acc + `\x1B[45m\x1B[97m${x}\x1b[105m\x1b[37m ${controls[x]} `, '');
|
53
|
+
const plainControlInfo = noAnsi(controlInfo);
|
54
|
+
|
55
|
+
globalThis.termWidth = process.stdout.columns || 80;
|
56
|
+
globalThis.termHeight = process.stdout.rows || 24;
|
57
|
+
|
58
|
+
export default ({ lines, pause, breakpoint }) => {
|
59
|
+
process.stdin.setRawMode(true);
|
60
|
+
process.stdin.resume();
|
61
|
+
process.stdin.setEncoding('utf8');
|
62
|
+
|
63
|
+
process.stdin.on('data', s => {
|
64
|
+
// ctrl c
|
65
|
+
if (s === '\u0003') {
|
66
|
+
process.exit();
|
67
|
+
}
|
68
|
+
|
69
|
+
// process.stdout.write(s);
|
70
|
+
|
71
|
+
if (!paused) pause();
|
72
|
+
});
|
73
|
+
|
74
|
+
const stdin = fs.openSync('/dev/stdin', 'r+');
|
75
|
+
const readCharSync = () => {
|
76
|
+
const buffer = Buffer.alloc(1);
|
77
|
+
fs.readSync(stdin, buffer, 0, 1);
|
78
|
+
return buffer.toString('utf8');
|
79
|
+
};
|
80
|
+
|
81
|
+
const tooManyLines = lines.length > (termHeight - 1);
|
82
|
+
const breakpoints = {};
|
83
|
+
|
84
|
+
process.on('exit', () => {
|
85
|
+
process.stdout.write('\x1b[0m');
|
86
|
+
// console.clear();
|
87
|
+
});
|
88
|
+
|
89
|
+
console.clear();
|
90
|
+
|
91
|
+
let paused = true;
|
92
|
+
return (_paused, currentLine, text, boxes = []) => {
|
93
|
+
paused = _paused;
|
94
|
+
|
95
|
+
let scrollOffset = 0;
|
96
|
+
let currentLinePos = currentLine;
|
97
|
+
|
98
|
+
const draw = () => {
|
99
|
+
console.clear();
|
100
|
+
process.stdout.write(`\x1b[1;1H`);
|
101
|
+
|
102
|
+
if (tooManyLines) {
|
103
|
+
const edgePadding = (termHeight / 2) - 1;
|
104
|
+
let beforePadding = currentLine - edgePadding;
|
105
|
+
let afterPadding = currentLine + edgePadding + 1;
|
106
|
+
|
107
|
+
if (beforePadding < 0) {
|
108
|
+
afterPadding += Math.abs(beforePadding);
|
109
|
+
beforePadding = 0;
|
110
|
+
}
|
111
|
+
|
112
|
+
beforePadding += scrollOffset;
|
113
|
+
afterPadding += scrollOffset;
|
114
|
+
|
115
|
+
if (afterPadding > lines.length) {
|
116
|
+
beforePadding -= afterPadding - lines.length;
|
117
|
+
afterPadding = lines.length;
|
118
|
+
}
|
119
|
+
|
120
|
+
for (let i = Math.max(0, beforePadding); i < Math.max(0, beforePadding) + (termHeight - 1); i++) {
|
121
|
+
printLine(lines[i], i + 1, !!breakpoints[i], currentLine === i, currentLine + scrollOffset === i);
|
122
|
+
}
|
123
|
+
|
124
|
+
currentLinePos = currentLine - beforePadding;
|
125
|
+
} else {
|
126
|
+
for (let i = 0; i < lines.length; i++) {
|
127
|
+
printLine(lines[i], i + 1, !!breakpoints[i], currentLine === i, currentLine + scrollOffset === i);
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
for (const x of boxes) {
|
132
|
+
const y = x.y({ currentLinePos });
|
133
|
+
const height = x.height;
|
134
|
+
if (y < 0 || y >= termHeight) continue;
|
135
|
+
|
136
|
+
// crop box if > termHeight
|
137
|
+
// if (y + height >= termHeight) {
|
138
|
+
// const excess = y + height - termHeight;
|
139
|
+
// height -= excess;
|
140
|
+
|
141
|
+
// content = content.slice(0, height - 2);
|
142
|
+
// }
|
143
|
+
|
144
|
+
box(x.x, y, x.width, height, x.title, x.content);
|
145
|
+
}
|
146
|
+
|
147
|
+
// text += ` | rss: ${(process.memoryUsage.rss() / 1024 / 1024).toFixed(2)}mb`;
|
148
|
+
|
149
|
+
process.stdout.write(`\x1b[${termHeight};1H\x1b[105m\x1b[37m${text}${' '.repeat(termWidth - plainControlInfo.length - noAnsi(text).length - 1)}${controlInfo} \x1b[0m`);
|
150
|
+
};
|
151
|
+
|
152
|
+
draw();
|
153
|
+
|
154
|
+
let lastSpecial = false;
|
155
|
+
while (true) {
|
156
|
+
const char = readCharSync();
|
157
|
+
|
158
|
+
if (char === '[') {
|
159
|
+
lastSpecial = true;
|
160
|
+
continue;
|
161
|
+
}
|
162
|
+
|
163
|
+
switch (char.toLowerCase()) {
|
164
|
+
case '\r': {
|
165
|
+
paused = false;
|
166
|
+
return 'resume';
|
167
|
+
}
|
168
|
+
|
169
|
+
case 's': {
|
170
|
+
return 'stepOver';
|
171
|
+
}
|
172
|
+
|
173
|
+
case 'i': {
|
174
|
+
return 'stepIn';
|
175
|
+
}
|
176
|
+
|
177
|
+
case 'o': {
|
178
|
+
return 'stepOut';
|
179
|
+
}
|
180
|
+
|
181
|
+
case 'b': {
|
182
|
+
if (!lastSpecial) { // b pressed normally
|
183
|
+
breakpoints[currentLine + scrollOffset] = !breakpoints[currentLine + scrollOffset];
|
184
|
+
draw();
|
185
|
+
|
186
|
+
breakpoint(currentLine + scrollOffset, breakpoints[currentLine + scrollOffset]);
|
187
|
+
break;
|
188
|
+
}
|
189
|
+
|
190
|
+
// arrow down
|
191
|
+
// if (screenOffset + termHeight <= lines.length) scrollOffset++;
|
192
|
+
if (scrollOffset < lines.length - currentLine - 1) scrollOffset++;
|
193
|
+
draw();
|
194
|
+
break;
|
195
|
+
}
|
196
|
+
|
197
|
+
case 'a': {
|
198
|
+
if (!lastSpecial) break;
|
199
|
+
|
200
|
+
// arrow up
|
201
|
+
// if (screenOffset > 0) scrollOffset--;
|
202
|
+
if (scrollOffset > -currentLine) scrollOffset--;
|
203
|
+
draw();
|
204
|
+
|
205
|
+
break;
|
206
|
+
}
|
207
|
+
|
208
|
+
case '5': {
|
209
|
+
if (!lastSpecial) break;
|
210
|
+
|
211
|
+
// page up
|
212
|
+
// scrollOffset -= Math.min(screenOffset, termHeight - 1);
|
213
|
+
scrollOffset -= Math.min(scrollOffset + currentLine, termHeight - 1);
|
214
|
+
draw();
|
215
|
+
break;
|
216
|
+
}
|
217
|
+
|
218
|
+
case '6': {
|
219
|
+
if (!lastSpecial) break;
|
220
|
+
|
221
|
+
// page down
|
222
|
+
// scrollOffset += Math.min((lines.length + 1) - (screenOffset + termHeight), termHeight - 1);
|
223
|
+
scrollOffset += Math.min(lines.length - (scrollOffset + currentLine) - 1, termHeight - 1);
|
224
|
+
draw();
|
225
|
+
break;
|
226
|
+
}
|
227
|
+
|
228
|
+
case 'q':
|
229
|
+
case '\u0003': {
|
230
|
+
process.exit();
|
231
|
+
}
|
232
|
+
}
|
233
|
+
|
234
|
+
lastSpecial = false;
|
235
|
+
}
|
236
|
+
};
|
237
|
+
};
|