diff --git a/bin/asc b/bin/asc old mode 100644 new mode 100755 diff --git a/package-lock.json b/package-lock.json index ee51b985c7..53330072f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -433,6 +433,7 @@ "requires": { "anymatch": "1.3.2", "async-each": "1.0.1", + "fsevents": "1.1.3", "glob-parent": "2.0.0", "inherits": "2.0.3", "is-binary-path": "1.0.1", @@ -936,6 +937,910 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, + "fsevents": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.1.3.tgz", + "integrity": "sha512-WIr7iDkdmdbxu/Gh6eKEZJL6KPE74/5MEsf2whTOFNxbIoIixogroLdKYqB6FDav4Wavh/lZdzzd3b2KxIXC5Q==", + "dev": true, + "optional": true, + "requires": { + "nan": "2.8.0", + "node-pre-gyp": "0.6.39" + }, + "dependencies": { + "abbrev": { + "version": "1.1.0", + "bundled": true, + "dev": true, + "optional": true + }, + "ajv": { + "version": "4.11.8", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "co": "4.6.0", + "json-stable-stringify": "1.0.1" + } + }, + "ansi-regex": { + "version": "2.1.1", + "bundled": true, + "dev": true + }, + "aproba": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "are-we-there-yet": { + "version": "1.1.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "delegates": "1.0.0", + "readable-stream": "2.2.9" + } + }, + "asn1": { + "version": "0.2.3", + "bundled": true, + "dev": true, + "optional": true + }, + "assert-plus": { + "version": "0.2.0", + "bundled": true, + "dev": true, + "optional": true + }, + "asynckit": { + "version": "0.4.0", + "bundled": true, + "dev": true, + "optional": true + }, + "aws-sign2": { + "version": "0.6.0", + "bundled": true, + "dev": true, + "optional": true + }, + "aws4": { + "version": "1.6.0", + "bundled": true, + "dev": true, + "optional": true + }, + "balanced-match": { + "version": "0.4.2", + "bundled": true, + "dev": true + }, + "bcrypt-pbkdf": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "tweetnacl": "0.14.5" + } + }, + "block-stream": { + "version": "0.0.9", + "bundled": true, + "dev": true, + "requires": { + "inherits": "2.0.3" + } + }, + "boom": { + "version": "2.10.1", + "bundled": true, + "dev": true, + "requires": { + "hoek": "2.16.3" + } + }, + "brace-expansion": { + "version": "1.1.7", + "bundled": true, + "dev": true, + "requires": { + "balanced-match": "0.4.2", + "concat-map": "0.0.1" + } + }, + "buffer-shims": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "caseless": { + "version": "0.12.0", + "bundled": true, + "dev": true, + "optional": true + }, + "co": { + "version": "4.6.0", + "bundled": true, + "dev": true, + "optional": true + }, + "code-point-at": { + "version": "1.1.0", + "bundled": true, + "dev": true + }, + "combined-stream": { + "version": "1.0.5", + "bundled": true, + "dev": true, + "requires": { + "delayed-stream": "1.0.0" + } + }, + "concat-map": { + "version": "0.0.1", + "bundled": true, + "dev": true + }, + "console-control-strings": { + "version": "1.1.0", + "bundled": true, + "dev": true + }, + "core-util-is": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "cryptiles": { + "version": "2.0.5", + "bundled": true, + "dev": true, + "requires": { + "boom": "2.10.1" + } + }, + "dashdash": { + "version": "1.14.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "assert-plus": "1.0.0" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "debug": { + "version": "2.6.8", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "ms": "2.0.0" + } + }, + "deep-extend": { + "version": "0.4.2", + "bundled": true, + "dev": true, + "optional": true + }, + "delayed-stream": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "delegates": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "detect-libc": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "ecc-jsbn": { + "version": "0.1.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "jsbn": "0.1.1" + } + }, + "extend": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "extsprintf": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "forever-agent": { + "version": "0.6.1", + "bundled": true, + "dev": true, + "optional": true + }, + "form-data": { + "version": "2.1.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "asynckit": "0.4.0", + "combined-stream": "1.0.5", + "mime-types": "2.1.15" + } + }, + "fs.realpath": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "fstream": { + "version": "1.0.11", + "bundled": true, + "dev": true, + "requires": { + "graceful-fs": "4.1.11", + "inherits": "2.0.3", + "mkdirp": "0.5.1", + "rimraf": "2.6.1" + } + }, + "fstream-ignore": { + "version": "1.0.5", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "fstream": "1.0.11", + "inherits": "2.0.3", + "minimatch": "3.0.4" + } + }, + "gauge": { + "version": "2.7.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "aproba": "1.1.1", + "console-control-strings": "1.1.0", + "has-unicode": "2.0.1", + "object-assign": "4.1.1", + "signal-exit": "3.0.2", + "string-width": "1.0.2", + "strip-ansi": "3.0.1", + "wide-align": "1.1.2" + } + }, + "getpass": { + "version": "0.1.7", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "assert-plus": "1.0.0" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "glob": { + "version": "7.1.2", + "bundled": true, + "dev": true, + "requires": { + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "graceful-fs": { + "version": "4.1.11", + "bundled": true, + "dev": true + }, + "har-schema": { + "version": "1.0.5", + "bundled": true, + "dev": true, + "optional": true + }, + "har-validator": { + "version": "4.2.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "ajv": "4.11.8", + "har-schema": "1.0.5" + } + }, + "has-unicode": { + "version": "2.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "hawk": { + "version": "3.1.3", + "bundled": true, + "dev": true, + "requires": { + "boom": "2.10.1", + "cryptiles": "2.0.5", + "hoek": "2.16.3", + "sntp": "1.0.9" + } + }, + "hoek": { + "version": "2.16.3", + "bundled": true, + "dev": true + }, + "http-signature": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "assert-plus": "0.2.0", + "jsprim": "1.4.0", + "sshpk": "1.13.0" + } + }, + "inflight": { + "version": "1.0.6", + "bundled": true, + "dev": true, + "requires": { + "once": "1.4.0", + "wrappy": "1.0.2" + } + }, + "inherits": { + "version": "2.0.3", + "bundled": true, + "dev": true + }, + "ini": { + "version": "1.3.4", + "bundled": true, + "dev": true, + "optional": true + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "requires": { + "number-is-nan": "1.0.1" + } + }, + "is-typedarray": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "isarray": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "isstream": { + "version": "0.1.2", + "bundled": true, + "dev": true, + "optional": true + }, + "jodid25519": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "jsbn": "0.1.1" + } + }, + "jsbn": { + "version": "0.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "json-schema": { + "version": "0.2.3", + "bundled": true, + "dev": true, + "optional": true + }, + "json-stable-stringify": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "jsonify": "0.0.0" + } + }, + "json-stringify-safe": { + "version": "5.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "jsonify": { + "version": "0.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "jsprim": { + "version": "1.4.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "assert-plus": "1.0.0", + "extsprintf": "1.0.2", + "json-schema": "0.2.3", + "verror": "1.3.6" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "mime-db": { + "version": "1.27.0", + "bundled": true, + "dev": true + }, + "mime-types": { + "version": "2.1.15", + "bundled": true, + "dev": true, + "requires": { + "mime-db": "1.27.0" + } + }, + "minimatch": { + "version": "3.0.4", + "bundled": true, + "dev": true, + "requires": { + "brace-expansion": "1.1.7" + } + }, + "minimist": { + "version": "0.0.8", + "bundled": true, + "dev": true + }, + "mkdirp": { + "version": "0.5.1", + "bundled": true, + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, + "ms": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "node-pre-gyp": { + "version": "0.6.39", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "detect-libc": "1.0.2", + "hawk": "3.1.3", + "mkdirp": "0.5.1", + "nopt": "4.0.1", + "npmlog": "4.1.0", + "rc": "1.2.1", + "request": "2.81.0", + "rimraf": "2.6.1", + "semver": "5.3.0", + "tar": "2.2.1", + "tar-pack": "3.4.0" + } + }, + "nopt": { + "version": "4.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "abbrev": "1.1.0", + "osenv": "0.1.4" + } + }, + "npmlog": { + "version": "4.1.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "are-we-there-yet": "1.1.4", + "console-control-strings": "1.1.0", + "gauge": "2.7.4", + "set-blocking": "2.0.0" + } + }, + "number-is-nan": { + "version": "1.0.1", + "bundled": true, + "dev": true + }, + "oauth-sign": { + "version": "0.8.2", + "bundled": true, + "dev": true, + "optional": true + }, + "object-assign": { + "version": "4.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "once": { + "version": "1.4.0", + "bundled": true, + "dev": true, + "requires": { + "wrappy": "1.0.2" + } + }, + "os-homedir": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "os-tmpdir": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "osenv": { + "version": "0.1.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "os-homedir": "1.0.2", + "os-tmpdir": "1.0.2" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "bundled": true, + "dev": true + }, + "performance-now": { + "version": "0.2.0", + "bundled": true, + "dev": true, + "optional": true + }, + "process-nextick-args": { + "version": "1.0.7", + "bundled": true, + "dev": true + }, + "punycode": { + "version": "1.4.1", + "bundled": true, + "dev": true, + "optional": true + }, + "qs": { + "version": "6.4.0", + "bundled": true, + "dev": true, + "optional": true + }, + "rc": { + "version": "1.2.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "deep-extend": "0.4.2", + "ini": "1.3.4", + "minimist": "1.2.0", + "strip-json-comments": "2.0.1" + }, + "dependencies": { + "minimist": { + "version": "1.2.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "readable-stream": { + "version": "2.2.9", + "bundled": true, + "dev": true, + "requires": { + "buffer-shims": "1.0.0", + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "1.0.0", + "process-nextick-args": "1.0.7", + "string_decoder": "1.0.1", + "util-deprecate": "1.0.2" + } + }, + "request": { + "version": "2.81.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "aws-sign2": "0.6.0", + "aws4": "1.6.0", + "caseless": "0.12.0", + "combined-stream": "1.0.5", + "extend": "3.0.1", + "forever-agent": "0.6.1", + "form-data": "2.1.4", + "har-validator": "4.2.1", + "hawk": "3.1.3", + "http-signature": "1.1.1", + "is-typedarray": "1.0.0", + "isstream": "0.1.2", + "json-stringify-safe": "5.0.1", + "mime-types": "2.1.15", + "oauth-sign": "0.8.2", + "performance-now": "0.2.0", + "qs": "6.4.0", + "safe-buffer": "5.0.1", + "stringstream": "0.0.5", + "tough-cookie": "2.3.2", + "tunnel-agent": "0.6.0", + "uuid": "3.0.1" + } + }, + "rimraf": { + "version": "2.6.1", + "bundled": true, + "dev": true, + "requires": { + "glob": "7.1.2" + } + }, + "safe-buffer": { + "version": "5.0.1", + "bundled": true, + "dev": true + }, + "semver": { + "version": "5.3.0", + "bundled": true, + "dev": true, + "optional": true + }, + "set-blocking": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "signal-exit": { + "version": "3.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "sntp": { + "version": "1.0.9", + "bundled": true, + "dev": true, + "requires": { + "hoek": "2.16.3" + } + }, + "sshpk": { + "version": "1.13.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "asn1": "0.2.3", + "assert-plus": "1.0.0", + "bcrypt-pbkdf": "1.0.1", + "dashdash": "1.14.1", + "ecc-jsbn": "0.1.1", + "getpass": "0.1.7", + "jodid25519": "1.0.2", + "jsbn": "0.1.1", + "tweetnacl": "0.14.5" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "string-width": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "requires": { + "code-point-at": "1.1.0", + "is-fullwidth-code-point": "1.0.0", + "strip-ansi": "3.0.1" + } + }, + "string_decoder": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "5.0.1" + } + }, + "stringstream": { + "version": "0.0.5", + "bundled": true, + "dev": true, + "optional": true + }, + "strip-ansi": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "requires": { + "ansi-regex": "2.1.1" + } + }, + "strip-json-comments": { + "version": "2.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "tar": { + "version": "2.2.1", + "bundled": true, + "dev": true, + "requires": { + "block-stream": "0.0.9", + "fstream": "1.0.11", + "inherits": "2.0.3" + } + }, + "tar-pack": { + "version": "3.4.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "debug": "2.6.8", + "fstream": "1.0.11", + "fstream-ignore": "1.0.5", + "once": "1.4.0", + "readable-stream": "2.2.9", + "rimraf": "2.6.1", + "tar": "2.2.1", + "uid-number": "0.0.6" + } + }, + "tough-cookie": { + "version": "2.3.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "punycode": "1.4.1" + } + }, + "tunnel-agent": { + "version": "0.6.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "safe-buffer": "5.0.1" + } + }, + "tweetnacl": { + "version": "0.14.5", + "bundled": true, + "dev": true, + "optional": true + }, + "uid-number": { + "version": "0.0.6", + "bundled": true, + "dev": true, + "optional": true + }, + "util-deprecate": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "uuid": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "verror": { + "version": "1.3.6", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "extsprintf": "1.0.2" + } + }, + "wide-align": { + "version": "1.1.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "string-width": "1.0.2" + } + }, + "wrappy": { + "version": "1.0.2", + "bundled": true, + "dev": true + } + } + }, "get-caller-file": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.2.tgz", @@ -1464,6 +2369,13 @@ } } }, + "nan": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.8.0.tgz", + "integrity": "sha1-7XFfP+neArV6XmJS2QqWZ14fCFo=", + "dev": true, + "optional": true + }, "node-libs-browser": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/node-libs-browser/-/node-libs-browser-2.1.0.tgz", diff --git a/std/assembly/string.ts b/std/assembly/string.ts index 6d06e4807b..1d17cd5b4f 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -1,6 +1,17 @@ // singleton empty string const EMPTY: String = changetype(""); +const cp: u16 = 43; // "+" +const cn: u16 = 45; // "-" +const cx: u16 = 120; // "x" +const cX: u16 = 88; // "X" +const c0: u16 = 48; // "0" +const c9: u16 = 57; // "9" +const ca: u16 = 97; // "a" +const cz: u16 = 122; // "z" +const cA: u16 = 65; // "A" +const cZ: u16 = 90; // "Z" + // number of bytes preceeding string data const HEAD: usize = 4; @@ -323,8 +334,71 @@ function isWhiteSpaceOrLineTerminator(c: u16): bool { } // @binding(CALL, [ STRING, PASS_THRU ], PASS_THRU) -export function parseInt(str: string, radix: i32 = 10): f64 { - throw new Error("not implemented"); +export function parseInt(str: String, radix: i32 = 0): f64 { + var len = str.length; + if (len == 0 || (radix != 0 && radix < 2) || radix > 36) + return NaN; + + var s0 = str.charCodeAt(0); + var pos: i32 = 0; + var neg = (s0 == cn); + + if (s0 == cp || neg) { + if (len == 1) + return NaN; + + pos = 1; + } + + if (radix == 0) { + if (str.charCodeAt(pos) == c0) { + var s1 = str.charCodeAt(pos + 1); + if (len > 1 && (s1 == cx || s1 == cX)) { + if (len < pos + 3) + return NaN; + + radix = 16; + pos += 2; + + } else { + // radix = 8; + // pos += 1; + radix = 10; + } + } else { + radix = 10; + } + } + + var valid = false; + var result: f64 = 0; + + for (; pos < len; ++pos) { + var digit: i32, c = str.charCodeAt(pos); + + if (c0 <= c && c <= c9) digit = c - c0; + else if (ca <= c && c <= cz) digit = c - ca + 10; + else if (cA <= c && c <= cZ) digit = c - cA + 10; + else { + if (valid) break; + return NaN; + } + + if (digit >= radix) { + if (valid) break; + return NaN; + } + + valid = true; + + result *= radix; + result += digit; + } + + if (!valid && len > 2) + return NaN; + + return neg ? -result : result; } // @binding(CALL, [ STRING ], PASS_THRU) diff --git a/tests/compiler/std/array.wast b/tests/compiler/std/array.wast index 8b11e5ed9b..4340267153 100644 --- a/tests/compiler/std/array.wast +++ b/tests/compiler/std/array.wast @@ -4065,6 +4065,16 @@ PROPERTY: std:set/Set#size CLASS_PROTOTYPE: Set GLOBAL: std:string/EMPTY + GLOBAL: std:string/cp + GLOBAL: std:string/cn + GLOBAL: std:string/cx + GLOBAL: std:string/cX + GLOBAL: std:string/c0 + GLOBAL: std:string/c9 + GLOBAL: std:string/ca + GLOBAL: std:string/cz + GLOBAL: std:string/cA + GLOBAL: std:string/cZ GLOBAL: std:string/HEAD FUNCTION_PROTOTYPE: std:string/allocate CLASS_PROTOTYPE: std:string/String diff --git a/tests/compiler/std/carray.wast b/tests/compiler/std/carray.wast index c58f2cdd5c..d1d5c4fb88 100644 --- a/tests/compiler/std/carray.wast +++ b/tests/compiler/std/carray.wast @@ -273,6 +273,16 @@ PROPERTY: std:set/Set#size CLASS_PROTOTYPE: Set GLOBAL: std:string/EMPTY + GLOBAL: std:string/cp + GLOBAL: std:string/cn + GLOBAL: std:string/cx + GLOBAL: std:string/cX + GLOBAL: std:string/c0 + GLOBAL: std:string/c9 + GLOBAL: std:string/ca + GLOBAL: std:string/cz + GLOBAL: std:string/cA + GLOBAL: std:string/cZ GLOBAL: std:string/HEAD FUNCTION_PROTOTYPE: std:string/allocate CLASS_PROTOTYPE: std:string/String diff --git a/tests/compiler/std/heap.wast b/tests/compiler/std/heap.wast index c8f9da39d2..f46eee47fe 100644 --- a/tests/compiler/std/heap.wast +++ b/tests/compiler/std/heap.wast @@ -2861,6 +2861,16 @@ PROPERTY: std:set/Set#size CLASS_PROTOTYPE: Set GLOBAL: std:string/EMPTY + GLOBAL: std:string/cp + GLOBAL: std:string/cn + GLOBAL: std:string/cx + GLOBAL: std:string/cX + GLOBAL: std:string/c0 + GLOBAL: std:string/c9 + GLOBAL: std:string/ca + GLOBAL: std:string/cz + GLOBAL: std:string/cA + GLOBAL: std:string/cZ GLOBAL: std:string/HEAD FUNCTION_PROTOTYPE: std:string/allocate CLASS_PROTOTYPE: std:string/String diff --git a/tests/compiler/std/new.wast b/tests/compiler/std/new.wast index 77f99f1134..6c27cf98d5 100644 --- a/tests/compiler/std/new.wast +++ b/tests/compiler/std/new.wast @@ -578,6 +578,16 @@ PROPERTY: std:set/Set#size CLASS_PROTOTYPE: Set GLOBAL: std:string/EMPTY + GLOBAL: std:string/cp + GLOBAL: std:string/cn + GLOBAL: std:string/cx + GLOBAL: std:string/cX + GLOBAL: std:string/c0 + GLOBAL: std:string/c9 + GLOBAL: std:string/ca + GLOBAL: std:string/cz + GLOBAL: std:string/cA + GLOBAL: std:string/cZ GLOBAL: std:string/HEAD FUNCTION_PROTOTYPE: std:string/allocate CLASS_PROTOTYPE: std:string/String diff --git a/tests/compiler/std/set.wast b/tests/compiler/std/set.wast index f81d864dc3..5a524a5a65 100644 --- a/tests/compiler/std/set.wast +++ b/tests/compiler/std/set.wast @@ -3145,6 +3145,16 @@ PROPERTY: std:set/Set#size CLASS_PROTOTYPE: Set GLOBAL: std:string/EMPTY + GLOBAL: std:string/cp + GLOBAL: std:string/cn + GLOBAL: std:string/cx + GLOBAL: std:string/cX + GLOBAL: std:string/c0 + GLOBAL: std:string/c9 + GLOBAL: std:string/ca + GLOBAL: std:string/cz + GLOBAL: std:string/cA + GLOBAL: std:string/cZ GLOBAL: std:string/HEAD FUNCTION_PROTOTYPE: std:string/allocate CLASS_PROTOTYPE: std:string/String diff --git a/tests/compiler/std/string.optimized.wast b/tests/compiler/std/string.optimized.wast index b0eebc05fb..b8bfc2ef9e 100644 --- a/tests/compiler/std/string.optimized.wast +++ b/tests/compiler/std/string.optimized.wast @@ -2,16 +2,37 @@ (type $i (func (result i32))) (type $iii (func (param i32 i32) (result i32))) (type $iiii (func (param i32 i32 i32) (result i32))) + (type $iiF (func (param i32 i32) (result f64))) (type $v (func)) (global $std/string/str (mut i32) (i32.const 8)) + (global $std/string/str123 (mut i32) (i32.const 48)) + (global $std/string/str123ab (mut i32) (i32.const 64)) + (global $std/string/strab123 (mut i32) (i32.const 80)) + (global $std/string/strHex (mut i32) (i32.const 96)) + (global $std/string/strHexInvalid (mut i32) (i32.const 112)) + (global $std/string/strHexnInvalid (mut i32) (i32.const 120)) + (global $std/string/strHexnnInv (mut i32) (i32.const 136)) + (global $std/string/str123n (mut i32) (i32.const 152)) + (global $std/string/strHexn (mut i32) (i32.const 168)) + (global $std/string/strHexp (mut i32) (i32.const 184)) (memory $0 1) (data (i32.const 8) "\10\00\00\00h\00i\00,\00 \00I\00\'\00m\00 \00a\00 \00s\00t\00r\00i\00n\00g") - (data (i32.const 48) "\02\00\00\00h\00i") - (data (i32.const 56) "\04\00\00\00n\00u\00l\00l") - (data (i32.const 72) "\06\00\00\00s\00t\00r\00i\00n\00g") - (data (i32.const 88) "\03\00\00\00I\00\'\00m") - (data (i32.const 104) "\01\00\00\00,") - (data (i32.const 112) "\01\00\00\00x") + (data (i32.const 48) "\03\00\00\001\002\003") + (data (i32.const 64) "\05\00\00\001\002\003\00a\00b") + (data (i32.const 80) "\05\00\00\00a\00b\001\002\003") + (data (i32.const 96) "\04\00\00\000\00x\001\000") + (data (i32.const 112) "\02\00\00\000\00x") + (data (i32.const 120) "\03\00\00\00-\000\00x") + (data (i32.const 136) "\06\00\00\00-\00-\000\00x\001\000") + (data (i32.const 152) "\04\00\00\00-\001\002\003") + (data (i32.const 168) "\05\00\00\00-\000\00x\001\000") + (data (i32.const 184) "\05\00\00\00+\000\00x\001\000") + (data (i32.const 200) "\02\00\00\00h\00i") + (data (i32.const 208) "\04\00\00\00n\00u\00l\00l") + (data (i32.const 224) "\06\00\00\00s\00t\00r\00i\00n\00g") + (data (i32.const 240) "\03\00\00\00I\00\'\00m") + (data (i32.const 256) "\01\00\00\00,") + (data (i32.const 264) "\01\00\00\00x") (export "getString" (func $std/string/getString)) (export "memory" (memory $0)) (start $start) @@ -118,7 +139,7 @@ (get_local $1) ) (set_local $1 - (i32.const 56) + (i32.const 208) ) ) (if @@ -276,7 +297,7 @@ (get_local $1) ) (set_local $1 - (i32.const 56) + (i32.const 208) ) ) (set_local $4 @@ -358,10 +379,334 @@ ) (i32.const -1) ) - (func $std/string/getString (; 5 ;) (type $i) (result i32) + (func $std:string/parseInt (; 5 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 f64) + (local $7 i32) + (block $folding-inner0 + (br_if $folding-inner0 + (i32.and + (if (result i32) + (tee_local $2 + (i32.and + (select + (i32.and + (select + (i32.lt_s + (get_local $1) + (i32.const 2) + ) + (i32.ne + (get_local $1) + (i32.const 0) + ) + (get_local $1) + ) + (i32.const 1) + ) + (i32.eqz + (tee_local $4 + (i32.load + (get_local $0) + ) + ) + ) + (get_local $4) + ) + (i32.const 1) + ) + ) + (get_local $2) + (i32.gt_s + (get_local $1) + (i32.const 36) + ) + ) + (i32.const 1) + ) + ) + (set_local $7 + (i32.eq + (tee_local $2 + (call $std:string/String#charCodeAt + (get_local $0) + (i32.const 0) + ) + ) + (i32.const 45) + ) + ) + (if + (i32.and + (select + (i32.eq + (get_local $2) + (i32.const 43) + ) + (get_local $7) + (i32.eq + (get_local $2) + (i32.const 43) + ) + ) + (i32.const 1) + ) + (block + (br_if $folding-inner0 + (i32.eq + (get_local $4) + (i32.const 1) + ) + ) + (set_local $3 + (i32.const 1) + ) + ) + ) + (if + (i32.eqz + (get_local $1) + ) + (set_local $1 + (if (result i32) + (i32.eq + (call $std:string/String#charCodeAt + (get_local $0) + (get_local $3) + ) + (i32.const 48) + ) + (if (result i32) + (i32.and + (select + (i32.and + (select + (i32.eq + (tee_local $1 + (call $std:string/String#charCodeAt + (get_local $0) + (i32.add + (get_local $3) + (i32.const 1) + ) + ) + ) + (i32.const 120) + ) + (i32.eq + (get_local $1) + (i32.const 88) + ) + (i32.eq + (get_local $1) + (i32.const 120) + ) + ) + (i32.const 1) + ) + (i32.gt_s + (get_local $4) + (i32.const 1) + ) + (i32.gt_s + (get_local $4) + (i32.const 1) + ) + ) + (i32.const 1) + ) + (block (result i32) + (br_if $folding-inner0 + (i32.lt_s + (get_local $4) + (i32.add + (get_local $3) + (i32.const 3) + ) + ) + ) + (set_local $3 + (i32.add + (get_local $3) + (i32.const 2) + ) + ) + (i32.const 16) + ) + (i32.const 10) + ) + (i32.const 10) + ) + ) + ) + (block $break|0 + (loop $continue|0 + (if + (i32.lt_s + (get_local $3) + (get_local $4) + ) + (block + (if + (i32.and + (select + (i32.le_s + (tee_local $2 + (call $std:string/String#charCodeAt + (get_local $0) + (get_local $3) + ) + ) + (i32.const 57) + ) + (i32.le_s + (i32.const 48) + (get_local $2) + ) + (i32.le_s + (i32.const 48) + (get_local $2) + ) + ) + (i32.const 1) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 48) + ) + ) + (if + (i32.and + (select + (i32.le_s + (get_local $2) + (i32.const 122) + ) + (i32.le_s + (i32.const 97) + (get_local $2) + ) + (i32.le_s + (i32.const 97) + (get_local $2) + ) + ) + (i32.const 1) + ) + (set_local $2 + (i32.add + (get_local $2) + (i32.const -87) + ) + ) + (if + (i32.and + (select + (i32.le_s + (get_local $2) + (i32.const 90) + ) + (i32.le_s + (i32.const 65) + (get_local $2) + ) + (i32.le_s + (i32.const 65) + (get_local $2) + ) + ) + (i32.const 1) + ) + (set_local $2 + (i32.add + (get_local $2) + (i32.const -55) + ) + ) + (block + (br_if $break|0 + (get_local $5) + ) + (br $folding-inner0) + ) + ) + ) + ) + (if + (i32.ge_s + (get_local $2) + (get_local $1) + ) + (block + (br_if $break|0 + (get_local $5) + ) + (br $folding-inner0) + ) + ) + (set_local $5 + (i32.const 1) + ) + (set_local $6 + (f64.add + (f64.mul + (get_local $6) + (f64.convert_s/i32 + (get_local $1) + ) + ) + (f64.convert_s/i32 + (get_local $2) + ) + ) + ) + (set_local $3 + (i32.add + (get_local $3) + (i32.const 1) + ) + ) + (br $continue|0) + ) + ) + ) + ) + (br_if $folding-inner0 + (i32.and + (select + (i32.eqz + (get_local $5) + ) + (i32.gt_s + (get_local $4) + (i32.const 2) + ) + (get_local $5) + ) + (i32.const 1) + ) + ) + (return + (select + (f64.neg + (get_local $6) + ) + (get_local $6) + (get_local $7) + ) + ) + ) + (f64.const nan:0x8000000000000) + ) + (func $std/string/getString (; 6 ;) (type $i) (result i32) (get_global $std/string/str) ) - (func $start (; 6 ;) (type $v) + (func $start (; 7 ;) (type $v) + (local $0 f64) (if (i32.ne (get_global $std/string/str) @@ -392,7 +737,7 @@ (i32.eqz (call $std:string/String#startsWith (get_global $std/string/str) - (i32.const 48) + (i32.const 200) (i32.const 0) ) ) @@ -402,7 +747,7 @@ (i32.eqz (call $std:string/String#endsWith (get_global $std/string/str) - (i32.const 72) + (i32.const 224) (i32.const 2147483647) ) ) @@ -413,7 +758,7 @@ (i32.ne (call $std:string/String#indexOf (get_global $std/string/str) - (i32.const 88) + (i32.const 240) (i32.const 0) ) (i32.const -1) @@ -425,7 +770,7 @@ (i32.ne (call $std:string/String#indexOf (get_global $std/string/str) - (i32.const 104) + (i32.const 256) (i32.const 0) ) (i32.const 2) @@ -436,12 +781,204 @@ (i32.ne (call $std:string/String#indexOf (get_global $std/string/str) - (i32.const 112) + (i32.const 264) (i32.const 0) ) (i32.const -1) ) (unreachable) ) + (if + (i32.ne + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/str123) + (i32.const 0) + ) + ) + (i32.const 123) + ) + (unreachable) + ) + (if + (i32.ne + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/str123ab) + (i32.const 0) + ) + ) + (i32.const 123) + ) + (unreachable) + ) + (if + (i32.ne + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/strHex) + (i32.const 0) + ) + ) + (i32.const 16) + ) + (unreachable) + ) + (if + (i32.ne + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/strHex) + (i32.const 0) + ) + ) + (i32.const 16) + ) + (unreachable) + ) + (if + (i32.ne + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/str123n) + (i32.const 0) + ) + ) + (i32.const -123) + ) + (unreachable) + ) + (if + (i32.ne + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/strHexn) + (i32.const 0) + ) + ) + (i32.const -16) + ) + (unreachable) + ) + (if + (i32.ne + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/strHexp) + (i32.const 0) + ) + ) + (i32.const 16) + ) + (unreachable) + ) + (if + (i32.ne + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/str123) + (i32.const 0) + ) + ) + (i32.const 123) + ) + (unreachable) + ) + (if + (i32.ne + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/str123) + (i32.const 10) + ) + ) + (i32.const 123) + ) + (unreachable) + ) + (if + (i32.ne + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/str123) + (i32.const 16) + ) + ) + (i32.const 291) + ) + (unreachable) + ) + (if + (f64.eq + (tee_local $0 + (call $std:string/parseInt + (get_global $std/string/strab123) + (i32.const 0) + ) + ) + (get_local $0) + ) + (unreachable) + ) + (if + (f64.eq + (tee_local $0 + (call $std:string/parseInt + (get_global $std/string/strHexInvalid) + (i32.const 0) + ) + ) + (get_local $0) + ) + (unreachable) + ) + (if + (f64.eq + (tee_local $0 + (call $std:string/parseInt + (get_global $std/string/strHexnInvalid) + (i32.const 0) + ) + ) + (get_local $0) + ) + (unreachable) + ) + (if + (f64.eq + (tee_local $0 + (call $std:string/parseInt + (get_global $std/string/strHexnnInv) + (i32.const 0) + ) + ) + (get_local $0) + ) + (unreachable) + ) + (if + (f64.eq + (tee_local $0 + (call $std:string/parseInt + (get_global $std/string/str123) + (i32.const 1) + ) + ) + (get_local $0) + ) + (unreachable) + ) + (if + (f64.eq + (tee_local $0 + (call $std:string/parseInt + (get_global $std/string/str123) + (i32.const 37) + ) + ) + (get_local $0) + ) + (unreachable) + ) ) ) diff --git a/tests/compiler/std/string.ts b/tests/compiler/std/string.ts index 02984a37b3..79f770075c 100644 --- a/tests/compiler/std/string.ts +++ b/tests/compiler/std/string.ts @@ -1,6 +1,17 @@ // preliminary var str: string = "hi, I'm a string"; +var str123: string = "123"; +var str123ab: string = "123ab"; +var strab123: string = "ab123"; +var strHex: string = "0x10"; +var strHexInvalid: string = "0x"; +var strHexnInvalid: string = "-0x"; +var strHexnnInv: string = "--0x10"; +// var strHexInvChar: string = "0x1g"; +var str123n: string = "-123"; +var strHexn: string = "-0x10"; +var strHexp: string = "+0x10"; // exactly once in static memory assert(changetype(str) === changetype("hi, I'm a string")); @@ -13,6 +24,31 @@ assert(str.includes("I'm")); assert(str.indexOf(",") == 2); assert(str.indexOf("x") == -1); +// test parseInt + +assert(parseInt(str123) == (123)); +assert(parseInt(str123ab) == (123)); +assert(parseInt(strHex) == (0x10)); +assert(parseInt(strHex) == (0x10)); + +assert(parseInt(str123n) == (-123)); +assert(parseInt(strHexn) == (-0x10)); +assert(parseInt(strHexp) == (+0x10)); + +assert(parseInt(str123, 0) == (123)); +assert(parseInt(str123, 10) == (123)); +assert(parseInt(str123, 16) == (0x123)); + +assert(isNaN(parseInt(strab123))); +assert(isNaN(parseInt(strHexInvalid))); +assert(isNaN(parseInt(strHexnInvalid))); +assert(isNaN(parseInt(strHexnnInv))); +// assert(isNaN(parseInt(strHexInvChar))); + +// Unsupported radix +assert(isNaN(parseInt(str123, 1))); +assert(isNaN(parseInt(str123, 37))); + export function getString(): string { return str; } diff --git a/tests/compiler/std/string.wast b/tests/compiler/std/string.wast index 79eae22bb3..aa350c8434 100644 --- a/tests/compiler/std/string.wast +++ b/tests/compiler/std/string.wast @@ -2,18 +2,49 @@ (type $i (func (result i32))) (type $iii (func (param i32 i32) (result i32))) (type $iiii (func (param i32 i32 i32) (result i32))) + (type $iiF (func (param i32 i32) (result f64))) (type $v (func)) (global $std/string/str (mut i32) (i32.const 8)) + (global $std/string/str123 (mut i32) (i32.const 48)) + (global $std/string/str123ab (mut i32) (i32.const 64)) + (global $std/string/strab123 (mut i32) (i32.const 80)) + (global $std/string/strHex (mut i32) (i32.const 96)) + (global $std/string/strHexInvalid (mut i32) (i32.const 112)) + (global $std/string/strHexnInvalid (mut i32) (i32.const 120)) + (global $std/string/strHexnnInv (mut i32) (i32.const 136)) + (global $std/string/str123n (mut i32) (i32.const 152)) + (global $std/string/strHexn (mut i32) (i32.const 168)) + (global $std/string/strHexp (mut i32) (i32.const 184)) (global $std:string/HEAD i32 (i32.const 4)) - (global $HEAP_BASE i32 (i32.const 118)) + (global $std:string/cn i32 (i32.const 45)) + (global $std:string/cp i32 (i32.const 43)) + (global $std:string/c0 i32 (i32.const 48)) + (global $std:string/cx i32 (i32.const 120)) + (global $std:string/cX i32 (i32.const 88)) + (global $std:string/c9 i32 (i32.const 57)) + (global $std:string/ca i32 (i32.const 97)) + (global $std:string/cz i32 (i32.const 122)) + (global $std:string/cA i32 (i32.const 65)) + (global $std:string/cZ i32 (i32.const 90)) + (global $HEAP_BASE i32 (i32.const 270)) (memory $0 1) (data (i32.const 8) "\10\00\00\00h\00i\00,\00 \00I\00\'\00m\00 \00a\00 \00s\00t\00r\00i\00n\00g\00") - (data (i32.const 48) "\02\00\00\00h\00i\00") - (data (i32.const 56) "\04\00\00\00n\00u\00l\00l\00") - (data (i32.const 72) "\06\00\00\00s\00t\00r\00i\00n\00g\00") - (data (i32.const 88) "\03\00\00\00I\00\'\00m\00") - (data (i32.const 104) "\01\00\00\00,\00") - (data (i32.const 112) "\01\00\00\00x\00") + (data (i32.const 48) "\03\00\00\001\002\003\00") + (data (i32.const 64) "\05\00\00\001\002\003\00a\00b\00") + (data (i32.const 80) "\05\00\00\00a\00b\001\002\003\00") + (data (i32.const 96) "\04\00\00\000\00x\001\000\00") + (data (i32.const 112) "\02\00\00\000\00x\00") + (data (i32.const 120) "\03\00\00\00-\000\00x\00") + (data (i32.const 136) "\06\00\00\00-\00-\000\00x\001\000\00") + (data (i32.const 152) "\04\00\00\00-\001\002\003\00") + (data (i32.const 168) "\05\00\00\00-\000\00x\001\000\00") + (data (i32.const 184) "\05\00\00\00+\000\00x\001\000\00") + (data (i32.const 200) "\02\00\00\00h\00i\00") + (data (i32.const 208) "\04\00\00\00n\00u\00l\00l\00") + (data (i32.const 224) "\06\00\00\00s\00t\00r\00i\00n\00g\00") + (data (i32.const 240) "\03\00\00\00I\00\'\00m\00") + (data (i32.const 256) "\01\00\00\00,\00") + (data (i32.const 264) "\01\00\00\00x\00") (export "getString" (func $std/string/getString)) (export "memory" (memory $0)) (start $start) @@ -144,7 +175,7 @@ (i32.const 0) ) (set_local $1 - (i32.const 56) + (i32.const 208) ) ) (set_local $3 @@ -341,7 +372,7 @@ (i32.const 0) ) (set_local $1 - (i32.const 56) + (i32.const 208) ) ) (set_local $3 @@ -456,12 +487,426 @@ ) ) ) - (func $std/string/getString (; 6 ;) (type $i) (result i32) + (func $std:string/parseInt (; 6 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 f64) + (local $10 i32) + (local $11 i32) + (set_local $2 + (i32.load + (get_local $0) + ) + ) + (if + (i32.and + (if (result i32) + (i32.ne + (tee_local $3 + (i32.and + (if (result i32) + (i32.ne + (i32.eq + (get_local $2) + (i32.const 0) + ) + (i32.const 0) + ) + (i32.eq + (get_local $2) + (i32.const 0) + ) + (i32.and + (if (result i32) + (i32.ne + (i32.ne + (get_local $1) + (i32.const 0) + ) + (i32.const 0) + ) + (i32.lt_s + (get_local $1) + (i32.const 2) + ) + (i32.ne + (get_local $1) + (i32.const 0) + ) + ) + (i32.const 1) + ) + ) + (i32.const 1) + ) + ) + (i32.const 0) + ) + (get_local $3) + (i32.gt_s + (get_local $1) + (i32.const 36) + ) + ) + (i32.const 1) + ) + (return + (f64.const nan:0x8000000000000) + ) + ) + (set_local $4 + (call $std:string/String#charCodeAt + (get_local $0) + (i32.const 0) + ) + ) + (set_local $5 + (i32.const 0) + ) + (set_local $6 + (i32.eq + (get_local $4) + (i32.const 45) + ) + ) + (if + (i32.and + (if (result i32) + (i32.ne + (i32.eq + (get_local $4) + (i32.const 43) + ) + (i32.const 0) + ) + (i32.eq + (get_local $4) + (i32.const 43) + ) + (get_local $6) + ) + (i32.const 1) + ) + (block + (if + (i32.eq + (get_local $2) + (i32.const 1) + ) + (return + (f64.const nan:0x8000000000000) + ) + ) + (set_local $5 + (i32.const 1) + ) + ) + ) + (if + (i32.eq + (get_local $1) + (i32.const 0) + ) + (if + (i32.eq + (call $std:string/String#charCodeAt + (get_local $0) + (get_local $5) + ) + (i32.const 48) + ) + (block + (set_local $7 + (call $std:string/String#charCodeAt + (get_local $0) + (i32.add + (get_local $5) + (i32.const 1) + ) + ) + ) + (if + (i32.and + (if (result i32) + (i32.ne + (i32.gt_s + (get_local $2) + (i32.const 1) + ) + (i32.const 0) + ) + (i32.and + (if (result i32) + (i32.ne + (i32.eq + (get_local $7) + (i32.const 120) + ) + (i32.const 0) + ) + (i32.eq + (get_local $7) + (i32.const 120) + ) + (i32.eq + (get_local $7) + (i32.const 88) + ) + ) + (i32.const 1) + ) + (i32.gt_s + (get_local $2) + (i32.const 1) + ) + ) + (i32.const 1) + ) + (block + (if + (i32.lt_s + (get_local $2) + (i32.add + (get_local $5) + (i32.const 3) + ) + ) + (return + (f64.const nan:0x8000000000000) + ) + ) + (set_local $1 + (i32.const 16) + ) + (set_local $5 + (i32.add + (get_local $5) + (i32.const 2) + ) + ) + ) + (set_local $1 + (i32.const 10) + ) + ) + ) + (set_local $1 + (i32.const 10) + ) + ) + ) + (set_local $8 + (i32.const 0) + ) + (set_local $9 + (f64.const 0) + ) + (block $break|0 + (nop) + (loop $continue|0 + (if + (i32.lt_s + (get_local $5) + (get_local $2) + ) + (block + (block + (set_local $11 + (call $std:string/String#charCodeAt + (get_local $0) + (get_local $5) + ) + ) + (if + (i32.and + (if (result i32) + (i32.ne + (i32.le_s + (i32.const 48) + (get_local $11) + ) + (i32.const 0) + ) + (i32.le_s + (get_local $11) + (i32.const 57) + ) + (i32.le_s + (i32.const 48) + (get_local $11) + ) + ) + (i32.const 1) + ) + (set_local $10 + (i32.sub + (get_local $11) + (i32.const 48) + ) + ) + (if + (i32.and + (if (result i32) + (i32.ne + (i32.le_s + (i32.const 97) + (get_local $11) + ) + (i32.const 0) + ) + (i32.le_s + (get_local $11) + (i32.const 122) + ) + (i32.le_s + (i32.const 97) + (get_local $11) + ) + ) + (i32.const 1) + ) + (set_local $10 + (i32.add + (i32.sub + (get_local $11) + (i32.const 97) + ) + (i32.const 10) + ) + ) + (if + (i32.and + (if (result i32) + (i32.ne + (i32.le_s + (i32.const 65) + (get_local $11) + ) + (i32.const 0) + ) + (i32.le_s + (get_local $11) + (i32.const 90) + ) + (i32.le_s + (i32.const 65) + (get_local $11) + ) + ) + (i32.const 1) + ) + (set_local $10 + (i32.add + (i32.sub + (get_local $11) + (i32.const 65) + ) + (i32.const 10) + ) + ) + (block + (if + (get_local $8) + (br $break|0) + ) + (return + (f64.const nan:0x8000000000000) + ) + ) + ) + ) + ) + (if + (i32.ge_s + (get_local $10) + (get_local $1) + ) + (block + (if + (get_local $8) + (br $break|0) + ) + (return + (f64.const nan:0x8000000000000) + ) + ) + ) + (set_local $8 + (i32.const 1) + ) + (set_local $9 + (f64.mul + (get_local $9) + (f64.convert_s/i32 + (get_local $1) + ) + ) + ) + (set_local $9 + (f64.add + (get_local $9) + (f64.convert_s/i32 + (get_local $10) + ) + ) + ) + ) + (set_local $5 + (i32.add + (get_local $5) + (i32.const 1) + ) + ) + (br $continue|0) + ) + ) + ) + ) + (if + (i32.and + (if (result i32) + (i32.ne + (i32.eqz + (get_local $8) + ) + (i32.const 0) + ) + (i32.gt_s + (get_local $2) + (i32.const 2) + ) + (i32.eqz + (get_local $8) + ) + ) + (i32.const 1) + ) + (return + (f64.const nan:0x8000000000000) + ) + ) + (return + (if (result f64) + (get_local $6) + (f64.neg + (get_local $9) + ) + (get_local $9) + ) + ) + ) + (func $std/string/getString (; 7 ;) (type $i) (result i32) (return (get_global $std/string/str) ) ) - (func $start (; 7 ;) (type $v) + (func $start (; 8 ;) (type $v) + (local $0 f64) (if (i32.eqz (i32.eq @@ -498,7 +943,7 @@ (i32.eqz (call $std:string/String#startsWith (get_global $std/string/str) - (i32.const 48) + (i32.const 200) (i32.const 0) ) ) @@ -508,7 +953,7 @@ (i32.eqz (call $std:string/String#endsWith (get_global $std/string/str) - (i32.const 72) + (i32.const 224) (i32.const 2147483647) ) ) @@ -518,7 +963,7 @@ (i32.eqz (call $std:string/String#includes (get_global $std/string/str) - (i32.const 88) + (i32.const 240) (i32.const 0) ) ) @@ -529,7 +974,7 @@ (i32.eq (call $std:string/String#indexOf (get_global $std/string/str) - (i32.const 104) + (i32.const 256) (i32.const 0) ) (i32.const 2) @@ -542,7 +987,7 @@ (i32.eq (call $std:string/String#indexOf (get_global $std/string/str) - (i32.const 112) + (i32.const 264) (i32.const 0) ) (i32.sub @@ -553,6 +998,236 @@ ) (unreachable) ) + (if + (i32.eqz + (i32.eq + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/str123) + (i32.const 0) + ) + ) + (i32.const 123) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i32.eq + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/str123ab) + (i32.const 0) + ) + ) + (i32.const 123) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i32.eq + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/strHex) + (i32.const 0) + ) + ) + (i32.const 16) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i32.eq + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/strHex) + (i32.const 0) + ) + ) + (i32.const 16) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i32.eq + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/str123n) + (i32.const 0) + ) + ) + (i32.sub + (i32.const 0) + (i32.const 123) + ) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i32.eq + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/strHexn) + (i32.const 0) + ) + ) + (i32.sub + (i32.const 0) + (i32.const 16) + ) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i32.eq + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/strHexp) + (i32.const 0) + ) + ) + (i32.const 16) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i32.eq + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/str123) + (i32.const 0) + ) + ) + (i32.const 123) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i32.eq + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/str123) + (i32.const 10) + ) + ) + (i32.const 123) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (i32.eq + (i32.trunc_s/f64 + (call $std:string/parseInt + (get_global $std/string/str123) + (i32.const 16) + ) + ) + (i32.const 291) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (f64.ne + (tee_local $0 + (call $std:string/parseInt + (get_global $std/string/strab123) + (i32.const 0) + ) + ) + (get_local $0) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (f64.ne + (tee_local $0 + (call $std:string/parseInt + (get_global $std/string/strHexInvalid) + (i32.const 0) + ) + ) + (get_local $0) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (f64.ne + (tee_local $0 + (call $std:string/parseInt + (get_global $std/string/strHexnInvalid) + (i32.const 0) + ) + ) + (get_local $0) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (f64.ne + (tee_local $0 + (call $std:string/parseInt + (get_global $std/string/strHexnnInv) + (i32.const 0) + ) + ) + (get_local $0) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (f64.ne + (tee_local $0 + (call $std:string/parseInt + (get_global $std/string/str123) + (i32.const 1) + ) + ) + (get_local $0) + ) + ) + (unreachable) + ) + (if + (i32.eqz + (f64.ne + (tee_local $0 + (call $std:string/parseInt + (get_global $std/string/str123) + (i32.const 37) + ) + ) + (get_local $0) + ) + ) + (unreachable) + ) ) ) (; @@ -623,6 +1298,16 @@ PROPERTY: std:set/Set#size CLASS_PROTOTYPE: Set GLOBAL: std:string/EMPTY + GLOBAL: std:string/cp + GLOBAL: std:string/cn + GLOBAL: std:string/cx + GLOBAL: std:string/cX + GLOBAL: std:string/c0 + GLOBAL: std:string/c9 + GLOBAL: std:string/ca + GLOBAL: std:string/cz + GLOBAL: std:string/cA + GLOBAL: std:string/cZ GLOBAL: std:string/HEAD FUNCTION_PROTOTYPE: std:string/allocate CLASS_PROTOTYPE: std:string/String @@ -635,6 +1320,16 @@ FUNCTION_PROTOTYPE: std:string/parseFloat FUNCTION_PROTOTYPE: parseFloat GLOBAL: std/string/str + GLOBAL: std/string/str123 + GLOBAL: std/string/str123ab + GLOBAL: std/string/strab123 + GLOBAL: std/string/strHex + GLOBAL: std/string/strHexInvalid + GLOBAL: std/string/strHexnInvalid + GLOBAL: std/string/strHexnnInv + GLOBAL: std/string/str123n + GLOBAL: std/string/strHexn + GLOBAL: std/string/strHexp FUNCTION_PROTOTYPE: std/string/getString GLOBAL: std:memory/arena/ALIGN_LOG2 GLOBAL: std:memory/arena/ALIGN_SIZE