porffor 0.35.1 → 0.35.3
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/compiler/builtins/annexb_string.js +18 -119
- package/compiler/builtins/object.ts +26 -2
- package/compiler/builtins.js +5 -5
- package/compiler/builtins_precompiled.js +116 -124
- package/compiler/codegen.js +87 -29
- package/package.json +1 -1
- package/runner/index.js +1 -1
- package/runner/repl.js +4 -1
@@ -1,59 +1,14 @@
|
|
1
1
|
export default () => {
|
2
|
-
let out =
|
3
|
-
`;
|
4
|
-
|
2
|
+
let out = ``;
|
5
3
|
const noArgs = (a0, a1) => out += `
|
6
|
-
export const __String_prototype_${a0} = (_this:
|
7
|
-
|
8
|
-
|
9
|
-
let outPtr: i32 = Porffor.wasm\`local.get \${out}\` + ${(2 + a1.length) * 2};
|
10
|
-
let thisPtr: i32 = Porffor.wasm\`local.get \${_this}\`;
|
11
|
-
let thisLen: i32 = _this.length;
|
12
|
-
let endPtr: i32 = thisPtr + thisLen * 2;
|
13
|
-
|
14
|
-
while (thisPtr < endPtr) {
|
15
|
-
let chr: i32 = Porffor.wasm.i32.load16_u(thisPtr, 0, 4);
|
16
|
-
Porffor.wasm.i32.store16(outPtr, chr, 0, 4);
|
17
|
-
|
18
|
-
thisPtr += 2;
|
19
|
-
outPtr += 2;
|
20
|
-
}
|
21
|
-
|
22
|
-
Porffor.wasm.i32.store16(outPtr, 60, 0, 4); // <
|
23
|
-
Porffor.wasm.i32.store16(outPtr, 47, 0, 6); // /
|
24
|
-
|
25
|
-
${[...a1].map((x, i) => ` Porffor.wasm.i32.store16(outPtr, ${x.charCodeAt(0)}, 0, ${8 + i * 2}); // ${x}`).join('\n')}
|
26
|
-
|
27
|
-
Porffor.wasm.i32.store16(outPtr, 62, 0, ${8 + a1.length * 2}); // >
|
28
|
-
|
29
|
-
out.length = thisLen + ${a1.length * 2 + 2 + 3};
|
30
|
-
|
31
|
-
return out;
|
32
|
-
};
|
33
|
-
export const __ByteString_prototype_${a0} = (_this: bytestring) => {
|
34
|
-
let out: bytestring = Porffor.bs\`<${a1}>\`;
|
35
|
-
|
36
|
-
let outPtr: i32 = Porffor.wasm\`local.get \${out}\` + ${2 + a1.length};
|
37
|
-
let thisPtr: i32 = Porffor.wasm\`local.get \${_this}\`;
|
38
|
-
let thisLen: i32 = _this.length;
|
39
|
-
let endPtr: i32 = thisPtr + thisLen;
|
40
|
-
|
41
|
-
while (thisPtr < endPtr) {
|
42
|
-
let chr: i32 = Porffor.wasm.i32.load8_u(thisPtr++, 0, 4);
|
43
|
-
Porffor.wasm.i32.store8(outPtr++, chr, 0, 4);
|
44
|
-
}
|
45
|
-
|
46
|
-
Porffor.wasm.i32.store8(outPtr, 60, 0, 4); // <
|
47
|
-
Porffor.wasm.i32.store8(outPtr, 47, 0, 5); // /
|
48
|
-
|
49
|
-
${[...a1].map((x, i) => ` Porffor.wasm.i32.store8(outPtr, ${x.charCodeAt(0)}, 0, ${6 + i}); // ${x}`).join('\n')}
|
50
|
-
|
51
|
-
Porffor.wasm.i32.store8(outPtr, 62, 0, ${6 + a1.length}); // >
|
4
|
+
export const __String_prototype_${a0} = (_this: any) => {
|
5
|
+
const pre: bytestring = '<${a1}>';
|
6
|
+
const post: bytestring = '</${a1}>';
|
52
7
|
|
53
|
-
|
54
|
-
|
55
|
-
return out;
|
8
|
+
return Porffor.concatStrings(Porffor.concatStrings(pre, _this), post);
|
56
9
|
};
|
10
|
+
export const __ByteString_prototype_${a0} = (_this: any) =>
|
11
|
+
__String_prototype_${a0}(_this);
|
57
12
|
`;
|
58
13
|
|
59
14
|
noArgs('big', 'big');
|
@@ -67,69 +22,15 @@ ${[...a1].map((x, i) => ` Porffor.wasm.i32.store8(outPtr, ${x.charCodeAt(0)}, 0
|
|
67
22
|
noArgs('sup', 'sup');
|
68
23
|
|
69
24
|
const arg = (name, s1, s2) => out += `
|
70
|
-
export const __String_prototype_${name} = (_this:
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
let outPtr: i32 = Porffor.wasm\`local.get \${out}\` + ${(`<${s1} ${s2}="`.length + 2) * 2} + arg.length * 2;
|
75
|
-
|
76
|
-
Porffor.wasm.i32.store16(outPtr, 34, 0, 0); // "
|
77
|
-
Porffor.wasm.i32.store16(outPtr, 62, 0, 2); // >
|
78
|
-
|
79
|
-
let thisPtr: i32 = Porffor.wasm\`local.get \${_this}\`;
|
80
|
-
let thisLen: i32 = _this.length;
|
81
|
-
let endPtr: i32 = thisPtr + thisLen * 2;
|
25
|
+
export const __String_prototype_${name} = (_this: any, arg: any) => {
|
26
|
+
const pre1: bytestring = '<${s1} ${s2}="';
|
27
|
+
const pre2: bytestring = '">';
|
28
|
+
const post: bytestring = '</${s1}>';
|
82
29
|
|
83
|
-
|
84
|
-
let chr: i32 = Porffor.wasm.i32.load16_u(thisPtr, 0, 4);
|
85
|
-
Porffor.wasm.i32.store16(outPtr, chr, 0, 4);
|
86
|
-
|
87
|
-
thisPtr += 2;
|
88
|
-
outPtr += 2;
|
89
|
-
}
|
90
|
-
|
91
|
-
Porffor.wasm.i32.store16(outPtr, 60, 0, 4); // <
|
92
|
-
Porffor.wasm.i32.store16(outPtr, 47, 0, 6); // /
|
93
|
-
|
94
|
-
${[...s1].map((x, i) => ` Porffor.wasm.i32.store16(outPtr, ${x.charCodeAt(0)}, 0, ${8 + i * 2}); // ${x}`).join('\n')}
|
95
|
-
|
96
|
-
Porffor.wasm.i32.store16(outPtr, 62, 0, ${8 + s1.length * 2}); // >
|
97
|
-
|
98
|
-
out.length = thisLen + arg.length + ${`<${s1} ${s2}="`.length + s1.length + 5};
|
99
|
-
|
100
|
-
return out;
|
101
|
-
};
|
102
|
-
export const __ByteString_prototype_${name} = (_this: bytestring, arg: any) => {
|
103
|
-
let out: string = Porffor.s\`${`<${s1} ${s2}="`}\`;
|
104
|
-
out += arg;
|
105
|
-
|
106
|
-
let outPtr: i32 = Porffor.wasm\`local.get \${out}\` + ${(`<${s1} ${s2}="`.length + 2) * 2} + arg.length * 2;
|
107
|
-
|
108
|
-
Porffor.wasm.i32.store16(outPtr, 34, 0, 0); // "
|
109
|
-
Porffor.wasm.i32.store16(outPtr, 62, 0, 2); // >
|
110
|
-
|
111
|
-
let thisPtr: i32 = Porffor.wasm\`local.get \${_this}\`;
|
112
|
-
let thisLen: i32 = _this.length;
|
113
|
-
let endPtr: i32 = thisPtr + thisLen;
|
114
|
-
|
115
|
-
while (thisPtr < endPtr) {
|
116
|
-
let chr: i32 = Porffor.wasm.i32.load8_u(thisPtr++, 0, 4);
|
117
|
-
Porffor.wasm.i32.store16(outPtr, chr, 0, 4);
|
118
|
-
|
119
|
-
outPtr += 2;
|
120
|
-
}
|
121
|
-
|
122
|
-
Porffor.wasm.i32.store16(outPtr, 60, 0, 4); // <
|
123
|
-
Porffor.wasm.i32.store16(outPtr, 47, 0, 6); // /
|
124
|
-
|
125
|
-
${[...s1].map((x, i) => ` Porffor.wasm.i32.store16(outPtr, ${x.charCodeAt(0)}, 0, ${8 + i * 2}); // ${x}`).join('\n')}
|
126
|
-
|
127
|
-
Porffor.wasm.i32.store16(outPtr, 62, 0, ${8 + s1.length * 2}); // >
|
128
|
-
|
129
|
-
out.length = thisLen + arg.length + ${`<${s1} ${s2}="`.length + s1.length + 5};
|
130
|
-
|
131
|
-
return out;
|
30
|
+
return Porffor.concatStrings(Porffor.concatStrings(Porffor.concatStrings(Porffor.concatStrings(pre1, arg), pre2), _this), post);
|
132
31
|
};
|
32
|
+
export const __ByteString_prototype_${name} = (_this: any, arg: any) =>
|
33
|
+
__String_prototype_${name}(_this, arg);
|
133
34
|
`;
|
134
35
|
|
135
36
|
arg('fontcolor', 'font', 'color');
|
@@ -137,12 +38,10 @@ ${[...s1].map((x, i) => ` Porffor.wasm.i32.store16(outPtr, ${x.charCodeAt(0)},
|
|
137
38
|
arg('anchor', 'a', 'name');
|
138
39
|
arg('link', 'a', 'href');
|
139
40
|
|
140
|
-
const prototypeAlias = (regular, annex) => `export const __String_prototype_${annex} = (_this:
|
141
|
-
|
142
|
-
}
|
143
|
-
|
144
|
-
return __ByteString_prototype_${regular}(_this);
|
145
|
-
};
|
41
|
+
const prototypeAlias = (regular, annex) => `export const __String_prototype_${annex} = (_this: any) =>
|
42
|
+
__String_prototype_${regular}(_this);
|
43
|
+
export const __ByteString_prototype_${annex} = (_this: any) =>
|
44
|
+
__ByteString_prototype_${regular}(_this);
|
146
45
|
`;
|
147
46
|
|
148
47
|
prototypeAlias('trimStart', 'trimLeft');
|
@@ -193,8 +193,7 @@ export const __Porffor_object_in = (obj: any, prop: any) => {
|
|
193
193
|
return true;
|
194
194
|
}
|
195
195
|
|
196
|
-
|
197
|
-
if (t != Porffor.TYPES.object) {
|
196
|
+
if (Porffor.rawType(obj) != Porffor.TYPES.object) {
|
198
197
|
return false;
|
199
198
|
}
|
200
199
|
|
@@ -206,6 +205,31 @@ export const __Porffor_object_in = (obj: any, prop: any) => {
|
|
206
205
|
|
207
206
|
if (__Object_prototype_hasOwnProperty(obj, prop)) return true;
|
208
207
|
}
|
208
|
+
|
209
|
+
return false;
|
210
|
+
};
|
211
|
+
|
212
|
+
export const __Porffor_object_instanceof = (obj: any, constr: any) => {
|
213
|
+
if (Porffor.rawType(constr) != Porffor.TYPES.function) {
|
214
|
+
throw new TypeError('instanceof right-hand side is not a function');
|
215
|
+
}
|
216
|
+
|
217
|
+
const checkProto: any = constr.prototype;
|
218
|
+
if (!Porffor.object.isObject(checkProto)) {
|
219
|
+
throw new TypeError('instanceof right-hand side has non-object prototype');
|
220
|
+
}
|
221
|
+
|
222
|
+
let lastProto = obj;
|
223
|
+
while (true) {
|
224
|
+
obj = obj.__proto__;
|
225
|
+
if (Porffor.fastOr(obj == null, Porffor.wasm`local.get ${obj}` == Porffor.wasm`local.get ${lastProto}`)) break;
|
226
|
+
lastProto = obj;
|
227
|
+
|
228
|
+
console.log(obj === Object.prototype);
|
229
|
+
if (obj === checkProto) return true;
|
230
|
+
}
|
231
|
+
|
232
|
+
return false;
|
209
233
|
};
|
210
234
|
|
211
235
|
|
package/compiler/builtins.js
CHANGED
@@ -160,19 +160,19 @@ export const BuiltinFuncs = function() {
|
|
160
160
|
// add bitwise ops by converting operands to i32 first
|
161
161
|
for (const [ char, op ] of [ ['&', Opcodes.i32_and], ['|', Opcodes.i32_or], ['^', Opcodes.i32_xor], ['<<', Opcodes.i32_shl], ['>>', Opcodes.i32_shr_s], ['>>>', Opcodes.i32_shr_u] ]) {
|
162
162
|
this[`f64_${char}`] = {
|
163
|
-
params: [
|
163
|
+
params: [ Valtype.f64, Valtype.f64 ],
|
164
164
|
locals: [],
|
165
|
-
returns: [
|
165
|
+
returns: [ Valtype.f64 ],
|
166
166
|
returnType: TYPES.number,
|
167
167
|
wasm: [
|
168
168
|
[ Opcodes.local_get, 0 ],
|
169
|
-
Opcodes.
|
169
|
+
Opcodes.i32_trunc_sat_f64_s,
|
170
170
|
|
171
171
|
[ Opcodes.local_get, 1 ],
|
172
|
-
Opcodes.
|
172
|
+
Opcodes.i32_trunc_sat_f64_s,
|
173
173
|
|
174
174
|
[ op ],
|
175
|
-
Opcodes.
|
175
|
+
[ Opcodes.f64_convert_i32_s ]
|
176
176
|
]
|
177
177
|
};
|
178
178
|
}
|