porffor 0.2.0-f2bbe1f → 0.2.0-f435128
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/CONTRIBUTING.md +181 -0
- package/LICENSE +20 -20
- package/README.md +154 -89
- 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 +1856 -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} +1156 -418
- package/compiler/decompile.js +0 -1
- package/compiler/embedding.js +22 -22
- package/compiler/encoding.js +108 -10
- package/compiler/generated_builtins.js +1445 -0
- package/compiler/index.js +36 -34
- package/compiler/log.js +6 -3
- package/compiler/opt.js +51 -36
- package/compiler/parse.js +33 -23
- package/compiler/precompile.js +128 -0
- package/compiler/prefs.js +27 -0
- package/compiler/prototype.js +177 -37
- package/compiler/types.js +37 -0
- package/compiler/wasmSpec.js +30 -7
- package/compiler/wrap.js +56 -40
- package/package.json +9 -5
- package/porf +4 -0
- package/rhemyn/compile.js +46 -27
- package/rhemyn/parse.js +322 -320
- package/rhemyn/test/parse.js +58 -58
- package/runner/compare.js +34 -34
- package/runner/debug.js +122 -0
- package/runner/index.js +91 -11
- package/runner/profiler.js +102 -0
- package/runner/repl.js +42 -9
- 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/rhemyn/compile.js
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
import { Blocktype, Opcodes, Valtype,
|
1
|
+
import { Blocktype, Opcodes, Valtype, ValtypeSize } from '../compiler/wasmSpec.js';
|
2
2
|
import { number } from '../compiler/embedding.js';
|
3
|
-
import { signedLEB128, unsignedLEB128 } from '../compiler/encoding.js';
|
4
3
|
import parse from './parse.js';
|
4
|
+
import Prefs from '../compiler/prefs.js';
|
5
|
+
import { TYPES } from '../compiler/types.js';
|
5
6
|
|
6
7
|
// local indexes
|
7
8
|
const BasePointer = 0; // base string pointer
|
@@ -13,7 +14,7 @@ const Length = 5;
|
|
13
14
|
const Tmp = 6;
|
14
15
|
|
15
16
|
let exprLastGet = false;
|
16
|
-
const generate = (node, negated = false, get = true, func = 'test') => {
|
17
|
+
const generate = (node, negated = false, get = true, stringSize = 2, func = 'test') => {
|
17
18
|
let out = [];
|
18
19
|
switch (node.type) {
|
19
20
|
case 'Expression':
|
@@ -41,7 +42,7 @@ const generate = (node, negated = false, get = true, func = 'test') => {
|
|
41
42
|
// generate checks
|
42
43
|
...node.body.flatMap((x, i) => {
|
43
44
|
exprLastGet = x.type !== 'Group' && i === (node.body.length - 1);
|
44
|
-
return generate(x, negated);
|
45
|
+
return generate(x, negated, true, stringSize, func);
|
45
46
|
}),
|
46
47
|
|
47
48
|
// reached end without branching out, successful match
|
@@ -55,9 +56,9 @@ const generate = (node, negated = false, get = true, func = 'test') => {
|
|
55
56
|
|
56
57
|
[ Opcodes.end ],
|
57
58
|
|
58
|
-
// increment iter pointer by
|
59
|
+
// increment iter pointer by string size
|
59
60
|
[ Opcodes.local_get, IterPointer ],
|
60
|
-
...number(
|
61
|
+
...number(stringSize, Valtype.i32),
|
61
62
|
[ Opcodes.i32_add ],
|
62
63
|
[ Opcodes.local_set, IterPointer ],
|
63
64
|
|
@@ -80,7 +81,7 @@ const generate = (node, negated = false, get = true, func = 'test') => {
|
|
80
81
|
})[func], Valtype.i32)
|
81
82
|
];
|
82
83
|
|
83
|
-
if (
|
84
|
+
if (Prefs.regexLog) {
|
84
85
|
const underline = x => `\u001b[4m\u001b[1m${x}\u001b[0m`;
|
85
86
|
console.log(`\n${underline('ast')}`);
|
86
87
|
console.log(node);
|
@@ -90,34 +91,34 @@ const generate = (node, negated = false, get = true, func = 'test') => {
|
|
90
91
|
break;
|
91
92
|
|
92
93
|
case 'Character':
|
93
|
-
out = generateChar(node, node.negated ^ negated, get);
|
94
|
+
out = generateChar(node, node.negated ^ negated, get, stringSize);
|
94
95
|
break;
|
95
96
|
|
96
97
|
case 'Set':
|
97
|
-
out = generateSet(node, node.negated, get);
|
98
|
+
out = generateSet(node, node.negated, get, stringSize);
|
98
99
|
break;
|
99
100
|
|
100
101
|
case 'Group':
|
101
|
-
out = generateGroup(node, negated, get);
|
102
|
+
out = generateGroup(node, negated, get, stringSize);
|
102
103
|
break;
|
103
104
|
|
104
105
|
case 'Range':
|
105
|
-
out = generateRange(node, negated, get);
|
106
|
+
out = generateRange(node, negated, get, stringSize);
|
106
107
|
break;
|
107
108
|
}
|
108
109
|
|
109
110
|
return out;
|
110
111
|
};
|
111
112
|
|
112
|
-
const getNextChar = () => [
|
113
|
+
const getNextChar = (stringSize) => [
|
113
114
|
// get char from pointer
|
114
115
|
[ Opcodes.local_get, Pointer ],
|
115
|
-
[ Opcodes.i32_load16_u
|
116
|
+
[ stringSize == 2 ? Opcodes.i32_load16_u : Opcodes.i32_load8_u, 0, 0 ],
|
116
117
|
|
117
118
|
...(exprLastGet ? [] : [
|
118
|
-
// pointer +=
|
119
|
+
// pointer += string size
|
119
120
|
[ Opcodes.local_get, Pointer ],
|
120
|
-
...number(
|
121
|
+
...number(stringSize, Valtype.i32),
|
121
122
|
[ Opcodes.i32_add ],
|
122
123
|
[ Opcodes.local_set, Pointer ]
|
123
124
|
])
|
@@ -133,21 +134,21 @@ const checkFailure = () => [
|
|
133
134
|
[ Opcodes.br_if, 0 ]
|
134
135
|
];
|
135
136
|
|
136
|
-
const generateChar = (node, negated, get) => {
|
137
|
+
const generateChar = (node, negated, get, stringSize) => {
|
137
138
|
return [
|
138
|
-
...(get ? getNextChar() : []),
|
139
|
+
...(get ? getNextChar(stringSize) : []),
|
139
140
|
...number(node.char.charCodeAt(0), Valtype.i32),
|
140
141
|
negated ? [ Opcodes.i32_eq ] : [ Opcodes.i32_ne ],
|
141
142
|
...(get ? checkFailure(): [])
|
142
143
|
];
|
143
144
|
};
|
144
145
|
|
145
|
-
const generateSet = (node, negated, get) => {
|
146
|
+
const generateSet = (node, negated, get, stringSize) => {
|
146
147
|
// for a single char we do not need a tmp, it is like just
|
147
148
|
const singleChar = node.body.length === 1 && node.body[0].type === 'Character';
|
148
149
|
|
149
150
|
let out = [
|
150
|
-
...(get ? getNextChar() : []),
|
151
|
+
...(get ? getNextChar(stringSize) : []),
|
151
152
|
...(singleChar ? [] : [ [ Opcodes.local_set, Tmp ] ]),
|
152
153
|
];
|
153
154
|
|
@@ -155,11 +156,11 @@ const generateSet = (node, negated, get) => {
|
|
155
156
|
out = [
|
156
157
|
...out,
|
157
158
|
...(singleChar ? [] : [ [ Opcodes.local_get, Tmp ] ]),
|
158
|
-
...generate(x, negated, false)
|
159
|
+
...generate(x, negated, false, stringSize)
|
159
160
|
];
|
160
161
|
}
|
161
162
|
|
162
|
-
out = out.concat(new Array(node.body.length - 1).fill(negated ? [ Opcodes.i32_or ] : [ Opcodes.i32_and ]));
|
163
|
+
if (node.body.length > 0) out = out.concat(new Array(node.body.length - 1).fill(negated ? [ Opcodes.i32_or ] : [ Opcodes.i32_and ]));
|
163
164
|
|
164
165
|
return [
|
165
166
|
...out,
|
@@ -167,9 +168,9 @@ const generateSet = (node, negated, get) => {
|
|
167
168
|
];
|
168
169
|
};
|
169
170
|
|
170
|
-
const generateRange = (node, negated, get) => {
|
171
|
+
const generateRange = (node, negated, get, stringSize) => {
|
171
172
|
return [
|
172
|
-
...(get ? getNextChar() : []),
|
173
|
+
...(get ? getNextChar(stringSize) : []),
|
173
174
|
...(get ? [ [ Opcodes.local_tee, Tmp ] ] : []),
|
174
175
|
|
175
176
|
...number(node.from.charCodeAt(0), Valtype.i32),
|
@@ -187,11 +188,29 @@ const generateRange = (node, negated, get) => {
|
|
187
188
|
};
|
188
189
|
|
189
190
|
const generateGroup = (node, negated, get) => {
|
191
|
+
// todo
|
192
|
+
return [];
|
193
|
+
};
|
190
194
|
|
195
|
+
const wrapFunc = (regex, func, name, index) => {
|
196
|
+
const parsed = parse(regex);
|
197
|
+
|
198
|
+
return outputFunc([
|
199
|
+
[ Opcodes.local_get, 1 ],
|
200
|
+
...number(TYPES.string, Valtype.i32),
|
201
|
+
[ Opcodes.i32_eq ],
|
202
|
+
[ Opcodes.if, Valtype.i32 ],
|
203
|
+
// string
|
204
|
+
...generate(parsed, false, true, 2, func),
|
205
|
+
[ Opcodes.else ],
|
206
|
+
// bytestring
|
207
|
+
...generate(parsed, false, true, 1, func),
|
208
|
+
[ Opcodes.end ]
|
209
|
+
], name, index);
|
191
210
|
};
|
192
211
|
|
193
|
-
export const test = (regex, index = 0, name = 'regex_test_' + regex) =>
|
194
|
-
export const search = (regex, index = 0, name = 'regex_search_' + regex) =>
|
212
|
+
export const test = (regex, index = 0, name = 'regex_test_' + regex) => wrapFunc(regex, 'test', name, index);
|
213
|
+
export const search = (regex, index = 0, name = 'regex_search_' + regex) => wrapFunc(regex, 'search', name, index);
|
195
214
|
|
196
215
|
const outputFunc = (wasm, name, index) => ({
|
197
216
|
name,
|
@@ -199,9 +218,9 @@ const outputFunc = (wasm, name, index) => ({
|
|
199
218
|
wasm,
|
200
219
|
|
201
220
|
export: true,
|
202
|
-
params: [ Valtype.i32 ],
|
221
|
+
params: [ Valtype.i32, Valtype.i32 ],
|
203
222
|
returns: [ Valtype.i32 ],
|
204
|
-
returnType:
|
223
|
+
returnType: TYPES.boolean,
|
205
224
|
locals: {
|
206
225
|
basePointer: { idx: 0, type: Valtype.i32 },
|
207
226
|
iterPointer: { idx: 1, type: Valtype.i32 },
|