diff --git a/circle.yml b/circle.yml index f6ee89045..268ce6735 100644 --- a/circle.yml +++ b/circle.yml @@ -10,10 +10,13 @@ dependencies: post: - mv ./gopherjs $HOME/bin - npm install --global node-gyp + - npm install - cd node-syscall && node-gyp rebuild && mkdir -p ~/.node_libraries/ && cp build/Release/syscall.node ~/.node_libraries/syscall.node test: override: + - PATH=node_modules/.bin:$PATH go generate github.com/gopherjs/gopherjs/compiler/prelude + - diff -u <(echo -n) <(git status --porcelain) - diff -u <(echo -n) <(gofmt -d .) - go tool vet *.go # Go package in root directory. - for d in */; do echo $d; done | grep -v tests/ | grep -v third_party/ | xargs go tool vet # All subdirectories except "tests", "third_party". diff --git a/compiler/prelude/prelude.go b/compiler/prelude/prelude.go index 8ee4ea5bf..41b592408 100644 --- a/compiler/prelude/prelude.go +++ b/compiler/prelude/prelude.go @@ -1,5 +1,7 @@ package prelude +//go:generate go run regen.go + const Prelude = prelude + numeric + types + goroutines + jsmapping const prelude = `Error.stackTraceLimit = Infinity; diff --git a/compiler/prelude/prelude_min.go b/compiler/prelude/prelude_min.go new file mode 100644 index 000000000..7d0820e17 --- /dev/null +++ b/compiler/prelude/prelude_min.go @@ -0,0 +1,6 @@ +// Code generated by regen. DO NOT EDIT. + +package prelude + +const Minified = `Error.stackTraceLimit=Infinity;var $global,$module;if(typeof window!=="undefined"){$global=window}else if(typeof self!=="undefined"){$global=self}else if(typeof global!=="undefined"){$global=global;$global.require=require}else{$global=this}if($global===undefined||$global.Array===undefined){throw new Error("no global object found")}if(typeof module!=="undefined"){$module=module}var $packages={},$idCounter=0;var $keys=function(m){return m?Object.keys(m):[]};var $flushConsole=function(){};var $throwRuntimeError;var $throwNilPointerError=function(){$throwRuntimeError("invalid memory address or nil pointer dereference")};var $call=function(fn,rcvr,args){return fn.apply(rcvr,args)};var $makeFunc=function(fn){return function(){return $externalize(fn(this,new($sliceType($jsObjectPtr))($global.Array.prototype.slice.call(arguments,[]))),$emptyInterface)}};var $unused=function(v){};var $mapArray=function(array,f){var newArray=new array.constructor(array.length);for(var i=0;islice.$capacity||max>slice.$capacity){$throwRuntimeError("slice bounds out of range")}var s=new slice.constructor(slice.$array);s.$offset=slice.$offset+low;s.$length=slice.$length-low;s.$capacity=slice.$capacity-low;if(high!==undefined){s.$length=high-low}if(max!==undefined){s.$capacity=max-low}return s};var $substring=function(str,low,high){if(low<0||highstr.length){$throwRuntimeError("slice bounds out of range")}return str.substring(low,high)};var $sliceToArray=function(slice){if(slice.$array.constructor!==Array){return slice.$array.subarray(slice.$offset,slice.$offset+slice.$length)}return slice.$array.slice(slice.$offset,slice.$offset+slice.$length)};var $decodeRune=function(str,pos){var c0=str.charCodeAt(pos);if(c0<128){return[c0,1]}if(c0!==c0||c0<192){return[65533,1]}var c1=str.charCodeAt(pos+1);if(c1!==c1||c1<128||192<=c1){return[65533,1]}if(c0<224){var r=(c0&31)<<6|c1&63;if(r<=127){return[65533,1]}return[r,2]}var c2=str.charCodeAt(pos+2);if(c2!==c2||c2<128||192<=c2){return[65533,1]}if(c0<240){var r=(c0&15)<<12|(c1&63)<<6|c2&63;if(r<=2047){return[65533,1]}if(55296<=r&&r<=57343){return[65533,1]}return[r,3]}var c3=str.charCodeAt(pos+3);if(c3!==c3||c3<128||192<=c3){return[65533,1]}if(c0<248){var r=(c0&7)<<18|(c1&63)<<12|(c2&63)<<6|c3&63;if(r<=65535||11141111114111||55296<=r&&r<=57343){r=65533}if(r<=127){return String.fromCharCode(r)}if(r<=2047){return String.fromCharCode(192|r>>6,128|r&63)}if(r<=65535){return String.fromCharCode(224|r>>12,128|r>>6&63,128|r&63)}return String.fromCharCode(240|r>>18,128|r>>12&63,128|r>>6&63,128|r&63)};var $stringToBytes=function(str){var array=new Uint8Array(str.length);for(var i=0;isrcOffset){for(var i=n-1;i>=0;i--){elem.copy(dst[dstOffset+i],src[srcOffset+i])}return}for(var i=0;isrcOffset){for(var i=n-1;i>=0;i--){dst[dstOffset+i]=src[srcOffset+i]}return}for(var i=0;inewCapacity){newOffset=0;newCapacity=Math.max(newLength,slice.$capacity<1024?slice.$capacity*2:Math.floor(slice.$capacity*5/4));if(slice.$array.constructor===Array){newArray=slice.$array.slice(slice.$offset,slice.$offset+slice.$length);newArray.length=newCapacity;var zero=slice.constructor.elem.zero;for(var i=slice.$length;i>>16&65535;var al=a&65535;var bh=b>>>16&65535;var bl=b&65535;return al*bl+(ah*bl+al*bh<<16>>>0)>>0};var $floatKey=function(f){if(f!==f){$idCounter++;return"NaN$"+$idCounter}return String(f)};var $flatten64=function(x){return x.$high*4294967296+x.$low};var $shiftLeft64=function(x,y){if(y===0){return x}if(y<32){return new x.constructor(x.$high<>>32-y,x.$low<>>0)}if(y<64){return new x.constructor(x.$low<>y,(x.$low>>>y|x.$high<<32-y)>>>0)}if(y<64){return new x.constructor(x.$high>>31,x.$high>>y-32>>>0)}if(x.$high<0){return new x.constructor(-1,4294967295)}return new x.constructor(0,0)};var $shiftRightUint64=function(x,y){if(y===0){return x}if(y<32){return new x.constructor(x.$high>>>y,(x.$low>>>y|x.$high<<32-y)>>>0)}if(y<64){return new x.constructor(0,x.$high>>>y-32)}return new x.constructor(0,0)};var $mul64=function(x,y){var high=0,low=0;if((y.$low&1)!==0){high=x.$high;low=x.$low}for(var i=1;i<32;i++){if((y.$low&1<>>32-i;low+=x.$low<>>0}}for(var i=0;i<32;i++){if((y.$high&1<yHigh||xHigh===yHigh&&xLow>yLow)){yHigh=(yHigh<<1|yLow>>>31)>>>0;yLow=yLow<<1>>>0;n++}for(var i=0;i<=n;i++){high=high<<1|low>>>31;low=low<<1>>>0;if(xHigh>yHigh||xHigh===yHigh&&xLow>=yLow){xHigh=xHigh-yHigh;xLow=xLow-yLow;if(xLow<0){xHigh--;xLow+=4294967296}low++;if(low===4294967296){high++;low=0}}yLow=(yLow>>>1|yHigh<<32-1)>>>0;yHigh=yHigh>>>1}if(returnRemainder){return new x.constructor(xHigh*rs,xLow*rs)}return new x.constructor(high*s,low*s)};var $divComplex=function(n,d){var ninf=n.$real===Infinity||n.$real===-Infinity||n.$imag===Infinity||n.$imag===-Infinity;var dinf=d.$real===Infinity||d.$real===-Infinity||d.$imag===Infinity||d.$imag===-Infinity;var nnan=!ninf&&(n.$real!==n.$real||n.$imag!==n.$imag);var dnan=!dinf&&(d.$real!==d.$real||d.$imag!==d.$imag);if(nnan||dnan){return new n.constructor(NaN,NaN)}if(ninf&&!dinf){return new n.constructor(Infinity,Infinity)}if(!ninf&&dinf){return new n.constructor(0,0)}if(d.$real===0&&d.$imag===0){if(n.$real===0&&n.$imag===0){return new n.constructor(NaN,NaN)}return new n.constructor(Infinity,Infinity)}var a=Math.abs(d.$real);var b=Math.abs(d.$imag);if(a<=b){var ratio=d.$real/d.$imag;var denom=d.$real*ratio+d.$imag;return new n.constructor((n.$real*ratio+n.$imag)/denom,(n.$imag*ratio-n.$real)/denom)}var ratio=d.$imag/d.$real;var denom=d.$imag*ratio+d.$real;return new n.constructor((n.$imag*ratio+n.$real)/denom,(n.$imag-n.$real*ratio)/denom)};var $kindBool=1;var $kindInt=2;var $kindInt8=3;var $kindInt16=4;var $kindInt32=5;var $kindInt64=6;var $kindUint=7;var $kindUint8=8;var $kindUint16=9;var $kindUint32=10;var $kindUint64=11;var $kindUintptr=12;var $kindFloat32=13;var $kindFloat64=14;var $kindComplex64=15;var $kindComplex128=16;var $kindArray=17;var $kindChan=18;var $kindFunc=19;var $kindInterface=20;var $kindMap=21;var $kindPtr=22;var $kindSlice=23;var $kindString=24;var $kindStruct=25;var $kindUnsafePointer=26;var $methodSynthesizers=[];var $addMethodSynthesizer=function(f){if($methodSynthesizers===null){f();return}$methodSynthesizers.push(f)};var $synthesizeMethods=function(){$methodSynthesizers.forEach(function(f){f()});$methodSynthesizers=null};var $ifaceKeyFor=function(x){if(x===$ifaceNil){return"nil"}var c=x.constructor;return c.string+"$"+c.keyFor(x.$val)};var $identity=function(x){return x};var $typeIDCounter=0;var $idKey=function(x){if(x.$id===undefined){$idCounter++;x.$id=$idCounter}return String(x.$id)};var $newType=function(size,kind,string,named,pkg,exported,constructor){var typ;switch(kind){case $kindBool:case $kindInt:case $kindInt8:case $kindInt16:case $kindInt32:case $kindUint:case $kindUint8:case $kindUint16:case $kindUint32:case $kindUintptr:case $kindUnsafePointer:typ=function(v){this.$val=v};typ.wrapped=true;typ.keyFor=$identity;break;case $kindString:typ=function(v){this.$val=v};typ.wrapped=true;typ.keyFor=function(x){return"$"+x};break;case $kindFloat32:case $kindFloat64:typ=function(v){this.$val=v};typ.wrapped=true;typ.keyFor=function(x){return $floatKey(x)};break;case $kindInt64:typ=function(high,low){this.$high=high+Math.floor(Math.ceil(low)/4294967296)>>0;this.$low=low>>>0;this.$val=this};typ.keyFor=function(x){return x.$high+"$"+x.$low};break;case $kindUint64:typ=function(high,low){this.$high=high+Math.floor(Math.ceil(low)/4294967296)>>>0;this.$low=low>>>0;this.$val=this};typ.keyFor=function(x){return x.$high+"$"+x.$low};break;case $kindComplex64:typ=function(real,imag){this.$real=$fround(real);this.$imag=$fround(imag);this.$val=this};typ.keyFor=function(x){return x.$real+"$"+x.$imag};break;case $kindComplex128:typ=function(real,imag){this.$real=real;this.$imag=imag;this.$val=this};typ.keyFor=function(x){return x.$real+"$"+x.$imag};break;case $kindArray:typ=function(v){this.$val=v};typ.wrapped=true;typ.ptr=$newType(4,$kindPtr,"*"+string,false,"",false,function(array){this.$get=function(){return array};this.$set=function(v){typ.copy(this,v)};this.$val=array});typ.init=function(elem,len){typ.elem=elem;typ.len=len;typ.comparable=elem.comparable;typ.keyFor=function(x){return Array.prototype.join.call($mapArray(x,function(e){return String(elem.keyFor(e)).replace(/\\/g,"\\\\").replace(/\$/g,"\\$")}),"$")};typ.copy=function(dst,src){$copyArray(dst,src,0,0,src.length,elem)};typ.ptr.init(typ);Object.defineProperty(typ.ptr.nil,"nilCheck",{get:$throwNilPointerError})};break;case $kindChan:typ=function(v){this.$val=v};typ.wrapped=true;typ.keyFor=$idKey;typ.init=function(elem,sendOnly,recvOnly){typ.elem=elem;typ.sendOnly=sendOnly;typ.recvOnly=recvOnly};break;case $kindFunc:typ=function(v){this.$val=v};typ.wrapped=true;typ.init=function(params,results,variadic){typ.params=params;typ.results=results;typ.variadic=variadic;typ.comparable=false};break;case $kindInterface:typ={implementedBy:{},missingMethodFor:{}};typ.keyFor=$ifaceKeyFor;typ.init=function(methods){typ.methods=methods;methods.forEach(function(m){$ifaceNil[m.prop]=$throwNilPointerError})};break;case $kindMap:typ=function(v){this.$val=v};typ.wrapped=true;typ.init=function(key,elem){typ.key=key;typ.elem=elem;typ.comparable=false};break;case $kindPtr:typ=constructor||function(getter,setter,target){this.$get=getter;this.$set=setter;this.$target=target;this.$val=this};typ.keyFor=$idKey;typ.init=function(elem){typ.elem=elem;typ.wrapped=elem.kind===$kindArray;typ.nil=new typ($throwNilPointerError,$throwNilPointerError)};break;case $kindSlice:typ=function(array){if(array.constructor!==typ.nativeArray){array=new typ.nativeArray(array)}this.$array=array;this.$offset=0;this.$length=array.length;this.$capacity=array.length;this.$val=this};typ.init=function(elem){typ.elem=elem;typ.comparable=false;typ.nativeArray=$nativeArray(elem.kind);typ.nil=new typ([])};break;case $kindStruct:typ=function(v){this.$val=v};typ.wrapped=true;typ.ptr=$newType(4,$kindPtr,"*"+string,false,pkg,exported,constructor);typ.ptr.elem=typ;typ.ptr.prototype.$get=function(){return this};typ.ptr.prototype.$set=function(v){typ.copy(this,v)};typ.init=function(pkgPath,fields){typ.pkgPath=pkgPath;typ.fields=fields;fields.forEach(function(f){if(!f.typ.comparable){typ.comparable=false}});typ.keyFor=function(x){var val=x.$val;return $mapArray(fields,function(f){return String(f.typ.keyFor(val[f.prop])).replace(/\\/g,"\\\\").replace(/\$/g,"\\$")}).join("$")};typ.copy=function(dst,src){for(var i=0;i0){var next=[];var mset=[];current.forEach(function(e){if(seen[e.typ.string]){return}seen[e.typ.string]=true;if(e.typ.named){mset=mset.concat(e.typ.methods);if(e.indirect){mset=mset.concat($ptrType(e.typ).methods)}}switch(e.typ.kind){case $kindStruct:e.typ.fields.forEach(function(f){if(f.anonymous){var fTyp=f.typ;var fIsPtr=fTyp.kind===$kindPtr;next.push({typ:fIsPtr?fTyp.elem:fTyp,indirect:e.indirect||fIsPtr})}});break;case $kindInterface:mset=mset.concat(e.typ.methods);break}});mset.forEach(function(m){if(base[m.name]===undefined){base[m.name]=m}});current=next}typ.methodSetCache=[];Object.keys(base).sort().forEach(function(name){typ.methodSetCache.push(base[name])});return typ.methodSetCache};var $Bool=$newType(1,$kindBool,"bool",true,"",false,null);var $Int=$newType(4,$kindInt,"int",true,"",false,null);var $Int8=$newType(1,$kindInt8,"int8",true,"",false,null);var $Int16=$newType(2,$kindInt16,"int16",true,"",false,null);var $Int32=$newType(4,$kindInt32,"int32",true,"",false,null);var $Int64=$newType(8,$kindInt64,"int64",true,"",false,null);var $Uint=$newType(4,$kindUint,"uint",true,"",false,null);var $Uint8=$newType(1,$kindUint8,"uint8",true,"",false,null);var $Uint16=$newType(2,$kindUint16,"uint16",true,"",false,null);var $Uint32=$newType(4,$kindUint32,"uint32",true,"",false,null);var $Uint64=$newType(8,$kindUint64,"uint64",true,"",false,null);var $Uintptr=$newType(4,$kindUintptr,"uintptr",true,"",false,null);var $Float32=$newType(4,$kindFloat32,"float32",true,"",false,null);var $Float64=$newType(8,$kindFloat64,"float64",true,"",false,null);var $Complex64=$newType(8,$kindComplex64,"complex64",true,"",false,null);var $Complex128=$newType(16,$kindComplex128,"complex128",true,"",false,null);var $String=$newType(8,$kindString,"string",true,"",false,null);var $UnsafePointer=$newType(4,$kindUnsafePointer,"unsafe.Pointer",true,"",false,null);var $nativeArray=function(elemKind){switch(elemKind){case $kindInt:return Int32Array;case $kindInt8:return Int8Array;case $kindInt16:return Int16Array;case $kindInt32:return Int32Array;case $kindUint:return Uint32Array;case $kindUint8:return Uint8Array;case $kindUint16:return Uint16Array;case $kindUint32:return Uint32Array;case $kindUintptr:return Uint32Array;case $kindFloat32:return Float32Array;case $kindFloat64:return Float64Array;default:return Array}};var $toNativeArray=function(elemKind,array){var nativeArray=$nativeArray(elemKind);if(nativeArray===Array){return array}return new nativeArray(array)};var $arrayTypes={};var $arrayType=function(elem,len){var typeKey=elem.id+"$"+len;var typ=$arrayTypes[typeKey];if(typ===undefined){typ=$newType(12,$kindArray,"["+len+"]"+elem.string,false,"",false,null);$arrayTypes[typeKey]=typ;typ.init(elem,len)}return typ};var $chanType=function(elem,sendOnly,recvOnly){var string=(recvOnly?"<-":"")+"chan"+(sendOnly?"<- ":" ")+elem.string;var field=sendOnly?"SendChan":recvOnly?"RecvChan":"Chan";var typ=elem[field];if(typ===undefined){typ=$newType(4,$kindChan,string,false,"",false,null);elem[field]=typ;typ.init(elem,sendOnly,recvOnly)}return typ};var $Chan=function(elem,capacity){if(capacity<0||capacity>2147483647){$throwRuntimeError("makechan: size out of range")}this.$elem=elem;this.$capacity=capacity;this.$buffer=[];this.$sendQueue=[];this.$recvQueue=[];this.$closed=false};var $chanNil=new $Chan(null,0);$chanNil.$sendQueue=$chanNil.$recvQueue={length:0,push:function(){},shift:function(){return undefined},indexOf:function(){return-1}};var $funcTypes={};var $funcType=function(params,results,variadic){var typeKey=$mapArray(params,function(p){return p.id}).join(",")+"$"+$mapArray(results,function(r){return r.id}).join(",")+"$"+variadic;var typ=$funcTypes[typeKey];if(typ===undefined){var paramTypes=$mapArray(params,function(p){return p.string});if(variadic){paramTypes[paramTypes.length-1]="..."+paramTypes[paramTypes.length-1].substr(2)}var string="func("+paramTypes.join(", ")+")";if(results.length===1){string+=" "+results[0].string}else if(results.length>1){string+=" ("+$mapArray(results,function(r){return r.string}).join(", ")+")"}typ=$newType(4,$kindFunc,string,false,"",false,null);$funcTypes[typeKey]=typ;typ.init(params,results,variadic)}return typ};var $interfaceTypes={};var $interfaceType=function(methods){var typeKey=$mapArray(methods,function(m){return m.pkg+","+m.name+","+m.typ.id}).join("$");var typ=$interfaceTypes[typeKey];if(typ===undefined){var string="interface {}";if(methods.length!==0){string="interface { "+$mapArray(methods,function(m){return(m.pkg!==""?m.pkg+".":"")+m.name+m.typ.string.substr(4)}).join("; ")+" }"}typ=$newType(8,$kindInterface,string,false,"",false,null);$interfaceTypes[typeKey]=typ;typ.init(methods)}return typ};var $emptyInterface=$interfaceType([]);var $ifaceNil={};var $error=$newType(8,$kindInterface,"error",true,"",false,null);$error.init([{prop:"Error",name:"Error",pkg:"",typ:$funcType([],[$String],false)}]);var $mapTypes={};var $mapType=function(key,elem){var typeKey=key.id+"$"+elem.id;var typ=$mapTypes[typeKey];if(typ===undefined){typ=$newType(4,$kindMap,"map["+key.string+"]"+elem.string,false,"",false,null);$mapTypes[typeKey]=typ;typ.init(key,elem)}return typ};var $makeMap=function(keyForFunc,entries){var m={};for(var i=0;i2147483647){$throwRuntimeError("makeslice: len out of range")}if(capacity<0||capacity2147483647){$throwRuntimeError("makeslice: cap out of range")}var array=new typ.nativeArray(capacity);if(typ.nativeArray===Array){for(var i=0;i=$curGoroutine.deferStack.length){throw jsErr}if(jsErr!==null){var newErr=null;try{$curGoroutine.deferStack.push(deferred);$panic(new $jsErrorPtr(jsErr))}catch(err){newErr=err}$curGoroutine.deferStack.pop();$callDeferred(deferred,newErr);return}if($curGoroutine.asleep){return}$stackDepthOffset--;var outerPanicStackDepth=$panicStackDepth;var outerPanicValue=$panicValue;var localPanicValue=$curGoroutine.panicStack.pop();if(localPanicValue!==undefined){$panicStackDepth=$getStackDepth();$panicValue=localPanicValue}try{while(true){if(deferred===null){deferred=$curGoroutine.deferStack[$curGoroutine.deferStack.length-1];if(deferred===undefined){$panicStackDepth=null;if(localPanicValue.Object instanceof Error){throw localPanicValue.Object}var msg;if(localPanicValue.constructor===$String){msg=localPanicValue.$val}else if(localPanicValue.Error!==undefined){msg=localPanicValue.Error()}else if(localPanicValue.String!==undefined){msg=localPanicValue.String()}else{msg=localPanicValue}throw new Error(msg)}}var call=deferred.pop();if(call===undefined){$curGoroutine.deferStack.pop();if(localPanicValue!==undefined){deferred=null;continue}return}var r=call[0].apply(call[2],call[1]);if(r&&r.$blk!==undefined){deferred.push([r.$blk,[],r]);if(fromPanic){throw null}return}if(localPanicValue!==undefined&&$panicStackDepth===null){throw null}}}finally{if(localPanicValue!==undefined){if($panicStackDepth!==null){$curGoroutine.panicStack.push(localPanicValue)}$panicStackDepth=outerPanicStackDepth;$panicValue=outerPanicValue}$stackDepthOffset++}};var $panic=function(value){$curGoroutine.panicStack.push(value);$callDeferred(null,null,true)};var $recover=function(){if($panicStackDepth===null||$panicStackDepth!==undefined&&$panicStackDepth!==$getStackDepth()-2){return $ifaceNil}$panicStackDepth=null;return $panicValue};var $throw=function(err){throw err};var $noGoroutine={asleep:false,exit:false,deferStack:[],panicStack:[]};var $curGoroutine=$noGoroutine,$totalGoroutines=0,$awakeGoroutines=0,$checkForDeadlock=true;var $mainFinished=false;var $go=function(fun,args){$totalGoroutines++;$awakeGoroutines++;var $goroutine=function(){try{$curGoroutine=$goroutine;var r=fun.apply(undefined,args);if(r&&r.$blk!==undefined){fun=function(){return r.$blk()};args=[];return}$goroutine.exit=true}catch(err){if(!$goroutine.exit){throw err}}finally{$curGoroutine=$noGoroutine;if($goroutine.exit){$totalGoroutines--;$goroutine.asleep=true}if($goroutine.asleep){$awakeGoroutines--;if(!$mainFinished&&$awakeGoroutines===0&&$checkForDeadlock){console.error("fatal error: all goroutines are asleep - deadlock!");if($global.process!==undefined){$global.process.exit(2)}}}}};$goroutine.asleep=false;$goroutine.exit=false;$goroutine.deferStack=[];$goroutine.panicStack=[];$schedule($goroutine)};var $scheduled=[];var $runScheduled=function(){try{var r;while((r=$scheduled.shift())!==undefined){r()}}finally{if($scheduled.length>0){setTimeout($runScheduled,0)}}};var $schedule=function(goroutine){if(goroutine.asleep){goroutine.asleep=false;$awakeGoroutines++}$scheduled.push(goroutine);if($curGoroutine===$noGoroutine){$runScheduled()}};var $setTimeout=function(f,t){$awakeGoroutines++;return setTimeout(function(){$awakeGoroutines--;f()},t)};var $block=function(){if($curGoroutine===$noGoroutine){$throwRuntimeError("cannot block in JavaScript callback, fix by wrapping code in goroutine")}$curGoroutine.asleep=true};var $send=function(chan,value){if(chan.$closed){$throwRuntimeError("send on closed channel")}var queuedRecv=chan.$recvQueue.shift();if(queuedRecv!==undefined){queuedRecv([value,true]);return}if(chan.$buffer.length65535){var h=Math.floor((c-65536)/1024)+55296;var l=(c-65536)%1024+56320;s+=String.fromCharCode(h,l);continue}s+=String.fromCharCode(c)}return s;case $kindStruct:var timePkg=$packages["time"];if(timePkg!==undefined&&v.constructor===timePkg.Time.ptr){var milli=$div64(v.UnixNano(),new $Int64(0,1e6));return new Date($flatten64(milli))}var noJsObject={};var searchJsObject=function(v,t){if(t===$jsObjectPtr){return v}switch(t.kind){case $kindPtr:if(v===t.nil){return noJsObject}return searchJsObject(v.$get(),t.elem);case $kindStruct:var f=t.fields[0];return searchJsObject(v[f.prop],f.typ);case $kindInterface:return searchJsObject(v.$val,v.constructor);default:return noJsObject}};var o=searchJsObject(v,t);if(o!==noJsObject){return o}o={};for(var i=0;i>24;case $kindInt16:return parseInt(v)<<16>>16;case $kindInt32:return parseInt(v)>>0;case $kindUint:return parseInt(v);case $kindUint8:return parseInt(v)<<24>>>24;case $kindUint16:return parseInt(v)<<16>>>16;case $kindUint32:case $kindUintptr:return parseInt(v)>>>0;case $kindInt64:case $kindUint64:return new t(0,v);case $kindFloat32:case $kindFloat64:return parseFloat(v);case $kindArray:if(v.length!==t.len){$throwRuntimeError("got array with wrong size from JavaScript native")}return $mapArray(v,function(e){return $internalize(e,t.elem)});case $kindFunc:return function(){var args=[];for(var i=0;i=128){return false}}return true}; +` diff --git a/compiler/prelude/regen.go b/compiler/prelude/regen.go new file mode 100644 index 000000000..af0fda38b --- /dev/null +++ b/compiler/prelude/regen.go @@ -0,0 +1,34 @@ +// +build ignore + +package main + +import ( + "io/ioutil" + "log" + "os" + "os/exec" + "strings" + + "github.com/gopherjs/gopherjs/compiler/prelude" +) + +func main() { + cmd := exec.Command("uglifyjs") + cmd.Stdin = strings.NewReader(prelude.Prelude) + + out, err := cmd.CombinedOutput() + if err != nil { + log.Fatalf("uglifyjs: %v\n%s", err, out) + os.Exit(1) + } + + err = ioutil.WriteFile("prelude_min.go", []byte(`// Code generated by regen. DO NOT EDIT. + +package prelude + +const Minified = `+"`"+string(out)+"`\n"), 0644) + + if err != nil { + log.Fatal(err) + } +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 000000000..7b2b25883 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,32 @@ +{ + "name": "gopherjs", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "uglify-es": { + "version": "3.3.9", + "resolved": "https://registry.npmjs.org/uglify-es/-/uglify-es-3.3.9.tgz", + "integrity": "sha512-r+MU0rfv4L/0eeW3xZrd16t4NZfK8Ld4SWVglYBb7ez5uXFWHuVRs6xCTrf1yirs9a4j4Y27nn7SRfO6v67XsQ==", + "dev": true, + "requires": { + "commander": "2.13.0", + "source-map": "0.6.1" + }, + "dependencies": { + "commander": { + "version": "2.13.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.13.0.tgz", + "integrity": "sha512-MVuS359B+YzaWqjCL/c+22gfryv+mCBPHAv3zyVI2GN8EY6IRP8VwtasXn8jyyhvvq84R4ImN1OKRtcbIasjYA==", + "dev": true + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + } + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 000000000..e4730d0cb --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "name": "gopherjs", + "devDependencies": { + "uglify-es": "^3.3.9" + } +}