From 5efcc52cfde434d9475e2bcb228ca88bf9290613 Mon Sep 17 00:00:00 2001 From: Dave Brophy Date: Sun, 25 Feb 2018 08:42:41 +0100 Subject: [PATCH 1/3] Minify prelude --- compiler/compiler.go | 8 +++++++- compiler/prelude/goroutines.go | 1 + compiler/prelude/jsmapping.go | 1 + compiler/prelude/numeric.go | 1 + compiler/prelude/prelude.go | 2 ++ compiler/prelude/types.go | 1 + 6 files changed, 13 insertions(+), 1 deletion(-) diff --git a/compiler/compiler.go b/compiler/compiler.go index d82f2d466..356fcfde1 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -154,7 +154,13 @@ func WriteProgramCode(pkgs []*Archive, w *SourceMapFilter) error { if _, err := w.Write([]byte("\"use strict\";\n(function() {\n\n")); err != nil { return err } - if _, err := w.Write(removeWhitespace([]byte(prelude.Prelude), minify)); err != nil { + var preludeString string + if minify { + preludeString = prelude.PreludeMinified + } else { + preludeString = prelude.Prelude + } + if _, err := w.Write([]byte(preludeString)); err != nil { return err } if _, err := w.Write([]byte("\n")); err != nil { diff --git a/compiler/prelude/goroutines.go b/compiler/prelude/goroutines.go index d9780b65d..f54413fe7 100644 --- a/compiler/prelude/goroutines.go +++ b/compiler/prelude/goroutines.go @@ -1,5 +1,6 @@ package prelude +const goroutinesMinified = `var $panicValue,$stackDepthOffset=0,$getStackDepth=function(){var e=new Error;if(void 0!==e.stack)return $stackDepthOffset+e.stack.split("\n").length},$panicStackDepth=null,$callDeferred=function(e,r,n){if(!n&&null!==e&&e.index>=$curGoroutine.deferStack.length)throw r;if(null!==r){var t=null;try{$curGoroutine.deferStack.push(e),$panic(new $jsErrorPtr(r))}catch(e){t=e}return $curGoroutine.deferStack.pop(),void $callDeferred(e,t)}if(!$curGoroutine.asleep){$stackDepthOffset--;var o=$panicStackDepth,c=$panicValue,u=$curGoroutine.panicStack.pop();void 0!==u&&($panicStackDepth=$getStackDepth(),$panicValue=u);try{for(;;){if(null===e&&void 0===(e=$curGoroutine.deferStack[$curGoroutine.deferStack.length-1])){if($panicStackDepth=null,u.Object instanceof Error)throw u.Object;var i;throw i=u.constructor===$String?u.$val:void 0!==u.Error?u.Error():void 0!==u.String?u.String():u,new Error(i)}var a=e.pop();if(void 0===a){if($curGoroutine.deferStack.pop(),void 0!==u){e=null;continue}return}var l=a[0].apply(a[2],a[1]);if(l&&void 0!==l.$blk){if(e.push([l.$blk,[],l]),n)throw null;return}if(void 0!==u&&null===$panicStackDepth)throw null}}finally{void 0!==u&&(null!==$panicStackDepth&&$curGoroutine.panicStack.push(u),$panicStackDepth=o,$panicValue=c),$stackDepthOffset++}}},$panic=function(e){$curGoroutine.panicStack.push(e),$callDeferred(null,null,!0)},$recover=function(){return null===$panicStackDepth||void 0!==$panicStackDepth&&$panicStackDepth!==$getStackDepth()-2?$ifaceNil:($panicStackDepth=null,$panicValue)},$throw=function(e){throw e},$noGoroutine={asleep:!1,exit:!1,deferStack:[],panicStack:[]},$curGoroutine=$noGoroutine,$totalGoroutines=0,$awakeGoroutines=0,$checkForDeadlock=!0,$mainFinished=!1,$go=function(e,r){$totalGoroutines++,$awakeGoroutines++;var n=function(){try{$curGoroutine=n;var t=e.apply(void 0,r);if(t&&void 0!==t.$blk)return e=function(){return t.$blk()},void(r=[]);n.exit=!0}catch(e){if(!n.exit)throw e}finally{$curGoroutine=$noGoroutine,n.exit&&($totalGoroutines--,n.asleep=!0),n.asleep&&($awakeGoroutines--,!$mainFinished&&0===$awakeGoroutines&&$checkForDeadlock&&(console.error("fatal error: all goroutines are asleep - deadlock!"),void 0!==$global.process&&$global.process.exit(2)))}};n.asleep=!1,n.exit=!1,n.deferStack=[],n.panicStack=[],$schedule(n)},$scheduled=[],$runScheduled=function(){try{for(var e;void 0!==(e=$scheduled.shift());)e()}finally{$scheduled.length>0&&setTimeout($runScheduled,0)}},$schedule=function(e){e.asleep&&(e.asleep=!1,$awakeGoroutines++),$scheduled.push(e),$curGoroutine===$noGoroutine&&$runScheduled()},$setTimeout=function(e,r){return $awakeGoroutines++,setTimeout(function(){$awakeGoroutines--,e()},r)},$block=function(){$curGoroutine===$noGoroutine&&$throwRuntimeError("cannot block in JavaScript callback, fix by wrapping code in goroutine"),$curGoroutine.asleep=!0},$send=function(e,r){e.$closed&&$throwRuntimeError("send on closed channel");var n=e.$recvQueue.shift();if(void 0===n){if(!(e.$buffer.length65535){var l=Math.floor(($-65536)/1024)+55296,u=($-65536)%1024+56320;c+=String.fromCharCode(l,u)}else c+=String.fromCharCode($)}return c;case $kindStruct:var o=$packages.time;if(void 0!==o&&e.constructor===o.Time.ptr){var d=$div64(e.UnixNano(),new $Int64(0,1e6));return new Date($flatten64(d))}var k={},f=function(e,r){if(r===$jsObjectPtr)return e;switch(r.kind){case $kindPtr:return e===r.nil?k:f(e.$get(),r.elem);case $kindStruct:var n=r.fields[0];return f(e[n.prop],n.typ);case $kindInterface:return f(e.$val,e.constructor);default:return k}},p=f(e,r);if(p!==k)return p;p={};for(a=0;a>24;case $kindInt16:return parseInt(e)<<16>>16;case $kindInt32:return parseInt(e)>>0;case $kindUint:return parseInt(e);case $kindUint8:return parseInt(e)<<24>>>24;case $kindUint16:return parseInt(e)<<16>>>16;case $kindUint32:case $kindUintptr:return parseInt(e)>>>0;case $kindInt64:case $kindUint64:return new r(0,e);case $kindFloat32:case $kindFloat64:return parseFloat(e);case $kindArray:return e.length!==r.len&&$throwRuntimeError("got array with wrong size from JavaScript native"),$mapArray(e,function(e){return $internalize(e,r.elem)});case $kindFunc:return function(){for(var t=[],a=0;a=128)return!1;return!0};` const jsmapping = ` var $jsObjectPtr, $jsErrorPtr; diff --git a/compiler/prelude/numeric.go b/compiler/prelude/numeric.go index 063d09f46..bdd6ce206 100644 --- a/compiler/prelude/numeric.go +++ b/compiler/prelude/numeric.go @@ -1,5 +1,6 @@ package prelude +const numericMinified = `var $min=Math.min,$mod=function(r,n){return r%n},$parseInt=parseInt,$parseFloat=function(r){return null!=r&&r.constructor===Number?r:parseFloat(r)},$froundBuf=new Float32Array(1),$fround=Math.fround||function(r){return $froundBuf[0]=r,$froundBuf[0]},$imul=Math.imul||function(r,n){var t=65535&r,$=65535&n;return t*$+((r>>>16&65535)*$+t*(n>>>16&65535)<<16>>>0)>>0},$floatKey=function(r){return r!=r?($idCounter++,"NaN$"+$idCounter):String(r)},$flatten64=function(r){return 4294967296*r.$high+r.$low},$shiftLeft64=function(r,n){return 0===n?r:n<32?new r.constructor(r.$high<>>32-n,r.$low<>>0):n<64?new r.constructor(r.$low<>n,(r.$low>>>n|r.$high<<32-n)>>>0):n<64?new r.constructor(r.$high>>31,r.$high>>n-32>>>0):r.$high<0?new r.constructor(-1,4294967295):new r.constructor(0,0)},$shiftRightUint64=function(r,n){return 0===n?r:n<32?new r.constructor(r.$high>>>n,(r.$low>>>n|r.$high<<32-n)>>>0):n<64?new r.constructor(0,r.$high>>>n-32):new r.constructor(0,0)},$mul64=function(r,n){var t=0,$=0;0!=(1&n.$low)&&(t=r.$high,$=r.$low);for(var o=1;o<32;o++)0!=(n.$low&1<>>32-o,$+=r.$low<>>0);for(o=0;o<32;o++)0!=(n.$high&1<a||e===a&&i>u);)a=(a<<1|u>>>31)>>>0,u=u<<1>>>0,l++;for(var g=0;g<=l;g++)c=c<<1|h>>>31,h=h<<1>>>0,(e>a||e===a&&i>=u)&&(e-=a,(i-=u)<0&&(e--,i+=4294967296),4294967296===++h&&(c++,h=0)),u=(u>>>1|a<<31)>>>0,a>>>=1;return t?new r.constructor(e*o,i*o):new r.constructor(c*$,h*$)},$divComplex=function(r,n){var t=r.$real===1/0||r.$real===-1/0||r.$imag===1/0||r.$imag===-1/0,$=n.$real===1/0||n.$real===-1/0||n.$imag===1/0||n.$imag===-1/0,o=!t&&(r.$real!=r.$real||r.$imag!=r.$imag),e=!$&&(n.$real!=n.$real||n.$imag!=n.$imag);if(o||e)return new r.constructor(NaN,NaN);if(t&&!$)return new r.constructor(1/0,1/0);if(!t&&$)return new r.constructor(0,0);if(0===n.$real&&0===n.$imag)return 0===r.$real&&0===r.$imag?new r.constructor(NaN,NaN):new r.constructor(1/0,1/0);if(Math.abs(n.$real)<=Math.abs(n.$imag)){var i=n.$real/n.$imag,a=n.$real*i+n.$imag;return new r.constructor((r.$real*i+r.$imag)/a,(r.$imag*i-r.$real)/a)}i=n.$imag/n.$real,a=n.$imag*i+n.$real;return new r.constructor((r.$imag*i+r.$real)/a,(r.$imag-r.$real*i)/a)};` const numeric = ` var $min = Math.min; var $mod = function(x, y) { return x % y; }; diff --git a/compiler/prelude/prelude.go b/compiler/prelude/prelude.go index 8ee4ea5bf..954db88eb 100644 --- a/compiler/prelude/prelude.go +++ b/compiler/prelude/prelude.go @@ -1,7 +1,9 @@ package prelude const Prelude = prelude + numeric + types + goroutines + jsmapping +const PreludeMinified = preludeMinified + numericMinified + typesMinified + goroutinesMinified + jsmappingMinified +const preludeMinified = `var $global,$module;if(Error.stackTraceLimit=1/0,"undefined"!=typeof window?$global=window:"undefined"!=typeof self?$global=self:"undefined"!=typeof global?($global=global).require=require:$global=this,void 0===$global||void 0===$global.Array)throw new Error("no global object found");"undefined"!=typeof module&&($module=module);var $throwRuntimeError,$packages={},$idCounter=0,$keys=function(r){return r?Object.keys(r):[]},$flushConsole=function(){},$throwNilPointerError=function(){$throwRuntimeError("invalid memory address or nil pointer dereference")},$call=function(r,e,t){return r.apply(e,t)},$makeFunc=function(r){return function(){return $externalize(r(this,new($sliceType($jsObjectPtr))($global.Array.prototype.slice.call(arguments,[]))),$emptyInterface)}},$unused=function(r){},$mapArray=function(r,e){for(var t=new r.constructor(r.length),n=0;nr.$capacity||n>r.$capacity)&&$throwRuntimeError("slice bounds out of range");var o=new r.constructor(r.$array);return o.$offset=r.$offset+e,o.$length=r.$length-e,o.$capacity=r.$capacity-e,void 0!==t&&(o.$length=t-e),void 0!==n&&(o.$capacity=n-e),o},$substring=function(r,e,t){return(e<0||tr.length)&&$throwRuntimeError("slice bounds out of range"),r.substring(e,t)},$sliceToArray=function(r){return r.$array.constructor!==Array?r.$array.subarray(r.$offset,r.$offset+r.$length):r.$array.slice(r.$offset,r.$offset+r.$length)},$decodeRune=function(r,e){var t=r.charCodeAt(e);if(t<128)return[t,1];if(t!=t||t<192)return[65533,1];var n=r.charCodeAt(e+1);if(n!=n||n<128||192<=n)return[65533,1];if(t<224)return(a=(31&t)<<6|63&n)<=127?[65533,1]:[a,2];var o=r.charCodeAt(e+2);if(o!=o||o<128||192<=o)return[65533,1];if(t<240)return(a=(15&t)<<12|(63&n)<<6|63&o)<=2047?[65533,1]:55296<=a&&a<=57343?[65533,1]:[a,3];var a,i=r.charCodeAt(e+3);return i!=i||i<128||192<=i?[65533,1]:t<248?(a=(7&t)<<18|(63&n)<<12|(63&o)<<6|63&i)<=65535||11141111114111||55296<=r&&r<=57343)&&(r=65533),r<=127?String.fromCharCode(r):r<=2047?String.fromCharCode(192|r>>6,128|63&r):r<=65535?String.fromCharCode(224|r>>12,128|r>>6&63,128|63&r):String.fromCharCode(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r)},$stringToBytes=function(r){for(var e=new Uint8Array(r.length),t=0;tn){for(var i=o-1;i>=0;i--)a.copy(r[t+i],e[n+i]);return}for(i=0;in)for(i=o-1;i>=0;i--)r[t+i]=e[n+i];else for(i=0;i$)if(a=0,$=Math.max(i,r.$capacity<1024?2*r.$capacity:Math.floor(5*r.$capacity/4)),r.$array.constructor===Array){(o=r.$array.slice(r.$offset,r.$offset+r.$length)).length=$;for(var c=r.constructor.elem.zero,f=r.$length;f<$;f++)o[f]=c()}else(o=new r.$array.constructor($)).set(r.$array.subarray(r.$offset,r.$offset+r.$length));$copyArray(o,e,a+r.$length,t,n,r.constructor.elem);var u=new r.constructor(o);return u.$offset=a,u.$length=i,u.$capacity=$,u},$equal=function(r,e,t){if(t===$jsObjectPtr)return r===e;switch(t.kind){case $kindComplex64:case $kindComplex128:return r.$real===e.$real&&r.$imag===e.$imag;case $kindInt64:case $kindUint64:return r.$high===e.$high&&r.$low===e.$low;case $kindArray:if(r.length!==e.length)return!1;for(var n=0;n>0,this.$low=t>>>0,this.$val=this}).keyFor=function(n){return n.$high+"$"+n.$low};break;case $kindUint64:($=function(n,t){this.$high=n+Math.floor(Math.ceil(t)/4294967296)>>>0,this.$low=t>>>0,this.$val=this}).keyFor=function(n){return n.$high+"$"+n.$low};break;case $kindComplex64:($=function(n,t){this.$real=$fround(n),this.$imag=$fround(t),this.$val=this}).keyFor=function(n){return n.$real+"$"+n.$imag};break;case $kindComplex128:($=function(n,t){this.$real=n,this.$imag=t,this.$val=this}).keyFor=function(n){return n.$real+"$"+n.$imag};break;case $kindArray:($=function(n){this.$val=n}).wrapped=!0,$.ptr=$newType(4,$kindPtr,"*"+e,!1,"",!1,function(n){this.$get=function(){return n},this.$set=function(n){$.copy(this,n)},this.$val=n}),$.init=function(n,t){$.elem=n,$.len=t,$.comparable=n.comparable,$.keyFor=function(t){return Array.prototype.join.call($mapArray(t,function(t){return String(n.keyFor(t)).replace(/\\/g,"\\\\").replace(/\$/g,"\\$")}),"$")},$.copy=function(t,e){$copyArray(t,e,0,0,e.length,n)},$.ptr.init($),Object.defineProperty($.ptr.nil,"nilCheck",{get:$throwNilPointerError})};break;case $kindChan:($=function(n){this.$val=n}).wrapped=!0,$.keyFor=$idKey,$.init=function(n,t,e){$.elem=n,$.sendOnly=t,$.recvOnly=e};break;case $kindFunc:($=function(n){this.$val=n}).wrapped=!0,$.init=function(n,t,e){$.params=n,$.results=t,$.variadic=e,$.comparable=!1};break;case $kindInterface:($={implementedBy:{},missingMethodFor:{}}).keyFor=$ifaceKeyFor,$.init=function(n){$.methods=n,n.forEach(function(n){$ifaceNil[n.prop]=$throwNilPointerError})};break;case $kindMap:($=function(n){this.$val=n}).wrapped=!0,$.init=function(n,t){$.key=n,$.elem=t,$.comparable=!1};break;case $kindPtr:($=o||function(n,t,e){this.$get=n,this.$set=t,this.$target=e,this.$val=this}).keyFor=$idKey,$.init=function(n){$.elem=n,$.wrapped=n.kind===$kindArray,$.nil=new $($throwNilPointerError,$throwNilPointerError)};break;case $kindSlice:($=function(n){n.constructor!==$.nativeArray&&(n=new $.nativeArray(n)),this.$array=n,this.$offset=0,this.$length=n.length,this.$capacity=n.length,this.$val=this}).init=function(n){$.elem=n,$.comparable=!1,$.nativeArray=$nativeArray(n.kind),$.nil=new $([])};break;case $kindStruct:($=function(n){this.$val=n}).wrapped=!0,$.ptr=$newType(4,$kindPtr,"*"+e,!1,i,a,o),$.ptr.elem=$,$.ptr.prototype.$get=function(){return this},$.ptr.prototype.$set=function(n){$.copy(this,n)},$.init=function(n,t){$.pkgPath=n,$.fields=t,t.forEach(function(n){n.typ.comparable||($.comparable=!1)}),$.keyFor=function(n){var e=n.$val;return $mapArray(t,function(n){return String(n.typ.keyFor(e[n.prop])).replace(/\\/g,"\\\\").replace(/\$/g,"\\$")}).join("$")},$.copy=function(n,e){for(var r=0;r0;){var a=[],o=[];r.forEach(function(n){if(!i[n.typ.string])switch(i[n.typ.string]=!0,n.typ.named&&(o=o.concat(n.typ.methods),n.indirect&&(o=o.concat($ptrType(n.typ).methods))),n.typ.kind){case $kindStruct:n.typ.fields.forEach(function(t){if(t.anonymous){var e=t.typ,r=e.kind===$kindPtr;a.push({typ:r?e.elem:e,indirect:n.indirect||r})}});break;case $kindInterface:o=o.concat(n.typ.methods)}}),o.forEach(function(n){void 0===t[n.name]&&(t[n.name]=n)}),r=a}n.methodSetCache=[];var $=Object.keys(t).sort();return 2===$.length&&"nonexported"===$[0]&&"ΦExported"===$[1]&&($[0]="ΦExported",$[1]="nonexported"),$.forEach(function(e){n.methodSetCache.push(t[e])}),n.methodSetCache},$Bool=$newType(1,$kindBool,"bool",!0,"",!1,null),$Int=$newType(4,$kindInt,"int",!0,"",!1,null),$Int8=$newType(1,$kindInt8,"int8",!0,"",!1,null),$Int16=$newType(2,$kindInt16,"int16",!0,"",!1,null),$Int32=$newType(4,$kindInt32,"int32",!0,"",!1,null),$Int64=$newType(8,$kindInt64,"int64",!0,"",!1,null),$Uint=$newType(4,$kindUint,"uint",!0,"",!1,null),$Uint8=$newType(1,$kindUint8,"uint8",!0,"",!1,null),$Uint16=$newType(2,$kindUint16,"uint16",!0,"",!1,null),$Uint32=$newType(4,$kindUint32,"uint32",!0,"",!1,null),$Uint64=$newType(8,$kindUint64,"uint64",!0,"",!1,null),$Uintptr=$newType(4,$kindUintptr,"uintptr",!0,"",!1,null),$Float32=$newType(4,$kindFloat32,"float32",!0,"",!1,null),$Float64=$newType(8,$kindFloat64,"float64",!0,"",!1,null),$Complex64=$newType(8,$kindComplex64,"complex64",!0,"",!1,null),$Complex128=$newType(16,$kindComplex128,"complex128",!0,"",!1,null),$String=$newType(8,$kindString,"string",!0,"",!1,null),$UnsafePointer=$newType(4,$kindUnsafePointer,"unsafe.Pointer",!0,"",!1,null),$nativeArray=function(n){switch(n){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:case $kindUintptr:return Uint32Array;case $kindFloat32:return Float32Array;case $kindFloat64:return Float64Array;default:return Array}},$toNativeArray=function(n,t){var e=$nativeArray(n);return e===Array?t:new e(t)},$arrayTypes={},$arrayType=function(n,t){var e=n.id+"$"+t,r=$arrayTypes[e];return void 0===r&&(r=$newType(12,$kindArray,"["+t+"]"+n.string,!1,"",!1,null),$arrayTypes[e]=r,r.init(n,t)),r},$chanType=function(n,t,e){var r=(e?"<-":"")+"chan"+(t?"<- ":" ")+n.string,i=t?"SendChan":e?"RecvChan":"Chan",a=n[i];return void 0===a&&(a=$newType(4,$kindChan,r,!1,"",!1,null),n[i]=a,a.init(n,t,e)),a},$Chan=function(n,t){(t<0||t>2147483647)&&$throwRuntimeError("makechan: size out of range"),this.$elem=n,this.$capacity=t,this.$buffer=[],this.$sendQueue=[],this.$recvQueue=[],this.$closed=!1},$chanNil=new $Chan(null,0);$chanNil.$sendQueue=$chanNil.$recvQueue={length:0,push:function(){},shift:function(){},indexOf:function(){return-1}};var $funcTypes={},$funcType=function(n,t,e){var r=$mapArray(n,function(n){return n.id}).join(",")+"$"+$mapArray(t,function(n){return n.id}).join(",")+"$"+e,i=$funcTypes[r];if(void 0===i){var a=$mapArray(n,function(n){return n.string});e&&(a[a.length-1]="..."+a[a.length-1].substr(2));var o="func("+a.join(", ")+")";1===t.length?o+=" "+t[0].string:t.length>1&&(o+=" ("+$mapArray(t,function(n){return n.string}).join(", ")+")"),i=$newType(4,$kindFunc,o,!1,"",!1,null),$funcTypes[r]=i,i.init(n,t,e)}return i},$interfaceTypes={},$interfaceType=function(n){var t=$mapArray(n,function(n){return n.pkg+","+n.name+","+n.typ.id}).join("$"),e=$interfaceTypes[t];if(void 0===e){var r="interface {}";0!==n.length&&(r="interface { "+$mapArray(n,function(n){return(""!==n.pkg?n.pkg+".":"")+n.name+n.typ.string.substr(4)}).join("; ")+" }"),e=$newType(8,$kindInterface,r,!1,"",!1,null),$interfaceTypes[t]=e,e.init(n)}return e},$emptyInterface=$interfaceType([]),$ifaceNil={},$error=$newType(8,$kindInterface,"error",!0,"",!1,null);$error.init([{prop:"Error",name:"Error",pkg:"",typ:$funcType([],[$String],!1)}]);var $mapTypes={},$mapType=function(n,t){var e=n.id+"$"+t.id,r=$mapTypes[e];return void 0===r&&(r=$newType(4,$kindMap,"map["+n.string+"]"+t.string,!1,"",!1,null),$mapTypes[e]=r,r.init(n,t)),r},$makeMap=function(n,t){for(var e={},r=0;r2147483647)&&$throwRuntimeError("makeslice: len out of range"),(e<0||e2147483647)&&$throwRuntimeError("makeslice: cap out of range");var r=new n.nativeArray(e);if(n.nativeArray===Array)for(var i=0;i Date: Tue, 27 Feb 2018 09:39:36 +0100 Subject: [PATCH 2/3] Rename PreludeMinified to Minified and document. Use io.WriteString --- compiler/compiler.go | 4 ++-- compiler/prelude/prelude.go | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/compiler.go b/compiler/compiler.go index 356fcfde1..244d81d55 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -156,11 +156,11 @@ func WriteProgramCode(pkgs []*Archive, w *SourceMapFilter) error { } var preludeString string if minify { - preludeString = prelude.PreludeMinified + preludeString = prelude.Minified } else { preludeString = prelude.Prelude } - if _, err := w.Write([]byte(preludeString)); err != nil { + if _, err := io.WriteString(w, preludeString); err != nil { return err } if _, err := w.Write([]byte("\n")); err != nil { diff --git a/compiler/prelude/prelude.go b/compiler/prelude/prelude.go index 954db88eb..21981838e 100644 --- a/compiler/prelude/prelude.go +++ b/compiler/prelude/prelude.go @@ -1,7 +1,9 @@ package prelude const Prelude = prelude + numeric + types + goroutines + jsmapping -const PreludeMinified = preludeMinified + numericMinified + typesMinified + goroutinesMinified + jsmappingMinified + +// Minified is Prelude ran through UglifyJS 3 via https://skalman.github.io/UglifyJS-online/. +const Minified = preludeMinified + numericMinified + typesMinified + goroutinesMinified + jsmappingMinified const preludeMinified = `var $global,$module;if(Error.stackTraceLimit=1/0,"undefined"!=typeof window?$global=window:"undefined"!=typeof self?$global=self:"undefined"!=typeof global?($global=global).require=require:$global=this,void 0===$global||void 0===$global.Array)throw new Error("no global object found");"undefined"!=typeof module&&($module=module);var $throwRuntimeError,$packages={},$idCounter=0,$keys=function(r){return r?Object.keys(r):[]},$flushConsole=function(){},$throwNilPointerError=function(){$throwRuntimeError("invalid memory address or nil pointer dereference")},$call=function(r,e,t){return r.apply(e,t)},$makeFunc=function(r){return function(){return $externalize(r(this,new($sliceType($jsObjectPtr))($global.Array.prototype.slice.call(arguments,[]))),$emptyInterface)}},$unused=function(r){},$mapArray=function(r,e){for(var t=new r.constructor(r.length),n=0;nr.$capacity||n>r.$capacity)&&$throwRuntimeError("slice bounds out of range");var o=new r.constructor(r.$array);return o.$offset=r.$offset+e,o.$length=r.$length-e,o.$capacity=r.$capacity-e,void 0!==t&&(o.$length=t-e),void 0!==n&&(o.$capacity=n-e),o},$substring=function(r,e,t){return(e<0||tr.length)&&$throwRuntimeError("slice bounds out of range"),r.substring(e,t)},$sliceToArray=function(r){return r.$array.constructor!==Array?r.$array.subarray(r.$offset,r.$offset+r.$length):r.$array.slice(r.$offset,r.$offset+r.$length)},$decodeRune=function(r,e){var t=r.charCodeAt(e);if(t<128)return[t,1];if(t!=t||t<192)return[65533,1];var n=r.charCodeAt(e+1);if(n!=n||n<128||192<=n)return[65533,1];if(t<224)return(a=(31&t)<<6|63&n)<=127?[65533,1]:[a,2];var o=r.charCodeAt(e+2);if(o!=o||o<128||192<=o)return[65533,1];if(t<240)return(a=(15&t)<<12|(63&n)<<6|63&o)<=2047?[65533,1]:55296<=a&&a<=57343?[65533,1]:[a,3];var a,i=r.charCodeAt(e+3);return i!=i||i<128||192<=i?[65533,1]:t<248?(a=(7&t)<<18|(63&n)<<12|(63&o)<<6|63&i)<=65535||11141111114111||55296<=r&&r<=57343)&&(r=65533),r<=127?String.fromCharCode(r):r<=2047?String.fromCharCode(192|r>>6,128|63&r):r<=65535?String.fromCharCode(224|r>>12,128|r>>6&63,128|63&r):String.fromCharCode(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r)},$stringToBytes=function(r){for(var e=new Uint8Array(r.length),t=0;tn){for(var i=o-1;i>=0;i--)a.copy(r[t+i],e[n+i]);return}for(i=0;in)for(i=o-1;i>=0;i--)r[t+i]=e[n+i];else for(i=0;i$)if(a=0,$=Math.max(i,r.$capacity<1024?2*r.$capacity:Math.floor(5*r.$capacity/4)),r.$array.constructor===Array){(o=r.$array.slice(r.$offset,r.$offset+r.$length)).length=$;for(var c=r.constructor.elem.zero,f=r.$length;f<$;f++)o[f]=c()}else(o=new r.$array.constructor($)).set(r.$array.subarray(r.$offset,r.$offset+r.$length));$copyArray(o,e,a+r.$length,t,n,r.constructor.elem);var u=new r.constructor(o);return u.$offset=a,u.$length=i,u.$capacity=$,u},$equal=function(r,e,t){if(t===$jsObjectPtr)return r===e;switch(t.kind){case $kindComplex64:case $kindComplex128:return r.$real===e.$real&&r.$imag===e.$imag;case $kindInt64:case $kindUint64:return r.$high===e.$high&&r.$low===e.$low;case $kindArray:if(r.length!==e.length)return!1;for(var n=0;n Date: Tue, 27 Feb 2018 13:18:28 -0500 Subject: [PATCH 3/3] Inline Minified content; adjust style. No need to minify parts of prelude separately. It actually improves minification slightly when done as a whole (32895 bytes -> 32763 bytes). Adjust style of if statement to make it simpler/shorter and rename preludeString variable to be more descriptive. It's prelude JavaScript code. --- compiler/compiler.go | 8 +++----- compiler/prelude/goroutines.go | 1 - compiler/prelude/jsmapping.go | 1 - compiler/prelude/numeric.go | 1 - compiler/prelude/prelude.go | 6 +++--- compiler/prelude/types.go | 1 - 6 files changed, 6 insertions(+), 12 deletions(-) diff --git a/compiler/compiler.go b/compiler/compiler.go index 244d81d55..785df795f 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -154,13 +154,11 @@ func WriteProgramCode(pkgs []*Archive, w *SourceMapFilter) error { if _, err := w.Write([]byte("\"use strict\";\n(function() {\n\n")); err != nil { return err } - var preludeString string + preludeJS := prelude.Prelude if minify { - preludeString = prelude.Minified - } else { - preludeString = prelude.Prelude + preludeJS = prelude.Minified } - if _, err := io.WriteString(w, preludeString); err != nil { + if _, err := io.WriteString(w, preludeJS); err != nil { return err } if _, err := w.Write([]byte("\n")); err != nil { diff --git a/compiler/prelude/goroutines.go b/compiler/prelude/goroutines.go index f54413fe7..d9780b65d 100644 --- a/compiler/prelude/goroutines.go +++ b/compiler/prelude/goroutines.go @@ -1,6 +1,5 @@ package prelude -const goroutinesMinified = `var $panicValue,$stackDepthOffset=0,$getStackDepth=function(){var e=new Error;if(void 0!==e.stack)return $stackDepthOffset+e.stack.split("\n").length},$panicStackDepth=null,$callDeferred=function(e,r,n){if(!n&&null!==e&&e.index>=$curGoroutine.deferStack.length)throw r;if(null!==r){var t=null;try{$curGoroutine.deferStack.push(e),$panic(new $jsErrorPtr(r))}catch(e){t=e}return $curGoroutine.deferStack.pop(),void $callDeferred(e,t)}if(!$curGoroutine.asleep){$stackDepthOffset--;var o=$panicStackDepth,c=$panicValue,u=$curGoroutine.panicStack.pop();void 0!==u&&($panicStackDepth=$getStackDepth(),$panicValue=u);try{for(;;){if(null===e&&void 0===(e=$curGoroutine.deferStack[$curGoroutine.deferStack.length-1])){if($panicStackDepth=null,u.Object instanceof Error)throw u.Object;var i;throw i=u.constructor===$String?u.$val:void 0!==u.Error?u.Error():void 0!==u.String?u.String():u,new Error(i)}var a=e.pop();if(void 0===a){if($curGoroutine.deferStack.pop(),void 0!==u){e=null;continue}return}var l=a[0].apply(a[2],a[1]);if(l&&void 0!==l.$blk){if(e.push([l.$blk,[],l]),n)throw null;return}if(void 0!==u&&null===$panicStackDepth)throw null}}finally{void 0!==u&&(null!==$panicStackDepth&&$curGoroutine.panicStack.push(u),$panicStackDepth=o,$panicValue=c),$stackDepthOffset++}}},$panic=function(e){$curGoroutine.panicStack.push(e),$callDeferred(null,null,!0)},$recover=function(){return null===$panicStackDepth||void 0!==$panicStackDepth&&$panicStackDepth!==$getStackDepth()-2?$ifaceNil:($panicStackDepth=null,$panicValue)},$throw=function(e){throw e},$noGoroutine={asleep:!1,exit:!1,deferStack:[],panicStack:[]},$curGoroutine=$noGoroutine,$totalGoroutines=0,$awakeGoroutines=0,$checkForDeadlock=!0,$mainFinished=!1,$go=function(e,r){$totalGoroutines++,$awakeGoroutines++;var n=function(){try{$curGoroutine=n;var t=e.apply(void 0,r);if(t&&void 0!==t.$blk)return e=function(){return t.$blk()},void(r=[]);n.exit=!0}catch(e){if(!n.exit)throw e}finally{$curGoroutine=$noGoroutine,n.exit&&($totalGoroutines--,n.asleep=!0),n.asleep&&($awakeGoroutines--,!$mainFinished&&0===$awakeGoroutines&&$checkForDeadlock&&(console.error("fatal error: all goroutines are asleep - deadlock!"),void 0!==$global.process&&$global.process.exit(2)))}};n.asleep=!1,n.exit=!1,n.deferStack=[],n.panicStack=[],$schedule(n)},$scheduled=[],$runScheduled=function(){try{for(var e;void 0!==(e=$scheduled.shift());)e()}finally{$scheduled.length>0&&setTimeout($runScheduled,0)}},$schedule=function(e){e.asleep&&(e.asleep=!1,$awakeGoroutines++),$scheduled.push(e),$curGoroutine===$noGoroutine&&$runScheduled()},$setTimeout=function(e,r){return $awakeGoroutines++,setTimeout(function(){$awakeGoroutines--,e()},r)},$block=function(){$curGoroutine===$noGoroutine&&$throwRuntimeError("cannot block in JavaScript callback, fix by wrapping code in goroutine"),$curGoroutine.asleep=!0},$send=function(e,r){e.$closed&&$throwRuntimeError("send on closed channel");var n=e.$recvQueue.shift();if(void 0===n){if(!(e.$buffer.length65535){var l=Math.floor(($-65536)/1024)+55296,u=($-65536)%1024+56320;c+=String.fromCharCode(l,u)}else c+=String.fromCharCode($)}return c;case $kindStruct:var o=$packages.time;if(void 0!==o&&e.constructor===o.Time.ptr){var d=$div64(e.UnixNano(),new $Int64(0,1e6));return new Date($flatten64(d))}var k={},f=function(e,r){if(r===$jsObjectPtr)return e;switch(r.kind){case $kindPtr:return e===r.nil?k:f(e.$get(),r.elem);case $kindStruct:var n=r.fields[0];return f(e[n.prop],n.typ);case $kindInterface:return f(e.$val,e.constructor);default:return k}},p=f(e,r);if(p!==k)return p;p={};for(a=0;a>24;case $kindInt16:return parseInt(e)<<16>>16;case $kindInt32:return parseInt(e)>>0;case $kindUint:return parseInt(e);case $kindUint8:return parseInt(e)<<24>>>24;case $kindUint16:return parseInt(e)<<16>>>16;case $kindUint32:case $kindUintptr:return parseInt(e)>>>0;case $kindInt64:case $kindUint64:return new r(0,e);case $kindFloat32:case $kindFloat64:return parseFloat(e);case $kindArray:return e.length!==r.len&&$throwRuntimeError("got array with wrong size from JavaScript native"),$mapArray(e,function(e){return $internalize(e,r.elem)});case $kindFunc:return function(){for(var t=[],a=0;a=128)return!1;return!0};` const jsmapping = ` var $jsObjectPtr, $jsErrorPtr; diff --git a/compiler/prelude/numeric.go b/compiler/prelude/numeric.go index bdd6ce206..063d09f46 100644 --- a/compiler/prelude/numeric.go +++ b/compiler/prelude/numeric.go @@ -1,6 +1,5 @@ package prelude -const numericMinified = `var $min=Math.min,$mod=function(r,n){return r%n},$parseInt=parseInt,$parseFloat=function(r){return null!=r&&r.constructor===Number?r:parseFloat(r)},$froundBuf=new Float32Array(1),$fround=Math.fround||function(r){return $froundBuf[0]=r,$froundBuf[0]},$imul=Math.imul||function(r,n){var t=65535&r,$=65535&n;return t*$+((r>>>16&65535)*$+t*(n>>>16&65535)<<16>>>0)>>0},$floatKey=function(r){return r!=r?($idCounter++,"NaN$"+$idCounter):String(r)},$flatten64=function(r){return 4294967296*r.$high+r.$low},$shiftLeft64=function(r,n){return 0===n?r:n<32?new r.constructor(r.$high<>>32-n,r.$low<>>0):n<64?new r.constructor(r.$low<>n,(r.$low>>>n|r.$high<<32-n)>>>0):n<64?new r.constructor(r.$high>>31,r.$high>>n-32>>>0):r.$high<0?new r.constructor(-1,4294967295):new r.constructor(0,0)},$shiftRightUint64=function(r,n){return 0===n?r:n<32?new r.constructor(r.$high>>>n,(r.$low>>>n|r.$high<<32-n)>>>0):n<64?new r.constructor(0,r.$high>>>n-32):new r.constructor(0,0)},$mul64=function(r,n){var t=0,$=0;0!=(1&n.$low)&&(t=r.$high,$=r.$low);for(var o=1;o<32;o++)0!=(n.$low&1<>>32-o,$+=r.$low<>>0);for(o=0;o<32;o++)0!=(n.$high&1<a||e===a&&i>u);)a=(a<<1|u>>>31)>>>0,u=u<<1>>>0,l++;for(var g=0;g<=l;g++)c=c<<1|h>>>31,h=h<<1>>>0,(e>a||e===a&&i>=u)&&(e-=a,(i-=u)<0&&(e--,i+=4294967296),4294967296===++h&&(c++,h=0)),u=(u>>>1|a<<31)>>>0,a>>>=1;return t?new r.constructor(e*o,i*o):new r.constructor(c*$,h*$)},$divComplex=function(r,n){var t=r.$real===1/0||r.$real===-1/0||r.$imag===1/0||r.$imag===-1/0,$=n.$real===1/0||n.$real===-1/0||n.$imag===1/0||n.$imag===-1/0,o=!t&&(r.$real!=r.$real||r.$imag!=r.$imag),e=!$&&(n.$real!=n.$real||n.$imag!=n.$imag);if(o||e)return new r.constructor(NaN,NaN);if(t&&!$)return new r.constructor(1/0,1/0);if(!t&&$)return new r.constructor(0,0);if(0===n.$real&&0===n.$imag)return 0===r.$real&&0===r.$imag?new r.constructor(NaN,NaN):new r.constructor(1/0,1/0);if(Math.abs(n.$real)<=Math.abs(n.$imag)){var i=n.$real/n.$imag,a=n.$real*i+n.$imag;return new r.constructor((r.$real*i+r.$imag)/a,(r.$imag*i-r.$real)/a)}i=n.$imag/n.$real,a=n.$imag*i+n.$real;return new r.constructor((r.$imag*i+r.$real)/a,(r.$imag-r.$real*i)/a)};` const numeric = ` var $min = Math.min; var $mod = function(x, y) { return x % y; }; diff --git a/compiler/prelude/prelude.go b/compiler/prelude/prelude.go index 21981838e..82fbbc934 100644 --- a/compiler/prelude/prelude.go +++ b/compiler/prelude/prelude.go @@ -2,10 +2,10 @@ package prelude const Prelude = prelude + numeric + types + goroutines + jsmapping -// Minified is Prelude ran through UglifyJS 3 via https://skalman.github.io/UglifyJS-online/. -const Minified = preludeMinified + numericMinified + typesMinified + goroutinesMinified + jsmappingMinified +// Minified is Prelude ran through UglifyJS 3 via https://skalman.github.io/UglifyJS-online/ +// with default options. +const Minified = `var $global,$module;if(Error.stackTraceLimit=1/0,"undefined"!=typeof window?$global=window:"undefined"!=typeof self?$global=self:"undefined"!=typeof global?($global=global).require=require:$global=this,void 0===$global||void 0===$global.Array)throw new Error("no global object found");"undefined"!=typeof module&&($module=module);var $throwRuntimeError,$packages={},$idCounter=0,$keys=function(e){return e?Object.keys(e):[]},$flushConsole=function(){},$throwNilPointerError=function(){$throwRuntimeError("invalid memory address or nil pointer dereference")},$call=function(e,n,r){return e.apply(n,r)},$makeFunc=function(e){return function(){return $externalize(e(this,new($sliceType($jsObjectPtr))($global.Array.prototype.slice.call(arguments,[]))),$emptyInterface)}},$unused=function(e){},$mapArray=function(e,n){for(var r=new e.constructor(e.length),t=0;te.$capacity||t>e.$capacity)&&$throwRuntimeError("slice bounds out of range");var i=new e.constructor(e.$array);return i.$offset=e.$offset+n,i.$length=e.$length-n,i.$capacity=e.$capacity-n,void 0!==r&&(i.$length=r-n),void 0!==t&&(i.$capacity=t-n),i},$substring=function(e,n,r){return(n<0||re.length)&&$throwRuntimeError("slice bounds out of range"),e.substring(n,r)},$sliceToArray=function(e){return e.$array.constructor!==Array?e.$array.subarray(e.$offset,e.$offset+e.$length):e.$array.slice(e.$offset,e.$offset+e.$length)},$decodeRune=function(e,n){var r=e.charCodeAt(n);if(r<128)return[r,1];if(r!=r||r<192)return[65533,1];var t=e.charCodeAt(n+1);if(t!=t||t<128||192<=t)return[65533,1];if(r<224)return(a=(31&r)<<6|63&t)<=127?[65533,1]:[a,2];var i=e.charCodeAt(n+2);if(i!=i||i<128||192<=i)return[65533,1];if(r<240)return(a=(15&r)<<12|(63&t)<<6|63&i)<=2047?[65533,1]:55296<=a&&a<=57343?[65533,1]:[a,3];var a,o=e.charCodeAt(n+3);return o!=o||o<128||192<=o?[65533,1]:r<248?(a=(7&r)<<18|(63&t)<<12|(63&i)<<6|63&o)<=65535||11141111114111||55296<=e&&e<=57343)&&(e=65533),e<=127?String.fromCharCode(e):e<=2047?String.fromCharCode(192|e>>6,128|63&e):e<=65535?String.fromCharCode(224|e>>12,128|e>>6&63,128|63&e):String.fromCharCode(240|e>>18,128|e>>12&63,128|e>>6&63,128|63&e)},$stringToBytes=function(e){for(var n=new Uint8Array(e.length),r=0;rt){for(var o=i-1;o>=0;o--)a.copy(e[r+o],n[t+o]);return}for(o=0;ot)for(o=i-1;o>=0;o--)e[r+o]=n[t+o];else for(o=0;o$)if(a=0,$=Math.max(o,e.$capacity<1024?2*e.$capacity:Math.floor(5*e.$capacity/4)),e.$array.constructor===Array){(i=e.$array.slice(e.$offset,e.$offset+e.$length)).length=$;for(var c=e.constructor.elem.zero,u=e.$length;u<$;u++)i[u]=c()}else(i=new e.$array.constructor($)).set(e.$array.subarray(e.$offset,e.$offset+e.$length));$copyArray(i,n,a+e.$length,r,t,e.constructor.elem);var l=new e.constructor(i);return l.$offset=a,l.$length=o,l.$capacity=$,l},$equal=function(e,n,r){if(r===$jsObjectPtr)return e===n;switch(r.kind){case $kindComplex64:case $kindComplex128:return e.$real===n.$real&&e.$imag===n.$imag;case $kindInt64:case $kindUint64:return e.$high===n.$high&&e.$low===n.$low;case $kindArray:if(e.length!==n.length)return!1;for(var t=0;t>>16&65535)*t+r*(n>>>16&65535)<<16>>>0)>>0},$floatKey=function(e){return e!=e?"NaN$"+ ++$idCounter:String(e)},$flatten64=function(e){return 4294967296*e.$high+e.$low},$shiftLeft64=function(e,n){return 0===n?e:n<32?new e.constructor(e.$high<>>32-n,e.$low<>>0):n<64?new e.constructor(e.$low<>n,(e.$low>>>n|e.$high<<32-n)>>>0):n<64?new e.constructor(e.$high>>31,e.$high>>n-32>>>0):e.$high<0?new e.constructor(-1,4294967295):new e.constructor(0,0)},$shiftRightUint64=function(e,n){return 0===n?e:n<32?new e.constructor(e.$high>>>n,(e.$low>>>n|e.$high<<32-n)>>>0):n<64?new e.constructor(0,e.$high>>>n-32):new e.constructor(0,0)},$mul64=function(e,n){var r=0,t=0;0!=(1&n.$low)&&(r=e.$high,t=e.$low);for(var i=1;i<32;i++)0!=(n.$low&1<>>32-i,t+=e.$low<>>0);for(i=0;i<32;i++)0!=(n.$high&1<$||a===$&&o>c);)$=($<<1|c>>>31)>>>0,c=c<<1>>>0,s++;for(var f=0;f<=s;f++)u=u<<1|l>>>31,l=l<<1>>>0,(a>$||a===$&&o>=c)&&(a-=$,(o-=c)<0&&(a--,o+=4294967296),4294967296===++l&&(u++,l=0)),c=(c>>>1|$<<31)>>>0,$>>>=1;return r?new e.constructor(a*i,o*i):new e.constructor(u*t,l*t)},$divComplex=function(e,n){var r=e.$real===1/0||e.$real===-1/0||e.$imag===1/0||e.$imag===-1/0,t=n.$real===1/0||n.$real===-1/0||n.$imag===1/0||n.$imag===-1/0,i=!r&&(e.$real!=e.$real||e.$imag!=e.$imag),a=!t&&(n.$real!=n.$real||n.$imag!=n.$imag);if(i||a)return new e.constructor(NaN,NaN);if(r&&!t)return new e.constructor(1/0,1/0);if(!r&&t)return new e.constructor(0,0);if(0===n.$real&&0===n.$imag)return 0===e.$real&&0===e.$imag?new e.constructor(NaN,NaN):new e.constructor(1/0,1/0);if(Math.abs(n.$real)<=Math.abs(n.$imag)){var o=n.$real/n.$imag,$=n.$real*o+n.$imag;return new e.constructor((e.$real*o+e.$imag)/$,(e.$imag*o-e.$real)/$)}o=n.$imag/n.$real,$=n.$imag*o+n.$real;return new e.constructor((e.$imag*o+e.$real)/$,(e.$imag-e.$real*o)/$)},$kindBool=1,$kindInt=2,$kindInt8=3,$kindInt16=4,$kindInt32=5,$kindInt64=6,$kindUint=7,$kindUint8=8,$kindUint16=9,$kindUint32=10,$kindUint64=11,$kindUintptr=12,$kindFloat32=13,$kindFloat64=14,$kindComplex64=15,$kindComplex128=16,$kindArray=17,$kindChan=18,$kindFunc=19,$kindInterface=20,$kindMap=21,$kindPtr=22,$kindSlice=23,$kindString=24,$kindStruct=25,$kindUnsafePointer=26,$methodSynthesizers=[],$addMethodSynthesizer=function(e){null!==$methodSynthesizers?$methodSynthesizers.push(e):e()},$synthesizeMethods=function(){$methodSynthesizers.forEach(function(e){e()}),$methodSynthesizers=null},$ifaceKeyFor=function(e){if(e===$ifaceNil)return"nil";var n=e.constructor;return n.string+"$"+n.keyFor(e.$val)},$identity=function(e){return e},$typeIDCounter=0,$idKey=function(e){return void 0===e.$id&&($idCounter++,e.$id=$idCounter),String(e.$id)},$newType=function(e,n,r,t,i,a,o){var $;switch(n){case $kindBool:case $kindInt:case $kindInt8:case $kindInt16:case $kindInt32:case $kindUint:case $kindUint8:case $kindUint16:case $kindUint32:case $kindUintptr:case $kindUnsafePointer:($=function(e){this.$val=e}).wrapped=!0,$.keyFor=$identity;break;case $kindString:($=function(e){this.$val=e}).wrapped=!0,$.keyFor=function(e){return"$"+e};break;case $kindFloat32:case $kindFloat64:($=function(e){this.$val=e}).wrapped=!0,$.keyFor=function(e){return $floatKey(e)};break;case $kindInt64:($=function(e,n){this.$high=e+Math.floor(Math.ceil(n)/4294967296)>>0,this.$low=n>>>0,this.$val=this}).keyFor=function(e){return e.$high+"$"+e.$low};break;case $kindUint64:($=function(e,n){this.$high=e+Math.floor(Math.ceil(n)/4294967296)>>>0,this.$low=n>>>0,this.$val=this}).keyFor=function(e){return e.$high+"$"+e.$low};break;case $kindComplex64:($=function(e,n){this.$real=$fround(e),this.$imag=$fround(n),this.$val=this}).keyFor=function(e){return e.$real+"$"+e.$imag};break;case $kindComplex128:($=function(e,n){this.$real=e,this.$imag=n,this.$val=this}).keyFor=function(e){return e.$real+"$"+e.$imag};break;case $kindArray:($=function(e){this.$val=e}).wrapped=!0,$.ptr=$newType(4,$kindPtr,"*"+r,!1,"",!1,function(e){this.$get=function(){return e},this.$set=function(e){$.copy(this,e)},this.$val=e}),$.init=function(e,n){$.elem=e,$.len=n,$.comparable=e.comparable,$.keyFor=function(n){return Array.prototype.join.call($mapArray(n,function(n){return String(e.keyFor(n)).replace(/\\/g,"\\\\").replace(/\$/g,"\\$")}),"$")},$.copy=function(n,r){$copyArray(n,r,0,0,r.length,e)},$.ptr.init($),Object.defineProperty($.ptr.nil,"nilCheck",{get:$throwNilPointerError})};break;case $kindChan:($=function(e){this.$val=e}).wrapped=!0,$.keyFor=$idKey,$.init=function(e,n,r){$.elem=e,$.sendOnly=n,$.recvOnly=r};break;case $kindFunc:($=function(e){this.$val=e}).wrapped=!0,$.init=function(e,n,r){$.params=e,$.results=n,$.variadic=r,$.comparable=!1};break;case $kindInterface:($={implementedBy:{},missingMethodFor:{}}).keyFor=$ifaceKeyFor,$.init=function(e){$.methods=e,e.forEach(function(e){$ifaceNil[e.prop]=$throwNilPointerError})};break;case $kindMap:($=function(e){this.$val=e}).wrapped=!0,$.init=function(e,n){$.key=e,$.elem=n,$.comparable=!1};break;case $kindPtr:($=o||function(e,n,r){this.$get=e,this.$set=n,this.$target=r,this.$val=this}).keyFor=$idKey,$.init=function(e){$.elem=e,$.wrapped=e.kind===$kindArray,$.nil=new $($throwNilPointerError,$throwNilPointerError)};break;case $kindSlice:($=function(e){e.constructor!==$.nativeArray&&(e=new $.nativeArray(e)),this.$array=e,this.$offset=0,this.$length=e.length,this.$capacity=e.length,this.$val=this}).init=function(e){$.elem=e,$.comparable=!1,$.nativeArray=$nativeArray(e.kind),$.nil=new $([])};break;case $kindStruct:($=function(e){this.$val=e}).wrapped=!0,$.ptr=$newType(4,$kindPtr,"*"+r,!1,i,a,o),$.ptr.elem=$,$.ptr.prototype.$get=function(){return this},$.ptr.prototype.$set=function(e){$.copy(this,e)},$.init=function(e,n){$.pkgPath=e,$.fields=n,n.forEach(function(e){e.typ.comparable||($.comparable=!1)}),$.keyFor=function(e){var r=e.$val;return $mapArray(n,function(e){return String(e.typ.keyFor(r[e.prop])).replace(/\\/g,"\\\\").replace(/\$/g,"\\$")}).join("$")},$.copy=function(e,r){for(var t=0;t0;){var a=[],o=[];t.forEach(function(e){if(!i[e.typ.string])switch(i[e.typ.string]=!0,e.typ.named&&(o=o.concat(e.typ.methods),e.indirect&&(o=o.concat($ptrType(e.typ).methods))),e.typ.kind){case $kindStruct:e.typ.fields.forEach(function(n){if(n.anonymous){var r=n.typ,t=r.kind===$kindPtr;a.push({typ:t?r.elem:r,indirect:e.indirect||t})}});break;case $kindInterface:o=o.concat(e.typ.methods)}}),o.forEach(function(e){void 0===n[e.name]&&(n[e.name]=e)}),t=a}return e.methodSetCache=[],Object.keys(n).sort().forEach(function(r){e.methodSetCache.push(n[r])}),e.methodSetCache},$Bool=$newType(1,$kindBool,"bool",!0,"",!1,null),$Int=$newType(4,$kindInt,"int",!0,"",!1,null),$Int8=$newType(1,$kindInt8,"int8",!0,"",!1,null),$Int16=$newType(2,$kindInt16,"int16",!0,"",!1,null),$Int32=$newType(4,$kindInt32,"int32",!0,"",!1,null),$Int64=$newType(8,$kindInt64,"int64",!0,"",!1,null),$Uint=$newType(4,$kindUint,"uint",!0,"",!1,null),$Uint8=$newType(1,$kindUint8,"uint8",!0,"",!1,null),$Uint16=$newType(2,$kindUint16,"uint16",!0,"",!1,null),$Uint32=$newType(4,$kindUint32,"uint32",!0,"",!1,null),$Uint64=$newType(8,$kindUint64,"uint64",!0,"",!1,null),$Uintptr=$newType(4,$kindUintptr,"uintptr",!0,"",!1,null),$Float32=$newType(4,$kindFloat32,"float32",!0,"",!1,null),$Float64=$newType(8,$kindFloat64,"float64",!0,"",!1,null),$Complex64=$newType(8,$kindComplex64,"complex64",!0,"",!1,null),$Complex128=$newType(16,$kindComplex128,"complex128",!0,"",!1,null),$String=$newType(8,$kindString,"string",!0,"",!1,null),$UnsafePointer=$newType(4,$kindUnsafePointer,"unsafe.Pointer",!0,"",!1,null),$nativeArray=function(e){switch(e){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:case $kindUintptr:return Uint32Array;case $kindFloat32:return Float32Array;case $kindFloat64:return Float64Array;default:return Array}},$toNativeArray=function(e,n){var r=$nativeArray(e);return r===Array?n:new r(n)},$arrayTypes={},$arrayType=function(e,n){var r=e.id+"$"+n,t=$arrayTypes[r];return void 0===t&&(t=$newType(12,$kindArray,"["+n+"]"+e.string,!1,"",!1,null),$arrayTypes[r]=t,t.init(e,n)),t},$chanType=function(e,n,r){var t=(r?"<-":"")+"chan"+(n?"<- ":" ")+e.string,i=n?"SendChan":r?"RecvChan":"Chan",a=e[i];return void 0===a&&(a=$newType(4,$kindChan,t,!1,"",!1,null),e[i]=a,a.init(e,n,r)),a},$Chan=function(e,n){(n<0||n>2147483647)&&$throwRuntimeError("makechan: size out of range"),this.$elem=e,this.$capacity=n,this.$buffer=[],this.$sendQueue=[],this.$recvQueue=[],this.$closed=!1},$chanNil=new $Chan(null,0);$chanNil.$sendQueue=$chanNil.$recvQueue={length:0,push:function(){},shift:function(){},indexOf:function(){return-1}};var $funcTypes={},$funcType=function(e,n,r){var t=$mapArray(e,function(e){return e.id}).join(",")+"$"+$mapArray(n,function(e){return e.id}).join(",")+"$"+r,i=$funcTypes[t];if(void 0===i){var a=$mapArray(e,function(e){return e.string});r&&(a[a.length-1]="..."+a[a.length-1].substr(2));var o="func("+a.join(", ")+")";1===n.length?o+=" "+n[0].string:n.length>1&&(o+=" ("+$mapArray(n,function(e){return e.string}).join(", ")+")"),i=$newType(4,$kindFunc,o,!1,"",!1,null),$funcTypes[t]=i,i.init(e,n,r)}return i},$interfaceTypes={},$interfaceType=function(e){var n=$mapArray(e,function(e){return e.pkg+","+e.name+","+e.typ.id}).join("$"),r=$interfaceTypes[n];if(void 0===r){var t="interface {}";0!==e.length&&(t="interface { "+$mapArray(e,function(e){return(""!==e.pkg?e.pkg+".":"")+e.name+e.typ.string.substr(4)}).join("; ")+" }"),r=$newType(8,$kindInterface,t,!1,"",!1,null),$interfaceTypes[n]=r,r.init(e)}return r},$emptyInterface=$interfaceType([]),$ifaceNil={},$error=$newType(8,$kindInterface,"error",!0,"",!1,null);$error.init([{prop:"Error",name:"Error",pkg:"",typ:$funcType([],[$String],!1)}]);var $panicValue,$jsObjectPtr,$jsErrorPtr,$mapTypes={},$mapType=function(e,n){var r=e.id+"$"+n.id,t=$mapTypes[r];return void 0===t&&(t=$newType(4,$kindMap,"map["+e.string+"]"+n.string,!1,"",!1,null),$mapTypes[r]=t,t.init(e,n)),t},$makeMap=function(e,n){for(var r={},t=0;t2147483647)&&$throwRuntimeError("makeslice: len out of range"),(r<0||r2147483647)&&$throwRuntimeError("makeslice: cap out of range");var t=new e.nativeArray(r);if(e.nativeArray===Array)for(var i=0;i=$curGoroutine.deferStack.length)throw n;if(null!==n){var t=null;try{$curGoroutine.deferStack.push(e),$panic(new $jsErrorPtr(n))}catch(e){t=e}return $curGoroutine.deferStack.pop(),void $callDeferred(e,t)}if(!$curGoroutine.asleep){$stackDepthOffset--;var i=$panicStackDepth,a=$panicValue,o=$curGoroutine.panicStack.pop();void 0!==o&&($panicStackDepth=$getStackDepth(),$panicValue=o);try{for(;;){if(null===e&&void 0===(e=$curGoroutine.deferStack[$curGoroutine.deferStack.length-1])){if($panicStackDepth=null,o.Object instanceof Error)throw o.Object;var $;throw $=o.constructor===$String?o.$val:void 0!==o.Error?o.Error():void 0!==o.String?o.String():o,new Error($)}var c=e.pop();if(void 0===c){if($curGoroutine.deferStack.pop(),void 0!==o){e=null;continue}return}var u=c[0].apply(c[2],c[1]);if(u&&void 0!==u.$blk){if(e.push([u.$blk,[],u]),r)throw null;return}if(void 0!==o&&null===$panicStackDepth)throw null}}finally{void 0!==o&&(null!==$panicStackDepth&&$curGoroutine.panicStack.push(o),$panicStackDepth=i,$panicValue=a),$stackDepthOffset++}}},$panic=function(e){$curGoroutine.panicStack.push(e),$callDeferred(null,null,!0)},$recover=function(){return null===$panicStackDepth||void 0!==$panicStackDepth&&$panicStackDepth!==$getStackDepth()-2?$ifaceNil:($panicStackDepth=null,$panicValue)},$throw=function(e){throw e},$noGoroutine={asleep:!1,exit:!1,deferStack:[],panicStack:[]},$curGoroutine=$noGoroutine,$totalGoroutines=0,$awakeGoroutines=0,$checkForDeadlock=!0,$mainFinished=!1,$go=function(e,n){$totalGoroutines++,$awakeGoroutines++;var r=function(){try{$curGoroutine=r;var t=e.apply(void 0,n);if(t&&void 0!==t.$blk)return e=function(){return t.$blk()},void(n=[]);r.exit=!0}catch(e){if(!r.exit)throw e}finally{$curGoroutine=$noGoroutine,r.exit&&($totalGoroutines--,r.asleep=!0),r.asleep&&($awakeGoroutines--,!$mainFinished&&0===$awakeGoroutines&&$checkForDeadlock&&(console.error("fatal error: all goroutines are asleep - deadlock!"),void 0!==$global.process&&$global.process.exit(2)))}};r.asleep=!1,r.exit=!1,r.deferStack=[],r.panicStack=[],$schedule(r)},$scheduled=[],$runScheduled=function(){try{for(var e;void 0!==(e=$scheduled.shift());)e()}finally{$scheduled.length>0&&setTimeout($runScheduled,0)}},$schedule=function(e){e.asleep&&(e.asleep=!1,$awakeGoroutines++),$scheduled.push(e),$curGoroutine===$noGoroutine&&$runScheduled()},$setTimeout=function(e,n){return $awakeGoroutines++,setTimeout(function(){$awakeGoroutines--,e()},n)},$block=function(){$curGoroutine===$noGoroutine&&$throwRuntimeError("cannot block in JavaScript callback, fix by wrapping code in goroutine"),$curGoroutine.asleep=!0},$send=function(e,n){e.$closed&&$throwRuntimeError("send on closed channel");var r=e.$recvQueue.shift();if(void 0===r){if(!(e.$buffer.length65535){var u=Math.floor((c-65536)/1024)+55296,l=(c-65536)%1024+56320;$+=String.fromCharCode(u,l)}else $+=String.fromCharCode(c)}return $;case $kindStruct:var s=$packages.time;if(void 0!==s&&e.constructor===s.Time.ptr){var f=$div64(e.UnixNano(),new $Int64(0,1e6));return new Date($flatten64(f))}var d={},p=function(e,n){if(n===$jsObjectPtr)return e;switch(n.kind){case $kindPtr:return e===n.nil?d:p(e.$get(),n.elem);case $kindStruct:var r=n.fields[0];return p(e[r.prop],r.typ);case $kindInterface:return p(e.$val,e.constructor);default:return d}},h=p(e,n);if(h!==d)return h;h={};for(i=0;i>24;case $kindInt16:return parseInt(e)<<16>>16;case $kindInt32:return parseInt(e)>>0;case $kindUint:return parseInt(e);case $kindUint8:return parseInt(e)<<24>>>24;case $kindUint16:return parseInt(e)<<16>>>16;case $kindUint32:case $kindUintptr:return parseInt(e)>>>0;case $kindInt64:case $kindUint64:return new n(0,e);case $kindFloat32:case $kindFloat64:return parseFloat(e);case $kindArray:return e.length!==n.len&&$throwRuntimeError("got array with wrong size from JavaScript native"),$mapArray(e,function(e){return $internalize(e,n.elem)});case $kindFunc:return function(){for(var t=[],i=0;i=128)return!1;return!0};` -const preludeMinified = `var $global,$module;if(Error.stackTraceLimit=1/0,"undefined"!=typeof window?$global=window:"undefined"!=typeof self?$global=self:"undefined"!=typeof global?($global=global).require=require:$global=this,void 0===$global||void 0===$global.Array)throw new Error("no global object found");"undefined"!=typeof module&&($module=module);var $throwRuntimeError,$packages={},$idCounter=0,$keys=function(r){return r?Object.keys(r):[]},$flushConsole=function(){},$throwNilPointerError=function(){$throwRuntimeError("invalid memory address or nil pointer dereference")},$call=function(r,e,t){return r.apply(e,t)},$makeFunc=function(r){return function(){return $externalize(r(this,new($sliceType($jsObjectPtr))($global.Array.prototype.slice.call(arguments,[]))),$emptyInterface)}},$unused=function(r){},$mapArray=function(r,e){for(var t=new r.constructor(r.length),n=0;nr.$capacity||n>r.$capacity)&&$throwRuntimeError("slice bounds out of range");var o=new r.constructor(r.$array);return o.$offset=r.$offset+e,o.$length=r.$length-e,o.$capacity=r.$capacity-e,void 0!==t&&(o.$length=t-e),void 0!==n&&(o.$capacity=n-e),o},$substring=function(r,e,t){return(e<0||tr.length)&&$throwRuntimeError("slice bounds out of range"),r.substring(e,t)},$sliceToArray=function(r){return r.$array.constructor!==Array?r.$array.subarray(r.$offset,r.$offset+r.$length):r.$array.slice(r.$offset,r.$offset+r.$length)},$decodeRune=function(r,e){var t=r.charCodeAt(e);if(t<128)return[t,1];if(t!=t||t<192)return[65533,1];var n=r.charCodeAt(e+1);if(n!=n||n<128||192<=n)return[65533,1];if(t<224)return(a=(31&t)<<6|63&n)<=127?[65533,1]:[a,2];var o=r.charCodeAt(e+2);if(o!=o||o<128||192<=o)return[65533,1];if(t<240)return(a=(15&t)<<12|(63&n)<<6|63&o)<=2047?[65533,1]:55296<=a&&a<=57343?[65533,1]:[a,3];var a,i=r.charCodeAt(e+3);return i!=i||i<128||192<=i?[65533,1]:t<248?(a=(7&t)<<18|(63&n)<<12|(63&o)<<6|63&i)<=65535||11141111114111||55296<=r&&r<=57343)&&(r=65533),r<=127?String.fromCharCode(r):r<=2047?String.fromCharCode(192|r>>6,128|63&r):r<=65535?String.fromCharCode(224|r>>12,128|r>>6&63,128|63&r):String.fromCharCode(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r)},$stringToBytes=function(r){for(var e=new Uint8Array(r.length),t=0;tn){for(var i=o-1;i>=0;i--)a.copy(r[t+i],e[n+i]);return}for(i=0;in)for(i=o-1;i>=0;i--)r[t+i]=e[n+i];else for(i=0;i$)if(a=0,$=Math.max(i,r.$capacity<1024?2*r.$capacity:Math.floor(5*r.$capacity/4)),r.$array.constructor===Array){(o=r.$array.slice(r.$offset,r.$offset+r.$length)).length=$;for(var c=r.constructor.elem.zero,f=r.$length;f<$;f++)o[f]=c()}else(o=new r.$array.constructor($)).set(r.$array.subarray(r.$offset,r.$offset+r.$length));$copyArray(o,e,a+r.$length,t,n,r.constructor.elem);var u=new r.constructor(o);return u.$offset=a,u.$length=i,u.$capacity=$,u},$equal=function(r,e,t){if(t===$jsObjectPtr)return r===e;switch(t.kind){case $kindComplex64:case $kindComplex128:return r.$real===e.$real&&r.$imag===e.$imag;case $kindInt64:case $kindUint64:return r.$high===e.$high&&r.$low===e.$low;case $kindArray:if(r.length!==e.length)return!1;for(var n=0;n>0,this.$low=t>>>0,this.$val=this}).keyFor=function(n){return n.$high+"$"+n.$low};break;case $kindUint64:($=function(n,t){this.$high=n+Math.floor(Math.ceil(t)/4294967296)>>>0,this.$low=t>>>0,this.$val=this}).keyFor=function(n){return n.$high+"$"+n.$low};break;case $kindComplex64:($=function(n,t){this.$real=$fround(n),this.$imag=$fround(t),this.$val=this}).keyFor=function(n){return n.$real+"$"+n.$imag};break;case $kindComplex128:($=function(n,t){this.$real=n,this.$imag=t,this.$val=this}).keyFor=function(n){return n.$real+"$"+n.$imag};break;case $kindArray:($=function(n){this.$val=n}).wrapped=!0,$.ptr=$newType(4,$kindPtr,"*"+e,!1,"",!1,function(n){this.$get=function(){return n},this.$set=function(n){$.copy(this,n)},this.$val=n}),$.init=function(n,t){$.elem=n,$.len=t,$.comparable=n.comparable,$.keyFor=function(t){return Array.prototype.join.call($mapArray(t,function(t){return String(n.keyFor(t)).replace(/\\/g,"\\\\").replace(/\$/g,"\\$")}),"$")},$.copy=function(t,e){$copyArray(t,e,0,0,e.length,n)},$.ptr.init($),Object.defineProperty($.ptr.nil,"nilCheck",{get:$throwNilPointerError})};break;case $kindChan:($=function(n){this.$val=n}).wrapped=!0,$.keyFor=$idKey,$.init=function(n,t,e){$.elem=n,$.sendOnly=t,$.recvOnly=e};break;case $kindFunc:($=function(n){this.$val=n}).wrapped=!0,$.init=function(n,t,e){$.params=n,$.results=t,$.variadic=e,$.comparable=!1};break;case $kindInterface:($={implementedBy:{},missingMethodFor:{}}).keyFor=$ifaceKeyFor,$.init=function(n){$.methods=n,n.forEach(function(n){$ifaceNil[n.prop]=$throwNilPointerError})};break;case $kindMap:($=function(n){this.$val=n}).wrapped=!0,$.init=function(n,t){$.key=n,$.elem=t,$.comparable=!1};break;case $kindPtr:($=o||function(n,t,e){this.$get=n,this.$set=t,this.$target=e,this.$val=this}).keyFor=$idKey,$.init=function(n){$.elem=n,$.wrapped=n.kind===$kindArray,$.nil=new $($throwNilPointerError,$throwNilPointerError)};break;case $kindSlice:($=function(n){n.constructor!==$.nativeArray&&(n=new $.nativeArray(n)),this.$array=n,this.$offset=0,this.$length=n.length,this.$capacity=n.length,this.$val=this}).init=function(n){$.elem=n,$.comparable=!1,$.nativeArray=$nativeArray(n.kind),$.nil=new $([])};break;case $kindStruct:($=function(n){this.$val=n}).wrapped=!0,$.ptr=$newType(4,$kindPtr,"*"+e,!1,i,a,o),$.ptr.elem=$,$.ptr.prototype.$get=function(){return this},$.ptr.prototype.$set=function(n){$.copy(this,n)},$.init=function(n,t){$.pkgPath=n,$.fields=t,t.forEach(function(n){n.typ.comparable||($.comparable=!1)}),$.keyFor=function(n){var e=n.$val;return $mapArray(t,function(n){return String(n.typ.keyFor(e[n.prop])).replace(/\\/g,"\\\\").replace(/\$/g,"\\$")}).join("$")},$.copy=function(n,e){for(var r=0;r0;){var a=[],o=[];r.forEach(function(n){if(!i[n.typ.string])switch(i[n.typ.string]=!0,n.typ.named&&(o=o.concat(n.typ.methods),n.indirect&&(o=o.concat($ptrType(n.typ).methods))),n.typ.kind){case $kindStruct:n.typ.fields.forEach(function(t){if(t.anonymous){var e=t.typ,r=e.kind===$kindPtr;a.push({typ:r?e.elem:e,indirect:n.indirect||r})}});break;case $kindInterface:o=o.concat(n.typ.methods)}}),o.forEach(function(n){void 0===t[n.name]&&(t[n.name]=n)}),r=a}n.methodSetCache=[];var $=Object.keys(t).sort();return 2===$.length&&"nonexported"===$[0]&&"ΦExported"===$[1]&&($[0]="ΦExported",$[1]="nonexported"),$.forEach(function(e){n.methodSetCache.push(t[e])}),n.methodSetCache},$Bool=$newType(1,$kindBool,"bool",!0,"",!1,null),$Int=$newType(4,$kindInt,"int",!0,"",!1,null),$Int8=$newType(1,$kindInt8,"int8",!0,"",!1,null),$Int16=$newType(2,$kindInt16,"int16",!0,"",!1,null),$Int32=$newType(4,$kindInt32,"int32",!0,"",!1,null),$Int64=$newType(8,$kindInt64,"int64",!0,"",!1,null),$Uint=$newType(4,$kindUint,"uint",!0,"",!1,null),$Uint8=$newType(1,$kindUint8,"uint8",!0,"",!1,null),$Uint16=$newType(2,$kindUint16,"uint16",!0,"",!1,null),$Uint32=$newType(4,$kindUint32,"uint32",!0,"",!1,null),$Uint64=$newType(8,$kindUint64,"uint64",!0,"",!1,null),$Uintptr=$newType(4,$kindUintptr,"uintptr",!0,"",!1,null),$Float32=$newType(4,$kindFloat32,"float32",!0,"",!1,null),$Float64=$newType(8,$kindFloat64,"float64",!0,"",!1,null),$Complex64=$newType(8,$kindComplex64,"complex64",!0,"",!1,null),$Complex128=$newType(16,$kindComplex128,"complex128",!0,"",!1,null),$String=$newType(8,$kindString,"string",!0,"",!1,null),$UnsafePointer=$newType(4,$kindUnsafePointer,"unsafe.Pointer",!0,"",!1,null),$nativeArray=function(n){switch(n){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:case $kindUintptr:return Uint32Array;case $kindFloat32:return Float32Array;case $kindFloat64:return Float64Array;default:return Array}},$toNativeArray=function(n,t){var e=$nativeArray(n);return e===Array?t:new e(t)},$arrayTypes={},$arrayType=function(n,t){var e=n.id+"$"+t,r=$arrayTypes[e];return void 0===r&&(r=$newType(12,$kindArray,"["+t+"]"+n.string,!1,"",!1,null),$arrayTypes[e]=r,r.init(n,t)),r},$chanType=function(n,t,e){var r=(e?"<-":"")+"chan"+(t?"<- ":" ")+n.string,i=t?"SendChan":e?"RecvChan":"Chan",a=n[i];return void 0===a&&(a=$newType(4,$kindChan,r,!1,"",!1,null),n[i]=a,a.init(n,t,e)),a},$Chan=function(n,t){(t<0||t>2147483647)&&$throwRuntimeError("makechan: size out of range"),this.$elem=n,this.$capacity=t,this.$buffer=[],this.$sendQueue=[],this.$recvQueue=[],this.$closed=!1},$chanNil=new $Chan(null,0);$chanNil.$sendQueue=$chanNil.$recvQueue={length:0,push:function(){},shift:function(){},indexOf:function(){return-1}};var $funcTypes={},$funcType=function(n,t,e){var r=$mapArray(n,function(n){return n.id}).join(",")+"$"+$mapArray(t,function(n){return n.id}).join(",")+"$"+e,i=$funcTypes[r];if(void 0===i){var a=$mapArray(n,function(n){return n.string});e&&(a[a.length-1]="..."+a[a.length-1].substr(2));var o="func("+a.join(", ")+")";1===t.length?o+=" "+t[0].string:t.length>1&&(o+=" ("+$mapArray(t,function(n){return n.string}).join(", ")+")"),i=$newType(4,$kindFunc,o,!1,"",!1,null),$funcTypes[r]=i,i.init(n,t,e)}return i},$interfaceTypes={},$interfaceType=function(n){var t=$mapArray(n,function(n){return n.pkg+","+n.name+","+n.typ.id}).join("$"),e=$interfaceTypes[t];if(void 0===e){var r="interface {}";0!==n.length&&(r="interface { "+$mapArray(n,function(n){return(""!==n.pkg?n.pkg+".":"")+n.name+n.typ.string.substr(4)}).join("; ")+" }"),e=$newType(8,$kindInterface,r,!1,"",!1,null),$interfaceTypes[t]=e,e.init(n)}return e},$emptyInterface=$interfaceType([]),$ifaceNil={},$error=$newType(8,$kindInterface,"error",!0,"",!1,null);$error.init([{prop:"Error",name:"Error",pkg:"",typ:$funcType([],[$String],!1)}]);var $mapTypes={},$mapType=function(n,t){var e=n.id+"$"+t.id,r=$mapTypes[e];return void 0===r&&(r=$newType(4,$kindMap,"map["+n.string+"]"+t.string,!1,"",!1,null),$mapTypes[e]=r,r.init(n,t)),r},$makeMap=function(n,t){for(var e={},r=0;r2147483647)&&$throwRuntimeError("makeslice: len out of range"),(e<0||e2147483647)&&$throwRuntimeError("makeslice: cap out of range");var r=new n.nativeArray(e);if(n.nativeArray===Array)for(var i=0;i