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,178 @@
|
|
|
1
|
+
import Syntax
|
|
2
|
+
|
|
3
|
+
class Substitution(mutable substitution: Map[Int, Type])
|
|
4
|
+
|
|
5
|
+
core(name: String): String {
|
|
6
|
+
"ff:core/" + name + "." + name
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
extend self: Substitution {
|
|
10
|
+
|
|
11
|
+
substituteModule(module: Module): Module {
|
|
12
|
+
let lets = module.lets.map { self.substituteLetDefinition(_) }
|
|
13
|
+
let functions = module.functions.map { self.substituteFunctionDefinition(_) }
|
|
14
|
+
let extends = module.extends.map { self.substituteExtendDefinition(_) }
|
|
15
|
+
//let traits = module.traits.map { self.substituteTraitDefinition(_) }
|
|
16
|
+
let instances = module.instances.map { self.substituteInstanceDefinition(_) }
|
|
17
|
+
module.Module(
|
|
18
|
+
//traits = traits,
|
|
19
|
+
instances = instances
|
|
20
|
+
extends = extends
|
|
21
|
+
lets = lets
|
|
22
|
+
functions = functions
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
substituteLetDefinition(definition: DLet): DLet {
|
|
27
|
+
definition.DLet(
|
|
28
|
+
variableType = self.substituteType(definition.variableType)
|
|
29
|
+
value = self.substituteTerm(definition.value)
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
substituteExtendDefinition(definition: DExtend): DExtend {
|
|
34
|
+
definition.DExtend(
|
|
35
|
+
methods = definition.methods.map { self.substituteFunctionDefinition(_) }
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
substituteFunctionDefinition(definition: DFunction): DFunction {
|
|
40
|
+
definition.DFunction(
|
|
41
|
+
signature = self.substituteSignature(definition.signature)
|
|
42
|
+
body = definition.body.mapFirefly {self.substituteLambda(_)}
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
substituteSignature(signature: Signature): Signature {
|
|
47
|
+
signature.Signature(
|
|
48
|
+
constraints = signature.constraints.map {self.substituteConstraint(_)}
|
|
49
|
+
parameters = signature.parameters.map {self.substituteParameter(_)}
|
|
50
|
+
returnType = self.substituteType(signature.returnType)
|
|
51
|
+
effect = self.substituteType(signature.effect)
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
substituteConstraint(constraint: Constraint): Constraint {
|
|
56
|
+
constraint.Constraint(
|
|
57
|
+
generics = constraint.generics.map {self.substituteType(_)}
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
substituteParameter(parameter: Parameter): Parameter {
|
|
62
|
+
parameter.Parameter(
|
|
63
|
+
valueType = self.substituteType(parameter.valueType)
|
|
64
|
+
default = parameter.default.map {self.substituteTerm(_)}
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
substituteInstanceDefinition(definition: DInstance): DInstance {
|
|
69
|
+
definition.DInstance(
|
|
70
|
+
methods = definition.methods.map { self.substituteFunctionDefinition(_) }
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
substituteLambda(definition: Lambda): Lambda {
|
|
75
|
+
definition.Lambda(
|
|
76
|
+
effect = self.substituteType(definition.effect)
|
|
77
|
+
cases = definition.cases.map { case =>
|
|
78
|
+
case.MatchCase(
|
|
79
|
+
guards = case.guards.map { g => g.MatchGuard(term = self.substituteTerm(g.term)) }
|
|
80
|
+
body = self.substituteTerm(case.body)
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
substituteTerm(term: Term): Term {
|
|
87
|
+
term.{
|
|
88
|
+
| EString _ => term
|
|
89
|
+
| EChar _ => term
|
|
90
|
+
| EInt _ => term
|
|
91
|
+
| EFloat _ => term
|
|
92
|
+
| EVariable _ => term
|
|
93
|
+
| EField e => e.EField(record = self.substituteTerm(e.record))
|
|
94
|
+
| EWildcard e => term
|
|
95
|
+
| EList e => e.EList(
|
|
96
|
+
elementType = self.substituteType(e.elementType)
|
|
97
|
+
items = e.items.map {| Pair(item, b) => Pair(self.substituteTerm(item), b) }
|
|
98
|
+
)
|
|
99
|
+
| ESequential e => e.ESequential(
|
|
100
|
+
before = self.substituteTerm(e.before)
|
|
101
|
+
after = self.substituteTerm(e.after)
|
|
102
|
+
)
|
|
103
|
+
| ELet e => e.ELet(
|
|
104
|
+
valueType = self.substituteType(e.valueType)
|
|
105
|
+
value = self.substituteTerm(e.value)
|
|
106
|
+
body = self.substituteTerm(e.body)
|
|
107
|
+
)
|
|
108
|
+
| ELambda e => e.ELambda(lambda = self.substituteLambda(e.lambda))
|
|
109
|
+
| EVariant e => e.EVariant(
|
|
110
|
+
typeArguments = e.typeArguments.map {self.substituteType(_)}
|
|
111
|
+
arguments = e.arguments.map { _.map {self.substituteArgument(_)} }
|
|
112
|
+
)
|
|
113
|
+
| EVariantIs e => e.EVariantIs(
|
|
114
|
+
typeArguments = e.typeArguments.map {self.substituteType(_)}
|
|
115
|
+
)
|
|
116
|
+
| ECopy e => e.ECopy(
|
|
117
|
+
record = self.substituteTerm(e.record)
|
|
118
|
+
arguments = e.arguments.map {self.substituteField(_)}
|
|
119
|
+
)
|
|
120
|
+
| EPipe e => e.EPipe(
|
|
121
|
+
value = self.substituteTerm(e.value)
|
|
122
|
+
effect = self.substituteType(e.effect)
|
|
123
|
+
function = self.substituteTerm(e.function)
|
|
124
|
+
)
|
|
125
|
+
| ECall e => e.ECall(
|
|
126
|
+
target = e.target.{
|
|
127
|
+
| DynamicCall call => call.DynamicCall(function = self.substituteTerm(call.function))
|
|
128
|
+
| StaticCall _ => e.target
|
|
129
|
+
}
|
|
130
|
+
effect = self.substituteType(e.effect)
|
|
131
|
+
typeArguments = e.typeArguments.map {self.substituteType(_)}
|
|
132
|
+
arguments = e.arguments.map {self.substituteArgument(_)}
|
|
133
|
+
)
|
|
134
|
+
| ERecord e => e.ERecord(fields = e.fields.map {self.substituteField(_)})
|
|
135
|
+
| EFunctions e => e.EFunctions(
|
|
136
|
+
functions = e.functions.map {self.substituteFunctionDefinition(_)}
|
|
137
|
+
body = self.substituteTerm(e.body)
|
|
138
|
+
)
|
|
139
|
+
| EAssign e => e.EAssign(value = self.substituteTerm(e.value))
|
|
140
|
+
| EAssignField e => e.EAssignField(
|
|
141
|
+
record = self.substituteTerm(e.record)
|
|
142
|
+
value = self.substituteTerm(e.value)
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
substituteArgument(argument: Argument): Argument {
|
|
148
|
+
argument.Argument(value = self.substituteTerm(argument.value))
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
substituteField(field: Field): Field {
|
|
152
|
+
field.Field(value = self.substituteTerm(field.value))
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
substituteType(type: Type): Type {
|
|
156
|
+
| TVariable(at, i) =>
|
|
157
|
+
if(self.has(i)) { self.substituteType(self.get(i)) } else { TConstructor(at, core("Nothing"), []) }
|
|
158
|
+
| TConstructor t =>
|
|
159
|
+
t.TConstructor(generics = t.generics.map { t => self.substituteType(t) })
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
get(index: Int): Type {
|
|
163
|
+
self.substitution.grab(index).{
|
|
164
|
+
| TVariable(_, i) { self.has(i) } =>
|
|
165
|
+
let t = self.get(i)
|
|
166
|
+
self.substitution = self.substitution.add(index, t)
|
|
167
|
+
t
|
|
168
|
+
| TVariable(at, _) =>
|
|
169
|
+
TConstructor(at, core("Nothing"), [])
|
|
170
|
+
| t => t
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
has(index: Int): Bool {
|
|
175
|
+
self.substitution.contains(index)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
data Location(file: String, line: Int, column: Int)
|
|
2
|
+
|
|
3
|
+
extend self: Location {
|
|
4
|
+
show(): String {
|
|
5
|
+
"in " + self.file + " " +
|
|
6
|
+
"at line " + self.line +
|
|
7
|
+
", column " + self.column
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
data CompileError(at: Location, message: String)
|
|
12
|
+
|
|
13
|
+
data ModuleWithPackageInfo(
|
|
14
|
+
packageInfo: Option[PackageInfo]
|
|
15
|
+
module: Module
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
data PackageInfo(
|
|
19
|
+
package: DPackage
|
|
20
|
+
dependencies: List[DDependency]
|
|
21
|
+
includes: List[DInclude]
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
data Module(
|
|
25
|
+
file: String
|
|
26
|
+
packagePair: PackagePair
|
|
27
|
+
imports: List[DImport]
|
|
28
|
+
types: List[DType]
|
|
29
|
+
traits: List[DTrait]
|
|
30
|
+
instances: List[DInstance]
|
|
31
|
+
extends: List[DExtend]
|
|
32
|
+
lets: List[DLet]
|
|
33
|
+
functions: List[DFunction]
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
data PackagePair(
|
|
37
|
+
group: String
|
|
38
|
+
name: String
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
extend self: PackagePair {
|
|
42
|
+
groupName(delimiter: String = ":"): String {
|
|
43
|
+
self.group + delimiter + self.name
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
data DPackage(
|
|
48
|
+
at: Location
|
|
49
|
+
packagePair: PackagePair
|
|
50
|
+
version: Version
|
|
51
|
+
targets: TargetNames
|
|
52
|
+
)
|
|
53
|
+
data DDependency(
|
|
54
|
+
at: Location
|
|
55
|
+
packagePair: PackagePair
|
|
56
|
+
version: Version
|
|
57
|
+
safety: Safety
|
|
58
|
+
targets: TargetNames
|
|
59
|
+
)
|
|
60
|
+
data DInclude(
|
|
61
|
+
at: Location
|
|
62
|
+
path: String
|
|
63
|
+
)
|
|
64
|
+
data TargetNames(
|
|
65
|
+
node: Bool
|
|
66
|
+
browser: Bool
|
|
67
|
+
)
|
|
68
|
+
data DImport(
|
|
69
|
+
at: Location
|
|
70
|
+
alias: String
|
|
71
|
+
package: PackagePair
|
|
72
|
+
directory: List[String]
|
|
73
|
+
file: String
|
|
74
|
+
)
|
|
75
|
+
data DFunction(
|
|
76
|
+
at: Location
|
|
77
|
+
signature: Signature
|
|
78
|
+
body: Target
|
|
79
|
+
)
|
|
80
|
+
data DLet(
|
|
81
|
+
at: Location
|
|
82
|
+
name: String
|
|
83
|
+
variableType: Type
|
|
84
|
+
value: Term
|
|
85
|
+
)
|
|
86
|
+
data DExtend(
|
|
87
|
+
at: Location
|
|
88
|
+
name: String
|
|
89
|
+
generics: List[String]
|
|
90
|
+
constraints: List[Constraint]
|
|
91
|
+
type: Type
|
|
92
|
+
methods: List[DFunction]
|
|
93
|
+
)
|
|
94
|
+
data DType(
|
|
95
|
+
at: Location
|
|
96
|
+
newtype: Bool
|
|
97
|
+
data: Bool
|
|
98
|
+
name: String
|
|
99
|
+
generics: List[String]
|
|
100
|
+
constraints: List[Constraint]
|
|
101
|
+
commonFields: List[Parameter]
|
|
102
|
+
variants: List[Variant]
|
|
103
|
+
)
|
|
104
|
+
data DTrait(
|
|
105
|
+
at: Location
|
|
106
|
+
name: String
|
|
107
|
+
generics: List[String]
|
|
108
|
+
constraints: List[Constraint]
|
|
109
|
+
generatorParameters: List[Parameter]
|
|
110
|
+
methods: List[Signature]
|
|
111
|
+
methodDefaults: List[Pair[String, Lambda]]
|
|
112
|
+
methodGenerators: List[Pair[String, Lambda]]
|
|
113
|
+
)
|
|
114
|
+
data DInstance(
|
|
115
|
+
at: Location
|
|
116
|
+
generics: List[String]
|
|
117
|
+
constraints: List[Constraint]
|
|
118
|
+
traitName: String
|
|
119
|
+
typeArguments: List[Type]
|
|
120
|
+
generatorArguments: List[Argument]
|
|
121
|
+
methods: List[DFunction]
|
|
122
|
+
derived: Bool
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
data Term(at: Location) {
|
|
126
|
+
EString(value: String)
|
|
127
|
+
EChar(value: String)
|
|
128
|
+
EInt(value: String)
|
|
129
|
+
EFloat(value: String)
|
|
130
|
+
EVariable(name: String)
|
|
131
|
+
ELambda(lambda: Lambda)
|
|
132
|
+
EFunctions(functions: List[DFunction], body: Term)
|
|
133
|
+
ELet(mutable: Bool, name: String, valueType: Type, value: Term, body: Term)
|
|
134
|
+
ESequential(before: Term, after: Term)
|
|
135
|
+
EAssign(operator: String, variable: String, value: Term)
|
|
136
|
+
EAssignField(operator: String, record: Term, field: String, value: Term)
|
|
137
|
+
EPipe(value: Term, effect: Type, function: Term)
|
|
138
|
+
ECall(
|
|
139
|
+
target: CallTarget
|
|
140
|
+
effect: Type
|
|
141
|
+
typeArguments: List[Type]
|
|
142
|
+
arguments: List[Argument]
|
|
143
|
+
dictionaries: List[Dictionary]
|
|
144
|
+
)
|
|
145
|
+
EList(elementType: Type, items: List[Pair[Term, Bool]])
|
|
146
|
+
ECopy(name: String, record: Term, arguments: List[Field])
|
|
147
|
+
EVariant(name: String, typeArguments: List[Type], arguments: Option[List[Argument]])
|
|
148
|
+
EVariantIs(name: String, typeArguments: List[Type])
|
|
149
|
+
ERecord(fields: List[Field])
|
|
150
|
+
EField(newtype: Bool, record: Term, field: String)
|
|
151
|
+
EWildcard(index: Int)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
data CallTarget {
|
|
155
|
+
DynamicCall(function: Term, tailCall: Bool)
|
|
156
|
+
StaticCall(name: String, tailCall: Bool, instanceCall: Bool)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
data MatchCase(
|
|
160
|
+
at: Location
|
|
161
|
+
patterns: List[MatchPattern]
|
|
162
|
+
guards: List[MatchGuard]
|
|
163
|
+
body: Term
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
data MatchPattern(at: Location) {
|
|
167
|
+
PString(value: String)
|
|
168
|
+
PInt(value: String)
|
|
169
|
+
PChar(value: String)
|
|
170
|
+
PVariable(name: Option[String])
|
|
171
|
+
PVariant(name: String, patterns: List[MatchPattern])
|
|
172
|
+
PVariantAs(name: String, variableAt: Location, variable: Option[String])
|
|
173
|
+
PAlias(pattern: MatchPattern, variable: String)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
data MatchGuard(
|
|
177
|
+
at: Location
|
|
178
|
+
term: Term
|
|
179
|
+
pattern: MatchPattern
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
data Dictionary(
|
|
183
|
+
packagePair: PackagePair
|
|
184
|
+
moduleName: String
|
|
185
|
+
traitName: String
|
|
186
|
+
typeName: String
|
|
187
|
+
dictionaries: List[Dictionary]
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
data Signature(
|
|
191
|
+
at: Location
|
|
192
|
+
name: String
|
|
193
|
+
member: Bool
|
|
194
|
+
generics: List[String]
|
|
195
|
+
constraints: List[Constraint]
|
|
196
|
+
parameters: List[Parameter]
|
|
197
|
+
returnType: Type
|
|
198
|
+
effect: Type
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
data Lambda(at: Location, effect: Type, cases: List[MatchCase])
|
|
202
|
+
|
|
203
|
+
data Variant(at: Location, name: String, fields: List[Parameter])
|
|
204
|
+
|
|
205
|
+
data Parameter(at: Location, mutable: Bool, name: String, valueType: Type, default: Option[Term])
|
|
206
|
+
|
|
207
|
+
data Argument(at: Location, name: Option[String], value: Term)
|
|
208
|
+
|
|
209
|
+
data Field(at: Location, name: String, value: Term)
|
|
210
|
+
|
|
211
|
+
data Constraint(at: Location, name: String, generics: List[Type])
|
|
212
|
+
|
|
213
|
+
data Target {
|
|
214
|
+
FireflyTarget(lambda: Lambda)
|
|
215
|
+
ForeignTarget(syncCode: Option[String], asyncCode: Option[String])
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
data Type(at: Location) {
|
|
219
|
+
TConstructor(name: String, generics: List[Type])
|
|
220
|
+
TVariable(index: Int)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
data Safety {
|
|
224
|
+
Safe
|
|
225
|
+
Unsafe
|
|
226
|
+
Trusted
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
data Version(at: Location, major: Int, minor: Int, patch: Int)
|
|
230
|
+
|
|
231
|
+
extend self: Type {
|
|
232
|
+
show(shownTypes: List[Type]): String {
|
|
233
|
+
mutable seenTypes = Map.empty()
|
|
234
|
+
let typeNames = 'a'.codeUnit.to('z'.codeUnit).map {Char(_).toString()}.toStream()
|
|
235
|
+
function shortenType(qualified: String): String {
|
|
236
|
+
qualified.reverse().takeWhile {_ != '.'}.reverse()
|
|
237
|
+
}
|
|
238
|
+
function shortenTypes(types: List[Type]) {
|
|
239
|
+
types.each {
|
|
240
|
+
| TConstructor(_, name, typeArguments) =>
|
|
241
|
+
let shortenedName = shortenType(name)
|
|
242
|
+
seenTypes.get(shortenedName).{
|
|
243
|
+
| None =>
|
|
244
|
+
seenTypes = seenTypes.add(shortenedName, name)
|
|
245
|
+
| Some(qualified) =>
|
|
246
|
+
if(name != qualified) {
|
|
247
|
+
seenTypes = seenTypes.add(shortenedName, "")
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
shortenTypes(typeArguments)
|
|
251
|
+
| TVariable(_, index) =>
|
|
252
|
+
if(!seenTypes.contains("$" + index)) {
|
|
253
|
+
seenTypes = seenTypes.add("$" + index, typeNames.next().else {"$" + index})
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
shortenTypes([...shownTypes, self])
|
|
258
|
+
function go(type: Type): String {
|
|
259
|
+
type.{
|
|
260
|
+
| TConstructor(at, name, [_, r]) {name.startsWith("Function$")} =>
|
|
261
|
+
"() => " + go(r)
|
|
262
|
+
| TConstructor(at, name, [_, a, r]) {name.startsWith("Function$")} =>
|
|
263
|
+
go(a) + " => " + go(r)
|
|
264
|
+
| TConstructor(at, name, [_, ...generics]) {name.startsWith("Function$")} =>
|
|
265
|
+
"(" + generics.dropLast().map {go(_)}.join(", ") + ") => " + go(generics.grabLast())
|
|
266
|
+
| TConstructor(at, name, generics) {name.startsWith("Record$")} =>
|
|
267
|
+
let as = name.split('$').toList().dropFirst().zip(generics)
|
|
268
|
+
"(" + as.map {| Pair(label, t) => label + ": " + go(t)}.join(", ") + ")"
|
|
269
|
+
| TConstructor(at, name, generics) =>
|
|
270
|
+
let shortenedName = shortenType(name)
|
|
271
|
+
let chosenName = seenTypes.grab(shortenedName).{
|
|
272
|
+
| "" => name
|
|
273
|
+
| _ => shortenedName
|
|
274
|
+
}
|
|
275
|
+
let filteredGenerics = generics.filter {
|
|
276
|
+
// Hack to hide the effect, only works when the effect is Q$
|
|
277
|
+
| TConstructor(_, "Q$", _) => False
|
|
278
|
+
| _ => True
|
|
279
|
+
}
|
|
280
|
+
if(filteredGenerics.isEmpty()) {chosenName} else {
|
|
281
|
+
chosenName + "[" + filteredGenerics.map {go(_)}.join(", ") + "]"
|
|
282
|
+
}
|
|
283
|
+
| TVariable(at, index) =>
|
|
284
|
+
seenTypes.grab("$" + index)
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
go(self)
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
extend self: Target {
|
|
292
|
+
mapFirefly(body: Lambda => Lambda): Target {
|
|
293
|
+
self.{
|
|
294
|
+
| FireflyTarget(lambda) => FireflyTarget(body(lambda))
|
|
295
|
+
| ForeignTarget(_, _) => self
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import Syntax
|
|
2
|
+
|
|
3
|
+
data Token(
|
|
4
|
+
file: String
|
|
5
|
+
code: String
|
|
6
|
+
kind: TokenKind
|
|
7
|
+
startLine: Int
|
|
8
|
+
startLineOffset: Int
|
|
9
|
+
startOffset: Int
|
|
10
|
+
stopLine: Int
|
|
11
|
+
stopLineOffset: Int
|
|
12
|
+
stopOffset: Int
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
extend token: Token {
|
|
16
|
+
|
|
17
|
+
at(): Location {
|
|
18
|
+
Location(token.file, token.startLine, (token.startOffset - token.startLineOffset) + 1)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
end(): Location {
|
|
22
|
+
Location(token.file, token.startLine, (token.stopOffset - token.startLineOffset) + 1)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
raw(): String {
|
|
26
|
+
token.code.slice(token.startOffset, token.stopOffset)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
is(kind1: TokenKind): Bool {
|
|
30
|
+
token.kind == kind1
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
is2(kind1: TokenKind, kind2: TokenKind): Bool {
|
|
34
|
+
token.kind == kind1 || token.kind == kind2
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
is3(kind1: TokenKind, kind2: TokenKind, kind3: TokenKind): Bool {
|
|
38
|
+
token.kind == kind1 || token.kind == kind2 || token.kind == kind3
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
rawIs(value: String): Bool {
|
|
42
|
+
token.stopOffset - token.startOffset == value.size() &&
|
|
43
|
+
token.code.startsWith(value, token.startOffset)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
rawIs2(value1: String, value2: String): Bool {
|
|
47
|
+
token.rawIs(value1) || token.rawIs(value2)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
rawIs3(value1: String, value2: String, value3: String): Bool {
|
|
51
|
+
token.rawIs(value1) || token.rawIs(value2) || token.rawIs(value3)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
rawIs4(value1: String, value2: String, value3: String, value4: String): Bool {
|
|
55
|
+
token.rawIs(value1) || token.rawIs(value2) || token.rawIs(value3) || token.rawIs(value4)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
data TokenKind {
|
|
61
|
+
LEnd
|
|
62
|
+
LString
|
|
63
|
+
LChar
|
|
64
|
+
LInt
|
|
65
|
+
LFloat
|
|
66
|
+
LKeyword
|
|
67
|
+
LNamespace
|
|
68
|
+
LLower
|
|
69
|
+
LUpper
|
|
70
|
+
LWildcard
|
|
71
|
+
LBracketLeft
|
|
72
|
+
LBracketRight
|
|
73
|
+
LOperator
|
|
74
|
+
LComma
|
|
75
|
+
LSeparator
|
|
76
|
+
LDot
|
|
77
|
+
LSemicolon
|
|
78
|
+
LPipe
|
|
79
|
+
LColon
|
|
80
|
+
LDotDotDot
|
|
81
|
+
LArrowThick
|
|
82
|
+
LAssign
|
|
83
|
+
LAssignPlus
|
|
84
|
+
LAssignMinus
|
|
85
|
+
LAssignLink
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
extend self: TokenKind {
|
|
89
|
+
|
|
90
|
+
beforeSeparator(): Bool {
|
|
91
|
+
self.{
|
|
92
|
+
| LEnd => False
|
|
93
|
+
| LString => True
|
|
94
|
+
| LChar => True
|
|
95
|
+
| LInt => True
|
|
96
|
+
| LFloat => True
|
|
97
|
+
| LKeyword => True
|
|
98
|
+
| LNamespace => False
|
|
99
|
+
| LLower => True
|
|
100
|
+
| LUpper => True
|
|
101
|
+
| LWildcard => True
|
|
102
|
+
| LBracketLeft => False
|
|
103
|
+
| LBracketRight => True
|
|
104
|
+
| LOperator => False
|
|
105
|
+
| LComma => False
|
|
106
|
+
| LSeparator => False
|
|
107
|
+
| LDot => False
|
|
108
|
+
| LSemicolon => False
|
|
109
|
+
| LPipe => False
|
|
110
|
+
| LColon => False
|
|
111
|
+
| LDotDotDot => False
|
|
112
|
+
| LArrowThick => False
|
|
113
|
+
| LAssign => False
|
|
114
|
+
| LAssignPlus => False
|
|
115
|
+
| LAssignMinus => False
|
|
116
|
+
| LAssignLink => False
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
afterSeparator(): Bool {
|
|
121
|
+
self.{
|
|
122
|
+
| LEnd => False
|
|
123
|
+
| LString => True
|
|
124
|
+
| LChar => True
|
|
125
|
+
| LInt => True
|
|
126
|
+
| LFloat => True
|
|
127
|
+
| LKeyword => True
|
|
128
|
+
| LNamespace => True
|
|
129
|
+
| LLower => True
|
|
130
|
+
| LUpper => True
|
|
131
|
+
| LWildcard => True
|
|
132
|
+
| LBracketLeft => True
|
|
133
|
+
| LBracketRight => False
|
|
134
|
+
| LOperator => False
|
|
135
|
+
| LComma => False
|
|
136
|
+
| LSeparator => False
|
|
137
|
+
| LDot => False
|
|
138
|
+
| LSemicolon => False
|
|
139
|
+
| LPipe => False
|
|
140
|
+
| LColon => False
|
|
141
|
+
| LDotDotDot => True
|
|
142
|
+
| LArrowThick => False
|
|
143
|
+
| LAssign => False
|
|
144
|
+
| LAssignPlus => False
|
|
145
|
+
| LAssignMinus => False
|
|
146
|
+
| LAssignLink => False
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
afterKeyword(): Bool {
|
|
151
|
+
self.{
|
|
152
|
+
| LEnd => False
|
|
153
|
+
| LString => True
|
|
154
|
+
| LChar => True
|
|
155
|
+
| LInt => True
|
|
156
|
+
| LFloat => True
|
|
157
|
+
| LKeyword => True
|
|
158
|
+
| LNamespace => True
|
|
159
|
+
| LLower => True
|
|
160
|
+
| LUpper => True
|
|
161
|
+
| LWildcard => True
|
|
162
|
+
| LBracketLeft => False
|
|
163
|
+
| LBracketRight => False
|
|
164
|
+
| LOperator => False
|
|
165
|
+
| LComma => False
|
|
166
|
+
| LSeparator => False
|
|
167
|
+
| LDot => False
|
|
168
|
+
| LSemicolon => False
|
|
169
|
+
| LPipe => False
|
|
170
|
+
| LColon => False
|
|
171
|
+
| LDotDotDot => False
|
|
172
|
+
| LArrowThick => False
|
|
173
|
+
| LAssign => False
|
|
174
|
+
| LAssignPlus => False
|
|
175
|
+
| LAssignMinus => False
|
|
176
|
+
| LAssignLink => False
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
}
|