porffor 0.14.0-2ce6edbb3 → 0.14.0-320727338
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 +9 -3
- package/asur/index.js +1 -1
- package/compiler/2c.js +3 -0
- package/compiler/assemble.js +14 -0
- package/compiler/builtins/annexb_string.ts +1 -0
- package/compiler/builtins/array.ts +84 -4
- package/compiler/builtins/base64.ts +1 -0
- package/compiler/builtins/boolean.ts +2 -0
- package/compiler/builtins/crypto.ts +1 -0
- package/compiler/builtins/date.ts +2 -0
- package/compiler/builtins/error.js +22 -0
- package/compiler/builtins/escape.ts +1 -2
- package/compiler/builtins/function.ts +2 -0
- package/compiler/builtins/int.ts +2 -0
- package/compiler/builtins/math.ts +410 -0
- package/compiler/builtins/number.ts +2 -0
- package/compiler/builtins/object.ts +2 -0
- package/compiler/builtins/set.ts +7 -6
- package/compiler/builtins/string.ts +1 -0
- package/compiler/builtins/symbol.ts +3 -1
- package/compiler/builtins.js +10 -6
- package/compiler/codegen.js +478 -257
- package/compiler/generated_builtins.js +491 -60
- package/compiler/precompile.js +5 -4
- package/compiler/prefs.js +1 -1
- package/compiler/prototype.js +180 -157
- package/compiler/wrap.js +66 -37
- package/package.json +1 -1
- package/runner/index.js +1 -1
- package/runner/repl.js +18 -2
package/compiler/builtins/set.ts
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
import type {} from './porffor.d.ts';
|
2
|
+
|
1
3
|
// dark wasm magic for dealing with memory, sorry.
|
2
4
|
export const __Porffor_allocate = (): number => {
|
3
5
|
Porffor.wasm`i32.const 1
|
@@ -56,14 +58,13 @@ i32.store8 0 12`;
|
|
56
58
|
};
|
57
59
|
|
58
60
|
|
59
|
-
|
60
|
-
export const __Set_prototype_size = (_this: Set) => {
|
61
|
+
export const __Set_prototype_size$get = (_this: Set) => {
|
61
62
|
return Porffor.wasm.i32.load(_this, 0, 0);
|
62
63
|
};
|
63
64
|
|
64
65
|
export const __Set_prototype_values = (_this: Set) => {
|
65
66
|
// todo: this should return an iterator not array
|
66
|
-
const size: number =
|
67
|
+
const size: number = Porffor.wasm.i32.load(_this, 0, 0);
|
67
68
|
|
68
69
|
const out: any[] = __Porffor_allocate();
|
69
70
|
for (let i: number = 0; i < size; i++) {
|
@@ -79,7 +80,7 @@ export const __Set_prototype_keys = (_this: Set) => {
|
|
79
80
|
};
|
80
81
|
|
81
82
|
export const __Set_prototype_has = (_this: Set, value: any) => {
|
82
|
-
const size: number =
|
83
|
+
const size: number = Porffor.wasm.i32.load(_this, 0, 0);
|
83
84
|
|
84
85
|
for (let i: number = 0; i < size; i++) {
|
85
86
|
if (__Porffor_set_read(_this, i) === value) return true;
|
@@ -89,7 +90,7 @@ export const __Set_prototype_has = (_this: Set, value: any) => {
|
|
89
90
|
};
|
90
91
|
|
91
92
|
export const __Set_prototype_add = (_this: Set, value: any) => {
|
92
|
-
const size: number =
|
93
|
+
const size: number = Porffor.wasm.i32.load(_this, 0, 0);
|
93
94
|
|
94
95
|
// check if already in set
|
95
96
|
for (let i: number = 0; i < size; i++) {
|
@@ -107,7 +108,7 @@ export const __Set_prototype_add = (_this: Set, value: any) => {
|
|
107
108
|
};
|
108
109
|
|
109
110
|
export const __Set_prototype_delete = (_this: Set, value: any) => {
|
110
|
-
const size: number =
|
111
|
+
const size: number = Porffor.wasm.i32.load(_this, 0, 0);
|
111
112
|
|
112
113
|
// check if already in set
|
113
114
|
for (let i: number = 0; i < size; i++) {
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import type {} from './porffor.d.ts';
|
2
|
+
|
1
3
|
export const __Porffor_symbol_descStore = (op: boolean, value: any): any => {
|
2
4
|
const ptr: bytestring = '';
|
3
5
|
|
@@ -19,7 +21,7 @@ export const Symbol = (description: any): Symbol => {
|
|
19
21
|
};
|
20
22
|
|
21
23
|
// todo: this should be a getter somehow not a method
|
22
|
-
export const __Symbol_prototype_description = (_this: Symbol) => {
|
24
|
+
export const __Symbol_prototype_description$get = (_this: Symbol) => {
|
23
25
|
const description: bytestring = __Porffor_symbol_descStore(false,
|
24
26
|
Porffor.wasm`local.get ${_this}` - 1);
|
25
27
|
return description;
|
package/compiler/builtins.js
CHANGED
@@ -221,7 +221,7 @@ export const BuiltinFuncs = function() {
|
|
221
221
|
typedParams: true,
|
222
222
|
locals: [ Valtype.i32, Valtype.i32 ],
|
223
223
|
returns: [],
|
224
|
-
wasm: (scope, { typeSwitch }) => [
|
224
|
+
wasm: (scope, { typeSwitch, builtin }) => [
|
225
225
|
...typeSwitch(scope, [ [ Opcodes.local_get, 1 ] ], {
|
226
226
|
[TYPES.number]: [
|
227
227
|
[ Opcodes.local_get, 0 ],
|
@@ -317,7 +317,7 @@ export const BuiltinFuncs = function() {
|
|
317
317
|
|
318
318
|
// make end pointer
|
319
319
|
[ Opcodes.i32_load, Math.log2(ValtypeSize.i32) - 1, 0 ],
|
320
|
-
...number(ValtypeSize[valtype], Valtype.i32),
|
320
|
+
...number(ValtypeSize[valtype] + 1, Valtype.i32),
|
321
321
|
[ Opcodes.i32_mul ],
|
322
322
|
|
323
323
|
[ Opcodes.local_get, 2 ],
|
@@ -326,14 +326,18 @@ export const BuiltinFuncs = function() {
|
|
326
326
|
|
327
327
|
[ Opcodes.loop, Blocktype.void ],
|
328
328
|
|
329
|
-
// print current
|
329
|
+
// print current array element
|
330
330
|
[ Opcodes.local_get, 2 ],
|
331
|
-
[ Opcodes.load,
|
332
|
-
|
331
|
+
[ Opcodes.load, 0, ValtypeSize.i32 ],
|
332
|
+
|
333
|
+
[ Opcodes.local_get, 2 ],
|
334
|
+
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ],
|
335
|
+
|
336
|
+
[ Opcodes.call, builtin('__Porffor_print') ],
|
333
337
|
|
334
338
|
// increment pointer by sizeof valtype
|
335
339
|
[ Opcodes.local_get, 2 ],
|
336
|
-
...number(ValtypeSize[valtype], Valtype.i32),
|
340
|
+
...number(ValtypeSize[valtype] + 1, Valtype.i32),
|
337
341
|
[ Opcodes.i32_add ],
|
338
342
|
[ Opcodes.local_tee, 2 ],
|
339
343
|
|