firefly-compiler 0.4.19 → 0.4.21

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 (68) hide show
  1. package/compiler/Builder.ff +23 -13
  2. package/compiler/JsEmitter.ff +120 -76
  3. package/compiler/LspHook.ff +17 -3
  4. package/compiler/Main.ff +13 -7
  5. package/compiler/Parser.ff +11 -13
  6. package/compiler/Resolver.ff +15 -15
  7. package/compiler/Syntax.ff +1 -0
  8. package/core/Array.ff +6 -4
  9. package/core/Int.ff +12 -12
  10. package/core/Json.ff +2 -2
  11. package/core/List.ff +6 -4
  12. package/experimental/benchmarks/ListGrab.ff +23 -0
  13. package/experimental/benchmarks/ListGrab.java +55 -0
  14. package/experimental/benchmarks/Pyrotek45.ff +30 -0
  15. package/experimental/benchmarks/Pyrotek45.java +64 -0
  16. package/experimental/tests/TestJson.ff +26 -0
  17. package/lsp/CompletionHandler.ff +14 -14
  18. package/lsp/Handler.ff +56 -60
  19. package/lsp/SignatureHelpHandler.ff +5 -4
  20. package/lsp/SymbolHandler.ff +18 -4
  21. package/lsp/TestReferences.ff +15 -0
  22. package/lsp/TestReferencesCase.ff +8 -0
  23. package/output/js/ff/compiler/Builder.mjs +50 -44
  24. package/output/js/ff/compiler/Dependencies.mjs +0 -2
  25. package/output/js/ff/compiler/Deriver.mjs +16 -140
  26. package/output/js/ff/compiler/Dictionaries.mjs +8 -222
  27. package/output/js/ff/compiler/Environment.mjs +12 -154
  28. package/output/js/ff/compiler/Inference.mjs +127 -1013
  29. package/output/js/ff/compiler/JsEmitter.mjs +434 -2344
  30. package/output/js/ff/compiler/JsImporter.mjs +0 -12
  31. package/output/js/ff/compiler/LspHook.mjs +548 -151
  32. package/output/js/ff/compiler/Main.mjs +96 -550
  33. package/output/js/ff/compiler/Parser.mjs +58 -390
  34. package/output/js/ff/compiler/Patterns.mjs +20 -200
  35. package/output/js/ff/compiler/Resolver.mjs +26 -340
  36. package/output/js/ff/compiler/Substitution.mjs +2 -160
  37. package/output/js/ff/compiler/Syntax.mjs +449 -3293
  38. package/output/js/ff/compiler/Token.mjs +9 -1095
  39. package/output/js/ff/compiler/Tokenizer.mjs +4 -2
  40. package/output/js/ff/compiler/Unification.mjs +26 -360
  41. package/output/js/ff/compiler/Wildcards.mjs +0 -86
  42. package/output/js/ff/compiler/Workspace.mjs +8 -96
  43. package/output/js/ff/core/Array.mjs +15 -8
  44. package/output/js/ff/core/AssetSystem.mjs +4 -14
  45. package/output/js/ff/core/Bool.mjs +0 -12
  46. package/output/js/ff/core/Core.mjs +0 -30
  47. package/output/js/ff/core/Int.mjs +24 -24
  48. package/output/js/ff/core/IntMap.mjs +0 -8
  49. package/output/js/ff/core/Json.mjs +2 -42
  50. package/output/js/ff/core/List.mjs +23 -32
  51. package/output/js/ff/core/Lock.mjs +0 -10
  52. package/output/js/ff/core/Map.mjs +0 -24
  53. package/output/js/ff/core/Option.mjs +10 -286
  54. package/output/js/ff/core/Ordering.mjs +16 -158
  55. package/output/js/ff/core/Pair.mjs +2 -34
  56. package/output/js/ff/core/Path.mjs +2 -28
  57. package/output/js/ff/core/Random.mjs +4 -4
  58. package/output/js/ff/core/RbMap.mjs +56 -644
  59. package/output/js/ff/core/Show.mjs +0 -16
  60. package/output/js/ff/core/Stream.mjs +14 -144
  61. package/output/js/ff/core/StringMap.mjs +0 -8
  62. package/output/js/ff/core/Try.mjs +4 -108
  63. package/output/js/ff/core/Unit.mjs +2 -16
  64. package/package.json +1 -1
  65. package/postgresql/Pg.ff +23 -23
  66. package/vscode/client/src/extension.ts +30 -2
  67. package/vscode/package.json +17 -1
  68. package/core/Stack.ff +0 -250
