Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

163 Commits

Repository files navigation

asm.js

A Mozilla Research project to specify and develop the extremely optimizable subset of JS targeted by compilers like Emscripten, Mandreel, and LLJS.

Discussion of the asm.js spec now takes place on Specifiction here.

The spec repo hosts the source for the current asm.js Working Draft.

This repo hosts JS source code which performs asm.js validation, however as of this update, this code is not up to date with the latest working draft and is not extensively tested. Patches to update it or fix bugs are welcome though.

Example

functionmymodule(stdlib,foreign,heap){"use asm";// -------------------------------------------------------------------------// SECTION 1: globalsvarH32=newstdlib.Int32Array(heap);varHU32=newstdlib.Uint32Array(heap);varlog=foreign.consoleDotLog;varg_i=0;// int globalvarg_f=0.0;// double global// -------------------------------------------------------------------------// SECTION 2: functionsfunctionf(x,y){// SECTION A: parameter type declarationsx=x|0;// int parametery=+y;// double parameter// SECTION B: function bodylog(x|0);// call into FFI -- must force the signlog(y);// call into FFI -- already know it's a doublex=(x+3)|0;// signed addition// SECTION C: unconditional returnreturn((((x+1)|0)>>>0)/(x>>>0))|0;// compound expression}functiong(){g_f=+(g_i|0);// read/write globalsreturn;}functiong2(){return;}functionh(i,x){i=i|0;x=x|0;H32[i>>2]=x;// shifted by log2(byte count)ftable_2[(x-2)&1]();// dynamic call of functions in table 2// no return necessary when return type is void}// -------------------------------------------------------------------------// SECTION 3: function tablesvarftable_1=[f];varftable_2=[g,g2];// all of the same type// -------------------------------------------------------------------------// SECTION 4: exportsreturn{f_export: f,goop: g};}

License

Apache 2.0.

About

A reference validator for asm.js.

Resources

Stars

1.8k stars

Watchers

138 watching

Forks

Releases

Packages

Used by

Contributors

Languages