Open ghost opened 9 years ago
Update:
According to the current errata (https://etherpad.mozilla.org/ibPVJ81u35), Math.imul
actually takes intish
arguments, so the aforementioned naive solution is adequate. Moreover, it will continue to work when Math.clz32
is added to the standard library, because its return type is fixnum
.
Sections 6.2 and 6.3 of the specification respectively state the following conditions for valid export statements and valid function tables:
(There are two additional conditions for valid function tables that are not relevant here.)
The former condition is not sufficient to ensure that a valid export statement only refers to (asm.js) function definitions. Similarly, the latter condition is not sufficient to ensure that a valid function table only refers to function definitions. (It is also missing an
imm
classifier.) In both cases, the types of several standard library functions match the required shape, includingMath.acos
: (double?
) →double
andMath.imul
: (int
,int
) →signed
.OdinMonkey's validator does not fall into this trap, correctly rejecting modules such as:
and
Note that in both cases Δ(
f
) unifies withimm
(σ,...) → τ.Unfortunately, it does not seem adequate to insist that each argument type σ,... is
int
,double
, orfloat
, and that the return type τ issigned
,double
,float
, orvoid
. Although this includes every valid function definition type (see sections 5.1 and 5.2), it still fails to exclude every standard library function type. Namely, that ofMath.imul
.One possibility is to introduce more contextual information into global type assumptions, by augmenting the (im)mutability classifier μ ::=
mut
|imm
(see section 3.1) as follows:where
in
indicates an internal (asm.js) function definition andext
an external (imported) function.