firefly-compiler 0.5.35 → 0.5.37

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.
Files changed (225) hide show
  1. package/.hintrc +4 -4
  2. package/.vscode/settings.json +4 -4
  3. package/bin/Release.ff +157 -154
  4. package/bin/firefly.mjs +1 -1
  5. package/compiler/Builder.ff +275 -277
  6. package/compiler/Compiler.ff +234 -233
  7. package/compiler/Dependencies.ff +186 -187
  8. package/compiler/DependencyLock.ff +17 -17
  9. package/compiler/Deriver.ff +23 -31
  10. package/compiler/Dictionaries.ff +1 -1
  11. package/compiler/Inference.ff +43 -20
  12. package/compiler/JsEmitter.ff +1437 -1282
  13. package/compiler/LspHook.ff +202 -202
  14. package/compiler/Main.ff +25 -24
  15. package/compiler/ModuleCache.ff +178 -178
  16. package/compiler/Parser.ff +36 -109
  17. package/compiler/Resolver.ff +5 -8
  18. package/compiler/Substitution.ff +1 -1
  19. package/compiler/Syntax.ff +1 -16
  20. package/compiler/Token.ff +9 -0
  21. package/compiler/Tokenizer.ff +4 -0
  22. package/compiler/Workspace.ff +88 -88
  23. package/core/.firefly/include/package.json +5 -5
  24. package/core/.firefly/package.ff +2 -2
  25. package/core/Any.ff +26 -30
  26. package/core/Array.ff +298 -265
  27. package/core/Atomic.ff +63 -64
  28. package/core/Box.ff +7 -7
  29. package/core/BrowserSystem.ff +40 -40
  30. package/core/Buffer.ff +185 -152
  31. package/core/BuildSystem.ff +156 -148
  32. package/core/Channel.ff +95 -92
  33. package/core/Char.ff +3 -2
  34. package/core/Core.ff +16 -23
  35. package/core/Crypto.ff +94 -96
  36. package/core/Equal.ff +41 -36
  37. package/core/Error.ff +15 -10
  38. package/core/FileHandle.ff +45 -37
  39. package/core/Float.ff +176 -200
  40. package/core/HttpClient.ff +142 -148
  41. package/core/Instant.ff +6 -8
  42. package/core/Int.ff +40 -24
  43. package/core/IntMap.ff +61 -39
  44. package/core/Js.ff +305 -0
  45. package/core/JsSystem.ff +135 -114
  46. package/core/JsValue.ff +303 -159
  47. package/core/Json.ff +423 -443
  48. package/core/List.ff +482 -486
  49. package/core/Lock.ff +108 -144
  50. package/core/Log.ff +25 -14
  51. package/core/NodeSystem.ff +198 -191
  52. package/core/Ordering.ff +160 -161
  53. package/core/Path.ff +377 -409
  54. package/core/Queue.ff +90 -0
  55. package/core/Random.ff +140 -134
  56. package/core/RbMap.ff +216 -216
  57. package/core/Serializable.ff +16 -13
  58. package/core/Show.ff +44 -43
  59. package/core/SourceLocation.ff +68 -68
  60. package/core/Stream.ff +1 -1
  61. package/core/String.ff +224 -202
  62. package/core/StringMap.ff +58 -36
  63. package/core/Task.ff +165 -149
  64. package/experimental/benchmarks/ListGrab.ff +23 -23
  65. package/experimental/benchmarks/ListGrab.java +55 -55
  66. package/experimental/benchmarks/Pyrotek45.ff +30 -30
  67. package/experimental/benchmarks/Pyrotek45.java +64 -64
  68. package/experimental/bidirectional/Bidi.ff +88 -88
  69. package/experimental/lines/Main.ff +40 -0
  70. package/experimental/random/Index.ff +53 -53
  71. package/experimental/random/Process.ff +120 -120
  72. package/experimental/random/RunLength.ff +65 -65
  73. package/experimental/random/Scrape.ff +51 -51
  74. package/experimental/random/Symbols.ff +73 -73
  75. package/experimental/random/Tensor.ff +52 -52
  76. package/experimental/random/Units.ff +36 -36
  77. package/experimental/s3/S3TestAuthorizationHeader.ff +39 -39
  78. package/experimental/s3/S3TestPut.ff +16 -16
  79. package/experimental/tests/TestJson.ff +26 -26
  80. package/firefly.sh +0 -0
  81. package/fireflysite/.firefly/package.ff +4 -4
  82. package/fireflysite/CommunityOverview.ff +20 -20
  83. package/fireflysite/CountingButtonDemo.ff +58 -58
  84. package/fireflysite/DocumentParser.ff +325 -331
  85. package/fireflysite/ExamplesOverview.ff +40 -40
  86. package/fireflysite/FrontPage.ff +344 -344
  87. package/fireflysite/GettingStarted.ff +45 -45
  88. package/fireflysite/Guide.ff +456 -456
  89. package/fireflysite/Main.ff +163 -152
  90. package/fireflysite/MatchingPasswordsDemo.ff +82 -82
  91. package/fireflysite/PackagesOverview.ff +49 -49
  92. package/fireflysite/PostgresqlDemo.ff +34 -34
  93. package/fireflysite/ReferenceAll.ff +18 -18
  94. package/fireflysite/ReferenceIntroduction.ff +11 -11
  95. package/fireflysite/Styles.ff +567 -567
  96. package/fireflysite/Test.ff +121 -62
  97. package/fireflysite/assets/markdown/reference/BaseTypes.md +209 -209
  98. package/fireflysite/assets/markdown/reference/EmittedJavascript.md +65 -65
  99. package/fireflysite/assets/markdown/reference/Exceptions.md +101 -101
  100. package/fireflysite/assets/markdown/reference/FunctionsAndMethods.md +364 -364
  101. package/fireflysite/assets/markdown/reference/JavascriptInterop.md +235 -172
  102. package/fireflysite/assets/markdown/reference/ModulesAndPackages.md +162 -162
  103. package/fireflysite/assets/markdown/reference/OldStructuredConcurrency.md +48 -48
  104. package/fireflysite/assets/markdown/reference/PatternMatching.md +224 -224
  105. package/fireflysite/assets/markdown/reference/StatementsAndExpressions.md +86 -86
  106. package/fireflysite/assets/markdown/reference/StructuredConcurrency.md +99 -99
  107. package/fireflysite/assets/markdown/reference/TraitsAndInstances.md +100 -100
  108. package/fireflysite/assets/markdown/reference/UserDefinedTypes.md +184 -184
  109. package/fireflysite/assets/markdown/scratch/ControlFlow.md +136 -136
  110. package/fireflysite/assets/markdown/scratch/Toc.md +40 -40
  111. package/lsp/.firefly/package.ff +1 -1
  112. package/lsp/CompletionHandler.ff +827 -827
  113. package/lsp/Handler.ff +714 -714
  114. package/lsp/HoverHandler.ff +79 -79
  115. package/lsp/LanguageServer.ff +272 -272
  116. package/lsp/SignatureHelpHandler.ff +55 -55
  117. package/lsp/SymbolHandler.ff +181 -181
  118. package/lsp/TestReferences.ff +17 -17
  119. package/lsp/TestReferencesCase.ff +7 -7
  120. package/lsp/stderr.txt +1 -1
  121. package/lsp/stdout.txt +34 -34
  122. package/lux/.firefly/package.ff +1 -1
  123. package/lux/Css.ff +648 -648
  124. package/lux/CssTest.ff +48 -48
  125. package/lux/Lux.ff +608 -617
  126. package/lux/LuxEvent.ff +79 -116
  127. package/lux/Main.ff +123 -123
  128. package/lux/Main2.ff +143 -143
  129. package/lux/TestDry.ff +28 -28
  130. package/output/js/ff/compiler/Builder.mjs +72 -71
  131. package/output/js/ff/compiler/Compiler.mjs +19 -13
  132. package/output/js/ff/compiler/Dependencies.mjs +8 -7
  133. package/output/js/ff/compiler/DependencyLock.mjs +6 -4
  134. package/output/js/ff/compiler/Deriver.mjs +26 -24
  135. package/output/js/ff/compiler/Dictionaries.mjs +14 -18
  136. package/output/js/ff/compiler/Environment.mjs +6 -4
  137. package/output/js/ff/compiler/Inference.mjs +238 -164
  138. package/output/js/ff/compiler/JsEmitter.mjs +1160 -350
  139. package/output/js/ff/compiler/JsImporter.mjs +20 -18
  140. package/output/js/ff/compiler/LspHook.mjs +12 -10
  141. package/output/js/ff/compiler/Main.mjs +61 -41
  142. package/output/js/ff/compiler/ModuleCache.mjs +10 -8
  143. package/output/js/ff/compiler/Parser.mjs +153 -669
  144. package/output/js/ff/compiler/Patterns.mjs +12 -10
  145. package/output/js/ff/compiler/Resolver.mjs +52 -78
  146. package/output/js/ff/compiler/Substitution.mjs +12 -16
  147. package/output/js/ff/compiler/Syntax.mjs +50 -341
  148. package/output/js/ff/compiler/Token.mjs +126 -4
  149. package/output/js/ff/compiler/Tokenizer.mjs +62 -52
  150. package/output/js/ff/compiler/Unification.mjs +74 -90
  151. package/output/js/ff/compiler/Wildcards.mjs +4 -2
  152. package/output/js/ff/compiler/Workspace.mjs +26 -20
  153. package/output/js/ff/core/Any.mjs +20 -20
  154. package/output/js/ff/core/Array.mjs +268 -175
  155. package/output/js/ff/core/AssetSystem.mjs +8 -6
  156. package/output/js/ff/core/Atomic.mjs +84 -52
  157. package/output/js/ff/core/Bool.mjs +6 -4
  158. package/output/js/ff/core/BrowserSystem.mjs +38 -29
  159. package/output/js/ff/core/Buffer.mjs +285 -133
  160. package/output/js/ff/core/BuildSystem.mjs +36 -56
  161. package/output/js/ff/core/Channel.mjs +250 -97
  162. package/output/js/ff/core/Char.mjs +5 -3
  163. package/output/js/ff/core/Core.mjs +28 -34
  164. package/output/js/ff/core/Crypto.mjs +30 -52
  165. package/output/js/ff/core/Duration.mjs +4 -2
  166. package/output/js/ff/core/Equal.mjs +14 -12
  167. package/output/js/ff/core/Error.mjs +17 -11
  168. package/output/js/ff/core/FileHandle.mjs +76 -38
  169. package/output/js/ff/core/Float.mjs +92 -160
  170. package/output/js/ff/core/HttpClient.mjs +208 -76
  171. package/output/js/ff/core/Instant.mjs +8 -10
  172. package/output/js/ff/core/Int.mjs +36 -26
  173. package/output/js/ff/core/IntMap.mjs +79 -33
  174. package/output/js/ff/core/Js.mjs +751 -0
  175. package/output/js/ff/core/JsSystem.mjs +54 -60
  176. package/output/js/ff/core/JsValue.mjs +294 -143
  177. package/output/js/ff/core/Json.mjs +443 -253
  178. package/output/js/ff/core/List.mjs +262 -214
  179. package/output/js/ff/core/Lock.mjs +156 -125
  180. package/output/js/ff/core/Log.mjs +20 -10
  181. package/output/js/ff/core/Map.mjs +10 -8
  182. package/output/js/ff/core/NodeSystem.mjs +189 -123
  183. package/output/js/ff/core/Nothing.mjs +4 -2
  184. package/output/js/ff/core/Option.mjs +40 -38
  185. package/output/js/ff/core/Ordering.mjs +26 -20
  186. package/output/js/ff/core/Pair.mjs +4 -2
  187. package/output/js/ff/core/Path.mjs +517 -315
  188. package/output/js/ff/core/Queue.mjs +306 -0
  189. package/output/js/ff/core/Random.mjs +141 -77
  190. package/output/js/ff/core/RbMap.mjs +36 -34
  191. package/output/js/ff/core/Serializable.mjs +44 -28
  192. package/output/js/ff/core/Set.mjs +6 -4
  193. package/output/js/ff/core/Show.mjs +8 -6
  194. package/output/js/ff/core/SourceLocation.mjs +4 -2
  195. package/output/js/ff/core/Stream.mjs +30 -50
  196. package/output/js/ff/core/String.mjs +263 -172
  197. package/output/js/ff/core/StringMap.mjs +77 -31
  198. package/output/js/ff/core/Task.mjs +91 -76
  199. package/output/js/ff/core/Try.mjs +20 -18
  200. package/output/js/ff/core/Unit.mjs +4 -2
  201. package/package.json +1 -1
  202. package/postgresql/Pg.ff +53 -59
  203. package/rpc/.firefly/package.ff +1 -1
  204. package/rpc/Rpc.ff +70 -70
  205. package/s3/.firefly/package.ff +1 -1
  206. package/s3/S3.ff +92 -94
  207. package/vscode/LICENSE.txt +21 -21
  208. package/vscode/Prepublish.ff +15 -15
  209. package/vscode/README.md +16 -16
  210. package/vscode/client/package-lock.json +544 -544
  211. package/vscode/client/package.json +22 -22
  212. package/vscode/client/src/extension.ts +104 -104
  213. package/vscode/icons/firefly-icon.svg +10 -10
  214. package/vscode/language-configuration.json +61 -61
  215. package/vscode/package-lock.json +3623 -3623
  216. package/vscode/package.json +1 -1
  217. package/vscode/snippets.json +241 -241
  218. package/vscode/syntaxes/firefly-markdown-injection.json +45 -45
  219. package/webserver/.firefly/include/package.json +5 -5
  220. package/webserver/.firefly/package.ff +2 -2
  221. package/webserver/WebServer.ff +647 -685
  222. package/websocket/.firefly/package.ff +1 -1
  223. package/websocket/WebSocket.ff +100 -131
  224. package/core/UnsafeJs.ff +0 -42
  225. package/output/js/ff/core/UnsafeJs.mjs +0 -191
