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.
Files changed (221) hide show
  1. package/.firefly-workspace +1 -0
  2. package/.vscode/settings.json +5 -0
  3. package/LICENSE.txt +21 -0
  4. package/README.md +96 -0
  5. package/bin/firefly.mjs +2 -0
  6. package/compiler/.firefly/package.ff +1 -0
  7. package/compiler/Builder.ff +218 -0
  8. package/compiler/Compiler.ff +241 -0
  9. package/compiler/Dependencies.ff +179 -0
  10. package/compiler/Deriver.ff +647 -0
  11. package/compiler/Dictionaries.ff +205 -0
  12. package/compiler/Environment.ff +166 -0
  13. package/compiler/Inference.ff +1117 -0
  14. package/compiler/JsEmitter.ff +861 -0
  15. package/compiler/JsImporter.ff +56 -0
  16. package/compiler/LspHook.ff +188 -0
  17. package/compiler/Main.ff +237 -0
  18. package/compiler/Parser.ff +1383 -0
  19. package/compiler/Patterns.ff +111 -0
  20. package/compiler/Resolver.ff +620 -0
  21. package/compiler/Substitution.ff +178 -0
  22. package/compiler/Syntax.ff +299 -0
  23. package/compiler/Token.ff +180 -0
  24. package/compiler/Tokenizer.ff +278 -0
  25. package/compiler/Unification.ff +220 -0
  26. package/compiler/Wildcards.ff +50 -0
  27. package/compiler/Workspace.ff +88 -0
  28. package/core/.firefly/package.ff +2 -0
  29. package/core/Any.ff +30 -0
  30. package/core/Array.ff +249 -0
  31. package/core/AssetSystem.ff +61 -0
  32. package/core/Atomic.ff +64 -0
  33. package/core/Bool.ff +13 -0
  34. package/core/BrowserSystem.ff +14 -0
  35. package/core/Buffer.ff +211 -0
  36. package/core/BuildSystem.ff +144 -0
  37. package/core/Channel.ff +131 -0
  38. package/core/Char.ff +18 -0
  39. package/core/Core.ff +58 -0
  40. package/core/Duration.ff +15 -0
  41. package/core/Equal.ff +52 -0
  42. package/core/Error.ff +20 -0
  43. package/core/FileHandle.ff +41 -0
  44. package/core/Float.ff +41 -0
  45. package/core/HttpClient.ff +84 -0
  46. package/core/Instant.ff +9 -0
  47. package/core/Int.ff +61 -0
  48. package/core/IntMap.ff +85 -0
  49. package/core/JsSystem.ff +66 -0
  50. package/core/JsValue.ff +240 -0
  51. package/core/List.ff +440 -0
  52. package/core/Lock.ff +144 -0
  53. package/core/Log.ff +24 -0
  54. package/core/Map.ff +126 -0
  55. package/core/NodeSystem.ff +88 -0
  56. package/core/Nothing.ff +1 -0
  57. package/core/Option.ff +133 -0
  58. package/core/Ordering.ff +157 -0
  59. package/core/Pair.ff +55 -0
  60. package/core/Path.ff +393 -0
  61. package/core/RbMap.ff +216 -0
  62. package/core/Serializable.ff +173 -0
  63. package/core/Set.ff +38 -0
  64. package/core/Show.ff +43 -0
  65. package/core/Stack.ff +263 -0
  66. package/core/Stream.ff +406 -0
  67. package/core/String.ff +175 -0
  68. package/core/StringMap.ff +85 -0
  69. package/core/Task.ff +138 -0
  70. package/core/Try.ff +81 -0
  71. package/core/Unit.ff +3 -0
  72. package/experimental/random/AltGeneric.ff +44 -0
  73. package/experimental/random/Async.ff +68 -0
  74. package/experimental/random/Buffer2.ff +77 -0
  75. package/experimental/random/Cat.ff +12 -0
  76. package/experimental/random/Dictionary.ff +52 -0
  77. package/experimental/random/Example.ff +46 -0
  78. package/experimental/random/Generic.ff +102 -0
  79. package/experimental/random/HappyEyeballs.ff +40 -0
  80. package/experimental/random/HashMap.ff +72 -0
  81. package/experimental/random/IfElseUnit.ff +9 -0
  82. package/experimental/random/InputOutput.ff +23 -0
  83. package/experimental/random/ListVsArray.ff +45 -0
  84. package/experimental/random/Main.ff +44 -0
  85. package/experimental/random/MapTest.ff +67 -0
  86. package/experimental/random/OldTaskSystem.ff +210 -0
  87. package/experimental/random/PatternTest.ff +39 -0
  88. package/experimental/random/Patterns.ff +226 -0
  89. package/experimental/random/ReadBytesTest.ff +10 -0
  90. package/experimental/random/RunLength.ff +65 -0
  91. package/experimental/random/Scrape.ff +51 -0
  92. package/experimental/random/Serialization.ff +217 -0
  93. package/experimental/random/SerializationTest.ff +46 -0
  94. package/experimental/random/Serializer.ff +36 -0
  95. package/experimental/random/StdInOutErr.ff +4 -0
  96. package/experimental/random/Symbols.ff +74 -0
  97. package/experimental/random/Tag.ff +49 -0
  98. package/experimental/random/Tensor.ff +52 -0
  99. package/experimental/random/Try.ff +56 -0
  100. package/experimental/random/Tsv.ff +9 -0
  101. package/experimental/random/TypesAreModules.ff +87 -0
  102. package/experimental/random/blueprints/Blueprint.ff +52 -0
  103. package/experimental/random/blueprints/Main.ff +11 -0
  104. package/experimental/random/blueprints/Pretty.ff +58 -0
  105. package/experimental/random/blueprints/User.ff +64 -0
  106. package/experimental/random/blueprintsystem/BlueprintSystem.ff +48 -0
  107. package/experimental/random/blueprintsystem/Deserialize.ff +53 -0
  108. package/experimental/random/blueprintsystem/ReadJs.ff +13 -0
  109. package/experimental/random/blueprintsystem/User.ff +2 -0
  110. package/experimental/random/kahrs/Kahrs.ff +112 -0
  111. package/experimental/random/kahrs/TestKahrs.ff +22 -0
  112. package/experimental/random/kahrs/TestMap.ff +18 -0
  113. package/experimental/random/streaming/Gzip.ff +3 -0
  114. package/experimental/random/streaming/Main.ff +34 -0
  115. package/experimental/random/streaming/S3Bucket.ff +11 -0
  116. package/experimental/random/streaming/Tar.ff +5 -0
  117. package/experimental/rhymeapp/Main.ff +81 -0
  118. package/experimental/rhymeapp/index.html +14 -0
  119. package/firefly.sh +5 -0
  120. package/fireflysite/Main.ff +13 -0
  121. package/httpserver/.firefly/package.ff +1 -0
  122. package/httpserver/HttpServer.ff +184 -0
  123. package/lsp/.firefly/package.ff +1 -0
  124. package/lsp/CompletionHandler.ff +814 -0
  125. package/lsp/Handler.ff +551 -0
  126. package/lsp/HoverHandler.ff +82 -0
  127. package/lsp/LanguageServer.ff +229 -0
  128. package/lsp/SignatureHelpHandler.ff +55 -0
  129. package/lsp/SymbolHandler.ff +167 -0
  130. package/output/js/ff/compiler/Builder.mjs +483 -0
  131. package/output/js/ff/compiler/Compiler.mjs +410 -0
  132. package/output/js/ff/compiler/Dependencies.mjs +388 -0
  133. package/output/js/ff/compiler/Deriver.mjs +1166 -0
  134. package/output/js/ff/compiler/Dictionaries.mjs +1305 -0
  135. package/output/js/ff/compiler/Environment.mjs +1005 -0
  136. package/output/js/ff/compiler/Inference.mjs +4264 -0
  137. package/output/js/ff/compiler/JsEmitter.mjs +5353 -0
  138. package/output/js/ff/compiler/JsImporter.mjs +262 -0
  139. package/output/js/ff/compiler/LspHook.mjs +789 -0
  140. package/output/js/ff/compiler/Main.mjs +1695 -0
  141. package/output/js/ff/compiler/Parser.mjs +4004 -0
  142. package/output/js/ff/compiler/Patterns.mjs +923 -0
  143. package/output/js/ff/compiler/Resolver.mjs +2303 -0
  144. package/output/js/ff/compiler/Substitution.mjs +1146 -0
  145. package/output/js/ff/compiler/Syntax.mjs +12430 -0
  146. package/output/js/ff/compiler/Token.mjs +3092 -0
  147. package/output/js/ff/compiler/Tokenizer.mjs +589 -0
  148. package/output/js/ff/compiler/Unification.mjs +1748 -0
  149. package/output/js/ff/compiler/Wildcards.mjs +604 -0
  150. package/output/js/ff/compiler/Workspace.mjs +683 -0
  151. package/output/js/ff/core/Any.mjs +139 -0
  152. package/output/js/ff/core/Array.mjs +594 -0
  153. package/output/js/ff/core/AssetSystem.mjs +270 -0
  154. package/output/js/ff/core/Atomic.mjs +186 -0
  155. package/output/js/ff/core/Bool.mjs +141 -0
  156. package/output/js/ff/core/BrowserSystem.mjs +122 -0
  157. package/output/js/ff/core/Buffer.mjs +467 -0
  158. package/output/js/ff/core/BuildSystem.mjs +320 -0
  159. package/output/js/ff/core/Channel.mjs +268 -0
  160. package/output/js/ff/core/Char.mjs +145 -0
  161. package/output/js/ff/core/Core.mjs +300 -0
  162. package/output/js/ff/core/Duration.mjs +112 -0
  163. package/output/js/ff/core/Equal.mjs +175 -0
  164. package/output/js/ff/core/Error.mjs +138 -0
  165. package/output/js/ff/core/FileHandle.mjs +164 -0
  166. package/output/js/ff/core/Float.mjs +214 -0
  167. package/output/js/ff/core/HttpClient.mjs +210 -0
  168. package/output/js/ff/core/Instant.mjs +105 -0
  169. package/output/js/ff/core/Int.mjs +254 -0
  170. package/output/js/ff/core/IntMap.mjs +282 -0
  171. package/output/js/ff/core/JsSystem.mjs +234 -0
  172. package/output/js/ff/core/JsValue.mjs +678 -0
  173. package/output/js/ff/core/List.mjs +2335 -0
  174. package/output/js/ff/core/Lock.mjs +322 -0
  175. package/output/js/ff/core/Log.mjs +159 -0
  176. package/output/js/ff/core/Map.mjs +358 -0
  177. package/output/js/ff/core/NodeSystem.mjs +288 -0
  178. package/output/js/ff/core/Nothing.mjs +100 -0
  179. package/output/js/ff/core/Option.mjs +1002 -0
  180. package/output/js/ff/core/Ordering.mjs +734 -0
  181. package/output/js/ff/core/Pair.mjs +318 -0
  182. package/output/js/ff/core/Path.mjs +768 -0
  183. package/output/js/ff/core/RbMap.mjs +1936 -0
  184. package/output/js/ff/core/Serializable.mjs +434 -0
  185. package/output/js/ff/core/Set.mjs +250 -0
  186. package/output/js/ff/core/Show.mjs +201 -0
  187. package/output/js/ff/core/Stack.mjs +595 -0
  188. package/output/js/ff/core/Stream.mjs +1300 -0
  189. package/output/js/ff/core/String.mjs +433 -0
  190. package/output/js/ff/core/StringMap.mjs +282 -0
  191. package/output/js/ff/core/Task.mjs +345 -0
  192. package/output/js/ff/core/Try.mjs +503 -0
  193. package/output/js/ff/core/Unit.mjs +103 -0
  194. package/package.json +29 -0
  195. package/postgresql/.firefly/include/package-lock.json +250 -0
  196. package/postgresql/.firefly/include/package.json +5 -0
  197. package/postgresql/.firefly/include/prepare.sh +2 -0
  198. package/postgresql/.firefly/package.ff +3 -0
  199. package/postgresql/Pg.ff +530 -0
  200. package/unsafejs/.firefly/package.ff +1 -0
  201. package/unsafejs/UnsafeJs.ff +19 -0
  202. package/vscode/.vscode/launch.json +18 -0
  203. package/vscode/.vscode/tasks.json +33 -0
  204. package/vscode/LICENSE.txt +21 -0
  205. package/vscode/Prepublish.ff +15 -0
  206. package/vscode/README.md +17 -0
  207. package/vscode/client/package-lock.json +544 -0
  208. package/vscode/client/package.json +22 -0
  209. package/vscode/client/src/extension.ts +64 -0
  210. package/vscode/client/tsconfig.json +12 -0
  211. package/vscode/icons/firefly-icon.png +0 -0
  212. package/vscode/icons/firefly-icon.svg +10 -0
  213. package/vscode/icons/firefly-logo-notext.png +0 -0
  214. package/vscode/icons/firefly-logo.png +0 -0
  215. package/vscode/language-configuration.json +39 -0
  216. package/vscode/package-lock.json +3623 -0
  217. package/vscode/package.json +144 -0
  218. package/vscode/snippets-none.json +1 -0
  219. package/vscode/snippets.json +241 -0
  220. package/vscode/syntaxes/firefly.tmLanguage.json +294 -0
  221. package/vscode/tsconfig.json +20 -0
