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.
@@ -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
@@ -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;
@@ -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 char
329
+ // print current array element
330
330
  [ Opcodes.local_get, 2 ],
331
- [ Opcodes.load, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
332
- [ 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') ],
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