@@ -1,148 +1,142 @@
1
- capability HttpClient {}
2
- capability FetchBody {}
3
- capability FetchResponse {}
4
- data FetchRedirect {
5
- RedirectFollow
6
- RedirectError
7
- RedirectManual
8
- }
9
- data FetchOptions(
10
- redirect: FetchRedirect = RedirectFollow
11
- referrer: Option[String] = None
12
- integrity: Option[String] = None
13
- mode: Option[String] = None
14
- credentials: Option[String] = None
15
- cache: Option[String] = None
16
- )
17
-
18
- extend self: HttpClient {
19
-
20
- get[T](
21
- url: String
22
- headers: List[Pair[String, String]]
23
- body: FetchResponse => T
24
- ): T {
25
- self.fetch("GET", url, headers, None, FetchOptions(), body)
26
- }
27
-
28
- post[T](
29
- url: String
30
- headers: List[Pair[String, String]]
31
- payload: Buffer
32
- body: FetchResponse => T
33
- ): T {
34
- self.fetch("POST", url, headers, Some(payload), FetchOptions(), body)
35
- }
36
-
37
- put[T](
38
- url: String
39
- headers: List[Pair[String, String]]
40
- payload: Buffer
41
- body: FetchResponse => T
42
- ): T {
43
- self.fetch("PUT", url, headers, Some(payload), FetchOptions(), body)
44
- }
45
-
46
- delete[T](
47
- url: String
48
- headers: List[Pair[String, String]]
49
- body: FetchResponse => T
50
- ): T {
51
- self.fetch("DELETE", url, headers, None, FetchOptions(), body)
52
- }
53
-
54
- fetch[T](
55
- method: String
56
- url: String
57
- headers: List[Pair[String, String]] = []
58
- payload: Option[Buffer] = None
59
- options: FetchOptions = FetchOptions()
60
- body: FetchResponse => T
61
- ): T
62
- target js async """
63
- const fetchResponse = {response: null, statusChecked: false};
64
- try {
65
- const options = {headers: {}, signal: $task.controller.signal};
66
- options.method = method_;
67
- headers_.forEach(pair => {options.headers[pair.first_] = pair.second_});
68
- if(payload_.value_) options.body = payload_.value_;
69
- if(options_.redirect_.RedirectError) options.redirect = "error";
70
- else if(options_.redirect_.RedirectManual) options.redirect = "manual";
71
- if(options_.referrer_.value_) options.referrer = options_.referrer_.value_;
72
- if(options_.integrity_.value_) options.integrity = options_.integrity_.value_;
73
- if(options_.mode_.value_) options.mode = options_.mode_.value_;
74
- if(options_.credentials_.value_) options.credentials = options_.credentials_.value_;
75
- if(options_.cache_.value_) options.cache = options_.cache_.value_;
76
- fetchResponse.response = await self_.fetch(url_, options);
77
- const result = await body_(fetchResponse, $task);
78
- internalCheck_(fetchResponse);
79
- return result;
80
- } finally {
81
- fetchResponse.response = null;
82
- if($task.controller.signal.aborted) $task.controller = new AbortController()
83
- }
84
- """
85
-
86
- }
87
-
88
- extend self: FetchResponse {
89
-
90
- ok(): Bool
91
- target js async """
92
- self_.statusChecked = true;
93
- internalCheck_(self_);
94
- return self_.response.ok;
95
- """
96
-
97
- status(): Int
98
- target js async """
99
- self_.statusChecked = true;
100
- internalCheck_(self_);
101
- return self_.response.status;
102
- """
103
-
104
- statusText(): String
105
- target js async """
106
- self_.statusChecked = true;
107
- internalCheck_(self_);
108
- return self_.response.statusText;
109
- """
110
-
111
- header(name: String): Option[String]
112
- target js async """
113
- internalCheck_(self_);
114
- const header = self_.response.headers.get(name_);
115
- return header != null
116
- ? ff_core_Option.Some(header)
117
- : ff_core_Option.None();
118
- """
119
-
120
- readText(): String
121
- target js async """
122
- internalCheck_(self_);
123
- return await self_.response.text();
124
- """
125
-
126
- readJson(): Json
127
- target js async """
128
- internalCheck_(self_);
129
- return await self_.response.json();
130
- """
131
-
132
- readBuffer(): Buffer
133
- target js async """
134
- internalCheck_(self_);
135
- return new DataView(await self_.response.arrayBuffer());
136
- """
137
-
138
- }
139
-
140
- internalCheck(fetchResponse: FetchResponse)
141
- target js sync """
142
- if(fetchResponse_.response === null) {
143
- throw new Error("Response closed");
144
- }
145
- if(!fetchResponse_.statusChecked && !fetchResponse_.response.ok) {
146
- throw new Error("Unchecked HTTP status code: " + fetchResponse_.response.status);
147
- }
148
- """
1
+ capability HttpClient {}
2
+ capability FetchBody {}
3
+ capability FetchResponse {}
4
+ data FetchRedirect {
5
+ RedirectFollow
6
+ RedirectError
7
+ RedirectManual
8
+ }
9
+ data FetchOptions(
10
+ redirect: FetchRedirect = RedirectFollow
11
+ referrer: Option[String] = None
12
+ integrity: Option[String] = None
13
+ mode: Option[String] = None
14
+ credentials: Option[String] = None
15
+ cache: Option[String] = None
16
+ )
17
+
18
+ extend self: HttpClient {
19
+
20
+ get[T](
21
+ url: String
22
+ headers: List[Pair[String, String]]
23
+ body: FetchResponse => T
24
+ ): T {
25
+ self.fetch("GET", url, headers, None, FetchOptions(), body)
26
+ }
27
+
28
+ post[T](
29
+ url: String
30
+ headers: List[Pair[String, String]]
31
+ payload: Buffer
32
+ body: FetchResponse => T
33
+ ): T {
34
+ self.fetch("POST", url, headers, Some(payload), FetchOptions(), body)
35
+ }
36
+
37
+ put[T](
38
+ url: String
39
+ headers: List[Pair[String, String]]
40
+ payload: Buffer
41
+ body: FetchResponse => T
42
+ ): T {
43
+ self.fetch("PUT", url, headers, Some(payload), FetchOptions(), body)
44
+ }
45
+
46
+ delete[T](
47
+ url: String
48
+ headers: List[Pair[String, String]]
49
+ body: FetchResponse => T
50
+ ): T {
51
+ self.fetch("DELETE", url, headers, None, FetchOptions(), body)
52
+ }
53
+
54
+ fetch[T](
55
+ method: String
56
+ url: String
57
+ headers: List[Pair[String, String]] = []
58
+ payload: Option[Buffer] = None
59
+ options: FetchOptions = FetchOptions()
60
+ body: FetchResponse => T
61
+ ): T {
62
+ let fetchResponse = Js->(response = Js.null(), statusChecked = False)
63
+ Js.withSignal {signal =>
64
+ try {
65
+ let fetchOptions = Js->(headers = Js->(), signal = signal, method = method)
66
+ headers.each {| Pair(k, v) =>
67
+ fetchOptions->headers.set(k, v)
68
+ }
69
+ payload.each {v => fetchOptions->body = v}
70
+ options.redirect.{
71
+ | RedirectError => fetchOptions->redirect = "error"
72
+ | RedirectFollow =>
73
+ | RedirectManual => fetchOptions->redirect = "manual"
74
+ }
75
+ options.referrer.each {v => fetchOptions->referrer = v}
76
+ options.integrity.each {v => fetchOptions->integrity = v}
77
+ options.mode.each {v => fetchOptions->mode = v}
78
+ options.credentials.each {v => fetchOptions->credentials = v}
79
+ options.cache.each {v => fetchOptions->cache = v}
80
+ fetchResponse->response = Js.await(self!->fetch(url, fetchOptions))
81
+ let result = Js.await(body(fetchResponse?)!)
82
+ internalCheck(fetchResponse?)
83
+ result?
84
+ } finally {
85
+ fetchResponse->response = Js.null()
86
+ }
87
+ }
88
+ }
89
+
90
+ }
91
+
92
+ extend self: FetchResponse {
93
+
94
+ ok(): Bool {
95
+ self!->statusChecked = True
96
+ internalCheck(self)
97
+ self!->response->ok?
98
+ }
99
+
100
+ status(): Int {
101
+ self!->statusChecked = True
102
+ internalCheck(self)
103
+ self!->response->status?
104
+ }
105
+
106
+ statusText(): String {
107
+ self!->statusChecked = True
108
+ internalCheck(self)
109
+ self!->response->statusText?
110
+ }
111
+
112
+ header(name: String): Option[String] {
113
+ internalCheck(self)
114
+ let header = self!->response->headers->get(name)
115
+ if(!header.isNullOrUndefined()) {header?}
116
+ }
117
+
118
+ readText(): String {
119
+ internalCheck(self)
120
+ Js.await(self!->response->text())?
121
+ }
122
+
123
+ readJson(): Json {
124
+ internalCheck(self)
125
+ Js.await(self!->response->json())?
126
+ }
127
+
128
+ readBuffer(): Buffer {
129
+ internalCheck(self)
130
+ Js->DataView->(Js.await(self!->response->arrayBuffer()))?
131
+ }
132
+
133
+ }
134
+
135
+ internalCheck(fetchResponse: FetchResponse) {
136
+ if(fetchResponse!->response.isNull()) {
137
+ Js.throw(Js->Error->("Response closed"))
138
+ }
139
+ if(!fetchResponse!->statusChecked? && !fetchResponse!->response->ok?) {
140
+ Js.throw(Js->Error->("Unchecked HTTP status code: " + fetchResponse!->response->status?))
141
+ }
142
+ }
package/core/Instant.ff CHANGED
@@ -13,14 +13,12 @@ extend self: Instant {
13
13
  Instant(Duration(self.since1970.seconds + duration.seconds))
14
14
  }
