From f5dbb48da8c2d8a18af594e56bc3735511dcec93 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sat, 21 Jan 2023 11:53:08 +0200 Subject: [PATCH 1/2] init --- std/assembly/index.d.ts | 8 ++++++-- std/portable/index.d.ts | 40 +++++++++++++++++++++++++++++++--------- std/portable/index.js | 36 +++++++++++++++++++++++++++--------- 3 files changed, 64 insertions(+), 20 deletions(-) diff --git a/std/assembly/index.d.ts b/std/assembly/index.d.ts index 2945fe460a..6820a57af4 100644 --- a/std/assembly/index.d.ts +++ b/std/assembly/index.d.ts @@ -304,6 +304,8 @@ declare namespace i8 { export const MIN_VALUE: i8; /** Largest representable value. */ export const MAX_VALUE: i8; + /** Converts a string to an i8 of this type. */ + export function parse(value: string, radix?: i32): i8; } /** Converts any other numeric value to a 16-bit signed integer. */ declare function i16(value: any): i16; @@ -312,6 +314,8 @@ declare namespace i16 { export const MIN_VALUE: i16; /** Largest representable value. */ export const MAX_VALUE: i16; + /** Converts a string to an i16 of this type. */ + export function parse(value: string, radix?: i32): i16; } /** Converts any other numeric value to a 32-bit signed integer. */ declare function i32(value: any): i32; @@ -666,7 +670,7 @@ declare namespace f32 { /** Difference between 1 and the smallest representable value greater than 1. */ export const EPSILON: f32; /** Converts a string to an f32 of this type. */ - export function parse(value: string, radix?: i32): f32; + export function parse(value: string): f32; /** Loads a 32-bit float from memory. */ export function load(ptr: usize, immOffset?: usize, immAlign?: usize): f32; /** Stores a 32-bit float to memory. */ @@ -726,7 +730,7 @@ declare namespace f64 { /** Difference between 1 and the smallest representable value greater than 1. */ export const EPSILON: f64; /** Converts a string to an f64 of this type. */ - export function parse(value: string, radix?: i32): f64; + export function parse(value: string): f64; /** Loads a 64-bit float from memory. */ export function load(ptr: usize, immOffset?: usize, immAlign?: usize): f64; /** Stores a 64-bit float to memory. */ diff --git a/std/portable/index.d.ts b/std/portable/index.d.ts index ca6701baa4..c2d1a04196 100644 --- a/std/portable/index.d.ts +++ b/std/portable/index.d.ts @@ -133,6 +133,8 @@ declare namespace i8 { export function parseFloat(string: string): i8; /** Converts A string to an integer. */ export function parseInt(string: string, radix?: i32): i8; + /** Converts a string to an i8. */ + export function parse(value: string, radix?: i32): i8; } /** Converts any other numeric value to a 16-bit signed integer. */ declare function i16(value: any): i16; @@ -143,8 +145,10 @@ declare namespace i16 { export const MAX_VALUE: i16; /** Converts a string to a floating-point number and cast to target integer after. */ export function parseFloat(string: string): i16; - /** Converts A string to an integer. */ + /** Converts a string to an integer. */ export function parseInt(string: string, radix?: i32): i16; + /** Converts a string to an i16. */ + export function parse(value: string, radix?: i32): i16; } /** Converts any other numeric value to a 32-bit signed integer. */ declare function i32(value: any): i32; @@ -155,8 +159,10 @@ declare namespace i32 { export const MAX_VALUE: i32; /** Converts a string to a floating-point number and cast to target integer after. */ export function parseFloat(string: string): i32; - /** Converts A string to an integer. */ + /** Converts a string to an integer. */ export function parseInt(string: string, radix?: i32): i32; + /** Converts a string to an i32. */ + export function parse(value: string, radix?: i32): i32; } /** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) signed integer. */ declare function isize(value: any): isize; @@ -167,8 +173,10 @@ declare namespace isize { export const MAX_VALUE: isize; /** Converts a string to a floating-point number and cast to target integer after. */ export function parseFloat(string: string): isize; - /** Converts A string to an integer. */ + /** Converts a string to an integer. */ export function parseInt(string: string, radix?: i32): isize; + /** Converts a string to an iszie. */ + export function parse(value: string, radix?: i32): isize; } /** Converts any other numeric value to an 8-bit unsigned integer. */ declare function u8(value: any): u8; @@ -179,8 +187,10 @@ declare namespace u8 { export const MAX_VALUE: u8; /** Converts a string to a floating-point number and cast to target integer after. */ export function parseFloat(string: string): u8; - /** Converts A string to an integer. */ + /** Converts a string to an integer. */ export function parseInt(string: string, radix?: i32): u8; + /** Converts a string to an u8. */ + export function parse(value: string, radix?: i32): u8; } /** Converts any other numeric value to a 16-bit unsigned integer. */ declare function u16(value: any): u16; @@ -191,8 +201,10 @@ declare namespace u16 { export const MAX_VALUE: u16; /** Converts a string to a floating-point number and cast to target integer after. */ export function parseFloat(string: string): u16; - /** Converts A string to an integer. */ + /** Converts a string to an integer. */ export function parseInt(string: string, radix?: i32): u16; + /** Converts a string to an u16. */ + export function parse(value: string, radix?: i32): u16; } /** Converts any other numeric value to a 32-bit unsigned integer. */ declare function u32(value: any): u32; @@ -203,8 +215,10 @@ declare namespace u32 { export const MAX_VALUE: u32; /** Converts a string to a floating-point number and cast to target integer after. */ export function parseFloat(string: string): u32; - /** Converts A string to an integer. */ + /** Converts a string to an integer. */ export function parseInt(string: string, radix?: i32): u32; + /** Converts a string to an u32. */ + export function parse(value: string, radix?: i32): u32; } /** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) unsigned integer. */ declare function usize(value: any): isize; @@ -215,8 +229,10 @@ declare namespace usize { export const MAX_VALUE: usize; /** Converts a string to a floating-point number and cast to target integer after. */ export function parseFloat(string: string): usize; - /** Converts A string to an integer. */ + /** Converts a string to an integer. */ export function parseInt(string: string, radix?: i32): usize; + /** Converts a string to an usize. */ + export function parse(value: string, radix?: i32): usize; } /** Converts any other numeric value to a 1-bit unsigned integer. */ declare function bool(value: any): bool; @@ -225,6 +241,8 @@ declare namespace bool { export const MIN_VALUE: bool; /** Largest representable value. */ export const MAX_VALUE: bool; + /** Converts a string to an bool. */ + export function parse(value: string): bool; } /** Converts any other numeric value to a 32-bit float. */ declare function f32(value: any): f32; @@ -258,8 +276,10 @@ declare namespace f32 { export function isInteger(value: f32): bool; /** Converts a string to a floating-point number. */ export function parseFloat(string: string): f32; - /** Converts A string to an integer. */ + /** Converts a string to an integer. */ export function parseInt(string: string, radix?: i32): f32; + /** Converts a string to an f32. */ + export function parse(value: string): f32; } /** Converts any other numeric value to a 64-bit float. */ declare function f64(value: any): f64; @@ -293,8 +313,10 @@ declare namespace f64 { export function isInteger(value: f64): bool; /** Converts a string to a floating-point number. */ export function parseFloat(string: string): f64; - /** Converts A string to an integer. */ + /** Converts a string to an integer. */ export function parseInt(string: string, radix?: i32): f64; + /** Converts a string to an f64. */ + export function parse(value: string): f64; } // Standard library diff --git a/std/portable/index.js b/std/portable/index.js index 24cff8382e..d35ce63ee2 100644 --- a/std/portable/index.js +++ b/std/portable/index.js @@ -22,7 +22,9 @@ if (typeof globalScope.ASC_TARGET === "undefined") { globalScope["i8"] = function i8(value) { return value << 24 >> 24; }, { "MIN_VALUE": { value: -128 }, - "MAX_VALUE": { value: 127 } + "MAX_VALUE": { value: 127 }, + + parse(str, radix) { return parseInt(str, radix) << 24 >> 24; } } ); @@ -30,7 +32,9 @@ if (typeof globalScope.ASC_TARGET === "undefined") { globalScope["i16"] = function i16(value) { return value << 16 >> 16; }, { "MIN_VALUE": { value: -32768 }, - "MAX_VALUE": { value: 32767 } + "MAX_VALUE": { value: 32767 }, + + parse(str, radix) { return parseInt(str, radix) << 16 >> 16; } } ); @@ -38,7 +42,9 @@ if (typeof globalScope.ASC_TARGET === "undefined") { globalScope["i32"] = globalScope["isize"] = function i32(value) { return value | 0; }, { "MIN_VALUE": { value: -2147483648 }, - "MAX_VALUE": { value: 2147483647 } + "MAX_VALUE": { value: 2147483647 }, + + parse(str, radix) { return parseInt(str, radix) | 0; } } ); @@ -46,7 +52,9 @@ if (typeof globalScope.ASC_TARGET === "undefined") { globalScope["u8"] = function u8(value) { return value & 0xff; }, { "MIN_VALUE": { value: 0 }, - "MAX_VALUE": { value: 255 } + "MAX_VALUE": { value: 255 }, + + parse(str, radix) { return parseInt(str, radix) & 0xff; } } ); @@ -54,7 +62,9 @@ if (typeof globalScope.ASC_TARGET === "undefined") { globalScope["u16"] = function u16(value) { return value & 0xffff; }, { "MIN_VALUE": { value: 0 }, - "MAX_VALUE": { value: 65535 } + "MAX_VALUE": { value: 65535 }, + + parse(str, radix) { return parseInt(str, radix) & 0xffff; } } ); @@ -62,7 +72,9 @@ if (typeof globalScope.ASC_TARGET === "undefined") { globalScope["u32"] = globalScope["usize"] = function u32(value) { return value >>> 0; }, { "MIN_VALUE": { value: 0 }, - "MAX_VALUE": { value: 4294967295 } + "MAX_VALUE": { value: 4294967295 }, + + parse(str, radix) { return parseInt(str, radix) >>> 0; } } ); @@ -70,7 +82,9 @@ if (typeof globalScope.ASC_TARGET === "undefined") { globalScope["bool"] = function bool(value) { return !!value; }, { "MIN_VALUE": { value: false }, - "MAX_VALUE": { value: true } + "MAX_VALUE": { value: true }, + + parse(str) { return str.trim() === "true"; } } ); @@ -85,7 +99,9 @@ if (typeof globalScope.ASC_TARGET === "undefined") { "MAX_SAFE_INTEGER": { value: 16777215 }, "POSITIVE_INFINITY": { value: Infinity }, "NEGATIVE_INFINITY": { value: -Infinity }, - "NaN": { value: NaN } + "NaN": { value: NaN }, + + parse(str) { return Math.fround(parseFloat(str)); } } ); @@ -100,7 +116,9 @@ if (typeof globalScope.ASC_TARGET === "undefined") { "MAX_SAFE_INTEGER": { value: 9007199254740991 }, "POSITIVE_INFINITY": { value: Infinity }, "NEGATIVE_INFINITY": { value: -Infinity }, - "NaN": { value: NaN } + "NaN": { value: NaN }, + + parse(str) { return parseFloat(str); } } ); From f05928fd8bffe6fed2f33e27ea62ac6380d39cf9 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 22 Jan 2023 16:22:08 +0200 Subject: [PATCH 2/2] update descriptions --- std/assembly/index.d.ts | 22 ++++++++++----------- std/portable/index.d.ts | 42 ++++++++++++++++++++--------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/std/assembly/index.d.ts b/std/assembly/index.d.ts index 6820a57af4..d2e0c280b4 100644 --- a/std/assembly/index.d.ts +++ b/std/assembly/index.d.ts @@ -304,7 +304,7 @@ declare namespace i8 { export const MIN_VALUE: i8; /** Largest representable value. */ export const MAX_VALUE: i8; - /** Converts a string to an i8 of this type. */ + /** Parses a string as an i8. */ export function parse(value: string, radix?: i32): i8; } /** Converts any other numeric value to a 16-bit signed integer. */ @@ -314,7 +314,7 @@ declare namespace i16 { export const MIN_VALUE: i16; /** Largest representable value. */ export const MAX_VALUE: i16; - /** Converts a string to an i16 of this type. */ + /** Parses a string as an i16. */ export function parse(value: string, radix?: i32): i16; } /** Converts any other numeric value to a 32-bit signed integer. */ @@ -324,7 +324,7 @@ declare namespace i32 { export const MIN_VALUE: i32; /** Largest representable value. */ export const MAX_VALUE: i32; - /** Converts a string to an i32 of this type. */ + /** Parses a string as an i32. */ export function parse(value: string, radix?: i32): i32; /** Loads an 8-bit signed integer value from memory and returns it as a 32-bit integer. */ export function load8_s(ptr: usize, immOffset?: usize, immAlign?: usize): i32; @@ -449,7 +449,7 @@ declare namespace i64 { export const MIN_VALUE: i64; /** Largest representable value. */ export const MAX_VALUE: i64; - /** Converts a string to an i64 of this type. */ + /** Parses a string as an i64. */ export function parse(value: string, radix?: i32): i64; /** Loads an 8-bit signed integer value from memory and returns it as a 64-bit integer. */ export function load8_s(ptr: usize, immOffset?: usize, immAlign?: usize): i64; @@ -603,7 +603,7 @@ declare namespace u8 { export const MIN_VALUE: u8; /** Largest representable value. */ export const MAX_VALUE: u8; - /** Converts a string to an u8 of this type. */ + /** Parses a string as an u8. */ export function parse(value: string, radix?: i32): u8; } /** Converts any other numeric value to a 16-bit unsigned integer. */ @@ -613,7 +613,7 @@ declare namespace u16 { export const MIN_VALUE: u16; /** Largest representable value. */ export const MAX_VALUE: u16; - /** Converts a string to an u16 of this type. */ + /** Parses a string as an u16. */ export function parse(value: string, radix?: i32): u16; } /** Converts any other numeric value to a 32-bit unsigned integer. */ @@ -623,7 +623,7 @@ declare namespace u32 { export const MIN_VALUE: u32; /** Largest representable value. */ export const MAX_VALUE: u32; - /** Converts a string to an u32 of this type. */ + /** Parses a string as an u32. */ export function parse(value: string, radix?: i32): u32; } /** Converts any other numeric value to a 64-bit unsigned integer. */ @@ -633,7 +633,7 @@ declare namespace u64 { export const MIN_VALUE: u64; /** Largest representable value. */ export const MAX_VALUE: u64; - /** Converts a string to an u64 of this type. */ + /** Parses a string as an u64. */ export function parse(value: string, radix?: i32): u64; } /** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) unsigned integer. */ @@ -645,7 +645,7 @@ declare namespace bool { export const MIN_VALUE: bool; /** Largest representable value. */ export const MAX_VALUE: bool; - /** Converts a string to an bool of this type. */ + /** Parses a string as a bool. */ export function parse(value: string): bool; } /** Converts any other numeric value to a 32-bit float. */ @@ -669,7 +669,7 @@ declare namespace f32 { export const NaN: f32; /** Difference between 1 and the smallest representable value greater than 1. */ export const EPSILON: f32; - /** Converts a string to an f32 of this type. */ + /** Parses a string as an f32. */ export function parse(value: string): f32; /** Loads a 32-bit float from memory. */ export function load(ptr: usize, immOffset?: usize, immAlign?: usize): f32; @@ -729,7 +729,7 @@ declare namespace f64 { export const NaN: f64; /** Difference between 1 and the smallest representable value greater than 1. */ export const EPSILON: f64; - /** Converts a string to an f64 of this type. */ + /** Parses a string as an f64. */ export function parse(value: string): f64; /** Loads a 64-bit float from memory. */ export function load(ptr: usize, immOffset?: usize, immAlign?: usize): f64; diff --git a/std/portable/index.d.ts b/std/portable/index.d.ts index c2d1a04196..98556ee41b 100644 --- a/std/portable/index.d.ts +++ b/std/portable/index.d.ts @@ -131,9 +131,9 @@ declare namespace i8 { export const MAX_VALUE: i8; /** Converts a string to a floating-point number and cast to target integer after. */ export function parseFloat(string: string): i8; - /** Converts A string to an integer. */ + /** Parses a string as an integer. */ export function parseInt(string: string, radix?: i32): i8; - /** Converts a string to an i8. */ + /** Parses a string as an i8. */ export function parse(value: string, radix?: i32): i8; } /** Converts any other numeric value to a 16-bit signed integer. */ @@ -145,9 +145,9 @@ declare namespace i16 { export const MAX_VALUE: i16; /** Converts a string to a floating-point number and cast to target integer after. */ export function parseFloat(string: string): i16; - /** Converts a string to an integer. */ + /** Parses a string as an integer. */ export function parseInt(string: string, radix?: i32): i16; - /** Converts a string to an i16. */ + /** Parses a string as an i16. */ export function parse(value: string, radix?: i32): i16; } /** Converts any other numeric value to a 32-bit signed integer. */ @@ -159,9 +159,9 @@ declare namespace i32 { export const MAX_VALUE: i32; /** Converts a string to a floating-point number and cast to target integer after. */ export function parseFloat(string: string): i32; - /** Converts a string to an integer. */ + /** Parses a string as an integer. */ export function parseInt(string: string, radix?: i32): i32; - /** Converts a string to an i32. */ + /** Parses a string as an i32. */ export function parse(value: string, radix?: i32): i32; } /** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) signed integer. */ @@ -173,9 +173,9 @@ declare namespace isize { export const MAX_VALUE: isize; /** Converts a string to a floating-point number and cast to target integer after. */ export function parseFloat(string: string): isize; - /** Converts a string to an integer. */ + /** Parses a string as an integer. */ export function parseInt(string: string, radix?: i32): isize; - /** Converts a string to an iszie. */ + /** Parses a string as an iszie. */ export function parse(value: string, radix?: i32): isize; } /** Converts any other numeric value to an 8-bit unsigned integer. */ @@ -187,9 +187,9 @@ declare namespace u8 { export const MAX_VALUE: u8; /** Converts a string to a floating-point number and cast to target integer after. */ export function parseFloat(string: string): u8; - /** Converts a string to an integer. */ + /** Parses a string as an integer. */ export function parseInt(string: string, radix?: i32): u8; - /** Converts a string to an u8. */ + /** Parses a string as an u8. */ export function parse(value: string, radix?: i32): u8; } /** Converts any other numeric value to a 16-bit unsigned integer. */ @@ -201,9 +201,9 @@ declare namespace u16 { export const MAX_VALUE: u16; /** Converts a string to a floating-point number and cast to target integer after. */ export function parseFloat(string: string): u16; - /** Converts a string to an integer. */ + /** Parses a string as an integer. */ export function parseInt(string: string, radix?: i32): u16; - /** Converts a string to an u16. */ + /** Parses a string as an u16. */ export function parse(value: string, radix?: i32): u16; } /** Converts any other numeric value to a 32-bit unsigned integer. */ @@ -215,9 +215,9 @@ declare namespace u32 { export const MAX_VALUE: u32; /** Converts a string to a floating-point number and cast to target integer after. */ export function parseFloat(string: string): u32; - /** Converts a string to an integer. */ + /** Parses a string as an integer. */ export function parseInt(string: string, radix?: i32): u32; - /** Converts a string to an u32. */ + /** Parses a string as an u32. */ export function parse(value: string, radix?: i32): u32; } /** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) unsigned integer. */ @@ -229,9 +229,9 @@ declare namespace usize { export const MAX_VALUE: usize; /** Converts a string to a floating-point number and cast to target integer after. */ export function parseFloat(string: string): usize; - /** Converts a string to an integer. */ + /** Parses a string as an integer. */ export function parseInt(string: string, radix?: i32): usize; - /** Converts a string to an usize. */ + /** Parses a string as an usize. */ export function parse(value: string, radix?: i32): usize; } /** Converts any other numeric value to a 1-bit unsigned integer. */ @@ -241,7 +241,7 @@ declare namespace bool { export const MIN_VALUE: bool; /** Largest representable value. */ export const MAX_VALUE: bool; - /** Converts a string to an bool. */ + /** Parses a string as a bool. */ export function parse(value: string): bool; } /** Converts any other numeric value to a 32-bit float. */ @@ -276,9 +276,9 @@ declare namespace f32 { export function isInteger(value: f32): bool; /** Converts a string to a floating-point number. */ export function parseFloat(string: string): f32; - /** Converts a string to an integer. */ + /** Parses a string as an integer and convert to an f32. */ export function parseInt(string: string, radix?: i32): f32; - /** Converts a string to an f32. */ + /** Parses a string as an f32. */ export function parse(value: string): f32; } /** Converts any other numeric value to a 64-bit float. */ @@ -313,9 +313,9 @@ declare namespace f64 { export function isInteger(value: f64): bool; /** Converts a string to a floating-point number. */ export function parseFloat(string: string): f64; - /** Converts a string to an integer. */ + /** Parses a string as an integer and convert to an f64. */ export function parseInt(string: string, radix?: i32): f64; - /** Converts a string to an f64. */ + /** Parses a string as an f64. */ export function parse(value: string): f64; }