diff --git a/package-lock.json b/package-lock.json index 2b087a09..1b6a6947 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,7 +33,7 @@ "requires": { "@types/events": "1.1.0", "@types/minimatch": "3.0.2", - "@types/node": "8.5.1" + "@types/node": "8.5.2" } }, "@types/long": { @@ -55,9 +55,9 @@ "dev": true }, "@types/node": { - "version": "8.5.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-8.5.1.tgz", - "integrity": "sha512-SrmAO+NhnsuG/6TychSl2VdxBZiw/d6V+8j+DFo8O3PwFi+QeYXWHhAw+b170aSc6zYab6/PjEWRZHIDN9mNUw==", + "version": "8.5.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-8.5.2.tgz", + "integrity": "sha512-KA4GKOpgXnrqEH2eCVhiv2CsxgXGQJgV1X0vsGlh+WCnxbeAE1GT44ZsTU1IN5dEeV/gDupKa7gWo08V5IxWVQ==", "dev": true }, "@types/strip-bom": { @@ -265,9 +265,9 @@ "dev": true }, "binaryen": { - "version": "40.0.0-nightly.20171209", - "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-40.0.0-nightly.20171209.tgz", - "integrity": "sha512-ELe79ZuH6dPLo+j3tbTvGl9BagzUTtIuYlY3LWz1kj5JzgpqeZmUweay1vK6MZo7J/1IA7Sgda4J7vxUhNu03Q==" + "version": "40.0.0-nightly.20171229", + "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-40.0.0-nightly.20171229.tgz", + "integrity": "sha512-P9VXMphJKRZbdr0AAmkpgRPGVWbnDmcqt8NPuZ+W0eSeC1igGDLdreJteCdtHA7Z+qRQ4BWqtmKPZEJKRZk47w==" }, "bn.js": { "version": "4.11.8", @@ -1314,9 +1314,9 @@ } }, "make-error": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.0.tgz", - "integrity": "sha1-Uq06M5zPEM5itAQLcI/nByRLi5Y=", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.2.tgz", + "integrity": "sha512-l9ra35l5VWLF24y75Tg8XgfGLX0ueRhph118WKM6H5denx4bB5QF59+4UAm9oJ2qsPQZas/CQUDdtDdfvYHBdQ==", "dev": true }, "md5.js": { @@ -2006,6 +2006,7 @@ "version": "0.5.0", "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.0.tgz", "integrity": "sha512-vUoN3I7fHQe0R/SJLKRdKYuEdRGogsviXFkHHo17AWaTGv17VLnxw+CFXvqy+y4ORZ3doWLQcxRYfwKrsd/H7Q==", + "dev": true, "requires": { "source-map": "0.6.1" }, @@ -2013,7 +2014,8 @@ "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true } } }, @@ -2164,15 +2166,15 @@ } }, "ts-node": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-4.0.2.tgz", - "integrity": "sha512-mg7l6ON8asjnfzkTi1LFWKaOGHl5Jf1+5ij0MQ502YfC6+4FBgh/idJgw9aN9kei1Rf4/pmFpNuFE1YbcQdOTA==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-4.1.0.tgz", + "integrity": "sha512-xcZH12oVg9PShKhy3UHyDmuDLV3y7iKwX25aMVPt1SIXSuAfWkFiGPEkg+th8R4YKW/QCxDoW7lJdb15lx6QWg==", "dev": true, "requires": { "arrify": "1.0.1", "chalk": "2.3.0", "diff": "3.4.0", - "make-error": "1.3.0", + "make-error": "1.3.2", "minimist": "1.2.0", "mkdirp": "0.5.1", "source-map-support": "0.5.0", diff --git a/package.json b/package.json index 5476d439..0bf92f02 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "url": "https://github.com/AssemblyScript/assemblyscript/issues" }, "dependencies": { - "binaryen": "40.0.0-nightly.20171209", + "binaryen": "40.0.0-nightly.20171229", "glob": "^7.1.2", "minimist": "^1.2.0" }, @@ -21,13 +21,13 @@ "@types/glob": "^5.0.34", "@types/long": "^3.0.32", "@types/minimist": "^1.2.0", - "@types/node": "^8.5.1", + "@types/node": "^8.5.2", "chalk": "^2.3.0", "diff": "^3.4.0", "long": "^3.2.0", "source-map-support": "^0.5.0", "ts-loader": "^3.2.0", - "ts-node": "^4.0.2", + "ts-node": "^4.1.0", "tslint": "^5.8.0", "typescript": "^2.6.2", "webpack": "^3.10.0" @@ -38,7 +38,7 @@ "asc": "bin/asc" }, "engines": { - "node" : ">=8" + "node": ">=8" }, "scripts": { "build": "webpack", diff --git a/src/ast.ts b/src/ast.ts index 0c369463..e822d19d 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -1028,7 +1028,7 @@ export class StringLiteralExpression extends LiteralExpression { value: string; serialize(sb: string[]): void { - sb.push(escapeString(this.value)); + sb.push(stringToLiteral(this.value)); } } @@ -2181,19 +2181,93 @@ function builderEndsWith(sb: string[], code: CharCode): bool { return false; } -/** Escapes a string to a string literal. */ -export function escapeString(str: string): string { - var k = str.length; - var ret = new Array(k); - for (var i = 0, c: string; i < k; ++i) { - switch (c = str.charAt(i)) { - case "\\": ret[i] = "\\\\"; break; - case "\"": ret[i] = "\\\""; break; - case "\r": ret[i] = "\\r"; break; - case "\n": ret[i] = "\\n"; break; - case "\0": ret[i] = "\\0"; break; - default: ret[i] = c; +/** Converts a string to its literal representation including quotes. */ +export function stringToLiteral(str: string): string { + var ret = new Array(); + var off = 0; + for (var i = 0, k = str.length; i < k;) { + switch (str.charCodeAt(i)) { + + case CharCode.NULL: + if (i > off) + ret.push(str.substring(off, off = i + 1)); + ret.push("\\0"); + off = ++i; + break; + + case CharCode.BACKSPACE: + if (i > off) + ret.push(str.substring(off, i)); + off = ++i; + ret.push("\\b"); + break; + + case CharCode.TAB: + if (i > off) + ret.push(str.substring(off, i)); + off = ++i; + ret.push("\\t"); + break; + + case CharCode.LINEFEED: + if (i > off) + ret.push(str.substring(off, i)); + off = ++i; + ret.push("\\n"); + break; + + case CharCode.VERTICALTAB: + if (i > off) + ret.push(str.substring(off, i)); + off = ++i; + ret.push("\\v"); + break; + + case CharCode.FORMFEED: + if (i > off) + ret.push(str.substring(off, i)); + off = ++i; + ret.push("\\f"); + break; + + case CharCode.CARRIAGERETURN: + if (i > off) + ret.push(str.substring(off, i)); + ret.push("\\r"); + off = ++i; + break; + + case CharCode.DOUBLEQUOTE: + if (i > off) + ret.push(str.substring(off, i)); + ret.push("\\\""); + off = ++i; + break; + + case CharCode.SINGLEQUOTE: + if (i > off) + ret.push(str.substring(off, i)); + ret.push("\\'"); + off = ++i; + break; + + case CharCode.BACKSLASH: + if (i > off) + ret.push(str.substring(off, i)); + ret.push("\\\\"); + off = ++i; + break; + + default: + ++i; + break; } } + if (off == 0) { + assert(ret.length == 0); + return "\"" + str + "\""; + } + if (i > off) + ret.push(str.substring(off, i)); return "\"" + ret.join("") + "\""; } diff --git a/src/compiler.ts b/src/compiler.ts index df6e287b..5dcf651b 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -1573,19 +1573,19 @@ export class Compiler extends DiagnosticEmitter { left = this.compileExpression(expression.left, contextualType, ConversionKind.NONE); right = this.compileExpression(expression.right, this.currentType); - // simplify if left is free of side effects while tolerating two levels of nesting, e.g., i32.load(i32.load(i32.const)) - // if (condition = this.module.cloneExpression(left, true, 2)) - // return this.module.createIf( - // this.currentType.isLongInteger - // ? this.module.createBinary(BinaryOp.NeI64, condition, this.module.createI64(0, 0)) - // : this.currentType == Type.f64 - // ? this.module.createBinary(BinaryOp.NeF64, condition, this.module.createF64(0)) - // : this.currentType == Type.f32 - // ? this.module.createBinary(BinaryOp.NeF32, condition, this.module.createF32(0)) - // : condition, // usual case: saves one EQZ when not using EQZ above - // right, - // left - // ); + // simplify if left is free of side effects while tolerating one level of nesting, e.g., i32.load(i32.const) + if (condition = this.module.cloneExpression(left, true, 1)) + return this.module.createIf( + this.currentType.isLongInteger + ? this.module.createBinary(BinaryOp.NeI64, condition, this.module.createI64(0, 0)) + : this.currentType == Type.f64 + ? this.module.createBinary(BinaryOp.NeF64, condition, this.module.createF64(0)) + : this.currentType == Type.f32 + ? this.module.createBinary(BinaryOp.NeF32, condition, this.module.createF32(0)) + : condition, // usual case: saves one EQZ when not using EQZ above + right, + left + ); // otherwise use a temporary local for the intermediate value tempLocal = this.currentFunction.getAndFreeTempLocal(this.currentType); @@ -1606,19 +1606,19 @@ export class Compiler extends DiagnosticEmitter { left = this.compileExpression(expression.left, contextualType, ConversionKind.NONE); right = this.compileExpression(expression.right, this.currentType); - // simplify if left is free of side effects while tolerating two levels of nesting - // if (condition = this.module.cloneExpression(left, true, 2)) - // return this.module.createIf( - // this.currentType.isLongInteger - // ? this.module.createBinary(BinaryOp.NeI64, condition, this.module.createI64(0, 0)) - // : this.currentType == Type.f64 - // ? this.module.createBinary(BinaryOp.NeF64, condition, this.module.createF64(0)) - // : this.currentType == Type.f32 - // ? this.module.createBinary(BinaryOp.NeF32, condition, this.module.createF32(0)) - // : condition, // usual case: saves one EQZ when not using EQZ above - // left, - // right - // ); + // simplify if left is free of side effects while tolerating one level of nesting + if (condition = this.module.cloneExpression(left, true, 1)) + return this.module.createIf( + this.currentType.isLongInteger + ? this.module.createBinary(BinaryOp.NeI64, condition, this.module.createI64(0, 0)) + : this.currentType == Type.f64 + ? this.module.createBinary(BinaryOp.NeF64, condition, this.module.createF64(0)) + : this.currentType == Type.f32 + ? this.module.createBinary(BinaryOp.NeF32, condition, this.module.createF32(0)) + : condition, // usual case: saves one EQZ when not using EQZ above + left, + right + ); // otherwise use a temporary local for the intermediate value tempLocal = this.currentFunction.getAndFreeTempLocal(this.currentType); diff --git a/src/module.ts b/src/module.ts index 45381f28..e4531792 100644 --- a/src/module.ts +++ b/src/module.ts @@ -15,33 +15,15 @@ export type ImportRef = usize; export type ExportRef = usize; export type Index = u32; -// snip... -declare function _BinaryenNone(): NativeType; -declare function _BinaryenInt32(): NativeType; -declare function _BinaryenInt64(): NativeType; -declare function _BinaryenFloat32(): NativeType; -declare function _BinaryenFloat64(): NativeType; -declare function _BinaryenUndefined(): NativeType; -export enum NativeType { - None = _BinaryenNone(), - I32 = _BinaryenInt32(), - I64 = _BinaryenInt64(), - F32 = _BinaryenFloat32(), - F64 = _BinaryenFloat64(), - Unreachable = 5, - Auto = _BinaryenUndefined() + export enum NativeType { + None = _BinaryenTypeNone(), + I32 = _BinaryenTypeInt32(), + I64 = _BinaryenTypeInt64(), + F32 = _BinaryenTypeFloat32(), + F64 = _BinaryenTypeFloat64(), + Unreachable = _BinaryenTypeUnreachable(), + Auto = _BinaryenTypeAuto() } -// ...snap, once binaryen is updated - -// export enum NativeType { -// None = _BinaryenTypeNone(), -// I32 = _BinaryenTypeInt32(), -// I64 = _BinaryenTypeInt64(), -// F32 = _BinaryenTypeFloat32(), -// F64 = _BinaryenTypeFloat64(), -// Unreachable = _BinaryenTypeUnreachable(), -// Auto = _BinaryenTypeAuto() -// } export enum ExpressionId { Invalid = _BinaryenInvalidId(), @@ -828,28 +810,35 @@ export class Module { case NativeType.I64: return this.createI64(_BinaryenConstGetValueI64Low(expr), _BinaryenConstGetValueI64High(expr)); case NativeType.F32: return this.createF32(_BinaryenConstGetValueF32(expr)); case NativeType.F64: return this.createF64(_BinaryenConstGetValueF64(expr)); - default: throw new Error("unexpected constant type"); + default: throw new Error("concrete type expected"); } case ExpressionId.GetLocal: return _BinaryenGetLocal(this.ref, _BinaryenGetLocalGetIndex(expr), _BinaryenExpressionGetType(expr)); - // case ExpressionId.GetGlobal: explodes if it doesn't have a name - // return _BinaryenGetGlobal(this.ref, _BinaryenGetGlobalGetName(expr), _BinaryenExpressionGetType(expr)); + case ExpressionId.GetGlobal: + var globalName = _BinaryenGetGlobalGetName(expr); + if (!globalName) + break; + return _BinaryenGetGlobal(this.ref, globalName, _BinaryenExpressionGetType(expr)); case ExpressionId.Load: - if (!(nested1 = this.cloneExpression(_BinaryenLoadGetPtr(expr), noSideEffects, maxDepth - 1))) break; + if (!(nested1 = this.cloneExpression(_BinaryenLoadGetPtr(expr), noSideEffects, maxDepth - 1))) + break; return _BinaryenLoadIsAtomic(expr) ? _BinaryenAtomicLoad(this.ref, _BinaryenLoadGetBytes(expr), _BinaryenLoadGetOffset(expr), _BinaryenExpressionGetType(expr), nested1) : _BinaryenLoad(this.ref, _BinaryenLoadGetBytes(expr), _BinaryenLoadIsSigned(expr) ? 1 : 0, _BinaryenLoadGetOffset(expr), _BinaryenLoadGetAlign(expr), _BinaryenExpressionGetType(expr), nested1); case ExpressionId.Unary: - if (!(nested1 = this.cloneExpression(_BinaryenUnaryGetValue(expr), noSideEffects, maxDepth - 1))) break; + if (!(nested1 = this.cloneExpression(_BinaryenUnaryGetValue(expr), noSideEffects, maxDepth - 1))) + break; return _BinaryenUnary(this.ref, _BinaryenUnaryGetOp(expr), nested1); case ExpressionId.Binary: - if (!(nested1 = this.cloneExpression(_BinaryenBinaryGetLeft(expr), noSideEffects, maxDepth - 1))) break; - if (!(nested2 = this.cloneExpression(_BinaryenBinaryGetRight(expr), noSideEffects, maxDepth - 1))) break; + if (!(nested1 = this.cloneExpression(_BinaryenBinaryGetLeft(expr), noSideEffects, maxDepth - 1))) + break; + if (!(nested2 = this.cloneExpression(_BinaryenBinaryGetRight(expr), noSideEffects, maxDepth - 1))) + break; return _BinaryenBinary(this.ref, _BinaryenBinaryGetOp(expr), nested1, nested2); } return 0; diff --git a/tests/compiler/game-of-life.optimized.wast b/tests/compiler/game-of-life.optimized.wast index 5daae13e..06c7dfeb 100644 --- a/tests/compiler/game-of-life.optimized.wast +++ b/tests/compiler/game-of-life.optimized.wast @@ -31,13 +31,13 @@ (local $5 i32) (local $6 i32) (local $7 i32) - (set_local $6 + (set_local $5 (i32.sub (get_global $../../examples/game-of-life/assembly/game-of-life/h) (i32.const 1) ) ) - (set_local $7 + (set_local $6 (i32.sub (get_global $../../examples/game-of-life/assembly/game-of-life/w) (i32.const 1) @@ -53,17 +53,17 @@ (get_global $../../examples/game-of-life/assembly/game-of-life/h) ) (block - (set_local $4 + (set_local $3 (select (i32.sub (get_local $0) (i32.const 1) ) - (get_local $6) + (get_local $5) (get_local $0) ) ) - (set_local $5 + (set_local $4 (select (i32.const 0) (i32.add @@ -72,7 +72,7 @@ ) (i32.eq (get_local $0) - (get_local $6) + (get_local $5) ) ) ) @@ -97,7 +97,7 @@ (i32.load8_u (i32.add (i32.mul - (get_local $4) + (get_local $3) (get_global $../../examples/game-of-life/assembly/game-of-life/w) ) (tee_local $2 @@ -106,7 +106,7 @@ (get_local $1) (i32.const 1) ) - (get_local $7) + (get_local $6) (get_local $1) ) ) @@ -115,7 +115,7 @@ (i32.load8_u (i32.add (i32.mul - (get_local $4) + (get_local $3) (get_global $../../examples/game-of-life/assembly/game-of-life/w) ) (get_local $1) @@ -125,10 +125,10 @@ (i32.load8_u (i32.add (i32.mul - (get_local $4) + (get_local $3) (get_global $../../examples/game-of-life/assembly/game-of-life/w) ) - (tee_local $3 + (tee_local $7 (select (i32.const 0) (i32.add @@ -137,7 +137,7 @@ ) (i32.eq (get_local $1) - (get_local $7) + (get_local $6) ) ) ) @@ -160,14 +160,14 @@ (get_local $0) (get_global $../../examples/game-of-life/assembly/game-of-life/w) ) - (get_local $3) + (get_local $7) ) ) ) (i32.load8_u (i32.add (i32.mul - (get_local $5) + (get_local $4) (get_global $../../examples/game-of-life/assembly/game-of-life/w) ) (get_local $2) @@ -177,7 +177,7 @@ (i32.load8_u (i32.add (i32.mul - (get_local $5) + (get_local $4) (get_global $../../examples/game-of-life/assembly/game-of-life/w) ) (get_local $1) @@ -187,10 +187,10 @@ (i32.load8_u (i32.add (i32.mul - (get_local $5) + (get_local $4) (get_global $../../examples/game-of-life/assembly/game-of-life/w) ) - (get_local $3) + (get_local $7) ) ) ) @@ -207,13 +207,14 @@ ) (if (if (result i32) - (tee_local $3 - (i32.lt_u - (get_local $2) - (i32.const 2) - ) + (i32.lt_u + (get_local $2) + (i32.const 2) + ) + (i32.lt_u + (get_local $2) + (i32.const 2) ) - (get_local $3) (i32.gt_u (get_local $2) (i32.const 3) diff --git a/tests/compiler/game-of-life.wast b/tests/compiler/game-of-life.wast index ce2c7882..07bcbd50 100644 --- a/tests/compiler/game-of-life.wast +++ b/tests/compiler/game-of-life.wast @@ -35,7 +35,6 @@ (local $8 i32) (local $9 i32) (local $10 i32) - (local $11 i32) (nop) (nop) (block @@ -236,13 +235,14 @@ (get_local $9) (if (if (result i32) - (tee_local $11 - (i32.lt_u - (get_local $8) - (i32.const 2) - ) + (i32.lt_u + (get_local $8) + (i32.const 2) + ) + (i32.lt_u + (get_local $8) + (i32.const 2) ) - (get_local $11) (i32.gt_u (get_local $8) (i32.const 3) diff --git a/tests/compiler/logical.optimized.wast b/tests/compiler/logical.optimized.wast index 3c0bd69b..d4c4b8b8 100644 --- a/tests/compiler/logical.optimized.wast +++ b/tests/compiler/logical.optimized.wast @@ -10,27 +10,10 @@ (func $start (; 0 ;) (type $v) (local $0 i32) (local $1 f64) - (local $2 i64) - (local $3 f32) - (if - (tee_local $0 - (i32.const 0) - ) - (unreachable) - ) - (if - (f64.ne - (tee_local $1 - (f64.const 0) - ) - (f64.const 0) - ) - (unreachable) - ) (if (i32.eqz (tee_local $0 - (i32.const 1) + (i32.const 2) ) ) (unreachable) @@ -38,52 +21,14 @@ (if (f64.eq (tee_local $1 - (f64.const 1) - ) - (f64.const 0) - ) - (unreachable) - ) - (if - (i32.eqz - (if (result i32) - (tee_local $0 - (i32.const 1) - ) - (tee_local $0 - (i32.const 2) - ) - (get_local $0) - ) - ) - (unreachable) - ) - (if - (f64.eq - (if (result f64) - (f64.ne - (tee_local $1 - (f64.const 1) - ) - (f64.const 0) - ) - (tee_local $1 - (f64.const 2) - ) - (get_local $1) + (f64.const 2) ) (f64.const 0) ) (unreachable) ) (set_global $logical/i - (if (result i32) - (tee_local $0 - (i32.const 1) - ) - (i32.const 2) - (get_local $0) - ) + (i32.const 2) ) (if (i32.ne @@ -93,13 +38,7 @@ (unreachable) ) (set_global $logical/i - (if (result i32) - (tee_local $0 - (i32.const 0) - ) - (get_local $0) - (i32.const 1) - ) + (i32.const 1) ) (if (i32.ne @@ -109,16 +48,7 @@ (unreachable) ) (set_global $logical/I - (if (result i64) - (i64.ne - (tee_local $2 - (i64.const 1) - ) - (i64.const 0) - ) - (i64.const 2) - (get_local $2) - ) + (i64.const 2) ) (if (i64.ne @@ -128,16 +58,7 @@ (unreachable) ) (set_global $logical/I - (if (result i64) - (i64.ne - (tee_local $2 - (i64.const 0) - ) - (i64.const 0) - ) - (get_local $2) - (i64.const 1) - ) + (i64.const 1) ) (if (i64.ne @@ -147,16 +68,7 @@ (unreachable) ) (set_global $logical/f - (if (result f32) - (f32.ne - (tee_local $3 - (f32.const 1) - ) - (f32.const 0) - ) - (f32.const 2) - (get_local $3) - ) + (f32.const 2) ) (if (f32.ne @@ -166,16 +78,7 @@ (unreachable) ) (set_global $logical/f - (if (result f32) - (f32.ne - (tee_local $3 - (f32.const 0) - ) - (f32.const 0) - ) - (get_local $3) - (f32.const 1) - ) + (f32.const 1) ) (if (f32.ne @@ -185,16 +88,7 @@ (unreachable) ) (set_global $logical/F - (if (result f64) - (f64.ne - (tee_local $1 - (f64.const 1) - ) - (f64.const 0) - ) - (f64.const 2) - (get_local $1) - ) + (f64.const 2) ) (if (f64.ne @@ -204,16 +98,7 @@ (unreachable) ) (set_global $logical/F - (if (result f64) - (f64.ne - (tee_local $1 - (f64.const 0) - ) - (f64.const 0) - ) - (get_local $1) - (f64.const 1) - ) + (f64.const 1) ) (if (f64.ne diff --git a/tests/compiler/logical.wast b/tests/compiler/logical.wast index a1c34c85..08617a39 100644 --- a/tests/compiler/logical.wast +++ b/tests/compiler/logical.wast @@ -11,47 +11,37 @@ (func $start (; 0 ;) (type $v) (local $0 i32) (local $1 f64) - (local $2 i64) - (local $3 f32) (drop (if (result i32) - (tee_local $0 - (i32.const 0) - ) + (i32.const 0) (unreachable) - (get_local $0) + (i32.const 0) ) ) (drop (if (result f64) (f64.ne - (tee_local $1 - (f64.const 0) - ) + (f64.const 0) (f64.const 0) ) (unreachable) - (get_local $1) + (f64.const 0) ) ) (drop (if (result i32) - (tee_local $0 - (i32.const 1) - ) - (get_local $0) + (i32.const 1) + (i32.const 1) (unreachable) ) ) (drop (if (result f64) (f64.ne - (tee_local $1 - (f64.const 1) - ) + (f64.const 1) (f64.const 0) ) - (get_local $1) + (f64.const 1) (unreachable) ) ) @@ -59,11 +49,9 @@ (if (result i32) (tee_local $0 (if (result i32) - (tee_local $0 - (i32.const 1) - ) + (i32.const 1) (i32.const 2) - (get_local $0) + (i32.const 1) ) ) (get_local $0) @@ -76,13 +64,11 @@ (tee_local $1 (if (result f64) (f64.ne - (tee_local $1 - (f64.const 1) - ) + (f64.const 1) (f64.const 0) ) (f64.const 2) - (get_local $1) + (f64.const 1) ) ) (f64.const 0) @@ -93,11 +79,9 @@ ) (set_global $logical/i (if (result i32) - (tee_local $0 - (i32.const 1) - ) + (i32.const 1) (i32.const 2) - (get_local $0) + (i32.const 1) ) ) (if @@ -111,10 +95,8 @@ ) (set_global $logical/i (if (result i32) - (tee_local $0 - (i32.const 0) - ) - (get_local $0) + (i32.const 0) + (i32.const 0) (i32.const 1) ) ) @@ -130,13 +112,11 @@ (set_global $logical/I (if (result i64) (i64.ne - (tee_local $2 - (i64.const 1) - ) + (i64.const 1) (i64.const 0) ) (i64.const 2) - (get_local $2) + (i64.const 1) ) ) (if @@ -151,12 +131,10 @@ (set_global $logical/I (if (result i64) (i64.ne - (tee_local $2 - (i64.const 0) - ) + (i64.const 0) (i64.const 0) ) - (get_local $2) + (i64.const 0) (i64.const 1) ) ) @@ -172,13 +150,11 @@ (set_global $logical/f (if (result f32) (f32.ne - (tee_local $3 - (f32.const 1) - ) + (f32.const 1) (f32.const 0) ) (f32.const 2) - (get_local $3) + (f32.const 1) ) ) (if @@ -193,12 +169,10 @@ (set_global $logical/f (if (result f32) (f32.ne - (tee_local $3 - (f32.const 0) - ) + (f32.const 0) (f32.const 0) ) - (get_local $3) + (f32.const 0) (f32.const 1) ) ) @@ -214,13 +188,11 @@ (set_global $logical/F (if (result f64) (f64.ne - (tee_local $1 - (f64.const 1) - ) + (f64.const 1) (f64.const 0) ) (f64.const 2) - (get_local $1) + (f64.const 1) ) ) (if @@ -235,12 +207,10 @@ (set_global $logical/F (if (result f64) (f64.ne - (tee_local $1 - (f64.const 0) - ) + (f64.const 0) (f64.const 0) ) - (get_local $1) + (f64.const 0) (f64.const 1) ) ) diff --git a/tests/compiler/memcpy.optimized.wast b/tests/compiler/memcpy.optimized.wast index 71a580d4..3edef66f 100644 --- a/tests/compiler/memcpy.optimized.wast +++ b/tests/compiler/memcpy.optimized.wast @@ -19,14 +19,12 @@ (loop $continue|0 (if (if (result i32) - (tee_local $1 - (get_local $2) - ) + (get_local $2) (i32.rem_u (get_local $3) (i32.const 4) ) - (get_local $1) + (get_local $2) ) (block (set_local $4 diff --git a/tests/compiler/memcpy.wast b/tests/compiler/memcpy.wast index d2520799..e5faa05e 100644 --- a/tests/compiler/memcpy.wast +++ b/tests/compiler/memcpy.wast @@ -27,14 +27,12 @@ (loop $continue|0 (if (if (result i32) - (tee_local $7 - (get_local $2) - ) + (get_local $2) (i32.rem_u (get_local $4) (i32.const 4) ) - (get_local $7) + (get_local $2) ) (block (block diff --git a/tests/compiler/std/heap.optimized.wast b/tests/compiler/std/heap.optimized.wast index d9352cc8..d9de4fb8 100644 --- a/tests/compiler/std/heap.optimized.wast +++ b/tests/compiler/std/heap.optimized.wast @@ -473,14 +473,12 @@ (loop $continue|0 (if (if (result i32) - (tee_local $3 - (get_local $2) - ) + (get_local $2) (i32.rem_u (get_local $1) (i32.const 4) ) - (get_local $3) + (get_local $2) ) (block (set_local $4 @@ -2049,7 +2047,6 @@ (get_local $0) ) (func $std:heap/Heap.compare (; 3 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (local $3 i32) (if (i32.eq (get_local $0) @@ -2062,9 +2059,7 @@ (loop $continue|0 (if (if (result i32) - (tee_local $3 - (get_local $2) - ) + (get_local $2) (i32.eq (i32.load8_u (get_local $0) @@ -2073,7 +2068,7 @@ (get_local $1) ) ) - (get_local $3) + (get_local $2) ) (block (set_local $2 diff --git a/tests/compiler/std/heap.wast b/tests/compiler/std/heap.wast index ad635d15..08132d0a 100644 --- a/tests/compiler/std/heap.wast +++ b/tests/compiler/std/heap.wast @@ -528,14 +528,12 @@ (loop $continue|0 (if (if (result i32) - (tee_local $6 - (get_local $2) - ) + (get_local $2) (i32.rem_u (get_local $1) (i32.const 4) ) - (get_local $6) + (get_local $2) ) (block (block @@ -2346,9 +2344,7 @@ (loop $continue|0 (if (if (result i32) - (tee_local $3 - (get_local $2) - ) + (get_local $2) (i32.eq (i32.load8_u (get_local $0) @@ -2357,7 +2353,7 @@ (get_local $1) ) ) - (get_local $3) + (get_local $2) ) (block (block diff --git a/tests/parser/literals.ts b/tests/parser/literals.ts index f143c24b..d5bd97ab 100644 --- a/tests/parser/literals.ts +++ b/tests/parser/literals.ts @@ -45,3 +45,8 @@ 0b0; 0b1; 0b1111111111111111111111111111111; + +"123"; +"1\"23"; +"1\"2\\3"; +"\0\n\\n\r"; diff --git a/tests/parser/literals.ts.fixture.ts b/tests/parser/literals.ts.fixture.ts index d4baa600..ecef08fb 100644 --- a/tests/parser/literals.ts.fixture.ts +++ b/tests/parser/literals.ts.fixture.ts @@ -45,3 +45,7 @@ 0; 1; 2147483647; +"123"; +"1\"23"; +"1\"2\\3"; +"\0\n\\n\r";