asm.js是一个底层、格外为JavaScript子集优化的编译器。这是Mozilla研究项目,类似Emscripten,Mandreel,和LLJS.
示例代码:
functionmymodule(global,foreign,buffer){"useasm";//-------------------------------------------------------------------------//SECTION1:importsvarH32=newglobal.Int32Array(buffer);varHU32=newglobal.Uint32Array(buffer);varlog=foreign.consoleDotLog;//-------------------------------------------------------------------------//SECTION2:functionsfunctionf(x,y,z,w){//SECTIONA:parametertypedeclarationsx=x|0;//intparametery=+y;//doubleparameter//SECTIONB:functionbodylog(x|0);//callintoFFI--mustforcethesignlog(y);//callintoFFI--alreadyknowit'sadoublex=(x+3)|0;//signedaddition//SECTIONC:unconditionalreturnreturn((((x+1)|0)>>>0)/(x|0))>>>0;//compoundexpression}functiong(){g_f=+g_i;//read/writeglobalsreturn;}functiong2(){return;}functionh(i,x){i=i|0;x=x|0;H32[(i&0xffffffff)>>4]=x;//maskedby2^k-1,shiftedbybytecountftable_2[(x-2)&2]();//dynamiccalloffunctionsintable2}//-------------------------------------------------------------------------//SECTION3:functiontablesvarftable_1=[f];varftable_2=[g,g2];//allofthesametype//-------------------------------------------------------------------------//SECTION4:globalsvarg_i=0;//intglobalvarg_f=0.0;//doubleglobal//-------------------------------------------------------------------------//SECTION5:exportsreturn{f_export:f,goop:g};}
评论