@@ -0,0 +1,205 @@
1
+ import Syntax
2
+ import Unification
3
+ import Environment
4
+
5
+ data Dictionaries(
6
+ instances: Map[InstanceKey, InstanceValue]
7
+ )
8
+
9
+ make(modules: List[Module]): Dictionaries {
10
+ Dictionaries(Unification.make(modules, False).instances)
11
+ }
12
+
13
+ fail[T](at: Location, message: String): T {
14
+ panic(message + " " + at.show())
15
+ }
16
+
17
+ extend self: Dictionaries {
18
+
19
+ processModule(module: Module, otherModules: List[Module]): Module {
20
+ let environment = Environment.make(module, otherModules, alreadyFlat = True)
21
+ let functionSignatures = environment.symbols.pairs().collect {
22
+ | Pair(name, s) {!s.isVariable} => Some(Pair(name, s.signature))
23
+ | _ => None
24
+ }.toMap()
25
+
26
+ let lets = module.lets.map { self.processLetDefinition(functionSignatures, _) }
27
+ let functions = module.functions.map { self.processFunctionDefinition(functionSignatures, _) }
28
+ let extends = module.extends.map { self.processExtendDefinition(functionSignatures, _) }
29
+ //let traits = module.traits.map { self.processTraitDefinition(functionSignatures, _) }
30
+ let instances = module.instances.map { self.processInstanceDefinition(functionSignatures, _) }
31
+ module.Module(
32
+ //traits = traits,
33
+ instances = instances,
34
+ extends = extends,
35
+ lets = lets,
36
+ functions = functions,
37
+ )
38
+ }
39
+
40
+ processLetDefinition(functions: Map[String, Signature], definition: DLet): DLet {
41
+ definition.DLet(
42
+ value = self.processTerm(functions, definition.value)
43
+ )
44
+ }
45
+
46
+ processExtendDefinition(functions: Map[String, Signature], definition: DExtend): DExtend {
47
+ definition.DExtend(
48
+ methods = definition.methods.map { self.processFunctionDefinition(functions, _) }
49
+ )
50
+ }
51
+
52
+ processFunctionDefinition(functions: Map[String, Signature], definition: DFunction): DFunction {
53
+ let instances = constraintsToInstances(definition.signature.constraints)
54
+ let self2 = self.Dictionaries(instances = self.instances.addAll(instances))
55
+ definition.DFunction(
56
+ body = definition.body.mapFirefly {self2.processLambda(functions, _)}
57
+ )
58
+ }
59
+
60
+ processInstanceDefinition(functions: Map[String, Signature], definition: DInstance): DInstance {
61
+ let instances = constraintsToInstances(definition.constraints)
62
+ let self2 = self.Dictionaries(instances = self.instances.addAll(instances))
63
+ definition.DInstance(
64
+ methods = definition.methods.map { self2.processFunctionDefinition(functions, _) }
65
+ )
66
+ }
67
+
68
+ processLambda(functions: Map[String, Signature], definition: Lambda): Lambda {
69
+ definition.Lambda(
70
+ cases = definition.cases.map { case =>
71
+ // TODO: Remove the case variables from the functions
72
+ case.MatchCase(
73
+ guards = case.guards.map { g => g.MatchGuard(term = self.processTerm(functions, g.term)) }
74
+ body = self.processTerm(functions, case.body)
75
+ )
76
+ }
77
+ )
78
+ }
79
+
80
+ processTerm(functions: Map[String, Signature], term: Term): Term {
81
+ term.{
82
+ | EString _ => term
83
+ | EChar _ => term
84
+ | EInt _ => term
85
+ | EFloat _ => term
86
+ | EVariable _ => term
87
+ | EField e => e.EField(record = self.processTerm(functions, e.record))
88
+ | EWildcard e => term
89
+ | EList e => e.EList(
90
+ items = e.items.map {| Pair(item, b) => Pair(self.processTerm(functions, item), b) }
91
+ )
92
+ | ESequential e => e.ESequential(
93
+ before = self.processTerm(functions, e.before)
94
+ after = self.processTerm(functions, e.after)
95
+ )
96
+ | ELet e =>
97
+ let newFunctions = functions.remove(e.name)
98
+ e.ELet(
99
+ value = self.processTerm(functions, e.value)
100
+ body = self.processTerm(newFunctions, e.body)
101
+ )
102
+ | ELambda e => e.ELambda(lambda = self.processLambda(functions, e.lambda))
103
+ | EVariant e => e.EVariant(
104
+ arguments = e.arguments.map { _.map { self.processArgument(functions, _) } }
105
+ )
106
+ | EVariantIs e => term
107
+ | ECopy e => e.ECopy(
108
+ record = self.processTerm(functions, e.record)
109
+ arguments = e.arguments.map { self.processField(functions, _) }
110
+ )
111
+ | EPipe e => e.EPipe(
112
+ value = self.processTerm(functions, e.value)
113
+ function = self.processTerm(functions, e.function)
114
+ )
115
+ | ECall(at, StaticCall target, effect, typeArguments, arguments, _) {
116
+ functions.get(target.name) | Some(signature)
117
+ } =>
118
+ let dictionaries = signature.constraints.map {
119
+ self.makeDictionary(at, signature.generics, typeArguments, _)
120
+ }
121
+ ECall(
122
+ at = at
123
+ target = target.StaticCall()
124
+ effect = effect
125
+ typeArguments = typeArguments
126
+ arguments = arguments.map { self.processArgument(functions, _) }
127
+ dictionaries = dictionaries
128
+ )
129
+ | ECall e =>
130
+ let target = e.target.{
131
+ | DynamicCall call => call.DynamicCall(function = self.processTerm(functions, call.function))
132
+ | StaticCall _ => e.target
133
+ }
134
+ e.ECall(
135
+ target = target
136
+ arguments = e.arguments.map { self.processArgument(functions, _) }
137
+ )
138
+ | ERecord e => e.ERecord(fields = e.fields.map { self.processField(functions, _) })
139
+ | EFunctions e =>
140
+ let newFunctions = functions.addAll(e.functions.map { f =>
141
+ Pair(f.signature.name, f.signature)
142
+ }.toMap())
143
+ e.EFunctions(
144
+ functions = e.functions.map { self.processFunctionDefinition(newFunctions, _) }
145
+ body = self.processTerm(newFunctions, e.body)
146
+ )
147
+ | EAssign e => e.EAssign(value = self.processTerm(functions, e.value))
148
+ | EAssignField e => e.EAssignField(
149
+ record = self.processTerm(functions, e.record)
150
+ value = self.processTerm(functions, e.value)
151
+ )
152
+ }
153
+ }
154
+
155
+ processArgument(functions: Map[String, Signature], argument: Argument): Argument {
156
+ argument.Argument(value = self.processTerm(functions, argument.value))
157
+ }
158
+
159
+ processField(functions: Map[String, Signature], field: Field): Field {
160
+ field.Field(value = self.processTerm(functions, field.value))
161
+ }
162
+
163
+ makeDictionary(
164
+ at: Location,
165
+ typeParameters: List[String],
166
+ typeArguments: List[Type],
167
+ constraint: Constraint
168
+ ): Dictionary {
169
+ let instantiationMap = typeParameters.zip(typeArguments).toMap()
170
+ let unification = Unification.make([], False)
171
+ let newGenerics = constraint.generics.map { unification.instantiate(instantiationMap, _) }
172
+ let firstType = newGenerics.grabFirst().{
173
+ | TConstructor t => t
174
+ | TVariable t => fail(t.at, " is still a unification variable")
175
+ }
176
+ let instance = self.instances.get(InstanceKey(constraint.name, firstType.name)).else {
177
+ throw(CompileError(at, "Missing instance " + firstType.name + ": " + constraint.name))
178
+ }
179
+ let dictionaries = instance.constraints.map { c =>
180
+ self.makeDictionary(at, instance.generics, firstType.generics, c)
181
+ }
182
+ Dictionary(instance.packagePair, instance.moduleName, constraint.name, firstType.name, dictionaries)
183
+ }
184
+
185
+ }
186
+
187
+ constraintsToInstances(constraints: List[Constraint]): Map[InstanceKey, InstanceValue] {
188
+ constraints.map { c =>
189
+ let typeName = c.generics.grabFirst().{
190
+ | TConstructor(_, name, _) => name
191
+ | TVariable(_, i) => fail(c.at, "Unexpected unification variable: $" + i)
192
+ }
193
+ Pair(
194
+ InstanceKey(c.name, typeName)
195
+ InstanceValue(
196
+ generics = []
197
+ constraints = []
198
+ packagePair = PackagePair("", "")
199
+ moduleName = ""
200
+ traitName = c.name
201
+ typeArguments = c.generics
202
+ )
203
+ )
204
+ }.toMap()
205
+ }
@@ -0,0 +1,166 @@
1
+ import Syntax
2
+
3
+ data Environment(
4
+ modulePrefix: String
5
+ symbols: Map[String, Scheme]
6
+ traits: Map[String, DTrait]
7
+ imports: Map[String, DImport]
8
+ effect: Type
9
+ selfVariable: Option[String]
10
+ )
11
+
12
+ data Scheme(
13
+ isVariable: Bool
14
+ isMutable: Bool
15
+ isNewtype: Bool
16
+ isTraitMethod: Bool
17
+ signature: Signature
18
+ )
19
+
20
+ data Instantiated(
21
+ typeArguments: List[Pair[String, Type]]
22
+ scheme: Scheme
23
+ )
24
+
25
+ make(module: Module, otherModules: List[Module], alreadyFlat: Bool): Environment {
26
+ let processed = processModule(module, True, alreadyFlat)
27
+ let otherProcessed = otherModules.map {processModule(_, False, False)}
28
+ Environment(
29
+ modulePrefix = fullName(module, "")
30
+ symbols = processed.symbols.addAll(otherProcessed.map {_.symbols}.foldLeft(Map.empty()) {_.addAll(_)})
31
+ traits = processed.traits.addAll(otherProcessed.map {_.traits}.foldLeft(Map.empty()) {_.addAll(_)})
32
+ imports = module.imports.map {i => Pair(i.alias, i)}.toMap()
33
+ effect = TConstructor(Location(module.file, 0, 0), "ff:core/Nothing.Nothing", [])
34
+ selfVariable = None
35
+ )
36
+ }
37
+
38
+ fullName(module: Module, name: String): String {
39
+ module.packagePair.groupName() + "/" +
40
+ module.file.dropLast(3) + "." + name
41
+ }
42
+
43
+ fail[T](at: Location, message: String): T {
44
+ panic(message + " " + at.show())
45
+ }
46
+
47
+ processModule(module: Module, isCurrentModule: Bool, alreadyFlat: Bool): Environment {
48
+
49
+ let functions =
50
+ module.functions.map {d => Pair(
51
+ fullName(module, d.signature.name)
52
+ Scheme(False, False, False, False, d.signature)
53
+ )}
54
+
55
+ let lets =
56
+ module.lets.map {d =>
57
+ let noEffect = TConstructor(d.at, "ff:core/Nothing.Nothing", [])
58
+ Pair(
59
+ fullName(module, d.name)
60
+ Scheme(True, False, False, False, Signature(d.at, d.name, False, [], [], [], d.variableType, noEffect))
61
+ )
62
+ }
63
+
64
+ let traitMethods =
65
+ module.traits.flatMap {definition =>
66
+ let generics = definition.generics.map {name => TConstructor(definition.at, name, [])}
67
+ let constraint = Constraint(definition.at, fullName(module, definition.name), generics)
68
+ let outerConstraints = if(alreadyFlat) {[]} else {definition.constraints}
69
+ definition.methods.map {methodSignature =>
70
+ let generics = [...definition.generics, ...methodSignature.generics].partition {_ == "Q$"}
71
+ let signature = methodSignature.Signature(
72
+ generics = [...generics.first.takeFirst(1), ...generics.second]
73
+ constraints = [constraint, ...outerConstraints, ...methodSignature.constraints]
74
+ )
75
+ Pair(
76
+ fullName(module, signature.name)
77
+ Scheme(False, False, False, True, signature)
78
+ )
79
+ }
80
+ }
81
+
82
+ let extends =
83
+ module.extends.flatMap {d =>
84
+ d.type.{
85
+ | TVariable t =>
86
+ fail(t.at, "Unexpected type variable: $" + t.index)
87
+ | TConstructor t =>
88
+ let prefix = t.name + "_"
89
+ let selfParameter = Parameter(d.at, False, d.name, d.type, None)
90
+ d.methods.map {method =>
91
+ let effect = method.signature.generics.filter {_ == "Q$"}
92
+ let normalGenerics = method.signature.generics.filter {_ != "Q$"}
93
+ let outerGenerics = if(alreadyFlat) {[]} else {d.generics}
94
+ Pair(
95
+ prefix + method.signature.name
96
+ Scheme(False, False, False, False, method.signature.Signature(
97
+ generics = [...effect, ...outerGenerics, ...normalGenerics]
98
+ constraints = [...d.constraints, ...method.signature.constraints]
99
+ parameters = [selfParameter, ...method.signature.parameters]
100
+ ))
101
+ )
102
+ }
103
+ }
104
+ }
105
+
106
+ let fields =
107
+ module.types.flatMap {d =>
108
+ let prefix = d.name + "_"
109
+ let t = TConstructor(d.at, d.name, d.generics.map {g => TConstructor(d.at, g, [])})
110
+ let selfParameter = Parameter(d.at, False, d.name, t, None)
111
+ d.commonFields.map {f =>
112
+ let noEffect = TConstructor(d.at, "ff:core/Nothing.Nothing", [])
113
+ Pair(
114
+ fullName(module, prefix + f.name)
115
+ Scheme(True, f.mutable, d.newtype, False, Signature(
116
+ at = f.at
117
+ name = f.name
118
+ member = True
119
+ generics = d.generics
120
+ constraints = d.constraints
121
+ parameters = [selfParameter]
122
+ returnType = f.valueType
123
+ effect = noEffect
124
+ ))
125
+ )
126
+ }
127
+ }
128
+
129
+ let variants =
130
+ module.types.flatMap {d =>
131
+ let returnType = TConstructor(d.at, fullName(module, d.name), d.generics.map {typeParameter =>
132
+ TConstructor(d.at, typeParameter, [])
133
+ })
134
+ d.variants.map {variant =>
135
+ let noEffect = TConstructor(d.at, "ff:core/Nothing.Nothing", [])
136
+ Pair(
137
+ fullName(module, variant.name)
138
+ Scheme(False, False, d.newtype, False, Signature(
139
+ variant.at
140
+ variant.name
141
+ member = False
142
+ generics = d.generics
143
+ constraints = d.constraints
144
+ parameters = [...d.commonFields, ...variant.fields]
145
+ returnType = returnType
146
+ effect = noEffect
147
+ ))
148
+ )
149
+ }
150
+ }
151
+
152
+ let traits =
153
+ module.traits.map {d =>
154
+ Pair(fullName(module, d.name), d)
155
+ }
156
+
157
+ let effect = TConstructor(Location(module.file, 0, 0), "ff:core/Nothing.Nothing", [])
158
+ Environment(
159
+ modulePrefix = ""
160
+ symbols = [...functions, ...lets, ...fields, ...extends, ...variants, ...traitMethods].toMap()
161
+ traits = traits.toMap()
162
+ imports = [].toMap()
163
+ effect = effect
164
+ selfVariable = None
165
+ )
166
+ }