Use the element type annotated on the setter when doing indexed sets

This commit is contained in:
dcodeIO 2018-04-23 16:17:33 +02:00
parent 78a3dcfaf0
commit 88b00c1689
7 changed files with 1499 additions and 2258 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -39,7 +39,7 @@ function asmFunc(global, env, buffer) {
} }
return 0 | 0; return 0 | 0;
} }
function $lib_internal_arraybuffer_allocUnsafe($0) { function $lib_internal_arraybuffer_allocUnsafe($0) {
$0 = $0 | 0; $0 = $0 | 0;
var $1 = 0; var $1 = 0;
@ -48,7 +48,7 @@ function asmFunc(global, env, buffer) {
HEAP32[$1 >> 2] = $0; HEAP32[$1 >> 2] = $0;
return $1 | 0; return $1 | 0;
} }
function $lib_array_Array_Body__constructor($0, $1) { function $lib_array_Array_Body__constructor($0, $1) {
$0 = $0 | 0; $0 = $0 | 0;
$1 = $1 | 0; $1 = $1 | 0;
@ -68,7 +68,7 @@ function asmFunc(global, env, buffer) {
HEAP32[($0 + 4 | 0) >> 2] = $1; HEAP32[($0 + 4 | 0) >> 2] = $1;
return $0 | 0; return $0 | 0;
} }
function assembly_index_Body_constructor($0, $1, $2, $3, $4, $5, $6, $7) { function assembly_index_Body_constructor($0, $1, $2, $3, $4, $5, $6, $7) {
$0 = $0 | 0; $0 = $0 | 0;
$1 = +$1; $1 = +$1;
@ -92,7 +92,7 @@ function asmFunc(global, env, buffer) {
} }
return $9 | 0; return $9 | 0;
} }
function $lib_memory_set_memory($0, $1, $2) { function $lib_memory_set_memory($0, $1, $2) {
$0 = $0 | 0; $0 = $0 | 0;
$1 = $1 | 0; $1 = $1 | 0;
@ -176,7 +176,7 @@ function asmFunc(global, env, buffer) {
break continue_0; break continue_0;
} while (1); } while (1);
} }
function $lib_memory_copy_memory($0, $1, $2) { function $lib_memory_copy_memory($0, $1, $2) {
$0 = $0 | 0; $0 = $0 | 0;
$1 = $1 | 0; $1 = $1 | 0;
@ -545,7 +545,7 @@ function asmFunc(global, env, buffer) {
HEAP8[$44 >> 0] = HEAPU8[$3 >> 0] | 0; HEAP8[$44 >> 0] = HEAPU8[$3 >> 0] | 0;
} }
} }
function $lib_memory_move_memory($0, $1, $2) { function $lib_memory_move_memory($0, $1, $2) {
$0 = $0 | 0; $0 = $0 | 0;
$1 = $1 | 0; $1 = $1 | 0;
@ -638,7 +638,7 @@ function asmFunc(global, env, buffer) {
} while (1); } while (1);
} }
} }
function $lib_internal_arraybuffer_reallocUnsafe($0, $1) { function $lib_internal_arraybuffer_reallocUnsafe($0, $1) {
$0 = $0 | 0; $0 = $0 | 0;
$1 = $1 | 0; $1 = $1 | 0;
@ -658,7 +658,7 @@ function asmFunc(global, env, buffer) {
} else if (($1 | 0) < ($2 | 0)) HEAP32[$0 >> 2] = $1;; } else if (($1 | 0) < ($2 | 0)) HEAP32[$0 >> 2] = $1;;
return $0 | 0; return $0 | 0;
} }
function $lib_array_Array_Body__push($0, $1) { function $lib_array_Array_Body__push($0, $1) {
$0 = $0 | 0; $0 = $0 | 0;
$1 = $1 | 0; $1 = $1 | 0;
@ -678,7 +678,7 @@ function asmFunc(global, env, buffer) {
HEAP32[(($4 + ($2 << 2 | 0) | 0) + 8 | 0) >> 2] = $1; HEAP32[(($4 + ($2 << 2 | 0) | 0) + 8 | 0) >> 2] = $1;
return $3 | 0; return $3 | 0;
} }
function $lib_array_Array_Body____get($0, $1) { function $lib_array_Array_Body____get($0, $1) {
$0 = $0 | 0; $0 = $0 | 0;
$1 = $1 | 0; $1 = $1 | 0;
@ -690,7 +690,7 @@ function asmFunc(global, env, buffer) {
} }
return HEAPU32[(($2 + ($1 << 2 | 0) | 0) + 8 | 0) >> 2] | 0 | 0; return HEAPU32[(($2 + ($1 << 2 | 0) | 0) + 8 | 0) >> 2] | 0 | 0;
} }
function assembly_index_NBodySystem_constructor($0, $1) { function assembly_index_NBodySystem_constructor($0, $1) {
$0 = $0 | 0; $0 = $0 | 0;
$1 = $1 | 0; $1 = $1 | 0;
@ -722,7 +722,7 @@ function asmFunc(global, env, buffer) {
HEAPF64[($1 + 40 | 0) >> 3] = -$7 / 39.47841760435743; HEAPF64[($1 + 40 | 0) >> 3] = -$7 / 39.47841760435743;
return $0 | 0; return $0 | 0;
} }
function assembly_index_init() { function assembly_index_init() {
var $0 = 0; var $0 = 0;
$argc = 0; $argc = 0;
@ -749,7 +749,7 @@ function asmFunc(global, env, buffer) {
$lib_array_Array_Body__push($0 | 0, assembly_index_Body_constructor(0 | 0, +(15.379697114850917), +(-25.919314609987964), +(.17925877295037118), +(.979090732243898), +(.5946989986476762), +(-.034755955504078104), +(2.0336868699246304e-03)) | 0 | 0) | 0; $lib_array_Array_Body__push($0 | 0, assembly_index_Body_constructor(0 | 0, +(15.379697114850917), +(-25.919314609987964), +(.17925877295037118), +(.979090732243898), +(.5946989986476762), +(-.034755955504078104), +(2.0336868699246304e-03)) | 0 | 0) | 0;
assembly_index_system = assembly_index_NBodySystem_constructor(0 | 0, $0 | 0) | 0; assembly_index_system = assembly_index_NBodySystem_constructor(0 | 0, $0 | 0) | 0;
} }
function assembly_index_getBody($0) { function assembly_index_getBody($0) {
$0 = $0 | 0; $0 = $0 | 0;
var $1 = 0, $2 = 0; var $1 = 0, $2 = 0;
@ -757,7 +757,7 @@ function asmFunc(global, env, buffer) {
if ($0 >>> 0 < (HEAP32[($1 + 4 | 0) >> 2] | 0) >>> 0) $2 = $lib_array_Array_Body____get($1 | 0, $0 | 0) | 0; else $2 = 0; if ($0 >>> 0 < (HEAP32[($1 + 4 | 0) >> 2] | 0) >>> 0) $2 = $lib_array_Array_Body____get($1 | 0, $0 | 0) | 0; else $2 = 0;
return $2 | 0; return $2 | 0;
} }
function assembly_index_NBodySystem_advance($0, $1) { function assembly_index_NBodySystem_advance($0, $1) {
$0 = $0 | 0; $0 = $0 | 0;
$1 = +$1; $1 = +$1;
@ -810,7 +810,7 @@ function asmFunc(global, env, buffer) {
break continue_0; break continue_0;
} while (1); } while (1);
} }
function assembly_index_NBodySystem_energy($0) { function assembly_index_NBodySystem_energy($0) {
$0 = $0 | 0; $0 = $0 | 0;
var $1 = 0.0, $2 = 0, $3 = 0, $4 = 0, $5 = 0, $10 = 0.0, $6 = 0.0, $7 = 0.0, $8 = 0.0, $9 = 0.0, $11 = 0.0, $12 = 0.0, $13 = 0.0, $14 = 0.0, $15 = 0.0; var $1 = 0.0, $2 = 0, $3 = 0, $4 = 0, $5 = 0, $10 = 0.0, $6 = 0.0, $7 = 0.0, $8 = 0.0, $9 = 0.0, $11 = 0.0, $12 = 0.0, $13 = 0.0, $14 = 0.0, $15 = 0.0;
@ -853,12 +853,12 @@ function asmFunc(global, env, buffer) {
} while (1); } while (1);
return +$1; return +$1;
} }
function assembly_index_step() { function assembly_index_step() {
assembly_index_NBodySystem_advance(assembly_index_system | 0, +(.01)); assembly_index_NBodySystem_advance(assembly_index_system | 0, +(.01));
return +(+assembly_index_NBodySystem_energy(assembly_index_system | 0)); return +(+assembly_index_NBodySystem_energy(assembly_index_system | 0));
} }
function assembly_index_bench($0) { function assembly_index_bench($0) {
$0 = $0 | 0; $0 = $0 | 0;
var $1 = 0; var $1 = 0;
@ -871,19 +871,19 @@ function asmFunc(global, env, buffer) {
break continue_0; break continue_0;
} while (1); } while (1);
} }
function start() { function start() {
$lib_allocator_arena_startOffset = (HEAP_BASE + 7 | 0) & 4294967288 | 0; $lib_allocator_arena_startOffset = (HEAP_BASE + 7 | 0) & 4294967288 | 0;
$lib_allocator_arena_offset = $lib_allocator_arena_startOffset; $lib_allocator_arena_offset = $lib_allocator_arena_startOffset;
} }
function __wasm_ctz_i32(x) { function __wasm_ctz_i32(x) {
x = x | 0; x = x | 0;
var $1 = 0; var $1 = 0;
if ((x | 0) == (0 | 0)) $1 = 32; else $1 = 31 - Math_clz32(x ^ (x - 1 | 0) | 0) | 0; if ((x | 0) == (0 | 0)) $1 = 32; else $1 = 31 - Math_clz32(x ^ (x - 1 | 0) | 0) | 0;
return $1 | 0; return $1 | 0;
} }
function __wasm_popcnt_i32(x) { function __wasm_popcnt_i32(x) {
x = x | 0; x = x | 0;
var count = 0, $2 = 0; var count = 0, $2 = 0;
@ -900,19 +900,19 @@ function asmFunc(global, env, buffer) {
}; };
return $2 | 0; return $2 | 0;
} }
function __wasm_rotl_i32(x, k) { function __wasm_rotl_i32(x, k) {
x = x | 0; x = x | 0;
k = k | 0; k = k | 0;
return ((4294967295 >>> (k & 31 | 0) | 0) & x | 0) << (k & 31 | 0) | 0 | (((4294967295 << (32 - (k & 31 | 0) | 0) | 0) & x | 0) >>> (32 - (k & 31 | 0) | 0) | 0) | 0 | 0; return ((4294967295 >>> (k & 31 | 0) | 0) & x | 0) << (k & 31 | 0) | 0 | (((4294967295 << (32 - (k & 31 | 0) | 0) | 0) & x | 0) >>> (32 - (k & 31 | 0) | 0) | 0) | 0 | 0;
} }
function __wasm_rotr_i32(x, k) { function __wasm_rotr_i32(x, k) {
x = x | 0; x = x | 0;
k = k | 0; k = k | 0;
return ((4294967295 << (k & 31 | 0) | 0) & x | 0) >>> (k & 31 | 0) | 0 | (((4294967295 >>> (32 - (k & 31 | 0) | 0) | 0) & x | 0) << (32 - (k & 31 | 0) | 0) | 0) | 0 | 0; return ((4294967295 << (k & 31 | 0) | 0) & x | 0) >>> (k & 31 | 0) | 0 | (((4294967295 >>> (32 - (k & 31 | 0) | 0) | 0) & x | 0) << (32 - (k & 31 | 0) | 0) | 0) | 0 | 0;
} }
function __wasm_grow_memory(pagesToAdd) { function __wasm_grow_memory(pagesToAdd) {
pagesToAdd = pagesToAdd | 0; pagesToAdd = pagesToAdd | 0;
var oldPages = __wasm_current_memory() | 0; var oldPages = __wasm_current_memory() | 0;
@ -933,25 +933,25 @@ function asmFunc(global, env, buffer) {
} }
return oldPages; return oldPages;
} }
function __wasm_current_memory() { function __wasm_current_memory() {
return buffer.byteLength / 65536 | 0; return buffer.byteLength / 65536 | 0;
} }
return { return {
init: assembly_index_init, init: assembly_index_init,
getBody: assembly_index_getBody, getBody: assembly_index_getBody,
step: assembly_index_step, step: assembly_index_step,
bench: assembly_index_bench, bench: assembly_index_bench,
memory: Object.create(Object.prototype, { memory: Object.create(Object.prototype, {
grow: { grow: {
value: __wasm_grow_memory value: __wasm_grow_memory
}, },
buffer: { buffer: {
get: function () { get: function () {
return buffer; return buffer;
} }
} }
}) })
}; };

