firefly-compiler 0.5.79 → 0.5.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler/Builder.ff +31 -39
- package/compiler/Compiler.ff +14 -4
- package/compiler/DevelopMode.ff +406 -0
- package/compiler/Main.ff +73 -53
- package/compiler/ModuleCache.ff +5 -5
- package/core/.firefly/include/package.json +1 -1
- package/core/BuildSystem.ff +82 -11
- package/core/NodeSystem.ff +47 -30
- package/core/Path.ff +7 -2
- package/experimental/proxy/Main.ff +60 -0
- package/experimental/proxy/Runner.ff +11 -0
- package/experimental/proxy/Tcp.ff +162 -0
- package/experimental/random/Superdigit.ff +18 -0
- package/experimental/terrain/Main.ff +40 -0
- package/experimental/terrain/Terrain.ff +97 -0
- package/experimental/terrain/Terrain2.ff +109 -0
- package/fireflysite/Main.ff +0 -1
- package/fireflysite/assets/markdown/reference/statements-and-expressions.md +1 -1
- package/lsp/CompletionHandler.ff +2 -2
- package/output/js/ff/compiler/Builder.mjs +24 -48
- package/output/js/ff/compiler/Builder.mjs.map +7 -11
- package/output/js/ff/compiler/Compiler.mjs +66 -12
- package/output/js/ff/compiler/Compiler.mjs.map +18 -14
- package/output/js/ff/compiler/Dependencies.mjs.map +2 -2
- package/output/js/ff/compiler/DependencyLock.mjs.map +1 -1
- package/output/js/ff/compiler/Deriver.mjs.map +1 -1
- package/output/js/ff/compiler/DevelopMode.mjs +1049 -0
- package/output/js/ff/compiler/DevelopMode.mjs.map +183 -0
- package/output/js/ff/compiler/Dictionaries.mjs.map +1 -1
- package/output/js/ff/compiler/Environment.mjs.map +1 -1
- package/output/js/ff/compiler/Inference.mjs.map +1 -1
- package/output/js/ff/compiler/JsEmitter.mjs.map +1 -1
- package/output/js/ff/compiler/JsImporter.mjs.map +1 -1
- package/output/js/ff/compiler/LspHook.mjs.map +1 -1
- package/output/js/ff/compiler/Main.mjs +256 -105
- package/output/js/ff/compiler/Main.mjs.map +43 -38
- package/output/js/ff/compiler/ModuleCache.mjs +12 -8
- package/output/js/ff/compiler/ModuleCache.mjs.map +4 -3
- package/output/js/ff/compiler/Parser.mjs.map +1 -1
- package/output/js/ff/compiler/Patterns.mjs.map +1 -1
- package/output/js/ff/compiler/Resolver.mjs.map +1 -1
- package/output/js/ff/compiler/SourceMap.mjs.map +1 -1
- package/output/js/ff/compiler/Substitution.mjs.map +1 -1
- package/output/js/ff/compiler/Syntax.mjs.map +1 -1
- package/output/js/ff/compiler/Token.mjs.map +1 -1
- package/output/js/ff/compiler/Tokenizer.mjs.map +1 -1
- package/output/js/ff/compiler/Unification.mjs.map +1 -1
- package/output/js/ff/compiler/Wildcards.mjs.map +1 -1
- package/output/js/ff/compiler/Workspace.mjs.map +1 -1
- package/output/js/ff/core/Any.mjs.map +1 -1
- package/output/js/ff/core/Array.mjs.map +1 -1
- package/output/js/ff/core/AssetSystem.mjs.map +1 -1
- package/output/js/ff/core/Atomic.mjs.map +1 -1
- package/output/js/ff/core/Bool.mjs.map +1 -1
- package/output/js/ff/core/BrowserSystem.mjs.map +1 -1
- package/output/js/ff/core/Buffer.mjs.map +1 -1
- package/output/js/ff/core/BuildSystem.mjs +116 -12
- package/output/js/ff/core/BuildSystem.mjs.map +35 -6
- package/output/js/ff/core/Channel.mjs.map +1 -1
- package/output/js/ff/core/Char.mjs.map +1 -1
- package/output/js/ff/core/Core.mjs.map +1 -1
- package/output/js/ff/core/Crypto.mjs.map +1 -1
- package/output/js/ff/core/Date.mjs.map +1 -1
- package/output/js/ff/core/Duration.mjs.map +1 -1
- package/output/js/ff/core/Equal.mjs.map +1 -1
- package/output/js/ff/core/Error.mjs.map +1 -1
- package/output/js/ff/core/FileHandle.mjs.map +1 -1
- package/output/js/ff/core/Float.mjs.map +1 -1
- package/output/js/ff/core/HttpClient.mjs.map +1 -1
- package/output/js/ff/core/Int.mjs.map +1 -1
- package/output/js/ff/core/IntMap.mjs.map +1 -1
- package/output/js/ff/core/Js.mjs.map +1 -1
- package/output/js/ff/core/JsSystem.mjs.map +1 -1
- package/output/js/ff/core/JsValue.mjs.map +1 -1
- package/output/js/ff/core/Json.mjs.map +1 -1
- package/output/js/ff/core/List.mjs.map +1 -1
- package/output/js/ff/core/Lock.mjs.map +1 -1
- package/output/js/ff/core/Log.mjs.map +1 -1
- package/output/js/ff/core/Map.mjs.map +1 -1
- package/output/js/ff/core/NodeSystem.mjs +54 -20
- package/output/js/ff/core/NodeSystem.mjs.map +14 -6
- package/output/js/ff/core/Nothing.mjs.map +1 -1
- package/output/js/ff/core/Option.mjs.map +1 -1
- package/output/js/ff/core/Ordering.mjs.map +1 -1
- package/output/js/ff/core/Pair.mjs.map +1 -1
- package/output/js/ff/core/Path.mjs +30 -4
- package/output/js/ff/core/Path.mjs.map +8 -6
- package/output/js/ff/core/Queue.mjs.map +1 -1
- package/output/js/ff/core/Random.mjs.map +1 -1
- package/output/js/ff/core/RbMap.mjs.map +1 -1
- package/output/js/ff/core/Serializable.mjs.map +1 -1
- package/output/js/ff/core/Set.mjs.map +1 -1
- package/output/js/ff/core/Show.mjs.map +1 -1
- package/output/js/ff/core/SourceLocation.mjs.map +1 -1
- package/output/js/ff/core/Stream.mjs.map +1 -1
- package/output/js/ff/core/String.mjs.map +1 -1
- package/output/js/ff/core/StringMap.mjs.map +1 -1
- package/output/js/ff/core/Task.mjs.map +1 -1
- package/output/js/ff/core/Try.mjs.map +1 -1
- package/output/js/ff/core/Unit.mjs.map +1 -1
- package/output/js/ff/core/node_modules +1 -0
- package/package.json +1 -1
- package/vscode/package.json +1 -1
- package/webserver/.firefly/include/package.json +1 -1
- package/webserver/WebServer.ff +6 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": [
|
|
4
|
-
"
|
|
4
|
+
"../../../../core/Date.ff"
|
|
5
5
|
],
|
|
6
6
|
"sourcesContent": [
|
|
7
7
|
"// Temporal.ZonedDateTime but with consistent equals/compare\r\nnewtype Date(jsValue: JsValue)\r\n\r\ndata DateGap(\r\n years: Int = 0\r\n months: Int = 0\r\n weeks: Int = 0\r\n days: Int = 0\r\n hours: Int = 0\r\n minutes: Int = 0\r\n seconds: Int = 0\r\n milliseconds: Int = 0\r\n microseconds: Int = 0\r\n nanoseconds: Int = 0\r\n)\r\n\r\nnew(\r\n timeZoneId: String\r\n year: Int\r\n month: Int\r\n day: Int\r\n hour: Int = 0\r\n minute: Int = 0\r\n second: Int = 0\r\n millisecond: Int = 0\r\n microsecond: Int = 0\r\n nanosecond: Int = 0\r\n calendarId: String = \"iso8601\"\r\n offset: Option[String] = None\r\n earlier: Bool = True\r\n later: Bool = True\r\n): Date {\r\n Date(Js->Temporal->ZonedDateTime->from(Js->(\r\n timeZone = timeZoneId\r\n year = year\r\n month = month\r\n day = day\r\n hour = hour\r\n minute = minute\r\n second = second\r\n millisecond = millisecond\r\n microsecond = microsecond\r\n nanosecond = nanosecond\r\n calendar = calendarId\r\n offset = offset.map {_!}.else {Js.undefined()}\r\n ), internalDisambiguation(earlier, later)))\r\n}\r\n\r\nnewEra(\r\n calendarId: String\r\n timeZoneId: String\r\n era: String\r\n eraYear: Int\r\n month: Int\r\n day: Int\r\n hour: Int = 0\r\n minute: Int = 0\r\n second: Int = 0\r\n millisecond: Int = 0\r\n microsecond: Int = 0\r\n nanosecond: Int = 0\r\n offset: Option[String] = None\r\n earlier: Bool = True\r\n later: Bool = True\r\n): Date {\r\n Date(Js->Temporal->ZonedDateTime->from(Js->(\r\n timeZone = timeZoneId\r\n era = era\r\n eraYear = eraYear\r\n month = month\r\n day = day\r\n hour = hour\r\n minute = minute\r\n second = second\r\n millisecond = millisecond\r\n microsecond = microsecond\r\n nanosecond = nanosecond\r\n calendar = calendarId\r\n offset = offset.map {_!}.else {Js.undefined()}\r\n ), internalDisambiguation(earlier, later)))\r\n}\r\n\r\nnewEpochMilliseconds(timeZoneId: String, epochMilliseconds: Int, calendarId: String = \"iso8601\"): Date {\r\n let zoned = Js->Temporal->Instant->fromEpochMilliseconds(epochMilliseconds)->toZonedDateTimeISO(timeZoneId)\r\n if(calendarId != \"iso8601\") {Date(zoned->withCalendar(calendarId))} else {Date(zoned)}\r\n}\r\n\r\nnewRfc9557(rfc9557: String): Date {\r\n Date(Js->Temporal->ZonedDateTime->from(rfc9557))\r\n}\r\n\r\ngap(iso8601: String): DateGap {\r\n let duration = Js->Temporal->Duration->from(iso8601)\r\n DateGap(\r\n years = duration->years?\r\n months = duration->months?\r\n weeks = duration->weeks?\r\n days = duration->days?\r\n hours = duration->hours?\r\n minutes = duration->minutes?\r\n seconds = duration->seconds?\r\n milliseconds = duration->milliseconds?\r\n microseconds = duration->microseconds?\r\n nanoseconds = duration->nanoseconds?\r\n )\r\n}\r\n\r\ninstance Date: Equal {\r\n equals(x: Date, y: Date): Bool {\r\n x.jsValue->equals(y.jsValue)?\r\n } \r\n}\r\n\r\ninstance Date: Order {\r\n compare(x: Date, y: Date): Ordering {\r\n let instant: Int = Js->Temporal->ZonedDateTime->compare(x.jsValue, y.jsValue)?\r\n if(instant != 0) {Ordering.fromInt(instant)} else:\r\n let timeZone = Ordering.compare(x.timeZoneId(), y.timeZoneId())\r\n if(timeZone != OrderingSame) {timeZone} else:\r\n Ordering.compare(x.calendarId(), y.calendarId())\r\n }\r\n}\r\n\r\ninstance Date: HasAnyTag {\r\n anyTag(): AnyTag[Date] {\r\n Any.internalAnyTag(\"ff:core/Date.Date[]\")\r\n }\r\n}\r\n\r\ninstance Date: Show {\r\n show(value: Date): String {\r\n value.toRfc9557()\r\n }\r\n}\r\n\r\ninstance Date: Serializable {\r\n \r\n serializeUsing(serialization: Serialization, value: Date): Unit {\r\n Serializable.serializeUsing(serialization, value.toRfc9557())\r\n }\r\n \r\n deserializeUsing(serialization: Serialization): Date {\r\n newRfc9557(Serializable.deserializeUsing(serialization))\r\n }\r\n \r\n}\r\n\r\nextend self: Date {\r\n \r\n timeZoneId(): String {\r\n self.jsValue->timeZoneId?\r\n }\r\n \r\n calendarId(): String {\r\n self.jsValue->calendarId?\r\n }\r\n \r\n day(): Int {\r\n self.jsValue->day?\r\n }\r\n \r\n dayOfWeek(): Int {\r\n self.jsValue->dayOfWeek?\r\n }\r\n \r\n dayOfYear(): Int {\r\n self.jsValue->dayOfYear?\r\n }\r\n \r\n daysInWeek(): Int {\r\n self.jsValue->daysInWeek?\r\n }\r\n \r\n daysInMonth(): Int {\r\n self.jsValue->daysInMonth?\r\n }\r\n \r\n daysInYear(): Int {\r\n self.jsValue->daysInYear?\r\n }\r\n \r\n epochMilliseconds(): Int {\r\n self.jsValue->epochMilliseconds?\r\n }\r\n \r\n era(): Option[String] {\r\n let era = self.jsValue->era\r\n if(!era.isNullOrUndefined()) {era?}\r\n }\r\n \r\n eraYear(): Option[Int] {\r\n let eraYear = self.jsValue->eraYear\r\n if(!eraYear.isNullOrUndefined()) {eraYear?}\r\n }\r\n \r\n hour(): Int {\r\n self.jsValue->hour?\r\n }\r\n \r\n hoursInDay(): Int {\r\n self.jsValue->hoursInDay?\r\n }\r\n\r\n inLeapYear(): Bool {\r\n self.jsValue->inLeapYear?\r\n }\r\n\r\n microsecond(): Int {\r\n self.jsValue->microsecond?\r\n }\r\n\r\n millisecond(): Int {\r\n self.jsValue->millisecond?\r\n }\r\n\r\n minute(): Int {\r\n self.jsValue->minute?\r\n }\r\n\r\n month(): Int {\r\n self.jsValue->month?\r\n }\r\n\r\n monthCode(): String {\r\n self.jsValue->monthCode?\r\n }\r\n\r\n monthsInYear(): Int {\r\n self.jsValue->monthsInYear?\r\n }\r\n\r\n nanosecond(): Int {\r\n self.jsValue->nanosecond?\r\n }\r\n\r\n offset(): String {\r\n self.jsValue->offset?\r\n }\r\n\r\n offsetNanoseconds(): Int {\r\n self.jsValue->offsetNanoseconds?\r\n }\r\n\r\n second(): Int {\r\n self.jsValue->second?\r\n }\r\n\r\n weekOfYear(): Int {\r\n self.jsValue->weekOfYear?\r\n }\r\n\r\n year(): Int {\r\n self.jsValue->year?\r\n }\r\n\r\n yearOfWeek(): Int {\r\n self.jsValue->yearOfWeek?\r\n }\r\n \r\n nextTimeZoneTransition(): Date {\r\n Date(self.jsValue->getTimeZoneTransition(\"next\"))\r\n }\r\n \r\n previousTimeZoneTransition(): Date {\r\n Date(self.jsValue->getTimeZoneTransition(\"previous\"))\r\n }\r\n \r\n startOfYear(): Date {\r\n Date(self.jsValue->with(Js->(year = self.year(), month = 1, day = 1))->startOfDay())\r\n }\r\n\r\n startOfMonth(): Date {\r\n Date(self.jsValue->with(Js->(year = self.year(), month = self.month(), day = 1))->startOfDay())\r\n }\r\n \r\n startOfWeek(firstDayOfWeek: Int = 1): Date {\r\n let offset = ((self.dayOfWeek() - firstDayOfWeek) + self.daysInWeek()) % self.daysInWeek()\r\n Date(self.jsValue->subtract(Js->(day = offset))->startOfDay())\r\n }\r\n \r\n startOfDay(): Date {\r\n Date(self.jsValue->startOfDay())\r\n }\r\n\r\n startOfHour(): Date {\r\n Date(self.jsValue->round(Js->(smallestUnit = \"hour\", roundingMode = \"floor\")))\r\n }\r\n \r\n startOfMinute(): Date {\r\n Date(self.jsValue->round(Js->(smallestUnit = \"minute\", roundingMode = \"floor\")))\r\n }\r\n \r\n startOfSecond(): Date {\r\n Date(self.jsValue->round(Js->(smallestUnit = \"second\", roundingMode = \"floor\")))\r\n }\r\n \r\n startOfMillisecond(): Date {\r\n Date(self.jsValue->round(Js->(smallestUnit = \"millisecond\", roundingMode = \"floor\")))\r\n }\r\n \r\n startOfMicrosecond(): Date {\r\n Date(self.jsValue->round(Js->(smallestUnit = \"microsecond\", roundingMode = \"floor\")))\r\n }\r\n \r\n toRfc9557(\r\n smallestUnit: Option[String] = None\r\n fractionalSecondDigits: Option[Int] = None\r\n timeZone: Bool = True\r\n offset: Bool = True\r\n calendar: Bool = True\r\n ): String {\r\n self.jsValue->toString(Js->(\r\n calendarName = if(calendar) {\"auto\"} else {\"never\"}\r\n fractionalSecondDigits = fractionalSecondDigits.map {_!}.else {\"auto\"!}\r\n smallestUnit = smallestUnit.map {_!}.else {Js.undefined()}\r\n timeZoneName = if(timeZone) {\"auto\"} else {\"never\"}\r\n offset = if(offset) {\"auto\"} else {\"never\"}\r\n ))?\r\n }\r\n \r\n withCalendar(calendarId: String): Date {\r\n Date(self.jsValue->withCalendar(calendarId))\r\n }\r\n \r\n withTimeZone(timeZoneId: String): Date {\r\n Date(self.jsValue->withTimeZone(timeZoneId))\r\n }\r\n \r\n withEra(\r\n era: String\r\n eraYear: Int\r\n monthCode: Option[String] = None\r\n day: Option[Int] = None\r\n earlier: Bool = True\r\n later: Bool = True\r\n ): Date {\r\n Date(self.jsValue->with(Js->(\r\n era = era\r\n eraYear = eraYear\r\n monthCode = monthCode.map {_!}.else {Js.undefined()} \r\n day = day.map {_!}.else {Js.undefined()} \r\n ), internalDisambiguation(earlier, later)))\r\n }\r\n \r\n withMonthCode(\r\n monthCode: String\r\n day: Option[Int] = None\r\n earlier: Bool = True\r\n later: Bool = True\r\n ): Date {\r\n Date(self.jsValue->with(Js->(\r\n monthCode = monthCode\r\n day = day.map {_!}.else {Js.undefined()} \r\n ), internalDisambiguation(earlier, later)))\r\n }\r\n \r\n with(\r\n year: Option[Int] = None\r\n month: Option[Int] = None\r\n week: Option[Int] = None\r\n day: Option[Int] = None\r\n hour: Option[Int] = None\r\n minute: Option[Int] = None\r\n second: Option[Int] = None\r\n millisecond: Option[Int] = None\r\n microsecond: Option[Int] = None\r\n nanosecond: Option[Int] = None\r\n offset: Option[String] = None\r\n earlier: Bool = True\r\n later: Bool = True\r\n ): Date {\r\n Date(self.jsValue->with(Js->(\r\n year = year.map {_!}.else {Js.undefined()} \r\n month = month.map {_!}.else {Js.undefined()} \r\n week = week.map {_!}.else {Js.undefined()} \r\n day = day.map {_!}.else {Js.undefined()} \r\n hour = hour.map {_!}.else {Js.undefined()} \r\n minute = minute.map {_!}.else {Js.undefined()} \r\n second = second.map {_!}.else {Js.undefined()} \r\n millisecond = millisecond.map {_!}.else {Js.undefined()} \r\n microsecond = microsecond.map {_!}.else {Js.undefined()} \r\n nanosecond = nanosecond.map {_!}.else {Js.undefined()}\r\n offset = offset.map {_!}.else {Js.undefined()}\r\n ), internalDisambiguation(earlier, later)))\r\n }\r\n \r\n add(\r\n years: Int = 0\r\n months: Int = 0\r\n weeks: Int = 0\r\n days: Int = 0\r\n hours: Int = 0\r\n minutes: Int = 0\r\n seconds: Int = 0\r\n milliseconds: Int = 0\r\n microseconds: Int = 0\r\n nanoseconds: Int = 0\r\n ): Date {\r\n Date(self.jsValue->add(Js->(\r\n years = years\r\n months = months\r\n weeks = weeks\r\n days = days\r\n hours = hours\r\n minutes = minutes\r\n seconds = seconds\r\n milliseconds = milliseconds\r\n microseconds = microseconds\r\n nanoseconds = nanoseconds\r\n )))\r\n }\r\n \r\n subtract(\r\n years: Int = 0\r\n months: Int = 0\r\n weeks: Int = 0\r\n days: Int = 0\r\n hours: Int = 0\r\n minutes: Int = 0\r\n seconds: Int = 0\r\n milliseconds: Int = 0\r\n microseconds: Int = 0\r\n nanoseconds: Int = 0\r\n ): Date {\r\n Date(self.jsValue->subtract(Js->(\r\n years = years\r\n months = months\r\n weeks = weeks\r\n days = days\r\n hours = hours\r\n minutes = minutes\r\n seconds = seconds\r\n milliseconds = milliseconds\r\n microseconds = microseconds\r\n nanoseconds = nanoseconds\r\n )))\r\n }\r\n \r\n addGap(gap: DateGap): Date {\r\n Date(self.jsValue->add(Js->(\r\n years = gap.years\r\n months = gap.months\r\n weeks = gap.weeks\r\n days = gap.days\r\n hours = gap.hours\r\n minutes = gap.minutes\r\n seconds = gap.seconds\r\n milliseconds = gap.milliseconds\r\n microseconds = gap.microseconds\r\n nanoseconds = gap.nanoseconds\r\n )))\r\n }\r\n \r\n subtractGap(gap: DateGap): Date {\r\n Date(self.jsValue->add(Js->(\r\n years = gap.years\r\n months = gap.months\r\n weeks = gap.weeks\r\n days = gap.days\r\n hours = gap.hours\r\n minutes = gap.minutes\r\n seconds = gap.seconds\r\n milliseconds = gap.milliseconds\r\n microseconds = gap.microseconds\r\n nanoseconds = gap.nanoseconds\r\n )))\r\n }\r\n \r\n since(that: Date): DateGap {\r\n let duration = self.jsValue->since(that.jsValue)\r\n DateGap(\r\n years = duration->years?\r\n months = duration->months?\r\n weeks = duration->weeks?\r\n days = duration->days?\r\n hours = duration->hours?\r\n minutes = duration->minutes?\r\n seconds = duration->seconds?\r\n milliseconds = duration->milliseconds?\r\n microseconds = duration->microseconds?\r\n nanoseconds = duration->nanoseconds?\r\n )\r\n }\r\n \r\n until(that: Date): DateGap {\r\n let duration = self.jsValue->until(that.jsValue)\r\n DateGap(\r\n years = duration->years?\r\n months = duration->months?\r\n weeks = duration->weeks?\r\n days = duration->days?\r\n hours = duration->hours?\r\n minutes = duration->minutes?\r\n seconds = duration->seconds?\r\n milliseconds = duration->milliseconds?\r\n microseconds = duration->microseconds?\r\n nanoseconds = duration->nanoseconds?\r\n )\r\n }\r\n \r\n yearsSince(that: Date): Float {\r\n let duration = self.jsValue->since(that.jsValue)\r\n duration->total(Js->(unit = \"years\", relativeTo = that.jsValue))?\r\n }\r\n \r\n monthsSince(that: Date): Float {\r\n let duration = self.jsValue->since(that.jsValue)\r\n duration->total(Js->(unit = \"months\", relativeTo = that.jsValue))?\r\n }\r\n \r\n weeksSince(that: Date): Float {\r\n let duration = self.jsValue->since(that.jsValue)\r\n duration->total(Js->(unit = \"weeks\", relativeTo = that.jsValue))?\r\n }\r\n \r\n daysSince(that: Date): Float {\r\n let duration = self.jsValue->since(that.jsValue)\r\n duration->total(Js->(unit = \"days\", relativeTo = that.jsValue))?\r\n }\r\n \r\n hoursSince(that: Date): Float {\r\n let duration = self.jsValue->since(that.jsValue)\r\n duration->total(Js->(unit = \"hours\", relativeTo = that.jsValue))?\r\n }\r\n \r\n minutesSince(that: Date): Float {\r\n let duration = self.jsValue->since(that.jsValue)\r\n duration->total(Js->(unit = \"minutes\", relativeTo = that.jsValue))?\r\n }\r\n \r\n secondsSince(that: Date): Float {\r\n let duration = self.jsValue->since(that.jsValue)\r\n duration->total(Js->(unit = \"seconds\", relativeTo = that.jsValue))?\r\n }\r\n \r\n millisecondsSince(that: Date): Float {\r\n let duration = self.jsValue->since(that.jsValue)\r\n duration->total(Js->(unit = \"milliseconds\", relativeTo = that.jsValue))?\r\n }\r\n \r\n microsecondsSince(that: Date): Float {\r\n let duration = self.jsValue->since(that.jsValue)\r\n duration->total(Js->(unit = \"microseconds\", relativeTo = that.jsValue))?\r\n }\r\n \r\n nanosecondsSince(that: Date): Float {\r\n let duration = self.jsValue->since(that.jsValue)\r\n duration->total(Js->(unit = \"nanoseconds\", relativeTo = that.jsValue))?\r\n }\r\n \r\n schedule(nextDate: Date => Date): Stream[Date] {\r\n mutable current = self\r\n [self].toStream().addAll(Stream.new {\r\n current = nextDate(current)\r\n Some(current)\r\n })\r\n }\r\n \r\n}\r\n\r\nextend self: DateGap {\r\n\r\n toIso8601(\r\n smallestUnit: Option[String] = None\r\n fractionalSecondDigits: Option[Int] = None\r\n ): String {\r\n let duration = Js->Temporal->Duration->from(Js->(\r\n years = self.years\r\n months = self.months\r\n weeks = self.weeks\r\n days = self.days\r\n hours = self.hours\r\n minutes = self.minutes\r\n seconds = self.seconds\r\n milliseconds = self.milliseconds\r\n microseconds = self.microseconds\r\n nanoseconds = self.nanoseconds\r\n ))\r\n duration->toString(Js->(\r\n smallestUnit = smallestUnit.map {_!}.else {Js.undefined()}\r\n fractionalSecondDigits = fractionalSecondDigits.map {_!}.else {\"auto\"!}\r\n ))?\r\n }\r\n \r\n}\r\n\r\nutcTimeZoneId: String = \"UTC\"\r\nisoCalendarId: String = \"iso8601\"\r\n\r\nmonday: Int = 1\r\ntuesday: Int = 2\r\nwednesday: Int = 3\r\nthursday: Int = 4\r\nfriday: Int = 5\r\nsaturday: Int = 6\r\nsunday: Int = 7\r\n\r\njanuary: Int = 1\r\nfebruary: Int = 2\r\nmarch: Int = 3\r\napril: Int = 4\r\nmay: Int = 5\r\njune: Int = 6\r\njuly: Int = 7\r\naugust: Int = 8\r\nseptember: Int = 9\r\noctober: Int = 10\r\nnovember: Int = 11\r\ndecember: Int = 12\r\n\r\ninternalDisambiguation(earlier: Bool, later: Bool): JsValue {\r\n Js->(\r\n disambiguation = if(earlier && later) {\r\n \"compatible\"\r\n } elseIf {earlier} {\r\n \"earlier\"\r\n } elseIf {later} {\r\n \"later\"\r\n } else {\r\n \"reject\"\r\n }\r\n ) \r\n}\r\n"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": [
|
|
4
|
-
"
|
|
4
|
+
"../../../../core/Duration.ff"
|
|
5
5
|
],
|
|
6
6
|
"sourcesContent": [
|
|
7
7
|
"newtype Duration(seconds: Float)\r\n\r\nextend self: Duration {\r\n\r\n show(digits: Int = 3): String {\r\n self.seconds.toFixed(digits) + \" s\"\r\n }\r\n\r\n}\r\n\r\ninstance Duration: Show {\r\n show(value: Duration): String {\r\n value.show()\r\n }\r\n}\r\n"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": [
|
|
4
|
-
"
|
|
4
|
+
"../../../../core/Equal.ff"
|
|
5
5
|
],
|
|
6
6
|
"sourcesContent": [
|
|
7
7
|
"trait T: Equal {\r\n equals(x: T, y: T): Bool\r\n}\r\n\r\nnotEquals[T: Equal](x: T, y: T): Bool {\r\n !equals(x, y)\r\n}\r\n\r\ninstance Nothing: Equal {\r\n equals(x: Nothing, y: Nothing): Bool {True}\r\n}\r\n\r\ninstance Bool: Equal {\r\n equals(x: Bool, y: Bool): Bool {\r\n x!.equals(y)\r\n }\r\n}\r\n\r\ninstance Char: Equal {\r\n equals(x: Char, y: Char): Bool {\r\n x!.equals(y)\r\n }\r\n}\r\n\r\ninstance Int: Equal {\r\n equals(x: Int, y: Int): Bool {\r\n x!.equals(y)\r\n }\r\n}\r\n\r\ninstance Float: Equal {\r\n equals(x: Float, y: Float): Bool {\r\n x!.equals(y)\r\n }\r\n}\r\n\r\ninstance String: Equal {\r\n equals(x: String, y: String): Bool {\r\n x!.equals(y)\r\n }\r\n}\r\n"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": [
|
|
4
|
-
"
|
|
4
|
+
"../../../../core/Error.ff"
|
|
5
5
|
],
|
|
6
6
|
"sourcesContent": [
|
|
7
7
|
"data Error {}\r\n\r\nextend self: Error {\r\n\r\n rethrow[T](): T {\r\n Js.throw(self!)\r\n }\r\n\r\n name(): String {\r\n self!->name.coalesce(\"\")?\r\n }\r\n\r\n message(): String {\r\n self!->message.coalesce(\"\")?\r\n }\r\n\r\n stack(): String {\r\n let stacktrace = self!->stack.coalesce(\"\")?\r\n if(!Js.inNode()) {stacktrace} else:\r\n stacktrace.lines().takeWhile {!_.contains(\"$run$\")}.map {line =>\r\n line.removeFirst(\" at \").map {line =>\r\n \" at \" + line.dropWhile {_ != '('}.dropFirst().dropLast()\r\n }.else {line}\r\n }.join(\"\\n\")\r\n }\r\n\r\n exception(): Option[Any] {\r\n if(!self!->ffException.isNullOrUndefined()) {self!->ffException?}\r\n }\r\n \r\n}\r\n"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": [
|
|
4
|
-
"
|
|
4
|
+
"../../../../core/FileHandle.ff"
|
|
5
5
|
],
|
|
6
6
|
"sourcesContent": [
|
|
7
7
|
"capability FileHandle {}\r\n\r\nextend self: FileHandle {\r\n\r\n close(): Unit {\r\n Js.await(self!->close())\r\n }\r\n\r\n read(buffer: Buffer, offset: Int = 0, length: Option[Int] = None, position: Option[Int] = None): Unit {\r\n Js.throwIfCancelled()\r\n Js.await(self!->read(buffer, Js->(\r\n offset = offset\r\n length = length.map {_!}.else {Js.undefined()}\r\n position = position.map {_!}.else {Js.undefined()}\r\n )))\r\n }\r\n\r\n write(buffer: Buffer, offset: Int = 0, length: Option[Int] = None, position: Option[Int] = None): Unit {\r\n Js.throwIfCancelled()\r\n Js.await(self!->write(\r\n buffer\r\n offset\r\n length.map {_!}.else {Js.undefined()}\r\n position.map {_!}.else {Js.undefined()}\r\n ))\r\n }\r\n \r\n writeText(text: String, position: Option[Int] = None, encoding: String = \"utf8\"): Unit {\r\n Js.throwIfCancelled()\r\n Js.await(self!->write(\r\n text\r\n position.map {_!}.else {Js.undefined()}\r\n encoding\r\n ))\r\n }\r\n \r\n writeLine(text: String, position: Option[Int] = None, encoding: String = \"utf8\"): Unit {\r\n self.writeText(text + \"\\n\", position, encoding)\r\n }\r\n \r\n truncate(length: Int = 0): Unit {\r\n Js.throwIfCancelled()\r\n Js.await(self!->truncate(length))\r\n }\r\n \r\n sync(dataOnly: Bool = False): Unit {\r\n Js.throwIfCancelled()\r\n if(dataOnly) {\r\n Js.await(self!->datasync())\r\n } else {\r\n Js.await(self!->sync())\r\n }\r\n }\r\n\r\n}\r\n"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": [
|
|
4
|
-
"
|
|
4
|
+
"../../../../core/Float.ff"
|
|
5
5
|
],
|
|
6
6
|
"sourcesContent": [
|
|
7
7
|
"data Float {}\r\n\r\nextend self: Float {\r\n\r\n toInt(): Int {\r\n Js->Math->trunc(self).coalesce(0)?\r\n }\r\n\r\n round(): Float {\r\n Js->Math->round(self)?\r\n }\r\n\r\n floor(): Float {\r\n Js->Math->floor(self)?\r\n }\r\n\r\n ceil(): Float {\r\n Js->Math->ceil(self)?\r\n }\r\n\r\n truncate(): Float {\r\n Js->Math->trunc(self)?\r\n }\r\n\r\n sign(): Float {\r\n Js->Math->sign(self)?\r\n }\r\n\r\n abs(): Float {\r\n Js->Math->abs(self)?\r\n }\r\n\r\n toFixed(digits: Int): String {\r\n self!->toFixed(digits)?\r\n }\r\n\r\n min(that: Float): Float {\r\n Js->Math->min(self, that)?\r\n }\r\n\r\n max(that: Float): Float {\r\n Js->Math->max(self, that)?\r\n }\r\n\r\n clamp(from: Float, to: Float): Float {\r\n Js->Math->min(Js->Math->max(self, from), to)?\r\n }\r\n \r\n lerp(that: Float, factor: Float): Float {\r\n self + factor * (that - self)\r\n }\r\n \r\n smoothstep(that: Float, factor: Float): Float {\r\n let t = ((factor - self) / (that - self)).clamp(0.0, 1.0)\r\n t * t * (3.0 - 2.0 * t)\r\n }\r\n \r\n expDecay(that: Float, decay: Float, factor: Float): Float {\r\n that + (self - that) * (-decay * factor).exp()\r\n }\r\n \r\n acos(): Float {\r\n Js->Math->acos(self)?\r\n }\r\n \r\n acosh(): Float {\r\n Js->Math->acosh(self)?\r\n }\r\n \r\n asin(): Float {\r\n Js->Math->asin(self)?\r\n }\r\n \r\n asinh(): Float {\r\n Js->Math->asinh(self)?\r\n }\r\n \r\n atan(): Float {\r\n Js->Math->atan(self)?\r\n }\r\n \r\n atan2(that: Float): Float {\r\n Js->Math->atan2(self, that)?\r\n }\r\n \r\n atanh(): Float {\r\n Js->Math->atanh(self)?\r\n }\r\n \r\n cbrt(): Float {\r\n Js->Math->cbrt(self)?\r\n }\r\n \r\n cos(): Float {\r\n Js->Math->cos(self)?\r\n }\r\n \r\n cosh(): Float {\r\n Js->Math->cosh(self)?\r\n }\r\n \r\n exp(): Float {\r\n Js->Math->exp(self)?\r\n }\r\n \r\n expm1(): Float {\r\n Js->Math->expm1(self)?\r\n }\r\n \r\n log(that: Float): Float {\r\n let l: Float = Js->Math->log2(self)?\r\n l / Js->Math->log2(that)?\r\n }\r\n \r\n log10(): Float {\r\n Js->Math->log10(self)?\r\n }\r\n \r\n log2(): Float {\r\n Js->Math->log2(self)?\r\n }\r\n \r\n ln(): Float {\r\n Js->Math->log(self)?\r\n }\r\n \r\n ln1p(): Float {\r\n Js->Math->log1p(self)?\r\n }\r\n\r\n sin(): Float {\r\n Js->Math->sin(self)?\r\n }\r\n \r\n sinh(): Float {\r\n Js->Math->sinh(self)?\r\n }\r\n \r\n sqrt(): Float {\r\n Js->Math->sqrt(self)?\r\n }\r\n \r\n tan(): Float {\r\n Js->Math->tan(self)?\r\n }\r\n \r\n tanh(): Float {\r\n Js->Math->tanh(self)?\r\n }\r\n \r\n isFinite(): Bool {\r\n Js->Number->isFinite(self)?\r\n }\r\n \r\n isNan(): Bool {\r\n Js->Number->isNaN(self)?\r\n }\r\n\r\n isSafeInteger(): Bool {\r\n Js->Number->isSafeInteger(self)?\r\n }\r\n\r\n}\r\n\r\nhypot(a: Float, b: Float, c: Float = 0.0, d: Float = 0.0) {\r\n Js->Math->hypot(a, b, c, d)?\r\n}\r\n\r\ne(): Float {\r\n Js->Math->E?\r\n}\r\n\r\nln10(): Float {\r\n Js->Math->LN10?\r\n}\r\n\r\nln2(): Float {\r\n Js->Math->LN2?\r\n}\r\n\r\nlog10e(): Float {\r\n Js->Math->LOG10E?\r\n}\r\n\r\nlog2e(): Float {\r\n Js->Math->LOG2E?\r\n}\r\n\r\npi(): Float {\r\n Js->Math->PI?\r\n}\r\n\r\nsqrtHalf(): Float {\r\n Js->Math->\"SQRT1_2\"?\r\n}\r\n\r\nsqrt2(): Float {\r\n Js->Math->SQRT2?\r\n}\r\n\r\nnan(): Float {\r\n Js->NaN?\r\n}\r\n\r\ninfinity(): Float {\r\n Js->Infinity?\r\n}\r\n"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": [
|
|
4
|
-
"
|
|
4
|
+
"../../../../core/HttpClient.ff"
|
|
5
5
|
],
|
|
6
6
|
"sourcesContent": [
|
|
7
7
|
"capability HttpClient {}\r\ncapability FetchBody {}\r\ncapability FetchResponse {}\r\ndata FetchRedirect {\r\n RedirectFollow\r\n RedirectError\r\n RedirectManual\r\n}\r\ndata FetchOptions(\r\n redirect: FetchRedirect = RedirectFollow\r\n referrer: Option[String] = None\r\n integrity: Option[String] = None\r\n mode: Option[String] = None\r\n credentials: Option[String] = None\r\n cache: Option[String] = None\r\n)\r\n\r\nextend self: HttpClient {\r\n \r\n get[T](\r\n url: String\r\n headers: List[Pair[String, String]]\r\n body: FetchResponse => T\r\n ): T {\r\n self.fetch(\"GET\", url, headers, None, FetchOptions(), body)\r\n }\r\n \r\n post[T](\r\n url: String\r\n headers: List[Pair[String, String]]\r\n payload: Buffer\r\n body: FetchResponse => T\r\n ): T {\r\n self.fetch(\"POST\", url, headers, Some(payload), FetchOptions(), body)\r\n }\r\n \r\n put[T](\r\n url: String\r\n headers: List[Pair[String, String]]\r\n payload: Buffer\r\n body: FetchResponse => T\r\n ): T {\r\n self.fetch(\"PUT\", url, headers, Some(payload), FetchOptions(), body)\r\n }\r\n \r\n delete[T](\r\n url: String\r\n headers: List[Pair[String, String]]\r\n body: FetchResponse => T\r\n ): T {\r\n self.fetch(\"DELETE\", url, headers, None, FetchOptions(), body)\r\n }\r\n\r\n fetch[T](\r\n method: String\r\n url: String\r\n headers: List[Pair[String, String]] = []\r\n payload: Option[Buffer] = None\r\n options: FetchOptions = FetchOptions()\r\n body: FetchResponse => T\r\n ): T {\r\n let fetchResponse = Js->(response = Js.null(), statusChecked = False)\r\n Js.withSignal {signal =>\r\n try {\r\n let fetchOptions = Js->(headers = Js->(), signal = signal, method = method)\r\n headers.each {| Pair(k, v) =>\r\n fetchOptions->headers.set(k, v)\r\n }\r\n payload.each {v => fetchOptions->body = v}\r\n options.redirect.{\r\n | RedirectError => fetchOptions->redirect = \"error\"\r\n | RedirectFollow => \r\n | RedirectManual => fetchOptions->redirect = \"manual\"\r\n }\r\n options.referrer.each {v => fetchOptions->referrer = v}\r\n options.integrity.each {v => fetchOptions->integrity = v}\r\n options.mode.each {v => fetchOptions->mode = v}\r\n options.credentials.each {v => fetchOptions->credentials = v}\r\n options.cache.each {v => fetchOptions->cache = v}\r\n fetchResponse->response = Js.await(self!->fetch(url, fetchOptions))\r\n let result = Js.await(body(fetchResponse?)!)\r\n internalCheck(fetchResponse?)\r\n result?\r\n } finally {\r\n fetchResponse->response = Js.null()\r\n }\r\n }\r\n }\r\n\r\n}\r\n\r\nextend self: FetchResponse {\r\n\r\n ok(): Bool {\r\n self!->statusChecked = True\r\n internalCheck(self)\r\n self!->response->ok?\r\n }\r\n\r\n status(): Int {\r\n self!->statusChecked = True\r\n internalCheck(self)\r\n self!->response->status?\r\n }\r\n\r\n statusText(): String {\r\n self!->statusChecked = True\r\n internalCheck(self)\r\n self!->response->statusText?\r\n }\r\n\r\n header(name: String): Option[String] {\r\n internalCheck(self)\r\n let header = self!->response->headers->get(name)\r\n if(!header.isNullOrUndefined()) {header?}\r\n }\r\n\r\n readText(): String {\r\n internalCheck(self)\r\n Js.await(self!->response->text())?\r\n }\r\n\r\n readJson(): Json {\r\n internalCheck(self)\r\n Js.await(self!->response->json())?\r\n }\r\n\r\n readBuffer(): Buffer {\r\n internalCheck(self)\r\n Js->DataView->(Js.await(self!->response->arrayBuffer()))?\r\n }\r\n\r\n}\r\n\r\ninternalCheck(fetchResponse: FetchResponse) {\r\n if(fetchResponse!->response.isNull()) {\r\n Js.throw(Js->Error->(\"Response closed\"))\r\n }\r\n if(!fetchResponse!->statusChecked? && !fetchResponse!->response->ok?) {\r\n Js.throw(Js->Error->(\"Unchecked HTTP status code: \" + fetchResponse!->response->status?))\r\n }\r\n}\r\n"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": [
|
|
4
|
-
"
|
|
4
|
+
"../../../../core/Int.ff"
|
|
5
5
|
],
|
|
6
6
|
"sourcesContent": [
|
|
7
7
|
"data Int {}\r\n\r\nextend self: Int {\r\n\r\n abs(): Int {\r\n Js->Math->abs(self)?\r\n }\r\n\r\n toFloat(): Float {\r\n self!?\r\n }\r\n\r\n bitNot(): Int {\r\n Js.unaryOperator(\"~\", self)?\r\n }\r\n\r\n bitOr(that: Int): Int {\r\n Js.binaryOperator(\"|\", self, that)?\r\n }\r\n\r\n bitAnd(that: Int): Int {\r\n Js.binaryOperator(\"&\", self, that)?\r\n }\r\n\r\n bitXor(that: Int): Int {\r\n Js.binaryOperator(\"^\", self, that)?\r\n }\r\n\r\n bitLeft(bits: Int): Int {\r\n Js.binaryOperator(\"<<\", self, bits)?\r\n }\r\n\r\n bitRight(bits: Int): Int {\r\n Js.binaryOperator(\">>\", self, bits)?\r\n }\r\n\r\n bitRightUnsigned(bits: Int): Int {\r\n Js.binaryOperator(\">>>\", self, bits)?\r\n }\r\n \r\n bitLeadingZeros(): Int {\r\n Js->Math->clz32(self)?\r\n }\r\n\r\n to(inclusiveEnd: Int): List[Int] {\r\n let result = Array.new()\r\n mutable n = self\r\n while {n <= inclusiveEnd} {\r\n result.push(n)\r\n n += 1\r\n }\r\n result.drain()\r\n }\r\n\r\n until(exclusiveEnd: Int): List[Int] {\r\n let result = Array.new()\r\n mutable n = self\r\n while {n < exclusiveEnd} {\r\n result.push(n)\r\n n += 1\r\n }\r\n result.drain()\r\n }\r\n\r\n min(that: Int): Int {\r\n Js->Math->min(self, that)?\r\n }\r\n\r\n max(that: Int): Int {\r\n Js->Math->max(self, that)?\r\n }\r\n\r\n clamp(from: Int, to: Int): Int {\r\n self.max(from).min(to)\r\n }\r\n \r\n pad(padding: String): String {\r\n (\"\" + self).padStart(padding.size(), padding)\r\n }\r\n \r\n div(divisor: Int): Int {\r\n (self / divisor).toInt()\r\n }\r\n\r\n rem(divisor: Int): Int {\r\n (self % divisor).toInt()\r\n }\r\n\r\n}\r\n"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": [
|
|
4
|
-
"
|
|
4
|
+
"../../../../core/IntMap.ff"
|
|
5
5
|
],
|
|
6
6
|
"sourcesContent": [
|
|
7
7
|
"class IntMap[V] {}\r\n\r\nnew[V](): IntMap[V] {\r\n Js->Map->()?\r\n}\r\n \r\nextend self[V]: IntMap[V] {\r\n\r\n get(key: Int): Option[V] {\r\n let result = self!->get(key)\r\n if(!result.isUndefined() || self!->has(key)?) {result?}\r\n }\r\n\r\n grab(key: Int): V {\r\n let result = self!->get(key)\r\n if(result.isUndefined() && !self.has(key)) {throw(GrabException())}\r\n result?\r\n }\r\n \r\n set(key: Int, value: V): Unit {\r\n self!->set(key, value!)\r\n }\r\n\r\n has(key: Int): Bool {\r\n self!->has(key)?\r\n }\r\n\r\n remove(key: Int): Bool {\r\n self!->delete(key)?\r\n }\r\n\r\n clear(): Unit {\r\n self!->clear()\r\n }\r\n\r\n size(): Int {\r\n self!->size?\r\n }\r\n \r\n isEmpty(): Bool {\r\n self.size() == 0\r\n }\r\n\r\n each(body: (Int, V) => Unit): Unit {\r\n if(Js.inAsync()) {\r\n let iterator = self!->entries()\r\n mutable result = iterator->next()\r\n while {!result->done?} {\r\n let value = result->value\r\n body(value.get(0)?, value.get(1)?)\r\n result = iterator->next()\r\n }\r\n } else {\r\n self!->forEach(Js->{v, k => body(k?, v?)})\r\n }\r\n }\r\n \r\n eachWhile(body: (Int, V) => Bool): Unit {\r\n self!.eachWhile {value =>\r\n body(value.get(0)?, value.get(1)?)\r\n }\r\n }\r\n \r\n toArray(): Array[Pair[Int, V]] {\r\n let array = Array.new()\r\n self.each {k, v => array.push(Pair(k, v))}\r\n array\r\n }\r\n\r\n toList(): List[Pair[Int, V]] {\r\n self.toArray().drain()\r\n }\r\n\r\n toStream(): Stream[Pair[Int, V]] {\r\n self.toList().toStream()\r\n }\r\n\r\n toMap(): Map[Int, V] {\r\n self.toList().toMap()\r\n }\r\n\r\n keys(): List[Int] {\r\n let array = Array.new()\r\n self.each {k, v => array.push(k)}\r\n array.drain()\r\n }\r\n\r\n values(): List[V] {\r\n let array = Array.new()\r\n self.each {k, v => array.push(v)}\r\n array.drain()\r\n }\r\n\r\n copy(): IntMap[V] {\r\n Js->Map->(self!)?\r\n }\r\n\r\n getOrSet(key: Int, body: () => V): V {\r\n if(!self.has(key)) {self.set(key, body())}\r\n self.grab(key)\r\n }\r\n \r\n}\r\n\r\nextend self[V]: IntMap[Array[V]] {\r\n\r\n push(key: Int, value: V) {\r\n self.get(key).{\r\n | None => self.set(key, [value].toArray())\r\n | Some(array) => array.push(value)\r\n }\r\n }\r\n\r\n}\r\n"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": [
|
|
4
|
-
"
|
|
4
|
+
"../../../../core/Js.ff"
|
|
5
5
|
],
|
|
6
6
|
"sourcesContent": [
|
|
7
7
|
"// The compiler may decide to access symbols by name instead of going through globalThis\r\n\r\njsSystem(): JsSystem {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nimport(module: String): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nbrowserImport(module: String): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\ndynamicImport(module: String): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nawait(promise: JsValue): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nasync0[R](body: () => JsValue): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nasync1[R](body: (JsValue) => JsValue): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nasync2[R](body: (JsValue, JsValue) => JsValue): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nasync3[R](body: (JsValue, JsValue, JsValue) => JsValue): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nasync4[R](body: (JsValue, JsValue, JsValue, JsValue) => JsValue): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nasync5[R](body: (JsValue, JsValue, JsValue, JsValue, JsValue) => JsValue): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nasync6[R](body: (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) => JsValue): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nasync7[R](body: (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) => JsValue): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nasync8[R](body: (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) => JsValue): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nasync9[R](body: (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) => JsValue): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\ninAsync(): Bool {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n \r\ninBrowser(): Bool {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n \r\ninNode(): Bool {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n \r\ninBuild(): Bool {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\ncurrentTask(): Task {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nthrowIfCancelled(): Unit {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\ncancelled(): Bool {\r\n if(inAsync()) {\r\n currentTask().controller->signal->aborted?\r\n } else {\r\n False\r\n }\r\n}\r\n\r\ncontroller(): JsValue {\r\n currentTask().controller\r\n}\r\n\r\nsetController(controller: JsValue) {\r\n currentTask().controller = controller\r\n}\r\n \r\nwithSignal[T](body: JsValue => T): T {\r\n let controller = Js.controller()\r\n try {\r\n body(controller->signal)\r\n } finally {\r\n if(controller->signal->aborted?) {Js.setController(Js->AbortController->())}\r\n }\r\n}\r\n\r\nawaitCancellablePromise[T](body: (T => Unit, Error => Unit, (Bool => Unit) => Unit) => Unit): T {\r\n Js.throwIfCancelled()\r\n Js.await(Js->Promise->(Js->{resolve, reject =>\r\n mutable settled = False\r\n let cleanups = Array.new[Bool => Unit]()\r\n let doResolve: T => Unit = {v => \r\n if(!settled) {\r\n settled = True\r\n try {\r\n cleanups.each {c => c(True)}\r\n resolve.callValue1(v!)\r\n } catchAny {e =>\r\n reject.callValue1(e!)\r\n }\r\n }\r\n }\r\n let doReject: Error => Unit = {v => \r\n if(!settled) {\r\n settled = True\r\n try {\r\n cleanups.each {c => c(False)}\r\n reject.callValue1(v!)\r\n } catchAny {e =>\r\n reject.callValue1(e!)\r\n } \r\n }\r\n }\r\n let controller = Js.controller()\r\n let jsDoReject = Js->{_ => doReject(controller->signal->reason?)}\r\n controller->signal->addEventListener(\"abort\", jsDoReject)\r\n cleanups.push({_ => controller->signal->removeEventListener(\"abort\", jsDoReject)})\r\n body(doResolve, doReject, {cleanup => cleanups.push(cleanup)})\r\n }))?\r\n}\r\n\r\nvalue[T](value: T): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nfromValue[T](value: JsValue): T {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nthrow[T](value: JsValue): T {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\ninitializeError[E: HasAnyTag: Show, T](exception: E, error: JsValue): JsValue {\r\n error->message = Show.show(exception)!\r\n initializeErrorKeepMessage(exception, error)\r\n}\r\n\r\ninitializeErrorKeepMessage[E: HasAnyTag, T](exception: E, error: JsValue): JsValue {\r\n if(inNode()) {\r\n Js->Object->defineProperty(error, \"ffException\", Js->(\r\n value = Any.toAny(exception)!\r\n enumerable = False\r\n ))\r\n } else {\r\n error->ffException = Any.toAny(exception)!\r\n }\r\n error\r\n}\r\n\r\nunaryOperator[T1: IsJsValue](operator: String, a1: T1): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nbinaryOperator[T1: IsJsValue, T2: IsJsValue](operator: String, a1: T1, a2: T2): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nshortCircuitingOperator[T1: IsJsValue, T2: IsJsValue](operator: String, a1: T1, a2: () => T2): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nrawIdentifier(operator: String): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\n\r\nglobalThis(): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nget(key: String): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nset[V: IsJsValue](key: String, value: V): Unit {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nincrement[V: IsJsValue](key: String, value: V): Unit {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\ndecrement[V: IsJsValue](key: String, value: V): Unit {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\ncall0(name: String): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\ncall1[A1: IsJsValue](name: String, a1: A1): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\ncall2[A1: IsJsValue, A2: IsJsValue](name: String, a1: A1, a2: A2): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\ncall3[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue](name: String, a1: A1, a2: A2, a3: A3): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\ncall4[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue](name: String, a1: A1, a2: A2, a3: A3, a4: A4): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\ncall5[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue](name: String, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\ncall6[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue](name: String, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\ncall7[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue, A7: IsJsValue](name: String, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\ncall8[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue, A7: IsJsValue, A8: IsJsValue](name: String, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\ncall9[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue, A7: IsJsValue, A8: IsJsValue, A9: IsJsValue](name: String, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8, a9: A9): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nnull(): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nundefined(): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\norUndefined[T: IsJsValue](value: Option[T]): JsValue {\r\n value.{\r\n | None => Js.undefined()\r\n | Some(v) => v!\r\n }\r\n}\r\n\r\nobject(): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nnew0(): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\narray(values: List[JsValue]): JsValue {\r\n values!\r\n}\r\n\r\njson(value: Json): JsValue {\r\n value.jsValue\r\n}\r\n\r\nfunction0[R](body: () => R): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nfunction1[R](body: JsValue => R): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nfunction2[R](body: (JsValue, JsValue) => R): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nfunction3[R](body: (JsValue, JsValue, JsValue) => R): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nfunction4[R](body: (JsValue, JsValue, JsValue, JsValue) => R): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nfunction5[R](body: (JsValue, JsValue, JsValue, JsValue, JsValue) => R): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nfunction6[R](body: (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) => R): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nfunction7[R](body: (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) => R): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nfunction8[R](body: (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) => R): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n\r\nfunction9[R](body: (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) => R): JsValue {\r\n panic(\"This call should have been eliminated by the compiler\")\r\n}\r\n"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": [
|
|
4
|
-
"
|
|
4
|
+
"../../../../core/JsSystem.ff"
|
|
5
5
|
],
|
|
6
6
|
"sourcesContent": [
|
|
7
7
|
"class JsSystem {}\r\n\r\n// The compiler may decide to access symbols by name instead of going through globalThis\r\n\r\nextend self: JsSystem {\r\n\r\n globalThis(): JsValue {\r\n Js.globalThis()\r\n }\r\n\r\n get(key: String): JsValue {\r\n Js.get(key)\r\n }\r\n\r\n set[V: IsJsValue](key: String, value: V): Unit {\r\n Js.set(key, value)\r\n }\r\n\r\n increment[V: IsJsValue](key: String, value: V): Unit {\r\n Js.increment(key, value)\r\n }\r\n \r\n decrement[V: IsJsValue](key: String, value: V): Unit {\r\n Js.decrement(key, value)\r\n }\r\n\r\n call0(name: String): JsValue {\r\n Js.call0(name)\r\n }\r\n\r\n call1[A1: IsJsValue](name: String, a1: A1): JsValue {\r\n Js.call1(name, a1)\r\n }\r\n\r\n call2[A1: IsJsValue, A2: IsJsValue](name: String, a1: A1, a2: A2): JsValue {\r\n Js.call2(name, a1, a2)\r\n }\r\n\r\n call3[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue](name: String, a1: A1, a2: A2, a3: A3): JsValue {\r\n Js.call3(name, a1, a2, a3)\r\n }\r\n\r\n call4[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue](name: String, a1: A1, a2: A2, a3: A3, a4: A4): JsValue {\r\n Js.call4(name, a1, a2, a3, a4)\r\n }\r\n\r\n call5[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue](name: String, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5): JsValue {\r\n Js.call5(name, a1, a2, a3, a4, a5)\r\n }\r\n\r\n call6[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue](name: String, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6): JsValue {\r\n Js.call6(name, a1, a2, a3, a4, a5, a6)\r\n }\r\n\r\n call7[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue, A7: IsJsValue](name: String, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7): JsValue {\r\n Js.call7(name, a1, a2, a3, a4, a5, a6, a7)\r\n }\r\n\r\n call8[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue, A7: IsJsValue, A8: IsJsValue](name: String, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8): JsValue {\r\n Js.call8(name, a1, a2, a3, a4, a5, a6, a7, a8)\r\n }\r\n\r\n call9[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue, A7: IsJsValue, A8: IsJsValue, A9: IsJsValue](name: String, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8, a9: A9): JsValue {\r\n Js.call9(name, a1, a2, a3, a4, a5, a6, a7, a8, a9)\r\n }\r\n\r\n null(): JsValue {\r\n Js.null()\r\n }\r\n\r\n undefined(): JsValue {\r\n Js.undefined()\r\n }\r\n\r\n value[T: IsJsValue](jsValue: T): JsValue {\r\n Js.value(jsValue)\r\n }\r\n\r\n object(): JsValue {\r\n Js.object()\r\n }\r\n \r\n new0(): JsValue {\r\n Js.new0()\r\n }\r\n\r\n array(values: List[JsValue]): JsValue {\r\n Js.array(values)\r\n }\r\n\r\n json(value: Json): JsValue {\r\n Js.json(value)\r\n }\r\n\r\n function0[R](body: () => R): JsValue {\r\n Js.function0(body)\r\n }\r\n\r\n function1[R](body: JsValue => R): JsValue {\r\n Js.function1(body)\r\n }\r\n\r\n function2[R](body: (JsValue, JsValue) => R): JsValue {\r\n Js.function2(body)\r\n }\r\n\r\n function3[R](body: (JsValue, JsValue, JsValue) => R): JsValue {\r\n Js.function3(body)\r\n }\r\n\r\n function4[R](body: (JsValue, JsValue, JsValue, JsValue) => R): JsValue {\r\n Js.function4(body)\r\n }\r\n\r\n function5[R](body: (JsValue, JsValue, JsValue, JsValue, JsValue) => R): JsValue {\r\n Js.function5(body)\r\n }\r\n\r\n function6[R](body: (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) => R): JsValue {\r\n Js.function6(body)\r\n }\r\n\r\n function7[R](body: (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) => R): JsValue {\r\n Js.function7(body)\r\n }\r\n\r\n function8[R](body: (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) => R): JsValue {\r\n Js.function8(body)\r\n }\r\n\r\n function9[R](body: (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) => R): JsValue {\r\n Js.function9(body)\r\n }\r\n\r\n}\r\n"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": [
|
|
4
|
-
"
|
|
4
|
+
"../../../../core/JsValue.ff"
|
|
5
5
|
],
|
|
6
6
|
"sourcesContent": [
|
|
7
7
|
"class JsValue {}\r\n\r\nextend self: JsValue {\r\n\r\n grabString(): String {\r\n if(!self.isString()) {throw(GrabException)}\r\n self?\r\n }\r\n\r\n grabChar(): Char {\r\n if(!self.isChar()) {throw(GrabException)}\r\n self?\r\n }\r\n\r\n grabInt(): Int {\r\n if(!self.isInt()) {throw(GrabException)}\r\n self?\r\n }\r\n\r\n grabFloat(): Float {\r\n if(!self.isFloat()) {throw(GrabException)}\r\n self?\r\n }\r\n\r\n grabBool(): Bool {\r\n if(!self.isBool()) {throw(GrabException)}\r\n self?\r\n }\r\n\r\n grabArray(): List[JsValue] {\r\n if(!self.isArray()) {throw(GrabException)}\r\n self?\r\n }\r\n\r\n grabBuffer(): Buffer {\r\n if(!self.isBuffer()) {throw(GrabException)}\r\n self?\r\n }\r\n \r\n grabJson(): Json {\r\n self? // Should check first\r\n }\r\n\r\n equals[V: IsJsValue](value: V): Bool {\r\n self === value\r\n }\r\n\r\n notEquals[V: IsJsValue](value: V): Bool {\r\n self !== value\r\n }\r\n\r\n isString(): Bool {\r\n self.typeof() == \"string\"\r\n }\r\n \r\n isChar(): Bool {\r\n Js->Number->isInteger(self)? && \r\n Js->Math->abs(self)? <= Js->Number->\"MAX_SAFE_INTEGER\"? &&\r\n self? >= 0 && \r\n self? < 1114112\r\n }\r\n \r\n isInt(): Bool {\r\n Js->Number->isInteger(self)? && \r\n Js->Math->abs(self)? <= Js->Number->\"MAX_SAFE_INTEGER\"?\r\n }\r\n\r\n isFloat(): Bool {\r\n self.typeof() == \"number\"\r\n }\r\n\r\n isBool(): Bool {\r\n self.typeof() == \"boolean\"\r\n }\r\n\r\n isArray(): Bool {\r\n Js->Array->isArray(self)?\r\n }\r\n\r\n isObject(): Bool {\r\n !self.isNull() && self.typeof() == \"object\"\r\n }\r\n\r\n isFunction(): Bool {\r\n self.typeof() == \"function\"\r\n }\r\n \r\n isBuffer(): Bool {\r\n self.instanceof(Js->DataView)\r\n }\r\n\r\n isNull(): Bool {\r\n self === Js.null()\r\n }\r\n\r\n isUndefined(): Bool {\r\n self === Js.undefined()\r\n }\r\n\r\n isNullOrUndefined(): Bool {\r\n self.isNull() || self.isUndefined()\r\n }\r\n\r\n isNan(): Bool {\r\n self.typeof() == \"number\" && self !== self\r\n }\r\n\r\n isFinite(): Bool {\r\n self.typeof() == \"number\" && Js->isFinite(self)?\r\n }\r\n\r\n get[K: IsJsValue](key: K): JsValue {\r\n // Special cased by the compiler\r\n self.get(key)\r\n }\r\n\r\n getOwn(key: String): Option[JsValue] {\r\n if(self.hasOwn(key)) {Some(self.get(key))} else {None}\r\n }\r\n\r\n set[K: IsJsValue, V: IsJsValue](key: K, value: V): Unit {\r\n // Special cased by the compiler\r\n self.set(key, value)\r\n }\r\n\r\n increment[K: IsJsValue, V: IsJsValue](key: K, value: V): Unit {\r\n // Special cased by the compiler\r\n self.increment(key, value)\r\n }\r\n \r\n decrement[K: IsJsValue, V: IsJsValue](key: K, value: V): Unit {\r\n // Special cased by the compiler\r\n self.decrement(key, value)\r\n }\r\n\r\n delete[K: IsJsValue](key: K): Unit {\r\n // Special cased by the compiler\r\n self.delete(key)\r\n }\r\n\r\n with[K: IsJsValue, V: IsJsValue](key: K, value: V): JsValue {\r\n // Special cased by the compiler\r\n self.with(key, value)\r\n }\r\n\r\n hasOwn(name: String): Bool {\r\n Js->Object->prototype->hasOwnProperty->call(self, name)?\r\n }\r\n\r\n\r\n assign(source: JsValue, source2: JsValue = source): JsValue {\r\n Js->Object->assign(self, source, if(source2 !== source) {source2} else {Js.null()})?\r\n }\r\n\r\n\r\n each(body: JsValue => Unit): Unit {\r\n let iterator = self.call0(Js->Symbol->iterator)\r\n mutable result = iterator->next()\r\n while {!result->done?} {\r\n body(result->value)\r\n result = iterator->next()\r\n }\r\n }\r\n\r\n eachWhile(body: JsValue => Bool): Unit {\r\n let iterator = self.call0(Js->Symbol->iterator)\r\n mutable result = iterator->next()\r\n while {!result->done? && body(result->value)} {\r\n result = iterator->next()\r\n }\r\n }\r\n\r\n call[A0: IsJsValue](name: A0, arguments: List[JsValue]): JsValue {\r\n self.get(name)->apply(self, arguments)\r\n }\r\n\r\n call0[A0: IsJsValue](name: A0): JsValue {\r\n // Special cased by the compiler\r\n self.call0(name)\r\n }\r\n\r\n call1[A0: IsJsValue, A1: IsJsValue](name: A0, a1: A1): JsValue {\r\n // Special cased by the compiler\r\n self.call1(name, a1)\r\n }\r\n\r\n call2[A0: IsJsValue, A1: IsJsValue, A2: IsJsValue](name: A0, a1: A1, a2: A2): JsValue {\r\n // Special cased by the compiler\r\n self.call2(name, a1, a2)\r\n }\r\n\r\n call3[A0: IsJsValue, A1: IsJsValue, A2: IsJsValue, A3: IsJsValue](name: A0, a1: A1, a2: A2, a3: A3): JsValue {\r\n // Special cased by the compiler\r\n self.call3(name, a1, a2, a3)\r\n }\r\n\r\n call4[A0: IsJsValue, A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue](name: A0, a1: A1, a2: A2, a3: A3, a4: A4): JsValue {\r\n // Special cased by the compiler\r\n self.call4(name, a1, a2, a3, a4)\r\n }\r\n\r\n call5[A0: IsJsValue, A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue](name: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5): JsValue {\r\n // Special cased by the compiler\r\n self.call5(name, a1, a2, a3, a4, a5)\r\n }\r\n\r\n call6[A0: IsJsValue, A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue](name: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6): JsValue {\r\n // Special cased by the compiler\r\n self.call6(name, a1, a2, a3, a4, a5, a6)\r\n }\r\n\r\n call7[A0: IsJsValue, A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue, A7: IsJsValue](name: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7): JsValue {\r\n // Special cased by the compiler\r\n self.call7(name, a1, a2, a3, a4, a5, a6, a7)\r\n }\r\n\r\n call8[A0: IsJsValue, A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue, A7: IsJsValue, A8: IsJsValue](name: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8): JsValue {\r\n // Special cased by the compiler\r\n self.call8(name, a1, a2, a3, a4, a5, a6, a7, a8)\r\n }\r\n\r\n call9[A0: IsJsValue, A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue, A7: IsJsValue, A8: IsJsValue, A9: IsJsValue](name: A0, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8, a9: A9): JsValue {\r\n // Special cased by the compiler\r\n self.call9(name, a1, a2, a3, a4, a5, a6, a7, a8, a9)\r\n }\r\n\r\n callValue(this: JsValue, arguments: List[JsValue]): JsValue {\r\n self->apply(this, arguments)\r\n }\r\n\r\n callValue0(): JsValue {\r\n // Special cased by the compiler\r\n self.callValue0()\r\n }\r\n\r\n callValue1[A1: IsJsValue](a1: A1): JsValue {\r\n // Special cased by the compiler\r\n self.callValue1(a1)\r\n }\r\n\r\n callValue2[A1: IsJsValue, A2: IsJsValue](a1: A1, a2: A2): JsValue {\r\n // Special cased by the compiler\r\n self.callValue2(a1, a2)\r\n }\r\n\r\n callValue3[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue](a1: A1, a2: A2, a3: A3): JsValue {\r\n // Special cased by the compiler\r\n self.callValue3(a1, a2, a3)\r\n }\r\n\r\n callValue4[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue](a1: A1, a2: A2, a3: A3, a4: A4): JsValue {\r\n // Special cased by the compiler\r\n self.callValue4(a1, a2, a3, a4)\r\n }\r\n\r\n callValue5[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue](a1: A1, a2: A2, a3: A3, a4: A4, a5: A5): JsValue {\r\n // Special cased by the compiler\r\n self.callValue5(a1, a2, a3, a4, a5)\r\n }\r\n\r\n callValue6[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue](a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6): JsValue {\r\n // Special cased by the compiler\r\n self.callValue6(a1, a2, a3, a4, a5, a6)\r\n }\r\n\r\n callValue7[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue, A7: IsJsValue](a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7): JsValue {\r\n // Special cased by the compiler\r\n self.callValue7(a1, a2, a3, a4, a5, a6, a7)\r\n }\r\n\r\n callValue8[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue, A7: IsJsValue, A8: IsJsValue](a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8): JsValue {\r\n // Special cased by the compiler\r\n self.callValue8(a1, a2, a3, a4, a5, a6, a7, a8)\r\n }\r\n\r\n callValue9[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue, A7: IsJsValue, A8: IsJsValue, A9: IsJsValue](a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8, a9: A9): JsValue {\r\n // Special cased by the compiler\r\n self.callValue9(a1, a2, a3, a4, a5, a6, a7, a8, a9)\r\n }\r\n\r\n\r\n new(arguments: List[JsValue]): JsValue {\r\n Js->Function->prototype->bind->apply->(self, arguments)\r\n }\r\n\r\n new0(): JsValue {\r\n // Special cased by the compiler\r\n self->()\r\n }\r\n\r\n new1[A1: IsJsValue](a1: A1): JsValue {\r\n // Special cased by the compiler\r\n self->(a1)\r\n }\r\n\r\n new2[A1: IsJsValue, A2: IsJsValue](a1: A1, a2: A2): JsValue {\r\n // Special cased by the compiler\r\n self->(a1, a2)\r\n }\r\n\r\n new3[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue](a1: A1, a2: A2, a3: A3): JsValue {\r\n // Special cased by the compiler\r\n self->(a1, a2, a3)\r\n }\r\n\r\n new4[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue](a1: A1, a2: A2, a3: A3, a4: A4): JsValue {\r\n // Special cased by the compiler\r\n self->(a1, a2, a3, a4)\r\n }\r\n\r\n new5[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue](a1: A1, a2: A2, a3: A3, a4: A4, a5: A5): JsValue {\r\n // Special cased by the compiler\r\n self->(a1, a2, a3, a4, a5)\r\n }\r\n\r\n new6[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue](a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6): JsValue {\r\n // Special cased by the compiler\r\n self->(a1, a2, a3, a4, a5, a6)\r\n }\r\n\r\n new7[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue, A7: IsJsValue](a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7): JsValue {\r\n // Special cased by the compiler\r\n self->(a1, a2, a3, a4, a5, a6, a7)\r\n }\r\n\r\n new8[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue, A7: IsJsValue, A8: IsJsValue](a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8): JsValue {\r\n // Special cased by the compiler\r\n self->(a1, a2, a3, a4, a5, a6, a7, a8)\r\n }\r\n\r\n new9[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue, A7: IsJsValue, A8: IsJsValue, A9: IsJsValue](a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8, a9: A9): JsValue {\r\n // Special cased by the compiler\r\n self->(a1, a2, a3, a4, a5, a6, a7, a8, a9)\r\n }\r\n\r\n new10[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue, A6: IsJsValue, A7: IsJsValue, A8: IsJsValue, A9: IsJsValue, A10: IsJsValue](a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8, a9: A9, a10: A10): JsValue {\r\n // Special cased by the compiler\r\n self->(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)\r\n }\r\n\r\n\r\n grabPairs(): List[Pair[String, JsValue]] {\r\n if(!self.isObject()) {throw(GrabException)}\r\n Js->Object->getOwnPropertyNames(self)->map(Js->{name, i => Pair(name, self.get(name))})?\r\n }\r\n\r\n grabMap(): Map[String, JsValue] {\r\n self.grabPairs().toMap()\r\n }\r\n\r\n grabIntMap(): IntMap[JsValue] {\r\n if(!self.instanceof(Js->Map)) {throw(GrabException)}\r\n self?\r\n }\r\n\r\n grabStringMap(): StringMap[JsValue] {\r\n if(!self.instanceof(Js->Map)) {throw(GrabException)}\r\n self?\r\n }\r\n \r\n spreadToArray(): List[JsValue] {\r\n // Special cased by the compiler\r\n self.spreadToArray()\r\n }\r\n \r\n coalesce[T: IsJsValue](defaultValue: T): JsValue {\r\n if(self.isNullOrUndefined()) {Js.value(defaultValue)} else {self}\r\n }\r\n\r\n typeof(): String {\r\n // Special cased by the compiler\r\n self.typeof()\r\n }\r\n\r\n instanceof(type: JsValue): Bool {\r\n // Special cased by the compiler\r\n self.instanceof(type)\r\n }\r\n \r\n truthy(): Bool {\r\n Js.unaryOperator(\"!!\", self)?\r\n }\r\n \r\n falsy(): Bool {\r\n Js.unaryOperator(\"!\", self)?\r\n }\r\n \r\n nullish(): Bool {\r\n self.isNullOrUndefined() // TODO: Rename\r\n }\r\n\r\n //toList(): List[JsValue] // TODO\r\n // TODO: JS operators\r\n\r\n}\r\n\r\ntrait T: IsJsValue {}\r\ninstance JsValue: IsJsValue {}\r\ninstance String: IsJsValue {}\r\ninstance Char: IsJsValue {}\r\ninstance Int: IsJsValue {}\r\ninstance Float: IsJsValue {}\r\ninstance Bool: IsJsValue {}\r\ninstance List[T: IsJsValue]: IsJsValue {}\r\ninstance IntMap[T: IsJsValue]: IsJsValue {}\r\ninstance StringMap[T: IsJsValue]: IsJsValue {}\r\ninstance Error: IsJsValue {}\r\ninstance Date: IsJsValue {}\r\ninstance Duration: IsJsValue {}\r\ninstance Buffer: IsJsValue {}\r\ninstance Nothing: IsJsValue {}\r\n"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": [
|
|
4
|
-
"
|
|
4
|
+
"../../../../core/Json.ff"
|
|
5
5
|
],
|
|
6
6
|
"sourcesContent": [
|
|
7
7
|
"newtype Json(jsValue: JsValue)\r\n\r\nread(json: String): Option[Json] {\r\n try {\r\n Some(Json(Js->JSON->parse(json)))\r\n } catchAny {_ =>\r\n None\r\n }\r\n}\r\n\r\nstring(json: String): Json {\r\n Json(json!)\r\n}\r\n\r\nint(json: Int): Json {\r\n Json(json!)\r\n}\r\n\r\nfloat(json: Float): Json {\r\n Json(json!)\r\n}\r\n\r\nbool(json: Bool): Json {\r\n Json(json!)\r\n}\r\n\r\nnull(): Json {\r\n Json(Js.null())\r\n}\r\n\r\narray(json: List[Json]): Json {\r\n Json(json!)\r\n}\r\n\r\nobject(): Json {\r\n Json(Js->())\r\n}\r\n\r\nnew0(): Json {\r\n Json(Js->())\r\n}\r\n\r\nfields(body: ((String, Json) => Unit) => Unit): Json {\r\n let result = Js->()\r\n body {k, v => result.set(k, v.jsValue)}\r\n Json(result)\r\n}\r\n\r\nextend self: Json {\r\n \r\n write(indentation: Option[String] = None): String {\r\n Js->JSON->stringify(self.jsValue, Js.null(), Js.orUndefined(indentation))?\r\n }\r\n\r\n with[T: JsonLike](field: String, value: T): Json {\r\n if(!self.isObject()) {\r\n Js.throw(Js->Error->(\"Not an object: \" + self.write()))\r\n }\r\n Json(self.jsValue.with(field, toJson(value).jsValue))\r\n }\r\n \r\n merge(that: Json): Json {\r\n if(!self.isObject()) {\r\n Js.throw(Js->Error->(\"Not an object: \" + self.write()))\r\n }\r\n if(!that.isObject()) {\r\n Js.throw(Js->Error->(\"Not an object: \" + that.write()))\r\n }\r\n Json(Js.object().assign(self.jsValue, that.jsValue))\r\n }\r\n \r\n grabString(): String {\r\n if(!self.isString()) {\r\n Js.throw(Js->Error->(\"Not a String: \" + self.write()))\r\n }\r\n self.jsValue?\r\n }\r\n \r\n grabInt(): Int {\r\n if(!self.isInt()) {\r\n Js.throw(Js->Error->(\"Not an Int: \" + self.write()))\r\n }\r\n self.jsValue?\r\n }\r\n\r\n grabFloat(): Float {\r\n if(!self.isFloat()) {\r\n Js.throw(Js->Error->(\"Not a Float: \" + self.write()))\r\n }\r\n self.jsValue?\r\n }\r\n\r\n grabBool(): Bool {\r\n if(!self.isBool()) {\r\n Js.throw(Js->Error->(\"Not a Bool: \" + self.write()))\r\n }\r\n self.jsValue?\r\n }\r\n \r\n grabArray(): List[Json] {\r\n if(!self.isArray()) {\r\n Js.throw(Js->Error->(\"Not an array: \" + self.write()))\r\n }\r\n self.jsValue?\r\n }\r\n\r\n grabMap(): Map[String, Json] {\r\n mutable map = Map.new()\r\n self.each {key, value => \r\n map = map.add(key, value)\r\n }\r\n map\r\n }\r\n\r\n getString(): Option[String] {\r\n if(self.isString()) {self.grabString()}\r\n }\r\n\r\n getInt(): Option[Int] {\r\n if(self.isInt()) {self.grabInt()}\r\n }\r\n\r\n getFloat(): Option[Float] {\r\n if(self.isFloat()) {self.grabFloat()}\r\n }\r\n\r\n getBool(): Option[Bool] {\r\n if(self.isBool()) {self.grabBool()}\r\n }\r\n\r\n getArray(): Option[List[Json]] {\r\n if(self.isArray()) {self.grabArray()}\r\n }\r\n\r\n getMap(): Option[Map[String, Json]] {\r\n if(self.isObject()) {self.grabMap()}\r\n }\r\n\r\n isString(): Bool {\r\n self.jsValue.typeof() == \"string\"\r\n }\r\n\r\n isInt(): Bool {\r\n Js->Number->isSafeInteger(self.jsValue)?\r\n }\r\n\r\n isFloat(): Bool {\r\n self.jsValue.typeof() == \"number\"\r\n }\r\n\r\n isBool(): Bool {\r\n self.jsValue.typeof() == \"boolean\"\r\n }\r\n\r\n isArray(): Bool {\r\n Js->Array->isArray(self.jsValue)?\r\n }\r\n\r\n isObject(): Bool {\r\n self.jsValue.typeof() == \"object\" && !self.jsValue.isNull() && !self.jsValue.isArray()\r\n }\r\n\r\n isNull(): Bool {\r\n self.jsValue.isNull()\r\n }\r\n\r\n get(key: String): Json {\r\n self.field(key)\r\n }\r\n\r\n field(key: String): Json {\r\n if(self.isObject() && self.jsValue.hasOwn(key)) {\r\n Json(self.jsValue.get(key))\r\n } else {\r\n Json(Js.null())\r\n }\r\n }\r\n\r\n index(key: Int): Json {\r\n if(self.isArray()) {\r\n Json(self.jsValue.get(key).coalesce(Js.null()))\r\n } else {\r\n Json(Js.null())\r\n }\r\n }\r\n \r\n hasField(key: String): Bool {\r\n self.isObject() && self.jsValue.hasOwn(key)\r\n }\r\n\r\n getField(key: String): Option[Json] {\r\n if(self.hasField(key)) {self.get(key)}\r\n }\r\n\r\n getIndex(key: Int): Option[Json] {\r\n if(self.isArray() && !self.jsValue.get(key).isUndefined()) {\r\n Json(self.jsValue.get(key))\r\n }\r\n }\r\n \r\n getFields(): Option[List[String]] {\r\n if(self.isObject()) {\r\n Js->Object->keys(self.jsValue)?\r\n }\r\n }\r\n\r\n grabField(key: String): Json {\r\n self.getField(key).else {\r\n throw(GrabException())\r\n }\r\n }\r\n\r\n grabIndex(key: Int): Json {\r\n self.getIndex(key).else {\r\n throw(GrabException())\r\n }\r\n }\r\n \r\n grabFields(): List[String] {\r\n self.getFields().else {\r\n throw(GrabException())\r\n }\r\n }\r\n\r\n map[T](body: (String, Json) => T): List[T] {\r\n let array = Array.new()\r\n self.each {field, value => array.push(body(field, value))}\r\n array.drain()\r\n }\r\n\r\n flatMap[T](body: (String, Json) => List[T]): List[T] {\r\n let array = Array.new()\r\n self.each {field, value => array.pushList(body(field, value))}\r\n array.drain()\r\n }\r\n \r\n each(body: (String, Json) => Unit) {\r\n if(!self.isObject()) {throw(GrabException())}\r\n Js->Object->entries(self.jsValue).each {p =>\r\n body(p.get(0)?, p.get(1)?)\r\n }\r\n }\r\n\r\n eachWhile(body: (String, Json) => Bool) {\r\n if(!self.isObject()) {throw(GrabException())}\r\n Js->Object->entries(self.jsValue).eachWhile {p =>\r\n body(p.get(0)?, p.get(1)?)\r\n }\r\n }\r\n\r\n}\r\n\r\ntrait T: JsonLike {\r\n toJson(value: T): Json\r\n fromJson(json: Json): Option[T]\r\n}\r\n\r\ninstance Json: JsonLike {\r\n toJson(value: Json): Json {value}\r\n fromJson(json: Json): Option[Json] {Some(json)}\r\n}\r\n\r\ninstance String: JsonLike {\r\n toJson(value: String): Json {string(value)}\r\n fromJson(json: Json): Option[String] {_.getString()}\r\n}\r\n\r\ninstance Int: JsonLike {\r\n toJson(value: Int): Json {int(value)}\r\n fromJson(json: Json): Option[Int] {_.getInt()}\r\n}\r\n\r\ninstance Float: JsonLike {\r\n toJson(value: Float): Json {float(value)}\r\n fromJson(json: Json): Option[Float] {_.getFloat()}\r\n}\r\n\r\ninstance Bool: JsonLike {\r\n toJson(value: Bool): Json {bool(value)}\r\n fromJson(json: Json): Option[Bool] {_.getBool()}\r\n}\r\n\r\ninstance List[T: JsonLike]: JsonLike {\r\n toJson(value: List[T]): Json {array(value.map(toJson))}\r\n fromJson(json: Json): Option[List[T]] {\r\n json.getArray().flatMap {array => \r\n mutable convertible = True\r\n let result = Array.new()\r\n array.eachWhile {item =>\r\n fromJson(item).{\r\n | None => convertible = False\r\n | Some(value) => result.push(value)\r\n }\r\n convertible\r\n }\r\n if(convertible) {result.drain()}\r\n }\r\n }\r\n}\r\n\r\ninstance StringMap[T: JsonLike]: JsonLike {\r\n toJson(value: StringMap[T]): Json {\r\n Json.fields {setField =>\r\n value.each {key, value => setField(key, toJson(value))}\r\n }\r\n }\r\n fromJson(json: Json): Option[StringMap[T]] {\r\n if(json.isObject()) {\r\n let map = StringMap.new()\r\n mutable convertible = True\r\n json.eachWhile {key, value => \r\n fromJson(value).{\r\n | None => convertible = False\r\n | Some(v) => map.set(key, v)\r\n }\r\n convertible\r\n }\r\n if(convertible) {map}\r\n }.flatten()\r\n }\r\n}\r\n\r\n\r\ninstance Json: HasAnyTag {\r\n anyTag(): AnyTag[Json] {Any.internalAnyTag(\"ff:core/Json.Json[]\")}\r\n}\r\n\r\ninstance Json: Show {\r\n show(value: Json): String {value.write(Some(\" \"))}\r\n}\r\n\r\ninstance Json: Equal {\r\n equals(a: Json, b: Json): Bool {\r\n internalEquals(a, b)\r\n }\r\n}\r\n\r\ninstance Json: Order {\r\n compare(a: Json, b: Json): Ordering {\r\n Ordering.fromInt(internalCompare(a, b))\r\n }\r\n}\r\n\r\ninstance Json: Serializable {\r\n serializeUsing(serialization: Serialization, value: Json): Unit {\r\n Serializable.serializeUsing(serialization, value.write())\r\n }\r\n deserializeUsing(serialization: Serialization): Json {\r\n Json.read(Serializable.deserializeUsing[String](serialization)).grab()\r\n }\r\n}\r\n\r\n\r\ninternalEquals(a: Json, b: Json): Bool {\r\n if(a.jsValue === b.jsValue) {True} else:\r\n if(a.jsValue.isArray() || b.jsValue.isArray()) {\r\n if(!a.jsValue.isArray() || !b.jsValue.isArray()) {False} else:\r\n if(a.jsValue->length !== b.jsValue->length) {False} else:\r\n mutable equal = True\r\n 0.until(a.jsValue->length?).eachWhile {i =>\r\n equal = internalEquals(Json(a.jsValue.get(i)), Json(b.jsValue.get(i)))\r\n equal\r\n }\r\n equal\r\n } else:\r\n if(a.isObject() && b.isObject()) {\r\n let aKeys = Js->Object->keys(a.jsValue)\r\n let bKeys = Js->Object->keys(b.jsValue)\r\n if(aKeys->length !== bKeys->length) {False} else:\r\n mutable equal = True\r\n aKeys.eachWhile {key =>\r\n equal = b.jsValue.hasOwn(key?) && internalEquals(Json(a.jsValue.get(key)), Json(b.jsValue.get(key)))\r\n equal\r\n }\r\n equal\r\n } else:\r\n False\r\n}\r\n\r\ninternalCompare(a: Json, b: Json): Int {\r\n if(a.jsValue === b.jsValue) {0} else:\r\n if(a.jsValue === Js.null() || b.jsValue === Js.null()) {\r\n if(a.jsValue === Js.null()) {-1} else {1}\r\n } else:\r\n if(a.isBool() || b.isBool()) {\r\n if(!b.isBool() || b.jsValue?) {-1} else {1}\r\n } else:\r\n if(a.isFloat() || b.isFloat()) {\r\n if(!b.isFloat()) {-1} else:\r\n if(!a.isFloat()) {1} else:\r\n if(a.jsValue.isNan()) {if(b.jsValue.isNan()) {0} else {-1}} else:\r\n if(b.jsValue.isNan()) {1} else:\r\n if(a.jsValue? < b.jsValue?) {-1} else {1}\r\n } else:\r\n if(a.isString() || b.isString()) {\r\n if(!b.isString()) {-1} else:\r\n if(!a.isString()) {1} else:\r\n a.jsValue->localeCompare(b.jsValue, \"en\")?\r\n } else:\r\n if(a.isArray() || b.isArray()) {\r\n if(!b.isArray()) {-1} else:\r\n if(!a.isArray()) {1} else:\r\n let aLength: Int = a.jsValue->length?\r\n let bLength: Int = b.jsValue->length?\r\n mutable result = 0\r\n 0.until(aLength.min(bLength)).eachWhile {i =>\r\n result = internalCompare(Json(a.jsValue.get(i)), Json(b.jsValue.get(i)))\r\n result == 0\r\n }\r\n if(result != 0) {result} else:\r\n aLength - bLength\r\n } else:\r\n let aKeys = Js->Object->keys(a.jsValue)->sort()\r\n let bKeys = Js->Object->keys(b.jsValue)->sort()\r\n let keyResult = internalCompare(Json(aKeys), Json(bKeys))\r\n if(keyResult != 0) {keyResult} else:\r\n mutable result = 0\r\n aKeys.eachWhile {key =>\r\n result = internalCompare(Json(a.jsValue.get(key)), Json(b.jsValue.get(key)))\r\n result == 0\r\n }\r\n result\r\n}\r\n"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": [
|
|
4
|
-
"
|
|
4
|
+
"../../../../core/List.ff"
|
|
5
5
|
],
|
|
6
6
|
"sourcesContent": [
|
|
7
7
|
"data List[T] {}\r\n\r\nnew[T](): List[T] {\r\n []\r\n}\r\n\r\nfill[T](size: Int, value: T): List[T] {\r\n Js->Array->(size)->fill(value!)?\r\n}\r\n\r\nfillBy[T](size: Int, body: Int => T): List[T] {\r\n if(Js.inAsync()) {\r\n let array = Js->Array->(size)\r\n 1.until(size).each {i => \r\n array.set(i, body(i)!)\r\n }\r\n array?\r\n } else {\r\n Js->Array->from(Js->(length = size), Js->{_, i => body(i?)})?\r\n }\r\n}\r\n\r\n\r\nrange(size: Int): List[Int] {\r\n Js->Array->from(Js->(length = size), Js->{_, i => i})?\r\n}\r\n\r\nextend self[T]: List[T] {\r\n\r\n addAll(that: List[T]): List[T] {\r\n self!->concat(that!)?\r\n }\r\n\r\n isEmpty(): Bool {\r\n self.size() == 0\r\n }\r\n\r\n size(): Int {\r\n self!->length?\r\n }\r\n\r\n get(index: Int): Option[T] {\r\n if(index >= 0 && index < self.size()) {\r\n Some(self!.get(index)?)\r\n } else {\r\n None\r\n }\r\n }\r\n\r\n grab(index: Int): T {\r\n if(index < 0 || index >= self.size()) {\r\n throw(GrabException())\r\n }\r\n self!.get(index)?\r\n }\r\n\r\n first(): Option[T] {self.get(0)}\r\n\r\n last(): Option[T] {self.get(self.size() - 1)}\r\n\r\n grabFirst(): T {self.grab(0)}\r\n\r\n grabLast(): T {self.grab(self.size() - 1)}\r\n\r\n takeFirst(count: Int = 1): List[T] {\r\n self!->slice(0, count)?\r\n }\r\n\r\n takeLast(count: Int = 1): List[T] {\r\n self!->slice(-count)?\r\n }\r\n\r\n dropFirst(count: Int = 1): List[T] {\r\n self!->slice(count)?\r\n }\r\n\r\n dropLast(count: Int = 1): List[T] {\r\n self!->slice(0, self.size() - count)?\r\n }\r\n \r\n count(body: T => Bool): Int {\r\n mutable result = 0\r\n mutable i = 0\r\n while {i < self.size()} {\r\n if(body(self.grab(i))) {result += 1}\r\n i += 1\r\n }\r\n result\r\n }\r\n\r\n countWhile(body: T => Bool): Int {\r\n mutable i = 0\r\n while {i < self.size() && body(self.grab(i))} {\r\n i += 1\r\n }\r\n i\r\n }\r\n\r\n takeWhile(body: T => Bool): List[T] {\r\n let result = Array.new()\r\n mutable i = 0\r\n while {i < self.size() && body(self.grab(i))} {\r\n result.push(self.grab(i))\r\n i += 1\r\n }\r\n result.drain()\r\n }\r\n\r\n dropWhile(body: T => Bool): List[T] {\r\n let result = Array.new()\r\n mutable i = 0\r\n while {i < self.size() && body(self.grab(i))} {\r\n i += 1\r\n }\r\n while {i < self.size()} {\r\n result.push(self.grab(i))\r\n i += 1\r\n }\r\n result.drain()\r\n }\r\n \r\n partitionWhile(body: T => Bool): Pair[List[T], List[T]] {\r\n let first = Array.new()\r\n let second = Array.new()\r\n mutable i = 0\r\n while {i < self.size() && body(self.grab(i))} {\r\n first.push(self.grab(i))\r\n i += 1\r\n }\r\n while {i < self.size()} {\r\n second.push(self.grab(i))\r\n i += 1\r\n }\r\n Pair(first.drain(), second.drain())\r\n }\r\n \r\n pairs(): List[Pair[Int, T]] {\r\n mutable i = 0\r\n self.map {x =>\r\n let r = Pair(i, x)\r\n i += 1\r\n r\r\n }\r\n }\r\n \r\n slice(from: Int, until: Int): List[T] {\r\n self.dropFirst(from).takeFirst(until - from)\r\n }\r\n \r\n foldLeft[R](initial: R, body: (R, T) => R): R {\r\n mutable result = initial\r\n self.each {x =>\r\n result = body(result, x)\r\n }\r\n result\r\n } \r\n\r\n update(index: Int, value: T): List[T] {\r\n self.modify(index) {_ => value}\r\n }\r\n \r\n modify(index: Int, body: T => T): List[T] {\r\n if(index < 0 || index >= self.size()) {\r\n throw(GrabException())\r\n }\r\n let result = self!->slice()\r\n result.set(index, body(result.get(index)?)!)\r\n result?\r\n }\r\n \r\n zip[S](that: List[S]): List[Pair[T, S]] {\r\n if(self.size() <= that.size()) {\r\n mutable i = -1\r\n self.map {x => \r\n i += 1\r\n Pair(x, that.grab(i))\r\n }\r\n } else {\r\n mutable i = -1\r\n that.map {y => \r\n i += 1\r\n Pair(self.grab(i), y)\r\n }\r\n }\r\n }\r\n\r\n chunk(chunkSize: Int): List[List[T]] {\r\n let results = Array.new()\r\n let result = Array.new()\r\n mutable added = 0\r\n self.each {item =>\r\n if(added < chunkSize) {\r\n added += 1\r\n } else {\r\n results.push(result.drain())\r\n added = 1\r\n }\r\n result.push(item)\r\n }\r\n if(added != 0) {\r\n results.push(result.drain())\r\n }\r\n results.drain()\r\n }\r\n\r\n toStream(cycle: Bool = False): Stream[T] {\r\n mutable index = 0\r\n Stream.new {\r\n if(index < self.size()) {\r\n let result = self.grab(index)\r\n index += 1\r\n result\r\n } elseIf {cycle && index != 0} {\r\n let result = self.grab(0)\r\n index = 1\r\n result\r\n }\r\n }\r\n }\r\n\r\n toArray(): Array[T] {\r\n Js->(array = self!->slice())?\r\n }\r\n \r\n toQueue(): Queue[T] {\r\n let queue = Queue.new()\r\n self.each {v => queue.push(v)}\r\n queue\r\n }\r\n\r\n each(body: T => Unit): Unit {\r\n mutable i = 0\r\n while {i < self.size()} {\r\n body(self!.get(i)?)\r\n i += 1\r\n }\r\n }\r\n \r\n eachWhile(body: T => Bool): Unit {\r\n mutable i = 0\r\n while {i < self.size()} {\r\n if(body(self!.get(i)?)) {\r\n i += 1\r\n } else {\r\n i = self.size()\r\n }\r\n }\r\n }\r\n\r\n all(body: T => Bool): Bool {\r\n mutable result = True\r\n self.eachWhile {x =>\r\n result = body(x)\r\n result\r\n }\r\n result\r\n }\r\n\r\n any(body: T => Bool): Bool {\r\n mutable result = False\r\n self.eachWhile {x =>\r\n result = body(x)\r\n (!result)\r\n }\r\n result\r\n }\r\n \r\n find(body: T => Bool): Option[T] {\r\n mutable result = None\r\n self.eachWhile {x =>\r\n if(body(x)) {\r\n result = Some(x)\r\n False\r\n } else {\r\n True\r\n }\r\n }\r\n result\r\n }\r\n\r\n indexWhere(body: T => Bool): Option[Int] {\r\n mutable i = -1\r\n mutable result = False\r\n self.eachWhile {x =>\r\n i += 1\r\n result = body(x)\r\n (!result)\r\n }\r\n if(result) {i}\r\n } \r\n \r\n filter(body: T => Bool): List[T] {\r\n let result = Array.new()\r\n self.each {x =>\r\n if(body(x)) {\r\n result.push(x)\r\n }\r\n }\r\n result.drain()\r\n }\r\n \r\n partition(body: T => Bool): Pair[List[T], List[T]] {\r\n Pair(self.filter(body), self.filter {!body(_)})\r\n }\r\n\r\n map[S](body: T => S): List[S] {\r\n let array = Array.new()\r\n self.each {e => \r\n array.push(body(e))\r\n }\r\n array.drain()\r\n }\r\n \r\n flatMap[S](body: T => List[S]): List[S] {\r\n let results = Array.new()\r\n self.each {x =>\r\n results.pushList(body(x))\r\n }\r\n results.drain()\r\n }\r\n \r\n collect[R](body: T => Option[R]): List[R] {\r\n mutable result = Array.new()\r\n self.each {x =>\r\n body(x).each {result.push(_)}\r\n }\r\n result.drain()\r\n }\r\n\r\n collectFirst[R](body: T => Option[R]): Option[R] {\r\n mutable result = None\r\n self.eachWhile {x =>\r\n body(x).{\r\n | None =>\r\n True\r\n | o =>\r\n result = o\r\n False\r\n }\r\n }\r\n result\r\n }\r\n\r\n sortBy[S: Order](body: T => S): List[T] {\r\n self.sortWith {Ordering.compare(body(_), body(_))}\r\n }\r\n\r\n sortWith(ordering: (T, T) => Ordering): List[T] {\r\n let array = self.toArray()\r\n array.sortWith(ordering)\r\n array.drain()\r\n }\r\n \r\n reverse(): List[T] {\r\n 1.to(self.size()).map {i =>\r\n self.grab(self.size() - i)\r\n }\r\n }\r\n \r\n separate(separator: List[T]): List[T] {\r\n let array = Array.new()\r\n self.pairs().each {| Pair(i, x) =>\r\n if(i != 0) {\r\n array.pushList(separator)\r\n }\r\n array.push(x)\r\n }\r\n array.drain()\r\n }\r\n \r\n}\r\n\r\nextend self[T: Order]: List[T] {\r\n\r\n sort(): List[T] {\r\n self.sortWith(Ordering.compare)\r\n }\r\n\r\n toSet(): Set[T] {\r\n self.foldLeft(Set.new()) {_.add(_)}\r\n }\r\n \r\n distinct(): List[T] {\r\n mutable seen = [].toSet()\r\n self.filter {\r\n | item {!seen.contains(item)} =>\r\n seen = seen.add(item)\r\n True\r\n | _ =>\r\n False\r\n }\r\n }\r\n\r\n}\r\n\r\nextend self[T]: List[List[T]] {\r\n\r\n flatten(): List[T] {\r\n let result = Array.new()\r\n self.each {xs =>\r\n result.pushList(xs)\r\n }\r\n result.drain()\r\n }\r\n\r\n}\r\n\r\nextend self[K: Order, V]: List[Pair[K, V]] {\r\n \r\n toMap(): Map[K, V] {\r\n self.foldLeft(Map.new()) {| map, Pair(key, value) => map.add(key, value)}\r\n }\r\n \r\n group(): Map[K, List[V]] {\r\n mutable map = Map.new[K, Array[V]]()\r\n self.each {| Pair(k, v) => map = map.push(k, v)}\r\n map.mapValues {_, v => v.drain()}\r\n }\r\n \r\n}\r\n\r\nextend self[K, V]: List[Pair[K, V]] {\r\n\r\n unzip(): Pair[List[K], List[V]] {\r\n let first = Array.new()\r\n let second = Array.new()\r\n self.each {| Pair(x, y) =>\r\n first.push(x)\r\n second.push(y)\r\n }\r\n Pair(first.drain(), second.drain())\r\n }\r\n\r\n}\r\n\r\nextend self: List[String] {\r\n\r\n join(separator: String = \"\"): String {\r\n self!->join(separator)?\r\n }\r\n\r\n}\r\n\r\ninstance List[T: Show]: Show {\r\n show(value: List[T]): String {\r\n let array = Array.new()\r\n array.push(\"[\")\r\n value.each {x =>\r\n if(array.size() > 1) {array.push(\", \")}\r\n array.push(Show.show(x))\r\n }\r\n array.push(\"]\")\r\n array.join()\r\n }\r\n}\r\n\r\ninstance List[T: Equal]: Equal {\r\n equals(x: List[T], y: List[T]): Bool {\r\n if(x!.equals(y!)) {True} else:\r\n if(x.size() != y.size()) {False} else:\r\n mutable i = -1\r\n x.all {l =>\r\n i += 1\r\n l == y.grab(i)\r\n }\r\n }\r\n}\r\n\r\ninstance List[T: Order]: Order {\r\n compare(x: List[T], y: List[T]): Ordering {\r\n if(x!.equals(y!)) {OrderingSame} else:\r\n let size = x.size().min(y.size())\r\n mutable i = 0\r\n mutable ordering = OrderingSame\r\n while {ordering == OrderingSame && i < size} {\r\n ordering = Ordering.compare(x.grab(i), y.grab(i))\r\n i += 1\r\n }\r\n if(ordering != OrderingSame) {ordering} else:\r\n Ordering.compare(x.size(), y.size())\r\n }\r\n}\r\n"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": [
|
|
4
|
-
"
|
|
4
|
+
"../../../../core/Lock.ff"
|
|
5
5
|
],
|
|
6
6
|
"sourcesContent": [
|
|
7
7
|
"capability Lock(\r\n mutable owner: JsValue\r\n mutable level: Int\r\n queue: Queue[Pair[JsValue, Unit => Unit]]\r\n)\r\n\r\ncapability LockCondition(\r\n lock: Lock\r\n queue: Queue[Unit => Unit]\r\n)\r\n\r\nextend self: Lock {\r\n\r\n condition(): LockCondition {\r\n LockCondition(self, Queue.new())\r\n }\r\n \r\n acquire(): Unit {\r\n if(self.level == 0 || self.owner === Js.currentTask()!) {\r\n self.owner = Js.currentTask()!\r\n self.level += 1\r\n } else {\r\n Js.awaitCancellablePromise {resolve, reject, onSettle =>\r\n let key = self.queue.push(Pair(Js.currentTask()!, resolve))\r\n onSettle {_ => self.queue.remove(key)}\r\n }\r\n }\r\n }\r\n \r\n release(): Unit {\r\n if(self.owner !== Js.currentTask()!) {\r\n throw(GrabException)\r\n } elseIf {self.level > 1} {\r\n self.level -= 1\r\n } else {\r\n self.owner = Js.undefined()\r\n self.level = 0\r\n if(!self.queue.isEmpty()) {\r\n let pending = self.queue.pop().grab()\r\n self.owner = pending.first\r\n self.level = 1\r\n pending.second(Unit)\r\n }\r\n }\r\n }\r\n \r\n do[T](body: () => T): T {\r\n self.acquire()\r\n try {\r\n body()\r\n } finally {\r\n self.release()\r\n }\r\n }\r\n\r\n}\r\n\r\nextend self: LockCondition {\r\n\r\n sleep(): Unit {\r\n if(self.lock.owner !== Js.currentTask()!) {\r\n throw(GrabException)\r\n }\r\n Js.throwIfCancelled()\r\n let level = self.lock.level\r\n self.lock.level = 1\r\n self.lock.release()\r\n try {\r\n Js.awaitCancellablePromise {resolve, reject, onSettle =>\r\n let key = self.queue.push(resolve)\r\n onSettle {_ => self.queue.remove(key)}\r\n }\r\n } finally {\r\n mutable error = Js.undefined()\r\n mutable acquired = False\r\n while {!acquired} {\r\n try {\r\n self.lock.acquire()\r\n self.lock.level = level\r\n acquired = True\r\n } catchAny {e =>\r\n error = e!\r\n }\r\n }\r\n if(!error.isUndefined()) {Js.throw(error)}\r\n }\r\n }\r\n\r\n sleepUntil[T](body: () => Option[T]): T {\r\n body().{\r\n | Some(value) =>\r\n value\r\n | None =>\r\n self.sleep()\r\n tailcall self.sleepUntil(body)\r\n }\r\n }\r\n\r\n wakeOne(): Unit {\r\n self.queue.pop().each {resolve => resolve(Unit)}\r\n }\r\n\r\n wakeAll(): Unit {\r\n self.queue.each {_, resolve => resolve(Unit)}\r\n self.queue.clear()\r\n }\r\n\r\n}\r\n"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": [
|
|
4
|
-
"
|
|
4
|
+
"../../../../core/Log.ff"
|
|
5
5
|
],
|
|
6
6
|
"sourcesContent": [
|
|
7
7
|
"show[T: Show](value: T): Unit {\r\n trace(Show.show(value))\r\n}\r\n\r\ndebugDynamic[T](value: T): Unit {\r\n Js->console->debug(value!)\r\n}\r\n\r\ndebug(value: String): Unit {\r\n Js->console->debug(value)\r\n}\r\n\r\nverbose(value: String): Unit {\r\n Js->console->log(value)\r\n}\r\n\r\ninfo(value: String): Unit {\r\n Js->console->info(value)\r\n}\r\n\r\nwarn(value: String): Unit {\r\n Js->console->warn(value)\r\n}\r\n\r\nerror(value: Error): Unit {\r\n Js->console->error(value)\r\n}\r\n\r\ntrace(value: String): Unit {\r\n if(Js.inBrowser()) {\r\n Js->console->debug(value)\r\n } else {\r\n Js->process->stderr->write(value + \"\\n\")\r\n }\r\n}\r\n"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": [
|
|
4
|
-
"
|
|
4
|
+
"../../../../core/Map.ff"
|
|
5
5
|
],
|
|
6
6
|
"sourcesContent": [
|
|
7
7
|
"import RbMap\r\n\r\nnewtype Map[K, V](redBlack: RB[K, V])\r\n\r\nnew[K, V](): Map[K, V] {Map(E)}\r\n\r\nextend self[K: Order, V]: Map[K, V] {\r\n\r\n add(key: K, value: V): Map[K, V] {\r\n Map(RbMap.insert(key, value, self.redBlack))\r\n }\r\n\r\n addAll(that: Map[K, V]): Map[K, V] {\r\n mutable result = self.redBlack\r\n that.redBlack.each {k, v =>\r\n result = RbMap.insert(k, v, result)\r\n }\r\n Map(result)\r\n }\r\n\r\n addList(that: List[Pair[K, V]]): Map[K, V] {\r\n mutable result = self.redBlack\r\n that.each {| Pair(k, v) =>\r\n result = RbMap.insert(k, v, result)\r\n }\r\n Map(result)\r\n }\r\n\r\n get(key: K): Option[V] {\r\n self.redBlack.get(key)\r\n }\r\n \r\n first(): Option[Pair[K, V]] {\r\n self.redBlack.first()\r\n }\r\n\r\n last(): Option[Pair[K, V]] {\r\n self.redBlack.last()\r\n }\r\n\r\n lastBefore(key: K): Option[Pair[K, V]] {\r\n self.redBlack.lastBefore(key)\r\n }\r\n \r\n firstAfter(key: K): Option[Pair[K, V]] {\r\n self.redBlack.firstAfter(key)\r\n }\r\n\r\n remove(key: K): Map[K, V] {\r\n Map(RbMap.delete(key, self.redBlack))\r\n }\r\n\r\n removeAll(that: Map[K, V]): Map[K, V] {\r\n mutable result = self.redBlack\r\n that.redBlack.each {| k, _ =>\r\n result = RbMap.delete(k, result)\r\n }\r\n Map(result)\r\n }\r\n \r\n removeList(keys: List[K]): Map[K, V] {\r\n mutable result = self.redBlack\r\n keys.each {k =>\r\n result = RbMap.delete(k, result)\r\n }\r\n Map(result)\r\n }\r\n\r\n pairs(): List[Pair[K, V]] { // TODO: Remove this method (use toList)\r\n self.toList()\r\n }\r\n\r\n toList(): List[Pair[K, V]] {\r\n self.redBlack.pairs()\r\n }\r\n\r\n toStream(cycle: Bool = False): Stream[Pair[K, V]] {\r\n self.redBlack.toStream(cycle)\r\n }\r\n\r\n keys(): Set[K] {\r\n self.pairs().map {_.first}.toSet()\r\n }\r\n\r\n values(): List[V] {\r\n self.pairs().map {_.second}\r\n }\r\n\r\n size(): Int {\r\n self.redBlack.size()\r\n }\r\n\r\n map[K1: Order, V1](body: (K, V) => Pair[K1, V1]): Map[K1, V1] {\r\n Map(self.redBlack.map(body))\r\n }\r\n\r\n mapValues[V1](body: (K, V) => V1): Map[K, V1] {\r\n Map(self.redBlack.mapValues(body))\r\n }\r\n\r\n contains(key: K): Bool {\r\n !self.get(key).isEmpty()\r\n }\r\n\r\n grab(key: K): V {\r\n self.get(key).grab()\r\n }\r\n\r\n updateOrInsert(key: K, update: V => V, default: () => V): Map[K, V] {\r\n self.get(key).{\r\n | None => self.add(key, default())\r\n | Some(v) => self.add(key, update(v))\r\n }\r\n }\r\n\r\n each(body: (K, V) => Unit): Unit {\r\n self.redBlack.each(body)\r\n }\r\n\r\n eachWhile(body: (K, V) => Bool): Bool {\r\n self.redBlack.eachWhile(body)\r\n }\r\n\r\n find(body: (K, V) => Bool): Option[Pair[K, V]] {\r\n self.redBlack.find(body)\r\n }\r\n\r\n}\r\n\r\nextend self[K: Order, V]: Map[K, List[V]] {\r\n\r\n addToList(key: K, value: V): Map[K, List[V]] {\r\n self.updateOrInsert(key, {[value, ..._]}, {[value]})\r\n }\r\n\r\n}\r\n\r\nextend self[K: Order, V]: Map[K, Array[V]] {\r\n\r\n push(key: K, value: V): Map[K, Array[V]] {\r\n self.get(key).{\r\n | None => self.add(key, [value].toArray())\r\n | Some(array) => array.push(value); self\r\n }\r\n }\r\n\r\n}\r\n\r\ninstance Map[K: Equal: Order, V: Equal]: Equal {\r\n equals(x: Map[K, V], y: Map[K, V]): Bool {\r\n Equal.equals(x.pairs(), y.pairs())\r\n }\r\n}\r\n\r\ninstance Map[K: Order, V: Order]: Order {\r\n compare(x: Map[K, V], y: Map[K, V]): Ordering {\r\n Ordering.compare(x.pairs(), y.pairs())\r\n }\r\n}\r\n\r\ninstance Map[K: Show: Order, V: Show]: Show {\r\n show(value: Map[K, V]): String {\r\n Show.show(value.pairs()) + \".toMap()\"\r\n }\r\n}\r\n"
|
|
@@ -213,7 +213,7 @@ return process.exit(exitCode_)
|
|
|
213
213
|
export function NodeSystem_readStream(self_) {
|
|
214
214
|
return ff_core_Path.internalReadStream_((() => {
|
|
215
215
|
return process.stdin
|
|
216
|
-
}))
|
|
216
|
+
}), true)
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
export function NodeSystem_writeBuffer(self_, buffer_) {
|
|
@@ -260,7 +260,8 @@ result_ = ff_core_Map.Map_add(result_, key_, process.env[key_], ff_core_Ordering
|
|
|
260
260
|
return result_
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
-
export function NodeSystem_execute(self_, command_, arguments_, standardIn_ = ff_core_Buffer.new_(0), directory_ = ff_core_Option.None(), environment_ = ff_core_Option.None(), maxBuffer_ = 16777216, killSignal_ = 9, shell_ = false) {
|
|
263
|
+
export function NodeSystem_execute(self_, command_, arguments_, standardIn_ = ff_core_Buffer.new_(0), directory_ = ff_core_Option.None(), environment_ = ff_core_Option.None(), maxBuffer_ = 16777216, killSignal_ = 9, shell_ = false, node_ = ff_core_Option.None()) {
|
|
264
|
+
const inheritStdio_ = (!ff_core_Option.Option_isEmpty(node_));
|
|
264
265
|
const childProcess_ = import$3;
|
|
265
266
|
const env_ = ff_core_Option.Option_else(ff_core_Option.Option_map(environment_, ((e_) => {
|
|
266
267
|
const o_ = {};
|
|
@@ -273,14 +274,29 @@ return process.env
|
|
|
273
274
|
}));
|
|
274
275
|
return ff_core_Js.withSignal_(((signal_) => {
|
|
275
276
|
return ff_core_Js.awaitCancellablePromise_(((resolve_, reject_, onSettle_) => {
|
|
276
|
-
const newProcess_ =
|
|
277
|
+
const newProcess_ = ((!ff_core_Option.Option_isEmpty(node_))
|
|
278
|
+
? (function() {
|
|
279
|
+
const p_ = childProcess_.fork(command_, arguments_, {cwd: ff_core_Option.Option_else(ff_core_Option.Option_map(directory_, ((_w1) => {
|
|
280
|
+
return _w1.absolutePath_
|
|
281
|
+
})), (() => {
|
|
282
|
+
return (void 0)
|
|
283
|
+
})), signal: signal_, killSignal: killSignal_, env: env_, silent: true, stdio: (inheritStdio_
|
|
284
|
+
? "inherit"
|
|
285
|
+
: "pipe")});
|
|
286
|
+
p_.on("message", ((message_) => {
|
|
287
|
+
return ff_core_Option.Option_grab(node_)(message_, p_)
|
|
288
|
+
}));
|
|
289
|
+
return p_
|
|
290
|
+
})()
|
|
291
|
+
: childProcess_.spawn(command_, arguments_, {cwd: ff_core_Option.Option_else(ff_core_Option.Option_map(directory_, ((_w1) => {
|
|
277
292
|
return _w1.absolutePath_
|
|
278
293
|
})), (() => {
|
|
279
294
|
return (void 0)
|
|
280
|
-
})), windowsHide: true, signal: signal_, killSignal: killSignal_, env: env_, shell: shell_});
|
|
295
|
+
})), windowsHide: true, signal: signal_, killSignal: killSignal_, env: env_, shell: shell_}));
|
|
281
296
|
let size_ = 0;
|
|
282
297
|
const out_ = ff_core_Array.new_();
|
|
283
298
|
const err_ = ff_core_Array.new_();
|
|
299
|
+
if((!inheritStdio_)) {
|
|
284
300
|
newProcess_.stdout.on("data", ((data_) => {
|
|
285
301
|
if((size_ <= maxBuffer_)) {
|
|
286
302
|
size_ += data_.byteLength;
|
|
@@ -304,7 +320,8 @@ err_.array.push(data_)
|
|
|
304
320
|
if((standardIn_.byteLength !== 0)) {
|
|
305
321
|
newProcess_.stdin.write(standardIn_)
|
|
306
322
|
};
|
|
307
|
-
newProcess_.stdin.end()
|
|
323
|
+
newProcess_.stdin.end()
|
|
324
|
+
};
|
|
308
325
|
newProcess_.on("error", ((error_) => {
|
|
309
326
|
if((size_ > maxBuffer_)) {
|
|
310
327
|
return reject_(ff_core_NodeSystem.internalProcessError_("maxBuffer exceeded"))
|
|
@@ -396,7 +413,7 @@ return process.exit(exitCode_)
|
|
|
396
413
|
export async function NodeSystem_readStream$(self_, $task) {
|
|
397
414
|
return (await ff_core_Path.internalReadStream_$((async ($task) => {
|
|
398
415
|
return process.stdin
|
|
399
|
-
}), $task))
|
|
416
|
+
}), true, $task))
|
|
400
417
|
}
|
|
401
418
|
|
|
402
419
|
export async function NodeSystem_writeBuffer$(self_, buffer_, $task) {
|
|
@@ -443,7 +460,8 @@ result_ = ff_core_Map.Map_add(result_, key_, process.env[key_], ff_core_Ordering
|
|
|
443
460
|
return result_
|
|
444
461
|
}
|
|
445
462
|
|
|
446
|
-
export async function NodeSystem_execute$(self_, command_, arguments_, standardIn_ = ff_core_Buffer.new_(0), directory_ = ff_core_Option.None(), environment_ = ff_core_Option.None(), maxBuffer_ = 16777216, killSignal_ = 9, shell_ = false, $task) {
|
|
463
|
+
export async function NodeSystem_execute$(self_, command_, arguments_, standardIn_ = ff_core_Buffer.new_(0), directory_ = ff_core_Option.None(), environment_ = ff_core_Option.None(), maxBuffer_ = 16777216, killSignal_ = 9, shell_ = false, node_ = ff_core_Option.None(), $task) {
|
|
464
|
+
const inheritStdio_ = (!ff_core_Option.Option_isEmpty(node_));
|
|
447
465
|
const childProcess_ = import$3;
|
|
448
466
|
const env_ = ff_core_Option.Option_else(ff_core_Option.Option_map(environment_, ((e_) => {
|
|
449
467
|
const o_ = {};
|
|
@@ -455,15 +473,30 @@ return o_
|
|
|
455
473
|
return process.env
|
|
456
474
|
}));
|
|
457
475
|
return (await ff_core_Js.withSignal_$((async (signal_, $task) => {
|
|
458
|
-
return (await ff_core_Js.awaitCancellablePromise_$(((resolve_, reject_, onSettle_) => {
|
|
459
|
-
const newProcess_ =
|
|
476
|
+
return (await ff_core_Js.awaitCancellablePromise_$((async (resolve_, reject_, onSettle_, $task) => {
|
|
477
|
+
const newProcess_ = ((!ff_core_Option.Option_isEmpty(node_))
|
|
478
|
+
? (await (async function() {
|
|
479
|
+
const p_ = childProcess_.fork(command_, arguments_, {cwd: ff_core_Option.Option_else(ff_core_Option.Option_map(directory_, ((_w1) => {
|
|
460
480
|
return _w1.absolutePath_
|
|
461
481
|
})), (() => {
|
|
462
482
|
return (void 0)
|
|
463
|
-
})),
|
|
483
|
+
})), signal: signal_, killSignal: killSignal_, env: env_, silent: true, stdio: (inheritStdio_
|
|
484
|
+
? "inherit"
|
|
485
|
+
: "pipe")});
|
|
486
|
+
p_.on("message", (async (a_1) => await (async (message_, $task) => {
|
|
487
|
+
return (await ff_core_Option.Option_grab(node_)(message_, p_, $task))
|
|
488
|
+
})(a_1, $task)));
|
|
489
|
+
return p_
|
|
490
|
+
})())
|
|
491
|
+
: childProcess_.spawn(command_, arguments_, {cwd: ff_core_Option.Option_else(ff_core_Option.Option_map(directory_, ((_w1) => {
|
|
492
|
+
return _w1.absolutePath_
|
|
493
|
+
})), (() => {
|
|
494
|
+
return (void 0)
|
|
495
|
+
})), windowsHide: true, signal: signal_, killSignal: killSignal_, env: env_, shell: shell_}));
|
|
464
496
|
let size_ = 0;
|
|
465
497
|
const out_ = ff_core_Array.new_();
|
|
466
498
|
const err_ = ff_core_Array.new_();
|
|
499
|
+
if((!inheritStdio_)) {
|
|
467
500
|
newProcess_.stdout.on("data", ((data_) => {
|
|
468
501
|
if((size_ <= maxBuffer_)) {
|
|
469
502
|
size_ += data_.byteLength;
|
|
@@ -487,24 +520,25 @@ err_.array.push(data_)
|
|
|
487
520
|
if((standardIn_.byteLength !== 0)) {
|
|
488
521
|
newProcess_.stdin.write(standardIn_)
|
|
489
522
|
};
|
|
490
|
-
newProcess_.stdin.end()
|
|
491
|
-
|
|
523
|
+
newProcess_.stdin.end()
|
|
524
|
+
};
|
|
525
|
+
newProcess_.on("error", (async (a_1) => await (async (error_, $task) => {
|
|
492
526
|
if((size_ > maxBuffer_)) {
|
|
493
|
-
return reject_(ff_core_NodeSystem.internalProcessError_("maxBuffer exceeded"))
|
|
527
|
+
return (await reject_(ff_core_NodeSystem.internalProcessError_("maxBuffer exceeded"), $task))
|
|
494
528
|
} else {
|
|
495
|
-
reject_(ff_core_NodeSystem.internalProcessError_(error_.message))
|
|
529
|
+
(await reject_(ff_core_NodeSystem.internalProcessError_(error_.message), $task))
|
|
496
530
|
}
|
|
497
|
-
}));
|
|
498
|
-
newProcess_.on("close", ((code_) => {
|
|
531
|
+
})(a_1, $task)));
|
|
532
|
+
newProcess_.on("close", (async (a_1) => await (async (code_, $task) => {
|
|
499
533
|
const o_ = Buffer.concat(ff_core_Array.Array_drain(out_));
|
|
500
534
|
const e_ = Buffer.concat(ff_core_Array.Array_drain(err_));
|
|
501
|
-
return resolve_(ff_core_NodeSystem.ProcessResult(code_, (new DataView(o_.buffer, o_.byteOffset, o_.byteLength)), (new DataView(e_.buffer, e_.byteOffset, e_.byteLength))))
|
|
502
|
-
}));
|
|
503
|
-
onSettle_(((fulfilled_) => {
|
|
535
|
+
return (await resolve_(ff_core_NodeSystem.ProcessResult(code_, (new DataView(o_.buffer, o_.byteOffset, o_.byteLength)), (new DataView(e_.buffer, e_.byteOffset, e_.byteLength))), $task))
|
|
536
|
+
})(a_1, $task)));
|
|
537
|
+
(await onSettle_((async (fulfilled_, $task) => {
|
|
504
538
|
if((!fulfilled_)) {
|
|
505
539
|
newProcess_.kill(killSignal_)
|
|
506
540
|
}
|
|
507
|
-
}))
|
|
541
|
+
}), $task))
|
|
508
542
|
}), $task))
|
|
509
543
|
}), $task))
|
|
510
544
|
}
|