porffor 0.14.0-a24ac8cf2 → 0.14.0-b1e1c2265

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.
@@ -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
- // todo: this should be a getter somehow not a method
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 = __Set_prototype_size(_this);
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 = __Set_prototype_size(_this);
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 = __Set_prototype_size(_this);
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 = __Set_prototype_size(_this);
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,4 +1,5 @@
1
1
  // @porf --valtype=i32
2
+ import type {} from './porffor.d.ts';
2
3
 
3
4
  export const __String_fromCharCode = (code: i32) => {
4
5
  // todo: support >1 arg
@@ -0,0 +1,63 @@
1
+ import type {} from './porffor.d.ts';
2
+
3
+ export const __Porffor_symbol_descStore = (op: boolean, value: any): any => {
4
+ const ptr: bytestring = '';
5
+
6
+ if (op) { // write
7
+ const size: number = Porffor.wasm.i32.load(ptr, 0, 0);
8
+ Porffor.wasm.i32.store(ptr, size + 1, 0, 0)
9
+
10
+ // reuse set internals to store description
11
+ __Porffor_set_write(ptr, size, value);
12
+ return size;
13
+ } else { // read
14
+ return __Porffor_set_read(ptr, value);
15
+ }
16
+ };
17
+
18
+ export const Symbol = (description: any): Symbol => {
19
+ // 1-based so always truthy as numeric value
20
+ return __Porffor_symbol_descStore(true, description) + 1;
21
+ };
22
+
23
+ // todo: this should be a getter somehow not a method
24
+ export const __Symbol_prototype_description$get = (_this: Symbol) => {
25
+ const description: bytestring = __Porffor_symbol_descStore(false,
26
+ Porffor.wasm`local.get ${_this}` - 1);
27
+ return description;
28
+ };
29
+
30
+ export const __Symbol_prototype_toString = (_this: Symbol) => {
31
+ let out: bytestring = '';
32
+
33
+ // Symbol(
34
+ Porffor.wasm.i32.store8(out, 83, 0, 4);
35
+ Porffor.wasm.i32.store8(out, 121, 0, 5);
36
+ Porffor.wasm.i32.store8(out, 109, 0, 6);
37
+ Porffor.wasm.i32.store8(out, 98, 0, 7);
38
+ Porffor.wasm.i32.store8(out, 111, 0, 8);
39
+ Porffor.wasm.i32.store8(out, 108, 0, 9);
40
+ Porffor.wasm.i32.store8(out, 40, 0, 10);
41
+
42
+ const description: bytestring = __Porffor_symbol_descStore(false,
43
+ Porffor.wasm`local.get ${_this}` - 1);
44
+
45
+ const descLen: i32 = description.length;
46
+ let outPtr: i32 = Porffor.wasm`local.get ${out}` + 7;
47
+ let descPtr: i32 = Porffor.wasm`local.get ${description}`;
48
+ const descPtrEnd: i32 = descPtr + descLen;
49
+ while (descPtr < descPtrEnd) {
50
+ Porffor.wasm.i32.store8(outPtr++, Porffor.wasm.i32.load8_u(descPtr++, 0, 4), 0, 4);
51
+ }
52
+
53
+ // )
54
+ Porffor.wasm.i32.store8(Porffor.wasm`local.get ${out}` + descLen, 41, 0, 11);
55
+
56
+ out.length = 8 + descLen;
57
+
58
+ return out;
59
+ };
60
+
61
+ export const __Symbol_prototype_valueOf = (_this: Symbol) => {
62
+ return _this;
63
+ };
@@ -198,7 +198,8 @@ export const BuiltinFuncs = function() {
198
198
  returns: [ valtypeBinary ],
199
199
  wasm: [
200
200
  [ Opcodes.local_get, 0 ]
201
- ]
201
+ ],
202
+ constr: true
202
203
  };
203
204
 
204
205
  // just return given (default 0) for (new) Object() as we somewhat supports object just not constructor
@@ -210,7 +211,8 @@ export const BuiltinFuncs = function() {
210
211
  wasm: [
211
212
  // [ Opcodes.local_get, 0 ]
212
213
  ...number(1)
213
- ]
214
+ ],
215
+ constr: true
214
216
  };
215
217
 
216
218
 
@@ -219,7 +221,7 @@ export const BuiltinFuncs = function() {
219
221
  typedParams: true,
220
222
  locals: [ Valtype.i32, Valtype.i32 ],
221
223
  returns: [],
222
- wasm: (scope, { typeSwitch }) => [
224
+ wasm: (scope, { typeSwitch, builtin }) => [
223
225
  ...typeSwitch(scope, [ [ Opcodes.local_get, 1 ] ], {
224
226
  [TYPES.number]: [
225
227
  [ Opcodes.local_get, 0 ],
@@ -315,7 +317,7 @@ export const BuiltinFuncs = function() {
315
317
 
316
318
  // make end pointer
317
319
  [ Opcodes.i32_load, Math.log2(ValtypeSize.i32) - 1, 0 ],
318
- ...number(ValtypeSize[valtype], Valtype.i32),
320
+ ...number(ValtypeSize[valtype] + 1, Valtype.i32),
319
321
  [ Opcodes.i32_mul ],
320
322
 
321
323
  [ Opcodes.local_get, 2 ],
@@ -324,14 +326,18 @@ export const BuiltinFuncs = function() {
324
326
 
325
327
  [ Opcodes.loop, Blocktype.void ],
326
328
 
327
- // print current char
329
+ // print current array element
328
330
  [ Opcodes.local_get, 2 ],
329
- [ Opcodes.load, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
330
- [ Opcodes.call, importedFuncs.print ],
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') ],
331
337
 
332
338
  // increment pointer by sizeof valtype
333
339
  [ Opcodes.local_get, 2 ],
334
- ...number(ValtypeSize[valtype], Valtype.i32),
340
+ ...number(ValtypeSize[valtype] + 1, Valtype.i32),
335
341
  [ Opcodes.i32_add ],
336
342
  [ Opcodes.local_tee, 2 ],
337
343