JS: use ES6 arrow functions and let where possible

This commit is contained in:
Alexey Andreev 2023-11-02 21:10:35 +01:00
parent 6738d6f1f8
commit ceffde38f3
15 changed files with 632 additions and 771 deletions

View File

@ -197,6 +197,20 @@ public class OutputSourceWriter extends SourceWriter implements LocationProvider
return this; return this;
} }
@Override
public SourceWriter sameLineWs() {
if (!minified) {
try {
innerWriter.append(' ');
} catch (IOException e) {
throw new RuntimeException(e);
}
column++;
offset++;
}
return this;
}
@Override @Override
public SourceWriter tokenBoundary() { public SourceWriter tokenBoundary() {
if (column >= lineWidth) { if (column >= lineWidth) {

View File

@ -139,6 +139,12 @@ public class RememberedSource implements SourceFragment {
} }
break; break;
case RememberingSourceWriter.SAME_LINE_WS:
if ((filter & FILTER_TEXT) != 0) {
sink.sameLineWs();
}
break;
case RememberingSourceWriter.TOKEN_BOUNDARY: case RememberingSourceWriter.TOKEN_BOUNDARY:
if ((filter & FILTER_TEXT) != 0) { if ((filter & FILTER_TEXT) != 0) {
sink.tokenBoundary(); sink.tokenBoundary();

View File

@ -37,6 +37,7 @@ public class RememberingSourceWriter extends SourceWriter {
static final byte CLASS_INIT = 8; static final byte CLASS_INIT = 8;
static final byte NEW_LINE = 9; static final byte NEW_LINE = 9;
static final byte WS = 10; static final byte WS = 10;
static final byte SAME_LINE_WS = 21;
static final byte TOKEN_BOUNDARY = 11; static final byte TOKEN_BOUNDARY = 11;
static final byte SOFT_NEW_LINE = 12; static final byte SOFT_NEW_LINE = 12;
static final byte INDENT = 13; static final byte INDENT = 13;
@ -184,6 +185,13 @@ public class RememberingSourceWriter extends SourceWriter {
return this; return this;
} }
@Override
public SourceWriter sameLineWs() {
flush();
commands.add(SAME_LINE_WS);
return this;
}
@Override @Override
public SourceWriter tokenBoundary() { public SourceWriter tokenBoundary() {
flush(); flush();

View File

@ -111,6 +111,9 @@ public abstract class SourceWriter implements Appendable, SourceWriterSink {
@Override @Override
public abstract SourceWriter ws(); public abstract SourceWriter ws();
@Override
public abstract SourceWriter sameLineWs();
@Override @Override
public abstract SourceWriter tokenBoundary(); public abstract SourceWriter tokenBoundary();

View File

@ -68,6 +68,10 @@ public interface SourceWriterSink {
return this; return this;
} }
default SourceWriterSink sameLineWs() {
return this;
}
default SourceWriterSink tokenBoundary() { default SourceWriterSink tokenBoundary() {
return this; return this;
} }

View File

@ -738,12 +738,14 @@ public class AstWriter {
if (!isArrow || node.getParams().size() != 1) { if (!isArrow || node.getParams().size() != 1) {
writer.append('('); writer.append('(');
printList(node.getParams()); printList(node.getParams());
writer.append(')').ws(); writer.append(')');
} else { } else {
print(node.getParams().get(0)); print(node.getParams().get(0));
} }
if (isArrow) { if (isArrow) {
writer.append("=>").ws(); writer.sameLineWs().append("=>").ws();
} else {
writer.ws();
} }
if (node.isExpressionClosure()) { if (node.isExpressionClosure()) {

View File

@ -126,12 +126,19 @@ public class MethodBodyRenderer implements MethodNodeVisitor, GeneratorContext {
if (modifiers.contains(ElementModifier.STATIC)) { if (modifiers.contains(ElementModifier.STATIC)) {
startParam = 1; startParam = 1;
} }
var count = reference.parameterCount() - startParam + 1;
if (count != 1) {
writer.append("(");
}
for (int i = startParam; i <= reference.parameterCount(); ++i) { for (int i = startParam; i <= reference.parameterCount(); ++i) {
if (i > startParam) { if (i > startParam) {
writer.append(",").ws(); writer.append(",").ws();
} }
writer.append(statementRenderer.variableName(i)); writer.append(statementRenderer.variableName(i));
} }
if (count != 1) {
writer.append(")");
}
parameters = writer.save(); parameters = writer.save();
writer.clear(); writer.clear();
} }
@ -165,7 +172,7 @@ public class MethodBodyRenderer implements MethodNodeVisitor, GeneratorContext {
variableNames.add("$$je"); variableNames.add("$$je");
} }
if (!variableNames.isEmpty()) { if (!variableNames.isEmpty()) {
writer.append("var "); writer.append("let ");
for (int i = 0; i < variableNames.size(); ++i) { for (int i = 0; i < variableNames.size(); ++i) {
if (i > 0) { if (i > 0) {
writer.append(",").ws(); writer.append(",").ws();
@ -227,7 +234,7 @@ public class MethodBodyRenderer implements MethodNodeVisitor, GeneratorContext {
} }
variableNames.add(context.pointerName()); variableNames.add(context.pointerName());
variableNames.add(context.tempVarName()); variableNames.add(context.tempVarName());
writer.append("var "); writer.append("let ");
for (int i = 0; i < variableNames.size(); ++i) { for (int i = 0; i < variableNames.size(); ++i) {
if (i > 0) { if (i > 0) {
writer.append(",").ws(); writer.append(",").ws();
@ -246,7 +253,7 @@ public class MethodBodyRenderer implements MethodNodeVisitor, GeneratorContext {
writer.append(context.pointerName()).ws().append('=').ws().append("0;").softNewLine(); writer.append(context.pointerName()).ws().append('=').ws().append("0;").softNewLine();
writer.append("if").ws().append("(").appendFunction("$rt_resuming").append("())").ws() writer.append("if").ws().append("(").appendFunction("$rt_resuming").append("())").ws()
.append("{").indent().softNewLine(); .append("{").indent().softNewLine();
writer.append("var ").append(context.threadName()).ws().append('=').ws() writer.append("let ").append(context.threadName()).ws().append('=').ws()
.appendFunction("$rt_nativeThread").append("();").softNewLine(); .appendFunction("$rt_nativeThread").append("();").softNewLine();
writer.append(context.pointerName()).ws().append('=').ws().append(context.threadName()).append(".") writer.append(context.pointerName()).ws().append('=').ws().append(context.threadName()).append(".")
.append(popName).append("();"); .append(popName).append("();");

View File

@ -184,7 +184,7 @@ public class Renderer implements RenderingManager {
private void renderJavaStringToString() { private void renderJavaStringToString() {
writer.appendClass("java.lang.String").append(".prototype.toString").ws().append("=").ws().append("()") writer.appendClass("java.lang.String").append(".prototype.toString").ws().append("=").ws().append("()")
.ws().append("=>").ws().append("{").indent().softNewLine(); .sameLineWs().append("=>").ws().append("{").indent().softNewLine();
writer.append("return ").appendFunction("$rt_ustr").append("(this);").softNewLine(); writer.append("return ").appendFunction("$rt_ustr").append("(this);").softNewLine();
writer.outdent().append("};").newLine(); writer.outdent().append("};").newLine();
writer.appendClass("java.lang.String").append(".prototype.valueOf").ws().append("=").ws() writer.appendClass("java.lang.String").append(".prototype.valueOf").ws().append("=").ws()
@ -193,7 +193,7 @@ public class Renderer implements RenderingManager {
private void renderJavaObjectToString() { private void renderJavaObjectToString() {
writer.appendClass("java.lang.Object").append(".prototype.toString").ws().append("=").ws() writer.appendClass("java.lang.Object").append(".prototype.toString").ws().append("=").ws()
.append("()").ws().append("=>").ws().append("{").indent().softNewLine(); .append("()").sameLineWs().append("=>").ws().append("{").indent().softNewLine();
writer.append("return ").appendFunction("$rt_ustr").append("(") writer.append("return ").appendFunction("$rt_ustr").append("(")
.appendMethodBody(Object.class, "toString", String.class).append("(this));") .appendMethodBody(Object.class, "toString", String.class).append("(this));")
.softNewLine(); .softNewLine();
@ -274,7 +274,7 @@ public class Renderer implements RenderingManager {
if (fieldName.scoped) { if (fieldName.scoped) {
writer.append(naming.getScopeName()).append("."); writer.append(naming.getScopeName()).append(".");
} else { } else {
writer.append("var "); writer.append("let ");
} }
writer.append(fieldName.value).ws().append("=").ws(); writer.append(fieldName.value).ws().append("=").ws();
context.constantToString(writer, value); context.constantToString(writer, value);
@ -289,7 +289,7 @@ public class Renderer implements RenderingManager {
writer.append("()").ws().append("{").indent().softNewLine(); writer.append("()").ws().append("{").indent().softNewLine();
if (nonStaticFields.size() > 1) { if (nonStaticFields.size() > 1) {
thisAliased = true; thisAliased = true;
writer.append("var a").ws().append("=").ws().append("this;").ws(); writer.append("let a").ws().append("=").ws().append("this;").ws();
} }
if (!cls.getClassHolder().getModifiers().contains(ElementModifier.INTERFACE) if (!cls.getClassHolder().getModifiers().contains(ElementModifier.INTERFACE)
&& cls.getParentName() != null) { && cls.getParentName() != null) {
@ -324,7 +324,7 @@ public class Renderer implements RenderingManager {
if (jsName.scoped) { if (jsName.scoped) {
writer.append(naming.getScopeName()).append("."); writer.append(naming.getScopeName()).append(".");
} else { } else {
writer.append("var "); writer.append("let ");
} }
writer.append(jsName.value).ws().append("=").ws().appendFunction("$rt_classWithoutFields").append("("); writer.append(jsName.value).ws().append("=").ws().appendFunction("$rt_classWithoutFields").append("(");
if (cls.getClassHolder().hasModifier(ElementModifier.INTERFACE)) { if (cls.getClassHolder().hasModifier(ElementModifier.INTERFACE)) {
@ -368,15 +368,15 @@ public class Renderer implements RenderingManager {
String clinitCalled = (className.scoped ? naming.getScopeName() + "_" : "") + className.value String clinitCalled = (className.scoped ? naming.getScopeName() + "_" : "") + className.value
+ "_$clinitCalled"; + "_$clinitCalled";
if (isAsync) { if (isAsync) {
writer.append("var ").append(clinitCalled).ws().append("=").ws().append("false;").softNewLine(); writer.append("let ").append(clinitCalled).ws().append("=").ws().append("false;").softNewLine();
} }
ScopedName name = naming.getNameForClassInit(cls.getName()); ScopedName name = naming.getNameForClassInit(cls.getName());
renderFunctionDeclaration(name); renderLambdaDeclaration(name);
writer.append("()").ws().append("{").softNewLine().indent(); writer.append("()").sameLineWs().append("=>").ws().append("{").softNewLine().indent();
if (isAsync) { if (isAsync) {
writer.append("var ").append(context.pointerName()).ws().append("=").ws() writer.append("let ").append(context.pointerName()).ws().append("=").ws()
.append("0").append(";").softNewLine(); .append("0").append(";").softNewLine();
writer.append("if").ws().append("(").appendFunction("$rt_resuming").append("())").ws().append("{") writer.append("if").ws().append("(").appendFunction("$rt_resuming").append("())").ws().append("{")
.indent().softNewLine(); .indent().softNewLine();
@ -690,18 +690,23 @@ public class Renderer implements RenderingManager {
MethodReference ref = method.reference; MethodReference ref = method.reference;
debugEmitter.emitMethod(ref.getDescriptor()); debugEmitter.emitMethod(ref.getDescriptor());
ScopedName name = naming.getNameForInit(ref); ScopedName name = naming.getNameForInit(ref);
renderFunctionDeclaration(name); renderLambdaDeclaration(name);
writer.append("("); if (ref.parameterCount() != 1) {
writer.append("(");
}
for (int i = 0; i < ref.parameterCount(); ++i) { for (int i = 0; i < ref.parameterCount(); ++i) {
if (i > 0) { if (i > 0) {
writer.append(",").ws(); writer.append(",").ws();
} }
writer.append(variableNameForInitializer(i)); writer.append(variableNameForInitializer(i));
} }
writer.append(")").ws().append("{").softNewLine().indent(); if (ref.parameterCount() != 1) {
writer.append(")");
}
writer.sameLineWs().append("=>").ws().append("{").softNewLine().indent();
String instanceName = variableNameForInitializer(ref.parameterCount()); String instanceName = variableNameForInitializer(ref.parameterCount());
writer.append("var " + instanceName).ws().append("=").ws().append("new ").appendClass( writer.append("let " + instanceName).ws().append("=").ws().append("new ").appendClass(
ref.getClassName()).append("();").softNewLine(); ref.getClassName()).append("();").softNewLine();
writer.appendMethodBody(ref).append("(" + instanceName); writer.appendMethodBody(ref).append("(" + instanceName);
for (int i = 0; i < ref.parameterCount(); ++i) { for (int i = 0; i < ref.parameterCount(); ++i) {
@ -787,15 +792,14 @@ public class Renderer implements RenderingManager {
debugEmitter.emitMethod(ref.getDescriptor()); debugEmitter.emitMethod(ref.getDescriptor());
ScopedName name = naming.getFullNameFor(ref); ScopedName name = naming.getFullNameFor(ref);
renderFunctionDeclaration(name); renderLambdaDeclaration(name);
writer.append("(");
method.parameters.replay(writer, RememberedSource.FILTER_ALL); method.parameters.replay(writer, RememberedSource.FILTER_ALL);
if (method.variables != null) { if (method.variables != null) {
for (var variable : method.variables) { for (var variable : method.variables) {
variable.emit(debugEmitter); variable.emit(debugEmitter);
} }
} }
writer.append(")").ws().append("{").indent().softNewLine(); writer.sameLineWs().append("=>").ws().append("{").indent().softNewLine();
method.body.replay(writer, RememberedSource.FILTER_ALL); method.body.replay(writer, RememberedSource.FILTER_ALL);
writer.outdent().append("}"); writer.outdent().append("}");
@ -807,6 +811,15 @@ public class Renderer implements RenderingManager {
debugEmitter.emitMethod(null); debugEmitter.emitMethod(null);
} }
private void renderLambdaDeclaration(ScopedName name) {
if (name.scoped) {
writer.append(naming.getScopeName()).append(".").append(name.value);
} else {
writer.append("let ").append(name.value);
}
writer.ws().append("=").ws();
}
private void renderFunctionDeclaration(ScopedName name) { private void renderFunctionDeclaration(ScopedName name) {
if (name.scoped) { if (name.scoped) {
writer.append(naming.getScopeName()).append(".").append(name.value).ws().append("=").ws(); writer.append(naming.getScopeName()).append(".").append(name.value).ws().append("=").ws();

View File

@ -14,11 +14,11 @@
* limitations under the License. * limitations under the License.
*/ */
var $rt_booleanArrayCls = $rt_arraycls($rt_booleancls); let $rt_booleanArrayCls = $rt_arraycls($rt_booleancls);
var $rt_charArrayCls = $rt_arraycls($rt_charcls); let $rt_charArrayCls = $rt_arraycls($rt_charcls);
var $rt_byteArrayCls = $rt_arraycls($rt_bytecls); let $rt_byteArrayCls = $rt_arraycls($rt_bytecls);
var $rt_shortArrayCls = $rt_arraycls($rt_shortcls); let $rt_shortArrayCls = $rt_arraycls($rt_shortcls);
var $rt_intArrayCls = $rt_arraycls($rt_intcls); let $rt_intArrayCls = $rt_arraycls($rt_intcls);
var $rt_longArrayCls = $rt_arraycls($rt_longcls); let $rt_longArrayCls = $rt_arraycls($rt_longcls);
var $rt_floatArrayCls = $rt_arraycls($rt_floatcls); let $rt_floatArrayCls = $rt_arraycls($rt_floatcls);
var $rt_doubleArrayCls = $rt_arraycls($rt_doublecls); let $rt_doubleArrayCls = $rt_arraycls($rt_doublecls);

View File

@ -15,21 +15,21 @@
*/ */
"use strict"; "use strict";
var $rt_intern let $rt_intern
if (teavm_javaMethodExists("java.lang.String", "intern()Ljava/lang/String;")) { if (teavm_javaMethodExists("java.lang.String", "intern()Ljava/lang/String;")) {
$rt_intern = function() { $rt_intern = function() {
var map = teavm_globals.Object.create(null); let map = teavm_globals.Object.create(null);
var get; let get;
if (typeof teavm_globals.WeakRef !== 'undefined') { if (typeof teavm_globals.WeakRef !== 'undefined') {
var registry = new teavm_globals.FinalizationRegistry(value => { let registry = new teavm_globals.FinalizationRegistry(value => {
delete map[value]; delete map[value];
}); });
get = function (str) { get = str => {
var key = $rt_ustr(str); let key = $rt_ustr(str);
var ref = map[key]; let ref = map[key];
var result = typeof ref !== 'undefined' ? ref.deref() : void 0; let result = typeof ref !== 'undefined' ? ref.deref() : void 0;
if (typeof result !== 'object') { if (typeof result !== 'object') {
result = str; result = str;
map[key] = new teavm_globals.WeakRef(result); map[key] = new teavm_globals.WeakRef(result);
@ -38,9 +38,9 @@ if (teavm_javaMethodExists("java.lang.String", "intern()Ljava/lang/String;")) {
return result; return result;
} }
} else { } else {
get = function (str) { get = str => {
var key = $rt_ustr(str); let key = $rt_ustr(str);
var result = map[key]; let result = map[key];
if (typeof result !== 'object') { if (typeof result !== 'object') {
result = str; result = str;
map[key] = result; map[key] = result;
@ -52,7 +52,5 @@ if (teavm_javaMethodExists("java.lang.String", "intern()Ljava/lang/String;")) {
return get; return get;
}(); }();
} else { } else {
$rt_intern = function(str) { $rt_intern = str => str;
return str;
}
} }

View File

@ -15,167 +15,161 @@
*/ */
"use strict"; "use strict";
var Long_eq; let Long_eq;
var Long_ne; let Long_ne;
var Long_gt; let Long_gt;
var Long_ge; let Long_ge;
var Long_lt; let Long_lt;
var Long_le; let Long_le;
var Long_compare; let Long_compare;
var Long_ucompare; let Long_ucompare;
var Long_add; let Long_add;
var Long_sub; let Long_sub;
var Long_inc; let Long_inc;
var Long_dec; let Long_dec;
var Long_mul; let Long_mul;
var Long_div; let Long_div;
var Long_rem; let Long_rem;
var Long_udiv; let Long_udiv;
var Long_urem; let Long_urem;
var Long_neg; let Long_neg;
var Long_and; let Long_and;
var Long_or; let Long_or;
var Long_xor; let Long_xor;
var Long_shl; let Long_shl;
var Long_shr; let Long_shr;
var Long_shru; let Long_shru;
var Long_not; let Long_not;
if (typeof teavm_globals.BigInt !== 'function') { if (typeof teavm_globals.BigInt !== 'function') {
Long_eq = function(a, b) { Long_eq = (a, b) => a.hi === b.hi && a.lo === b.lo;
return a.hi === b.hi && a.lo === b.lo;
}
Long_ne = function(a, b) { Long_ne = (a, b) => a.hi !== b.hi || a.lo !== b.lo;
return a.hi !== b.hi || a.lo !== b.lo;
}
Long_gt = function(a, b) { Long_gt = (a, b) => {
if (a.hi < b.hi) { if (a.hi < b.hi) {
return false; return false;
} }
if (a.hi > b.hi) { if (a.hi > b.hi) {
return true; return true;
} }
var x = a.lo >>> 1; let x = a.lo >>> 1;
var y = b.lo >>> 1; let y = b.lo >>> 1;
if (x !== y) { if (x !== y) {
return x > y; return x > y;
} }
return (a.lo & 1) > (b.lo & 1); return (a.lo & 1) > (b.lo & 1);
} }
Long_ge = function(a, b) { Long_ge = (a, b) => {
if (a.hi < b.hi) { if (a.hi < b.hi) {
return false; return false;
} }
if (a.hi > b.hi) { if (a.hi > b.hi) {
return true; return true;
} }
var x = a.lo >>> 1; let x = a.lo >>> 1;
var y = b.lo >>> 1; let y = b.lo >>> 1;
if (x !== y) { if (x !== y) {
return x >= y; return x >= y;
} }
return (a.lo & 1) >= (b.lo & 1); return (a.lo & 1) >= (b.lo & 1);
} }
Long_lt = function(a, b) { Long_lt = (a, b) => {
if (a.hi > b.hi) { if (a.hi > b.hi) {
return false; return false;
} }
if (a.hi < b.hi) { if (a.hi < b.hi) {
return true; return true;
} }
var x = a.lo >>> 1; let x = a.lo >>> 1;
var y = b.lo >>> 1; let y = b.lo >>> 1;
if (x !== y) { if (x !== y) {
return x < y; return x < y;
} }
return (a.lo & 1) < (b.lo & 1); return (a.lo & 1) < (b.lo & 1);
} }
Long_le = function(a, b) { Long_le = (a, b) => {
if (a.hi > b.hi) { if (a.hi > b.hi) {
return false; return false;
} }
if (a.hi < b.hi) { if (a.hi < b.hi) {
return true; return true;
} }
var x = a.lo >>> 1; let x = a.lo >>> 1;
var y = b.lo >>> 1; let y = b.lo >>> 1;
if (x !== y) { if (x !== y) {
return x <= y; return x <= y;
} }
return (a.lo & 1) <= (b.lo & 1); return (a.lo & 1) <= (b.lo & 1);
} }
Long_add = function(a, b) { Long_add = (a, b) => {
if (a.hi === (a.lo >> 31) && b.hi === (b.lo >> 31)) { if (a.hi === (a.lo >> 31) && b.hi === (b.lo >> 31)) {
return Long_fromNumber(a.lo + b.lo); return Long_fromNumber(a.lo + b.lo);
} else if (Math.abs(a.hi) < Long_MAX_NORMAL && Math.abs(b.hi) < Long_MAX_NORMAL) { } else if (Math.abs(a.hi) < Long_MAX_NORMAL && Math.abs(b.hi) < Long_MAX_NORMAL) {
return Long_fromNumber(Long_toNumber(a) + Long_toNumber(b)); return Long_fromNumber(Long_toNumber(a) + Long_toNumber(b));
} }
var a_lolo = a.lo & 0xFFFF; let a_lolo = a.lo & 0xFFFF;
var a_lohi = a.lo >>> 16; let a_lohi = a.lo >>> 16;
var a_hilo = a.hi & 0xFFFF; let a_hilo = a.hi & 0xFFFF;
var a_hihi = a.hi >>> 16; let a_hihi = a.hi >>> 16;
var b_lolo = b.lo & 0xFFFF; let b_lolo = b.lo & 0xFFFF;
var b_lohi = b.lo >>> 16; let b_lohi = b.lo >>> 16;
var b_hilo = b.hi & 0xFFFF; let b_hilo = b.hi & 0xFFFF;
var b_hihi = b.hi >>> 16; let b_hihi = b.hi >>> 16;
var lolo = (a_lolo + b_lolo) | 0; let lolo = (a_lolo + b_lolo) | 0;
var lohi = (a_lohi + b_lohi + (lolo >> 16)) | 0; let lohi = (a_lohi + b_lohi + (lolo >> 16)) | 0;
var hilo = (a_hilo + b_hilo + (lohi >> 16)) | 0; let hilo = (a_hilo + b_hilo + (lohi >> 16)) | 0;
var hihi = (a_hihi + b_hihi + (hilo >> 16)) | 0; let hihi = (a_hihi + b_hihi + (hilo >> 16)) | 0;
return new Long((lolo & 0xFFFF) | ((lohi & 0xFFFF) << 16), (hilo & 0xFFFF) | ((hihi & 0xFFFF) << 16)); return new Long((lolo & 0xFFFF) | ((lohi & 0xFFFF) << 16), (hilo & 0xFFFF) | ((hihi & 0xFFFF) << 16));
} }
Long_inc = function(a) { Long_inc = a => {
var lo = (a.lo + 1) | 0; let lo = (a.lo + 1) | 0;
var hi = a.hi; let hi = a.hi;
if (lo === 0) { if (lo === 0) {
hi = (hi + 1) | 0; hi = (hi + 1) | 0;
} }
return new Long(lo, hi); return new Long(lo, hi);
} }
Long_dec = function(a) { Long_dec = a => {
var lo = (a.lo - 1) | 0; let lo = (a.lo - 1) | 0;
var hi = a.hi; let hi = a.hi;
if (lo === -1) { if (lo === -1) {
hi = (hi - 1) | 0; hi = (hi - 1) | 0;
} }
return new Long(lo, hi); return new Long(lo, hi);
} }
Long_neg = function(a) { Long_neg = a => Long_inc(new Long(a.lo ^ 0xFFFFFFFF, a.hi ^ 0xFFFFFFFF))
return Long_inc(new Long(a.lo ^ 0xFFFFFFFF, a.hi ^ 0xFFFFFFFF));
}
Long_sub = function(a, b) { Long_sub = (a, b) => {
if (a.hi === (a.lo >> 31) && b.hi === (b.lo >> 31)) { if (a.hi === (a.lo >> 31) && b.hi === (b.lo >> 31)) {
return Long_fromNumber(a.lo - b.lo); return Long_fromNumber(a.lo - b.lo);
} }
var a_lolo = a.lo & 0xFFFF; let a_lolo = a.lo & 0xFFFF;
var a_lohi = a.lo >>> 16; let a_lohi = a.lo >>> 16;
var a_hilo = a.hi & 0xFFFF; let a_hilo = a.hi & 0xFFFF;
var a_hihi = a.hi >>> 16; let a_hihi = a.hi >>> 16;
var b_lolo = b.lo & 0xFFFF; let b_lolo = b.lo & 0xFFFF;
var b_lohi = b.lo >>> 16; let b_lohi = b.lo >>> 16;
var b_hilo = b.hi & 0xFFFF; let b_hilo = b.hi & 0xFFFF;
var b_hihi = b.hi >>> 16; let b_hihi = b.hi >>> 16;
var lolo = (a_lolo - b_lolo) | 0; let lolo = (a_lolo - b_lolo) | 0;
var lohi = (a_lohi - b_lohi + (lolo >> 16)) | 0; let lohi = (a_lohi - b_lohi + (lolo >> 16)) | 0;
var hilo = (a_hilo - b_hilo + (lohi >> 16)) | 0; let hilo = (a_hilo - b_hilo + (lohi >> 16)) | 0;
var hihi = (a_hihi - b_hihi + (hilo >> 16)) | 0; let hihi = (a_hihi - b_hihi + (hilo >> 16)) | 0;
return new Long((lolo & 0xFFFF) | ((lohi & 0xFFFF) << 16), (hilo & 0xFFFF) | ((hihi & 0xFFFF) << 16)); return new Long((lolo & 0xFFFF) | ((lohi & 0xFFFF) << 16), (hilo & 0xFFFF) | ((hihi & 0xFFFF) << 16));
} }
Long_compare = function(a, b) { Long_compare = (a, b) => {
var r = a.hi - b.hi; let r = a.hi - b.hi;
if (r !== 0) { if (r !== 0) {
return r; return r;
} }
@ -186,8 +180,8 @@ if (typeof teavm_globals.BigInt !== 'function') {
return (a.lo & 1) - (b.lo & 1); return (a.lo & 1) - (b.lo & 1);
} }
Long_ucompare = function(a, b) { Long_ucompare = (a, b) => {
var r = $rt_ucmp(a.hi, b.hi); let r = $rt_ucmp(a.hi, b.hi);
if (r !== 0) { if (r !== 0) {
return r; return r;
} }
@ -198,27 +192,27 @@ if (typeof teavm_globals.BigInt !== 'function') {
return (a.lo & 1) - (b.lo & 1); return (a.lo & 1) - (b.lo & 1);
} }
Long_mul = function(a, b) { Long_mul = (a, b) => {
var positive = Long_isNegative(a) === Long_isNegative(b); let positive = Long_isNegative(a) === Long_isNegative(b);
if (Long_isNegative(a)) { if (Long_isNegative(a)) {
a = Long_neg(a); a = Long_neg(a);
} }
if (Long_isNegative(b)) { if (Long_isNegative(b)) {
b = Long_neg(b); b = Long_neg(b);
} }
var a_lolo = a.lo & 0xFFFF; let a_lolo = a.lo & 0xFFFF;
var a_lohi = a.lo >>> 16; let a_lohi = a.lo >>> 16;
var a_hilo = a.hi & 0xFFFF; let a_hilo = a.hi & 0xFFFF;
var a_hihi = a.hi >>> 16; let a_hihi = a.hi >>> 16;
var b_lolo = b.lo & 0xFFFF; let b_lolo = b.lo & 0xFFFF;
var b_lohi = b.lo >>> 16; let b_lohi = b.lo >>> 16;
var b_hilo = b.hi & 0xFFFF; let b_hilo = b.hi & 0xFFFF;
var b_hihi = b.hi >>> 16; let b_hihi = b.hi >>> 16;
var lolo = 0; let lolo = 0;
var lohi = 0; let lohi = 0;
var hilo = 0; let hilo = 0;
var hihi = 0; let hihi = 0;
lolo = (a_lolo * b_lolo) | 0; lolo = (a_lolo * b_lolo) | 0;
lohi = lolo >>> 16; lohi = lolo >>> 16;
lohi = ((lohi & 0xFFFF) + a_lohi * b_lolo) | 0; lohi = ((lohi & 0xFFFF) + a_lohi * b_lolo) | 0;
@ -233,43 +227,43 @@ if (typeof teavm_globals.BigInt !== 'function') {
hilo = ((hilo & 0xFFFF) + a_lolo * b_hilo) | 0; hilo = ((hilo & 0xFFFF) + a_lolo * b_hilo) | 0;
hihi = (hihi + (hilo >>> 16)) | 0; hihi = (hihi + (hilo >>> 16)) | 0;
hihi = (hihi + a_hihi * b_lolo + a_hilo * b_lohi + a_lohi * b_hilo + a_lolo * b_hihi) | 0; hihi = (hihi + a_hihi * b_lolo + a_hilo * b_lohi + a_lohi * b_hilo + a_lolo * b_hihi) | 0;
var result = new Long((lolo & 0xFFFF) | (lohi << 16), (hilo & 0xFFFF) | (hihi << 16)); let result = new Long((lolo & 0xFFFF) | (lohi << 16), (hilo & 0xFFFF) | (hihi << 16));
return positive ? result : Long_neg(result); return positive ? result : Long_neg(result);
} }
Long_div = function(a, b) { Long_div = (a, b) => {
if (Math.abs(a.hi) < Long_MAX_NORMAL && Math.abs(b.hi) < Long_MAX_NORMAL) { if (Math.abs(a.hi) < Long_MAX_NORMAL && Math.abs(b.hi) < Long_MAX_NORMAL) {
return Long_fromNumber(Long_toNumber(a) / Long_toNumber(b)); return Long_fromNumber(Long_toNumber(a) / Long_toNumber(b));
} }
return Long_divRem(a, b)[0]; return Long_divRem(a, b)[0];
} }
Long_udiv = function(a, b) { Long_udiv = (a, b) => {
if (a.hi >= 0 && a.hi < Long_MAX_NORMAL && b.hi >= 0 && b.hi < Long_MAX_NORMAL) { if (a.hi >= 0 && a.hi < Long_MAX_NORMAL && b.hi >= 0 && b.hi < Long_MAX_NORMAL) {
return Long_fromNumber(Long_toNumber(a) / Long_toNumber(b)); return Long_fromNumber(Long_toNumber(a) / Long_toNumber(b));
} }
return Long_udivRem(a, b)[0]; return Long_udivRem(a, b)[0];
} }
Long_rem = function(a, b) { Long_rem = (a, b) => {
if (Math.abs(a.hi) < Long_MAX_NORMAL && Math.abs(b.hi) < Long_MAX_NORMAL) { if (Math.abs(a.hi) < Long_MAX_NORMAL && Math.abs(b.hi) < Long_MAX_NORMAL) {
return Long_fromNumber(Long_toNumber(a) % Long_toNumber(b)); return Long_fromNumber(Long_toNumber(a) % Long_toNumber(b));
} }
return Long_divRem(a, b)[1]; return Long_divRem(a, b)[1];
} }
Long_urem = function(a, b) { Long_urem = (a, b) => {
if (a.hi >= 0 && a.hi < Long_MAX_NORMAL && b.hi >= 0 && b.hi < Long_MAX_NORMAL) { if (a.hi >= 0 && a.hi < Long_MAX_NORMAL && b.hi >= 0 && b.hi < Long_MAX_NORMAL) {
return Long_fromNumber(Long_toNumber(a) / Long_toNumber(b)); return Long_fromNumber(Long_toNumber(a) / Long_toNumber(b));
} }
return Long_udivRem(a, b)[1]; return Long_udivRem(a, b)[1];
} }
function Long_divRem(a, b) { let Long_divRem = (a, b) => {
if (b.lo === 0 && b.hi === 0) { if (b.lo === 0 && b.hi === 0) {
throw new teavm_globals.Error("Division by zero"); throw new teavm_globals.Error("Division by zero");
} }
var positive = Long_isNegative(a) === Long_isNegative(b); let positive = Long_isNegative(a) === Long_isNegative(b);
if (Long_isNegative(a)) { if (Long_isNegative(a)) {
a = Long_neg(a); a = Long_neg(a);
} }
@ -278,45 +272,31 @@ if (typeof teavm_globals.BigInt !== 'function') {
} }
a = new LongInt(a.lo, a.hi, 0); a = new LongInt(a.lo, a.hi, 0);
b = new LongInt(b.lo, b.hi, 0); b = new LongInt(b.lo, b.hi, 0);
var q = LongInt_div(a, b); let q = LongInt_div(a, b);
a = new Long(a.lo, a.hi); a = new Long(a.lo, a.hi);
q = new Long(q.lo, q.hi); q = new Long(q.lo, q.hi);
return positive ? [q, a] : [Long_neg(q), Long_neg(a)]; return positive ? [q, a] : [Long_neg(q), Long_neg(a)];
} };
function Long_udivRem(a, b) { let Long_udivRem = (a, b) => {
if (b.lo === 0 && b.hi === 0) { if (b.lo === 0 && b.hi === 0) {
throw new teavm_globals.Error("Division by zero"); throw new teavm_globals.Error("Division by zero");
} }
a = new LongInt(a.lo, a.hi, 0); a = new LongInt(a.lo, a.hi, 0);
b = new LongInt(b.lo, b.hi, 0); b = new LongInt(b.lo, b.hi, 0);
var q = LongInt_div(a, b); let q = LongInt_div(a, b);
a = new Long(a.lo, a.hi); a = new Long(a.lo, a.hi);
q = new Long(q.lo, q.hi); q = new Long(q.lo, q.hi);
return [q, a]; return [q, a];
} };
function Long_shiftLeft16(a) { Long_and = (a, b) => new Long(a.lo & b.lo, a.hi & b.hi)
return new Long(a.lo << 16, (a.lo >>> 16) | (a.hi << 16));
}
function Long_shiftRight16(a) { Long_or = (a, b) => new Long(a.lo | b.lo, a.hi | b.hi)
return new Long((a.lo >>> 16) | (a.hi << 16), a.hi >>> 16);
}
Long_and = function(a, b) { Long_xor = (a, b) => new Long(a.lo ^ b.lo, a.hi ^ b.hi)
return new Long(a.lo & b.lo, a.hi & b.hi);
}
Long_or = function(a, b) { Long_shl = (a, b) => {
return new Long(a.lo | b.lo, a.hi | b.hi);
}
Long_xor = function(a, b) {
return new Long(a.lo ^ b.lo, a.hi ^ b.hi);
}
Long_shl = function(a, b) {
b &= 63; b &= 63;
if (b === 0) { if (b === 0) {
return a; return a;
@ -329,7 +309,7 @@ if (typeof teavm_globals.BigInt !== 'function') {
} }
} }
Long_shr = function(a, b) { Long_shr = (a, b) => {
b &= 63; b &= 63;
if (b === 0) { if (b === 0) {
return a; return a;
@ -342,7 +322,7 @@ if (typeof teavm_globals.BigInt !== 'function') {
} }
} }
Long_shru = function(a, b) { Long_shru = (a, b) => {
b &= 63; b &= 63;
if (b === 0) { if (b === 0) {
return a; return a;
@ -355,9 +335,7 @@ if (typeof teavm_globals.BigInt !== 'function') {
} }
} }
Long_not = function(a) { Long_not = a => new Long(~a.hi, ~a.lo)
return new Long(~a.hi, ~a.lo);
}
// Represents a mutable 80-bit unsigned integer // Represents a mutable 80-bit unsigned integer
function LongInt(lo, hi, sup) { function LongInt(lo, hi, sup) {
@ -366,12 +344,12 @@ if (typeof teavm_globals.BigInt !== 'function') {
this.sup = sup; this.sup = sup;
} }
function LongInt_mul(a, b) { let LongInt_mul = (a, b) => {
var a_lolo = ((a.lo & 0xFFFF) * b) | 0; let a_lolo = ((a.lo & 0xFFFF) * b) | 0;
var a_lohi = ((a.lo >>> 16) * b) | 0; let a_lohi = ((a.lo >>> 16) * b) | 0;
var a_hilo = ((a.hi & 0xFFFF) * b) | 0; let a_hilo = ((a.hi & 0xFFFF) * b) | 0;
var a_hihi = ((a.hi >>> 16) * b) | 0; let a_hihi = ((a.hi >>> 16) * b) | 0;
var sup = (a.sup * b) | 0; let sup = (a.sup * b) | 0;
a_lohi = (a_lohi + (a_lolo >>> 16)) | 0; a_lohi = (a_lohi + (a_lolo >>> 16)) | 0;
a_hilo = (a_hilo + (a_lohi >>> 16)) | 0; a_hilo = (a_hilo + (a_lohi >>> 16)) | 0;
@ -380,49 +358,49 @@ if (typeof teavm_globals.BigInt !== 'function') {
a.lo = (a_lolo & 0xFFFF) | (a_lohi << 16); a.lo = (a_lolo & 0xFFFF) | (a_lohi << 16);
a.hi = (a_hilo & 0xFFFF) | (a_hihi << 16); a.hi = (a_hilo & 0xFFFF) | (a_hihi << 16);
a.sup = sup & 0xFFFF; a.sup = sup & 0xFFFF;
} };
function LongInt_sub(a, b) { let LongInt_sub = (a, b) => {
var a_lolo = a.lo & 0xFFFF; let a_lolo = a.lo & 0xFFFF;
var a_lohi = a.lo >>> 16; let a_lohi = a.lo >>> 16;
var a_hilo = a.hi & 0xFFFF; let a_hilo = a.hi & 0xFFFF;
var a_hihi = a.hi >>> 16; let a_hihi = a.hi >>> 16;
var b_lolo = b.lo & 0xFFFF; let b_lolo = b.lo & 0xFFFF;
var b_lohi = b.lo >>> 16; let b_lohi = b.lo >>> 16;
var b_hilo = b.hi & 0xFFFF; let b_hilo = b.hi & 0xFFFF;
var b_hihi = b.hi >>> 16; let b_hihi = b.hi >>> 16;
a_lolo = (a_lolo - b_lolo) | 0; a_lolo = (a_lolo - b_lolo) | 0;
a_lohi = (a_lohi - b_lohi + (a_lolo >> 16)) | 0; a_lohi = (a_lohi - b_lohi + (a_lolo >> 16)) | 0;
a_hilo = (a_hilo - b_hilo + (a_lohi >> 16)) | 0; a_hilo = (a_hilo - b_hilo + (a_lohi >> 16)) | 0;
a_hihi = (a_hihi - b_hihi + (a_hilo >> 16)) | 0; a_hihi = (a_hihi - b_hihi + (a_hilo >> 16)) | 0;
var sup = (a.sup - b.sup + (a_hihi >> 16)) | 0; let sup = (a.sup - b.sup + (a_hihi >> 16)) | 0;
a.lo = (a_lolo & 0xFFFF) | (a_lohi << 16); a.lo = (a_lolo & 0xFFFF) | (a_lohi << 16);
a.hi = (a_hilo & 0xFFFF) | (a_hihi << 16); a.hi = (a_hilo & 0xFFFF) | (a_hihi << 16);
a.sup = sup; a.sup = sup;
} };
function LongInt_add(a, b) { let LongInt_add = (a, b) => {
var a_lolo = a.lo & 0xFFFF; let a_lolo = a.lo & 0xFFFF;
var a_lohi = a.lo >>> 16; let a_lohi = a.lo >>> 16;
var a_hilo = a.hi & 0xFFFF; let a_hilo = a.hi & 0xFFFF;
var a_hihi = a.hi >>> 16; let a_hihi = a.hi >>> 16;
var b_lolo = b.lo & 0xFFFF; let b_lolo = b.lo & 0xFFFF;
var b_lohi = b.lo >>> 16; let b_lohi = b.lo >>> 16;
var b_hilo = b.hi & 0xFFFF; let b_hilo = b.hi & 0xFFFF;
var b_hihi = b.hi >>> 16; let b_hihi = b.hi >>> 16;
a_lolo = (a_lolo + b_lolo) | 0; a_lolo = (a_lolo + b_lolo) | 0;
a_lohi = (a_lohi + b_lohi + (a_lolo >> 16)) | 0; a_lohi = (a_lohi + b_lohi + (a_lolo >> 16)) | 0;
a_hilo = (a_hilo + b_hilo + (a_lohi >> 16)) | 0; a_hilo = (a_hilo + b_hilo + (a_lohi >> 16)) | 0;
a_hihi = (a_hihi + b_hihi + (a_hilo >> 16)) | 0; a_hihi = (a_hihi + b_hihi + (a_hilo >> 16)) | 0;
var sup = (a.sup + b.sup + (a_hihi >> 16)) | 0; let sup = (a.sup + b.sup + (a_hihi >> 16)) | 0;
a.lo = (a_lolo & 0xFFFF) | (a_lohi << 16); a.lo = (a_lolo & 0xFFFF) | (a_lohi << 16);
a.hi = (a_hilo & 0xFFFF) | (a_hihi << 16); a.hi = (a_hilo & 0xFFFF) | (a_hihi << 16);
a.sup = sup; a.sup = sup;
} };
function LongInt_inc(a) { let LongInt_inc = a => {
a.lo = (a.lo + 1) | 0; a.lo = (a.lo + 1) | 0;
if (a.lo === 0) { if (a.lo === 0) {
a.hi = (a.hi + 1) | 0; a.hi = (a.hi + 1) | 0;
@ -430,9 +408,9 @@ if (typeof teavm_globals.BigInt !== 'function') {
a.sup = (a.sup + 1) & 0xFFFF; a.sup = (a.sup + 1) & 0xFFFF;
} }
} }
} };
function LongInt_dec(a) { let LongInt_dec = a => {
a.lo = (a.lo - 1) | 0; a.lo = (a.lo - 1) | 0;
if (a.lo === -1) { if (a.lo === -1) {
a.hi = (a.hi - 1) | 0; a.hi = (a.hi - 1) | 0;
@ -440,10 +418,10 @@ if (typeof teavm_globals.BigInt !== 'function') {
a.sup = (a.sup - 1) & 0xFFFF; a.sup = (a.sup - 1) & 0xFFFF;
} }
} }
} };
function LongInt_ucompare(a, b) { let LongInt_ucompare = (a, b) => {
var r = (a.sup - b.sup); let r = (a.sup - b.sup);
if (r !== 0) { if (r !== 0) {
return r; return r;
} }
@ -460,11 +438,11 @@ if (typeof teavm_globals.BigInt !== 'function') {
return r; return r;
} }
return (a.lo & 1) - (b.lo & 1); return (a.lo & 1) - (b.lo & 1);
} };
function LongInt_numOfLeadingZeroBits(a) { let LongInt_numOfLeadingZeroBits = a => {
var n = 0; let n = 0;
var d = 16; let d = 16;
while (d > 0) { while (d > 0) {
if ((a >>> d) !== 0) { if ((a >>> d) !== 0) {
a >>>= d; a >>>= d;
@ -473,9 +451,9 @@ if (typeof teavm_globals.BigInt !== 'function') {
d = (d / 2) | 0; d = (d / 2) | 0;
} }
return 31 - n; return 31 - n;
} };
function LongInt_shl(a, b) { let LongInt_shl = (a, b) => {
if (b === 0) { if (b === 0) {
return; return;
} }
@ -500,9 +478,9 @@ if (typeof teavm_globals.BigInt !== 'function') {
a.hi = 0; a.hi = 0;
a.lo = 0; a.lo = 0;
} }
} };
function LongInt_shr(a, b) { let LongInt_shr = (a, b) => {
if (b === 0) { if (b === 0) {
return; return;
} }
@ -527,27 +505,25 @@ if (typeof teavm_globals.BigInt !== 'function') {
a.hi = 0; a.hi = 0;
a.sup = 0; a.sup = 0;
} }
} };
function LongInt_copy(a) { let LongInt_copy = a => new LongInt(a.lo, a.hi, a.sup);
return new LongInt(a.lo, a.hi, a.sup);
}
function LongInt_div(a, b) { let LongInt_div = (a, b) => {
// Normalize divisor // Normalize divisor
var bits = b.hi !== 0 ? LongInt_numOfLeadingZeroBits(b.hi) : LongInt_numOfLeadingZeroBits(b.lo) + 32; let bits = b.hi !== 0 ? LongInt_numOfLeadingZeroBits(b.hi) : LongInt_numOfLeadingZeroBits(b.lo) + 32;
var sz = 1 + ((bits / 16) | 0); let sz = 1 + ((bits / 16) | 0);
var dividentBits = bits % 16; let dividentBits = bits % 16;
LongInt_shl(b, bits); LongInt_shl(b, bits);
LongInt_shl(a, dividentBits); LongInt_shl(a, dividentBits);
var q = new LongInt(0, 0, 0); let q = new LongInt(0, 0, 0);
while (sz-- > 0) { while (sz-- > 0) {
LongInt_shl(q, 16); LongInt_shl(q, 16);
// Calculate approximate q // Calculate approximate q
var digitA = (a.hi >>> 16) + (0x10000 * a.sup); let digitA = (a.hi >>> 16) + (0x10000 * a.sup);
var digitB = b.hi >>> 16; let digitB = b.hi >>> 16;
var digit = (digitA / digitB) | 0; let digit = (digitA / digitB) | 0;
var t = LongInt_copy(b); let t = LongInt_copy(b);
LongInt_mul(t, digit); LongInt_mul(t, digit);
// Adjust q either down or up // Adjust q either down or up
if (LongInt_ucompare(t, a) >= 0) { if (LongInt_ucompare(t, a) >= 0) {
@ -557,7 +533,7 @@ if (typeof teavm_globals.BigInt !== 'function') {
} }
} else { } else {
while (true) { while (true) {
var nextT = LongInt_copy(t); let nextT = LongInt_copy(t);
LongInt_add(nextT, b); LongInt_add(nextT, b);
if (LongInt_ucompare(nextT, a) > 0) { if (LongInt_ucompare(nextT, a) > 0) {
break; break;
@ -572,108 +548,61 @@ if (typeof teavm_globals.BigInt !== 'function') {
} }
LongInt_shr(a, bits + 16); LongInt_shr(a, bits + 16);
return q; return q;
} };
} else { } else {
Long_eq = function(a, b) { Long_eq = (a, b) => a === b
return a === b;
}
Long_ne = function(a, b) { Long_ne = (a, b) => a !== b
return a !== b;
}
Long_gt = function(a, b) { Long_gt = (a, b) => a > b
return a > b;
}
Long_ge = function(a, b) { Long_ge = (a, b) => a >= b
return a >= b;
}
Long_lt = function(a, b) { Long_lt = (a, b) => a < b
return a < b;
}
Long_le = function(a, b) { Long_le = (a, b) => a <= b
return a <= b;
}
Long_add = function(a, b) { Long_add = (a, b) => teavm_globals.BigInt.asIntN(64, a + b)
return teavm_globals.BigInt.asIntN(64, a + b);
}
Long_inc = function(a) { Long_inc = a => teavm_globals.BigInt.asIntN(64, a + 1)
return teavm_globals.BigInt.asIntN(64, a + 1);
}
Long_dec = function(a) { Long_dec = a => teavm_globals.BigInt.asIntN(64, a - 1)
return teavm_globals.BigInt.asIntN(64, a - 1);
}
Long_neg = function(a) { Long_neg = a => teavm_globals.BigInt.asIntN(64, -a)
return teavm_globals.BigInt.asIntN(64, -a);
}
Long_sub = function(a, b) { Long_sub = (a, b) => teavm_globals.BigInt.asIntN(64, a - b)
return teavm_globals.BigInt.asIntN(64, a - b);
}
Long_compare = function(a, b) { Long_compare = (a, b) => a < b ? -1 : a > b ? 1 : 0
return a < b ? -1 : a > b ? 1 : 0; Long_ucompare = (a, b) => {
}
Long_ucompare = function(a, b) {
a = teavm_globals.BigInt.asUintN(64, a); a = teavm_globals.BigInt.asUintN(64, a);
b = teavm_globals.BigInt.asUintN(64, b); b = teavm_globals.BigInt.asUintN(64, b);
return a < b ? -1 : a > b ? 1 : 0; return a < b ? -1 : a > b ? 1 : 0;
} }
Long_mul = function(a, b) { Long_mul = (a, b) => teavm_globals.BigInt.asIntN(64, a * b)
return teavm_globals.BigInt.asIntN(64, a * b);
}
Long_div = function(a, b) { Long_div = (a, b) => teavm_globals.BigInt.asIntN(64, a / b)
return teavm_globals.BigInt.asIntN(64, a / b);
}
Long_udiv = function(a, b) { Long_udiv = (a, b) => teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt.asUintN(64, a) /
return teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt.asUintN(64, a) / teavm_globals.BigInt.asUintN(64, b))
teavm_globals.BigInt.asUintN(64, b));
}
Long_rem = function(a, b) { Long_rem = (a, b) => teavm_globals.BigInt.asIntN(64, a % b)
return teavm_globals.BigInt.asIntN(64, a % b);
}
Long_urem = function(a, b) { Long_urem = (a, b) => teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt.asUintN(64, a) %
return teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt.asUintN(64, a) % teavm_globals.BigInt.asUintN(64, b))
teavm_globals.BigInt.asUintN(64, b));
}
Long_and = function(a, b) { Long_and = (a, b) => teavm_globals.BigInt.asIntN(64, a & b)
return teavm_globals.BigInt.asIntN(64, a & b);
}
Long_or = function(a, b) { Long_or = (a, b) => teavm_globals.BigInt.asIntN(64, a | b)
return teavm_globals.BigInt.asIntN(64, a | b);
}
Long_xor = function(a, b) { Long_xor = (a, b) => teavm_globals.BigInt.asIntN(64, a ^ b)
return teavm_globals.BigInt.asIntN(64, a ^ b);
}
Long_shl = function(a, b) { Long_shl = (a, b) => teavm_globals.BigInt.asIntN(64, a << teavm_globals.BigInt(b & 63))
return teavm_globals.BigInt.asIntN(64, a << teavm_globals.BigInt(b & 63));
}
Long_shr = function(a, b) { Long_shr = (a, b) => teavm_globals.BigInt.asIntN(64, a >> teavm_globals.BigInt(b & 63))
return teavm_globals.BigInt.asIntN(64, a >> teavm_globals.BigInt(b & 63));
}
Long_shru = function(a, b) { Long_shru = (a, b) => teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt.asUintN(64, a) >>
return teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt.asUintN(64, a) >> teavm_globals.BigInt(b & 63)); teavm_globals.BigInt(b & 63))
}
Long_not = function(a) { Long_not = a => teavm_globals.BigInt.asIntN(64, ~a)
return teavm_globals.BigInt.asIntN(64, ~a);
}
} }

View File

@ -15,8 +15,8 @@
*/ */
"use strict"; "use strict";
function $rt_startThread(runner, callback) { let $rt_startThread = (runner, callback) => {
var result; let result;
try { try {
result = runner(); result = runner();
} catch (e) { } catch (e) {
@ -28,14 +28,7 @@ function $rt_startThread(runner, callback) {
throw result; throw result;
} }
} }
function $rt_suspending() { let $rt_suspending = () => false;
return false; let $rt_resuming = () => false;
} let $rt_nativeThread = () => null;
function $rt_resuming() { let $rt_invalidPointer = () => {};
return false;
}
function $rt_nativeThread() {
return null;
}
function $rt_invalidPointer() {
}

View File

@ -24,7 +24,7 @@ function TeaVMThread(runner) {
this.completeCallback = null; this.completeCallback = null;
} }
TeaVMThread.prototype.push = function() { TeaVMThread.prototype.push = function() {
for (var i = 0; i < arguments.length; ++i) { for (let i = 0; i < arguments.length; ++i) {
this.stack.push(arguments[i]); this.stack.push(arguments[i]);
} }
return this; return this;
@ -68,7 +68,7 @@ TeaVMThread.prototype.resume = function() {
}; };
TeaVMThread.prototype.run = function() { TeaVMThread.prototype.run = function() {
$rt_currentNativeThread = this; $rt_currentNativeThread = this;
var result; let result;
try { try {
result = this.runner(); result = this.runner();
} catch (e) { } catch (e) {
@ -77,8 +77,8 @@ TeaVMThread.prototype.run = function() {
$rt_currentNativeThread = null; $rt_currentNativeThread = null;
} }
if (this.suspendCallback !== null) { if (this.suspendCallback !== null) {
var self = this; let self = this;
var callback = this.suspendCallback; let callback = this.suspendCallback;
this.suspendCallback = null; this.suspendCallback = null;
callback(() => self.resume()); callback(() => self.resume());
} else if (this.status === 0) { } else if (this.status === 0) {
@ -86,28 +86,24 @@ TeaVMThread.prototype.run = function() {
} }
}; };
function $rt_suspending() { let $rt_suspending = () => {
var thread = $rt_nativeThread(); let thread = $rt_nativeThread();
return thread != null && thread.isSuspending(); return thread != null && thread.isSuspending();
} }
function $rt_resuming() { let $rt_resuming = () => {
var thread = $rt_nativeThread(); let thread = $rt_nativeThread();
return thread != null && thread.isResuming(); return thread != null && thread.isResuming();
} }
function $rt_suspend(callback) { let $rt_suspend = callback => {
var nativeThread = $rt_nativeThread(); let nativeThread = $rt_nativeThread();
if (nativeThread === null) { if (nativeThread === null) {
throw new teavm_globals.Error("Suspension point reached from non-threading context (perhaps, from native JS method)."); throw new teavm_globals.Error("Suspension point reached from non-threading context (perhaps, from native JS method).");
} }
return nativeThread.suspend(callback); return nativeThread.suspend(callback);
} }
function $rt_startThread(runner, callback) { let $rt_startThread = (runner, callback) => new TeaVMThread(runner).start(callback);
new TeaVMThread(runner).start(callback); let $rt_currentNativeThread = null;
} let $rt_nativeThread = () => $rt_currentNativeThread;
var $rt_currentNativeThread = null; let $rt_invalidPointer = () => {
function $rt_nativeThread() {
return $rt_currentNativeThread;
}
function $rt_invalidPointer() {
throw new teavm_globals.Error("Invalid recorded state"); throw new teavm_globals.Error("Invalid recorded state");
} }

View File

@ -166,7 +166,7 @@ public class PlatformGenerator implements Generator, Injector, DependencyPlugin
MethodReference selfRef = new MethodReference(Platform.class, "getEnumConstants", MethodReference selfRef = new MethodReference(Platform.class, "getEnumConstants",
PlatformClass.class, Enum[].class); PlatformClass.class, Enum[].class);
writer.appendMethodBody(selfRef).ws().append("=").ws().append("cls").ws().append("=>").ws() writer.appendMethodBody(selfRef).ws().append("=").ws().append("cls").sameLineWs().append("=>").ws()
.append("{").softNewLine().indent(); .append("{").softNewLine().indent();
writer.append("if").ws().append("(!cls.hasOwnProperty(c))").ws().append("{").indent().softNewLine(); writer.append("if").ws().append("(!cls.hasOwnProperty(c))").ws().append("{").indent().softNewLine();
writer.append("return null;").softNewLine(); writer.append("return null;").softNewLine();
@ -196,7 +196,7 @@ public class PlatformGenerator implements Generator, Injector, DependencyPlugin
MethodReference selfRef = new MethodReference(Platform.class, "getAnnotations", PlatformClass.class, MethodReference selfRef = new MethodReference(Platform.class, "getAnnotations", PlatformClass.class,
Annotation[].class); Annotation[].class);
writer.appendMethodBody(selfRef).ws().append("=").ws().append("cls").ws().append("=>").ws() writer.appendMethodBody(selfRef).ws().append("=").ws().append("cls").sameLineWs().append("=>").ws()
.append("{").softNewLine().indent(); .append("{").softNewLine().indent();
writer.append("if").ws().append("(!cls.hasOwnProperty(c))").ws().append("{").indent().softNewLine(); writer.append("if").ws().append("(!cls.hasOwnProperty(c))").ws().append("{").indent().softNewLine();
writer.append("return null;").softNewLine(); writer.append("return null;").softNewLine();