firefly-compiler 0.4.18 → 0.4.19

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 (115) hide show
  1. package/compiler/Builder.ff +1 -1
  2. package/compiler/Compiler.ff +6 -5
  3. package/compiler/Inference.ff +31 -19
  4. package/compiler/JsEmitter.ff +98 -71
  5. package/compiler/JsImporter.ff +1 -1
  6. package/compiler/LspHook.ff +4 -4
  7. package/compiler/Main.ff +6 -6
  8. package/compiler/Parser.ff +39 -39
  9. package/compiler/Patterns.ff +2 -0
  10. package/compiler/Syntax.ff +1 -1
  11. package/compiler/Tokenizer.ff +2 -2
  12. package/compiler/Workspace.ff +2 -2
  13. package/core/Array.ff +135 -294
  14. package/core/Buffer.ff +3 -3
  15. package/core/BuildSystem.ff +1 -1
  16. package/core/Equal.ff +36 -52
  17. package/core/HttpClient.ff +1 -1
  18. package/core/IntMap.ff +14 -18
  19. package/core/JsSystem.ff +1 -1
  20. package/core/JsValue.ff +6 -12
  21. package/core/Json.ff +19 -28
  22. package/core/List.ff +281 -312
  23. package/core/Map.ff +4 -8
  24. package/core/NodeSystem.ff +2 -2
  25. package/core/Option.ff +0 -4
  26. package/core/Ordering.ff +10 -6
  27. package/core/Pair.ff +0 -4
  28. package/core/Random.ff +12 -26
  29. package/core/RbMap.ff +216 -216
  30. package/core/Serializable.ff +9 -18
  31. package/core/Set.ff +0 -1
  32. package/core/SourceLocation.ff +1 -1
  33. package/core/Stack.ff +32 -45
  34. package/core/Stream.ff +10 -14
  35. package/core/String.ff +24 -6
  36. package/core/StringMap.ff +15 -19
  37. package/guide/Main.ff +20 -2
  38. package/lsp/CompletionHandler.ff +4 -4
  39. package/lsp/Handler.ff +44 -33
  40. package/lsp/HoverHandler.ff +2 -2
  41. package/lsp/LanguageServer.ff +2 -2
  42. package/lsp/SignatureHelpHandler.ff +1 -1
  43. package/lsp/SymbolHandler.ff +1 -1
  44. package/lux/Lux.ff +3 -3
  45. package/output/js/ff/compiler/Builder.mjs +19 -21
  46. package/output/js/ff/compiler/Compiler.mjs +18 -20
  47. package/output/js/ff/compiler/Dependencies.mjs +8 -10
  48. package/output/js/ff/compiler/Deriver.mjs +234 -236
  49. package/output/js/ff/compiler/Dictionaries.mjs +6 -8
  50. package/output/js/ff/compiler/Environment.mjs +42 -44
  51. package/output/js/ff/compiler/Inference.mjs +346 -304
  52. package/output/js/ff/compiler/JsEmitter.mjs +907 -833
  53. package/output/js/ff/compiler/JsImporter.mjs +0 -2
  54. package/output/js/ff/compiler/LspHook.mjs +10 -12
  55. package/output/js/ff/compiler/Main.mjs +109 -111
  56. package/output/js/ff/compiler/Parser.mjs +405 -407
  57. package/output/js/ff/compiler/Patterns.mjs +64 -50
  58. package/output/js/ff/compiler/Resolver.mjs +36 -38
  59. package/output/js/ff/compiler/Substitution.mjs +4 -6
  60. package/output/js/ff/compiler/Syntax.mjs +160 -162
  61. package/output/js/ff/compiler/Token.mjs +52 -54
  62. package/output/js/ff/compiler/Tokenizer.mjs +16 -18
  63. package/output/js/ff/compiler/Unification.mjs +24 -26
  64. package/output/js/ff/compiler/Wildcards.mjs +0 -2
  65. package/output/js/ff/compiler/Workspace.mjs +18 -20
  66. package/output/js/ff/core/Any.mjs +0 -2
  67. package/output/js/ff/core/Array.mjs +216 -613
  68. package/output/js/ff/core/AssetSystem.mjs +2 -4
  69. package/output/js/ff/core/Atomic.mjs +0 -2
  70. package/output/js/ff/core/Bool.mjs +0 -2
  71. package/output/js/ff/core/Box.mjs +0 -2
  72. package/output/js/ff/core/BrowserSystem.mjs +0 -2
  73. package/output/js/ff/core/Buffer.mjs +0 -2
  74. package/output/js/ff/core/BuildSystem.mjs +12 -14
  75. package/output/js/ff/core/Channel.mjs +0 -2
  76. package/output/js/ff/core/Char.mjs +0 -2
  77. package/output/js/ff/core/Core.mjs +0 -2
  78. package/output/js/ff/core/Duration.mjs +0 -2
  79. package/output/js/ff/core/Equal.mjs +0 -22
  80. package/output/js/ff/core/Error.mjs +0 -2
  81. package/output/js/ff/core/FileHandle.mjs +0 -2
  82. package/output/js/ff/core/Float.mjs +0 -2
  83. package/output/js/ff/core/HttpClient.mjs +2 -4
  84. package/output/js/ff/core/Instant.mjs +0 -2
  85. package/output/js/ff/core/Int.mjs +8 -10
  86. package/output/js/ff/core/IntMap.mjs +32 -42
  87. package/output/js/ff/core/JsSystem.mjs +1 -3
  88. package/output/js/ff/core/JsValue.mjs +5 -12
  89. package/output/js/ff/core/Json.mjs +23 -56
  90. package/output/js/ff/core/List.mjs +648 -1989
  91. package/output/js/ff/core/Lock.mjs +0 -2
  92. package/output/js/ff/core/Log.mjs +0 -2
  93. package/output/js/ff/core/Map.mjs +10 -20
  94. package/output/js/ff/core/NodeSystem.mjs +6 -8
  95. package/output/js/ff/core/Nothing.mjs +0 -2
  96. package/output/js/ff/core/Option.mjs +8 -18
  97. package/output/js/ff/core/Ordering.mjs +20 -98
  98. package/output/js/ff/core/Pair.mjs +6 -16
  99. package/output/js/ff/core/Path.mjs +12 -14
  100. package/output/js/ff/core/Random.mjs +24 -54
  101. package/output/js/ff/core/RbMap.mjs +54 -56
  102. package/output/js/ff/core/Serializable.mjs +19 -36
  103. package/output/js/ff/core/Set.mjs +0 -14
  104. package/output/js/ff/core/Show.mjs +0 -2
  105. package/output/js/ff/core/SourceLocation.mjs +0 -2
  106. package/output/js/ff/core/Stream.mjs +34 -44
  107. package/output/js/ff/core/String.mjs +31 -5
  108. package/output/js/ff/core/StringMap.mjs +32 -42
  109. package/output/js/ff/core/Task.mjs +0 -2
  110. package/output/js/ff/core/Try.mjs +0 -2
  111. package/output/js/ff/core/Unit.mjs +0 -2
  112. package/package.json +1 -1
  113. package/vscode/package.json +1 -1
  114. package/webserver/WebServer.ff +8 -8
  115. package/output/js/ff/core/Stack.mjs +0 -603
