porffor 0.2.0-aea77ff → 0.2.0-af678f0

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.
@@ -170,25 +170,6 @@ export const BuiltinFuncs = function() {
170
170
  ]
171
171
  };
172
172
 
173
- // todo: return false for NaN
174
- this.Boolean = {
175
- params: [ valtypeBinary ],
176
- locals: [],
177
- returns: [ valtypeBinary ],
178
- returnType: 'boolean',
179
- wasm: [
180
- [ Opcodes.local_get, 0 ],
181
- ...(valtype === 'f64' ? [
182
- ...number(0),
183
- [ Opcodes.f64_ne ]
184
- ] : [
185
- ...Opcodes.eqz,
186
- [ Opcodes.i32_eqz ]
187
- ]),
188
- Opcodes.i32_from
189
- ]
190
- };
191
-
192
173
  // just return given (default 0) for (new) Object() as we somewhat supports object just not constructor
193
174
  this.Object = {
194
175
  params: [ valtypeBinary ],
@@ -699,6 +680,49 @@ export const BuiltinFuncs = function() {
699
680
  };
700
681
 
701
682
 
683
+ this.__Porffor_type = {
684
+ params: [ valtypeBinary, Valtype.i32 ],
685
+ typedParams: true,
686
+ locals: [ Valtype.i32, Valtype.i32 ],
687
+ returns: [ valtypeBinary ],
688
+ returnType: process.argv.includes('-bytestring') ? '_bytestring' : 'string',
689
+ wasm: (scope, { TYPE_NAMES, typeSwitch, makeString }) => {
690
+ const bc = {};
691
+ for (const x in TYPE_NAMES) {
692
+ bc[x] = makeString(scope, TYPE_NAMES[x], false, '#Porffor_type_result');
693
+ }
694
+
695
+ return typeSwitch(scope, [ [ Opcodes.local_get, 1 ] ], bc);
696
+ }
697
+ };
698
+
699
+ const localIsOneOf = (getter, arr, valtype = valtypeBinary) => {
700
+ const out = [];
701
+
702
+ for (let i = 0; i < arr.length; i++) {
703
+ out.push(...getter, ...number(arr[i], valtype), valtype === Valtype.f64 ? [ Opcodes.f64_eq ] : [ Opcodes.i32_eq ]);
704
+ if (i !== 0) out.push([ Opcodes.i32_or ]);
705
+ }
706
+
707
+ return out;
708
+ };
709
+
710
+ this.__Porffor_pointer = {
711
+ params: [ valtypeBinary, Valtype.i32 ],
712
+ typedParams: true,
713
+ locals: [ Valtype.i32, Valtype.i32 ],
714
+ returns: [ valtypeBinary ],
715
+ wasm: (scope, { TYPES }) => [
716
+ ...localIsOneOf([ [ Opcodes.local_get, 1 ] ], [ TYPES.string, TYPES._array, TYPES._bytestring ], Valtype.i32),
717
+ [ Opcodes.if, valtypeBinary ],
718
+ [ Opcodes.local_get, 0 ],
719
+ [ Opcodes.else ],
720
+ ...number(NaN),
721
+ [ Opcodes.end ]
722
+ ]
723
+ };
724
+
725
+
702
726
  this.__SIMD_i32x4_load = {
703
727
  params: [ Valtype.i32 ],
704
728
  locals: [],