UNPKG

earlgrey

Version:

Programming language compiling to JavaScript, featuring macros, dynamic typing annotations and pattern matching.

5 lines (2 loc) 10.5 kB
'use strict';require('earlgrey-runtime/6');let $targ$12;let $targ$13;let $0$0;let __lt____lt____colon__$0;let s$0;let varstats$0;let replaceVars$0;let eliminate_spurious_variables$0;let hoist$0;let hoistable$0;let not_hoistable$0;let hoist_helper$0;$0$0=require("./location");__lt____lt____colon__$0=getProperty($0$0,"<<:","./location");s$0=(function s(stats$0,v$0){let $targ$0;if((!Object.hasOwnProperty.call(stats$0,v$0))){$targ$0=({"assigns":0,"uses":0,"transfers":[],"replaceable":false});(stats$0[v$0]=$targ$0);(void 0);}return send(stats$0,v$0);});varstats$0=(function varstats(temp$0$0,stats$1){let t0$0;let x$0;let m$0;let m$1;let m$2;let acc$0;let temp$1;let other$0;let vars$1;let body$1;let generator$0;let vars$0;let body$0;let v$1;let v1$1;let expr$1;let v1$0;let v2$0;let $$20476$0;let $$20477$0;let $$20478$0;let $$20479$0;let $$20480$0;let $$20481$0;let $$20482$0;let $$20483$0;let $$20484$0;let t0$1;let t1$0;let t2$0;let t3$0;let t4$0;let t5$0;let expr$0;let ph$0$0;t0$0=temp$0$0;expr$0=t0$0;ph$0$0=t0$0;t0$1=ph$0$0;t1$0=t0$1.length;if((($$20478$0=(t1$0===3))&&(($$20479$0=(t0$1[0]==="assign"))&&((t2$0=t0$1[1]),(($$20481$0=Array.isArray(t2$0))&&((t3$0=t2$0.length),(($$20483$0=(t3$0===2))&&(($$20484$0=(t2$0[0]==="variable"))&&((v1$0=t2$0[1]),(t4$0=t0$1[2]),(Array.isArray(t4$0)&&((t5$0=t4$0.length),((t5$0===2)&&(t4$0[0]==="variable"))))))))))))){v2$0=t4$0[1];(s$0(stats$1,v1$0)["assigns"]=(s$0(stats$1,v1$0).assigns+1));(s$0(stats$1,v2$0)["uses"]=(s$0(stats$1,v2$0).uses+1));return s$0(stats$1,v2$0).transfers.push(v1$0);}else{if($$20484$0){v1$1=t2$0[1];expr$1=t0$1[2];(s$0(stats$1,v1$1)["assigns"]=(s$0(stats$1,v1$1).assigns+1));return varstats$0(expr$1,stats$1);}else{if(((t1$0===2)&&(t0$1[0]==="variable"))){v$1=t0$1[1];return (s$0(stats$1,v$1)["uses"]=(s$0(stats$1,v$1).uses+1));}else{if(((x$0=ph$0$0),((x$0 instanceof Array)&&(x$0[0]==="value")))){return undefined;}else{t0$1=ph$0$0;t1$0=t0$1.length;if(((t1$0===3)&&(t0$1[0]==="scope"))){vars$0=t0$1[1];body$0=t0$1[2];m$0=null;$1:for(m$0 of vars$0){let $targ$1;let v$2;let t0$2;let t1$1;t0$2=m$0;if((Array.isArray(t0$2)&&((t1$1=t0$2.length),((t1$1===2)&&(t0$2[0]==="variable"))))){v$2=t0$2[1];$targ$1=true;(s$0(stats$1,v$2)["replaceable"]=$targ$1);(void 0);}else{___match_error(m$0);}}return varstats$0(body$0,stats$1);}else{if((((t1$0>=3)&&(t1$0<=4))&&(t0$1[0]==="lambda"))){vars$1=t0$1[1];body$1=t0$1[2];if((3>=t1$0)){generator$0=null;}else{generator$0=t0$1[3];}m$1=null;$2:for(m$1 of vars$1){let v$3;let t0$3;let t1$2;t0$3=m$1;if((Array.isArray(t0$3)&&((t1$2=t0$3.length),((t1$2===2)&&(t0$3[0]==="variable"))))){v$3=t0$3[1];(s$0(stats$1,v$3)["assigns"]=(s$0(stats$1,v$3).assigns+1));}else{___match_error(m$1);}}return varstats$0(body$1,stats$1);}else{other$0=ph$0$0;acc$0=[];temp$1=null;m$2=null;$3:for(m$2 of other$0.slice(1)){let x$1;x$1=m$2;temp$1=varstats$0(x$1,stats$1);acc$0.push(temp$1);}return acc$0;}}}}}}});replaceVars$0=(function replaceVars(temp$2$0,repl$0){let t0$4;let x$2;let x$3;let m$3;let newvars$0;let m$4;let acc$1;let temp$3;let newrest$0;let other$1;let x$4;let rest$0;let vars$3;let body$3;let generator$1;let vars$2;let body$2;let v1$2;let v2$1;let v$4;let $$20646$0;let $$20647$0;let $$20648$0;let t0$5;let t1$3;let t2$1;let t3$1;let t4$1;let t5$1;let bridge$$20641$0;let expr$2;let ph$1$0;t0$4=temp$2$0;expr$2=t0$4;ph$1$0=t0$4;t0$5=ph$1$0;if((($$20647$0=Array.isArray(t0$5))&&((t1$3=t0$5.length),((t1$3===2)&&((t0$5[0]==="variable")&&((v$4=t0$5[1]),(Object.hasOwnProperty.call(repl$0,v$4)&&send(repl$0,v$4)))))))){return __lt____lt____colon__$0(["variable",send(repl$0,v$4)],expr$2);}else{if(($$20647$0&&((t1$3===3)&&((t0$5[0]==="assign")&&((t2$1=t0$5[1]),(Array.isArray(t2$1)&&((t3$1=t2$1.length),((t3$1===2)&&((t2$1[0]==="variable")&&((v1$2=t2$1[1]),(t4$1=t0$5[2]),(Array.isArray(t4$1)&&((t5$1=t4$1.length),((t5$1===2)&&((t4$1[0]==="variable")&&((v2$1=t4$1[1]),(equal(send(repl$0,v1$2),v2$1)||equal(send(repl$0,v2$1),v1$2))))))))))))))))){return __lt____lt____colon__$0(["multi"],expr$2);}else{bridge$$20641$0=ph$1$0;if((((x$2=bridge$$20641$0),((x$2 instanceof Array)&&(x$2[0]==="variable")))||((x$3=bridge$$20641$0),((x$3 instanceof Array)&&(x$3[0]==="value"))))){return expr$2;}else{t0$5=ph$1$0;t1$3=t0$5.length;if(((t1$3===3)&&(t0$5[0]==="scope"))){vars$2=t0$5[1];body$2=t0$5[2];newvars$0=[];m$3=null;$4:for(m$3 of vars$2){let _var$0;let v$5;let t0$6;let t1$4;t0$6=m$3;_var$0=t0$6;if((Array.isArray(t0$6)&&((t1$4=t0$6.length),((t1$4===2)&&(t0$6[0]==="variable"))))){v$5=t0$6[1];if(Object.hasOwnProperty.call(repl$0,v$5)){if((send(repl$0,v$5)!==false)){newvars$0.push(__lt____lt____colon__$0(["variable",send(repl$0,v$5)],_var$0));}}else{newvars$0.push(_var$0);}}else{___match_error(m$3);}}return __lt____lt____colon__$0(["scope",newvars$0,replaceVars$0(body$2,repl$0)],expr$2);}else{if((((t1$3>=3)&&(t1$3<=4))&&(t0$5[0]==="lambda"))){vars$3=t0$5[1];body$3=t0$5[2];if((3>=t1$3)){generator$1=null;}else{generator$1=t0$5[3];}return __lt____lt____colon__$0(["lambda",vars$3,replaceVars$0(body$3,repl$0),generator$1],expr$2);}else{if((t1$3>=1)){x$4=t0$5[0];rest$0=Array.prototype.slice.call(t0$5,1);acc$1=[];temp$3=null;m$4=null;$5:for(m$4 of rest$0){let elem$0;elem$0=m$4;temp$3=replaceVars$0(elem$0,repl$0);acc$1.push(temp$3);}newrest$0=acc$1;return __lt____lt____colon__$0([x$4].concat(newrest$0),expr$2);}else{other$1=ph$1$0;console.error(other$1);throw ErrorFactory(["replaceVars"]).create(("Unknown: "+String(other$1)));}}}}}}});eliminate_spurious_variables$0=(function eliminate_spurious_variables(expr$3){let m$5;let stats$2;let repl$1;stats$2=({});varstats$0(expr$3,stats$2);repl$1=({});m$5=null;$6:for(m$5 of items(stats$2)){let t0$8;let t1$6;let $targ$3;let $targ$4;let $targ$5;let $targ$6;let $targ$2;let tr$0;let st2$0;let v$6;let st$0;let t0$7;let t1$5;t0$7=m$5;if((Array.isArray(t0$7)&&((t1$5=t0$7.length),(t1$5===2)))){v$6=t0$7[0];st$0=t0$7[1];if((((equal(st$0.uses,1)&&equal(st$0.assigns,1))&&equal(st$0.transfers.length,1))&&st$0.replaceable)){$targ$2=st$0.transfers;t0$8=$targ$2;if((Array.isArray(t0$8)&&((t1$6=t0$8.length),(t1$6===1)))){tr$0=t0$8[0];}else{___match_error($targ$2,"{tr}");}st2$0=s$0(stats$2,tr$0);if((equal(st2$0.assigns,1)&&st2$0.replaceable)){$targ$3=tr$0;(repl$1[v$6]=$targ$3);$targ$4=false;(repl$1[tr$0]=$targ$4);$targ$5=false;(st$0["replaceable"]=$targ$5);$targ$6=false;(st2$0["replaceable"]=$targ$6);(void 0);}}}else{___match_error(m$5);}}return replaceVars$0(expr$3,repl$1);});hoist$0=(function hoist(expr$4){let t0$9;let t1$7;let $targ$7;let b$0;let inner$0;$targ$7=hoist_helper$0(expr$4);t0$9=$targ$7;if((Array.isArray(t0$9)&&((t1$7=t0$9.length),(t1$7===2)))){b$0=t0$9[0];inner$0=t0$9[1];}else{___match_error($targ$7,"{b, inner}");}[b$0,inner$0];return ["scope",inner$0,b$0];});hoistable$0=["send","array","object","multi","if","assign","js_break","js_continue","js_return","js_delete","js_throw","js_try","js_new","js_yield"];not_hoistable$0=["void","js_while","js_for","js_for_in","js_for_of","js_label","js_class"];hoist_helper$0=(function hoist_helper(temp$4$0){let t0$10;let x$5;let x$6;let bridge$$20900$0;let x$7;let t0$12;let t1$9;let $targ$8;let newbody$0;let inner$1;let t0$13;let t1$10;let $targ$9;let newbody$1;let inner$2;let newlambda$0;let m$6;let acc$2;let temp$5;let accum$0;let newargs$0;let m$7;let acc$3;let temp$6;let newargs$1;let other$3;let type$1;let args$1;let type$0;let args$0;let vars$5;let body$5;let generator$2;let vars$4;let body$4;let $$20906$0;let $$20907$0;let $$20908$0;let $$20909$0;let bridge$$20899$0;let t0$11;let t1$8;let expr$5;let ph$2$0;t0$10=temp$4$0;expr$5=t0$10;ph$2$0=t0$10;bridge$$20899$0=ph$2$0;if((((bridge$$20900$0=bridge$$20899$0),(((x$5=bridge$$20900$0),((x$5 instanceof Array)&&(x$5[0]==="symbol")))||((x$6=bridge$$20900$0),((x$6 instanceof Array)&&(x$6[0]==="value")))))||((x$7=bridge$$20899$0),((x$7 instanceof Array)&&(x$7[0]==="variable"))))){return [expr$5,[]];}else{t0$11=ph$2$0;t1$8=t0$11.length;if(((t1$8===3)&&(t0$11[0]==="scope"))){vars$4=t0$11[1];body$4=t0$11[2];$targ$8=hoist_helper$0(body$4);t0$12=$targ$8;if((Array.isArray(t0$12)&&((t1$9=t0$12.length),(t1$9===2)))){newbody$0=t0$12[0];inner$1=t0$12[1];}else{___match_error($targ$8,"{newbody, inner}");}[newbody$0,inner$1];return [newbody$0,inner$1.concat(vars$4)];}else{if(((t1$8===4)&&(t0$11[0]==="lambda"))){vars$5=t0$11[1];body$5=t0$11[2];generator$2=t0$11[3];$targ$9=hoist_helper$0(body$5);t0$13=$targ$9;if((Array.isArray(t0$13)&&((t1$10=t0$13.length),(t1$10===2)))){newbody$1=t0$13[0];inner$2=t0$13[1];}else{___match_error($targ$9,"{newbody, inner}");}[newbody$1,inner$2];newlambda$0=__amp____colon__(["lambda",vars$5,__lt____lt____colon__$0(["scope",inner$2,newbody$1],body$5),generator$2],({"name":expr$5.name}));return [__lt____lt____colon__$0(newlambda$0,expr$5),[]];}else{if((($$20907$0=Array.isArray(t0$11))&&((t1$8=t0$11.length),(($$20909$0=(t1$8>=1))&&((type$0=t0$11[0]),(args$0=Array.prototype.slice.call(t0$11,1)),(hoistable$0.indexOf(type$0)!==-1)))))){accum$0=[];acc$2=[];temp$5=null;m$6=null;$7:for(m$6 of args$0){let t0$14;let t1$11;let $targ$10;let b$1;let inner$3;let arg$0;arg$0=m$6;$targ$10=hoist_helper$0(arg$0);t0$14=$targ$10;if((Array.isArray(t0$14)&&((t1$11=t0$14.length),(t1$11===2)))){b$1=t0$14[0];inner$3=t0$14[1];}else{___match_error($targ$10,"{b, inner}");}[b$1,inner$3];accum$0=accum$0.concat(inner$3);temp$5=b$1;acc$2.push(temp$5);}newargs$0=acc$2;return [__lt____lt____colon__$0([type$0].concat(newargs$0),expr$5),accum$0];}else{if(($$20909$0&&((type$1=t0$11[0]),(args$1=Array.prototype.slice.call(t0$11,1)),(not_hoistable$0.indexOf(type$1)!==-1)))){acc$3=[];temp$6=null;m$7=null;$8:for(m$7 of args$1){let t0$15;let t1$12;let other$2;let t0$16;let m$8$0;let $targ$11;let b$2;let inner$4;let arg$1;arg$1=m$7;$targ$11=hoist_helper$0(arg$1);t0$15=$targ$11;if((Array.isArray(t0$15)&&((t1$12=t0$15.length),(t1$12===2)))){b$2=t0$15[0];inner$4=t0$15[1];}else{___match_error($targ$11,"{b, inner}");}[b$2,inner$4];m$8$0=inner$4;if((Array.isArray(m$8$0)&&((t0$16=m$8$0.length),(t0$16===0)))){temp$6=b$2;}else{other$2=m$8$0;temp$6=["scope",inner$4,b$2];}acc$3.push(temp$6);}newargs$1=acc$3;return [__lt____lt____colon__$0([type$1].concat(newargs$1),expr$5),[]];}else{other$3=ph$2$0;throw ErrorFactory(["syntax","illegal"]).create("Illegal node -- this should not happen.",({"node":other$3}));}}}}}});$targ$12=hoist$0;(exports["hoist"]=$targ$12);$targ$13=eliminate_spurious_variables$0;(exports["eliminate_spurious_variables"]=$targ$13);(void 0); //# sourceMappingURL=opt.js.map