15
15
 
16
- toIso(): String
17
- target js sync """
18
- return new Date(self_ * 1000).toISOString();
19
- """
16
+ toIso(): String {
17
+ Js->Date->(self.since1970.seconds * 1000.0)->toISOString()?
18
+ }
20
19
 
21
20
  }
22
21
 
23
- internalParseDate(date: String): Instant
24
- target js sync """
25
- return Date.parse(date_) * 0.001;
26
- """
22
+ internalParseDate(date: String): Instant {
23
+ Instant(Duration(Js->Date->parse(date)? * 0.001))
24
+ }
package/core/Int.ff CHANGED
@@ -2,32 +2,45 @@ data Int {}
2
2
 
3
3
  extend self: Int {
4
4
 
5
- abs(): Int
6
- target js sync "return Math.abs(self_)"
5
+ abs(): Int {
6
+ Js->Math->abs(self)?
7
+ }
7
8
 
8
- toFloat(): Float
9
- target js sync "return self_"
9
+ toFloat(): Float {
10
+ self!?
11
+ }
10
12
 
11
- bitNot(): Int
12
- target js sync "return ~self_;"
13
+ bitNot(): Int {
14
+ Js.unaryOperator("~", self)?
15
+ }
13
16
 
14
- bitOr(that: Int): Int
15
- target js sync "return self_ | that_;"
17
+ bitOr(that: Int): Int {
18
+ Js.binaryOperator("|", self, that)?
19
+ }
16
20
 
17
- bitAnd(that: Int): Int
18
- target js sync "return self_ & that_;"
21
+ bitAnd(that: Int): Int {
22
+ Js.binaryOperator("&", self, that)?
23
+ }
19
24
 
20
- bitXor(that: Int): Int
21
- target js sync "return self_ ^ that_;"
25
+ bitXor(that: Int): Int {
26
+ Js.binaryOperator("^", self, that)?
27
+ }
22
28
 
23
- bitLeft(bits: Int): Int
24
- target js sync "return self_ << bits_;"
29
+ bitLeft(bits: Int): Int {
30
+ Js.binaryOperator("<<", self, bits)?
31
+ }
25
32
 
26
- bitRight(bits: Int, signed: Bool = True): Int
27
- target js sync "return signed_ ? self_ >> bits_ : self_ >>> bits_;"
33
+ bitRight(bits: Int): Int {
34
+ Js.binaryOperator(">>", self, bits)?
35
+ }
28
36
 
29
- bitLeadingZeros(): Int
30
- target js sync "return Math.clz32(self_);"
37
+ bitRightUnsigned(bits: Int): Int {
38
+ Js.binaryOperator(">>>", self, bits)?
39
+ }
40
+
41
+ bitLeadingZeros(): Int {
42
+ Js->Math->clz32(self)?
43
+ }
31
44
 
32
45
  to(inclusiveEnd: Int): List[Int] {
33
46
  let result = Array.new()
@@ -49,14 +62,17 @@ extend self: Int {
49
62
  result.drain()
50
63
  }
51
64
 
52
- min(that: Int): Int
53
- target js sync "return Math.min(self_, that_)"
65
+ min(that: Int): Int {
66
+ Js->Math->min(self, that)?
67
+ }
54
68
 
55
- max(that: Int): Int
56
- target js sync "return Math.max(self_, that_)"
69
+ max(that: Int): Int {
70
+ Js->Math->max(self, that)?
71
+ }
57
72
 
58
- clamp(from: Int, to: Int): Int
59
- target js sync "return Math.min(Math.max(self_, from_), to_)"
73
+ clamp(from: Int, to: Int): Int {
74
+ self.max(from).min(to)
75
+ }
60
76
 
61
77
  pad(padding: String): String {
62
78
  ("" + self).padStart(padding.size(), padding)
package/core/IntMap.ff CHANGED
@@ -1,45 +1,66 @@
1
1
  class IntMap[V] {}
2
2
 
3
- new[V](): IntMap[V]
4
- target js sync "return new Map()"
5
-
3
+ new[V](): IntMap[V] {
4
+ Js->Map->()?
5
+ }
6
+
6
7
  extend self[V]: IntMap[V] {
7
8
 
8
- get(key: Int): Option[V]
9
- target js sync "return self_.has(key_) ? ff_core_Option.Some(self_.get(key_)) : ff_core_Option.None()"
10
-
11
- grab(key: Int): V
12
- target js sync """
13
- const result = self_.get(key_)
14
- if(key_ === void 0 && !self_.has(key_)) {
15
- ff_core_Try.internalThrowGrabException_()
16
- }
17
- return result
18
- """
19
-
20
- set(key: Int, value: V): Unit
21
- target js sync "self_.set(key_, value_)"
22
-
23
- has(key: Int): Bool
24
- target js sync "return self_.has(key_)"
9
+ get(key: Int): Option[V] {
10
+ let result = self!->get(key)
11
+ if(!result.isUndefined() || self!->has(key)?) {result?}
12
+ }
25
13
 
26
- remove(key: Int): Bool
27
- target js sync "return self_.delete(key_)"
14
+ grab(key: Int): V {
15
+ let result = self!->get(key)
16
+ if(result.isUndefined() && !self.has(key)) {throw(GrabException())}
17
+ result?
18
+ }
19
+
20
+ set(key: Int, value: V): Unit {
21
+ self!->set(key, value!)
22
+ }
28
23
 
29
- clear(): Unit
30
- target js sync "self_.clear()"
24
+ has(key: Int): Bool {
25
+ self!->has(key)?
26
+ }
31
27
 
32
- size(): Int
33
- target js sync "return self_.size"
28
+ remove(key: Int): Bool {
29
+ self!->delete(key)?
30
+ }
34
31
 
35
- each(body: (Int, V) => Unit): Bool
36
- target js sync "return self_.forEach((v, k) => body_(k, v))"
37
- target js async "for(const [k, v] of self_) await body_(k, v)"
32
+ clear(): Unit {
33
+ self!->clear()
34
+ }
38
35
 
39
- eachWhile(body: (Int, V) => Bool): Bool
40
- target js sync "for(const [k, v] of self_) if(!body_(k, v)) break"
41
- target js async "for(const [k, v] of self_) if(!await body_(k, v)) break"
36
+ size(): Int {
37
+ self!->size?
38
+ }
39
+
40
+ isEmpty(): Bool {
41
+ self.size() == 0
42
+ }
42
43
 
44
+ each(body: (Int, V) => Unit): Unit {
45
+ if(Js.inAsync()) {
46
+ let iterator = self!->entries()
47
+ mutable result = iterator->next()
48
+ while {!result->done?} {
49
+ let value = result->value
50
+ body(value.get(0)?, value.get(1)?)
51
+ result = iterator->next()
52
+ }
53
+ } else {
54
+ self!->forEach(Js->{v, k => body(k?, v?)})
55
+ }
56
+ }
57
+
58
+ eachWhile(body: (Int, V) => Bool): Unit {
59
+ self!.eachWhile {value =>
60
+ body(value.get(0)?, value.get(1)?)
61
+ }
62
+ }
63
+
43
64
  toArray(): Array[Pair[Int, V]] {
44
65
  let array = Array.new()
45
66
  self.each {k, v => array.push(Pair(k, v))}
@@ -51,7 +72,7 @@ extend self[V]: IntMap[V] {
51
72
  }
52
73
 
53
74
  toStream(): Stream[Pair[Int, V]] {
54
- self.toArray().toStream()
75
+ self.toList().toStream()
55
76
  }
56
77
 
57
78
  toMap(): Map[Int, V] {
@@ -61,23 +82,24 @@ extend self[V]: IntMap[V] {
61
82
  keys(): List[Int] {
62
83
  let array = Array.new()
63
84
  self.each {k, v => array.push(k)}
64
- array.toList()
85
+ array.drain()
65
86
  }
66
87
 
67
88
  values(): List[V] {
68
89
  let array = Array.new()
69
90
  self.each {k, v => array.push(v)}
70
- array.toList()
91
+ array.drain()
92
+ }
93
+
94
+ copy(): IntMap[V] {
95
+ Js->Map->(self!)?
71
96
  }
72
97
 
73
- copy(): IntMap[V]
74
- target js sync "return new Map(self_)"
75
-
76
98
  getOrSet(key: Int, body: () => V): V {
77
99
  if(!self.has(key)) {self.set(key, body())}
78
100
  self.grab(key)
79
101
  }
80
-
102
+
81
103
  }
82
104
 
83
105
  extend self[V]: IntMap[Array[V]] {