firefly-compiler 0.4.83 → 0.4.85

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/core/JsSystem.ff CHANGED
@@ -1,8 +1,8 @@
1
- class JsSystem {} // TODO: It has to be async if the async ffi is to be called - solve in the compiler?
1
+ class JsSystem {}
2
2
 
3
3
  extend self: JsSystem {
4
4
 
5
- global(): JsValue
5
+ globalThis(): JsValue
6
6
  target js sync "return self_"
7
7
 
8
8
  get(key: String): JsValue
@@ -16,6 +16,36 @@ extend self: JsSystem {
16
16
 
17
17
  decrement[V: IsJsValue](key: String, value: V): Unit
18
18
  target js sync "self_[key_] -= value_"
19
+
20
+ call0(name: String): JsValue
21
+ target js sync "return self_[name_].call(void 0)"
22
+
23
+ call1[A1: IsJsValue](name: String, a1: A1): JsValue
24
+ target js sync "return self_[name_].call(void 0, a1_)"
25
+
26
+ call2[A1: IsJsValue, A2: IsJsValue](name: String, a1: A1, a2: A2): JsValue
27
+ target js sync "return self_[name_].call(void 0, a1_, a2_)"
28
+
29
+ call3[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue](name: String, a1: A1, a2: A2, a3: A3): JsValue
30
+ target js sync "return self_[name_].call(void 0, a1_, a2_, a3_)"
31
+
32
+ call4[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue](name: String, a1: A1, a2: A2, a3: A3, a4: A4): JsValue
33
+ target js sync "return self_[name_].call(void 0, a1_, a2_, a3_, a4_)"
34
+
35
+ call5[A1: IsJsValue, A2: IsJsValue, A3: IsJsValue, A4: IsJsValue, A5: IsJsValue](name: String, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5): JsValue
36
+ target js sync "return self_[name_].call(void 0, a1_, a2_, a3_, a4_, a5_)"
37
+
38
+ 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
39
+ target js sync "return self_[name_].call(void 0, a1_, a2_, a3_, a4_, a5_, a6_)"
40
+
41
+ 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
42
+ target js sync "return self_[name_].call(void 0, a1_, a2_, a3_, a4_, a5_, a6_, a7_)"
43
+
44
+ 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
45
+ target js sync "return self_[name_].call(void 0, a1_, a2_, a3_, a4_, a5_, a6_, a7_, a8_)"
46
+
47
+ 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
48
+ target js sync "return self_[name_].call(void 0, a1_, a2_, a3_, a4_, a5_, a6_, a7_, a8_, a9_)"
19
49
 
20
50
  parseJson(json: String): JsValue
21
51
  target js sync "return JSON.parse(json_)"
package/core/Json.ff CHANGED
@@ -184,7 +184,7 @@ extend self: Json {
184
184
 
185
185
  index(key: Int): Json
186
186
  target js sync """
187
- return Array.isArray(self_) ? self_[key] ?? null : null;
187
+ return Array.isArray(self_) ? self_[key_] ?? null : null;
188
188
  """
189
189
 
190
190
  hasField(key: String): Bool
@@ -3,7 +3,7 @@ import HttpServer from ff:httpserver
3
3
 
4
4
  browserMain(system: BrowserSystem): Unit {
5
5
 
6
- let document = system.js().global().get("document")
6
+ let document = system.js().globalThis().get("document")
7
7
  let input = document.call1("getElementById", "input")
8
8
  let output = document.call1("getElementById", "output")
9
9
  let button = document.call1("getElementById", "button")
@@ -413,6 +413,7 @@ renderHighlightedCode(lux: Lux, code: String) {
413
413
  | LString => Styles.codeStringCss
414
414
  | LUpper => Styles.codeTypeCss
415
415
  | LWildcard => Styles.codeVariableCss
416
+ | LLower {tokens.get(index - 1).any {_.kind == LArrowThin}} => Styles.codeStringCss
416
417
  | LLower {tokens.get(index - 1).any {t =>
417
418
  t.kind == LBracketRight || t.kind == LDot
418
419
  }} => Styles.codeCallCss
@@ -12,14 +12,16 @@ Most JavaScript functionality can be accessed via the `JsSystem` object.
12
12
 
13
13
  ```firefly
14
14
  browserMain(system: BrowserSystem): Unit {
15
- let document = system.js().global().get("document")
16
- let element = document.call1("getElementById", "my-id")
17
- element.set("innerText", "Hi!")
15
+ let document = system.js()->document
16
+ let element = document->getElementById("my-id")
17
+ element->innerText = "Hi!"
18
18
  }
19
19
  ```
20
20
 
21
21
  This example gets the global `document`, calls `getElementId("my-id")` on it, and sets `innerText = "Hi!"`.
22
22
 
23
+ The `->` is shorthand for calling the methods `get`, `set`, `increment`, `decrement`, `call1` etc.
24
+
23
25
  The type of the `document` and `element` variables here is `JsValue`, which represents an arbitrary JavaScript value.
24
26
 
25
27
 
@@ -770,8 +770,7 @@ toplevelCompletion(lspHook: LspHook): List[CompletionInfo] {
770
770
  ""
771
771
  "browserMain(system: BrowserSystem): Unit {"
772
772
  " let message = system.httpClient().get(\"http://localhost:8080/hello\", []) {_.readText()}"
773
- " let window = system.js().global().get(\"window\")"
774
- " window.call1(\"alert\", message)"
773
+ " system.js()->alert(message)"
775
774
  "}"
776
775
  ""
777
776
  "nodeMain(system: NodeSystem): Unit {"
@@ -99,7 +99,7 @@ import * as ff_core_Unit from "../../ff/core/Unit.mjs"
99
99
 
100
100
 
101
101
 
102
- export function JsSystem_global(self_) {
102
+ export function JsSystem_globalThis(self_) {
103
103
  return self_
104
104
  }
105
105
 
@@ -119,6 +119,46 @@ export function JsSystem_decrement(self_, key_, value_, ff_core_JsValue_IsJsValu
119
119
  self_[key_] -= value_
120
120
  }
121
121
 
122
+ export function JsSystem_call0(self_, name_) {
123
+ return self_[name_].call(void 0)
124
+ }
125
+
126
+ export function JsSystem_call1(self_, name_, a1_, ff_core_JsValue_IsJsValue$A1) {
127
+ return self_[name_].call(void 0, a1_)
128
+ }
129
+
130
+ export function JsSystem_call2(self_, name_, a1_, a2_, ff_core_JsValue_IsJsValue$A1, ff_core_JsValue_IsJsValue$A2) {
131
+ return self_[name_].call(void 0, a1_, a2_)
132
+ }
133
+
134
+ export function JsSystem_call3(self_, name_, a1_, a2_, a3_, ff_core_JsValue_IsJsValue$A1, ff_core_JsValue_IsJsValue$A2, ff_core_JsValue_IsJsValue$A3) {
135
+ return self_[name_].call(void 0, a1_, a2_, a3_)
136
+ }
137
+
138
+ export function JsSystem_call4(self_, name_, a1_, a2_, a3_, a4_, ff_core_JsValue_IsJsValue$A1, ff_core_JsValue_IsJsValue$A2, ff_core_JsValue_IsJsValue$A3, ff_core_JsValue_IsJsValue$A4) {
139
+ return self_[name_].call(void 0, a1_, a2_, a3_, a4_)
140
+ }
141
+
142
+ export function JsSystem_call5(self_, name_, a1_, a2_, a3_, a4_, a5_, ff_core_JsValue_IsJsValue$A1, ff_core_JsValue_IsJsValue$A2, ff_core_JsValue_IsJsValue$A3, ff_core_JsValue_IsJsValue$A4, ff_core_JsValue_IsJsValue$A5) {
143
+ return self_[name_].call(void 0, a1_, a2_, a3_, a4_, a5_)
144
+ }
145
+
146
+ export function JsSystem_call6(self_, name_, a1_, a2_, a3_, a4_, a5_, a6_, ff_core_JsValue_IsJsValue$A1, ff_core_JsValue_IsJsValue$A2, ff_core_JsValue_IsJsValue$A3, ff_core_JsValue_IsJsValue$A4, ff_core_JsValue_IsJsValue$A5, ff_core_JsValue_IsJsValue$A6) {
147
+ return self_[name_].call(void 0, a1_, a2_, a3_, a4_, a5_, a6_)
148
+ }
149
+
150
+ export function JsSystem_call7(self_, name_, a1_, a2_, a3_, a4_, a5_, a6_, a7_, ff_core_JsValue_IsJsValue$A1, ff_core_JsValue_IsJsValue$A2, ff_core_JsValue_IsJsValue$A3, ff_core_JsValue_IsJsValue$A4, ff_core_JsValue_IsJsValue$A5, ff_core_JsValue_IsJsValue$A6, ff_core_JsValue_IsJsValue$A7) {
151
+ return self_[name_].call(void 0, a1_, a2_, a3_, a4_, a5_, a6_, a7_)
152
+ }
153
+
154
+ export function JsSystem_call8(self_, name_, a1_, a2_, a3_, a4_, a5_, a6_, a7_, a8_, ff_core_JsValue_IsJsValue$A1, ff_core_JsValue_IsJsValue$A2, ff_core_JsValue_IsJsValue$A3, ff_core_JsValue_IsJsValue$A4, ff_core_JsValue_IsJsValue$A5, ff_core_JsValue_IsJsValue$A6, ff_core_JsValue_IsJsValue$A7, ff_core_JsValue_IsJsValue$A8) {
155
+ return self_[name_].call(void 0, a1_, a2_, a3_, a4_, a5_, a6_, a7_, a8_)
156
+ }
157
+
158
+ export function JsSystem_call9(self_, name_, a1_, a2_, a3_, a4_, a5_, a6_, a7_, a8_, a9_, ff_core_JsValue_IsJsValue$A1, ff_core_JsValue_IsJsValue$A2, ff_core_JsValue_IsJsValue$A3, ff_core_JsValue_IsJsValue$A4, ff_core_JsValue_IsJsValue$A5, ff_core_JsValue_IsJsValue$A6, ff_core_JsValue_IsJsValue$A7, ff_core_JsValue_IsJsValue$A8, ff_core_JsValue_IsJsValue$A9) {
159
+ return self_[name_].call(void 0, a1_, a2_, a3_, a4_, a5_, a6_, a7_, a8_, a9_)
160
+ }
161
+
122
162
  export function JsSystem_parseJson(self_, json_) {
123
163
  return JSON.parse(json_)
124
164
  }
@@ -187,8 +227,8 @@ export function JsSystem_function9(self_, body_) {
187
227
  return body_
188
228
  }
189
229
 
190
- export async function JsSystem_global$(self_, $task) {
191
- throw new Error('Function JsSystem_global is missing on this target in async context.');
230
+ export async function JsSystem_globalThis$(self_, $task) {
231
+ throw new Error('Function JsSystem_globalThis is missing on this target in async context.');
192
232
  }
193
233
 
194
234
  export async function JsSystem_get$(self_, key_, $task) {
@@ -207,6 +247,46 @@ export async function JsSystem_decrement$(self_, key_, value_, ff_core_JsValue_I
207
247
  throw new Error('Function JsSystem_decrement is missing on this target in async context.');
208
248
  }
209
249
 
250
+ export async function JsSystem_call0$(self_, name_, $task) {
251
+ throw new Error('Function JsSystem_call0 is missing on this target in async context.');
252
+ }
253
+
254
+ export async function JsSystem_call1$(self_, name_, a1_, ff_core_JsValue_IsJsValue$A1, $task) {
255
+ throw new Error('Function JsSystem_call1 is missing on this target in async context.');
256
+ }
257
+
258
+ export async function JsSystem_call2$(self_, name_, a1_, a2_, ff_core_JsValue_IsJsValue$A1, ff_core_JsValue_IsJsValue$A2, $task) {
259
+ throw new Error('Function JsSystem_call2 is missing on this target in async context.');
260
+ }
261
+
262
+ export async function JsSystem_call3$(self_, name_, a1_, a2_, a3_, ff_core_JsValue_IsJsValue$A1, ff_core_JsValue_IsJsValue$A2, ff_core_JsValue_IsJsValue$A3, $task) {
263
+ throw new Error('Function JsSystem_call3 is missing on this target in async context.');
264
+ }
265
+
266
+ export async function JsSystem_call4$(self_, name_, a1_, a2_, a3_, a4_, ff_core_JsValue_IsJsValue$A1, ff_core_JsValue_IsJsValue$A2, ff_core_JsValue_IsJsValue$A3, ff_core_JsValue_IsJsValue$A4, $task) {
267
+ throw new Error('Function JsSystem_call4 is missing on this target in async context.');
268
+ }
269
+
270
+ export async function JsSystem_call5$(self_, name_, a1_, a2_, a3_, a4_, a5_, ff_core_JsValue_IsJsValue$A1, ff_core_JsValue_IsJsValue$A2, ff_core_JsValue_IsJsValue$A3, ff_core_JsValue_IsJsValue$A4, ff_core_JsValue_IsJsValue$A5, $task) {
271
+ throw new Error('Function JsSystem_call5 is missing on this target in async context.');
272
+ }
273
+
274
+ export async function JsSystem_call6$(self_, name_, a1_, a2_, a3_, a4_, a5_, a6_, ff_core_JsValue_IsJsValue$A1, ff_core_JsValue_IsJsValue$A2, ff_core_JsValue_IsJsValue$A3, ff_core_JsValue_IsJsValue$A4, ff_core_JsValue_IsJsValue$A5, ff_core_JsValue_IsJsValue$A6, $task) {
275
+ throw new Error('Function JsSystem_call6 is missing on this target in async context.');
276
+ }
277
+
278
+ export async function JsSystem_call7$(self_, name_, a1_, a2_, a3_, a4_, a5_, a6_, a7_, ff_core_JsValue_IsJsValue$A1, ff_core_JsValue_IsJsValue$A2, ff_core_JsValue_IsJsValue$A3, ff_core_JsValue_IsJsValue$A4, ff_core_JsValue_IsJsValue$A5, ff_core_JsValue_IsJsValue$A6, ff_core_JsValue_IsJsValue$A7, $task) {
279
+ throw new Error('Function JsSystem_call7 is missing on this target in async context.');
280
+ }
281
+
282
+ export async function JsSystem_call8$(self_, name_, a1_, a2_, a3_, a4_, a5_, a6_, a7_, a8_, ff_core_JsValue_IsJsValue$A1, ff_core_JsValue_IsJsValue$A2, ff_core_JsValue_IsJsValue$A3, ff_core_JsValue_IsJsValue$A4, ff_core_JsValue_IsJsValue$A5, ff_core_JsValue_IsJsValue$A6, ff_core_JsValue_IsJsValue$A7, ff_core_JsValue_IsJsValue$A8, $task) {
283
+ throw new Error('Function JsSystem_call8 is missing on this target in async context.');
284
+ }
285
+
286
+ export async function JsSystem_call9$(self_, name_, a1_, a2_, a3_, a4_, a5_, a6_, a7_, a8_, a9_, ff_core_JsValue_IsJsValue$A1, ff_core_JsValue_IsJsValue$A2, ff_core_JsValue_IsJsValue$A3, ff_core_JsValue_IsJsValue$A4, ff_core_JsValue_IsJsValue$A5, ff_core_JsValue_IsJsValue$A6, ff_core_JsValue_IsJsValue$A7, ff_core_JsValue_IsJsValue$A8, ff_core_JsValue_IsJsValue$A9, $task) {
287
+ throw new Error('Function JsSystem_call9 is missing on this target in async context.');
288
+ }
289
+
210
290
  export async function JsSystem_parseJson$(self_, json_, $task) {
211
291
  throw new Error('Function JsSystem_parseJson is missing on this target in async context.');
212
292
  }
@@ -452,7 +452,7 @@ export function Json_field(self_, key_) {
452
452
 
453
453
  export function Json_index(self_, key_) {
454
454
 
455
- return Array.isArray(self_) ? self_[key] ?? null : null;
455
+ return Array.isArray(self_) ? self_[key_] ?? null : null;
456
456
 
457
457
  }
458
458
 
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "description": "Firefly compiler",
5
5
  "author": "Firefly team",
6
6
  "license": "MIT",
7
- "version": "0.4.83",
7
+ "version": "0.4.85",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "https://github.com/Ahnfelt/firefly-boot"
package/postgresql/Pg.ff CHANGED
@@ -190,7 +190,7 @@ extend self: PgStatement {
190
190
  }
191
191
 
192
192
  withInstant(name: String, value: Instant): PgStatement {
193
- let jsDate = UnsafeJs.jsSystem().global().get("Date")
193
+ let jsDate = UnsafeJs.jsSystem().globalThis().get("Date")
194
194
  function toJsDate(instant: Instant): JsValue {
195
195
  jsDate.new1(instant.since1970.seconds * 1000.0)
196
196
  }
@@ -199,7 +199,7 @@ extend self: PgStatement {
199
199
  }
200
200
 
201
201
  withNullableInstant(name: String, value: Option[Instant]): PgStatement {
202
- let jsDate = UnsafeJs.jsSystem().global().get("Date")
202
+ let jsDate = UnsafeJs.jsSystem().globalThis().get("Date")
203
203
  function toJsDate(instant: Instant): JsValue {
204
204
  jsDate.new1(instant.since1970.seconds * 1000.0)
205
205
  }
@@ -258,7 +258,7 @@ extend self: PgStatement {
258
258
  }
259
259
 
260
260
  withInstantArray(name: String, value: List[Instant]): PgStatement {
261
- let jsDate = UnsafeJs.jsSystem().global().get("Date")
261
+ let jsDate = UnsafeJs.jsSystem().globalThis().get("Date")
262
262
  function toJsDate(instant: Instant): JsValue {
263
263
  jsDate.new1(instant.since1970.seconds * 1000.0)
264
264
  }
@@ -267,7 +267,7 @@ extend self: PgStatement {
267
267
  }
268
268
 
269
269
  withNullableInstantArray(name: String, value: Option[List[Instant]]): PgStatement {
270
- let jsDate = UnsafeJs.jsSystem().global().get("Date")
270
+ let jsDate = UnsafeJs.jsSystem().globalThis().get("Date")
271
271
  function toJsDate(instant: Instant): JsValue {
272
272
  jsDate.new1(instant.since1970.seconds * 1000.0)
273
273
  }
@@ -4,7 +4,7 @@
4
4
  "description": "Firefly language support",
5
5
  "author": "Firefly team",
6
6
  "license": "MIT",
7
- "version": "0.4.83",
7
+ "version": "0.4.85",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "https://github.com/Ahnfelt/firefly-boot"
@@ -43,7 +43,7 @@
43
43
  "",
44
44
  "browserMain(system: BrowserSystem): Unit {",
45
45
  " let response = system.httpClient().fetch(\"http://localhost:8080/hello\")",
46
- " let window = system.js().global().get(\"window\")",
46
+ " let window = system.js().globalThis().get(\"window\")",
47
47
  " window.call1(\"alert\", response.readText())",
48
48
  "}",
49
49
  "",