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,179 @@
|
|
|
1
|
+
import Parser
|
|
2
|
+
import Syntax
|
|
3
|
+
import Tokenizer
|
|
4
|
+
import Workspace
|
|
5
|
+
import LspHook
|
|
6
|
+
|
|
7
|
+
capability Dependencies(
|
|
8
|
+
workspace: Workspace
|
|
9
|
+
mutable packages: Map[PackagePair, PackageInfo]
|
|
10
|
+
mutable packagePaths: Map[PackagePair, Path]
|
|
11
|
+
mutable singleFilePackages: Set[PackagePair]
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
capability ResolvedDependencies(
|
|
15
|
+
mainPackagePair: PackagePair
|
|
16
|
+
packages: Map[PackagePair, PackageInfo]
|
|
17
|
+
packagePaths: Map[PackagePair, Path]
|
|
18
|
+
singleFilePackages: Set[PackagePair]
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
extend self: Dependencies {
|
|
22
|
+
|
|
23
|
+
loadPackageInfo(
|
|
24
|
+
packagePair: PackagePair
|
|
25
|
+
path: Path
|
|
26
|
+
): PackageInfo {
|
|
27
|
+
let packageDirectory = if(path.extension() == ".ff") {path.parent().grab()} else {path}
|
|
28
|
+
let sharedPackageFile = packageDirectory.slash(".firefly").slash("package.ff")
|
|
29
|
+
let packageFile = if(sharedPackageFile.exists()) {
|
|
30
|
+
sharedPackageFile
|
|
31
|
+
} else {
|
|
32
|
+
self.singleFilePackages = self.singleFilePackages.add(packagePair)
|
|
33
|
+
path
|
|
34
|
+
}
|
|
35
|
+
let code = packageFile.readText()
|
|
36
|
+
self.parsePackageFile(packagePair, packageFile.relativeTo(path), code)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
parsePackageFile(
|
|
40
|
+
packagePair: PackagePair
|
|
41
|
+
fileName: String
|
|
42
|
+
code: String
|
|
43
|
+
): PackageInfo {
|
|
44
|
+
let tokens = Tokenizer.tokenize(fileName, code, None, True)
|
|
45
|
+
let parser = Parser.make(packagePair, fileName, tokens, False, LspHook.disabled())
|
|
46
|
+
let info = parser.parsePackageInfo()
|
|
47
|
+
self.addCoreDependencyIfMissing(info)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
addCoreDependencyIfMissing(info: PackageInfo): PackageInfo {
|
|
51
|
+
if(info.dependencies.any {d =>
|
|
52
|
+
d.packagePair.group == "ff" && d.packagePair.name == "core"
|
|
53
|
+
}) {
|
|
54
|
+
info
|
|
55
|
+
} else {
|
|
56
|
+
let coreDependency = DDependency(
|
|
57
|
+
at = info.package.at
|
|
58
|
+
packagePair = PackagePair("ff", "core")
|
|
59
|
+
version = Version(info.package.at, 0, 0, 0)
|
|
60
|
+
safety = Trusted
|
|
61
|
+
targets = info.package.targets
|
|
62
|
+
)
|
|
63
|
+
info.PackageInfo(dependencies = [coreDependency, ...info.dependencies])
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
processPackageInfo(
|
|
68
|
+
packageInfo: PackageInfo
|
|
69
|
+
): List[DDependency] {
|
|
70
|
+
self.packages = self.packages.add(packageInfo.package.packagePair, packageInfo)
|
|
71
|
+
packageInfo.dependencies.filter {!self.packages.contains(_.packagePair)}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
fetchDependency(
|
|
75
|
+
path: Path
|
|
76
|
+
httpClient: HttpClient
|
|
77
|
+
dependency: DDependency
|
|
78
|
+
): Path {
|
|
79
|
+
let location = self.workspace.findPackageLocation(dependency.packagePair, dependency.version)
|
|
80
|
+
if(location.contains(":") && !location.dropFirst(1).startsWith(":")) {
|
|
81
|
+
if(location.startsWith("http://") || location.startsWith("https://")) {
|
|
82
|
+
let packagePair = dependency.packagePair
|
|
83
|
+
let directory = if(path.isDirectory()) {path} else {path.parent().grab()}
|
|
84
|
+
let dependenciesPath = directory.slash(".firefly").slash("dependencies")
|
|
85
|
+
let dependencyPath = dependenciesPath.slash(packagePair.group).slash(packagePair.name)
|
|
86
|
+
let tarGzPath = dependenciesPath.slash(Workspace.tarGzName(packagePair, dependency.version))
|
|
87
|
+
let donePath = dependenciesPath.slash(Workspace.tarGzName(packagePair, dependency.version) + ".done")
|
|
88
|
+
if(!donePath.exists()) {
|
|
89
|
+
Log.trace("Fetching " + location)
|
|
90
|
+
let response = httpClient.fetch(location, throw = False)
|
|
91
|
+
if(!response.ok()) {
|
|
92
|
+
panic("Could not download dependency: " + location)
|
|
93
|
+
}
|
|
94
|
+
let buffer = response.readBuffer()
|
|
95
|
+
if(dependencyPath.exists()) {
|
|
96
|
+
dependencyPath.delete()
|
|
97
|
+
}
|
|
98
|
+
dependencyPath.createDirectory(createParentDirectories = True)
|
|
99
|
+
tarGzPath.writeStream([buffer].toStream())
|
|
100
|
+
internalExtractTarGz(tarGzPath, dependencyPath)
|
|
101
|
+
tarGzPath.renameTo(donePath)
|
|
102
|
+
}
|
|
103
|
+
dependencyPath
|
|
104
|
+
} else {
|
|
105
|
+
panic("Loading packages by this protocol is not supported: " + location)
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
path.path(location)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
processDependencies(
|
|
113
|
+
path: Path
|
|
114
|
+
httpClient: HttpClient
|
|
115
|
+
dependencies: List[DDependency]
|
|
116
|
+
): Unit {
|
|
117
|
+
// Remember to check for cycles
|
|
118
|
+
let packageInfos = dependencies.map {dependency =>
|
|
119
|
+
let dependencyPath = self.fetchDependency(path, httpClient, dependency)
|
|
120
|
+
self.packagePaths = self.packagePaths.add(dependency.packagePair, dependencyPath)
|
|
121
|
+
let packageInfo = self.loadPackageInfo(dependency.packagePair, dependencyPath)
|
|
122
|
+
checkPackagePairs(dependency.packagePair, packageInfo.package.packagePair)
|
|
123
|
+
packageInfo
|
|
124
|
+
}
|
|
125
|
+
let newDependencies = packageInfos.flatMap {self.processPackageInfo(_)}
|
|
126
|
+
if(newDependencies != []) {
|
|
127
|
+
self.processDependencies(path, httpClient, newDependencies)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
process(fetch: HttpClient, path: Path): ResolvedDependencies {
|
|
134
|
+
let workspace = Workspace.loadWorkspace(path)
|
|
135
|
+
let self = Dependencies(workspace, [].toMap(), [].toMap(), [].toSet())
|
|
136
|
+
let packageInfo = self.loadPackageInfo(PackagePair("script", "script"), path)
|
|
137
|
+
let newDependencies = self.processPackageInfo(packageInfo)
|
|
138
|
+
self.processDependencies(path, fetch, newDependencies)
|
|
139
|
+
let packagePaths = self.packagePaths.add(packageInfo.package.packagePair, findScriptPackageLocation(path))
|
|
140
|
+
ResolvedDependencies(
|
|
141
|
+
mainPackagePair = packageInfo.package.packagePair
|
|
142
|
+
packages = self.packages
|
|
143
|
+
packagePaths = packagePaths
|
|
144
|
+
singleFilePackages = self.singleFilePackages
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
findScriptPackageLocation(path: Path): Path {
|
|
149
|
+
let packageDirectory = if(path.extension() == ".ff") {path.parent().grab()} else {path}
|
|
150
|
+
function go(directory: Path): Path {
|
|
151
|
+
let packageFile = directory.slash(".firefly").slash("package.ff")
|
|
152
|
+
if(packageFile.exists()) {
|
|
153
|
+
directory
|
|
154
|
+
} elseIf {!directory.parent().isEmpty()} {
|
|
155
|
+
go(directory.parent().grab())
|
|
156
|
+
} else {
|
|
157
|
+
packageDirectory
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
go(packageDirectory)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
checkPackagePairs(dependencyPair: PackagePair, packagePair: PackagePair): Unit {
|
|
164
|
+
if(
|
|
165
|
+
packagePair.group != dependencyPair.group ||
|
|
166
|
+
packagePair.name != dependencyPair.name
|
|
167
|
+
) {
|
|
168
|
+
panic(
|
|
169
|
+
"Dependency declaration and package declaration disagree on package name: " +
|
|
170
|
+
dependencyPair.groupName() + " vs. " + packagePair.groupName()
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
internalExtractTarGz(tarGzPath: Path, path: Path): Unit
|
|
176
|
+
target node async """
|
|
177
|
+
import * as tar from 'tar'
|
|
178
|
+
await tar.extract({file: tarGzPath_, cwd: path_, strict: true})
|
|
179
|
+
"""
|