Skip to content

Commit 1f3bb61

Browse files
committed
Fix issues with more than 64 locals, see AssemblyScript#99
1 parent 2a7f409 commit 1f3bb61

9 files changed

Lines changed: 1451 additions & 18 deletions

File tree

dist/asc.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/asc.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assemblyscript.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assemblyscript.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,8 +2008,10 @@ export class Compiler extends DiagnosticEmitter {
20082008
}
20092009
if (initExpr) {
20102010
initializers.push(this.compileAssignmentWithValue(declaration.name, initExpr));
2011-
flow.setLocalWrapped(local.index, !flow.canOverflow(initExpr, type));
2012-
} else {
2011+
if (local.type.is(TypeFlags.SHORT | TypeFlags.INTEGER)) {
2012+
flow.setLocalWrapped(local.index, !flow.canOverflow(initExpr, type));
2013+
}
2014+
} else if (local.type.is(TypeFlags.SHORT | TypeFlags.INTEGER)) {
20132015
flow.setLocalWrapped(local.index, true); // zero
20142016
}
20152017
}
@@ -4418,7 +4420,9 @@ export class Compiler extends DiagnosticEmitter {
44184420
return module.createUnreachable();
44194421
}
44204422
let flow = this.currentFunction.flow;
4421-
flow.setLocalWrapped((<Local>target).index, !flow.canOverflow(valueWithCorrectType, type));
4423+
if (type.is(TypeFlags.SHORT | TypeFlags.INTEGER)) {
4424+
flow.setLocalWrapped((<Local>target).index, !flow.canOverflow(valueWithCorrectType, type));
4425+
}
44224426
return tee
44234427
? module.createTeeLocal((<Local>target).index, valueWithCorrectType)
44244428
: module.createSetLocal((<Local>target).index, valueWithCorrectType);

src/program.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2898,7 +2898,7 @@ export class Function extends Element {
28982898
private tempF64s: Local[] | null = null;
28992899

29002900
/** Gets a free temporary local of the specified type. */
2901-
getTempLocal(type: Type, wrapped: bool): Local {
2901+
getTempLocal(type: Type, wrapped: bool = false): Local {
29022902
var temps: Local[] | null;
29032903
switch (type.toNativeType()) {
29042904
case NativeType.I32: {
@@ -2926,7 +2926,9 @@ export class Function extends Element {
29262926
} else {
29272927
local = this.addLocal(type);
29282928
}
2929-
this.flow.setLocalWrapped(local.index, wrapped);
2929+
if (type.is(TypeFlags.SHORT | TypeFlags.INTEGER)) {
2930+
this.flow.setLocalWrapped(local.index, wrapped);
2931+
}
29302932
return local;
29312933
}
29322934

@@ -2989,7 +2991,9 @@ export class Function extends Element {
29892991
local = this.addLocal(type);
29902992
temps.push(local);
29912993
}
2992-
this.flow.setLocalWrapped(local.index, wrapped);
2994+
if (type.is(TypeFlags.SHORT | TypeFlags.INTEGER)) {
2995+
this.flow.setLocalWrapped(local.index, wrapped);
2996+
}
29932997
return local;
29942998
}
29952999

@@ -3701,7 +3705,9 @@ export class Flow {
37013705
}
37023706
}
37033707
this.scopedLocals.set(name, scopedLocal);
3704-
this.setLocalWrapped(scopedLocal.index, wrapped);
3708+
if (type.is(TypeFlags.SHORT | TypeFlags.INTEGER)) {
3709+
this.setLocalWrapped(scopedLocal.index, wrapped);
3710+
}
37053711
return scopedLocal;
37063712
}
37073713

@@ -3775,17 +3781,20 @@ export class Flow {
37753781
/** Sets if the local with the specified index is considered wrapped. */
37763782
setLocalWrapped(index: i32, wrapped: bool): void {
37773783
var map: I64;
3778-
var i: i32 = -1;
3784+
var off: i32 = -1;
37793785
if (index < 64) {
37803786
if (index < 0) return; // inlined constant
37813787
map = this.wrappedLocals;
37823788
} else {
37833789
let ext = this.wrappedLocalsExt;
3784-
i = ((index - 64) / 64) | 0;
3785-
if (!ext) ext = new Array(i + 1);
3786-
else while (ext.length <= i) ext.push(i64_new(0));
3787-
map = ext[i];
3788-
index -= (i + 1) * 64;
3790+
off = ((index - 64) / 64) | 0;
3791+
if (!ext) {
3792+
this.wrappedLocalsExt = ext = new Array(off + 1);
3793+
ext.length = 0;
3794+
}
3795+
while (ext.length <= off) ext.push(i64_new(0));
3796+
map = ext[off];
3797+
index -= (off + 1) * 64;
37893798
}
37903799
map = wrapped
37913800
? i64_or(
@@ -3804,7 +3813,7 @@ export class Flow {
38043813
)
38053814
)
38063815
);
3807-
if (i >= 0) (<I64[]>this.wrappedLocalsExt)[i] = map;
3816+
if (off >= 0) (<I64[]>this.wrappedLocalsExt)[off] = map;
38083817
else this.wrappedLocals = map;
38093818
}
38103819

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
(module
2+
(type $ii (func (param i32) (result i32)))
3+
(type $iiiiv (func (param i32 i32 i32 i32)))
4+
(type $v (func))
5+
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
6+
(memory $0 1)
7+
(data (i32.const 4) "\0e\00\00\00m\00a\00n\00y\00-\00l\00o\00c\00a\00l\00s\00.\00t\00s")
8+
(export "testI32" (func $many-locals/testI32))
9+
(export "testI8" (func $many-locals/testI8))
10+
(export "memory" (memory $0))
11+
(start $start)
12+
(func $many-locals/testI32 (; 1 ;) (type $ii) (param $0 i32) (result i32)
13+
(get_local $0)
14+
)
15+
(func $many-locals/testI8 (; 2 ;) (type $ii) (param $0 i32) (result i32)
16+
(i32.shr_s
17+
(i32.shl
18+
(get_local $0)
19+
(i32.const 24)
20+
)
21+
(i32.const 24)
22+
)
23+
)
24+
(func $start (; 3 ;) (type $v)
25+
(if
26+
(i32.ne
27+
(call $many-locals/testI32
28+
(i32.const 42)
29+
)
30+
(i32.const 42)
31+
)
32+
(block
33+
(call $abort
34+
(i32.const 0)
35+
(i32.const 4)
36+
(i32.const 133)
37+
(i32.const 0)
38+
)
39+
(unreachable)
40+
)
41+
)
42+
(if
43+
(i32.ne
44+
(call $many-locals/testI8
45+
(i32.const 42)
46+
)
47+
(i32.const 42)
48+
)
49+
(block
50+
(call $abort
51+
(i32.const 0)
52+
(i32.const 4)
53+
(i32.const 267)
54+
(i32.const 0)
55+
)
56+
(unreachable)
57+
)
58+
)
59+
)
60+
)

0 commit comments

Comments
 (0)