porffor 0.35.1 → 0.35.2
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.js +5 -5
- package/compiler/builtins_precompiled.js +91 -104
- package/compiler/codegen.js +57 -9
- 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');
|
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
|
}
|
|
@@ -136,160 +136,147 @@ params:[124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
|
136
136
|
locals:[124,124,127],localNames:["a","a#type","b","b#type","at","bt","#last_type"],
|
|
137
137
|
};
|
|
138
138
|
this.__String_prototype_big = {
|
|
139
|
-
wasm:(_,{allocPage})=>[...number(allocPage(_,'
|
|
140
|
-
params:[
|
|
141
|
-
locals:[
|
|
142
|
-
data:{"
|
|
139
|
+
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'bytestring: __String_prototype_big/pre','i8'),124),[33,2],...number(allocPage(_,'bytestring: __String_prototype_big/post','i8'),124),[33,3],[32,2],[65,195,1],[32,0],[32,1],[16,builtin('__Porffor_concatStrings')],[34,4],[32,3],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,4],[15]],
|
|
140
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
141
|
+
locals:[124,124,127],localNames:["_this","_this#type","pre","post","#last_type"],
|
|
142
|
+
data:{"bytestring: __String_prototype_big/pre":[5,0,0,0,60,98,105,103,62],"bytestring: __String_prototype_big/post":[6,0,0,0,60,47,98,105,103,62]},
|
|
143
143
|
};
|
|
144
144
|
this.__ByteString_prototype_big = {
|
|
145
|
-
wasm:(_,{
|
|
146
|
-
params:[
|
|
147
|
-
locals:[127
|
|
148
|
-
data:{"bytestring: __ByteString_prototype_big/out":[5,0,0,0,60,98,105,103,62]},
|
|
145
|
+
wasm:(_,{builtin})=>[[32,0],[32,1],[16,builtin('__String_prototype_big')],[34,2],[15]],
|
|
146
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
147
|
+
locals:[127],localNames:["_this","_this#type","#last_type"],
|
|
149
148
|
};
|
|
150
149
|
this.__String_prototype_blink = {
|
|
151
|
-
wasm:(_,{allocPage})=>[...number(allocPage(_,'
|
|
152
|
-
params:[
|
|
153
|
-
locals:[
|
|
154
|
-
data:{"
|
|
150
|
+
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'bytestring: __String_prototype_blink/pre','i8'),124),[33,2],...number(allocPage(_,'bytestring: __String_prototype_blink/post','i8'),124),[33,3],[32,2],[65,195,1],[32,0],[32,1],[16,builtin('__Porffor_concatStrings')],[34,4],[32,3],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,4],[15]],
|
|
151
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
152
|
+
locals:[124,124,127],localNames:["_this","_this#type","pre","post","#last_type"],
|
|
153
|
+
data:{"bytestring: __String_prototype_blink/pre":[7,0,0,0,60,98,108,105,110,107,62],"bytestring: __String_prototype_blink/post":[8,0,0,0,60,47,98,108,105,110,107,62]},
|
|
155
154
|
};
|
|
156
155
|
this.__ByteString_prototype_blink = {
|
|
157
|
-
wasm:(_,{
|
|
158
|
-
params:[
|
|
159
|
-
locals:[127
|
|
160
|
-
data:{"bytestring: __ByteString_prototype_blink/out":[7,0,0,0,60,98,108,105,110,107,62]},
|
|
156
|
+
wasm:(_,{builtin})=>[[32,0],[32,1],[16,builtin('__String_prototype_blink')],[34,2],[15]],
|
|
157
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
158
|
+
locals:[127],localNames:["_this","_this#type","#last_type"],
|
|
161
159
|
};
|
|
162
160
|
this.__String_prototype_bold = {
|
|
163
|
-
wasm:(_,{allocPage})=>[...number(allocPage(_,'
|
|
164
|
-
params:[
|
|
165
|
-
locals:[
|
|
166
|
-
data:{"
|
|
161
|
+
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'bytestring: __String_prototype_bold/pre','i8'),124),[33,2],...number(allocPage(_,'bytestring: __String_prototype_bold/post','i8'),124),[33,3],[32,2],[65,195,1],[32,0],[32,1],[16,builtin('__Porffor_concatStrings')],[34,4],[32,3],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,4],[15]],
|
|
162
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
163
|
+
locals:[124,124,127],localNames:["_this","_this#type","pre","post","#last_type"],
|
|
164
|
+
data:{"bytestring: __String_prototype_bold/pre":[3,0,0,0,60,98,62],"bytestring: __String_prototype_bold/post":[4,0,0,0,60,47,98,62]},
|
|
167
165
|
};
|
|
168
166
|
this.__ByteString_prototype_bold = {
|
|
169
|
-
wasm:(_,{
|
|
170
|
-
params:[
|
|
171
|
-
locals:[127
|
|
172
|
-
data:{"bytestring: __ByteString_prototype_bold/out":[3,0,0,0,60,98,62]},
|
|
167
|
+
wasm:(_,{builtin})=>[[32,0],[32,1],[16,builtin('__String_prototype_bold')],[34,2],[15]],
|
|
168
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
169
|
+
locals:[127],localNames:["_this","_this#type","#last_type"],
|
|
173
170
|
};
|
|
174
171
|
this.__String_prototype_fixed = {
|
|
175
|
-
wasm:(_,{allocPage})=>[...number(allocPage(_,'
|
|
176
|
-
params:[
|
|
177
|
-
locals:[
|
|
178
|
-
data:{"
|
|
172
|
+
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'bytestring: __String_prototype_fixed/pre','i8'),124),[33,2],...number(allocPage(_,'bytestring: __String_prototype_fixed/post','i8'),124),[33,3],[32,2],[65,195,1],[32,0],[32,1],[16,builtin('__Porffor_concatStrings')],[34,4],[32,3],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,4],[15]],
|
|
173
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
174
|
+
locals:[124,124,127],localNames:["_this","_this#type","pre","post","#last_type"],
|
|
175
|
+
data:{"bytestring: __String_prototype_fixed/pre":[4,0,0,0,60,116,116,62],"bytestring: __String_prototype_fixed/post":[5,0,0,0,60,47,116,116,62]},
|
|
179
176
|
};
|
|
180
177
|
this.__ByteString_prototype_fixed = {
|
|
181
|
-
wasm:(_,{
|
|
182
|
-
params:[
|
|
183
|
-
locals:[127
|
|
184
|
-
data:{"bytestring: __ByteString_prototype_fixed/out":[4,0,0,0,60,116,116,62]},
|
|
178
|
+
wasm:(_,{builtin})=>[[32,0],[32,1],[16,builtin('__String_prototype_fixed')],[34,2],[15]],
|
|
179
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
180
|
+
locals:[127],localNames:["_this","_this#type","#last_type"],
|
|
185
181
|
};
|
|
186
182
|
this.__String_prototype_italics = {
|
|
187
|
-
wasm:(_,{allocPage})=>[...number(allocPage(_,'
|
|
188
|
-
params:[
|
|
189
|
-
locals:[
|
|
190
|
-
data:{"
|
|
183
|
+
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'bytestring: __String_prototype_italics/pre','i8'),124),[33,2],...number(allocPage(_,'bytestring: __String_prototype_italics/post','i8'),124),[33,3],[32,2],[65,195,1],[32,0],[32,1],[16,builtin('__Porffor_concatStrings')],[34,4],[32,3],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,4],[15]],
|
|
184
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
185
|
+
locals:[124,124,127],localNames:["_this","_this#type","pre","post","#last_type"],
|
|
186
|
+
data:{"bytestring: __String_prototype_italics/pre":[3,0,0,0,60,105,62],"bytestring: __String_prototype_italics/post":[4,0,0,0,60,47,105,62]},
|
|
191
187
|
};
|
|
192
188
|
this.__ByteString_prototype_italics = {
|
|
193
|
-
wasm:(_,{
|
|
194
|
-
params:[
|
|
195
|
-
locals:[127
|
|
196
|
-
data:{"bytestring: __ByteString_prototype_italics/out":[3,0,0,0,60,105,62]},
|
|
189
|
+
wasm:(_,{builtin})=>[[32,0],[32,1],[16,builtin('__String_prototype_italics')],[34,2],[15]],
|
|
190
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
191
|
+
locals:[127],localNames:["_this","_this#type","#last_type"],
|
|
197
192
|
};
|
|
198
193
|
this.__String_prototype_small = {
|
|
199
|
-
wasm:(_,{allocPage})=>[...number(allocPage(_,'
|
|
200
|
-
params:[
|
|
201
|
-
locals:[
|
|
202
|
-
data:{"
|
|
194
|
+
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'bytestring: __String_prototype_small/pre','i8'),124),[33,2],...number(allocPage(_,'bytestring: __String_prototype_small/post','i8'),124),[33,3],[32,2],[65,195,1],[32,0],[32,1],[16,builtin('__Porffor_concatStrings')],[34,4],[32,3],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,4],[15]],
|
|
195
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
196
|
+
locals:[124,124,127],localNames:["_this","_this#type","pre","post","#last_type"],
|
|
197
|
+
data:{"bytestring: __String_prototype_small/pre":[7,0,0,0,60,115,109,97,108,108,62],"bytestring: __String_prototype_small/post":[8,0,0,0,60,47,115,109,97,108,108,62]},
|
|
203
198
|
};
|
|
204
199
|
this.__ByteString_prototype_small = {
|
|
205
|
-
wasm:(_,{
|
|
206
|
-
params:[
|
|
207
|
-
locals:[127
|
|
208
|
-
data:{"bytestring: __ByteString_prototype_small/out":[7,0,0,0,60,115,109,97,108,108,62]},
|
|
200
|
+
wasm:(_,{builtin})=>[[32,0],[32,1],[16,builtin('__String_prototype_small')],[34,2],[15]],
|
|
201
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
202
|
+
locals:[127],localNames:["_this","_this#type","#last_type"],
|
|
209
203
|
};
|
|
210
204
|
this.__String_prototype_strike = {
|
|
211
|
-
wasm:(_,{allocPage})=>[...number(allocPage(_,'
|
|
212
|
-
params:[
|
|
213
|
-
locals:[
|
|
214
|
-
data:{"
|
|
205
|
+
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'bytestring: __String_prototype_strike/pre','i8'),124),[33,2],...number(allocPage(_,'bytestring: __String_prototype_strike/post','i8'),124),[33,3],[32,2],[65,195,1],[32,0],[32,1],[16,builtin('__Porffor_concatStrings')],[34,4],[32,3],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,4],[15]],
|
|
206
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
207
|
+
locals:[124,124,127],localNames:["_this","_this#type","pre","post","#last_type"],
|
|
208
|
+
data:{"bytestring: __String_prototype_strike/pre":[8,0,0,0,60,115,116,114,105,107,101,62],"bytestring: __String_prototype_strike/post":[9,0,0,0,60,47,115,116,114,105,107,101,62]},
|
|
215
209
|
};
|
|
216
210
|
this.__ByteString_prototype_strike = {
|
|
217
|
-
wasm:(_,{
|
|
218
|
-
params:[
|
|
219
|
-
locals:[127
|
|
220
|
-
data:{"bytestring: __ByteString_prototype_strike/out":[8,0,0,0,60,115,116,114,105,107,101,62]},
|
|
211
|
+
wasm:(_,{builtin})=>[[32,0],[32,1],[16,builtin('__String_prototype_strike')],[34,2],[15]],
|
|
212
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
213
|
+
locals:[127],localNames:["_this","_this#type","#last_type"],
|
|
221
214
|
};
|
|
222
215
|
this.__String_prototype_sub = {
|
|
223
|
-
wasm:(_,{allocPage})=>[...number(allocPage(_,'
|
|
224
|
-
params:[
|
|
225
|
-
locals:[
|
|
226
|
-
data:{"
|
|
216
|
+
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'bytestring: __String_prototype_sub/pre','i8'),124),[33,2],...number(allocPage(_,'bytestring: __String_prototype_sub/post','i8'),124),[33,3],[32,2],[65,195,1],[32,0],[32,1],[16,builtin('__Porffor_concatStrings')],[34,4],[32,3],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,4],[15]],
|
|
217
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
218
|
+
locals:[124,124,127],localNames:["_this","_this#type","pre","post","#last_type"],
|
|
219
|
+
data:{"bytestring: __String_prototype_sub/pre":[5,0,0,0,60,115,117,98,62],"bytestring: __String_prototype_sub/post":[6,0,0,0,60,47,115,117,98,62]},
|
|
227
220
|
};
|
|
228
221
|
this.__ByteString_prototype_sub = {
|
|
229
|
-
wasm:(_,{
|
|
230
|
-
params:[
|
|
231
|
-
locals:[127
|
|
232
|
-
data:{"bytestring: __ByteString_prototype_sub/out":[5,0,0,0,60,115,117,98,62]},
|
|
222
|
+
wasm:(_,{builtin})=>[[32,0],[32,1],[16,builtin('__String_prototype_sub')],[34,2],[15]],
|
|
223
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
224
|
+
locals:[127],localNames:["_this","_this#type","#last_type"],
|
|
233
225
|
};
|
|
234
226
|
this.__String_prototype_sup = {
|
|
235
|
-
wasm:(_,{allocPage})=>[...number(allocPage(_,'
|
|
236
|
-
params:[
|
|
237
|
-
locals:[
|
|
238
|
-
data:{"
|
|
227
|
+
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'bytestring: __String_prototype_sup/pre','i8'),124),[33,2],...number(allocPage(_,'bytestring: __String_prototype_sup/post','i8'),124),[33,3],[32,2],[65,195,1],[32,0],[32,1],[16,builtin('__Porffor_concatStrings')],[34,4],[32,3],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,4],[15]],
|
|
228
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
229
|
+
locals:[124,124,127],localNames:["_this","_this#type","pre","post","#last_type"],
|
|
230
|
+
data:{"bytestring: __String_prototype_sup/pre":[5,0,0,0,60,115,117,112,62],"bytestring: __String_prototype_sup/post":[6,0,0,0,60,47,115,117,112,62]},
|
|
239
231
|
};
|
|
240
232
|
this.__ByteString_prototype_sup = {
|
|
241
|
-
wasm:(_,{
|
|
242
|
-
params:[
|
|
243
|
-
locals:[127
|
|
244
|
-
data:{"bytestring: __ByteString_prototype_sup/out":[5,0,0,0,60,115,117,112,62]},
|
|
233
|
+
wasm:(_,{builtin})=>[[32,0],[32,1],[16,builtin('__String_prototype_sup')],[34,2],[15]],
|
|
234
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
235
|
+
locals:[127],localNames:["_this","_this#type","#last_type"],
|
|
245
236
|
};
|
|
246
237
|
this.__String_prototype_fontcolor = {
|
|
247
|
-
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'
|
|
248
|
-
params:[
|
|
249
|
-
locals:[
|
|
250
|
-
data:{"
|
|
238
|
+
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'bytestring: __String_prototype_fontcolor/pre1','i8'),124),[33,4],...number(allocPage(_,'bytestring: __String_prototype_fontcolor/pre2','i8'),124),[33,5],...number(allocPage(_,'bytestring: __String_prototype_fontcolor/post','i8'),124),[33,6],[32,4],[65,195,1],[32,2],[32,3],[16,builtin('__Porffor_concatStrings')],[34,7],[32,5],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,7],[32,0],[32,1],[16,builtin('__Porffor_concatStrings')],[34,7],[32,6],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,7],[15]],
|
|
239
|
+
params:[124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
240
|
+
locals:[124,124,124,127],localNames:["_this","_this#type","arg","arg#type","pre1","pre2","post","#last_type"],
|
|
241
|
+
data:{"bytestring: __String_prototype_fontcolor/pre1":[13,0,0,0,60,102,111,110,116,32,99,111,108,111,114,61,34],"bytestring: __String_prototype_fontcolor/pre2":[2,0,0,0,34,62],"bytestring: __String_prototype_fontcolor/post":[7,0,0,0,60,47,102,111,110,116,62]},
|
|
251
242
|
};
|
|
252
243
|
this.__ByteString_prototype_fontcolor = {
|
|
253
|
-
wasm:(_,{
|
|
254
|
-
params:[
|
|
255
|
-
locals:[127
|
|
256
|
-
data:{"string: __ByteString_prototype_fontcolor/out":[13,0,0,0,60,0,102,0,111,0,110,0,116,0,32,0,99,0,111,0,108,0,111,0,114,0,61,0,34,0]},
|
|
244
|
+
wasm:(_,{builtin})=>[[32,0],[32,1],[32,2],[32,3],[16,builtin('__String_prototype_fontcolor')],[34,4],[15]],
|
|
245
|
+
params:[124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
246
|
+
locals:[127],localNames:["_this","_this#type","arg","arg#type","#last_type"],
|
|
257
247
|
};
|
|
258
248
|
this.__String_prototype_fontsize = {
|
|
259
|
-
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'
|
|
260
|
-
params:[
|
|
261
|
-
locals:[
|
|
262
|
-
data:{"
|
|
249
|
+
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'bytestring: __String_prototype_fontsize/pre1','i8'),124),[33,4],...number(allocPage(_,'bytestring: __String_prototype_fontsize/pre2','i8'),124),[33,5],...number(allocPage(_,'bytestring: __String_prototype_fontsize/post','i8'),124),[33,6],[32,4],[65,195,1],[32,2],[32,3],[16,builtin('__Porffor_concatStrings')],[34,7],[32,5],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,7],[32,0],[32,1],[16,builtin('__Porffor_concatStrings')],[34,7],[32,6],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,7],[15]],
|
|
250
|
+
params:[124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
251
|
+
locals:[124,124,124,127],localNames:["_this","_this#type","arg","arg#type","pre1","pre2","post","#last_type"],
|
|
252
|
+
data:{"bytestring: __String_prototype_fontsize/pre1":[12,0,0,0,60,102,111,110,116,32,115,105,122,101,61,34],"bytestring: __String_prototype_fontsize/pre2":[2,0,0,0,34,62],"bytestring: __String_prototype_fontsize/post":[7,0,0,0,60,47,102,111,110,116,62]},
|
|
263
253
|
};
|
|
264
254
|
this.__ByteString_prototype_fontsize = {
|
|
265
|
-
wasm:(_,{
|
|
266
|
-
params:[
|
|
267
|
-
locals:[127
|
|
268
|
-
data:{"string: __ByteString_prototype_fontsize/out":[12,0,0,0,60,0,102,0,111,0,110,0,116,0,32,0,115,0,105,0,122,0,101,0,61,0,34,0]},
|
|
255
|
+
wasm:(_,{builtin})=>[[32,0],[32,1],[32,2],[32,3],[16,builtin('__String_prototype_fontsize')],[34,4],[15]],
|
|
256
|
+
params:[124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
257
|
+
locals:[127],localNames:["_this","_this#type","arg","arg#type","#last_type"],
|
|
269
258
|
};
|
|
270
259
|
this.__String_prototype_anchor = {
|
|
271
|
-
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'
|
|
272
|
-
params:[
|
|
273
|
-
locals:[
|
|
274
|
-
data:{"
|
|
260
|
+
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'bytestring: __String_prototype_anchor/pre1','i8'),124),[33,4],...number(allocPage(_,'bytestring: __String_prototype_anchor/pre2','i8'),124),[33,5],...number(allocPage(_,'bytestring: __String_prototype_anchor/post','i8'),124),[33,6],[32,4],[65,195,1],[32,2],[32,3],[16,builtin('__Porffor_concatStrings')],[34,7],[32,5],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,7],[32,0],[32,1],[16,builtin('__Porffor_concatStrings')],[34,7],[32,6],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,7],[15]],
|
|
261
|
+
params:[124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
262
|
+
locals:[124,124,124,127],localNames:["_this","_this#type","arg","arg#type","pre1","pre2","post","#last_type"],
|
|
263
|
+
data:{"bytestring: __String_prototype_anchor/pre1":[9,0,0,0,60,97,32,110,97,109,101,61,34],"bytestring: __String_prototype_anchor/pre2":[2,0,0,0,34,62],"bytestring: __String_prototype_anchor/post":[4,0,0,0,60,47,97,62]},
|
|
275
264
|
};
|
|
276
265
|
this.__ByteString_prototype_anchor = {
|
|
277
|
-
wasm:(_,{
|
|
278
|
-
params:[
|
|
279
|
-
locals:[127
|
|
280
|
-
data:{"string: __ByteString_prototype_anchor/out":[9,0,0,0,60,0,97,0,32,0,110,0,97,0,109,0,101,0,61,0,34,0]},
|
|
266
|
+
wasm:(_,{builtin})=>[[32,0],[32,1],[32,2],[32,3],[16,builtin('__String_prototype_anchor')],[34,4],[15]],
|
|
267
|
+
params:[124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
268
|
+
locals:[127],localNames:["_this","_this#type","arg","arg#type","#last_type"],
|
|
281
269
|
};
|
|
282
270
|
this.__String_prototype_link = {
|
|
283
|
-
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'
|
|
284
|
-
params:[
|
|
285
|
-
locals:[
|
|
286
|
-
data:{"
|
|
271
|
+
wasm:(_,{allocPage,builtin})=>[...number(allocPage(_,'bytestring: __String_prototype_link/pre1','i8'),124),[33,4],...number(allocPage(_,'bytestring: __String_prototype_link/pre2','i8'),124),[33,5],...number(allocPage(_,'bytestring: __String_prototype_link/post','i8'),124),[33,6],[32,4],[65,195,1],[32,2],[32,3],[16,builtin('__Porffor_concatStrings')],[34,7],[32,5],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,7],[32,0],[32,1],[16,builtin('__Porffor_concatStrings')],[34,7],[32,6],[65,195,1],[16,builtin('__Porffor_concatStrings')],[34,7],[15]],
|
|
272
|
+
params:[124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
273
|
+
locals:[124,124,124,127],localNames:["_this","_this#type","arg","arg#type","pre1","pre2","post","#last_type"],
|
|
274
|
+
data:{"bytestring: __String_prototype_link/pre1":[9,0,0,0,60,97,32,104,114,101,102,61,34],"bytestring: __String_prototype_link/pre2":[2,0,0,0,34,62],"bytestring: __String_prototype_link/post":[4,0,0,0,60,47,97,62]},
|
|
287
275
|
};
|
|
288
276
|
this.__ByteString_prototype_link = {
|
|
289
|
-
wasm:(_,{
|
|
290
|
-
params:[
|
|
291
|
-
locals:[127
|
|
292
|
-
data:{"string: __ByteString_prototype_link/out":[9,0,0,0,60,0,97,0,32,0,104,0,114,0,101,0,102,0,61,0,34,0]},
|
|
277
|
+
wasm:(_,{builtin})=>[[32,0],[32,1],[32,2],[32,3],[16,builtin('__String_prototype_link')],[34,4],[15]],
|
|
278
|
+
params:[124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
279
|
+
locals:[127],localNames:["_this","_this#type","arg","arg#type","#last_type"],
|
|
293
280
|
};
|
|
294
281
|
this.__Array_isArray = {
|
|
295
282
|
wasm:()=>[[32,1],[184],[68,80],[97],[184],[65,2],[15]],
|
package/compiler/codegen.js
CHANGED
|
@@ -183,6 +183,9 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
|
|
|
183
183
|
case 'AwaitExpression':
|
|
184
184
|
return cacheAst(decl, generateAwait(scope, decl));
|
|
185
185
|
|
|
186
|
+
case 'TemplateLiteral':
|
|
187
|
+
return cacheAst(decl, generateTemplate(scope, decl));
|
|
188
|
+
|
|
186
189
|
case 'ExportNamedDeclaration':
|
|
187
190
|
if (!decl.declaration) return todo(scope, 'unsupported export declaration');
|
|
188
191
|
|
|
@@ -722,8 +725,8 @@ const performOp = (scope, op, left, right, leftType, rightType, _global = false,
|
|
|
722
725
|
return performLogicOp(scope, op, left, right, leftType, rightType);
|
|
723
726
|
}
|
|
724
727
|
|
|
725
|
-
const knownLeft =
|
|
726
|
-
const knownRight =
|
|
728
|
+
const knownLeft = knownTypeWithGuess(scope, leftType);
|
|
729
|
+
const knownRight = knownTypeWithGuess(scope, rightType);
|
|
727
730
|
|
|
728
731
|
const eqOp = ['==', '===', '!=', '!==', '>', '>=', '<', '<='].includes(op);
|
|
729
732
|
const strictOp = op === '===' || op === '!==';
|
|
@@ -1213,6 +1216,7 @@ const setLastType = (scope, type = []) => [
|
|
|
1213
1216
|
];
|
|
1214
1217
|
|
|
1215
1218
|
const getNodeType = (scope, node) => {
|
|
1219
|
+
let guess = null;
|
|
1216
1220
|
const ret = (() => {
|
|
1217
1221
|
if (node._type) return node._type;
|
|
1218
1222
|
if (node.type === 'Literal') {
|
|
@@ -1338,17 +1342,20 @@ const getNodeType = (scope, node) => {
|
|
|
1338
1342
|
|
|
1339
1343
|
const leftType = getNodeType(scope, node.left);
|
|
1340
1344
|
const rightType = getNodeType(scope, node.right);
|
|
1341
|
-
const knownLeft =
|
|
1342
|
-
const knownRight =
|
|
1345
|
+
const knownLeft = knownTypeWithGuess(scope, leftType);
|
|
1346
|
+
const knownRight = knownTypeWithGuess(scope, rightType);
|
|
1343
1347
|
|
|
1344
1348
|
if ((knownLeft != null || knownRight != null) && !(
|
|
1345
1349
|
(knownLeft === TYPES.string || knownRight === TYPES.string) ||
|
|
1346
1350
|
(knownLeft === TYPES.bytestring || knownRight === TYPES.bytestring)
|
|
1347
1351
|
)) return TYPES.number;
|
|
1348
1352
|
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1353
|
+
if (knownLeft === TYPES.string || knownRight === TYPES.string)
|
|
1354
|
+
return TYPES.string;
|
|
1355
|
+
|
|
1356
|
+
// guess bytestring, could really be bytestring or string
|
|
1357
|
+
if (knownLeft === TYPES.bytestring || knownRight === TYPES.bytestring)
|
|
1358
|
+
guess = TYPES.bytestring;
|
|
1352
1359
|
|
|
1353
1360
|
if (scope.locals['#last_type']) return getLastType(scope);
|
|
1354
1361
|
|
|
@@ -1426,8 +1433,10 @@ const getNodeType = (scope, node) => {
|
|
|
1426
1433
|
return TYPES.number;
|
|
1427
1434
|
})();
|
|
1428
1435
|
|
|
1429
|
-
|
|
1430
|
-
|
|
1436
|
+
const out = typeof ret === 'number' ? number(ret, Valtype.i32) : ret;
|
|
1437
|
+
if (guess != null) out.guess = typeof guess === 'number' ? number(guess, Valtype.i32) : guess;
|
|
1438
|
+
|
|
1439
|
+
return out;
|
|
1431
1440
|
};
|
|
1432
1441
|
|
|
1433
1442
|
const generateLiteral = (scope, decl, global, name) => {
|
|
@@ -2557,6 +2566,13 @@ const knownType = (scope, type) => {
|
|
|
2557
2566
|
|
|
2558
2567
|
return null;
|
|
2559
2568
|
};
|
|
2569
|
+
const knownTypeWithGuess = (scope, type) => {
|
|
2570
|
+
let known = knownType(scope, type);
|
|
2571
|
+
if (known != null) return known;
|
|
2572
|
+
|
|
2573
|
+
if (type.guess != null) return knownType(scope, type.guess);
|
|
2574
|
+
return known;
|
|
2575
|
+
};
|
|
2560
2576
|
|
|
2561
2577
|
const brTable = (input, bc, returns) => {
|
|
2562
2578
|
const out = [];
|
|
@@ -5663,6 +5679,38 @@ const generateClass = (scope, decl) => {
|
|
|
5663
5679
|
return out;
|
|
5664
5680
|
};
|
|
5665
5681
|
|
|
5682
|
+
export const generateTemplate = (scope, decl) => {
|
|
5683
|
+
let current = null;
|
|
5684
|
+
const append = val => {
|
|
5685
|
+
// console.log(val);
|
|
5686
|
+
if (!current) {
|
|
5687
|
+
current = val;
|
|
5688
|
+
return;
|
|
5689
|
+
}
|
|
5690
|
+
|
|
5691
|
+
current = {
|
|
5692
|
+
type: 'BinaryExpression',
|
|
5693
|
+
operator: '+',
|
|
5694
|
+
left: current,
|
|
5695
|
+
right: val
|
|
5696
|
+
};
|
|
5697
|
+
};
|
|
5698
|
+
|
|
5699
|
+
const { expressions, quasis } = decl;
|
|
5700
|
+
for (let i = 0; i < quasis.length; i++) {
|
|
5701
|
+
append({
|
|
5702
|
+
type: 'Literal',
|
|
5703
|
+
value: quasis[i].value.cooked
|
|
5704
|
+
});
|
|
5705
|
+
|
|
5706
|
+
if (i < expressions.length) {
|
|
5707
|
+
append(expressions[i]);
|
|
5708
|
+
}
|
|
5709
|
+
}
|
|
5710
|
+
|
|
5711
|
+
return generate(scope, current);
|
|
5712
|
+
};
|
|
5713
|
+
|
|
5666
5714
|
globalThis._uniqId = 0;
|
|
5667
5715
|
const uniqId = () => '_' + globalThis._uniqId++;
|
|
5668
5716
|
|
package/package.json
CHANGED
package/runner/index.js
CHANGED
package/runner/repl.js
CHANGED
|
@@ -61,7 +61,10 @@ const memoryToString = mem => {
|
|
|
61
61
|
out += ` \x1B[34m${name}${' '.repeat(longestName - name.length)} \x1B[90m│\x1B[0m \x1B[36m${type}${' '.repeat(longestType - type.length)} \x1B[90m│\x1B[0m `;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
let j = 0;
|
|
65
|
+
if (i === 0) j = 16;
|
|
66
|
+
const end = j + 40;
|
|
67
|
+
for (; j < end; j++) {
|
|
65
68
|
const val = buf[i * pageSize + j];
|
|
66
69
|
// if (val === 0) out += '\x1B[2m';
|
|
67
70
|
if (val === 0) out += '\x1B[90m';
|