@@ -44,10 +44,11 @@ handleSignatureHelp(system: NodeSystem, lspHook: LspHook): Json {
44
44
 
45
45
  pickActiveParameter(help: Json, argumentIndex: Int, parameterName: Option[String]): Json {
46
46
  parameterName.flatMap {name =>
47
- let parameters = help.field("signatures").index(0).field("parameters").grabArray()
48
- parameters.pairs().collectFirst {| Pair(i, p) =>
49
- if(name == p.field("label").grabString().takeWhile {_.isAsciiLetterOrDigit()}) {
50
- help.with("activeParameter", i)
47
+ help.field("signatures").index(0).field("parameters").getArray().flatMap {parameters =>
48
+ parameters.pairs().collectFirst {| Pair(i, p) =>
49
+ if(name == p.field("label").grabString().takeWhile {_.isAsciiLetterOrDigit()}) {
50
+ help.with("activeParameter", i)
51
+ }
51
52
  }
52
53
  }
53
54
  }.else {help.with("activeParameter", argumentIndex)}
@@ -3,7 +3,7 @@ import Syntax from ff:compiler
3
3
 
4
4
  data DocumentSymbol(
5
5
  name: String
6
- kind: Int
6
+ kind: DocumentSymbolKind
7
7
  selectionStart: Location
8
8
  selectionEnd: Location
9
9
  start: Location
@@ -13,7 +13,7 @@ data DocumentSymbol(
13
13
 
14
14
  data WorkspaceSymbol(
15
15
  name: String
16
- kind: Int
16
+ kind: DocumentSymbolKind
17
17
  containerName: Option[String]
18
18
  selectionStart: Location
19
19
  selectionEnd: Location
@@ -93,16 +93,30 @@ showPosition(at: Location): String {
93
93
  documentSymbolToLsp(symbol: DocumentSymbol): Json {
94
94
  Json.object()
95
95
  .with("name", symbol.name)
96
- .with("kind", symbol.kind)
96
+ .with("kind", documentSymbolNumber(symbol.kind))
97
97
  .with("range", locationsToLspRange(symbol.start, symbol.end))
98
98
  .with("selectionRange", locationsToLspRange(symbol.selectionStart, symbol.selectionEnd))
99
99
  .with("children", symbol.children.map {documentSymbolToLsp(_)})
100
100
  }
101
101
 
102
+ documentSymbolNumber(kind: DocumentSymbolKind): Int {
103
+ | SExtend => 3 // Namespace
104
+ | SFunction(True) => 6
105
+ | SFunction(False) => 12
106
+ | SInstance => 19 // Object
107
+ | SLet(True) => 13
108
+ | SLet(False) => 14
109
+ | SParameter => 7 // Property
110
+ | STrait => 11 // Interface
111
+ | STraitFunction => 12 // Function
112
+ | SType => 5
113
+ | SVariant => 10 // Enum
114
+ }
115
+
102
116
  workspaceSymbolToLsp(rootPath: Path, symbol: WorkspaceSymbol): Json {
103
117
  let o = Json.object()
104
118
  .with("name", symbol.name)
105
- .with("kind", symbol.kind)
119
+ .with("kind", documentSymbolNumber(symbol.kind))
106
120
  .with("location", Json.object()
107
121
  .with("uri", rootPath.path(symbol.selectionStart.file).url())
108
122
  .with("range", locationsToLspRange(symbol.selectionStart, symbol.selectionEnd))
@@ -0,0 +1,15 @@
1
+ import Handler
2
+ import Syntax from ff:compiler
3
+
4
+ nodeMain(system: NodeSystem) {
5
+ Log.debug("Hello")
6
+ let fireflyPath = system.path(".")
7
+ Log.debug(fireflyPath.absolute())
8
+ let handler = Handler(fireflyPath, None, Map.empty(), [].toSet(), Map.empty(), Map.empty())
9
+ let targetAt = Location("/home/werk/projects/firefly-boot/lsp/TestReferencesCase.ff", 7, 5)
10
+ let references = handler.findReferences(system, targetAt, local = False, includeDeclaration = True)
11
+ Log.show(references)
12
+ references.each {_.each {r =>
13
+ Log.show(r)
14
+ }}
15
+ }
@@ -0,0 +1,8 @@
1
+ foo(a: Int): Int {
2
+ a + a
3
+ }
4
+
5
+ nodeMain(system: NodeSystem) {
6
+ foo(13)
7
+ foo(37)
8
+ }
@@ -166,30 +166,19 @@ return ff_compiler_Dependencies.ResolvedDependencies(_c.mainPackagePair_, _c.pac
166
166
  }))(resolvedDependencies_), ff_core_Option.None(), ff_core_NodeSystem.NodeSystem_path(system_, ".firefly/temporary"), ff_core_Path.Path_slash(ff_core_NodeSystem.NodeSystem_path(system_, ".firefly/output"), target_), false)
167
167
  }
168
168
 
169
- export function check_(system_, fireflyPath_, path_, virtualFiles_, lspHook_, infer_) {
169
+ export function check_(system_, fireflyPath_, path_, mustContain_, virtualFiles_, lspHook_, infer_) {
170
170
  const packages_ = (((_1) => {
171
- {
172
171
  if(_1) {
173
- return ff_compiler_Builder.findPackageFiles_(path_)
174
- return
175
- }
172
+ return ff_compiler_Builder.findPackageFiles_(path_, mustContain_)
176
173
  }
177
- {
178
- if(!_1) {
179
- const _guard1 = ff_core_Path.Path_endsWith(path_, [".firefly", "package.ff"]);
180
- if(_guard1) {
174
+ if(!_1 && ff_core_Path.Path_endsWith(path_, [".firefly", "package.ff"])) {
181
175
  return [ff_compiler_Builder.PackageFiles(ff_core_Option.Option_grab(ff_core_Path.Path_parent(path_)), ff_core_Option.Some(path_), [])]
182
- return
183
- }
184
176
  }
185
- }
186
- {
187
177
  if(!_1) {
188
178
  return [ff_compiler_Builder.PackageFiles(ff_core_Option.Option_grab(ff_core_Path.Path_parent(path_)), ff_core_Option.None(), [path_])]
189
- return
190
- }
191
179
  }
192
180
  }))(ff_core_Path.Path_isDirectory(path_));
181
+ const errors_ = ff_core_Array.make_();
193
182
  ff_core_List.List_each(ff_core_List.List_filter(packages_, ((_w1) => {
194
183
  return (!ff_core_List.List_isEmpty(_w1.files_))
195
184
  })), ((package_) => {
@@ -204,17 +193,29 @@ return ff_compiler_Dependencies.ResolvedDependencies(_c.mainPackagePair_, _c.pac
204
193
  const compiler_ = ff_compiler_Compiler.make_(ff_compiler_JsEmitter.EmitBuild(), ff_core_NodeSystem.NodeSystem_mainTask(system_), ff_core_Option.None(), ff_core_Path.Path_slash(ff_core_Path.Path_slash(package_.root_, ".firefly"), "temporary"), fixedResolvedDependencies_, virtualFiles_, lspHook_);
205
194
  ff_core_List.List_each(package_.files_, ((file_) => {
206
195
  const localFile_ = ff_core_Path.Path_base(file_);
196
+ try {
207
197
  if(infer_) {
208
198
  ff_compiler_Compiler.Compiler_infer(compiler_, resolvedDependencies_.mainPackagePair_, ff_core_String.String_dropLast(localFile_, ff_core_String.String_size(".ff")))
209
199
  } else {
210
200
  ff_compiler_Compiler.Compiler_resolve(compiler_, resolvedDependencies_.mainPackagePair_, ff_core_String.String_dropLast(localFile_, ff_core_String.String_size(".ff")))
211
201
  }
202
+ } catch(_error) {
203
+ if(!_error.ffException) throw _error
204
+ const _exception = ff_core_Any.fromAny_(_error.ffException, ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)
205
+ if(!_exception.Some) throw _error
206
+ {
207
+ const c_ = _exception.value_;
208
+ const error_ = _error;
209
+ ff_core_Array.Array_push(errors_, c_)
210
+ }
211
+ }
212
212
  }))
213
- }))
213
+ }));
214
+ return ff_core_Array.Array_drain(errors_)
214
215
  }
215
216
 
216
- export function findPackageFiles_(path_) {
217
- const files_ = ff_compiler_Builder.findFireflyFiles_(path_);
217
+ export function findPackageFiles_(path_, mustContain_) {
218
+ const files_ = ff_compiler_Builder.findFireflyFiles_(path_, mustContain_);
218
219
  const split_ = ff_core_List.List_partition(files_, ((_w1) => {
219
220
  return ff_core_Path.Path_endsWith(_w1, [".firefly", "package.ff"])
220
221
  }));
@@ -235,7 +236,7 @@ return ff_compiler_Builder.PackageFiles(projectRoot_, ff_core_Option.None(), [fi
235
236
  return [...multiFileProjects_, ...singleFileProjects_]
236
237
  }
237
238
 
238
- export function findFireflyFiles_(path_) {
239
+ export function findFireflyFiles_(path_, mustContain_) {
239
240
  const split_ = ff_core_List.List_partition(ff_core_Stream.Stream_toList(ff_core_Path.Path_entries(path_)), ((_w1) => {
240
241
  return ff_core_Path.PathEntry_isDirectory(_w1)
241
242
  }));
@@ -248,11 +249,13 @@ return (((c_ === 46) || ff_core_Char.Char_isAsciiLower(c_)) || ff_core_Char.Char
248
249
  }));
249
250
  const fireflyFiles_ = ff_core_List.List_filter(ff_core_List.List_map(split_.second_, ((_w1) => {
250
251
  return ff_core_Path.PathEntry_path(_w1)
251
- })), ((_w1) => {
252
- return (ff_core_Path.Path_extension(_w1) === ".ff")
252
+ })), ((file_) => {
253
+ return ((ff_core_Path.Path_extension(file_) === ".ff") && ff_core_Option.Option_all(mustContain_, ((s_) => {
254
+ return ff_core_String.String_contains(ff_core_Path.Path_readText(file_), s_)
255
+ })))
253
256
  }));
254
257
  return [...fireflyFiles_, ...ff_core_List.List_flatMap(directories_, ((_w1) => {
255
- return ff_compiler_Builder.findFireflyFiles_(_w1)
258
+ return ff_compiler_Builder.findFireflyFiles_(_w1, mustContain_)
256
259
  }))]
257
260
  }
258
261
 
@@ -345,30 +348,19 @@ return ff_compiler_Dependencies.ResolvedDependencies(_c.mainPackagePair_, _c.pac
345
348
  }))(resolvedDependencies_), ff_core_Option.None(), (await ff_core_NodeSystem.NodeSystem_path$(system_, ".firefly/temporary", $task)), (await ff_core_Path.Path_slash$((await ff_core_NodeSystem.NodeSystem_path$(system_, ".firefly/output", $task)), target_, $task)), false, $task))
346
349
  }
347
350
 
348
- export async function check_$(system_, fireflyPath_, path_, virtualFiles_, lspHook_, infer_, $task) {
351
+ export async function check_$(system_, fireflyPath_, path_, mustContain_, virtualFiles_, lspHook_, infer_, $task) {
349
352
  const packages_ = (await ((async (_1, $task) => {
350
- {
351
353
  if(_1) {
352
- return (await ff_compiler_Builder.findPackageFiles_$(path_, $task))
353
- return
354
- }
354
+ return (await ff_compiler_Builder.findPackageFiles_$(path_, mustContain_, $task))
355
355
  }
356
- {
357
- if(!_1) {
358
- const _guard1 = (await ff_core_Path.Path_endsWith$(path_, [".firefly", "package.ff"], $task));
359
- if(_guard1) {
356
+ if(!_1 && (await ff_core_Path.Path_endsWith$(path_, [".firefly", "package.ff"], $task))) {
360
357
  return [ff_compiler_Builder.PackageFiles(ff_core_Option.Option_grab((await ff_core_Path.Path_parent$(path_, $task))), ff_core_Option.Some(path_), [])]
361
- return
362
- }
363
358
  }
364
- }
365
- {
366
359
  if(!_1) {
367
360
  return [ff_compiler_Builder.PackageFiles(ff_core_Option.Option_grab((await ff_core_Path.Path_parent$(path_, $task))), ff_core_Option.None(), [path_])]
368
- return
369
- }
370
361
  }
371
362
  }))((await ff_core_Path.Path_isDirectory$(path_, $task)), $task));
363
+ const errors_ = ff_core_Array.make_();
372
364
  (await ff_core_List.List_each$(ff_core_List.List_filter(packages_, ((_w1) => {
373
365
  return (!ff_core_List.List_isEmpty(_w1.files_))
374
366
  })), (async (package_, $task) => {
@@ -383,17 +375,29 @@ return ff_compiler_Dependencies.ResolvedDependencies(_c.mainPackagePair_, _c.pac
383
375
  const compiler_ = (await ff_compiler_Compiler.make_$(ff_compiler_JsEmitter.EmitBuild(), (await ff_core_NodeSystem.NodeSystem_mainTask$(system_, $task)), ff_core_Option.None(), (await ff_core_Path.Path_slash$((await ff_core_Path.Path_slash$(package_.root_, ".firefly", $task)), "temporary", $task)), fixedResolvedDependencies_, virtualFiles_, lspHook_, $task));
384
376
  (await ff_core_List.List_each$(package_.files_, (async (file_, $task) => {
385
377
  const localFile_ = (await ff_core_Path.Path_base$(file_, $task));
378
+ try {
386
379
  if(infer_) {
387
380
  (await ff_compiler_Compiler.Compiler_infer$(compiler_, resolvedDependencies_.mainPackagePair_, ff_core_String.String_dropLast(localFile_, ff_core_String.String_size(".ff")), $task))
388
381
  } else {
389
382
  (await ff_compiler_Compiler.Compiler_resolve$(compiler_, resolvedDependencies_.mainPackagePair_, ff_core_String.String_dropLast(localFile_, ff_core_String.String_size(".ff")), $task))
390
383
  }
384
+ } catch(_error) {
385
+ if(!_error.ffException) throw _error
386
+ const _exception = ff_core_Any.fromAny_(_error.ffException, ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)
387
+ if(!_exception.Some) throw _error
388
+ {
389
+ const c_ = _exception.value_;
390
+ const error_ = _error;
391
+ ff_core_Array.Array_push(errors_, c_)
392
+ }
393
+ }
391
394
  }), $task))
392
- }), $task))
395
+ }), $task));
396
+ return ff_core_Array.Array_drain(errors_)
393
397
  }
394
398
 
395
- export async function findPackageFiles_$(path_, $task) {
396
- const files_ = (await ff_compiler_Builder.findFireflyFiles_$(path_, $task));
399
+ export async function findPackageFiles_$(path_, mustContain_, $task) {
400
+ const files_ = (await ff_compiler_Builder.findFireflyFiles_$(path_, mustContain_, $task));
397
401
  const split_ = (await ff_core_List.List_partition$(files_, (async (_w1, $task) => {
398
402
  return (await ff_core_Path.Path_endsWith$(_w1, [".firefly", "package.ff"], $task))
399
403
  }), $task));
@@ -414,7 +418,7 @@ return ff_compiler_Builder.PackageFiles(projectRoot_, ff_core_Option.None(), [fi
414
418
  return [...multiFileProjects_, ...singleFileProjects_]
415
419
  }
416
420
 
417
- export async function findFireflyFiles_$(path_, $task) {
421
+ export async function findFireflyFiles_$(path_, mustContain_, $task) {
418
422
  const split_ = (await ff_core_List.List_partition$((await ff_core_Stream.Stream_toList$((await ff_core_Path.Path_entries$(path_, $task)), $task)), (async (_w1, $task) => {
419
423
  return (await ff_core_Path.PathEntry_isDirectory$(_w1, $task))
420
424
  }), $task));
@@ -427,11 +431,13 @@ return (((c_ === 46) || ff_core_Char.Char_isAsciiLower(c_)) || ff_core_Char.Char
427
431
  }), $task));
428
432
  const fireflyFiles_ = (await ff_core_List.List_filter$((await ff_core_List.List_map$(split_.second_, (async (_w1, $task) => {
429
433
  return (await ff_core_Path.PathEntry_path$(_w1, $task))
430
- }), $task)), (async (_w1, $task) => {
431
- return ((await ff_core_Path.Path_extension$(_w1, $task)) === ".ff")
434
+ }), $task)), (async (file_, $task) => {
435
+ return (((await ff_core_Path.Path_extension$(file_, $task)) === ".ff") && (await ff_core_Option.Option_all$(mustContain_, (async (s_, $task) => {
436
+ return ff_core_String.String_contains((await ff_core_Path.Path_readText$(file_, $task)), s_)
437
+ }), $task)))
432
438
  }), $task));
433
439
  return [...fireflyFiles_, ...(await ff_core_List.List_flatMap$(directories_, (async (_w1, $task) => {
434
- return (await ff_compiler_Builder.findFireflyFiles_$(_w1, $task))
440
+ return (await ff_compiler_Builder.findFireflyFiles_$(_w1, mustContain_, $task))
435
441
  }), $task))]
436
442
  }
437
443
 
@@ -225,7 +225,6 @@ const _1 = info_;
225
225
  {
226
226
  const _c = _1;
227
227
  return ff_compiler_Syntax.PackageInfo(_c.package_, [coreDependency_, ...info_.dependencies_], _c.includes_)
228
- return
229
228
  }
230
229
  }
231
230
  }
@@ -324,7 +323,6 @@ const _1 = info_;
324
323
  {
325
324
  const _c = _1;
326
325
  return ff_compiler_Syntax.PackageInfo(_c.package_, [coreDependency_, ...info_.dependencies_], _c.includes_)
327
- return
328
326
  }
329
327
  }
330
328
  }