package/core/IntMap.ff CHANGED
@@ -40,18 +40,14 @@ extend self[V]: IntMap[V] {
40
40
  target js sync "for(const [k, v] of self_) if(!body_(k, v)) break"
41
41
  target js async "for(const [k, v] of self_) if(!await body_(k, v)) break"
42
42
 
43
- toStack(): Stack[Pair[Int, V]] {
44
- let stack = Stack.make()
45
- self.each {k, v => stack.push(Pair(k, v))}
46
- stack
47
- }
48
-
49
43
  toArray(): Array[Pair[Int, V]] {
50
- self.toStack().drain()
44
+ let array = Array.make()
45
+ self.each {k, v => array.push(Pair(k, v))}
46
+ array
51
47
  }
52
48
 
53
49
  toList(): List[Pair[Int, V]] {
54
- self.toArray().toList()
50
+ self.toArray().drain()
55
51
  }
56
52
 
57
53
  toStream(): Stream[Pair[Int, V]] {
@@ -59,19 +55,19 @@ extend self[V]: IntMap[V] {
59
55
  }
60
56
 
61
57
  toMap(): Map[Int, V] {
62
- self.toArray().toMap()
58
+ self.toList().toMap()
63
59
  }
64
60
 
65
61
  keys(): List[Int] {
66
- let stack = Stack.make()
67
- self.each {k, v => stack.push(k)}
68
- stack.toList()
62
+ let array = Array.make()
63
+ self.each {k, v => array.push(k)}
64
+ array.toList()
69
65
  }
70
66
 
71
67
  values(): List[V] {
72
- let stack = Stack.make()
73
- self.each {k, v => stack.push(v)}
74
- stack.toList()
68
+ let array = Array.make()
69
+ self.each {k, v => array.push(v)}
70
+ array.toList()
75
71
  }
76
72
 
77
73
  copy(): IntMap[V]
@@ -84,12 +80,12 @@ extend self[V]: IntMap[V] {
84
80
 
85
81
  }
86
82
 
87
- extend self[V]: IntMap[Stack[V]] {
83
+ extend self[V]: IntMap[Array[V]] {
88
84
 
89
85
  push(key: Int, value: V) {
90
86
  self.get(key).{
91
- | None => self.set(key, [value].toStack())
92
- | Some(stack) => stack.push(value)
87
+ | None => self.set(key, [value].toArray())
88
+ | Some(array) => array.push(value)
93
89
  }
94
90
  }
95
91
 
package/core/JsSystem.ff CHANGED
@@ -21,7 +21,7 @@ extend self: JsSystem {
21
21
  target js sync "return {}"
22
22
 
23
23
  array(values: List[JsValue]): JsValue
24
- target js sync "return ff_core_List.List_toArray(values_)"
24
+ target js sync "return values_.slice()"
25
25
 
26
26
  json(value: Json): JsValue
27
27
  target js sync "return value_"
package/core/JsValue.ff CHANGED
@@ -17,7 +17,7 @@ extend self: JsValue {
17
17
  grabBool(): Bool
18
18
  target js sync "return self_"
19
19
 
20
- grabArray(): Array[JsValue]
20
+ grabArray(): List[JsValue]
21
21
  target js sync "return self_"
22
22
 
23
23
  grabBuffer(): Buffer
@@ -112,7 +112,7 @@ extend self: JsValue {
112
112
 
113
113
 
114
114
  call(name: String, arguments: List[JsValue]): JsValue
115
- target js sync "return self_[name_].apply(this_, ff_core_List.List_toArray(arguments_))"
115
+ target js sync "return self_[name_].apply(this_, arguments_)"
116
116
 
117
117
  call0(name: String): JsValue
118
118
  target js sync "return self_[name_].call(self_)"
@@ -146,7 +146,7 @@ extend self: JsValue {
146
146
 
147
147
 
148
148
  callValue(this: JsValue, arguments: List[JsValue]): JsValue
149
- target js sync "return self_.apply(this_, ff_core_List.List_toArray(arguments_))"
149
+ target js sync "return self_.apply(this_, arguments_)"
150
150
 
151
151
  callValue0(): JsValue
152
152
  target js sync "return self_.call(self_)"
@@ -180,7 +180,7 @@ extend self: JsValue {
180
180
 
181
181
 
182
182
  new(this: JsValue, arguments: List[JsValue]): JsValue
183
- target js sync "return new (Function.prototype.bind.apply(self_, ff_core_List.List_toArray(arguments_)))"
183
+ target js sync "return new (Function.prototype.bind.apply(self_, arguments_))"
184
184
 
185
185
  new0(): JsValue
186
186
  target js sync "return new self_()"
@@ -216,12 +216,7 @@ extend self: JsValue {
216
216
  grabPairs(): List[Pair[String, JsValue]]
217
217
  target js sync """
218
218
  if(!(self_ instanceof Object)) throw new Error('Expected object, got '+ typeof self_);;
219
- let result = ff_core_List.Empty();
220
- Object.getOwnPropertyNames(self_).forEach((name, i) => {
221
- let pair = ff_core_Pair.Pair(name, self_[name]);
222
- result = ff_core_List.Link(pair, result);
223
- })
224
- return result;
219
+ return Object.getOwnPropertyNames(self_).map((name, i) => ff_core_Pair.Pair(name, self_[name]));
225
220
  """
226
221
 
227
222
  grabMap(): Map[String, JsValue] {
@@ -240,7 +235,6 @@ extend self: JsValue {
240
235
  return self_
241
236
  """
242
237
 
243
- //toArray(): Array[JsValue] // TODO
244
238
  //toList(): List[JsValue] // TODO
245
239
  // TODO: JS operators
246
240
 
@@ -253,7 +247,7 @@ instance Char: IsJsValue {}
253
247
  instance Int: IsJsValue {}
254
248
  instance Float: IsJsValue {}
255
249
  instance Bool: IsJsValue {}
256
- instance Array[T: IsJsValue]: IsJsValue {}
250
+ instance List[T: IsJsValue]: IsJsValue {}
257
251
  instance IntMap[T: IsJsValue]: IsJsValue {}
258
252
  instance StringMap[T: IsJsValue]: IsJsValue {}
259
253
  instance Error: IsJsValue {}
package/core/Json.ff CHANGED
@@ -34,15 +34,11 @@ null(): Json
34
34
  return null;
35
35
  """
36
36
 
37
- array(json: Array[Json]): Json
37
+ array(json: List[Json]): Json
38
38
  target js sync """
39
39
  return json_;
40
40
  """
41
41
 
42
- list(json: List[Json]): Json {
43
- array(json.toArray())
44
- }
45
-
46
42
  object(): Json
47
43
  target js sync """
48
44
  return {};
@@ -107,7 +103,7 @@ extend self: Json {
107
103
  throw new Error('Not a bool: ' + JSON.stringify(self_));
108
104
  """
109
105
 
110
- grabArray(): Array[Json]
106
+ grabArray(): List[Json]
111
107
  target js sync """
112
108
  if(!Array.isArray(self_)) throw new Error('Not an array: ' + JSON.stringify(self_));
113
109
  return self_;
@@ -137,7 +133,7 @@ extend self: Json {
137
133
  if(self.isBool()) {self.grabBool()}
138
134
  }
139
135
 
140
- getArray(): Option[Array[Json]] {
136
+ getArray(): Option[List[Json]] {
141
137
  if(self.isArray()) {self.grabArray()}
142
138
  }
143
139
 
@@ -207,7 +203,7 @@ extend self: Json {
207
203
  return typeof self_ === 'array' ? ff_core_Option.Some(self_[key_] ?? null) : ff_core_Option.None();
208
204
  """
209
205
 
210
- getFields(): Option[Array[String]]
206
+ getFields(): Option[List[String]]
211
207
  target js sync """
212
208
  return typeof self_ === 'object' && self_ !== null && !Array.isArray(self_)
213
209
  ? ff_core_Option.Some(Object.keys(self_)) : ff_core_Option.None();
@@ -225,22 +221,22 @@ extend self: Json {
225
221
  }
226
222
  }
227
223
 
228
- grabFields(): Array[String] {
224
+ grabFields(): List[String] {
229
225
  self.getFields().else {
230
226
  throw(GrabException())
231
227
  }
232
228
  }
233
229
 
234
- map[T](body: (String, Json) => T): Array[T] {
235
- let stack = Stack.make()
236
- self.each {field, value => stack.push(body(field, value))}
237
- stack.drain()
230
+ map[T](body: (String, Json) => T): List[T] {
231
+ let array = Array.make()
232
+ self.each {field, value => array.push(body(field, value))}
233
+ array.drain()
238
234
  }
239
235
 
240
- flatMap[T](body: (String, Json) => Array[T]): Array[T] {
241
- let stack = Stack.make()
242
- self.each {field, value => stack.pushArray(body(field, value))}
243
- stack.drain()
236
+ flatMap[T](body: (String, Json) => List[T]): List[T] {
237
+ let array = Array.make()
238
+ self.each {field, value => array.pushList(body(field, value))}
239
+ array.drain()
244
240
  }
245
241
 
246
242
  each(body: (String, Json) => Unit) {
@@ -301,29 +297,24 @@ instance Bool: JsonLike {
301
297
  fromJson(json: Json): Option[Bool] {_.getBool()}
302
298
  }
303
299
 
304
- instance Array[T: JsonLike]: JsonLike {
305
- toJson(value: Array[T]): Json {array(value.map(toJson))}
306
- fromJson(json: Json): Option[Array[T]] {
300
+ instance List[T: JsonLike]: JsonLike {
301
+ toJson(value: List[T]): Json {array(value.map(toJson))}
302
+ fromJson(json: Json): Option[List[T]] {
307
303
  json.getArray().flatMap {array =>
308
304
  mutable convertible = True
309
- let stack = Stack.make()
305
+ let result = Array.make()
310
306
  array.eachWhile {item =>
311
307
  fromJson(item).{
312
308
  | None => convertible = False
313
- | Some(value) => stack.push(value)
309
+ | Some(value) => result.push(value)
314
310
  }
315
311
  convertible
316
312
  }
317
- if(convertible) {stack.drain()}
313
+ if(convertible) {result.drain()}
318
314
  }
319
315
  }
320
316
  }
321
317
 
322
- instance List[T: JsonLike]: JsonLike {
323
- toJson(value: List[T]): Json {list(value.map(toJson))}
324
- fromJson(json: Json): Option[List[T]] {fromJson[Array[T]](json).map {_.toList()}}
325
- }
326
-
327
318
  instance StringMap[T: JsonLike]: JsonLike {
328
319
  toJson(value: StringMap[T]): Json {
329
320
  Json.fields {setField =>