diff --git a/examples/tlsf/assembly/tlsf.ts b/examples/tlsf/assembly/tlsf.ts index 691841c3..4a3a6a71 100644 --- a/examples/tlsf/assembly/tlsf.ts +++ b/examples/tlsf/assembly/tlsf.ts @@ -326,8 +326,9 @@ class Control extends BlockHeader { // Empty lists point here, indicating free if (this.blocks(fl, sl) == block) { this.blocks_set(fl, sl, next); if (next == this) { - this.sl_bitmap_set(fl, this.sl_bitmap(fl) & ~(1 << sl)); - if (!this.sl_bitmap(fl)) { + var sl_bitmap = this.sl_bitmap(fl) & ~(1 << sl); + this.sl_bitmap_set(fl, sl_bitmap); + if (!sl_bitmap) { this.fl_bitmap &= ~(1 << fl); } } diff --git a/package-lock.json b/package-lock.json index 923af15a..ee51b985 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.8" + "@types/node": "8.5.9" } }, "@types/long": { @@ -55,9 +55,9 @@ "dev": true }, "@types/node": { - "version": "8.5.8", - "resolved": "https://registry.npmjs.org/@types/node/-/node-8.5.8.tgz", - "integrity": "sha512-8KmlRxwbKZfjUHFIt3q8TF5S2B+/E5BaAoo/3mgc5h6FJzqxXkCK/VMetO+IRDtwtU6HUvovHMBn+XRj7SV9Qg==", + "version": "8.5.9", + "resolved": "https://registry.npmjs.org/@types/node/-/node-8.5.9.tgz", + "integrity": "sha512-s+c3AjymyAccTI4hcgNFK4mToH8l+hyPDhu4LIkn71lRy56FLijGu00fyLgldjM/846Pmk9N4KFUs2P8GDs0pA==", "dev": true }, "@types/strip-bom": { @@ -274,9 +274,9 @@ "dev": true }, "binaryen": { - "version": "42.0.0", - "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-42.0.0.tgz", - "integrity": "sha512-1JkYPfxkkjkTrG1QekDeMyNdwbA/RIvlkpio+BJ41po9X6d7qZnlQHM/CNVhgXCtmGzlw2hbkAyYxEfnE001vw==" + "version": "42.0.0-nightly.20180120", + "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-42.0.0-nightly.20180120.tgz", + "integrity": "sha512-QDdxO1AARASXt9jvPHCxpZogm/5CrrmKpAktiwkqJUFZPNl0DRY5dlmOS9nleASLm1h7PxF4otIIwFI6GVmtAQ==" }, "bn.js": { "version": "4.11.8", @@ -2028,9 +2028,9 @@ "dev": true }, "source-map-support": { - "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==", + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.2.tgz", + "integrity": "sha512-9zHceZbQwERaMK1MiFguvx1dL9GQPLXInr2D/wUxAsuV6ZKc9F0DHYWeloMcalkYRbtanwqUakoDjvj55cL/4A==", "dev": true, "requires": { "source-map": "0.6.1" @@ -2208,7 +2208,7 @@ "make-error": "1.3.2", "minimist": "1.2.0", "mkdirp": "0.5.1", - "source-map-support": "0.5.0", + "source-map-support": "0.5.2", "tsconfig": "7.0.0", "v8flags": "3.0.1", "yn": "2.0.0" diff --git a/package.json b/package.json index 7e5ba40c..51fa40cd 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "url": "https://github.com/AssemblyScript/assemblyscript/issues" }, "dependencies": { - "binaryen": "42.0.0", + "binaryen": "42.0.0-nightly.20180120", "glob": "^7.1.2", "minimist": "^1.2.0" }, @@ -21,11 +21,11 @@ "@types/glob": "^5.0.34", "@types/long": "^3.0.32", "@types/minimist": "^1.2.0", - "@types/node": "^8.5.8", + "@types/node": "^8.5.9", "chalk": "^2.3.0", "diff": "^3.4.0", "long": "^3.2.0", - "source-map-support": "^0.5.0", + "source-map-support": "^0.5.2", "ts-loader": "^3.2.0", "ts-node": "^4.1.0", "tslint": "^5.9.1", diff --git a/src/builtins.ts b/src/builtins.ts index dce7b473..0e5d4aa1 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -38,7 +38,8 @@ import { FunctionPrototype, Local, ElementFlags, - Class + Class, + ElementKind } from "./program"; /** Initializes the specified program with built-in constants and functions. */ @@ -1826,24 +1827,27 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty return module.createUnreachable(); } -/** Compiles an allocation of the specified class. */ +/** Compiles a memory allocation for an instance of the specified class. */ export function compileAllocate(compiler: Compiler, cls: Class, reportNode: Node): ExpressionRef { var program = cls.program; var prototype = program.elements.get(compiler.options.allocateImpl); if (prototype) { - var instance = (prototype).resolve(); // reports - if (instance) { - var usizeType = program.target == Target.WASM64 ? Type.usize64 : Type.usize32; - if (!instance.is(ElementFlags.GENERIC) && instance.returnType == usizeType && instance.parameters.length == 1 && instance.parameters[0].type == usizeType) { - if (compiler.compileFunction(instance)) // reports - return compiler.makeCall(instance, [ - program.target == Target.WASM64 - ? compiler.module.createI64(cls.currentMemoryOffset) - : compiler.module.createI32(cls.currentMemoryOffset) - ]); - } else - program.error(DiagnosticCode.Implementation_0_must_match_the_signature_1, reportNode.range, compiler.options.allocateImpl, "(size: usize): usize"); - } + if (prototype.kind == ElementKind.FUNCTION_PROTOTYPE) { + var instance = (prototype).resolve(); // reports + if (instance) { + var usizeType = program.target == Target.WASM64 ? Type.usize64 : Type.usize32; + if (!instance.is(ElementFlags.GENERIC) && instance.returnType == usizeType && instance.parameters.length == 1 && instance.parameters[0].type == usizeType) { + if (compiler.compileFunction(instance)) // reports + return compiler.makeCall(instance, [ + program.target == Target.WASM64 + ? compiler.module.createI64(cls.currentMemoryOffset) + : compiler.module.createI32(cls.currentMemoryOffset) + ]); + } else + program.error(DiagnosticCode.Implementation_0_must_match_the_signature_1, reportNode.range, compiler.options.allocateImpl, "(size: usize): usize"); + } + } else + program.error(DiagnosticCode.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures, reportNode.range, prototype.internalName); } else program.error(DiagnosticCode.Cannot_find_name_0, reportNode.range, compiler.options.allocateImpl); return compiler.module.createUnreachable(); diff --git a/tests/compiler/fmod.optimized.wast b/tests/compiler/fmod.optimized.wast index bc61939a..e7a81965 100644 --- a/tests/compiler/fmod.optimized.wast +++ b/tests/compiler/fmod.optimized.wast @@ -175,12 +175,9 @@ (i64.shl (get_local $2) (i64.extend_u/i32 - (i32.add - (i32.sub - (i32.const 0) - (get_local $3) - ) + (i32.sub (i32.const 1) + (get_local $3) ) ) ) @@ -232,12 +229,9 @@ (i64.shl (get_local $5) (i64.extend_u/i32 - (i32.add - (i32.sub - (i32.const 0) - (get_local $6) - ) + (i32.sub (i32.const 1) + (get_local $6) ) ) ) @@ -358,12 +352,9 @@ (i64.shr_u (get_local $2) (i64.extend_u/i32 - (i32.add - (i32.sub - (i32.const 0) - (get_local $3) - ) + (i32.sub (i32.const 1) + (get_local $3) ) ) ) @@ -548,12 +539,9 @@ ) (i32.shl (get_local $2) - (i32.add - (i32.sub - (i32.const 0) - (get_local $4) - ) + (i32.sub (i32.const 1) + (get_local $4) ) ) ) @@ -603,12 +591,9 @@ ) (i32.shl (get_local $5) - (i32.add - (i32.sub - (i32.const 0) - (get_local $6) - ) + (i32.sub (i32.const 1) + (get_local $6) ) ) ) @@ -725,12 +710,9 @@ ) (i32.shr_u (get_local $2) - (i32.add - (i32.sub - (i32.const 0) - (get_local $4) - ) + (i32.sub (i32.const 1) + (get_local $4) ) ) (i32.gt_s diff --git a/tests/compiler/showcase.optimized.wast b/tests/compiler/showcase.optimized.wast index 0e18b1e9..1a7a7cf4 100644 --- a/tests/compiler/showcase.optimized.wast +++ b/tests/compiler/showcase.optimized.wast @@ -1800,12 +1800,9 @@ (i64.shl (get_local $2) (i64.extend_u/i32 - (i32.add - (i32.sub - (i32.const 0) - (get_local $3) - ) + (i32.sub (i32.const 1) + (get_local $3) ) ) ) @@ -1857,12 +1854,9 @@ (i64.shl (get_local $5) (i64.extend_u/i32 - (i32.add - (i32.sub - (i32.const 0) - (get_local $6) - ) + (i32.sub (i32.const 1) + (get_local $6) ) ) ) @@ -1983,12 +1977,9 @@ (i64.shr_u (get_local $2) (i64.extend_u/i32 - (i32.add - (i32.sub - (i32.const 0) - (get_local $3) - ) + (i32.sub (i32.const 1) + (get_local $3) ) ) ) @@ -2173,12 +2164,9 @@ ) (i32.shl (get_local $2) - (i32.add - (i32.sub - (i32.const 0) - (get_local $4) - ) + (i32.sub (i32.const 1) + (get_local $4) ) ) ) @@ -2228,12 +2216,9 @@ ) (i32.shl (get_local $5) - (i32.add - (i32.sub - (i32.const 0) - (get_local $6) - ) + (i32.sub (i32.const 1) + (get_local $6) ) ) ) @@ -2350,12 +2335,9 @@ ) (i32.shr_u (get_local $2) - (i32.add - (i32.sub - (i32.const 0) - (get_local $4) - ) + (i32.sub (i32.const 1) + (get_local $4) ) ) (i32.gt_s