File diff suppressed because it is too large Load Diff

View File

@ -4,9 +4,11 @@
"private": true, "private": true,
"scripts": { "scripts": {
"asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --sourceMap --validate", "asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --sourceMap --validate",
"asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -a build/optimized.asm.js -O3 --validate --noDebug --noAssert", "asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -O3 --validate --noDebug --noAssert",
"asbuild": "npm run asbuild:untouched && npm run asbuild:optimized", "asbuild:asmjs": "asc assembly/index.ts -a build/index.asm.js -O3 --validate --noDebug --noAssert",
"asbuild": "npm run asbuild:untouched && npm run asbuild:optimized && npm run asbuild:asmjs",
"tsbuild": "tsc -p assembly -t ES2017 -m commonjs --outDir build", "tsbuild": "tsc -p assembly -t ES2017 -m commonjs --outDir build",
"build": "npm run asbuild && npm run tsbuild",
"server": "http-server . -o -c-1", "server": "http-server . -o -c-1",
"test": "node tests" "test": "node tests"
}, },

View File

@ -4,7 +4,7 @@ const fs = require("fs");
const nbodyWASM = require("../index.js"); const nbodyWASM = require("../index.js");
// Load ASMJS version // Load ASMJS version
src = fs.readFileSync(__dirname + "/../build/optimized.asm.js", "utf8"); src = fs.readFileSync(__dirname + "/../build/index.asm.js", "utf8");
if (src.indexOf("var Math_sqrt =") < 0) { // currently missing in asm.js output if (src.indexOf("var Math_sqrt =") < 0) { // currently missing in asm.js output
let p = src.indexOf(" var abort = env.abort;"); let p = src.indexOf(" var abort = env.abort;");
src = src.substring(0, p) + " var Math_sqrt = global.Math.sqrt;\n " + src.substring(p); src = src.substring(0, p) + " var Math_sqrt = global.Math.sqrt;\n " + src.substring(p);

View File

@ -4281,15 +4281,24 @@ export class Compiler extends DiagnosticEmitter {
} }
case ElementKind.CLASS: { case ElementKind.CLASS: {
if (program.resolvedElementExpression) { // indexed access if (program.resolvedElementExpression) { // indexed access
let indexedGet = (<Class>target).lookupOverload(OperatorKind.INDEXED_GET); let indexedSet = (<Class>target).lookupOverload(OperatorKind.INDEXED_SET);
if (!indexedGet) { if (!indexedSet) {
this.error( let indexedGet = (<Class>target).lookupOverload(OperatorKind.INDEXED_GET);
DiagnosticCode.Index_signature_is_missing_in_type_0, if (!indexedGet) {
expression.range, (<Class>target).internalName this.error(
); DiagnosticCode.Index_signature_is_missing_in_type_0,
expression.range, (<Class>target).internalName
);
} else {
this.error(
DiagnosticCode.Index_signature_in_type_0_only_permits_reading,
expression.range, (<Class>target).internalName
);
}
return this.module.createUnreachable(); return this.module.createUnreachable();
} }
elementType = indexedGet.signature.returnType; assert(indexedSet.signature.parameterTypes.length == 2); // parser must guarantee this
elementType = indexedSet.signature.parameterTypes[1]; // 2nd parameter is the element
break; break;
} }
// fall-through // fall-through