porffor 0.57.26 → 0.57.28
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/README.md +0 -7
- package/compiler/builtins/regexp.ts +128 -0
- package/compiler/builtins_precompiled.js +411 -344
- package/compiler/codegen.js +55 -104
- package/compiler/wrap.js +8 -0
- package/foo.js +8 -0
- package/package.json +1 -1
- package/runtime/index.js +1 -1
- package/rhemyn/README.md +0 -40
- package/rhemyn/compile.js +0 -331
- package/rhemyn/parse.js +0 -323
- package/rhemyn/test/parse.js +0 -59
package/README.md
CHANGED
@@ -76,9 +76,6 @@ Expect nothing to work! Only very limited JS is currently supported. See files i
|
|
76
76
|
### Asur
|
77
77
|
Asur is Porffor's own Wasm engine; it is an intentionally simple interpreter written in JS. It is very WIP. See [its readme](asur/README.md) for more details.
|
78
78
|
|
79
|
-
### Rhemyn
|
80
|
-
Rhemyn is Porffor's own regex engine; it compiles literal regex to Wasm bytecode AOT (remind you of anything?). It is quite basic and WIP. See [its readme](rhemyn/README.md) for more details.
|
81
|
-
|
82
79
|
### 2c
|
83
80
|
2c is Porffor's own Wasm -> C compiler, using generated Wasm bytecode and internal info to generate specific and efficient C code. Little boilerplate/preluded code or required external files, just for CLI binaries (not like wasm2c very much).
|
84
81
|
|
@@ -126,10 +123,6 @@ Porffor can run Test262 via some hacks/transforms which remove unsupported featu
|
|
126
123
|
- `index.js`: the main file, you probably want to use this
|
127
124
|
- `repl.js`: basic repl (uses `node:repl`)
|
128
125
|
|
129
|
-
- `rhemyn`: contains [Rhemyn](#rhemyn) - our regex engine (used by Porffor)
|
130
|
-
- `compile.js`: compiles regex ast into wasm bytecode aot
|
131
|
-
- `parse.js`: own regex parser
|
132
|
-
|
133
126
|
- `test262`: test262 runner and utils
|
134
127
|
|
135
128
|
## Usecases
|
@@ -0,0 +1,128 @@
|
|
1
|
+
import type {} from './porffor.d.ts';
|
2
|
+
|
3
|
+
// regex memory structure:
|
4
|
+
// source string ptr (u32)
|
5
|
+
// flags string ptr (u32)
|
6
|
+
// flags (u16):
|
7
|
+
// g, global - 0b00000001
|
8
|
+
// i, ignore case - 0b00000010
|
9
|
+
// m, multiline - 0b00000100
|
10
|
+
// s, dotall - 0b00001000
|
11
|
+
// u, unicode - 0b00010000
|
12
|
+
// y, sticky - 0b00100000
|
13
|
+
// d, has indices - 0b01000000
|
14
|
+
// v, unicode sets - 0b10000000
|
15
|
+
// bytecode length (u16)
|
16
|
+
// bytecode ...
|
17
|
+
|
18
|
+
export const __Porffor_regex_construct = (patternStr: bytestring, flagsStr: bytestring): RegExp => {
|
19
|
+
const ptr: i32 = Porffor.allocate();
|
20
|
+
Porffor.wasm.i32.store(ptr, patternStr, 0, 0);
|
21
|
+
Porffor.wasm.i32.store(ptr, flagsStr, 0, 4);
|
22
|
+
|
23
|
+
// parse flags
|
24
|
+
let flags: i32 = 0;
|
25
|
+
let flagsPtr: i32 = flagsStr;
|
26
|
+
const flagsEndPtr: i32 = flagsPtr + flagsStr.length;
|
27
|
+
while (flagsPtr < flagsEndPtr) {
|
28
|
+
const char: i32 = Porffor.wasm.i32.load8_u(flagsPtr, 0, 4);
|
29
|
+
flagsPtr = flagsPtr + 1;
|
30
|
+
|
31
|
+
if (char == 103) { // g
|
32
|
+
flags |= 0b00000001;
|
33
|
+
continue;
|
34
|
+
}
|
35
|
+
if (char == 105) { // i
|
36
|
+
flags |= 0b00000010;
|
37
|
+
continue;
|
38
|
+
}
|
39
|
+
if (char == 109) { // m
|
40
|
+
flags |= 0b00000100;
|
41
|
+
continue;
|
42
|
+
}
|
43
|
+
if (char == 115) { // s
|
44
|
+
flags |= 0b00001000;
|
45
|
+
continue;
|
46
|
+
}
|
47
|
+
if (char == 117) { // u
|
48
|
+
if (flags & 0b10000000) throw new SyntaxError('Conflicting regular expression unicode flags');
|
49
|
+
flags |= 0b00010000;
|
50
|
+
continue;
|
51
|
+
}
|
52
|
+
if (char == 121) { // y
|
53
|
+
flags |= 0b00100000;
|
54
|
+
continue;
|
55
|
+
}
|
56
|
+
if (char == 100) { // d
|
57
|
+
flags |= 0b01000000;
|
58
|
+
continue;
|
59
|
+
}
|
60
|
+
if (char == 118) { // v
|
61
|
+
if (flags & 0b00010000) throw new SyntaxError('Conflicting regular expression unicode flags');
|
62
|
+
flags |= 0b10000000;
|
63
|
+
continue;
|
64
|
+
}
|
65
|
+
|
66
|
+
throw new SyntaxError('Invalid regular expression flag');
|
67
|
+
}
|
68
|
+
|
69
|
+
Porffor.wasm.i32.store16(ptr, flags, 0, 8);
|
70
|
+
|
71
|
+
return ptr;
|
72
|
+
};
|
73
|
+
|
74
|
+
|
75
|
+
export const RegExp = function (patternStr: any, flagsStr: any = ''): RegExp {
|
76
|
+
if (Porffor.fastOr(
|
77
|
+
Porffor.type(patternStr) != Porffor.TYPES.bytestring,
|
78
|
+
Porffor.type(flagsStr) != Porffor.TYPES.bytestring
|
79
|
+
)) {
|
80
|
+
throw new TypeError('Invalid regular expression');
|
81
|
+
}
|
82
|
+
|
83
|
+
return __Porffor_regex_construct(patternStr, flagsStr);
|
84
|
+
};
|
85
|
+
|
86
|
+
export const __RegExp_prototype_source$get = (_this: RegExp) => {
|
87
|
+
return Porffor.wasm.i32.load(_this, 0, 0) as bytestring;
|
88
|
+
};
|
89
|
+
|
90
|
+
export const __RegExp_prototype_flags$get = (_this: RegExp) => {
|
91
|
+
return Porffor.wasm.i32.load(_this, 0, 4) as bytestring;
|
92
|
+
};
|
93
|
+
|
94
|
+
export const __RegExp_prototype_global$get = (_this: RegExp) => {
|
95
|
+
return (Porffor.wasm.i32.load(_this, 0, 8) & 0b00000001) as boolean;
|
96
|
+
};
|
97
|
+
|
98
|
+
export const __RegExp_prototype_ignoreCase$get = (_this: RegExp) => {
|
99
|
+
return (Porffor.wasm.i32.load(_this, 0, 8) & 0b00000010) as boolean;
|
100
|
+
};
|
101
|
+
|
102
|
+
export const __RegExp_prototype_multiline$get = (_this: RegExp) => {
|
103
|
+
return (Porffor.wasm.i32.load(_this, 0, 8) & 0b00000100) as boolean;
|
104
|
+
};
|
105
|
+
|
106
|
+
export const __RegExp_prototype_dotAll$get = (_this: RegExp) => {
|
107
|
+
return (Porffor.wasm.i32.load(_this, 0, 8) & 0b00001000) as boolean;
|
108
|
+
};
|
109
|
+
|
110
|
+
export const __RegExp_prototype_unicode$get = (_this: RegExp) => {
|
111
|
+
return (Porffor.wasm.i32.load(_this, 0, 8) & 0b00010000) as boolean;
|
112
|
+
};
|
113
|
+
|
114
|
+
export const __RegExp_prototype_sticky$get = (_this: RegExp) => {
|
115
|
+
return (Porffor.wasm.i32.load(_this, 0, 8) & 0b00100000) as boolean;
|
116
|
+
};
|
117
|
+
|
118
|
+
export const __RegExp_prototype_hasIndices$get = (_this: RegExp) => {
|
119
|
+
return (Porffor.wasm.i32.load(_this, 0, 8) & 0b01000000) as boolean;
|
120
|
+
};
|
121
|
+
|
122
|
+
export const __RegExp_prototype_unicodeSets$get = (_this: RegExp) => {
|
123
|
+
return (Porffor.wasm.i32.load(_this, 0, 8) & 0b10000000) as boolean;
|
124
|
+
};
|
125
|
+
|
126
|
+
export const __RegExp_prototype_toString = (_this: RegExp) => {
|
127
|
+
return '/' + _this.source + '/' + _this.flags;
|
128
|
+
};
|