firefly-compiler 0.4.4
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/.firefly-workspace +1 -0
- package/.vscode/settings.json +5 -0
- package/LICENSE.txt +21 -0
- package/README.md +96 -0
- package/bin/firefly.mjs +2 -0
- package/compiler/.firefly/package.ff +1 -0
- package/compiler/Builder.ff +218 -0
- package/compiler/Compiler.ff +241 -0
- package/compiler/Dependencies.ff +179 -0
- package/compiler/Deriver.ff +647 -0
- package/compiler/Dictionaries.ff +205 -0
- package/compiler/Environment.ff +166 -0
- package/compiler/Inference.ff +1117 -0
- package/compiler/JsEmitter.ff +861 -0
- package/compiler/JsImporter.ff +56 -0
- package/compiler/LspHook.ff +188 -0
- package/compiler/Main.ff +237 -0
- package/compiler/Parser.ff +1383 -0
- package/compiler/Patterns.ff +111 -0
- package/compiler/Resolver.ff +620 -0
- package/compiler/Substitution.ff +178 -0
- package/compiler/Syntax.ff +299 -0
- package/compiler/Token.ff +180 -0
- package/compiler/Tokenizer.ff +278 -0
- package/compiler/Unification.ff +220 -0
- package/compiler/Wildcards.ff +50 -0
- package/compiler/Workspace.ff +88 -0
- package/core/.firefly/package.ff +2 -0
- package/core/Any.ff +30 -0
- package/core/Array.ff +249 -0
- package/core/AssetSystem.ff +61 -0
- package/core/Atomic.ff +64 -0
- package/core/Bool.ff +13 -0
- package/core/BrowserSystem.ff +14 -0
- package/core/Buffer.ff +211 -0
- package/core/BuildSystem.ff +144 -0
- package/core/Channel.ff +131 -0
- package/core/Char.ff +18 -0
- package/core/Core.ff +58 -0
- package/core/Duration.ff +15 -0
- package/core/Equal.ff +52 -0
- package/core/Error.ff +20 -0
- package/core/FileHandle.ff +41 -0
- package/core/Float.ff +41 -0
- package/core/HttpClient.ff +84 -0
- package/core/Instant.ff +9 -0
- package/core/Int.ff +61 -0
- package/core/IntMap.ff +85 -0
- package/core/JsSystem.ff +66 -0
- package/core/JsValue.ff +240 -0
- package/core/List.ff +440 -0
- package/core/Lock.ff +144 -0
- package/core/Log.ff +24 -0
- package/core/Map.ff +126 -0
- package/core/NodeSystem.ff +88 -0
- package/core/Nothing.ff +1 -0
- package/core/Option.ff +133 -0
- package/core/Ordering.ff +157 -0
- package/core/Pair.ff +55 -0
- package/core/Path.ff +393 -0
- package/core/RbMap.ff +216 -0
- package/core/Serializable.ff +173 -0
- package/core/Set.ff +38 -0
- package/core/Show.ff +43 -0
- package/core/Stack.ff +263 -0
- package/core/Stream.ff +406 -0
- package/core/String.ff +175 -0
- package/core/StringMap.ff +85 -0
- package/core/Task.ff +138 -0
- package/core/Try.ff +81 -0
- package/core/Unit.ff +3 -0
- package/experimental/random/AltGeneric.ff +44 -0
- package/experimental/random/Async.ff +68 -0
- package/experimental/random/Buffer2.ff +77 -0
- package/experimental/random/Cat.ff +12 -0
- package/experimental/random/Dictionary.ff +52 -0
- package/experimental/random/Example.ff +46 -0
- package/experimental/random/Generic.ff +102 -0
- package/experimental/random/HappyEyeballs.ff +40 -0
- package/experimental/random/HashMap.ff +72 -0
- package/experimental/random/IfElseUnit.ff +9 -0
- package/experimental/random/InputOutput.ff +23 -0
- package/experimental/random/ListVsArray.ff +45 -0
- package/experimental/random/Main.ff +44 -0
- package/experimental/random/MapTest.ff +67 -0
- package/experimental/random/OldTaskSystem.ff +210 -0
- package/experimental/random/PatternTest.ff +39 -0
- package/experimental/random/Patterns.ff +226 -0
- package/experimental/random/ReadBytesTest.ff +10 -0
- package/experimental/random/RunLength.ff +65 -0
- package/experimental/random/Scrape.ff +51 -0
- package/experimental/random/Serialization.ff +217 -0
- package/experimental/random/SerializationTest.ff +46 -0
- package/experimental/random/Serializer.ff +36 -0
- package/experimental/random/StdInOutErr.ff +4 -0
- package/experimental/random/Symbols.ff +74 -0
- package/experimental/random/Tag.ff +49 -0
- package/experimental/random/Tensor.ff +52 -0
- package/experimental/random/Try.ff +56 -0
- package/experimental/random/Tsv.ff +9 -0
- package/experimental/random/TypesAreModules.ff +87 -0
- package/experimental/random/blueprints/Blueprint.ff +52 -0
- package/experimental/random/blueprints/Main.ff +11 -0
- package/experimental/random/blueprints/Pretty.ff +58 -0
- package/experimental/random/blueprints/User.ff +64 -0
- package/experimental/random/blueprintsystem/BlueprintSystem.ff +48 -0
- package/experimental/random/blueprintsystem/Deserialize.ff +53 -0
- package/experimental/random/blueprintsystem/ReadJs.ff +13 -0
- package/experimental/random/blueprintsystem/User.ff +2 -0
- package/experimental/random/kahrs/Kahrs.ff +112 -0
- package/experimental/random/kahrs/TestKahrs.ff +22 -0
- package/experimental/random/kahrs/TestMap.ff +18 -0
- package/experimental/random/streaming/Gzip.ff +3 -0
- package/experimental/random/streaming/Main.ff +34 -0
- package/experimental/random/streaming/S3Bucket.ff +11 -0
- package/experimental/random/streaming/Tar.ff +5 -0
- package/experimental/rhymeapp/Main.ff +81 -0
- package/experimental/rhymeapp/index.html +14 -0
- package/firefly.sh +5 -0
- package/fireflysite/Main.ff +13 -0
- package/httpserver/.firefly/package.ff +1 -0
- package/httpserver/HttpServer.ff +184 -0
- package/lsp/.firefly/package.ff +1 -0
- package/lsp/CompletionHandler.ff +814 -0
- package/lsp/Handler.ff +551 -0
- package/lsp/HoverHandler.ff +82 -0
- package/lsp/LanguageServer.ff +229 -0
- package/lsp/SignatureHelpHandler.ff +55 -0
- package/lsp/SymbolHandler.ff +167 -0
- package/output/js/ff/compiler/Builder.mjs +483 -0
- package/output/js/ff/compiler/Compiler.mjs +410 -0
- package/output/js/ff/compiler/Dependencies.mjs +388 -0
- package/output/js/ff/compiler/Deriver.mjs +1166 -0
- package/output/js/ff/compiler/Dictionaries.mjs +1305 -0
- package/output/js/ff/compiler/Environment.mjs +1005 -0
- package/output/js/ff/compiler/Inference.mjs +4264 -0
- package/output/js/ff/compiler/JsEmitter.mjs +5353 -0
- package/output/js/ff/compiler/JsImporter.mjs +262 -0
- package/output/js/ff/compiler/LspHook.mjs +789 -0
- package/output/js/ff/compiler/Main.mjs +1695 -0
- package/output/js/ff/compiler/Parser.mjs +4004 -0
- package/output/js/ff/compiler/Patterns.mjs +923 -0
- package/output/js/ff/compiler/Resolver.mjs +2303 -0
- package/output/js/ff/compiler/Substitution.mjs +1146 -0
- package/output/js/ff/compiler/Syntax.mjs +12430 -0
- package/output/js/ff/compiler/Token.mjs +3092 -0
- package/output/js/ff/compiler/Tokenizer.mjs +589 -0
- package/output/js/ff/compiler/Unification.mjs +1748 -0
- package/output/js/ff/compiler/Wildcards.mjs +604 -0
- package/output/js/ff/compiler/Workspace.mjs +683 -0
- package/output/js/ff/core/Any.mjs +139 -0
- package/output/js/ff/core/Array.mjs +594 -0
- package/output/js/ff/core/AssetSystem.mjs +270 -0
- package/output/js/ff/core/Atomic.mjs +186 -0
- package/output/js/ff/core/Bool.mjs +141 -0
- package/output/js/ff/core/BrowserSystem.mjs +122 -0
- package/output/js/ff/core/Buffer.mjs +467 -0
- package/output/js/ff/core/BuildSystem.mjs +320 -0
- package/output/js/ff/core/Channel.mjs +268 -0
- package/output/js/ff/core/Char.mjs +145 -0
- package/output/js/ff/core/Core.mjs +300 -0
- package/output/js/ff/core/Duration.mjs +112 -0
- package/output/js/ff/core/Equal.mjs +175 -0
- package/output/js/ff/core/Error.mjs +138 -0
- package/output/js/ff/core/FileHandle.mjs +164 -0
- package/output/js/ff/core/Float.mjs +214 -0
- package/output/js/ff/core/HttpClient.mjs +210 -0
- package/output/js/ff/core/Instant.mjs +105 -0
- package/output/js/ff/core/Int.mjs +254 -0
- package/output/js/ff/core/IntMap.mjs +282 -0
- package/output/js/ff/core/JsSystem.mjs +234 -0
- package/output/js/ff/core/JsValue.mjs +678 -0
- package/output/js/ff/core/List.mjs +2335 -0
- package/output/js/ff/core/Lock.mjs +322 -0
- package/output/js/ff/core/Log.mjs +159 -0
- package/output/js/ff/core/Map.mjs +358 -0
- package/output/js/ff/core/NodeSystem.mjs +288 -0
- package/output/js/ff/core/Nothing.mjs +100 -0
- package/output/js/ff/core/Option.mjs +1002 -0
- package/output/js/ff/core/Ordering.mjs +734 -0
- package/output/js/ff/core/Pair.mjs +318 -0
- package/output/js/ff/core/Path.mjs +768 -0
- package/output/js/ff/core/RbMap.mjs +1936 -0
- package/output/js/ff/core/Serializable.mjs +434 -0
- package/output/js/ff/core/Set.mjs +250 -0
- package/output/js/ff/core/Show.mjs +201 -0
- package/output/js/ff/core/Stack.mjs +595 -0
- package/output/js/ff/core/Stream.mjs +1300 -0
- package/output/js/ff/core/String.mjs +433 -0
- package/output/js/ff/core/StringMap.mjs +282 -0
- package/output/js/ff/core/Task.mjs +345 -0
- package/output/js/ff/core/Try.mjs +503 -0
- package/output/js/ff/core/Unit.mjs +103 -0
- package/package.json +29 -0
- package/postgresql/.firefly/include/package-lock.json +250 -0
- package/postgresql/.firefly/include/package.json +5 -0
- package/postgresql/.firefly/include/prepare.sh +2 -0
- package/postgresql/.firefly/package.ff +3 -0
- package/postgresql/Pg.ff +530 -0
- package/unsafejs/.firefly/package.ff +1 -0
- package/unsafejs/UnsafeJs.ff +19 -0
- package/vscode/.vscode/launch.json +18 -0
- package/vscode/.vscode/tasks.json +33 -0
- package/vscode/LICENSE.txt +21 -0
- package/vscode/Prepublish.ff +15 -0
- package/vscode/README.md +17 -0
- package/vscode/client/package-lock.json +544 -0
- package/vscode/client/package.json +22 -0
- package/vscode/client/src/extension.ts +64 -0
- package/vscode/client/tsconfig.json +12 -0
- package/vscode/icons/firefly-icon.png +0 -0
- package/vscode/icons/firefly-icon.svg +10 -0
- package/vscode/icons/firefly-logo-notext.png +0 -0
- package/vscode/icons/firefly-logo.png +0 -0
- package/vscode/language-configuration.json +39 -0
- package/vscode/package-lock.json +3623 -0
- package/vscode/package.json +144 -0
- package/vscode/snippets-none.json +1 -0
- package/vscode/snippets.json +241 -0
- package/vscode/syntaxes/firefly.tmLanguage.json +294 -0
- package/vscode/tsconfig.json +20 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import Syntax
|
|
2
|
+
|
|
3
|
+
data PatternInfo(
|
|
4
|
+
variant: String
|
|
5
|
+
otherVariants: Set[String]
|
|
6
|
+
fields: List[Pair[String, PatternInfo]]
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
data PatternCaseInfo(
|
|
10
|
+
fields: List[Pair[String, PatternInfo]]
|
|
11
|
+
guard: Bool
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
check(
|
|
15
|
+
variants: Map[String, Set[String]]
|
|
16
|
+
fields: List[Pair[String, PatternInfo]]
|
|
17
|
+
cases: List[PatternCaseInfo]
|
|
18
|
+
success: Bool
|
|
19
|
+
guard: Bool
|
|
20
|
+
): Unit {
|
|
21
|
+
Pair(fields, cases).{
|
|
22
|
+
| Pair([Pair(f, PatternInfo p), ...fs], cs) =>
|
|
23
|
+
let vs = variants.get(f).else {p.otherVariants.add(p.variant)}
|
|
24
|
+
if(vs.contains(p.variant)) {
|
|
25
|
+
let newFields = p.fields.map {_.mapFirst {f + "." + p.variant + "_" + _}}
|
|
26
|
+
if(vs.size() == 1) {
|
|
27
|
+
check(variants.add(f, vs), [...newFields, ...fs], cs, True, guard)
|
|
28
|
+
} else {
|
|
29
|
+
check(variants.add(f, [p.variant].toSet()), [...newFields, ...fs], cs, True, guard)
|
|
30
|
+
check(variants.add(f, vs.remove(p.variant)), [], cs, False, guard)
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
check(variants, [], cs, False, guard)
|
|
34
|
+
}
|
|
35
|
+
| _ {success && !guard} =>
|
|
36
|
+
| Pair([], [PatternCaseInfo(fs, g), ...cs]) =>
|
|
37
|
+
check(variants, fs, cs, True, g)
|
|
38
|
+
| Pair([], []) =>
|
|
39
|
+
let remaining = variants.pairs().filter {_.second.size() != 0}.map {| Pair(f, vs) =>
|
|
40
|
+
f + " could be " + Show.show(vs.toList())
|
|
41
|
+
}
|
|
42
|
+
if(remaining.size() != 0) {
|
|
43
|
+
panic("Unexhaustive match:\n" + remaining.join("\n"))
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
convert(modules: Map[String, Module], cases: List[MatchCase]): List[PatternCaseInfo] {
|
|
49
|
+
function unqualifiedName(name: String): String {
|
|
50
|
+
name.reverse().takeWhile {_ != '.'}.reverse()
|
|
51
|
+
}
|
|
52
|
+
function otherVariants(name: String): Set[String] {
|
|
53
|
+
let variantName = unqualifiedName(name)
|
|
54
|
+
let moduleName = name.dropLast(variantName.size() + 1)
|
|
55
|
+
let variantModule = modules.grab(moduleName)
|
|
56
|
+
variantModule.types.collectFirst {definition =>
|
|
57
|
+
definition.variants.find {_.name == variantName}.map {variant =>
|
|
58
|
+
definition.variants.map {_.name}.filter {_ != variantName}.toSet()
|
|
59
|
+
}
|
|
60
|
+
}.grab()
|
|
61
|
+
}
|
|
62
|
+
function convertPattern(pattern: MatchPattern): Option[PatternInfo] {
|
|
63
|
+
| PString _ =>
|
|
64
|
+
Some(PatternInfo("String literal", ["Any other String literal"].toSet(), []))
|
|
65
|
+
| PInt _ =>
|
|
66
|
+
Some(PatternInfo("Int literal", ["Any other Int literal"].toSet(), []))
|
|
67
|
+
| PChar _ =>
|
|
68
|
+
Some(PatternInfo("Char literal", ["Any other Char literal"].toSet(), []))
|
|
69
|
+
| PVariable p =>
|
|
70
|
+
None
|
|
71
|
+
| PVariant p =>
|
|
72
|
+
let fields = p.patterns.map(convertPattern).pairs().collect {
|
|
73
|
+
| Pair(i, Some(p)) => Some(Pair("" + i, p))
|
|
74
|
+
| _ => None
|
|
75
|
+
}
|
|
76
|
+
Some(PatternInfo(unqualifiedName(p.name), otherVariants(p.name), fields))
|
|
77
|
+
| PVariantAs p =>
|
|
78
|
+
Some(PatternInfo(unqualifiedName(p.name), otherVariants(p.name), []))
|
|
79
|
+
| PAlias p =>
|
|
80
|
+
convertPattern(p.pattern)
|
|
81
|
+
}
|
|
82
|
+
cases.pairs().map {| Pair(caseIndex, case) =>
|
|
83
|
+
let fields = case.patterns.map(convertPattern).pairs().collect {
|
|
84
|
+
| Pair(i, Some(p)) => Some(Pair("" + i, p))
|
|
85
|
+
| _ => None
|
|
86
|
+
}
|
|
87
|
+
let exhaustiveGuards = case.guards.all {g =>
|
|
88
|
+
let guardConverted = convert(modules, [MatchCase(g.at, [g.pattern], [], case.body)])
|
|
89
|
+
try {
|
|
90
|
+
check([].toMap(), [], guardConverted, False, False)
|
|
91
|
+
True
|
|
92
|
+
} else {
|
|
93
|
+
False
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
PatternCaseInfo(fields, !exhaustiveGuards)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
convertAndCheck(modules: Map[String, Module], cases: List[MatchCase]): Unit {
|
|
101
|
+
let converted = convert(modules, cases)
|
|
102
|
+
try {
|
|
103
|
+
check([].toMap(), [], converted, False, False)
|
|
104
|
+
} else {
|
|
105
|
+
throw(CompileError(cases.grab(0).at, "Unexhaustive match"))
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
fail[T](at: Location, message: String): T {
|
|
110
|
+
panic(message + " " + at.show())
|
|
111
|
+
}
|