JS: change how declarations are exported from modules. Change how parts of kotlin.js merged

This commit is contained in:
Alexey Andreev
2016-10-25 12:50:16 +03:00
parent 3d9beb15da
commit f244bbaae3
10 changed files with 1295 additions and 1336 deletions
+9 -11
View File
@@ -368,20 +368,9 @@
<sources dir="${js.stdlib.output.dir}"> <sources dir="${js.stdlib.output.dir}">
<file name="builtins.js"/> <file name="builtins.js"/>
</sources>
<sources dir="${stdlib.js.dir}">
<file name="merge-builtins.js"/>
</sources>
<sources dir="${js.stdlib.output.dir}">
<file name="${compiled.stdlib.js}"/> <file name="${compiled.stdlib.js}"/>
</sources> </sources>
<sources dir="${stdlib.js.dir}">
<file name="merge.js"/>
</sources>
<externs dir="${stdlib.js.dir}"> <externs dir="${stdlib.js.dir}">
<file name="externs.js"/> <file name="externs.js"/>
</externs> </externs>
@@ -412,6 +401,15 @@
<move file="${js.stdlib.output.dir}/tmp/kotlin" todir="${js.stdlib.output.dir}" /> <move file="${js.stdlib.output.dir}/tmp/kotlin" todir="${js.stdlib.output.dir}" />
<move file="${js.stdlib.output.dir}/tmp/${compiled.stdlib.meta.js}" tofile="${js.stdlib.output.dir}/${compiled.stdlib.meta.js}" /> <move file="${js.stdlib.output.dir}/tmp/${compiled.stdlib.meta.js}" tofile="${js.stdlib.output.dir}/${compiled.stdlib.meta.js}" />
<replaceregexp file="${js.stdlib.output.dir}/builtins.js"
match="module.exports,\s*require\([^)]+\)"
replace="Kotlin, Kotlin"
byline="true" encoding="UTF-8" />
<replaceregexp file="${js.stdlib.output.dir}/${compiled.stdlib.js}"
match="module.exports,\s*require\([^)]+\)"
replace="Kotlin, Kotlin"
byline="true" encoding="UTF-8" />
<condition property="jdk17" value="${env.JDK_17}" else="${env.JAVA_HOME}"> <condition property="jdk17" value="${env.JDK_17}" else="${env.JAVA_HOME}">
<isset property="env.JDK_17" /> <isset property="env.JDK_17" />
</condition> </condition>
@@ -39,7 +39,6 @@ import org.jetbrains.kotlin.js.translate.intrinsic.Intrinsics;
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils; import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.FqNameUnsafe; import org.jetbrains.kotlin.name.FqNameUnsafe;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.resolve.BindingContext; import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.BindingTrace; import org.jetbrains.kotlin.resolve.BindingTrace;
import org.jetbrains.kotlin.resolve.DescriptorUtils; import org.jetbrains.kotlin.resolve.DescriptorUtils;
@@ -145,15 +144,12 @@ public final class StaticContext {
@NotNull @NotNull
private final Set<ClassDescriptor> classes = new HashSet<ClassDescriptor>(); private final Set<ClassDescriptor> classes = new HashSet<ClassDescriptor>();
@NotNull
private final ExportedPackage rootPackage = new ExportedPackage("");
@NotNull
private final JsObjectLiteral exportObject = rootPackage.objectLiteral;
@NotNull @NotNull
private final Set<MemberDescriptor> exportedDeclarations = new HashSet<MemberDescriptor>(); private final Set<MemberDescriptor> exportedDeclarations = new HashSet<MemberDescriptor>();
@NotNull
private final Map<FqName, JsName> localPackageNames = new HashMap<FqName, JsName>();
//TODO: too many parameters in constructor //TODO: too many parameters in constructor
private StaticContext( private StaticContext(
@NotNull JsProgram program, @NotNull JsProgram program,
@@ -665,11 +661,7 @@ public final class StaticContext {
exportedDeclarations.add(descriptor); exportedDeclarations.add(descriptor);
if (container instanceof PackageFragmentDescriptor) { if (container instanceof PackageFragmentDescriptor) {
PackageFragmentDescriptor packageDescriptor = (PackageFragmentDescriptor) container; JsExpression packageRef = getLocalPackageReference(((PackageFragmentDescriptor) container).getFqName());
ExportedPackage exportedPackage = rootPackage;
for (Name packageName : packageDescriptor.getFqName().pathSegments()) {
exportedPackage = exportedPackage.getSubpackage(packageName.asString());
}
JsExpression initializerExpr = DeclarationExporter.exportDeclaration(this, descriptor, exportStatements); JsExpression initializerExpr = DeclarationExporter.exportDeclaration(this, descriptor, exportStatements);
if (initializerExpr != null) { if (initializerExpr != null) {
@@ -679,8 +671,7 @@ public final class StaticContext {
MetadataProperties.setStaticRef(propertyName, initializerExpr); MetadataProperties.setStaticRef(propertyName, initializerExpr);
} }
} }
JsPropertyInitializer initializer = new JsPropertyInitializer(propertyName.makeRef(), initializerExpr); exportStatements.add(JsAstUtils.assignment(new JsNameRef(propertyName, packageRef), initializerExpr).makeStmt());
exportedPackage.objectLiteral.getPropertyInitializers().add(initializer);
} }
} }
else { else {
@@ -689,6 +680,24 @@ public final class StaticContext {
} }
} }
private JsExpression getLocalPackageReference(FqName packageName) {
if (packageName.isRoot()) {
return rootFunction.getScope().declareName(Namer.getRootPackageName()).makeRef();
}
JsName name = localPackageNames.get(packageName);
if (name == null) {
name = rootFunction.getScope().declareFreshName("package$" + packageName.shortName().asString());
localPackageNames.put(packageName, name);
JsExpression parentRef = getLocalPackageReference(packageName.parent());
JsExpression selfRef = new JsNameRef(packageName.shortName().asString(), parentRef);
JsExpression rhs = JsAstUtils.or(selfRef, JsAstUtils.assignment(selfRef.deepCopy(), new JsObjectLiteral(false)));
exportStatements.add(JsAstUtils.newVar(name, rhs));
}
return name.makeRef();
}
@NotNull @NotNull
public NameSuggestion getNameSuggestion() { public NameSuggestion getNameSuggestion() {
return nameSuggestion; return nameSuggestion;
@@ -704,11 +713,7 @@ public final class StaticContext {
rootFunction.getBody().getStatements().addAll(importStatements); rootFunction.getBody().getStatements().addAll(importStatements);
addClassPrototypes(); addClassPrototypes();
rootFunction.getBody().getStatements().addAll(declarationStatements); rootFunction.getBody().getStatements().addAll(declarationStatements);
JsName rootPackageName = rootFunction.getScope().declareName(Namer.getRootPackageName());
rootFunction.getBody().getStatements().add(JsAstUtils.newVar(rootPackageName, exportObject));
rootFunction.getBody().getStatements().addAll(exportStatements); rootFunction.getBody().getStatements().addAll(exportStatements);
rootFunction.getBody().getStatements().addAll(topLevelStatements); rootFunction.getBody().getStatements().addAll(topLevelStatements);
} }
@@ -753,25 +758,4 @@ public final class StaticContext {
} }
return false; return false;
} }
private static class ExportedPackage {
@NotNull final String name;
@NotNull final Map<String, ExportedPackage> subpackages = new HashMap<String, ExportedPackage>();
@NotNull final JsObjectLiteral objectLiteral = new JsObjectLiteral(true);
public ExportedPackage(@NotNull String name) {
this.name = name;
}
@NotNull
public ExportedPackage getSubpackage(@NotNull String name) {
ExportedPackage subpackage = subpackages.get(name);
if (subpackage == null) {
subpackage = new ExportedPackage(name);
subpackages.put(name, subpackage);
objectLiteral.getPropertyInitializers().add(new JsPropertyInitializer(new JsNameRef(name), subpackage.objectLiteral));
}
return subpackage;
}
}
} }
@@ -55,7 +55,7 @@ object ModuleWrapperTranslation {
val amdBody = JsBlock(wrapAmd(moduleId, factoryName.makeRef(), importedModules, program)) val amdBody = JsBlock(wrapAmd(moduleId, factoryName.makeRef(), importedModules, program))
val commonJsBody = JsBlock(wrapCommonJs(factoryName.makeRef(), importedModules, program)) val commonJsBody = JsBlock(wrapCommonJs(factoryName.makeRef(), importedModules, program))
val plainInvocation = makePlainInvocation(factoryName.makeRef(), importedModules, program) val plainInvocation = makePlainInvocation(moduleId, factoryName.makeRef(), importedModules, program)
val lhs: JsExpression = if (Namer.requiresEscaping(moduleId)) { val lhs: JsExpression = if (Namer.requiresEscaping(moduleId)) {
JsArrayAccess(rootName.makeRef(), program.getStringLiteral(moduleId)) JsArrayAccess(rootName.makeRef(), program.getStringLiteral(moduleId))
@@ -79,7 +79,7 @@ object ModuleWrapperTranslation {
val defineName = scope.declareName("define") val defineName = scope.declareName("define")
val invocationArgs = listOf( val invocationArgs = listOf(
program.getStringLiteral(moduleId), program.getStringLiteral(moduleId),
JsArrayLiteral(importedModules.map { program.getStringLiteral(it) }), JsArrayLiteral(listOf(program.getStringLiteral("exports")) + importedModules.map { program.getStringLiteral(it) }),
function function
) )
@@ -93,16 +93,15 @@ object ModuleWrapperTranslation {
val requireName = scope.declareName("require") val requireName = scope.declareName("require")
val invocationArgs = importedModules.map { JsInvocation(requireName.makeRef(), program.getStringLiteral(it)) } val invocationArgs = importedModules.map { JsInvocation(requireName.makeRef(), program.getStringLiteral(it)) }
val invocation = JsInvocation(function, invocationArgs) val invocation = JsInvocation(function, listOf(JsNameRef("exports", moduleName.makeRef())) + invocationArgs)
val assignment = JsAstUtils.assignment(JsNameRef("exports", moduleName.makeRef()), invocation) return listOf(invocation.makeStmt())
return listOf(assignment.makeStmt())
} }
private fun wrapPlain( private fun wrapPlain(
moduleId: String, function: JsExpression, moduleId: String, function: JsExpression,
importedModules: List<String>, program: JsProgram importedModules: List<String>, program: JsProgram
): List<JsStatement> { ): List<JsStatement> {
val invocation = makePlainInvocation(function, importedModules, program) val invocation = makePlainInvocation(moduleId, function, importedModules, program)
val statement = if (Namer.requiresEscaping(moduleId)) { val statement = if (Namer.requiresEscaping(moduleId)) {
JsAstUtils.assignment(makePlainModuleRef(moduleId, program), invocation).makeStmt() JsAstUtils.assignment(makePlainModuleRef(moduleId, program), invocation).makeStmt()
@@ -114,9 +113,18 @@ object ModuleWrapperTranslation {
return listOf(statement) return listOf(statement)
} }
private fun makePlainInvocation(function: JsExpression, importedModules: List<String>, program: JsProgram): JsInvocation { private fun makePlainInvocation(
moduleId: String,
function: JsExpression,
importedModules: List<String>,
program: JsProgram
): JsInvocation {
val invocationArgs = importedModules.map { makePlainModuleRef(it, program) } val invocationArgs = importedModules.map { makePlainModuleRef(it, program) }
return JsInvocation(function, invocationArgs) val moduleRef = makePlainModuleRef(moduleId, program)
val testModuleDefined = JsAstUtils.typeOfIs(moduleRef, program.getStringLiteral("undefined"))
val selfArg = JsConditional(testModuleDefined, JsObjectLiteral(false), moduleRef.deepCopy())
return JsInvocation(function, listOf(selfArg) + invocationArgs)
} }
private fun makePlainModuleRef(moduleId: String, program: JsProgram): JsExpression { private fun makePlainModuleRef(moduleId: String, program: JsProgram): JsExpression {
@@ -269,6 +269,9 @@ public final class Translation {
mayBeGenerateTests(files, config, rootBlock, context); mayBeGenerateTests(files, config, rootBlock, context);
JsName rootPackageName = program.getRootScope().declareName(Namer.getRootPackageName());
rootFunction.getParameters().add(new JsParameter((rootPackageName)));
// Invoke function passing modules as arguments // Invoke function passing modules as arguments
// This should help minifier tool to recognize references to these modules as local variables and make them shorter. // This should help minifier tool to recognize references to these modules as local variables and make them shorter.
List<String> importedModuleList = new ArrayList<String>(); List<String> importedModuleList = new ArrayList<String>();
@@ -288,7 +291,7 @@ public final class Translation {
} }
} }
statements.add(new JsReturn(program.getRootScope().declareName(Namer.getRootPackageName()).makeRef())); statements.add(new JsReturn(rootPackageName.makeRef()));
JsBlock block = program.getGlobalBlock(); JsBlock block = program.getGlobalBlock();
block.getStatements().addAll(wrapIfNecessary(config.getModuleId(), rootFunction, importedModuleList, program, block.getStatements().addAll(wrapIfNecessary(config.getModuleId(), rootFunction, importedModuleList, program,
+2 -5
View File
@@ -8,11 +8,8 @@
} }
}(this, function () { }(this, function () {
var Kotlin = {}; var Kotlin = {};
function require() {
return Kotlin;
}
var module = {};
%output% %output%
Kotlin.modules.kotlin = Kotlin;
return Kotlin; return Kotlin;
})); }));
+130 -134
View File
@@ -14,17 +14,14 @@
* limitations under the License. * limitations under the License.
*/ */
(function (Kotlin) { // Shims for String
"use strict"; if (typeof String.prototype.startsWith === "undefined") {
// Shims for String
if (typeof String.prototype.startsWith === "undefined") {
String.prototype.startsWith = function(searchString, position) { String.prototype.startsWith = function(searchString, position) {
position = position || 0; position = position || 0;
return this.lastIndexOf(searchString, position) === position; return this.lastIndexOf(searchString, position) === position;
}; };
} }
if (typeof String.prototype.endsWith === "undefined") { if (typeof String.prototype.endsWith === "undefined") {
String.prototype.endsWith = function(searchString, position) { String.prototype.endsWith = function(searchString, position) {
var subjectString = this.toString(); var subjectString = this.toString();
if (position === undefined || position > subjectString.length) { if (position === undefined || position > subjectString.length) {
@@ -34,15 +31,15 @@
var lastIndex = subjectString.indexOf(searchString, position); var lastIndex = subjectString.indexOf(searchString, position);
return lastIndex !== -1 && lastIndex === position; return lastIndex !== -1 && lastIndex === position;
}; };
} }
String.prototype.contains = function (s) { String.prototype.contains = function (s) {
return this.indexOf(s) !== -1; return this.indexOf(s) !== -1;
}; };
// Kotlin stdlib // Kotlin stdlib
Kotlin.equals = function (obj1, obj2) { Kotlin.equals = function (obj1, obj2) {
if (obj1 == null) { if (obj1 == null) {
return obj2 == null; return obj2 == null;
} }
@@ -56,9 +53,9 @@
} }
return obj1 === obj2; return obj1 === obj2;
}; };
Kotlin.hashCode = function (obj) { Kotlin.hashCode = function (obj) {
if (obj == null) { if (obj == null) {
return 0; return 0;
} }
@@ -77,9 +74,9 @@
var str = String(obj); var str = String(obj);
return getStringHashCode(str); return getStringHashCode(str);
}; };
Kotlin.toString = function (o) { Kotlin.toString = function (o) {
if (o == null) { if (o == null) {
return "null"; return "null";
} }
@@ -89,13 +86,13 @@
else { else {
return o.toString(); return o.toString();
} }
}; };
Kotlin.arrayToString = function (a) { Kotlin.arrayToString = function (a) {
return "[" + a.map(Kotlin.toString).join(", ") + "]"; return "[" + a.map(Kotlin.toString).join(", ") + "]";
}; };
Kotlin.arrayDeepToString = function (a, visited) { Kotlin.arrayDeepToString = function (a, visited) {
visited = visited || [a]; visited = visited || [a];
return "[" + a.map(function(e) { return "[" + a.map(function(e) {
if (Array.isArray(e) && visited.indexOf(e) < 0) { if (Array.isArray(e) && visited.indexOf(e) < 0) {
@@ -108,9 +105,9 @@
return Kotlin.toString(e); return Kotlin.toString(e);
} }
}).join(", ") + "]"; }).join(", ") + "]";
}; };
Kotlin.compareTo = function (a, b) { Kotlin.compareTo = function (a, b) {
var typeA = typeof a; var typeA = typeof a;
var typeB = typeof a; var typeB = typeof a;
if (Kotlin.isChar(a) && typeB == "number") { if (Kotlin.isChar(a) && typeB == "number") {
@@ -123,135 +120,135 @@
return a < b ? -1 : a > b ? 1 : 0; return a < b ? -1 : a > b ? 1 : 0;
} }
return a.compareTo_za3rmp$(b); return a.compareTo_za3rmp$(b);
}; };
Kotlin.primitiveCompareTo = function (a, b) { Kotlin.primitiveCompareTo = function (a, b) {
return a < b ? -1 : a > b ? 1 : 0; return a < b ? -1 : a > b ? 1 : 0;
}; };
Kotlin.isNumber = function (a) { Kotlin.isNumber = function (a) {
return typeof a == "number" || a instanceof Kotlin.Long; return typeof a == "number" || a instanceof Kotlin.Long;
}; };
Kotlin.isChar = function (value) { Kotlin.isChar = function (value) {
return (typeof value) == "string" && value.length == 1; return (typeof value) == "string" && value.length == 1;
}; };
Kotlin.isComparable = function (value) { Kotlin.isComparable = function (value) {
var type = typeof value; var type = typeof value;
return type === "string" || return type === "string" ||
type === "boolean" || type === "boolean" ||
Kotlin.isNumber(value) || Kotlin.isNumber(value) ||
Kotlin.isType(value, Kotlin.kotlin.Comparable); Kotlin.isType(value, Kotlin.kotlin.Comparable);
}; };
Kotlin.isCharSequence = function (value) { Kotlin.isCharSequence = function (value) {
return typeof value === "string" || Kotlin.isType(value, Kotlin.kotlin.CharSequence); return typeof value === "string" || Kotlin.isType(value, Kotlin.kotlin.CharSequence);
}; };
Kotlin.charInc = function (value) { Kotlin.charInc = function (value) {
return String.fromCharCode(value.charCodeAt(0)+1); return String.fromCharCode(value.charCodeAt(0)+1);
}; };
Kotlin.charDec = function (value) { Kotlin.charDec = function (value) {
return String.fromCharCode(value.charCodeAt(0)-1); return String.fromCharCode(value.charCodeAt(0)-1);
}; };
Kotlin.toShort = function (a) { Kotlin.toShort = function (a) {
return (a & 0xFFFF) << 16 >> 16; return (a & 0xFFFF) << 16 >> 16;
}; };
Kotlin.toByte = function (a) { Kotlin.toByte = function (a) {
return (a & 0xFF) << 24 >> 24; return (a & 0xFF) << 24 >> 24;
}; };
Kotlin.toChar = function (a) { Kotlin.toChar = function (a) {
return String.fromCharCode((((a | 0) % 65536) & 0xFFFF) << 16 >>> 16); return String.fromCharCode((((a | 0) % 65536) & 0xFFFF) << 16 >>> 16);
}; };
Kotlin.numberToLong = function (a) { Kotlin.numberToLong = function (a) {
return a instanceof Kotlin.Long ? a : Kotlin.Long.fromNumber(a); return a instanceof Kotlin.Long ? a : Kotlin.Long.fromNumber(a);
}; };
Kotlin.numberToInt = function (a) { Kotlin.numberToInt = function (a) {
return a instanceof Kotlin.Long ? a.toInt() : (a | 0); return a instanceof Kotlin.Long ? a.toInt() : (a | 0);
}; };
Kotlin.numberToShort = function (a) { Kotlin.numberToShort = function (a) {
return Kotlin.toShort(Kotlin.numberToInt(a)); return Kotlin.toShort(Kotlin.numberToInt(a));
}; };
Kotlin.numberToByte = function (a) { Kotlin.numberToByte = function (a) {
return Kotlin.toByte(Kotlin.numberToInt(a)); return Kotlin.toByte(Kotlin.numberToInt(a));
}; };
Kotlin.numberToDouble = function (a) { Kotlin.numberToDouble = function (a) {
return +a; return +a;
}; };
Kotlin.numberToChar = function (a) { Kotlin.numberToChar = function (a) {
return Kotlin.toChar(Kotlin.numberToInt(a)); return Kotlin.toChar(Kotlin.numberToInt(a));
}; };
Kotlin.intUpto = function (from, to) { Kotlin.intUpto = function (from, to) {
return new Kotlin.kotlin.ranges.IntRange(from, to); return new Kotlin.kotlin.ranges.IntRange(from, to);
}; };
Kotlin.intDownto = function (from, to) { Kotlin.intDownto = function (from, to) {
return new Kotlin.kotlin.ranges.IntProgression(from, to, -1); return new Kotlin.kotlin.ranges.IntProgression(from, to, -1);
}; };
Kotlin.Throwable = Error; Kotlin.Throwable = Error;
Kotlin.throwNPE = function (message) { Kotlin.throwNPE = function (message) {
throw new Kotlin.kotlin.NullPointerException(message); throw new Kotlin.kotlin.NullPointerException(message);
}; };
Kotlin.throwCCE = function () { Kotlin.throwCCE = function () {
throw new Kotlin.kotlin.ClassCastException("Illegal cast"); throw new Kotlin.kotlin.ClassCastException("Illegal cast");
}; };
/** @const */ /** @const */
var POW_2_32 = 4294967296; var POW_2_32 = 4294967296;
// TODO: consider switching to Symbol type once we are on ES6. // TODO: consider switching to Symbol type once we are on ES6.
/** @const */ /** @const */
var OBJECT_HASH_CODE_PROPERTY_NAME = "kotlinHashCodeValue$"; var OBJECT_HASH_CODE_PROPERTY_NAME = "kotlinHashCodeValue$";
function getObjectHashCode(obj) { function getObjectHashCode(obj) {
if (!(OBJECT_HASH_CODE_PROPERTY_NAME in obj)) { if (!(OBJECT_HASH_CODE_PROPERTY_NAME in obj)) {
var hash = (Math.random() * POW_2_32) | 0; // Make 32-bit singed integer. var hash = (Math.random() * POW_2_32) | 0; // Make 32-bit singed integer.
Object.defineProperty(obj, OBJECT_HASH_CODE_PROPERTY_NAME, { value: hash, enumerable: false }); Object.defineProperty(obj, OBJECT_HASH_CODE_PROPERTY_NAME, { value: hash, enumerable: false });
} }
return obj[OBJECT_HASH_CODE_PROPERTY_NAME]; return obj[OBJECT_HASH_CODE_PROPERTY_NAME];
} }
function getStringHashCode(str) { function getStringHashCode(str) {
var hash = 0; var hash = 0;
for (var i = 0; i < str.length; i++) { for (var i = 0; i < str.length; i++) {
var code = str.charCodeAt(i); var code = str.charCodeAt(i);
hash = (hash * 31 + code) | 0; // Keep it 32-bit. hash = (hash * 31 + code) | 0; // Keep it 32-bit.
} }
return hash; return hash;
} }
Kotlin.PropertyMetadata = Kotlin.createClassNow(null, Kotlin.PropertyMetadata = Kotlin.createClassNow(null,
function (name) { function (name) {
this.name = name; this.name = name;
} }
); );
Kotlin.safeParseInt = function (str) { Kotlin.safeParseInt = function (str) {
var r = parseInt(str, 10); var r = parseInt(str, 10);
return isNaN(r) ? null : r; return isNaN(r) ? null : r;
}; };
Kotlin.safeParseDouble = function (str) { Kotlin.safeParseDouble = function (str) {
var r = parseFloat(str); var r = parseFloat(str);
return isNaN(r) ? null : r; return isNaN(r) ? null : r;
}; };
Kotlin.arrayEquals = function (a, b) { Kotlin.arrayEquals = function (a, b) {
if (a === b) { if (a === b) {
return true; return true;
} }
@@ -265,9 +262,9 @@
} }
} }
return true; return true;
}; };
Kotlin.arrayDeepEquals = function (a, b) { Kotlin.arrayDeepEquals = function (a, b) {
if (a === b) { if (a === b) {
return true; return true;
} }
@@ -285,27 +282,26 @@
} }
} }
return true; return true;
}; };
Kotlin.arrayHashCode = function (arr) { Kotlin.arrayHashCode = function (arr) {
var result = 1; var result = 1;
for (var i = 0, n = arr.length; i < n; i++) { for (var i = 0, n = arr.length; i < n; i++) {
result = ((31 * result | 0) + Kotlin.hashCode(arr[i])) | 0; result = ((31 * result | 0) + Kotlin.hashCode(arr[i])) | 0;
} }
return result; return result;
}; };
Kotlin.arrayDeepHashCode = function (arr) { Kotlin.arrayDeepHashCode = function (arr) {
var result = 1; var result = 1;
for (var i = 0, n = arr.length; i < n; i++) { for (var i = 0, n = arr.length; i < n; i++) {
var e = arr[i]; var e = arr[i];
result = ((31 * result | 0) + (Array.isArray(e) ? Kotlin.arrayDeepHashCode(e) : Kotlin.hashCode(e))) | 0; result = ((31 * result | 0) + (Array.isArray(e) ? Kotlin.arrayDeepHashCode(e) : Kotlin.hashCode(e))) | 0;
} }
return result; return result;
}; };
var BaseOutput = Kotlin.createClassNow(null, null, {
var BaseOutput = Kotlin.createClassNow(null, null, {
println: function (a) { println: function (a) {
if (typeof a !== "undefined") this.print(a); if (typeof a !== "undefined") this.print(a);
this.print("\n"); this.print("\n");
@@ -313,9 +309,10 @@
flush: function () { flush: function () {
} }
} }
); );
Kotlin.NodeJsOutput = Kotlin.createClassNow(BaseOutput,
Kotlin.NodeJsOutput = Kotlin.createClassNow(BaseOutput,
function(outputStream) { function(outputStream) {
this.outputStream = outputStream; this.outputStream = outputStream;
}, { }, {
@@ -323,9 +320,9 @@
this.outputStream.write(a); this.outputStream.write(a);
} }
} }
); );
Kotlin.OutputToConsoleLog = Kotlin.createClassNow(BaseOutput, null, { Kotlin.OutputToConsoleLog = Kotlin.createClassNow(BaseOutput, null, {
print: function (a) { print: function (a) {
console.log(a); console.log(a);
}, },
@@ -333,9 +330,9 @@
this.print(typeof a !== "undefined" ? a : ""); this.print(typeof a !== "undefined" ? a : "");
} }
} }
); );
Kotlin.BufferedOutput = Kotlin.createClassNow(BaseOutput, Kotlin.BufferedOutput = Kotlin.createClassNow(BaseOutput,
function() { function() {
this.buffer = "" this.buffer = ""
}, { }, {
@@ -346,9 +343,9 @@
this.buffer = ""; this.buffer = "";
} }
} }
); );
Kotlin.BufferedOutputToConsoleLog = Kotlin.createClassNow(Kotlin.BufferedOutput, Kotlin.BufferedOutputToConsoleLog = Kotlin.createClassNow(Kotlin.BufferedOutput,
function() { function() {
Kotlin.BufferedOutput.call(this); Kotlin.BufferedOutput.call(this);
}, { }, {
@@ -371,24 +368,24 @@
this.buffer = ""; this.buffer = "";
} }
} }
); );
Kotlin.out = function() { Kotlin.out = function() {
var isNode = typeof process !== 'undefined' && process.versions && !!process.versions.node; var isNode = typeof process !== 'undefined' && process.versions && !!process.versions.node;
if (isNode) return new Kotlin.NodeJsOutput(process.stdout); if (isNode) return new Kotlin.NodeJsOutput(process.stdout);
return new Kotlin.BufferedOutputToConsoleLog(); return new Kotlin.BufferedOutputToConsoleLog();
}(); }();
Kotlin.println = function (s) { Kotlin.println = function (s) {
Kotlin.out.println(s); Kotlin.out.println(s);
}; };
Kotlin.print = function (s) { Kotlin.print = function (s) {
Kotlin.out.print(s); Kotlin.out.print(s);
}; };
Kotlin.collectionsMax = function (c, comp) { Kotlin.collectionsMax = function (c, comp) {
if (c.isEmpty()) { if (c.isEmpty()) {
//TODO: which exception? //TODO: which exception?
throw new Error(); throw new Error();
@@ -402,9 +399,9 @@
} }
} }
return max; return max;
}; };
Kotlin.collectionsSort = function (mutableList, comparator) { Kotlin.collectionsSort = function (mutableList, comparator) {
var boundComparator = void 0; var boundComparator = void 0;
if (comparator !== void 0) { if (comparator !== void 0) {
boundComparator = comparator.compare.bind(comparator); boundComparator = comparator.compare.bind(comparator);
@@ -419,18 +416,18 @@
mutableList.set_vux3hl$(i, array[i]); mutableList.set_vux3hl$(i, array[i]);
} }
} }
}; };
Kotlin.primitiveArraySort = function(array) { Kotlin.primitiveArraySort = function(array) {
array.sort(Kotlin.primitiveCompareTo) array.sort(Kotlin.primitiveCompareTo)
}; };
Kotlin.copyToArray = function (collection) { Kotlin.copyToArray = function (collection) {
if (typeof collection.toArray !== "undefined") return collection.toArray(); if (typeof collection.toArray !== "undefined") return collection.toArray();
return Kotlin.copyToArrayImpl(collection); return Kotlin.copyToArrayImpl(collection);
}; };
Kotlin.copyToArrayImpl = function (collection) { Kotlin.copyToArrayImpl = function (collection) {
var array = []; var array = [];
var it = collection.iterator(); var it = collection.iterator();
while (it.hasNext()) { while (it.hasNext()) {
@@ -438,66 +435,65 @@
} }
return array; return array;
}; };
Kotlin.splitString = function (str, regex, limit) { Kotlin.splitString = function (str, regex, limit) {
return str.split(new RegExp(regex), limit); return str.split(new RegExp(regex), limit);
}; };
Kotlin.nullArray = function (size) { Kotlin.nullArray = function (size) {
var res = []; var res = [];
var i = size; var i = size;
while (i > 0) { while (i > 0) {
res[--i] = null; res[--i] = null;
} }
return res; return res;
}; };
Kotlin.numberArrayOfSize = function (size) { Kotlin.numberArrayOfSize = function (size) {
return Kotlin.arrayFromFun(size, function () { return Kotlin.arrayFromFun(size, function () {
return 0; return 0;
}); });
}; };
Kotlin.charArrayOfSize = function (size) { Kotlin.charArrayOfSize = function (size) {
return Kotlin.arrayFromFun(size, function () { return Kotlin.arrayFromFun(size, function () {
return '\0'; return '\0';
}); });
}; };
Kotlin.booleanArrayOfSize = function (size) { Kotlin.booleanArrayOfSize = function (size) {
return Kotlin.arrayFromFun(size, function () { return Kotlin.arrayFromFun(size, function () {
return false; return false;
}); });
}; };
Kotlin.longArrayOfSize = function (size) { Kotlin.longArrayOfSize = function (size) {
return Kotlin.arrayFromFun(size, function () { return Kotlin.arrayFromFun(size, function () {
return Kotlin.Long.ZERO; return Kotlin.Long.ZERO;
}); });
}; };
Kotlin.arrayFromFun = function (size, initFun) { Kotlin.arrayFromFun = function (size, initFun) {
var result = new Array(size); var result = new Array(size);
for (var i = 0; i < size; i++) { for (var i = 0; i < size; i++) {
result[i] = initFun(i); result[i] = initFun(i);
} }
return result; return result;
}; };
Kotlin.deleteProperty = function (object, property) { Kotlin.deleteProperty = function (object, property) {
delete object[property]; delete object[property];
}; };
Kotlin.jsonAddProperties = function (obj1, obj2) { Kotlin.jsonAddProperties = function (obj1, obj2) {
for (var p in obj2) { for (var p in obj2) {
if (obj2.hasOwnProperty(p)) { if (obj2.hasOwnProperty(p)) {
obj1[p] = obj2[p]; obj1[p] = obj2[p];
} }
} }
return obj1; return obj1;
}; };
Kotlin.identityHashCode = getObjectHashCode; Kotlin.identityHashCode = getObjectHashCode;
})(Kotlin);
+156 -160
View File
@@ -26,10 +26,7 @@
// distributed under the License is distributed on an "AS-IS" BASIS, // distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
(function (Kotlin) { /**
"use strict";
/**
* Constructs a 64-bit two's-complement integer, given its low and high 32-bit * Constructs a 64-bit two's-complement integer, given its low and high 32-bit
* values as *signed* integers. See the from* functions below for more * values as *signed* integers. See the from* functions below for more
* convenient ways of constructing Longs. * convenient ways of constructing Longs.
@@ -53,7 +50,7 @@
* @constructor * @constructor
* @final * @final
*/ */
Kotlin.Long = function(low, high) { Kotlin.Long = function(low, high) {
/** /**
* @type {number} * @type {number}
* @private * @private
@@ -65,27 +62,27 @@
* @private * @private
*/ */
this.high_ = high | 0; // force into 32 signed bits. this.high_ = high | 0; // force into 32 signed bits.
}; };
// NOTE: Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the // NOTE: Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the
// from* methods on which they depend. // from* methods on which they depend.
/** /**
* A cache of the Long representations of small integer values. * A cache of the Long representations of small integer values.
* @type {!Object} * @type {!Object}
* @private * @private
*/ */
Kotlin.Long.IntCache_ = {}; Kotlin.Long.IntCache_ = {};
/** /**
* Returns a Long representing the given (32-bit) integer value. * Returns a Long representing the given (32-bit) integer value.
* @param {number} value The 32-bit integer in question. * @param {number} value The 32-bit integer in question.
* @return {!Kotlin.Long} The corresponding Long value. * @return {!Kotlin.Long} The corresponding Long value.
*/ */
Kotlin.Long.fromInt = function(value) { Kotlin.Long.fromInt = function(value) {
if (-128 <= value && value < 128) { if (-128 <= value && value < 128) {
var cachedObj = Kotlin.Long.IntCache_[value]; var cachedObj = Kotlin.Long.IntCache_[value];
if (cachedObj) { if (cachedObj) {
@@ -98,16 +95,16 @@
Kotlin.Long.IntCache_[value] = obj; Kotlin.Long.IntCache_[value] = obj;
} }
return obj; return obj;
}; };
/** /**
* Returns a Long representing the given value, provided that it is a finite * Returns a Long representing the given value, provided that it is a finite
* number. Otherwise, zero is returned. * number. Otherwise, zero is returned.
* @param {number} value The number in question. * @param {number} value The number in question.
* @return {!Kotlin.Long} The corresponding Long value. * @return {!Kotlin.Long} The corresponding Long value.
*/ */
Kotlin.Long.fromNumber = function(value) { Kotlin.Long.fromNumber = function(value) {
if (isNaN(value) || !isFinite(value)) { if (isNaN(value) || !isFinite(value)) {
return Kotlin.Long.ZERO; return Kotlin.Long.ZERO;
} else if (value <= -Kotlin.Long.TWO_PWR_63_DBL_) { } else if (value <= -Kotlin.Long.TWO_PWR_63_DBL_) {
@@ -121,29 +118,29 @@
(value % Kotlin.Long.TWO_PWR_32_DBL_) | 0, (value % Kotlin.Long.TWO_PWR_32_DBL_) | 0,
(value / Kotlin.Long.TWO_PWR_32_DBL_) | 0); (value / Kotlin.Long.TWO_PWR_32_DBL_) | 0);
} }
}; };
/** /**
* Returns a Long representing the 64-bit integer that comes by concatenating * Returns a Long representing the 64-bit integer that comes by concatenating
* the given high and low bits. Each is assumed to use 32 bits. * the given high and low bits. Each is assumed to use 32 bits.
* @param {number} lowBits The low 32-bits. * @param {number} lowBits The low 32-bits.
* @param {number} highBits The high 32-bits. * @param {number} highBits The high 32-bits.
* @return {!Kotlin.Long} The corresponding Long value. * @return {!Kotlin.Long} The corresponding Long value.
*/ */
Kotlin.Long.fromBits = function(lowBits, highBits) { Kotlin.Long.fromBits = function(lowBits, highBits) {
return new Kotlin.Long(lowBits, highBits); return new Kotlin.Long(lowBits, highBits);
}; };
/** /**
* Returns a Long representation of the given string, written using the given * Returns a Long representation of the given string, written using the given
* radix. * radix.
* @param {string} str The textual representation of the Long. * @param {string} str The textual representation of the Long.
* @param {number=} opt_radix The radix in which the text is written. * @param {number=} opt_radix The radix in which the text is written.
* @return {!Kotlin.Long} The corresponding Long value. * @return {!Kotlin.Long} The corresponding Long value.
*/ */
Kotlin.Long.fromString = function(str, opt_radix) { Kotlin.Long.fromString = function(str, opt_radix) {
if (str.length == 0) { if (str.length == 0) {
throw Error('number format error: empty string'); throw Error('number format error: empty string');
} }
@@ -176,120 +173,120 @@
} }
} }
return result; return result;
}; };
// NOTE: the compiler should inline these constant values below and then remove // NOTE: the compiler should inline these constant values below and then remove
// these variables, so there should be no runtime penalty for these. // these variables, so there should be no runtime penalty for these.
/** /**
* Number used repeated below in calculations. This must appear before the * Number used repeated below in calculations. This must appear before the
* first call to any from* function below. * first call to any from* function below.
* @type {number} * @type {number}
* @private * @private
*/ */
Kotlin.Long.TWO_PWR_16_DBL_ = 1 << 16; Kotlin.Long.TWO_PWR_16_DBL_ = 1 << 16;
/** /**
* @type {number} * @type {number}
* @private * @private
*/ */
Kotlin.Long.TWO_PWR_24_DBL_ = 1 << 24; Kotlin.Long.TWO_PWR_24_DBL_ = 1 << 24;
/** /**
* @type {number} * @type {number}
* @private * @private
*/ */
Kotlin.Long.TWO_PWR_32_DBL_ = Kotlin.Long.TWO_PWR_32_DBL_ =
Kotlin.Long.TWO_PWR_16_DBL_ * Kotlin.Long.TWO_PWR_16_DBL_; Kotlin.Long.TWO_PWR_16_DBL_ * Kotlin.Long.TWO_PWR_16_DBL_;
/** /**
* @type {number} * @type {number}
* @private * @private
*/ */
Kotlin.Long.TWO_PWR_31_DBL_ = Kotlin.Long.TWO_PWR_31_DBL_ =
Kotlin.Long.TWO_PWR_32_DBL_ / 2; Kotlin.Long.TWO_PWR_32_DBL_ / 2;
/** /**
* @type {number} * @type {number}
* @private * @private
*/ */
Kotlin.Long.TWO_PWR_48_DBL_ = Kotlin.Long.TWO_PWR_48_DBL_ =
Kotlin.Long.TWO_PWR_32_DBL_ * Kotlin.Long.TWO_PWR_16_DBL_; Kotlin.Long.TWO_PWR_32_DBL_ * Kotlin.Long.TWO_PWR_16_DBL_;
/** /**
* @type {number} * @type {number}
* @private * @private
*/ */
Kotlin.Long.TWO_PWR_64_DBL_ = Kotlin.Long.TWO_PWR_64_DBL_ =
Kotlin.Long.TWO_PWR_32_DBL_ * Kotlin.Long.TWO_PWR_32_DBL_; Kotlin.Long.TWO_PWR_32_DBL_ * Kotlin.Long.TWO_PWR_32_DBL_;
/** /**
* @type {number} * @type {number}
* @private * @private
*/ */
Kotlin.Long.TWO_PWR_63_DBL_ = Kotlin.Long.TWO_PWR_63_DBL_ =
Kotlin.Long.TWO_PWR_64_DBL_ / 2; Kotlin.Long.TWO_PWR_64_DBL_ / 2;
/** @type {!Kotlin.Long} */ /** @type {!Kotlin.Long} */
Kotlin.Long.ZERO = Kotlin.Long.fromInt(0); Kotlin.Long.ZERO = Kotlin.Long.fromInt(0);
/** @type {!Kotlin.Long} */ /** @type {!Kotlin.Long} */
Kotlin.Long.ONE = Kotlin.Long.fromInt(1); Kotlin.Long.ONE = Kotlin.Long.fromInt(1);
/** @type {!Kotlin.Long} */ /** @type {!Kotlin.Long} */
Kotlin.Long.NEG_ONE = Kotlin.Long.fromInt(-1); Kotlin.Long.NEG_ONE = Kotlin.Long.fromInt(-1);
/** @type {!Kotlin.Long} */ /** @type {!Kotlin.Long} */
Kotlin.Long.MAX_VALUE = Kotlin.Long.MAX_VALUE =
Kotlin.Long.fromBits(0xFFFFFFFF | 0, 0x7FFFFFFF | 0); Kotlin.Long.fromBits(0xFFFFFFFF | 0, 0x7FFFFFFF | 0);
/** @type {!Kotlin.Long} */ /** @type {!Kotlin.Long} */
Kotlin.Long.MIN_VALUE = Kotlin.Long.fromBits(0, 0x80000000 | 0); Kotlin.Long.MIN_VALUE = Kotlin.Long.fromBits(0, 0x80000000 | 0);
/** /**
* @type {!Kotlin.Long} * @type {!Kotlin.Long}
* @private * @private
*/ */
Kotlin.Long.TWO_PWR_24_ = Kotlin.Long.fromInt(1 << 24); Kotlin.Long.TWO_PWR_24_ = Kotlin.Long.fromInt(1 << 24);
/** @return {number} The value, assuming it is a 32-bit integer. */ /** @return {number} The value, assuming it is a 32-bit integer. */
Kotlin.Long.prototype.toInt = function() { Kotlin.Long.prototype.toInt = function() {
return this.low_; return this.low_;
}; };
/** @return {number} The closest floating-point representation to this value. */ /** @return {number} The closest floating-point representation to this value. */
Kotlin.Long.prototype.toNumber = function() { Kotlin.Long.prototype.toNumber = function() {
return this.high_ * Kotlin.Long.TWO_PWR_32_DBL_ + return this.high_ * Kotlin.Long.TWO_PWR_32_DBL_ +
this.getLowBitsUnsigned(); this.getLowBitsUnsigned();
}; };
/** @return {number} The 32-bit hashCode of this value. */ /** @return {number} The 32-bit hashCode of this value. */
Kotlin.Long.prototype.hashCode = function() { Kotlin.Long.prototype.hashCode = function() {
return this.high_ ^ this.low_; return this.high_ ^ this.low_;
}; };
/** /**
* @param {number=} opt_radix The radix in which the text should be written. * @param {number=} opt_radix The radix in which the text should be written.
* @return {string} The textual representation of this value. * @return {string} The textual representation of this value.
* @override * @override
*/ */
Kotlin.Long.prototype.toString = function(opt_radix) { Kotlin.Long.prototype.toString = function(opt_radix) {
var radix = opt_radix || 10; var radix = opt_radix || 10;
if (radix < 2 || 36 < radix) { if (radix < 2 || 36 < radix) {
throw Error('radix out of range: ' + radix); throw Error('radix out of range: ' + radix);
@@ -333,33 +330,33 @@
result = '' + digits + result; result = '' + digits + result;
} }
} }
}; };
/** @return {number} The high 32-bits as a signed value. */ /** @return {number} The high 32-bits as a signed value. */
Kotlin.Long.prototype.getHighBits = function() { Kotlin.Long.prototype.getHighBits = function() {
return this.high_; return this.high_;
}; };
/** @return {number} The low 32-bits as a signed value. */ /** @return {number} The low 32-bits as a signed value. */
Kotlin.Long.prototype.getLowBits = function() { Kotlin.Long.prototype.getLowBits = function() {
return this.low_; return this.low_;
}; };
/** @return {number} The low 32-bits as an unsigned value. */ /** @return {number} The low 32-bits as an unsigned value. */
Kotlin.Long.prototype.getLowBitsUnsigned = function() { Kotlin.Long.prototype.getLowBitsUnsigned = function() {
return (this.low_ >= 0) ? return (this.low_ >= 0) ?
this.low_ : Kotlin.Long.TWO_PWR_32_DBL_ + this.low_; this.low_ : Kotlin.Long.TWO_PWR_32_DBL_ + this.low_;
}; };
/** /**
* @return {number} Returns the number of bits needed to represent the absolute * @return {number} Returns the number of bits needed to represent the absolute
* value of this Long. * value of this Long.
*/ */
Kotlin.Long.prototype.getNumBitsAbs = function() { Kotlin.Long.prototype.getNumBitsAbs = function() {
if (this.isNegative()) { if (this.isNegative()) {
if (this.equals(Kotlin.Long.MIN_VALUE)) { if (this.equals(Kotlin.Long.MIN_VALUE)) {
return 64; return 64;
@@ -375,88 +372,88 @@
} }
return this.high_ != 0 ? bit + 33 : bit + 1; return this.high_ != 0 ? bit + 33 : bit + 1;
} }
}; };
/** @return {boolean} Whether this value is zero. */ /** @return {boolean} Whether this value is zero. */
Kotlin.Long.prototype.isZero = function() { Kotlin.Long.prototype.isZero = function() {
return this.high_ == 0 && this.low_ == 0; return this.high_ == 0 && this.low_ == 0;
}; };
/** @return {boolean} Whether this value is negative. */ /** @return {boolean} Whether this value is negative. */
Kotlin.Long.prototype.isNegative = function() { Kotlin.Long.prototype.isNegative = function() {
return this.high_ < 0; return this.high_ < 0;
}; };
/** @return {boolean} Whether this value is odd. */ /** @return {boolean} Whether this value is odd. */
Kotlin.Long.prototype.isOdd = function() { Kotlin.Long.prototype.isOdd = function() {
return (this.low_ & 1) == 1; return (this.low_ & 1) == 1;
}; };
/** /**
* @param {Kotlin.Long} other Long to compare against. * @param {Kotlin.Long} other Long to compare against.
* @return {boolean} Whether this Long equals the other. * @return {boolean} Whether this Long equals the other.
*/ */
Kotlin.Long.prototype.equals = function(other) { Kotlin.Long.prototype.equals = function(other) {
return (this.high_ == other.high_) && (this.low_ == other.low_); return (this.high_ == other.high_) && (this.low_ == other.low_);
}; };
/** /**
* @param {Kotlin.Long} other Long to compare against. * @param {Kotlin.Long} other Long to compare against.
* @return {boolean} Whether this Long does not equal the other. * @return {boolean} Whether this Long does not equal the other.
*/ */
Kotlin.Long.prototype.notEquals = function(other) { Kotlin.Long.prototype.notEquals = function(other) {
return (this.high_ != other.high_) || (this.low_ != other.low_); return (this.high_ != other.high_) || (this.low_ != other.low_);
}; };
/** /**
* @param {Kotlin.Long} other Long to compare against. * @param {Kotlin.Long} other Long to compare against.
* @return {boolean} Whether this Long is less than the other. * @return {boolean} Whether this Long is less than the other.
*/ */
Kotlin.Long.prototype.lessThan = function(other) { Kotlin.Long.prototype.lessThan = function(other) {
return this.compare(other) < 0; return this.compare(other) < 0;
}; };
/** /**
* @param {Kotlin.Long} other Long to compare against. * @param {Kotlin.Long} other Long to compare against.
* @return {boolean} Whether this Long is less than or equal to the other. * @return {boolean} Whether this Long is less than or equal to the other.
*/ */
Kotlin.Long.prototype.lessThanOrEqual = function(other) { Kotlin.Long.prototype.lessThanOrEqual = function(other) {
return this.compare(other) <= 0; return this.compare(other) <= 0;
}; };
/** /**
* @param {Kotlin.Long} other Long to compare against. * @param {Kotlin.Long} other Long to compare against.
* @return {boolean} Whether this Long is greater than the other. * @return {boolean} Whether this Long is greater than the other.
*/ */
Kotlin.Long.prototype.greaterThan = function(other) { Kotlin.Long.prototype.greaterThan = function(other) {
return this.compare(other) > 0; return this.compare(other) > 0;
}; };
/** /**
* @param {Kotlin.Long} other Long to compare against. * @param {Kotlin.Long} other Long to compare against.
* @return {boolean} Whether this Long is greater than or equal to the other. * @return {boolean} Whether this Long is greater than or equal to the other.
*/ */
Kotlin.Long.prototype.greaterThanOrEqual = function(other) { Kotlin.Long.prototype.greaterThanOrEqual = function(other) {
return this.compare(other) >= 0; return this.compare(other) >= 0;
}; };
/** /**
* Compares this Long with the given one. * Compares this Long with the given one.
* @param {Kotlin.Long} other Long to compare against. * @param {Kotlin.Long} other Long to compare against.
* @return {number} 0 if they are the same, 1 if the this is greater, and -1 * @return {number} 0 if they are the same, 1 if the this is greater, and -1
* if the given one is greater. * if the given one is greater.
*/ */
Kotlin.Long.prototype.compare = function(other) { Kotlin.Long.prototype.compare = function(other) {
if (this.equals(other)) { if (this.equals(other)) {
return 0; return 0;
} }
@@ -476,25 +473,25 @@
} else { } else {
return 1; return 1;
} }
}; };
/** @return {!Kotlin.Long} The negation of this value. */ /** @return {!Kotlin.Long} The negation of this value. */
Kotlin.Long.prototype.negate = function() { Kotlin.Long.prototype.negate = function() {
if (this.equals(Kotlin.Long.MIN_VALUE)) { if (this.equals(Kotlin.Long.MIN_VALUE)) {
return Kotlin.Long.MIN_VALUE; return Kotlin.Long.MIN_VALUE;
} else { } else {
return this.not().add(Kotlin.Long.ONE); return this.not().add(Kotlin.Long.ONE);
} }
}; };
/** /**
* Returns the sum of this and the given Long. * Returns the sum of this and the given Long.
* @param {Kotlin.Long} other Long to add to this one. * @param {Kotlin.Long} other Long to add to this one.
* @return {!Kotlin.Long} The sum of this and the given Long. * @return {!Kotlin.Long} The sum of this and the given Long.
*/ */
Kotlin.Long.prototype.add = function(other) { Kotlin.Long.prototype.add = function(other) {
// Divide each number into 4 chunks of 16 bits, and then sum the chunks. // Divide each number into 4 chunks of 16 bits, and then sum the chunks.
var a48 = this.high_ >>> 16; var a48 = this.high_ >>> 16;
@@ -520,25 +517,25 @@
c48 += a48 + b48; c48 += a48 + b48;
c48 &= 0xFFFF; c48 &= 0xFFFF;
return Kotlin.Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32); return Kotlin.Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32);
}; };
/** /**
* Returns the difference of this and the given Long. * Returns the difference of this and the given Long.
* @param {Kotlin.Long} other Long to subtract from this. * @param {Kotlin.Long} other Long to subtract from this.
* @return {!Kotlin.Long} The difference of this and the given Long. * @return {!Kotlin.Long} The difference of this and the given Long.
*/ */
Kotlin.Long.prototype.subtract = function(other) { Kotlin.Long.prototype.subtract = function(other) {
return this.add(other.negate()); return this.add(other.negate());
}; };
/** /**
* Returns the product of this and the given long. * Returns the product of this and the given long.
* @param {Kotlin.Long} other Long to multiply with this. * @param {Kotlin.Long} other Long to multiply with this.
* @return {!Kotlin.Long} The product of this and the other. * @return {!Kotlin.Long} The product of this and the other.
*/ */
Kotlin.Long.prototype.multiply = function(other) { Kotlin.Long.prototype.multiply = function(other) {
if (this.isZero()) { if (this.isZero()) {
return Kotlin.Long.ZERO; return Kotlin.Long.ZERO;
} else if (other.isZero()) { } else if (other.isZero()) {
@@ -602,15 +599,15 @@
c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48; c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
c48 &= 0xFFFF; c48 &= 0xFFFF;
return Kotlin.Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32); return Kotlin.Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32);
}; };
/** /**
* Returns this Long divided by the given one. * Returns this Long divided by the given one.
* @param {Kotlin.Long} other Long by which to divide. * @param {Kotlin.Long} other Long by which to divide.
* @return {!Kotlin.Long} This Long divided by the given one. * @return {!Kotlin.Long} This Long divided by the given one.
*/ */
Kotlin.Long.prototype.div = function(other) { Kotlin.Long.prototype.div = function(other) {
if (other.isZero()) { if (other.isZero()) {
throw Error('division by zero'); throw Error('division by zero');
} else if (this.isZero()) { } else if (this.isZero()) {
@@ -686,64 +683,64 @@
rem = rem.subtract(approxRem); rem = rem.subtract(approxRem);
} }
return res; return res;
}; };
/** /**
* Returns this Long modulo the given one. * Returns this Long modulo the given one.
* @param {Kotlin.Long} other Long by which to mod. * @param {Kotlin.Long} other Long by which to mod.
* @return {!Kotlin.Long} This Long modulo the given one. * @return {!Kotlin.Long} This Long modulo the given one.
*/ */
Kotlin.Long.prototype.modulo = function(other) { Kotlin.Long.prototype.modulo = function(other) {
return this.subtract(this.div(other).multiply(other)); return this.subtract(this.div(other).multiply(other));
}; };
/** @return {!Kotlin.Long} The bitwise-NOT of this value. */ /** @return {!Kotlin.Long} The bitwise-NOT of this value. */
Kotlin.Long.prototype.not = function() { Kotlin.Long.prototype.not = function() {
return Kotlin.Long.fromBits(~this.low_, ~this.high_); return Kotlin.Long.fromBits(~this.low_, ~this.high_);
}; };
/** /**
* Returns the bitwise-AND of this Long and the given one. * Returns the bitwise-AND of this Long and the given one.
* @param {Kotlin.Long} other The Long with which to AND. * @param {Kotlin.Long} other The Long with which to AND.
* @return {!Kotlin.Long} The bitwise-AND of this and the other. * @return {!Kotlin.Long} The bitwise-AND of this and the other.
*/ */
Kotlin.Long.prototype.and = function(other) { Kotlin.Long.prototype.and = function(other) {
return Kotlin.Long.fromBits(this.low_ & other.low_, return Kotlin.Long.fromBits(this.low_ & other.low_,
this.high_ & other.high_); this.high_ & other.high_);
}; };
/** /**
* Returns the bitwise-OR of this Long and the given one. * Returns the bitwise-OR of this Long and the given one.
* @param {Kotlin.Long} other The Long with which to OR. * @param {Kotlin.Long} other The Long with which to OR.
* @return {!Kotlin.Long} The bitwise-OR of this and the other. * @return {!Kotlin.Long} The bitwise-OR of this and the other.
*/ */
Kotlin.Long.prototype.or = function(other) { Kotlin.Long.prototype.or = function(other) {
return Kotlin.Long.fromBits(this.low_ | other.low_, return Kotlin.Long.fromBits(this.low_ | other.low_,
this.high_ | other.high_); this.high_ | other.high_);
}; };
/** /**
* Returns the bitwise-XOR of this Long and the given one. * Returns the bitwise-XOR of this Long and the given one.
* @param {Kotlin.Long} other The Long with which to XOR. * @param {Kotlin.Long} other The Long with which to XOR.
* @return {!Kotlin.Long} The bitwise-XOR of this and the other. * @return {!Kotlin.Long} The bitwise-XOR of this and the other.
*/ */
Kotlin.Long.prototype.xor = function(other) { Kotlin.Long.prototype.xor = function(other) {
return Kotlin.Long.fromBits(this.low_ ^ other.low_, return Kotlin.Long.fromBits(this.low_ ^ other.low_,
this.high_ ^ other.high_); this.high_ ^ other.high_);
}; };
/** /**
* Returns this Long with bits shifted to the left by the given amount. * Returns this Long with bits shifted to the left by the given amount.
* @param {number} numBits The number of bits by which to shift. * @param {number} numBits The number of bits by which to shift.
* @return {!Kotlin.Long} This shifted to the left by the given amount. * @return {!Kotlin.Long} This shifted to the left by the given amount.
*/ */
Kotlin.Long.prototype.shiftLeft = function(numBits) { Kotlin.Long.prototype.shiftLeft = function(numBits) {
numBits &= 63; numBits &= 63;
if (numBits == 0) { if (numBits == 0) {
return this; return this;
@@ -758,15 +755,15 @@
return Kotlin.Long.fromBits(0, low << (numBits - 32)); return Kotlin.Long.fromBits(0, low << (numBits - 32));
} }
} }
}; };
/** /**
* Returns this Long with bits shifted to the right by the given amount. * Returns this Long with bits shifted to the right by the given amount.
* @param {number} numBits The number of bits by which to shift. * @param {number} numBits The number of bits by which to shift.
* @return {!Kotlin.Long} This shifted to the right by the given amount. * @return {!Kotlin.Long} This shifted to the right by the given amount.
*/ */
Kotlin.Long.prototype.shiftRight = function(numBits) { Kotlin.Long.prototype.shiftRight = function(numBits) {
numBits &= 63; numBits &= 63;
if (numBits == 0) { if (numBits == 0) {
return this; return this;
@@ -783,17 +780,17 @@
high >= 0 ? 0 : -1); high >= 0 ? 0 : -1);
} }
} }
}; };
/** /**
* Returns this Long with bits shifted to the right by the given amount, with * Returns this Long with bits shifted to the right by the given amount, with
* zeros placed into the new leading bits. * zeros placed into the new leading bits.
* @param {number} numBits The number of bits by which to shift. * @param {number} numBits The number of bits by which to shift.
* @return {!Kotlin.Long} This shifted to the right by the given amount, with * @return {!Kotlin.Long} This shifted to the right by the given amount, with
* zeros placed into the new leading bits. * zeros placed into the new leading bits.
*/ */
Kotlin.Long.prototype.shiftRightUnsigned = function(numBits) { Kotlin.Long.prototype.shiftRightUnsigned = function(numBits) {
numBits &= 63; numBits &= 63;
if (numBits == 0) { if (numBits == 0) {
return this; return this;
@@ -810,35 +807,34 @@
return Kotlin.Long.fromBits(high >>> (numBits - 32), 0); return Kotlin.Long.fromBits(high >>> (numBits - 32), 0);
} }
} }
}; };
// Support for Kotlin // Support for Kotlin
Kotlin.Long.prototype.equals_za3rmp$ = function (other) { Kotlin.Long.prototype.equals_za3rmp$ = function (other) {
return other instanceof Kotlin.Long && this.equals(other); return other instanceof Kotlin.Long && this.equals(other);
}; };
Kotlin.Long.prototype.compareTo_za3rmp$ = Kotlin.Long.prototype.compare; Kotlin.Long.prototype.compareTo_za3rmp$ = Kotlin.Long.prototype.compare;
Kotlin.Long.prototype.inc = function() { Kotlin.Long.prototype.inc = function() {
return this.add(Kotlin.Long.ONE); return this.add(Kotlin.Long.ONE);
}; };
Kotlin.Long.prototype.dec = function() { Kotlin.Long.prototype.dec = function() {
return this.add(Kotlin.Long.NEG_ONE); return this.add(Kotlin.Long.NEG_ONE);
}; };
Kotlin.Long.prototype.valueOf = function() { Kotlin.Long.prototype.valueOf = function() {
return this.toNumber(); return this.toNumber();
}; };
Kotlin.Long.prototype.unaryPlus = function() { Kotlin.Long.prototype.unaryPlus = function() {
return this; return this;
}; };
Kotlin.Long.prototype.unaryMinus = Kotlin.Long.prototype.negate; Kotlin.Long.prototype.unaryMinus = Kotlin.Long.prototype.negate;
Kotlin.Long.prototype.inv = Kotlin.Long.prototype.not; Kotlin.Long.prototype.inv = Kotlin.Long.prototype.not;
Kotlin.Long.prototype.rangeTo = function (other) { Kotlin.Long.prototype.rangeTo = function (other) {
return new Kotlin.kotlin.ranges.LongRange(this, other); return new Kotlin.kotlin.ranges.LongRange(this, other);
}; };
}(Kotlin));
-12
View File
@@ -1,12 +0,0 @@
var require = (function () {
var builtins = module.exports.kotlin;
var propertyNames = Object.getOwnPropertyNames(builtins);
Kotlin.kotlin = Kotlin.kotlin || {};
for (var i = 0; i < propertyNames.length; ++i) {
var propertyName = propertyNames[i];
Kotlin.kotlin[propertyName] = builtins[propertyName];
}
return function() {
return Kotlin;
}
})();
-16
View File
@@ -1,16 +0,0 @@
(function () {
var stdlib = module.exports;
function copyProperties(from, to) {
var propertyNames = Object.getOwnPropertyNames(from);
for (var i = 0; i < propertyNames.length; ++i) {
var propertyName = propertyNames[i];
if (propertyName in to) {
copyProperties(from[propertyName], to[propertyName]);
}
else {
to[propertyName] = from[propertyName];
}
}
}
copyProperties(stdlib, Kotlin);
})();
+17 -12
View File
@@ -1,24 +1,29 @@
var emulatedModules = { kotlin: kotlin }; var emulatedModules = { kotlin: kotlin };
var module = { exports: {} }; var module = { exports: {} };
function require(moduleId) { function require(moduleId) {
return emulatedModules[moduleId]; return emulatedModules[moduleId];
} }
function __beginModule__() { function __beginModule__() {
module.exports = {}; module.exports = {};
} }
function __endModule__(moduleId) { function __endModule__(moduleId) {
emulatedModules[moduleId] = module.exports; emulatedModules[moduleId] = module.exports;
} }
function define(moduleId, dependencies, body) { function define(moduleId, dependencies, body) {
var resolvedDependencies = []; var resolvedDependencies = [];
emulatedModules[moduleId] = {};
for (var i = 0; i < dependencies.length; ++i) { for (var i = 0; i < dependencies.length; ++i) {
resolvedDependencies.push(emulatedModules[dependencies[i]]); var dependencyName = dependencies[i];
resolvedDependencies.push(emulatedModules[dependencyName === 'exports' ? moduleId : dependencyName]);
} }
emulatedModules[moduleId] = body.apply(null, resolvedDependencies); var result = body.apply(null, resolvedDependencies);
if (result != null) {
emulatedModules[moduleId] = result;
} }
define.amd = {}; }
define.amd = {};