asm-js / validator

A reference validator for asm.js.
Apache License 2.0
1.78k stars 148 forks source link

Emscripten and spec disagree about mutability of foreign imports. #64

Closed cscott closed 10 years ago

cscott commented 11 years ago

The spec says:

A foreign import is of one of the following three forms:

var x:Identifier = foreign:Identifier.y:Identifier; var x:Identifier = foreign:Identifier.y:Identifier|0; var x:Identifier = +foreign:Identifier.y:Identifier;

The variable foreign must match the second parameter of the module declaration. The global variable x is stored in the global environment with type imm Function for the first form, imm int for the second, and imm double for the third.

The spec should probably read "mut int for the second and mut double for the third", since emscripten generates the following code (this is from https://github.com/dvander/arewefastyet/blob/9de7037324e0b5b155b761225f26f94fff5c76f5/benchmarks/asmjs-apps/box2d.js):

    var i = env.STACKTOP | 0;
    function a5(a) {
        a = a | 0;
        var b = 0;
        b = i;
        i = i + a | 0;
        i = i + 3 >> 2 << 2;
        return b | 0
    }
ghost commented 10 years ago

This has been fixed in Section 5.5.