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,4264 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import * as ff_compiler_Inference from "../../ff/compiler/Inference.mjs"
|
|
4
|
+
|
|
5
|
+
import * as ff_compiler_Environment from "../../ff/compiler/Environment.mjs"
|
|
6
|
+
|
|
7
|
+
import * as ff_compiler_LspHook from "../../ff/compiler/LspHook.mjs"
|
|
8
|
+
|
|
9
|
+
import * as ff_compiler_Substitution from "../../ff/compiler/Substitution.mjs"
|
|
10
|
+
|
|
11
|
+
import * as ff_compiler_Syntax from "../../ff/compiler/Syntax.mjs"
|
|
12
|
+
|
|
13
|
+
import * as ff_compiler_Unification from "../../ff/compiler/Unification.mjs"
|
|
14
|
+
|
|
15
|
+
import * as ff_core_Any from "../../ff/core/Any.mjs"
|
|
16
|
+
|
|
17
|
+
import * as ff_core_Array from "../../ff/core/Array.mjs"
|
|
18
|
+
|
|
19
|
+
import * as ff_core_AssetSystem from "../../ff/core/AssetSystem.mjs"
|
|
20
|
+
|
|
21
|
+
import * as ff_core_Atomic from "../../ff/core/Atomic.mjs"
|
|
22
|
+
|
|
23
|
+
import * as ff_core_Bool from "../../ff/core/Bool.mjs"
|
|
24
|
+
|
|
25
|
+
import * as ff_core_BrowserSystem from "../../ff/core/BrowserSystem.mjs"
|
|
26
|
+
|
|
27
|
+
import * as ff_core_Buffer from "../../ff/core/Buffer.mjs"
|
|
28
|
+
|
|
29
|
+
import * as ff_core_BuildSystem from "../../ff/core/BuildSystem.mjs"
|
|
30
|
+
|
|
31
|
+
import * as ff_core_Channel from "../../ff/core/Channel.mjs"
|
|
32
|
+
|
|
33
|
+
import * as ff_core_Char from "../../ff/core/Char.mjs"
|
|
34
|
+
|
|
35
|
+
import * as ff_core_Core from "../../ff/core/Core.mjs"
|
|
36
|
+
|
|
37
|
+
import * as ff_core_Duration from "../../ff/core/Duration.mjs"
|
|
38
|
+
|
|
39
|
+
import * as ff_core_Equal from "../../ff/core/Equal.mjs"
|
|
40
|
+
|
|
41
|
+
import * as ff_core_Error from "../../ff/core/Error.mjs"
|
|
42
|
+
|
|
43
|
+
import * as ff_core_FileHandle from "../../ff/core/FileHandle.mjs"
|
|
44
|
+
|
|
45
|
+
import * as ff_core_Float from "../../ff/core/Float.mjs"
|
|
46
|
+
|
|
47
|
+
import * as ff_core_HttpClient from "../../ff/core/HttpClient.mjs"
|
|
48
|
+
|
|
49
|
+
import * as ff_core_Instant from "../../ff/core/Instant.mjs"
|
|
50
|
+
|
|
51
|
+
import * as ff_core_Int from "../../ff/core/Int.mjs"
|
|
52
|
+
|
|
53
|
+
import * as ff_core_IntMap from "../../ff/core/IntMap.mjs"
|
|
54
|
+
|
|
55
|
+
import * as ff_core_JsSystem from "../../ff/core/JsSystem.mjs"
|
|
56
|
+
|
|
57
|
+
import * as ff_core_JsValue from "../../ff/core/JsValue.mjs"
|
|
58
|
+
|
|
59
|
+
import * as ff_core_List from "../../ff/core/List.mjs"
|
|
60
|
+
|
|
61
|
+
import * as ff_core_Lock from "../../ff/core/Lock.mjs"
|
|
62
|
+
|
|
63
|
+
import * as ff_core_Log from "../../ff/core/Log.mjs"
|
|
64
|
+
|
|
65
|
+
import * as ff_core_Map from "../../ff/core/Map.mjs"
|
|
66
|
+
|
|
67
|
+
import * as ff_core_NodeSystem from "../../ff/core/NodeSystem.mjs"
|
|
68
|
+
|
|
69
|
+
import * as ff_core_Nothing from "../../ff/core/Nothing.mjs"
|
|
70
|
+
|
|
71
|
+
import * as ff_core_Option from "../../ff/core/Option.mjs"
|
|
72
|
+
|
|
73
|
+
import * as ff_core_Ordering from "../../ff/core/Ordering.mjs"
|
|
74
|
+
|
|
75
|
+
import * as ff_core_Pair from "../../ff/core/Pair.mjs"
|
|
76
|
+
|
|
77
|
+
import * as ff_core_Path from "../../ff/core/Path.mjs"
|
|
78
|
+
|
|
79
|
+
import * as ff_core_Serializable from "../../ff/core/Serializable.mjs"
|
|
80
|
+
|
|
81
|
+
import * as ff_core_Set from "../../ff/core/Set.mjs"
|
|
82
|
+
|
|
83
|
+
import * as ff_core_Show from "../../ff/core/Show.mjs"
|
|
84
|
+
|
|
85
|
+
import * as ff_core_Stack from "../../ff/core/Stack.mjs"
|
|
86
|
+
|
|
87
|
+
import * as ff_core_Stream from "../../ff/core/Stream.mjs"
|
|
88
|
+
|
|
89
|
+
import * as ff_core_String from "../../ff/core/String.mjs"
|
|
90
|
+
|
|
91
|
+
import * as ff_core_StringMap from "../../ff/core/StringMap.mjs"
|
|
92
|
+
|
|
93
|
+
import * as ff_core_Task from "../../ff/core/Task.mjs"
|
|
94
|
+
|
|
95
|
+
import * as ff_core_Try from "../../ff/core/Try.mjs"
|
|
96
|
+
|
|
97
|
+
import * as ff_core_Unit from "../../ff/core/Unit.mjs"
|
|
98
|
+
|
|
99
|
+
// type Inference
|
|
100
|
+
export function Inference(unification_, missing_, lspHook_) {
|
|
101
|
+
return {unification_, missing_, lspHook_};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
export function make_(modules_, lspHook_) {
|
|
107
|
+
return ff_compiler_Inference.Inference(ff_compiler_Unification.make_(modules_, ff_compiler_LspHook.LspHook_isEnabled(lspHook_)), ff_core_StringMap.make_(), lspHook_)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function fail_(at_, message_) {
|
|
111
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(at_, message_), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function core_(name_) {
|
|
115
|
+
return ((("ff:core/" + name_) + ".") + name_)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function constraintsToInstances_(constraints_) {
|
|
119
|
+
return ff_core_List.List_toMap(ff_core_List.List_map(constraints_, ((c_) => {
|
|
120
|
+
const typeName_ = (((_1) => {
|
|
121
|
+
{
|
|
122
|
+
if(_1.TConstructor) {
|
|
123
|
+
const name_ = _1.name_;
|
|
124
|
+
return name_
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
{
|
|
129
|
+
if(_1.TVariable) {
|
|
130
|
+
const at_ = _1.at_;
|
|
131
|
+
const i_ = _1.index_;
|
|
132
|
+
return ff_compiler_Inference.fail_(c_.at_, ("Unexpected unification variable: $" + i_))
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}))(ff_core_List.List_grabFirst(c_.generics_));
|
|
137
|
+
return ff_core_Pair.Pair(ff_compiler_Unification.InstanceKey(c_.name_, typeName_), ff_compiler_Unification.InstanceValue(ff_core_List.Empty(), ff_core_List.Empty(), ff_compiler_Syntax.PackagePair("", ""), "", c_.name_, c_.generics_))
|
|
138
|
+
})), ff_compiler_Unification.ff_core_Ordering_Order$ff_compiler_Unification_InstanceKey)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export async function make_$(modules_, lspHook_, $task) {
|
|
142
|
+
return ff_compiler_Inference.Inference(ff_compiler_Unification.make_(modules_, ff_compiler_LspHook.LspHook_isEnabled(lspHook_)), ff_core_StringMap.make_(), lspHook_)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export async function fail_$(at_, message_, $task) {
|
|
146
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(at_, message_), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export async function core_$(name_, $task) {
|
|
150
|
+
return ((("ff:core/" + name_) + ".") + name_)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export async function constraintsToInstances_$(constraints_, $task) {
|
|
154
|
+
return ff_core_List.List_toMap(ff_core_List.List_map(constraints_, ((c_) => {
|
|
155
|
+
const typeName_ = (((_1) => {
|
|
156
|
+
{
|
|
157
|
+
if(_1.TConstructor) {
|
|
158
|
+
const name_ = _1.name_;
|
|
159
|
+
return name_
|
|
160
|
+
return
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
{
|
|
164
|
+
if(_1.TVariable) {
|
|
165
|
+
const at_ = _1.at_;
|
|
166
|
+
const i_ = _1.index_;
|
|
167
|
+
return ff_compiler_Inference.fail_(c_.at_, ("Unexpected unification variable: $" + i_))
|
|
168
|
+
return
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}))(ff_core_List.List_grabFirst(c_.generics_));
|
|
172
|
+
return ff_core_Pair.Pair(ff_compiler_Unification.InstanceKey(c_.name_, typeName_), ff_compiler_Unification.InstanceValue(ff_core_List.Empty(), ff_core_List.Empty(), ff_compiler_Syntax.PackagePair("", ""), "", c_.name_, c_.generics_))
|
|
173
|
+
})), ff_compiler_Unification.ff_core_Ordering_Order$ff_compiler_Unification_InstanceKey)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function Inference_inferModule(self_, module_, otherModules_) {
|
|
177
|
+
const environment_ = ff_compiler_Environment.make_(module_, otherModules_, false);
|
|
178
|
+
const traits_ = ff_core_List.List_map(module_.traits_, ((_w1) => {
|
|
179
|
+
return ff_compiler_Inference.Inference_inferTraitDefinition(self_, environment_, _w1)
|
|
180
|
+
}));
|
|
181
|
+
const instances_ = ff_core_List.List_map(module_.instances_, ((_w1) => {
|
|
182
|
+
return ff_compiler_Inference.Inference_inferInstanceDefinition(self_, environment_, _w1)
|
|
183
|
+
}));
|
|
184
|
+
const lets_ = ff_core_List.List_map(module_.lets_, ((_w1) => {
|
|
185
|
+
return ff_compiler_Inference.Inference_inferLetDefinition(self_, environment_, _w1)
|
|
186
|
+
}));
|
|
187
|
+
const functions_ = ff_core_List.List_map(module_.functions_, ((_w1) => {
|
|
188
|
+
return ff_compiler_Inference.Inference_inferFunctionDefinition(self_, environment_, _w1)
|
|
189
|
+
}));
|
|
190
|
+
const extends_ = ff_core_List.List_map(module_.extends_, ((_w1) => {
|
|
191
|
+
return ff_compiler_Inference.Inference_inferExtendDefinition(self_, environment_, _w1)
|
|
192
|
+
}));
|
|
193
|
+
const result_ = (((_c) => {
|
|
194
|
+
return ff_compiler_Syntax.Module(_c.file_, _c.packagePair_, _c.imports_, _c.types_, traits_, instances_, extends_, lets_, functions_)
|
|
195
|
+
}))(module_);
|
|
196
|
+
const subsititution_ = ff_compiler_Substitution.Substitution(self_.unification_.substitution_);
|
|
197
|
+
return ff_compiler_Substitution.Substitution_substituteModule(subsititution_, result_)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function Inference_inferTraitDefinition(self_, environment_, definition_) {
|
|
201
|
+
{
|
|
202
|
+
const _1 = definition_;
|
|
203
|
+
{
|
|
204
|
+
const _c = _1;
|
|
205
|
+
return ff_compiler_Syntax.DTrait(_c.at_, _c.name_, _c.generics_, _c.constraints_, _c.generatorParameters_, _c.methods_, _c.methodDefaults_, _c.methodGenerators_)
|
|
206
|
+
return
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function Inference_inferInstanceDefinition(self_, environment_, definition_) {
|
|
212
|
+
if((ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_) && definition_.derived_)) {
|
|
213
|
+
return definition_
|
|
214
|
+
} else {
|
|
215
|
+
const instances_ = ff_compiler_Inference.constraintsToInstances_(definition_.constraints_);
|
|
216
|
+
return ff_compiler_Unification.Unification_withLocalInstances(self_.unification_, instances_, (() => {
|
|
217
|
+
const traitName_ = definition_.traitName_;
|
|
218
|
+
const traitDefinition_ = ff_core_Option.Option_else(ff_core_Map.Map_get(environment_.traits_, traitName_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String), (() => {
|
|
219
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(definition_.at_, ("No such trait: " + traitName_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
220
|
+
}));
|
|
221
|
+
if((ff_core_List.List_size(traitDefinition_.generics_) !== ff_core_List.List_size(definition_.typeArguments_))) {
|
|
222
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(definition_.at_, ((((("Wrong number of type arguments for " + traitName_) + ", expected ") + (ff_core_List.List_size(traitDefinition_.generics_) - 1)) + ", got ") + (ff_core_List.List_size(definition_.typeArguments_) - 1))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
223
|
+
};
|
|
224
|
+
const instantiationMap_ = ff_core_List.List_toMap(ff_core_List.List_zip(traitDefinition_.generics_, definition_.typeArguments_), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
225
|
+
ff_core_List.List_each(traitDefinition_.methods_, ((traitMethod_) => {
|
|
226
|
+
const found_ = ff_core_List.List_filter(definition_.methods_, ((_w1) => {
|
|
227
|
+
return (_w1.signature_.name_ === traitMethod_.name_)
|
|
228
|
+
}));
|
|
229
|
+
if(ff_core_List.List_isEmpty(found_)) {
|
|
230
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(definition_.at_, ("Missing instance method: " + traitMethod_.name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
231
|
+
};
|
|
232
|
+
ff_core_List.List_each(ff_core_List.List_dropFirst(found_, 1), ((duplicateMethod_) => {
|
|
233
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(duplicateMethod_.at_, ("Duplicated instance method: " + traitMethod_.name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
234
|
+
}))
|
|
235
|
+
}));
|
|
236
|
+
{
|
|
237
|
+
const _1 = definition_;
|
|
238
|
+
{
|
|
239
|
+
const _c = _1;
|
|
240
|
+
return ff_compiler_Syntax.DInstance(_c.at_, _c.generics_, _c.constraints_, _c.traitName_, _c.typeArguments_, _c.generatorArguments_, ff_core_List.List_map(definition_.methods_, ((instanceFunction_) => {
|
|
241
|
+
const methodName_ = instanceFunction_.signature_.name_;
|
|
242
|
+
const traitMethodName_ = (ff_core_String.String_reverse(ff_core_String.String_dropWhile(ff_core_String.String_reverse(traitName_), ((_w1) => {
|
|
243
|
+
return (_w1 !== 46)
|
|
244
|
+
}))) + methodName_);
|
|
245
|
+
const traitMethodScheme_ = ff_core_Option.Option_else(ff_core_Map.Map_get(environment_.symbols_, traitMethodName_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String), (() => {
|
|
246
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(instanceFunction_.at_, ((("Trait " + traitName_) + " has no such method: ") + methodName_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
247
|
+
}));
|
|
248
|
+
const parameters_ = ff_core_List.List_map(traitMethodScheme_.signature_.parameters_, ((p_) => {
|
|
249
|
+
{
|
|
250
|
+
const _1 = p_;
|
|
251
|
+
{
|
|
252
|
+
const _c = _1;
|
|
253
|
+
return ff_compiler_Syntax.Parameter(_c.at_, _c.mutable_, _c.name_, ff_compiler_Unification.Unification_instantiate(self_.unification_, instantiationMap_, p_.valueType_), _c.default_)
|
|
254
|
+
return
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}));
|
|
258
|
+
const returnType_ = ff_compiler_Unification.Unification_instantiate(self_.unification_, instantiationMap_, traitMethodScheme_.signature_.returnType_);
|
|
259
|
+
ff_core_List.List_each(ff_core_List.List_dropFirst(instanceFunction_.signature_.parameters_, ff_core_List.List_size(parameters_)), ((instanceParameter_) => {
|
|
260
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(instanceParameter_.at_, ("Unexpected parameter: " + instanceParameter_.name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
261
|
+
}));
|
|
262
|
+
ff_core_List.List_each(ff_core_List.List_dropFirst(parameters_, ff_core_List.List_size(instanceFunction_.signature_.parameters_)), ((traitParameter_) => {
|
|
263
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(instanceFunction_.at_, ("Missing parameter: " + traitParameter_.name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
264
|
+
}));
|
|
265
|
+
ff_core_List.List_each(ff_core_List.List_zip(parameters_, instanceFunction_.signature_.parameters_), ((_1) => {
|
|
266
|
+
{
|
|
267
|
+
const traitParameter_ = _1.first_;
|
|
268
|
+
const instanceParameter_ = _1.second_;
|
|
269
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, instanceParameter_.valueType_.at_, traitParameter_.valueType_, instanceParameter_.valueType_)
|
|
270
|
+
return
|
|
271
|
+
}
|
|
272
|
+
}));
|
|
273
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, instanceFunction_.signature_.returnType_.at_, returnType_, instanceFunction_.signature_.returnType_);
|
|
274
|
+
if((ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, instanceFunction_.at_) || ff_compiler_LspHook.LspHook_isDefinedAt(self_.lspHook_, traitMethodScheme_.signature_.at_))) {
|
|
275
|
+
const symbolHook_ = ff_compiler_LspHook.SymbolHook(instanceFunction_.signature_.name_, instanceFunction_.at_, traitMethodScheme_.signature_.at_);
|
|
276
|
+
const h_ = ff_compiler_LspHook.InferLookupHook(self_.unification_, environment_, instanceFunction_.signature_.returnType_, ff_core_Option.None(), ff_compiler_LspHook.Box(symbolHook_), ff_compiler_LspHook.Box(ff_core_Option.None()));
|
|
277
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, h_)
|
|
278
|
+
};
|
|
279
|
+
return ff_compiler_Inference.Inference_inferFunctionDefinition(self_, environment_, instanceFunction_)
|
|
280
|
+
})), _c.derived_)
|
|
281
|
+
return
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}))
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function Inference_inferLetDefinition(self_, environment_, definition_) {
|
|
289
|
+
const value_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, definition_.variableType_, definition_.value_);
|
|
290
|
+
{
|
|
291
|
+
const _1 = definition_;
|
|
292
|
+
{
|
|
293
|
+
const _c = _1;
|
|
294
|
+
return ff_compiler_Syntax.DLet(_c.at_, _c.name_, _c.variableType_, value_)
|
|
295
|
+
return
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export function Inference_inferExtendDefinition(self_, environment_, definition_) {
|
|
301
|
+
const selfParameter_ = ff_compiler_Syntax.Parameter(definition_.at_, false, definition_.name_, definition_.type_, ff_core_Option.None());
|
|
302
|
+
const functions_ = ff_core_List.List_map(definition_.methods_, ((method_) => {
|
|
303
|
+
const signature_ = (((_c) => {
|
|
304
|
+
return ff_compiler_Syntax.Signature(_c.at_, _c.name_, _c.member_, ff_core_List.List_addAll(definition_.generics_, method_.signature_.generics_), ff_core_List.List_addAll(definition_.constraints_, method_.signature_.constraints_), ff_core_List.Link(selfParameter_, method_.signature_.parameters_), _c.returnType_, _c.effect_)
|
|
305
|
+
}))(method_.signature_);
|
|
306
|
+
const body_ = ff_compiler_Syntax.Target_mapFirefly(method_.body_, ((lambda_) => {
|
|
307
|
+
{
|
|
308
|
+
const _1 = lambda_;
|
|
309
|
+
{
|
|
310
|
+
const _c = _1;
|
|
311
|
+
return ff_compiler_Syntax.Lambda(_c.at_, _c.effect_, ff_core_List.List_map(lambda_.cases_, ((case_) => {
|
|
312
|
+
{
|
|
313
|
+
const _1 = case_;
|
|
314
|
+
{
|
|
315
|
+
const _c = _1;
|
|
316
|
+
return ff_compiler_Syntax.MatchCase(_c.at_, ff_core_List.Link(ff_compiler_Syntax.PVariable(method_.at_, ff_core_Option.None()), case_.patterns_), _c.guards_, _c.body_)
|
|
317
|
+
return
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
})))
|
|
321
|
+
return
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}));
|
|
325
|
+
const function_ = (((_c) => {
|
|
326
|
+
return ff_compiler_Syntax.DFunction(_c.at_, signature_, body_)
|
|
327
|
+
}))(method_);
|
|
328
|
+
return ff_compiler_Inference.Inference_inferFunctionDefinition(self_, (((_c) => {
|
|
329
|
+
return ff_compiler_Environment.Environment(_c.modulePrefix_, _c.symbols_, _c.traits_, _c.imports_, _c.effect_, ff_core_Option.Some(definition_.name_))
|
|
330
|
+
}))(environment_), function_)
|
|
331
|
+
}));
|
|
332
|
+
{
|
|
333
|
+
const _1 = definition_;
|
|
334
|
+
{
|
|
335
|
+
const _c = _1;
|
|
336
|
+
return ff_compiler_Syntax.DExtend(_c.at_, _c.name_, _c.generics_, _c.constraints_, _c.type_, functions_)
|
|
337
|
+
return
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export function Inference_inferFunctionDefinition(self_, environment_, definition_) {
|
|
343
|
+
if(ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, definition_.at_)) {
|
|
344
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferFunctionDefinitionHook(self_.unification_, environment_, definition_, self_.missing_))
|
|
345
|
+
};
|
|
346
|
+
const parameters_ = ff_core_List.List_map(definition_.signature_.parameters_, ((p_) => {
|
|
347
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(p_.at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
348
|
+
const scheme_ = ff_compiler_Environment.Scheme(true, false, false, false, ff_compiler_Syntax.Signature(p_.at_, p_.name_, false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Empty(), p_.valueType_, noEffect_));
|
|
349
|
+
if(ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, p_.at_)) {
|
|
350
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferParameterHook(self_.unification_, environment_, p_, self_.missing_))
|
|
351
|
+
};
|
|
352
|
+
return ff_core_Pair.Pair(p_.name_, scheme_)
|
|
353
|
+
}));
|
|
354
|
+
const parameterMap_ = ff_core_List.List_toMap(parameters_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
355
|
+
const environment2_ = (((_c) => {
|
|
356
|
+
return ff_compiler_Environment.Environment(_c.modulePrefix_, ff_core_Map.Map_addAll(environment_.symbols_, parameterMap_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String), _c.traits_, _c.imports_, _c.effect_, _c.selfVariable_)
|
|
357
|
+
}))(environment_);
|
|
358
|
+
const parameterTypes_ = ff_core_List.List_map(parameters_, ((_w1) => {
|
|
359
|
+
return _w1.second_.signature_.returnType_
|
|
360
|
+
}));
|
|
361
|
+
const functionType_ = ff_compiler_Syntax.TConstructor(definition_.at_, ("Function$" + ff_core_List.List_size(parameterTypes_)), ff_core_List.Link(definition_.signature_.effect_, ff_core_List.List_addAll(parameterTypes_, ff_core_List.Link(definition_.signature_.returnType_, ff_core_List.Empty()))));
|
|
362
|
+
const instances_ = ff_compiler_Inference.constraintsToInstances_(definition_.signature_.constraints_);
|
|
363
|
+
return ff_compiler_Unification.Unification_withLocalInstances(self_.unification_, instances_, (() => {
|
|
364
|
+
{
|
|
365
|
+
const _1 = definition_;
|
|
366
|
+
{
|
|
367
|
+
const _c = _1;
|
|
368
|
+
return ff_compiler_Syntax.DFunction(_c.at_, _c.signature_, ff_compiler_Syntax.Target_mapFirefly(definition_.body_, ((_w1) => {
|
|
369
|
+
return ff_compiler_Inference.Inference_inferLambda(self_, environment2_, functionType_, _w1)
|
|
370
|
+
})))
|
|
371
|
+
return
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}))
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export function Inference_inferLambda(self_, environment_, expected_, lambda_) {
|
|
378
|
+
const unitName_ = ff_compiler_Inference.core_("Unit");
|
|
379
|
+
const returnsUnit_ = (((_1) => {
|
|
380
|
+
{
|
|
381
|
+
if(_1.TConstructor) {
|
|
382
|
+
const name_ = _1.name_;
|
|
383
|
+
const ts_ = _1.generics_;
|
|
384
|
+
const _guard1 = ff_core_String.String_startsWith(name_, "Function$", 0);
|
|
385
|
+
if(_guard1) {
|
|
386
|
+
{
|
|
387
|
+
const _1 = ff_core_List.List_grabLast(ts_);
|
|
388
|
+
{
|
|
389
|
+
if(_1.TConstructor) {
|
|
390
|
+
const n_ = _1.name_;
|
|
391
|
+
if(_1.generics_.Empty) {
|
|
392
|
+
return (n_ === unitName_)
|
|
393
|
+
return
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
{
|
|
398
|
+
return false
|
|
399
|
+
return
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
{
|
|
407
|
+
return false
|
|
408
|
+
return
|
|
409
|
+
}
|
|
410
|
+
}))(ff_compiler_Unification.Unification_substitute(self_.unification_, expected_));
|
|
411
|
+
const cases_ = ((!returnsUnit_)
|
|
412
|
+
? lambda_.cases_
|
|
413
|
+
: ff_core_List.List_map(lambda_.cases_, ((c_) => {
|
|
414
|
+
{
|
|
415
|
+
const _1 = c_;
|
|
416
|
+
{
|
|
417
|
+
const _c = _1;
|
|
418
|
+
return ff_compiler_Syntax.MatchCase(_c.at_, _c.patterns_, _c.guards_, ff_compiler_Syntax.ESequential(c_.at_, c_.body_, ff_compiler_Syntax.EVariant(c_.at_, unitName_, ff_core_List.Empty(), ff_core_Option.None())))
|
|
419
|
+
return
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
})));
|
|
423
|
+
const newEnvironment_ = (((_c) => {
|
|
424
|
+
return ff_compiler_Environment.Environment(_c.modulePrefix_, _c.symbols_, _c.traits_, _c.imports_, lambda_.effect_, _c.selfVariable_)
|
|
425
|
+
}))(environment_);
|
|
426
|
+
{
|
|
427
|
+
const _1 = lambda_;
|
|
428
|
+
{
|
|
429
|
+
const _c = _1;
|
|
430
|
+
return ff_compiler_Syntax.Lambda(_c.at_, _c.effect_, ff_core_List.List_map(cases_, ((_w1) => {
|
|
431
|
+
return ff_compiler_Inference.Inference_inferMatchCase(self_, newEnvironment_, expected_, _w1)
|
|
432
|
+
})))
|
|
433
|
+
return
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export function Inference_inferMatchCase(self_, environment_, expected_, case_) {
|
|
439
|
+
const parameterTypes_ = ff_core_List.List_map(case_.patterns_, ((_w1) => {
|
|
440
|
+
return ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, _w1.at_)
|
|
441
|
+
}));
|
|
442
|
+
const returnType_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, case_.at_);
|
|
443
|
+
const functionType_ = ff_compiler_Syntax.TConstructor(case_.at_, ("Function$" + ff_core_List.List_size(case_.patterns_)), ff_core_List.Link(environment_.effect_, ff_core_List.List_addAll(parameterTypes_, ff_core_List.Link(returnType_, ff_core_List.Empty()))));
|
|
444
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, case_.at_, expected_, functionType_);
|
|
445
|
+
const environment1_ = ff_core_List.List_foldLeft(ff_core_List.List_zip(parameterTypes_, case_.patterns_), environment_, ((_1, _2) => {
|
|
446
|
+
{
|
|
447
|
+
const environment1_ = _1;
|
|
448
|
+
const t_ = _2.first_;
|
|
449
|
+
const c_ = _2.second_;
|
|
450
|
+
const symbols_ = ff_core_Map.Map_mapValues(ff_compiler_Inference.Inference_inferPattern(self_, environment_, t_, c_), ((_1, _2) => {
|
|
451
|
+
{
|
|
452
|
+
const name_ = _1;
|
|
453
|
+
const at_ = _2.first_;
|
|
454
|
+
const type_ = _2.second_;
|
|
455
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
456
|
+
return ff_compiler_Environment.Scheme(true, false, false, false, ff_compiler_Syntax.Signature(at_, name_, false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Empty(), type_, noEffect_))
|
|
457
|
+
return
|
|
458
|
+
}
|
|
459
|
+
}), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
460
|
+
{
|
|
461
|
+
const _1 = environment_;
|
|
462
|
+
{
|
|
463
|
+
const _c = _1;
|
|
464
|
+
return ff_compiler_Environment.Environment(_c.modulePrefix_, ff_core_Map.Map_addAll(environment1_.symbols_, symbols_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String), _c.traits_, _c.imports_, _c.effect_, _c.selfVariable_)
|
|
465
|
+
return
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return
|
|
469
|
+
}
|
|
470
|
+
}));
|
|
471
|
+
let guards_ = ff_core_List.Empty();
|
|
472
|
+
const environment3_ = ff_core_List.List_foldLeft(case_.guards_, environment1_, ((environment2_, g_) => {
|
|
473
|
+
const guardType_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, g_.at_);
|
|
474
|
+
const guardTerm_ = ff_compiler_Inference.Inference_inferTerm(self_, environment2_, guardType_, g_.term_);
|
|
475
|
+
const symbols_ = ff_core_Map.Map_mapValues(ff_compiler_Inference.Inference_inferPattern(self_, environment2_, guardType_, g_.pattern_), ((_1, _2) => {
|
|
476
|
+
{
|
|
477
|
+
const name_ = _1;
|
|
478
|
+
const at_ = _2.first_;
|
|
479
|
+
const type_ = _2.second_;
|
|
480
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
481
|
+
return ff_compiler_Environment.Scheme(true, false, false, false, ff_compiler_Syntax.Signature(at_, name_, false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Empty(), type_, noEffect_))
|
|
482
|
+
return
|
|
483
|
+
}
|
|
484
|
+
}), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
485
|
+
guards_ = ff_core_List.Link((((_c) => {
|
|
486
|
+
return ff_compiler_Syntax.MatchGuard(_c.at_, guardTerm_, _c.pattern_)
|
|
487
|
+
}))(g_), guards_);
|
|
488
|
+
{
|
|
489
|
+
const _1 = environment2_;
|
|
490
|
+
{
|
|
491
|
+
const _c = _1;
|
|
492
|
+
return ff_compiler_Environment.Environment(_c.modulePrefix_, ff_core_Map.Map_addAll(environment2_.symbols_, symbols_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String), _c.traits_, _c.imports_, _c.effect_, _c.selfVariable_)
|
|
493
|
+
return
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}));
|
|
497
|
+
{
|
|
498
|
+
const _1 = case_;
|
|
499
|
+
{
|
|
500
|
+
const _c = _1;
|
|
501
|
+
return ff_compiler_Syntax.MatchCase(_c.at_, _c.patterns_, ff_core_List.List_reverse(guards_), ff_compiler_Inference.Inference_inferTerm(self_, environment3_, returnType_, case_.body_))
|
|
502
|
+
return
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
export function Inference_inferPattern(self_, environment_, expected_, pattern_) {
|
|
508
|
+
if(ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_)) {
|
|
509
|
+
if((((_1) => {
|
|
510
|
+
{
|
|
511
|
+
if(_1.PVariantAs) {
|
|
512
|
+
const at_ = _1.at_;
|
|
513
|
+
const variableAt_ = _1.variableAt_;
|
|
514
|
+
return ((ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, at_) || ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, variableAt_)) || ff_compiler_LspHook.LspHook_isDefinedAt(self_.lspHook_, variableAt_))
|
|
515
|
+
return
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
{
|
|
519
|
+
if(_1.PAlias) {
|
|
520
|
+
const at_ = _1.at_;
|
|
521
|
+
return (ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, at_) || ff_compiler_LspHook.LspHook_isDefinedAt(self_.lspHook_, at_))
|
|
522
|
+
return
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
{
|
|
526
|
+
return ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, pattern_.at_)
|
|
527
|
+
return
|
|
528
|
+
}
|
|
529
|
+
}))(pattern_)) {
|
|
530
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferPatternHook(self_.unification_, environment_, expected_, pattern_))
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
function literal_(coreTypeName_) {
|
|
534
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, pattern_.at_, expected_, ff_compiler_Syntax.TConstructor(pattern_.at_, ff_compiler_Inference.core_(coreTypeName_), ff_core_List.Empty()));
|
|
535
|
+
return ff_core_Map.empty_()
|
|
536
|
+
}
|
|
537
|
+
{
|
|
538
|
+
const _1 = pattern_;
|
|
539
|
+
{
|
|
540
|
+
if(_1.PString) {
|
|
541
|
+
return literal_("String")
|
|
542
|
+
return
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
{
|
|
546
|
+
if(_1.PInt) {
|
|
547
|
+
return literal_("Int")
|
|
548
|
+
return
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
{
|
|
552
|
+
if(_1.PChar) {
|
|
553
|
+
return literal_("Char")
|
|
554
|
+
return
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
{
|
|
558
|
+
if(_1.PVariable) {
|
|
559
|
+
const at_ = _1.at_;
|
|
560
|
+
if(_1.name_.None) {
|
|
561
|
+
return ff_core_Map.empty_()
|
|
562
|
+
return
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
{
|
|
567
|
+
if(_1.PVariable) {
|
|
568
|
+
const at_ = _1.at_;
|
|
569
|
+
if(_1.name_.Some) {
|
|
570
|
+
const name_ = _1.name_.value_;
|
|
571
|
+
return ff_core_List.List_toMap(ff_core_List.Link(ff_core_Pair.Pair(name_, ff_core_Pair.Pair(at_, expected_)), ff_core_List.Empty()), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String)
|
|
572
|
+
return
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
{
|
|
577
|
+
if(_1.PAlias) {
|
|
578
|
+
const at_ = _1.at_;
|
|
579
|
+
const pattern_ = _1.pattern_;
|
|
580
|
+
const variable_ = _1.variable_;
|
|
581
|
+
return ff_core_Map.Map_add(ff_compiler_Inference.Inference_inferPattern(self_, environment_, expected_, pattern_), variable_, ff_core_Pair.Pair(at_, expected_), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String)
|
|
582
|
+
return
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
{
|
|
586
|
+
if(_1.PVariantAs) {
|
|
587
|
+
const at_ = _1.at_;
|
|
588
|
+
const name_ = _1.name_;
|
|
589
|
+
const variableAt_ = _1.variableAt_;
|
|
590
|
+
const variableOption_ = _1.variable_;
|
|
591
|
+
const instantiated_ = ff_core_Option.Option_else(ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, at_, name_, ff_core_List.Empty(), ff_core_Option.None()), (() => {
|
|
592
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(at_, ("No such variant: " + name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
593
|
+
}));
|
|
594
|
+
if(instantiated_.scheme_.isNewtype_) {
|
|
595
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(at_, "This kind of pattern is not allowed for newtypes"), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
596
|
+
};
|
|
597
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, at_, expected_, instantiated_.scheme_.signature_.returnType_);
|
|
598
|
+
const parameters_ = ff_core_List.List_sortBy(instantiated_.scheme_.signature_.parameters_, ((_w1) => {
|
|
599
|
+
return _w1.name_
|
|
600
|
+
}), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
601
|
+
const recordType_ = ff_compiler_Syntax.TConstructor(at_, ("Record$" + ff_core_List.List_join(ff_core_List.List_map(parameters_, ((_w1) => {
|
|
602
|
+
return _w1.name_
|
|
603
|
+
})), "$")), ff_core_List.List_map(parameters_, ((_w1) => {
|
|
604
|
+
return _w1.valueType_
|
|
605
|
+
})));
|
|
606
|
+
return ff_core_List.List_toMap(ff_core_List.List_map(ff_core_Option.Option_toList(variableOption_), ((_w1) => {
|
|
607
|
+
return ff_core_Pair.Pair(_w1, ff_core_Pair.Pair(variableAt_, recordType_))
|
|
608
|
+
})), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String)
|
|
609
|
+
return
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
{
|
|
613
|
+
if(_1.PVariant) {
|
|
614
|
+
const at_ = _1.at_;
|
|
615
|
+
const name_ = _1.name_;
|
|
616
|
+
const patterns_ = _1.patterns_;
|
|
617
|
+
const instantiated_ = ff_core_Option.Option_else(ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, at_, name_, ff_core_List.Empty(), ff_core_Option.None()), (() => {
|
|
618
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(at_, ("No such variant: " + name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
619
|
+
}));
|
|
620
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, at_, expected_, instantiated_.scheme_.signature_.returnType_);
|
|
621
|
+
if(((ff_core_List.List_size(patterns_) !== ff_core_List.List_size(instantiated_.scheme_.signature_.parameters_)) && (!ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_)))) {
|
|
622
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(at_, (((("Wrong number of subpatterns, expected " + ff_core_List.List_size(instantiated_.scheme_.signature_.parameters_)) + ", got ") + ff_core_List.List_size(patterns_)) + ".")), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
623
|
+
};
|
|
624
|
+
return ff_core_List.List_foldLeft(ff_core_List.List_map(ff_core_List.List_zip(patterns_, instantiated_.scheme_.signature_.parameters_), ((_1) => {
|
|
625
|
+
{
|
|
626
|
+
const pattern_ = _1.first_;
|
|
627
|
+
const parameter_ = _1.second_;
|
|
628
|
+
return ff_compiler_Inference.Inference_inferPattern(self_, environment_, parameter_.valueType_, pattern_)
|
|
629
|
+
return
|
|
630
|
+
}
|
|
631
|
+
})), ff_core_Map.empty_(), ((_w1, _w2) => {
|
|
632
|
+
return ff_core_Map.Map_addAll(_w1, _w2, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String)
|
|
633
|
+
}))
|
|
634
|
+
return
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
export function Inference_inferTerm(self_, environment_, expected_, term_) {
|
|
641
|
+
const hookRecordTypeBox_ = (ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, term_.at_)
|
|
642
|
+
? ff_core_Option.Some((function() {
|
|
643
|
+
const box_ = ff_compiler_LspHook.Box(ff_core_Option.None());
|
|
644
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferTermHook(self_.unification_, environment_, expected_, term_, box_, self_.missing_));
|
|
645
|
+
return box_
|
|
646
|
+
})())
|
|
647
|
+
: ff_core_Option.None());
|
|
648
|
+
function literal_(coreTypeName_) {
|
|
649
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, term_.at_, expected_, ff_compiler_Syntax.TConstructor(term_.at_, ff_compiler_Inference.core_(coreTypeName_), ff_core_List.Empty()));
|
|
650
|
+
return term_
|
|
651
|
+
}
|
|
652
|
+
{
|
|
653
|
+
const _1 = term_;
|
|
654
|
+
{
|
|
655
|
+
if(_1.EString) {
|
|
656
|
+
return literal_("String")
|
|
657
|
+
return
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
{
|
|
661
|
+
if(_1.EChar) {
|
|
662
|
+
return literal_("Char")
|
|
663
|
+
return
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
{
|
|
667
|
+
if(_1.EInt) {
|
|
668
|
+
return literal_("Int")
|
|
669
|
+
return
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
{
|
|
673
|
+
if(_1.EFloat) {
|
|
674
|
+
return literal_("Float")
|
|
675
|
+
return
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
{
|
|
679
|
+
if(_1.EVariable) {
|
|
680
|
+
const e_ = _1;
|
|
681
|
+
return ff_core_Option.Option_else(ff_core_Option.Option_map(ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, e_.at_, e_.name_, ff_core_List.Empty(), ff_core_Option.None()), ((instantiated_) => {
|
|
682
|
+
if(instantiated_.scheme_.isVariable_) {
|
|
683
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, instantiated_.scheme_.signature_.returnType_);
|
|
684
|
+
return term_
|
|
685
|
+
} else {
|
|
686
|
+
return ff_compiler_Inference.Inference_inferEtaExpansion(self_, environment_, expected_, e_.at_, instantiated_.scheme_.signature_, term_)
|
|
687
|
+
}
|
|
688
|
+
})), (() => {
|
|
689
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ("Symbol not in scope: " + e_.name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
690
|
+
}))
|
|
691
|
+
return
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
{
|
|
695
|
+
if(_1.EField) {
|
|
696
|
+
const e_ = _1;
|
|
697
|
+
const recordType_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_);
|
|
698
|
+
if(ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, term_.at_)) {
|
|
699
|
+
ff_core_Option.Option_each(hookRecordTypeBox_, ((_w1) => {
|
|
700
|
+
_w1.value_ = ff_core_Option.Some(recordType_)
|
|
701
|
+
}))
|
|
702
|
+
};
|
|
703
|
+
const record_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, recordType_, e_.record_);
|
|
704
|
+
{
|
|
705
|
+
const _1 = ff_compiler_Unification.Unification_substitute(self_.unification_, recordType_);
|
|
706
|
+
{
|
|
707
|
+
const t_ = _1;
|
|
708
|
+
if(_1.TConstructor) {
|
|
709
|
+
const name_ = _1.name_;
|
|
710
|
+
const typeArguments_ = _1.generics_;
|
|
711
|
+
const _guard1 = ff_core_String.String_startsWith(name_, "Record$", 0);
|
|
712
|
+
if(_guard1) {
|
|
713
|
+
if(ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, e_.at_)) {
|
|
714
|
+
const symbolHook_ = ff_compiler_LspHook.SymbolHook(e_.field_, e_.at_, e_.at_);
|
|
715
|
+
const noEffect_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_);
|
|
716
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferRecordFieldHook(self_.unification_, environment_, expected_, t_, e_.field_))
|
|
717
|
+
};
|
|
718
|
+
const fieldNames_ = ff_core_List.List_dropFirst(ff_core_Array.Array_toList(ff_core_String.String_split(name_, 36)), 1);
|
|
719
|
+
return ff_core_Option.Option_else(ff_core_Option.Option_elseIf(ff_core_Option.Option_map(ff_core_Option.Option_map(ff_core_List.List_find(ff_core_List.List_pairs(fieldNames_), ((_w1) => {
|
|
720
|
+
return (_w1.second_ === e_.field_)
|
|
721
|
+
})), ((_w1) => {
|
|
722
|
+
return _w1.first_
|
|
723
|
+
})), ((index_) => {
|
|
724
|
+
const t1_ = ff_core_List.List_grab(typeArguments_, index_);
|
|
725
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t1_);
|
|
726
|
+
{
|
|
727
|
+
const _1 = e_;
|
|
728
|
+
{
|
|
729
|
+
const _c = _1;
|
|
730
|
+
return ff_compiler_Syntax.EField(_c.at_, _c.newtype_, record_, _c.field_)
|
|
731
|
+
return
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
})), (() => {
|
|
735
|
+
return ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_)
|
|
736
|
+
}), (() => {
|
|
737
|
+
return term_
|
|
738
|
+
})), (() => {
|
|
739
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ((("No such field " + e_.field_) + " on type: ") + ff_compiler_Syntax.Type_show(t_, ff_core_List.Empty()))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
740
|
+
}))
|
|
741
|
+
return
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
{
|
|
746
|
+
const t_ = _1;
|
|
747
|
+
if(_1.TConstructor) {
|
|
748
|
+
const name_ = _1.name_;
|
|
749
|
+
const typeArguments_ = _1.generics_;
|
|
750
|
+
const memberPrefix_ = (name_ + "_");
|
|
751
|
+
const memberName_ = (memberPrefix_ + e_.field_);
|
|
752
|
+
{
|
|
753
|
+
const _1 = ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, e_.at_, memberName_, typeArguments_, ff_core_Option.None());
|
|
754
|
+
{
|
|
755
|
+
if(_1.Some) {
|
|
756
|
+
const instantiated_ = _1.value_;
|
|
757
|
+
const _guard1 = (!instantiated_.scheme_.isVariable_);
|
|
758
|
+
if(_guard1) {
|
|
759
|
+
const signature_ = (((_c) => {
|
|
760
|
+
return ff_compiler_Syntax.Signature(_c.at_, _c.name_, _c.member_, _c.generics_, _c.constraints_, ff_core_List.List_dropFirst(instantiated_.scheme_.signature_.parameters_, 1), _c.returnType_, _c.effect_)
|
|
761
|
+
}))(instantiated_.scheme_.signature_);
|
|
762
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, recordType_, ff_core_List.List_grab(instantiated_.scheme_.signature_.parameters_, 0).valueType_);
|
|
763
|
+
return ff_compiler_Inference.Inference_inferEtaExpansion(self_, environment_, expected_, e_.at_, signature_, term_)
|
|
764
|
+
return
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
{
|
|
769
|
+
if(_1.Some) {
|
|
770
|
+
const instantiated_ = _1.value_;
|
|
771
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, instantiated_.scheme_.signature_.returnType_);
|
|
772
|
+
{
|
|
773
|
+
const _1 = e_;
|
|
774
|
+
{
|
|
775
|
+
const _c = _1;
|
|
776
|
+
return ff_compiler_Syntax.EField(_c.at_, instantiated_.scheme_.isNewtype_, record_, _c.field_)
|
|
777
|
+
return
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
return
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
{
|
|
784
|
+
if(_1.None) {
|
|
785
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ((("No such field " + e_.field_) + " on type: ") + ff_compiler_Syntax.Type_show(t_, ff_core_List.Empty()))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
786
|
+
return
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
return
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
{
|
|
794
|
+
if(_1.TVariable) {
|
|
795
|
+
const _guard1 = ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_);
|
|
796
|
+
if(_guard1) {
|
|
797
|
+
return term_
|
|
798
|
+
return
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
{
|
|
803
|
+
if(_1.TVariable) {
|
|
804
|
+
const index_ = _1.index_;
|
|
805
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ((("No such field " + e_.field_) + " on unknown type: $") + index_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
806
|
+
return
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
return
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
{
|
|
814
|
+
if(_1.EWildcard) {
|
|
815
|
+
const e_ = _1;
|
|
816
|
+
return ff_core_Option.Option_grab(ff_core_Option.Option_map(ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, e_.at_, ("_w" + e_.index_), ff_core_List.Empty(), ff_core_Option.None()), ((instantiated_) => {
|
|
817
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, instantiated_.scheme_.signature_.returnType_);
|
|
818
|
+
return term_
|
|
819
|
+
})))
|
|
820
|
+
return
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
{
|
|
824
|
+
if(_1.EList) {
|
|
825
|
+
const at_ = _1.at_;
|
|
826
|
+
const t_ = _1.elementType_;
|
|
827
|
+
const items_ = _1.items_;
|
|
828
|
+
const listType_ = ff_compiler_Syntax.TConstructor(term_.at_, ff_compiler_Inference.core_("List"), ff_core_List.Link(t_, ff_core_List.Empty()));
|
|
829
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, at_, expected_, listType_);
|
|
830
|
+
return ff_compiler_Syntax.EList(at_, t_, ff_core_List.List_map(items_, ((_1) => {
|
|
831
|
+
{
|
|
832
|
+
const item_ = _1.first_;
|
|
833
|
+
const spread_ = _1.second_;
|
|
834
|
+
return ff_core_Pair.Pair(ff_compiler_Inference.Inference_inferTerm(self_, environment_, (spread_
|
|
835
|
+
? listType_
|
|
836
|
+
: t_), item_), spread_)
|
|
837
|
+
return
|
|
838
|
+
}
|
|
839
|
+
})))
|
|
840
|
+
return
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
{
|
|
844
|
+
if(_1.ESequential) {
|
|
845
|
+
const at_ = _1.at_;
|
|
846
|
+
const before_ = _1.before_;
|
|
847
|
+
const after_ = _1.after_;
|
|
848
|
+
if(ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, before_.at_)) {
|
|
849
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferSequentialStartHook(self_.unification_, term_, self_.missing_))
|
|
850
|
+
};
|
|
851
|
+
const newExpected_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, at_);
|
|
852
|
+
{
|
|
853
|
+
const _1 = before_;
|
|
854
|
+
{
|
|
855
|
+
if(_1.EPipe) {
|
|
856
|
+
const at1_ = _1.at_;
|
|
857
|
+
const value_ = _1.value_;
|
|
858
|
+
const effect1_ = _1.effect_;
|
|
859
|
+
if(_1.function_.ELambda) {
|
|
860
|
+
const at2_ = _1.function_.at_;
|
|
861
|
+
const at3_ = _1.function_.lambda_.at_;
|
|
862
|
+
const effect3_ = _1.function_.lambda_.effect_;
|
|
863
|
+
const cases_ = _1.function_.lambda_.cases_;
|
|
864
|
+
const e_ = ff_compiler_Syntax.EVariant(at_, "ff:core/Unit.Unit", ff_core_List.Empty(), ff_core_Option.None());
|
|
865
|
+
const newCases_ = ff_core_List.List_map(cases_, ((case_) => {
|
|
866
|
+
{
|
|
867
|
+
const _1 = case_;
|
|
868
|
+
{
|
|
869
|
+
const _c = _1;
|
|
870
|
+
return ff_compiler_Syntax.MatchCase(_c.at_, _c.patterns_, _c.guards_, ff_compiler_Syntax.ESequential(case_.at_, case_.body_, e_))
|
|
871
|
+
return
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}));
|
|
875
|
+
const newPipe_ = ff_compiler_Syntax.EPipe(at1_, value_, effect1_, ff_compiler_Syntax.ELambda(at2_, ff_compiler_Syntax.Lambda(at3_, effect3_, newCases_)));
|
|
876
|
+
{
|
|
877
|
+
const _1 = after_;
|
|
878
|
+
{
|
|
879
|
+
if(_1.EVariant) {
|
|
880
|
+
const at_ = _1.at_;
|
|
881
|
+
if(_1.name_ == "ff:core/Unit.Unit") {
|
|
882
|
+
const unitType_ = ff_compiler_Syntax.TConstructor(at_, ff_compiler_Inference.core_("Unit"), ff_core_List.Empty());
|
|
883
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, at_, expected_, unitType_);
|
|
884
|
+
return ff_compiler_Inference.Inference_inferTerm(self_, environment_, newExpected_, newPipe_)
|
|
885
|
+
return
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
{
|
|
890
|
+
return ff_compiler_Syntax.ESequential(at_, ff_compiler_Inference.Inference_inferTerm(self_, environment_, newExpected_, newPipe_), ff_compiler_Inference.Inference_inferTerm(self_, environment_, expected_, after_))
|
|
891
|
+
return
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
return
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
{
|
|
899
|
+
return ff_compiler_Syntax.ESequential(at_, ff_compiler_Inference.Inference_inferTerm(self_, environment_, newExpected_, before_), ff_compiler_Inference.Inference_inferTerm(self_, environment_, expected_, after_))
|
|
900
|
+
return
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
return
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
{
|
|
907
|
+
if(_1.ELet) {
|
|
908
|
+
const e_ = _1;
|
|
909
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(e_.at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
910
|
+
const scheme_ = ff_compiler_Environment.Scheme(true, e_.mutable_, false, false, ff_compiler_Syntax.Signature(e_.at_, e_.name_, false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Empty(), e_.valueType_, noEffect_));
|
|
911
|
+
const environment2_ = (((_c) => {
|
|
912
|
+
return ff_compiler_Environment.Environment(_c.modulePrefix_, ff_core_Map.Map_add(environment_.symbols_, e_.name_, scheme_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String), _c.traits_, _c.imports_, _c.effect_, _c.selfVariable_)
|
|
913
|
+
}))(environment_);
|
|
914
|
+
{
|
|
915
|
+
const _1 = e_;
|
|
916
|
+
{
|
|
917
|
+
const _c = _1;
|
|
918
|
+
return ff_compiler_Syntax.ELet(_c.at_, _c.mutable_, _c.name_, _c.valueType_, ff_compiler_Inference.Inference_inferTerm(self_, environment_, e_.valueType_, e_.value_), ff_compiler_Inference.Inference_inferTerm(self_, environment2_, expected_, e_.body_))
|
|
919
|
+
return
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
return
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
{
|
|
926
|
+
if(_1.ELambda) {
|
|
927
|
+
const at_ = _1.at_;
|
|
928
|
+
const l_ = _1.lambda_;
|
|
929
|
+
do {
|
|
930
|
+
const _1 = l_.cases_;
|
|
931
|
+
{
|
|
932
|
+
if(_1.Link) {
|
|
933
|
+
if(_1.head_.patterns_.Empty) {
|
|
934
|
+
if(_1.head_.guards_.Empty) {
|
|
935
|
+
if(_1.head_.body_.EVariable) {
|
|
936
|
+
const insideAt_ = _1.head_.body_.at_;
|
|
937
|
+
if(_1.head_.body_.name_ == "") {
|
|
938
|
+
if(_1.tail_.Empty) {
|
|
939
|
+
const _guard1 = ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, insideAt_);
|
|
940
|
+
if(_guard1) {
|
|
941
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferLambdaStartHook(self_.unification_, environment_, expected_))
|
|
942
|
+
break
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
{
|
|
952
|
+
if(_1.Link) {
|
|
953
|
+
if(_1.head_.patterns_.Empty) {
|
|
954
|
+
if(_1.head_.guards_.Empty) {
|
|
955
|
+
if(_1.head_.body_.ESequential) {
|
|
956
|
+
if(_1.head_.body_.before_.EVariable) {
|
|
957
|
+
const insideAt_ = _1.head_.body_.before_.at_;
|
|
958
|
+
if(_1.head_.body_.before_.name_ == "") {
|
|
959
|
+
if(_1.head_.body_.after_.EVariant) {
|
|
960
|
+
if(_1.head_.body_.after_.name_ == "ff:core/Unit.Unit") {
|
|
961
|
+
if(_1.tail_.Empty) {
|
|
962
|
+
const _guard1 = ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, insideAt_);
|
|
963
|
+
if(_guard1) {
|
|
964
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferLambdaStartHook(self_.unification_, environment_, expected_))
|
|
965
|
+
break
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
{
|
|
978
|
+
|
|
979
|
+
break
|
|
980
|
+
}
|
|
981
|
+
} while(false);
|
|
982
|
+
const lambda_ = ff_compiler_Inference.Inference_inferLambda(self_, environment_, expected_, l_);
|
|
983
|
+
return ff_compiler_Syntax.ELambda(at_, lambda_)
|
|
984
|
+
return
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
{
|
|
988
|
+
if(_1.EVariant) {
|
|
989
|
+
const e_ = _1;
|
|
990
|
+
const instantiated_ = ff_core_Option.Option_else(ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, e_.at_, e_.name_, e_.typeArguments_, e_.arguments_), (() => {
|
|
991
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ("Symbol not in scope: " + e_.name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
992
|
+
}));
|
|
993
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, instantiated_.scheme_.signature_.returnType_);
|
|
994
|
+
const arguments_ = ff_core_Option.Option_map(e_.arguments_, ((_w1) => {
|
|
995
|
+
return ff_compiler_Inference.Inference_inferArguments(self_, e_.at_, e_.name_, environment_, instantiated_.scheme_.signature_.parameters_, _w1)
|
|
996
|
+
}));
|
|
997
|
+
{
|
|
998
|
+
const _1 = e_;
|
|
999
|
+
{
|
|
1000
|
+
const _c = _1;
|
|
1001
|
+
return ff_compiler_Syntax.EVariant(_c.at_, _c.name_, ff_core_List.List_map(instantiated_.typeArguments_, ((_w1) => {
|
|
1002
|
+
return _w1.second_
|
|
1003
|
+
})), arguments_)
|
|
1004
|
+
return
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
return
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
{
|
|
1011
|
+
if(_1.EVariantIs) {
|
|
1012
|
+
const e_ = _1;
|
|
1013
|
+
const instantiated_ = ff_core_Option.Option_else(ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, e_.at_, e_.name_, e_.typeArguments_, ff_core_Option.None()), (() => {
|
|
1014
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ("Symbol not in scope: " + e_.name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1015
|
+
}));
|
|
1016
|
+
const parameters_ = ff_core_List.List_sortBy(instantiated_.scheme_.signature_.parameters_, ((_w1) => {
|
|
1017
|
+
return _w1.name_
|
|
1018
|
+
}), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
1019
|
+
const recordType_ = ff_compiler_Syntax.TConstructor(e_.at_, ("Record$" + ff_core_List.List_join(ff_core_List.List_map(parameters_, ((_w1) => {
|
|
1020
|
+
return _w1.name_
|
|
1021
|
+
})), "$")), ff_core_List.List_map(parameters_, ((_w1) => {
|
|
1022
|
+
return _w1.valueType_
|
|
1023
|
+
})));
|
|
1024
|
+
const functionType_ = ff_compiler_Syntax.TConstructor(e_.at_, "Function$1", ff_core_List.Link(ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_), ff_core_List.Link(instantiated_.scheme_.signature_.returnType_, ff_core_List.Link(ff_compiler_Syntax.TConstructor(e_.at_, ff_compiler_Inference.core_("Option"), ff_core_List.Link(recordType_, ff_core_List.Empty())), ff_core_List.Empty()))));
|
|
1025
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, functionType_);
|
|
1026
|
+
{
|
|
1027
|
+
const _1 = e_;
|
|
1028
|
+
{
|
|
1029
|
+
const _c = _1;
|
|
1030
|
+
return ff_compiler_Syntax.EVariantIs(_c.at_, _c.name_, ff_core_List.List_map(instantiated_.typeArguments_, ((_w1) => {
|
|
1031
|
+
return _w1.second_
|
|
1032
|
+
})))
|
|
1033
|
+
return
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
return
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
{
|
|
1040
|
+
if(_1.ECopy) {
|
|
1041
|
+
const e_ = _1;
|
|
1042
|
+
const scheme_ = ff_core_Option.Option_else(ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, e_.at_, e_.name_, ff_core_List.Empty(), ff_core_Option.None()), (() => {
|
|
1043
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ("Symbol not in scope: " + e_.name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1044
|
+
})).scheme_;
|
|
1045
|
+
if(scheme_.isNewtype_) {
|
|
1046
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, "Newtypes can't be copied"), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1047
|
+
};
|
|
1048
|
+
const signature_ = scheme_.signature_;
|
|
1049
|
+
if(ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_)) {
|
|
1050
|
+
ff_core_List.List_each(ff_core_List.List_pairs(e_.arguments_), ((_1) => {
|
|
1051
|
+
{
|
|
1052
|
+
const i_ = _1.first_;
|
|
1053
|
+
const a_ = _1.second_;
|
|
1054
|
+
const p_ = ff_core_List.List_find(signature_.parameters_, ((_w1) => {
|
|
1055
|
+
return (_w1.name_ === a_.name_)
|
|
1056
|
+
}));
|
|
1057
|
+
if((ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, a_.at_) || ff_core_Option.Option_any(p_, ((_w1) => {
|
|
1058
|
+
return ff_compiler_LspHook.LspHook_isDefinedAt(self_.lspHook_, _w1.at_)
|
|
1059
|
+
})))) {
|
|
1060
|
+
const arguments_ = ff_core_List.List_map(e_.arguments_, ((f_) => {
|
|
1061
|
+
{
|
|
1062
|
+
const _1 = f_;
|
|
1063
|
+
{
|
|
1064
|
+
const _c = _1;
|
|
1065
|
+
return ff_compiler_Syntax.Argument(_c.at_, ff_core_Option.Some(f_.name_), _c.value_)
|
|
1066
|
+
return
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
}));
|
|
1070
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferArgumentHook(self_.unification_, environment_, true, term_.at_, e_.name_, signature_.parameters_, arguments_, i_))
|
|
1071
|
+
}
|
|
1072
|
+
return
|
|
1073
|
+
}
|
|
1074
|
+
}))
|
|
1075
|
+
};
|
|
1076
|
+
const parameterNames_ = ff_core_List.List_map(signature_.parameters_, ((_w1) => {
|
|
1077
|
+
return _w1.name_
|
|
1078
|
+
}));
|
|
1079
|
+
ff_core_Option.Option_each(ff_core_List.List_find(e_.arguments_, ((a_) => {
|
|
1080
|
+
return (!ff_core_List.List_any(parameterNames_, ((_w1) => {
|
|
1081
|
+
return (_w1 === a_.name_)
|
|
1082
|
+
})))
|
|
1083
|
+
})), ((_1) => {
|
|
1084
|
+
{
|
|
1085
|
+
const at_ = _1.at_;
|
|
1086
|
+
const name_ = _1.name_;
|
|
1087
|
+
const value_ = _1.value_;
|
|
1088
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(at_, ("Unknown parameter: " + name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1089
|
+
return
|
|
1090
|
+
}
|
|
1091
|
+
}));
|
|
1092
|
+
const arguments_ = ff_core_List.List_map(parameterNames_, ((name_) => {
|
|
1093
|
+
return ff_core_Option.Option_else(ff_core_Option.Option_map(ff_core_List.List_find(e_.arguments_, ((_w1) => {
|
|
1094
|
+
return (_w1.name_ === name_)
|
|
1095
|
+
})), ((_1) => {
|
|
1096
|
+
{
|
|
1097
|
+
const at_ = _1.at_;
|
|
1098
|
+
const value_ = _1.value_;
|
|
1099
|
+
return ff_compiler_Syntax.Argument(at_, ff_core_Option.Some(name_), value_)
|
|
1100
|
+
return
|
|
1101
|
+
}
|
|
1102
|
+
})), (() => {
|
|
1103
|
+
const at_ = (((_c) => {
|
|
1104
|
+
return ff_compiler_Syntax.Location((e_.at_.file_ + "/<copy>"), _c.line_, _c.column_)
|
|
1105
|
+
}))(e_.at_);
|
|
1106
|
+
return ff_compiler_Syntax.Argument(at_, ff_core_Option.Some(name_), ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "_c"), name_))
|
|
1107
|
+
}))
|
|
1108
|
+
}));
|
|
1109
|
+
const body_ = ff_compiler_Syntax.EVariant(e_.at_, e_.name_, ff_core_List.Empty(), ff_core_Option.Some(arguments_));
|
|
1110
|
+
const effect_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_);
|
|
1111
|
+
const e1_ = ff_compiler_Syntax.EPipe(e_.at_, e_.record_, effect_, ff_compiler_Syntax.ELambda(e_.at_, ff_compiler_Syntax.Lambda(e_.at_, effect_, ff_core_List.Link(ff_compiler_Syntax.MatchCase(e_.at_, ff_core_List.Link(ff_compiler_Syntax.PVariable(e_.at_, ff_core_Option.Some("_c")), ff_core_List.Empty()), ff_core_List.Empty(), body_), ff_core_List.Empty()))));
|
|
1112
|
+
return ff_compiler_Inference.Inference_inferTerm(self_, environment_, expected_, e1_)
|
|
1113
|
+
return
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
{
|
|
1117
|
+
if(_1.EPipe) {
|
|
1118
|
+
const e_ = _1;
|
|
1119
|
+
const valueType_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_);
|
|
1120
|
+
const functionType_ = ff_compiler_Syntax.TConstructor(e_.at_, "Function$1", ff_core_List.Link(e_.effect_, ff_core_List.Link(valueType_, ff_core_List.Link(expected_, ff_core_List.Empty()))));
|
|
1121
|
+
const value_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, valueType_, e_.value_);
|
|
1122
|
+
const function_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, functionType_, e_.function_);
|
|
1123
|
+
ff_compiler_Unification.Unification_affect(self_.unification_, term_.at_, e_.effect_, environment_.effect_);
|
|
1124
|
+
{
|
|
1125
|
+
const _1 = e_;
|
|
1126
|
+
{
|
|
1127
|
+
const _c = _1;
|
|
1128
|
+
return ff_compiler_Syntax.EPipe(_c.at_, value_, _c.effect_, function_)
|
|
1129
|
+
return
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
return
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
{
|
|
1136
|
+
if(_1.ECall) {
|
|
1137
|
+
const e_ = _1;
|
|
1138
|
+
if((ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_) && (((_1) => {
|
|
1139
|
+
{
|
|
1140
|
+
if(_1.StaticCall) {
|
|
1141
|
+
return true
|
|
1142
|
+
return
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
{
|
|
1146
|
+
return false
|
|
1147
|
+
return
|
|
1148
|
+
}
|
|
1149
|
+
}))(e_.target_))) {
|
|
1150
|
+
return term_
|
|
1151
|
+
} else {
|
|
1152
|
+
const call_ = (((_1) => {
|
|
1153
|
+
{
|
|
1154
|
+
if(_1.DynamicCall) {
|
|
1155
|
+
const call_ = _1;
|
|
1156
|
+
return call_
|
|
1157
|
+
return
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
{
|
|
1161
|
+
if(_1.StaticCall) {
|
|
1162
|
+
return ff_compiler_Inference.fail_(e_.at_, "Internal error: Static calls not expected in the Inference phase")
|
|
1163
|
+
return
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
}))(e_.target_);
|
|
1167
|
+
{
|
|
1168
|
+
const _1 = call_.function_;
|
|
1169
|
+
{
|
|
1170
|
+
if(_1.EVariable) {
|
|
1171
|
+
const variableAt_ = _1.at_;
|
|
1172
|
+
const x_ = _1.name_;
|
|
1173
|
+
if(ff_core_Option.Option_any(ff_core_String.String_first(x_), ((c_) => {
|
|
1174
|
+
return ((c_ !== 95) && (!ff_core_Char.Char_isAsciiLetter(c_)))
|
|
1175
|
+
}))) {
|
|
1176
|
+
return ff_compiler_Inference.Inference_inferOperator(self_, environment_, expected_, x_, term_)
|
|
1177
|
+
} else {
|
|
1178
|
+
{
|
|
1179
|
+
const _1 = ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, e_.at_, x_, e_.typeArguments_, ff_core_Option.Some(e_.arguments_));
|
|
1180
|
+
{
|
|
1181
|
+
if(_1.Some) {
|
|
1182
|
+
const instantiated_ = _1.value_;
|
|
1183
|
+
if(instantiated_.scheme_.isVariable_) {
|
|
1184
|
+
return ff_compiler_Inference.Inference_inferLambdaCall(self_, environment_, expected_, term_)
|
|
1185
|
+
} else {
|
|
1186
|
+
const signature_ = instantiated_.scheme_.signature_;
|
|
1187
|
+
return ff_compiler_Inference.Inference_inferFunctionCall(self_, environment_, expected_, signature_, instantiated_.scheme_.isTraitMethod_, instantiated_.typeArguments_, term_, x_)
|
|
1188
|
+
}
|
|
1189
|
+
return
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
{
|
|
1193
|
+
if(_1.None) {
|
|
1194
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(variableAt_, ("No such function: " + x_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1195
|
+
return
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
return
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
{
|
|
1204
|
+
if(_1.EField) {
|
|
1205
|
+
const f_ = _1;
|
|
1206
|
+
const recordType_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, f_.at_);
|
|
1207
|
+
if(ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, term_.at_)) {
|
|
1208
|
+
ff_core_Option.Option_each(hookRecordTypeBox_, ((_w1) => {
|
|
1209
|
+
_w1.value_ = ff_core_Option.Some(recordType_)
|
|
1210
|
+
}))
|
|
1211
|
+
};
|
|
1212
|
+
const record_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, recordType_, f_.record_);
|
|
1213
|
+
const e2_ = (((_c) => {
|
|
1214
|
+
return ff_compiler_Syntax.ECall(_c.at_, (((_c) => {
|
|
1215
|
+
return ff_compiler_Syntax.DynamicCall((((_c) => {
|
|
1216
|
+
return ff_compiler_Syntax.EField(_c.at_, _c.newtype_, record_, _c.field_)
|
|
1217
|
+
}))(f_), _c.tailCall_)
|
|
1218
|
+
}))(call_), _c.effect_, _c.typeArguments_, _c.arguments_, _c.dictionaries_)
|
|
1219
|
+
}))(e_);
|
|
1220
|
+
{
|
|
1221
|
+
const _1 = ff_compiler_Unification.Unification_substitute(self_.unification_, recordType_);
|
|
1222
|
+
{
|
|
1223
|
+
const t_ = _1;
|
|
1224
|
+
if(_1.TConstructor) {
|
|
1225
|
+
const name_ = _1.name_;
|
|
1226
|
+
const methodName_ = ((name_ + "_") + f_.field_);
|
|
1227
|
+
const arguments_ = ff_core_List.Link(ff_compiler_Syntax.Argument(f_.record_.at_, ff_core_Option.None(), f_.record_), e_.arguments_);
|
|
1228
|
+
{
|
|
1229
|
+
const _1 = ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, f_.at_, methodName_, ff_core_List.Empty(), ff_core_Option.Some(arguments_));
|
|
1230
|
+
{
|
|
1231
|
+
if(_1.Some) {
|
|
1232
|
+
const instantiated_ = _1.value_;
|
|
1233
|
+
const _guard1 = (!instantiated_.scheme_.isVariable_);
|
|
1234
|
+
if(_guard1) {
|
|
1235
|
+
return ff_compiler_Inference.Inference_inferMethodCall(self_, environment_, expected_, instantiated_.scheme_.signature_, instantiated_.typeArguments_, e2_, record_, recordType_, methodName_)
|
|
1236
|
+
return
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
{
|
|
1241
|
+
if(_1.Some) {
|
|
1242
|
+
const instantiated_ = _1.value_;
|
|
1243
|
+
return ff_compiler_Inference.Inference_inferLambdaCall(self_, environment_, expected_, e2_)
|
|
1244
|
+
return
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
{
|
|
1248
|
+
if(_1.None) {
|
|
1249
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(f_.at_, ((("No such field " + f_.field_) + " on type: ") + ff_compiler_Syntax.Type_show(t_, ff_core_List.Empty()))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1250
|
+
return
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
return
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
{
|
|
1258
|
+
if(_1.TVariable) {
|
|
1259
|
+
const _guard1 = ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_);
|
|
1260
|
+
if(_guard1) {
|
|
1261
|
+
return ff_compiler_Inference.Inference_inferLambdaCall(self_, environment_, expected_, e2_)
|
|
1262
|
+
return
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
{
|
|
1267
|
+
if(_1.TVariable) {
|
|
1268
|
+
const index_ = _1.index_;
|
|
1269
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(f_.at_, ((("No such field " + f_.field_) + " on unknown type: $") + index_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1270
|
+
return
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
return
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
{
|
|
1278
|
+
return ff_compiler_Inference.Inference_inferLambdaCall(self_, environment_, expected_, term_)
|
|
1279
|
+
return
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
return
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
{
|
|
1287
|
+
if(_1.ERecord) {
|
|
1288
|
+
const e_ = _1;
|
|
1289
|
+
const fields_ = ff_core_List.List_sortBy(e_.fields_, ((_w1) => {
|
|
1290
|
+
return _w1.name_
|
|
1291
|
+
}), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
1292
|
+
const fieldTypes_ = ff_core_List.List_map(fields_, ((_w1) => {
|
|
1293
|
+
return ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, _w1.at_)
|
|
1294
|
+
}));
|
|
1295
|
+
const recordType_ = ff_compiler_Syntax.TConstructor(e_.at_, ("Record$" + ff_core_List.List_join(ff_core_List.List_map(fields_, ((_w1) => {
|
|
1296
|
+
return _w1.name_
|
|
1297
|
+
})), "$")), fieldTypes_);
|
|
1298
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, recordType_);
|
|
1299
|
+
const newFields_ = ff_core_List.List_map(ff_core_List.List_zip(fields_, fieldTypes_), ((_1) => {
|
|
1300
|
+
{
|
|
1301
|
+
const field_ = _1.first_;
|
|
1302
|
+
const t_ = _1.second_;
|
|
1303
|
+
{
|
|
1304
|
+
const _1 = field_;
|
|
1305
|
+
{
|
|
1306
|
+
const _c = _1;
|
|
1307
|
+
return ff_compiler_Syntax.Field(_c.at_, _c.name_, ff_compiler_Inference.Inference_inferTerm(self_, environment_, t_, field_.value_))
|
|
1308
|
+
return
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
return
|
|
1312
|
+
}
|
|
1313
|
+
}));
|
|
1314
|
+
{
|
|
1315
|
+
const _1 = e_;
|
|
1316
|
+
{
|
|
1317
|
+
const _c = _1;
|
|
1318
|
+
return ff_compiler_Syntax.ERecord(_c.at_, newFields_)
|
|
1319
|
+
return
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
return
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
{
|
|
1326
|
+
if(_1.EFunctions) {
|
|
1327
|
+
const at_ = _1.at_;
|
|
1328
|
+
const functions_ = _1.functions_;
|
|
1329
|
+
const body_ = _1.body_;
|
|
1330
|
+
const functionMap_ = ff_core_List.List_toMap(ff_core_List.List_map(functions_, ((f_) => {
|
|
1331
|
+
const scheme_ = ff_compiler_Environment.Scheme(false, false, false, false, f_.signature_);
|
|
1332
|
+
return ff_core_Pair.Pair(f_.signature_.name_, scheme_)
|
|
1333
|
+
})), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
1334
|
+
const environment2_ = (((_c) => {
|
|
1335
|
+
return ff_compiler_Environment.Environment(_c.modulePrefix_, ff_core_Map.Map_addAll(environment_.symbols_, functionMap_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String), _c.traits_, _c.imports_, _c.effect_, _c.selfVariable_)
|
|
1336
|
+
}))(environment_);
|
|
1337
|
+
const newFunctions_ = ff_core_List.List_map(functions_, ((_w1) => {
|
|
1338
|
+
return ff_compiler_Inference.Inference_inferFunctionDefinition(self_, environment2_, _w1)
|
|
1339
|
+
}));
|
|
1340
|
+
const newBody_ = ff_compiler_Inference.Inference_inferTerm(self_, environment2_, expected_, body_);
|
|
1341
|
+
return ff_compiler_Syntax.EFunctions(at_, newFunctions_, newBody_)
|
|
1342
|
+
return
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
{
|
|
1346
|
+
if(_1.EAssign) {
|
|
1347
|
+
const e_ = _1;
|
|
1348
|
+
return ff_core_Option.Option_else(ff_core_Option.Option_map(ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, e_.at_, e_.variable_, ff_core_List.Empty(), ff_core_Option.None()), ((instantiated_) => {
|
|
1349
|
+
if((instantiated_.scheme_.isMutable_ || ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_))) {
|
|
1350
|
+
const value_ = ff_compiler_Inference.Inference_inferAssignment(self_, environment_, expected_, e_.at_, e_.operator_, e_.value_, instantiated_.scheme_.signature_);
|
|
1351
|
+
{
|
|
1352
|
+
const _1 = e_;
|
|
1353
|
+
{
|
|
1354
|
+
const _c = _1;
|
|
1355
|
+
return ff_compiler_Syntax.EAssign(_c.at_, _c.operator_, _c.variable_, value_)
|
|
1356
|
+
return
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
} else {
|
|
1360
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ("Symbol is not mutable: " + e_.variable_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1361
|
+
}
|
|
1362
|
+
})), (() => {
|
|
1363
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ("Symbol not in scope: " + e_.variable_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1364
|
+
}))
|
|
1365
|
+
return
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
{
|
|
1369
|
+
if(_1.EAssignField) {
|
|
1370
|
+
const e_ = _1;
|
|
1371
|
+
const recordType_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_);
|
|
1372
|
+
const record_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, recordType_, e_.record_);
|
|
1373
|
+
{
|
|
1374
|
+
const _1 = ff_compiler_Unification.Unification_substitute(self_.unification_, recordType_);
|
|
1375
|
+
{
|
|
1376
|
+
const t_ = _1;
|
|
1377
|
+
if(_1.TConstructor) {
|
|
1378
|
+
const name_ = _1.name_;
|
|
1379
|
+
const typeArguments_ = _1.generics_;
|
|
1380
|
+
const _guard1 = ff_core_String.String_startsWith(name_, "Record$", 0);
|
|
1381
|
+
if(_guard1) {
|
|
1382
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ("Can't assign fields of anonymous records: " + e_.field_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1383
|
+
return
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
{
|
|
1388
|
+
const t_ = _1;
|
|
1389
|
+
if(_1.TConstructor) {
|
|
1390
|
+
const name_ = _1.name_;
|
|
1391
|
+
const typeArguments_ = _1.generics_;
|
|
1392
|
+
const methodName_ = ((name_ + "_") + e_.field_);
|
|
1393
|
+
{
|
|
1394
|
+
const _1 = ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, e_.at_, methodName_, typeArguments_, ff_core_Option.None());
|
|
1395
|
+
{
|
|
1396
|
+
if(_1.Some) {
|
|
1397
|
+
const instantiated_ = _1.value_;
|
|
1398
|
+
const _guard1 = (instantiated_.scheme_.isMutable_ || ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_));
|
|
1399
|
+
if(_guard1) {
|
|
1400
|
+
const value_ = ff_compiler_Inference.Inference_inferAssignment(self_, environment_, expected_, e_.at_, e_.operator_, e_.value_, instantiated_.scheme_.signature_);
|
|
1401
|
+
{
|
|
1402
|
+
const _1 = e_;
|
|
1403
|
+
{
|
|
1404
|
+
const _c = _1;
|
|
1405
|
+
return ff_compiler_Syntax.EAssignField(_c.at_, _c.operator_, record_, _c.field_, value_)
|
|
1406
|
+
return
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
return
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
{
|
|
1414
|
+
if(_1.Some) {
|
|
1415
|
+
const instantiated_ = _1.value_;
|
|
1416
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ((("Can't assign an immutable field " + e_.field_) + " on type: ") + ff_compiler_Syntax.Type_show(t_, ff_core_List.Empty()))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1417
|
+
return
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
{
|
|
1421
|
+
if(_1.None) {
|
|
1422
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ((("No such field " + e_.field_) + " on type: ") + ff_compiler_Syntax.Type_show(t_, ff_core_List.Empty()))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1423
|
+
return
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
return
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
{
|
|
1431
|
+
if(_1.TVariable) {
|
|
1432
|
+
const _guard1 = ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_);
|
|
1433
|
+
if(_guard1) {
|
|
1434
|
+
return term_
|
|
1435
|
+
return
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
{
|
|
1440
|
+
if(_1.TVariable) {
|
|
1441
|
+
const index_ = _1.index_;
|
|
1442
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ((("No such field " + e_.field_) + " on unknown type: $") + index_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1443
|
+
return
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
return
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
export function Inference_inferAssignment(self_, environment_, expected_, at_, operator_, value_, signature_) {
|
|
1454
|
+
const t_ = signature_.returnType_;
|
|
1455
|
+
if(((operator_ === "+") || (operator_ === "-"))) {
|
|
1456
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, at_, t_, ff_compiler_Syntax.TConstructor(at_, ff_compiler_Inference.core_("Int"), ff_core_List.Empty()))
|
|
1457
|
+
} else if((operator_ !== "")) {
|
|
1458
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(at_, (("Only +=, -= and = assignments are supported. Got: " + operator_) + "=")), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1459
|
+
} else {};
|
|
1460
|
+
const newValue_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t_, value_);
|
|
1461
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, at_, expected_, ff_compiler_Syntax.TConstructor(at_, ff_compiler_Inference.core_("Unit"), ff_core_List.Empty()));
|
|
1462
|
+
return newValue_
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
export function Inference_inferMethodCall(self_, environment_, expected_, signature_, instantiation_, term_, record_, recordType_, name_) {
|
|
1466
|
+
const e_ = (((_1) => {
|
|
1467
|
+
{
|
|
1468
|
+
if(_1.ECall) {
|
|
1469
|
+
const e_ = _1;
|
|
1470
|
+
return e_
|
|
1471
|
+
return
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
{
|
|
1475
|
+
return ff_compiler_Inference.fail_(term_.at_, "Call expected")
|
|
1476
|
+
return
|
|
1477
|
+
}
|
|
1478
|
+
}))(term_);
|
|
1479
|
+
const call_ = (((_1) => {
|
|
1480
|
+
{
|
|
1481
|
+
if(_1.DynamicCall) {
|
|
1482
|
+
const call_ = _1;
|
|
1483
|
+
return call_
|
|
1484
|
+
return
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
{
|
|
1488
|
+
if(_1.StaticCall) {
|
|
1489
|
+
return ff_compiler_Inference.fail_(e_.at_, "Internal error: Static calls not expected in inferMethodCall")
|
|
1490
|
+
return
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
}))(e_.target_);
|
|
1494
|
+
const selfParameter_ = ff_core_List.List_grabFirst(signature_.parameters_);
|
|
1495
|
+
const selfArgument_ = ff_compiler_Syntax.Argument(record_.at_, ff_core_Option.Some(selfParameter_.name_), record_);
|
|
1496
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, term_.at_, expected_, signature_.returnType_);
|
|
1497
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, term_.at_, selfParameter_.valueType_, recordType_);
|
|
1498
|
+
const arguments_ = ff_compiler_Inference.Inference_inferArguments(self_, term_.at_, name_, environment_, ff_core_List.List_dropFirst(signature_.parameters_, 1), e_.arguments_);
|
|
1499
|
+
ff_compiler_Unification.Unification_affect(self_.unification_, term_.at_, signature_.effect_, environment_.effect_);
|
|
1500
|
+
{
|
|
1501
|
+
const _1 = e_;
|
|
1502
|
+
{
|
|
1503
|
+
const _c = _1;
|
|
1504
|
+
return ff_compiler_Syntax.ECall(_c.at_, ff_compiler_Syntax.StaticCall(name_, call_.tailCall_, false), signature_.effect_, ff_core_List.List_map(instantiation_, ((_w1) => {
|
|
1505
|
+
return _w1.second_
|
|
1506
|
+
})), ff_core_List.Link(selfArgument_, arguments_), _c.dictionaries_)
|
|
1507
|
+
return
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
export function Inference_inferFunctionCall(self_, environment_, expected_, signature_, instanceCall_, instantiation_, term_, name_) {
|
|
1513
|
+
const e_ = (((_1) => {
|
|
1514
|
+
{
|
|
1515
|
+
if(_1.ECall) {
|
|
1516
|
+
const e_ = _1;
|
|
1517
|
+
return e_
|
|
1518
|
+
return
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
{
|
|
1522
|
+
return ff_compiler_Inference.fail_(term_.at_, "Call expected")
|
|
1523
|
+
return
|
|
1524
|
+
}
|
|
1525
|
+
}))(term_);
|
|
1526
|
+
const call_ = (((_1) => {
|
|
1527
|
+
{
|
|
1528
|
+
if(_1.DynamicCall) {
|
|
1529
|
+
const call_ = _1;
|
|
1530
|
+
return call_
|
|
1531
|
+
return
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
{
|
|
1535
|
+
if(_1.StaticCall) {
|
|
1536
|
+
return ff_compiler_Inference.fail_(e_.at_, "Internal error: Static calls not expected in inferFunctionCall")
|
|
1537
|
+
return
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
}))(e_.target_);
|
|
1541
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, signature_.returnType_);
|
|
1542
|
+
const arguments_ = ff_compiler_Inference.Inference_inferArguments(self_, e_.at_, name_, environment_, signature_.parameters_, e_.arguments_);
|
|
1543
|
+
ff_compiler_Unification.Unification_affect(self_.unification_, term_.at_, signature_.effect_, environment_.effect_);
|
|
1544
|
+
{
|
|
1545
|
+
const _1 = e_;
|
|
1546
|
+
{
|
|
1547
|
+
const _c = _1;
|
|
1548
|
+
return ff_compiler_Syntax.ECall(_c.at_, ff_compiler_Syntax.StaticCall(name_, call_.tailCall_, instanceCall_), signature_.effect_, ff_core_List.List_map(instantiation_, ((_w1) => {
|
|
1549
|
+
return _w1.second_
|
|
1550
|
+
})), arguments_, _c.dictionaries_)
|
|
1551
|
+
return
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
export function Inference_inferLambdaCall(self_, environment_, expected_, term_) {
|
|
1557
|
+
const e_ = (((_1) => {
|
|
1558
|
+
{
|
|
1559
|
+
if(_1.ECall) {
|
|
1560
|
+
const e_ = _1;
|
|
1561
|
+
return e_
|
|
1562
|
+
return
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
{
|
|
1566
|
+
return ff_compiler_Inference.fail_(term_.at_, "Call expected")
|
|
1567
|
+
return
|
|
1568
|
+
}
|
|
1569
|
+
}))(term_);
|
|
1570
|
+
const call_ = (((_1) => {
|
|
1571
|
+
{
|
|
1572
|
+
if(_1.DynamicCall) {
|
|
1573
|
+
const call_ = _1;
|
|
1574
|
+
const _guard1 = (!call_.tailCall_);
|
|
1575
|
+
if(_guard1) {
|
|
1576
|
+
return call_
|
|
1577
|
+
return
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
{
|
|
1582
|
+
if(_1.DynamicCall) {
|
|
1583
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, "Tailcalls not supported on lambda functions"), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1584
|
+
return
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
{
|
|
1588
|
+
if(_1.StaticCall) {
|
|
1589
|
+
return ff_compiler_Inference.fail_(e_.at_, "Internal error: Static calls not expected in inferLambdaCall")
|
|
1590
|
+
return
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
}))(e_.target_);
|
|
1594
|
+
const effect_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, term_.at_);
|
|
1595
|
+
const argumentTypes_ = ff_core_List.List_map(e_.arguments_, ((_w1) => {
|
|
1596
|
+
return ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, _w1.at_)
|
|
1597
|
+
}));
|
|
1598
|
+
const functionType_ = ff_compiler_Syntax.TConstructor(e_.at_, ("Function$" + ff_core_List.List_size(e_.arguments_)), ff_core_List.Link(effect_, ff_core_List.List_addAll(argumentTypes_, ff_core_List.Link(expected_, ff_core_List.Empty()))));
|
|
1599
|
+
const function_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, functionType_, call_.function_);
|
|
1600
|
+
const arguments_ = ff_core_List.List_map(ff_core_List.List_zip(e_.arguments_, argumentTypes_), ((_1) => {
|
|
1601
|
+
{
|
|
1602
|
+
const argument_ = _1.first_;
|
|
1603
|
+
const t_ = _1.second_;
|
|
1604
|
+
ff_core_Option.Option_each(argument_.name_, ((name_) => {
|
|
1605
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(argument_.at_, ("Named argument not allowed here: " + name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1606
|
+
}));
|
|
1607
|
+
{
|
|
1608
|
+
const _1 = argument_;
|
|
1609
|
+
{
|
|
1610
|
+
const _c = _1;
|
|
1611
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, ff_compiler_Inference.Inference_inferTerm(self_, environment_, t_, argument_.value_))
|
|
1612
|
+
return
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
return
|
|
1616
|
+
}
|
|
1617
|
+
}));
|
|
1618
|
+
ff_core_Option.Option_each(ff_core_List.List_first(e_.typeArguments_), ((typeArgument_) => {
|
|
1619
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(typeArgument_.at_, "Type arguments not allowed here"), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1620
|
+
}));
|
|
1621
|
+
ff_compiler_Unification.Unification_affect(self_.unification_, term_.at_, effect_, environment_.effect_);
|
|
1622
|
+
{
|
|
1623
|
+
const _1 = e_;
|
|
1624
|
+
{
|
|
1625
|
+
const _c = _1;
|
|
1626
|
+
return ff_compiler_Syntax.ECall(_c.at_, (((_c) => {
|
|
1627
|
+
return ff_compiler_Syntax.DynamicCall(function_, _c.tailCall_)
|
|
1628
|
+
}))(call_), effect_, ff_core_List.Empty(), arguments_, _c.dictionaries_)
|
|
1629
|
+
return
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
export function Inference_inferOperator(self_, environment_, expected_, operator_, term_) {
|
|
1635
|
+
const e_ = (((_1) => {
|
|
1636
|
+
{
|
|
1637
|
+
if(_1.ECall) {
|
|
1638
|
+
const e_ = _1;
|
|
1639
|
+
return e_
|
|
1640
|
+
return
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
{
|
|
1644
|
+
return ff_compiler_Inference.fail_(term_.at_, "Call expected")
|
|
1645
|
+
return
|
|
1646
|
+
}
|
|
1647
|
+
}))(term_);
|
|
1648
|
+
const target_ = ff_compiler_Syntax.StaticCall(operator_, false, false);
|
|
1649
|
+
{
|
|
1650
|
+
const _1 = e_.arguments_;
|
|
1651
|
+
{
|
|
1652
|
+
if(_1.Link) {
|
|
1653
|
+
const a1_ = _1.head_;
|
|
1654
|
+
if(_1.tail_.Empty) {
|
|
1655
|
+
const _guard1 = (operator_ === "!");
|
|
1656
|
+
if(_guard1) {
|
|
1657
|
+
const t_ = ff_compiler_Syntax.TConstructor(e_.at_, ff_compiler_Inference.core_("Bool"), ff_core_List.Empty());
|
|
1658
|
+
const e1_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t_, a1_.value_);
|
|
1659
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t_);
|
|
1660
|
+
{
|
|
1661
|
+
const _1 = e_;
|
|
1662
|
+
{
|
|
1663
|
+
const _c = _1;
|
|
1664
|
+
return ff_compiler_Syntax.ECall(_c.at_, target_, _c.effect_, _c.typeArguments_, ff_core_List.Link((((_c) => {
|
|
1665
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, e1_)
|
|
1666
|
+
}))(a1_), ff_core_List.Empty()), _c.dictionaries_)
|
|
1667
|
+
return
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
return
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
{
|
|
1676
|
+
if(_1.Link) {
|
|
1677
|
+
const a1_ = _1.head_;
|
|
1678
|
+
if(_1.tail_.Empty) {
|
|
1679
|
+
const _guard1 = (operator_ === "-");
|
|
1680
|
+
if(_guard1) {
|
|
1681
|
+
const t1_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_);
|
|
1682
|
+
const e1_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t1_, a1_.value_);
|
|
1683
|
+
do {
|
|
1684
|
+
const _1 = ff_compiler_Unification.Unification_substitute(self_.unification_, t1_);
|
|
1685
|
+
{
|
|
1686
|
+
if(_1.TConstructor) {
|
|
1687
|
+
const name_ = _1.name_;
|
|
1688
|
+
if(_1.generics_.Empty) {
|
|
1689
|
+
const _guard1 = (name_ === ff_compiler_Inference.core_("Float"));
|
|
1690
|
+
if(_guard1) {
|
|
1691
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t1_)
|
|
1692
|
+
break
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
{
|
|
1698
|
+
if(_1.TConstructor) {
|
|
1699
|
+
const name_ = _1.name_;
|
|
1700
|
+
if(_1.generics_.Empty) {
|
|
1701
|
+
const _guard1 = (name_ === ff_compiler_Inference.core_("Int"));
|
|
1702
|
+
if(_guard1) {
|
|
1703
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t1_)
|
|
1704
|
+
break
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
{
|
|
1710
|
+
const _guard1 = ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_);
|
|
1711
|
+
if(_guard1) {
|
|
1712
|
+
|
|
1713
|
+
break
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
{
|
|
1717
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, "Operators on unknown types not currently supported"), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1718
|
+
break
|
|
1719
|
+
}
|
|
1720
|
+
} while(false);
|
|
1721
|
+
{
|
|
1722
|
+
const _1 = e_;
|
|
1723
|
+
{
|
|
1724
|
+
const _c = _1;
|
|
1725
|
+
return ff_compiler_Syntax.ECall(_c.at_, target_, _c.effect_, _c.typeArguments_, ff_core_List.Link((((_c) => {
|
|
1726
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, e1_)
|
|
1727
|
+
}))(a1_), ff_core_List.Empty()), _c.dictionaries_)
|
|
1728
|
+
return
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
return
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
{
|
|
1737
|
+
if(_1.Link) {
|
|
1738
|
+
const a1_ = _1.head_;
|
|
1739
|
+
if(_1.tail_.Link) {
|
|
1740
|
+
const a2_ = _1.tail_.head_;
|
|
1741
|
+
if(_1.tail_.tail_.Empty) {
|
|
1742
|
+
const _guard1 = ((operator_ === "||") || (operator_ === "&&"));
|
|
1743
|
+
if(_guard1) {
|
|
1744
|
+
const t_ = ff_compiler_Syntax.TConstructor(e_.at_, ff_compiler_Inference.core_("Bool"), ff_core_List.Empty());
|
|
1745
|
+
const e1_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t_, a1_.value_);
|
|
1746
|
+
const e2_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t_, a2_.value_);
|
|
1747
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t_);
|
|
1748
|
+
{
|
|
1749
|
+
const _1 = e_;
|
|
1750
|
+
{
|
|
1751
|
+
const _c = _1;
|
|
1752
|
+
return ff_compiler_Syntax.ECall(_c.at_, target_, _c.effect_, _c.typeArguments_, ff_core_List.Link((((_c) => {
|
|
1753
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, e1_)
|
|
1754
|
+
}))(a1_), ff_core_List.Link((((_c) => {
|
|
1755
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, e2_)
|
|
1756
|
+
}))(a2_), ff_core_List.Empty())), _c.dictionaries_)
|
|
1757
|
+
return
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
return
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
{
|
|
1767
|
+
if(_1.Link) {
|
|
1768
|
+
const a1_ = _1.head_;
|
|
1769
|
+
if(_1.tail_.Link) {
|
|
1770
|
+
const a2_ = _1.tail_.head_;
|
|
1771
|
+
if(_1.tail_.tail_.Empty) {
|
|
1772
|
+
const _guard1 = ((operator_ === "===") || (operator_ === "!=="));
|
|
1773
|
+
if(_guard1) {
|
|
1774
|
+
const t1_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_);
|
|
1775
|
+
const e1_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t1_, a1_.value_);
|
|
1776
|
+
const e2_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t1_, a2_.value_);
|
|
1777
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, ff_compiler_Syntax.TConstructor(e_.at_, ff_compiler_Inference.core_("Bool"), ff_core_List.Empty()));
|
|
1778
|
+
{
|
|
1779
|
+
const _1 = e_;
|
|
1780
|
+
{
|
|
1781
|
+
const _c = _1;
|
|
1782
|
+
return ff_compiler_Syntax.ECall(_c.at_, target_, _c.effect_, _c.typeArguments_, ff_core_List.Link((((_c) => {
|
|
1783
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, e1_)
|
|
1784
|
+
}))(a1_), ff_core_List.Link((((_c) => {
|
|
1785
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, e2_)
|
|
1786
|
+
}))(a2_), ff_core_List.Empty())), _c.dictionaries_)
|
|
1787
|
+
return
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
return
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
{
|
|
1797
|
+
if(_1.Link) {
|
|
1798
|
+
const a1_ = _1.head_;
|
|
1799
|
+
if(_1.tail_.Link) {
|
|
1800
|
+
const a2_ = _1.tail_.head_;
|
|
1801
|
+
if(_1.tail_.tail_.Empty) {
|
|
1802
|
+
const _guard1 = ((((((operator_ === "+") || (operator_ === "-")) || (operator_ === "*")) || (operator_ === "/")) || (operator_ === "%")) || (operator_ === "^"));
|
|
1803
|
+
if(_guard1) {
|
|
1804
|
+
const t1_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_);
|
|
1805
|
+
const t2_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_);
|
|
1806
|
+
const e1_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t1_, a1_.value_);
|
|
1807
|
+
const e2_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t2_, a2_.value_);
|
|
1808
|
+
const magic_ = ((t_) => {
|
|
1809
|
+
{
|
|
1810
|
+
const _1 = ff_compiler_Unification.Unification_substitute(self_.unification_, t_);
|
|
1811
|
+
{
|
|
1812
|
+
if(_1.TConstructor) {
|
|
1813
|
+
const name_ = _1.name_;
|
|
1814
|
+
if(_1.generics_.Empty) {
|
|
1815
|
+
const _guard1 = (name_ === ff_compiler_Inference.core_("Float"));
|
|
1816
|
+
if(_guard1) {
|
|
1817
|
+
return ff_core_Option.Some("Float")
|
|
1818
|
+
return
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
{
|
|
1824
|
+
if(_1.TConstructor) {
|
|
1825
|
+
const name_ = _1.name_;
|
|
1826
|
+
if(_1.generics_.Empty) {
|
|
1827
|
+
const _guard1 = (name_ === ff_compiler_Inference.core_("Int"));
|
|
1828
|
+
if(_guard1) {
|
|
1829
|
+
return ff_core_Option.Some("Int")
|
|
1830
|
+
return
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
{
|
|
1836
|
+
if(_1.TConstructor) {
|
|
1837
|
+
const name_ = _1.name_;
|
|
1838
|
+
if(_1.generics_.Empty) {
|
|
1839
|
+
const _guard1 = ((operator_ === "+") && (name_ === ff_compiler_Inference.core_("String")));
|
|
1840
|
+
if(_guard1) {
|
|
1841
|
+
return ff_core_Option.Some("String")
|
|
1842
|
+
return
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
{
|
|
1848
|
+
return ff_core_Option.None()
|
|
1849
|
+
return
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
});
|
|
1853
|
+
const chooseType_ = ((_1, _2) => {
|
|
1854
|
+
{
|
|
1855
|
+
if(_1.Some) {
|
|
1856
|
+
if(_1.value_ == "String") {
|
|
1857
|
+
if(_2.Some) {
|
|
1858
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t1_)
|
|
1859
|
+
return
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
{
|
|
1865
|
+
if(_1.Some) {
|
|
1866
|
+
if(_2.Some) {
|
|
1867
|
+
if(_2.value_ == "String") {
|
|
1868
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t2_)
|
|
1869
|
+
return
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
{
|
|
1875
|
+
if(_1.Some) {
|
|
1876
|
+
if(_1.value_ == "Float") {
|
|
1877
|
+
if(_2.Some) {
|
|
1878
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t1_)
|
|
1879
|
+
return
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
{
|
|
1885
|
+
if(_1.Some) {
|
|
1886
|
+
if(_2.Some) {
|
|
1887
|
+
if(_2.value_ == "Float") {
|
|
1888
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t2_)
|
|
1889
|
+
return
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
{
|
|
1895
|
+
if(_1.Some) {
|
|
1896
|
+
if(_1.value_ == "Int") {
|
|
1897
|
+
if(_2.Some) {
|
|
1898
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t1_)
|
|
1899
|
+
return
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
{
|
|
1905
|
+
if(_1.Some) {
|
|
1906
|
+
if(_2.Some) {
|
|
1907
|
+
if(_2.value_ == "Int") {
|
|
1908
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t2_)
|
|
1909
|
+
return
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
{
|
|
1915
|
+
if(_1.Some) {
|
|
1916
|
+
if(_2.None) {
|
|
1917
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, t1_, t2_);
|
|
1918
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t1_)
|
|
1919
|
+
return
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
{
|
|
1924
|
+
if(_1.None) {
|
|
1925
|
+
if(_2.Some) {
|
|
1926
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, t2_, t1_);
|
|
1927
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t2_)
|
|
1928
|
+
return
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
{
|
|
1933
|
+
const _guard1 = ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_);
|
|
1934
|
+
if(_guard1) {
|
|
1935
|
+
|
|
1936
|
+
return
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
{
|
|
1940
|
+
if(_1.Some) {
|
|
1941
|
+
if(_2.Some) {
|
|
1942
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, "Operators on these types not currently supported"), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1943
|
+
return
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
{
|
|
1948
|
+
if(_1.None) {
|
|
1949
|
+
if(_2.None) {
|
|
1950
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, "Operators on unknown types not currently supported"), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1951
|
+
return
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
});
|
|
1956
|
+
chooseType_(magic_(t1_), magic_(t2_));
|
|
1957
|
+
{
|
|
1958
|
+
const _1 = e_;
|
|
1959
|
+
{
|
|
1960
|
+
const _c = _1;
|
|
1961
|
+
return ff_compiler_Syntax.ECall(_c.at_, target_, _c.effect_, _c.typeArguments_, ff_core_List.Link((((_c) => {
|
|
1962
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, e1_)
|
|
1963
|
+
}))(a1_), ff_core_List.Link((((_c) => {
|
|
1964
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, e2_)
|
|
1965
|
+
}))(a2_), ff_core_List.Empty())), _c.dictionaries_)
|
|
1966
|
+
return
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
return
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
{
|
|
1976
|
+
const _guard1 = ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_);
|
|
1977
|
+
if(_guard1) {
|
|
1978
|
+
return term_
|
|
1979
|
+
return
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
{
|
|
1983
|
+
return ff_compiler_Inference.fail_(e_.at_, ("Unknown operator: " + operator_))
|
|
1984
|
+
return
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
export function Inference_inferEtaExpansion(self_, environment_, expected_, at_, signature_, term_) {
|
|
1990
|
+
const parameters_ = ff_core_List.List_map(ff_core_List.List_filter(signature_.parameters_, ((_w1) => {
|
|
1991
|
+
return ff_core_Option.Option_isEmpty(_w1.default_)
|
|
1992
|
+
})), ((p_) => {
|
|
1993
|
+
return p_.name_
|
|
1994
|
+
}));
|
|
1995
|
+
const effect1_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, at_);
|
|
1996
|
+
const body_ = ff_compiler_Syntax.ECall(at_, ff_compiler_Syntax.DynamicCall(term_, false), effect1_, ff_core_List.Empty(), ff_core_List.List_map(parameters_, ((x_) => {
|
|
1997
|
+
return ff_compiler_Syntax.Argument(at_, ff_core_Option.Some(x_), ff_compiler_Syntax.EVariable(at_, x_))
|
|
1998
|
+
})), ff_core_List.Empty());
|
|
1999
|
+
const effect2_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, at_);
|
|
2000
|
+
const lambda_ = ff_compiler_Syntax.ELambda(at_, ff_compiler_Syntax.Lambda(at_, effect2_, ff_core_List.Link(ff_compiler_Syntax.MatchCase(at_, ff_core_List.List_map(parameters_, ((_w1) => {
|
|
2001
|
+
return ff_compiler_Syntax.PVariable(at_, ff_core_Option.Some(_w1))
|
|
2002
|
+
})), ff_core_List.Empty(), body_), ff_core_List.Empty())));
|
|
2003
|
+
return ff_compiler_Inference.Inference_inferTerm(self_, (((_c) => {
|
|
2004
|
+
return ff_compiler_Environment.Environment(_c.modulePrefix_, _c.symbols_, _c.traits_, _c.imports_, effect2_, _c.selfVariable_)
|
|
2005
|
+
}))(environment_), expected_, lambda_)
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
export function Inference_inferArguments(self_, callAt_, callName_, environment_, parameters_, arguments_) {
|
|
2009
|
+
if(ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_)) {
|
|
2010
|
+
ff_core_List.List_each(ff_core_List.List_pairs(arguments_), ((_1) => {
|
|
2011
|
+
{
|
|
2012
|
+
const i_ = _1.first_;
|
|
2013
|
+
const a_ = _1.second_;
|
|
2014
|
+
const p_ = ff_core_List.List_find(parameters_, ((p_) => {
|
|
2015
|
+
return ff_core_Option.Option_any(a_.name_, ((_w1) => {
|
|
2016
|
+
return (_w1 === p_.name_)
|
|
2017
|
+
}))
|
|
2018
|
+
}));
|
|
2019
|
+
if((ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, a_.at_) || ff_core_Option.Option_any(p_, ((_w1) => {
|
|
2020
|
+
return ff_compiler_LspHook.LspHook_isDefinedAt(self_.lspHook_, _w1.at_)
|
|
2021
|
+
})))) {
|
|
2022
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferArgumentHook(self_.unification_, environment_, false, callAt_, callName_, parameters_, arguments_, i_))
|
|
2023
|
+
}
|
|
2024
|
+
return
|
|
2025
|
+
}
|
|
2026
|
+
}))
|
|
2027
|
+
};
|
|
2028
|
+
let remainingArguments_ = arguments_;
|
|
2029
|
+
const newArguments_ = ff_core_List.List_map(parameters_, ((p_) => {
|
|
2030
|
+
const t_ = p_.valueType_;
|
|
2031
|
+
function defaultArgument_() {
|
|
2032
|
+
return ff_core_Option.Option_else(ff_core_Option.Option_map(p_.default_, ((e_) => {
|
|
2033
|
+
const e2_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t_, e_);
|
|
2034
|
+
return ff_compiler_Syntax.Argument(callAt_, ff_core_Option.Some(p_.name_), e2_)
|
|
2035
|
+
})), (() => {
|
|
2036
|
+
if((!ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_))) {
|
|
2037
|
+
return ff_compiler_Inference.fail_(callAt_, ("Missing argument: " + p_.name_))
|
|
2038
|
+
} else {
|
|
2039
|
+
return ff_compiler_Syntax.Argument(callAt_, ff_core_Option.Some(p_.name_), ff_compiler_Syntax.EVariable(callAt_, ""))
|
|
2040
|
+
}
|
|
2041
|
+
}))
|
|
2042
|
+
}
|
|
2043
|
+
{
|
|
2044
|
+
const _1 = remainingArguments_;
|
|
2045
|
+
{
|
|
2046
|
+
if(_1.Empty) {
|
|
2047
|
+
return defaultArgument_()
|
|
2048
|
+
return
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
{
|
|
2052
|
+
if(_1.Link) {
|
|
2053
|
+
const at_ = _1.head_.at_;
|
|
2054
|
+
if(_1.head_.name_.None) {
|
|
2055
|
+
const e_ = _1.head_.value_;
|
|
2056
|
+
const remaining_ = _1.tail_;
|
|
2057
|
+
remainingArguments_ = remaining_;
|
|
2058
|
+
const e2_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t_, e_);
|
|
2059
|
+
return ff_compiler_Syntax.Argument(at_, ff_core_Option.Some(p_.name_), e2_)
|
|
2060
|
+
return
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
{
|
|
2065
|
+
return ff_core_Option.Option_else(ff_core_Option.Option_map(ff_core_List.List_find(remainingArguments_, ((_w1) => {
|
|
2066
|
+
return ff_core_Option.Option_contains(_w1.name_, p_.name_, ff_core_Equal.ff_core_Equal_Equal$ff_core_String_String)
|
|
2067
|
+
})), ((_1) => {
|
|
2068
|
+
{
|
|
2069
|
+
const at_ = _1.at_;
|
|
2070
|
+
const e_ = _1.value_;
|
|
2071
|
+
remainingArguments_ = ff_core_List.List_filter(remainingArguments_, ((_w1) => {
|
|
2072
|
+
return (!ff_core_Option.Option_contains(_w1.name_, p_.name_, ff_core_Equal.ff_core_Equal_Equal$ff_core_String_String))
|
|
2073
|
+
}));
|
|
2074
|
+
const e2_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t_, e_);
|
|
2075
|
+
return ff_compiler_Syntax.Argument(at_, ff_core_Option.Some(p_.name_), e2_)
|
|
2076
|
+
return
|
|
2077
|
+
}
|
|
2078
|
+
})), (() => {
|
|
2079
|
+
return defaultArgument_()
|
|
2080
|
+
}))
|
|
2081
|
+
return
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
}));
|
|
2085
|
+
if((!ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_))) {
|
|
2086
|
+
ff_core_Option.Option_each(ff_core_List.List_first(remainingArguments_), ((_1) => {
|
|
2087
|
+
{
|
|
2088
|
+
const callAt_ = _1.at_;
|
|
2089
|
+
if(_1.name_.None) {
|
|
2090
|
+
ff_compiler_Inference.fail_(callAt_, "Too many arguments")
|
|
2091
|
+
return
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
{
|
|
2095
|
+
const callAt_ = _1.at_;
|
|
2096
|
+
if(_1.name_.Some) {
|
|
2097
|
+
const n_ = _1.name_.value_;
|
|
2098
|
+
ff_compiler_Inference.fail_(callAt_, ("Unknown argument: " + n_))
|
|
2099
|
+
return
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
}));
|
|
2103
|
+
return newArguments_
|
|
2104
|
+
} else {
|
|
2105
|
+
return ff_core_List.List_addAll(newArguments_, ff_core_List.List_map(remainingArguments_, ((a_) => {
|
|
2106
|
+
{
|
|
2107
|
+
const _1 = a_;
|
|
2108
|
+
{
|
|
2109
|
+
const _c = _1;
|
|
2110
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, ff_compiler_Inference.Inference_inferTerm(self_, environment_, ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, a_.at_), a_.value_))
|
|
2111
|
+
return
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
})))
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
|
|
2118
|
+
export function Inference_lookup(self_, environment_, expected_, at_, symbol_, typeArguments_, arguments_) {
|
|
2119
|
+
return ff_core_Option.Option_elseIf(ff_compiler_Inference.Inference_lookupOption(self_, environment_, expected_, at_, symbol_, typeArguments_), (() => {
|
|
2120
|
+
return ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_)
|
|
2121
|
+
}), (() => {
|
|
2122
|
+
const instantiated_ = ff_compiler_Environment.Instantiated(ff_core_List.Empty(), ff_compiler_Environment.Scheme(ff_core_Option.Option_isEmpty(arguments_), false, false, false, ff_compiler_Syntax.Signature(at_, symbol_, false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.List_map(ff_core_List.List_pairs(ff_core_List.List_flatten(ff_core_Option.Option_toList(arguments_))), ((_1) => {
|
|
2123
|
+
{
|
|
2124
|
+
const i_ = _1.first_;
|
|
2125
|
+
const a_ = _1.second_;
|
|
2126
|
+
const t_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, at_);
|
|
2127
|
+
return ff_compiler_Syntax.Parameter(a_.at_, false, ff_core_Option.Option_else(a_.name_, (() => {
|
|
2128
|
+
return ("_p" + i_)
|
|
2129
|
+
})), t_, ff_core_Option.None())
|
|
2130
|
+
return
|
|
2131
|
+
}
|
|
2132
|
+
})), ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, at_), ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, at_))));
|
|
2133
|
+
if(((!ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, at_)) && (!ff_core_StringMap.StringMap_has(self_.missing_, symbol_)))) {
|
|
2134
|
+
ff_core_StringMap.StringMap_set(self_.missing_, symbol_, ff_core_Pair.Pair(instantiated_, arguments_))
|
|
2135
|
+
};
|
|
2136
|
+
return instantiated_
|
|
2137
|
+
}))
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
export function Inference_lookupOption(self_, environment_, expected_, at_, symbol_, typeArguments_) {
|
|
2141
|
+
const hook_ = (ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, at_)
|
|
2142
|
+
? ff_core_Option.Some((function() {
|
|
2143
|
+
const symbolHook_ = ff_compiler_LspHook.SymbolHook(symbol_, at_, at_);
|
|
2144
|
+
const selfName_ = environment_.selfVariable_;
|
|
2145
|
+
const h_ = ff_compiler_LspHook.InferLookupHook(self_.unification_, environment_, expected_, selfName_, ff_compiler_LspHook.Box(symbolHook_), ff_compiler_LspHook.Box(ff_core_Option.None()));
|
|
2146
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, h_);
|
|
2147
|
+
return h_
|
|
2148
|
+
})())
|
|
2149
|
+
: ff_core_Option.None());
|
|
2150
|
+
return ff_core_Option.Option_map(ff_core_Map.Map_get(environment_.symbols_, symbol_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String), ((scheme_) => {
|
|
2151
|
+
const instantiation_ = ((!ff_core_List.List_isEmpty(typeArguments_))
|
|
2152
|
+
? (function() {
|
|
2153
|
+
const newTypeArguments_ = (((!scheme_.isVariable_) && ff_core_Option.Option_any(ff_core_List.List_first(scheme_.signature_.generics_), ((_w1) => {
|
|
2154
|
+
return (_w1 === "Q$")
|
|
2155
|
+
})))
|
|
2156
|
+
? ff_core_List.Link(ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, at_), typeArguments_)
|
|
2157
|
+
: typeArguments_);
|
|
2158
|
+
if(((ff_core_List.List_size(scheme_.signature_.generics_) !== ff_core_List.List_size(newTypeArguments_)) && (!ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_)))) {
|
|
2159
|
+
const extra_ = (ff_core_List.List_size(newTypeArguments_) - ff_core_List.List_size(typeArguments_));
|
|
2160
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(at_, ((((("Wrong number of type arguments for " + symbol_) + ", expected ") + (ff_core_List.List_size(scheme_.signature_.generics_) - extra_)) + ", got ") + (ff_core_List.List_size(newTypeArguments_) - extra_))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
2161
|
+
};
|
|
2162
|
+
return ff_core_List.List_zip(scheme_.signature_.generics_, newTypeArguments_)
|
|
2163
|
+
})()
|
|
2164
|
+
: ff_core_List.List_map(scheme_.signature_.generics_, ((name_) => {
|
|
2165
|
+
return ff_core_Pair.Pair(name_, ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, at_))
|
|
2166
|
+
})));
|
|
2167
|
+
const instantiationMap_ = ff_core_List.List_toMap(instantiation_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
2168
|
+
const parameters_ = ff_core_List.List_map(scheme_.signature_.parameters_, ((p_) => {
|
|
2169
|
+
{
|
|
2170
|
+
const _1 = p_;
|
|
2171
|
+
{
|
|
2172
|
+
const _c = _1;
|
|
2173
|
+
return ff_compiler_Syntax.Parameter(_c.at_, _c.mutable_, _c.name_, ff_compiler_Unification.Unification_instantiate(self_.unification_, instantiationMap_, p_.valueType_), _c.default_)
|
|
2174
|
+
return
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
}));
|
|
2178
|
+
const returnType_ = ff_compiler_Unification.Unification_instantiate(self_.unification_, instantiationMap_, scheme_.signature_.returnType_);
|
|
2179
|
+
const effect_ = ff_compiler_Unification.Unification_instantiate(self_.unification_, instantiationMap_, scheme_.signature_.effect_);
|
|
2180
|
+
ff_core_List.List_each(scheme_.signature_.constraints_, ((c_) => {
|
|
2181
|
+
const generics_ = ff_core_List.List_map(c_.generics_, ((_w1) => {
|
|
2182
|
+
return ff_compiler_Unification.Unification_instantiate(self_.unification_, instantiationMap_, _w1)
|
|
2183
|
+
}));
|
|
2184
|
+
ff_compiler_Unification.Unification_constrain(self_.unification_, at_, ff_core_List.List_grabFirst(generics_), c_.name_, ff_core_List.List_dropFirst(generics_, 1))
|
|
2185
|
+
}));
|
|
2186
|
+
const signature_ = (((_c) => {
|
|
2187
|
+
return ff_compiler_Syntax.Signature(_c.at_, _c.name_, _c.member_, ff_core_List.Empty(), ff_core_List.Empty(), parameters_, returnType_, effect_)
|
|
2188
|
+
}))(scheme_.signature_);
|
|
2189
|
+
const instantiated_ = ff_compiler_Environment.Instantiated(instantiation_, (((_c) => {
|
|
2190
|
+
return ff_compiler_Environment.Scheme(_c.isVariable_, _c.isMutable_, _c.isNewtype_, _c.isTraitMethod_, signature_)
|
|
2191
|
+
}))(scheme_));
|
|
2192
|
+
if((ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, at_) || ff_compiler_LspHook.LspHook_isDefinedAt(self_.lspHook_, scheme_.signature_.at_))) {
|
|
2193
|
+
const symbolHook_ = ff_compiler_LspHook.SymbolHook(symbol_, at_, scheme_.signature_.at_);
|
|
2194
|
+
const emittedHook_ = (((_1) => {
|
|
2195
|
+
{
|
|
2196
|
+
if(_1.InferLookupHook) {
|
|
2197
|
+
const h_ = _1;
|
|
2198
|
+
h_.symbol_.value_ = symbolHook_;
|
|
2199
|
+
h_.instantiated_.value_ = ff_core_Option.Some(instantiated_)
|
|
2200
|
+
return
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
{
|
|
2204
|
+
|
|
2205
|
+
return
|
|
2206
|
+
}
|
|
2207
|
+
}))(ff_core_Option.Option_else(hook_, (() => {
|
|
2208
|
+
const selfName_ = environment_.selfVariable_;
|
|
2209
|
+
const h_ = ff_compiler_LspHook.InferLookupHook(self_.unification_, environment_, expected_, selfName_, ff_compiler_LspHook.Box(symbolHook_), ff_compiler_LspHook.Box(ff_core_Option.None()));
|
|
2210
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, h_);
|
|
2211
|
+
return h_
|
|
2212
|
+
})));
|
|
2213
|
+
|
|
2214
|
+
};
|
|
2215
|
+
return instantiated_
|
|
2216
|
+
}))
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
export async function Inference_inferModule$(self_, module_, otherModules_, $task) {
|
|
2220
|
+
const environment_ = ff_compiler_Environment.make_(module_, otherModules_, false);
|
|
2221
|
+
const traits_ = ff_core_List.List_map(module_.traits_, ((_w1) => {
|
|
2222
|
+
return ff_compiler_Inference.Inference_inferTraitDefinition(self_, environment_, _w1)
|
|
2223
|
+
}));
|
|
2224
|
+
const instances_ = ff_core_List.List_map(module_.instances_, ((_w1) => {
|
|
2225
|
+
return ff_compiler_Inference.Inference_inferInstanceDefinition(self_, environment_, _w1)
|
|
2226
|
+
}));
|
|
2227
|
+
const lets_ = ff_core_List.List_map(module_.lets_, ((_w1) => {
|
|
2228
|
+
return ff_compiler_Inference.Inference_inferLetDefinition(self_, environment_, _w1)
|
|
2229
|
+
}));
|
|
2230
|
+
const functions_ = ff_core_List.List_map(module_.functions_, ((_w1) => {
|
|
2231
|
+
return ff_compiler_Inference.Inference_inferFunctionDefinition(self_, environment_, _w1)
|
|
2232
|
+
}));
|
|
2233
|
+
const extends_ = ff_core_List.List_map(module_.extends_, ((_w1) => {
|
|
2234
|
+
return ff_compiler_Inference.Inference_inferExtendDefinition(self_, environment_, _w1)
|
|
2235
|
+
}));
|
|
2236
|
+
const result_ = (((_c) => {
|
|
2237
|
+
return ff_compiler_Syntax.Module(_c.file_, _c.packagePair_, _c.imports_, _c.types_, traits_, instances_, extends_, lets_, functions_)
|
|
2238
|
+
}))(module_);
|
|
2239
|
+
const subsititution_ = ff_compiler_Substitution.Substitution(self_.unification_.substitution_);
|
|
2240
|
+
return ff_compiler_Substitution.Substitution_substituteModule(subsititution_, result_)
|
|
2241
|
+
}
|
|
2242
|
+
|
|
2243
|
+
export async function Inference_inferTraitDefinition$(self_, environment_, definition_, $task) {
|
|
2244
|
+
{
|
|
2245
|
+
const _1 = definition_;
|
|
2246
|
+
{
|
|
2247
|
+
const _c = _1;
|
|
2248
|
+
return ff_compiler_Syntax.DTrait(_c.at_, _c.name_, _c.generics_, _c.constraints_, _c.generatorParameters_, _c.methods_, _c.methodDefaults_, _c.methodGenerators_)
|
|
2249
|
+
return
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
export async function Inference_inferInstanceDefinition$(self_, environment_, definition_, $task) {
|
|
2255
|
+
if((ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_) && definition_.derived_)) {
|
|
2256
|
+
return definition_
|
|
2257
|
+
} else {
|
|
2258
|
+
const instances_ = ff_compiler_Inference.constraintsToInstances_(definition_.constraints_);
|
|
2259
|
+
return ff_compiler_Unification.Unification_withLocalInstances(self_.unification_, instances_, (() => {
|
|
2260
|
+
const traitName_ = definition_.traitName_;
|
|
2261
|
+
const traitDefinition_ = ff_core_Option.Option_else(ff_core_Map.Map_get(environment_.traits_, traitName_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String), (() => {
|
|
2262
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(definition_.at_, ("No such trait: " + traitName_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
2263
|
+
}));
|
|
2264
|
+
if((ff_core_List.List_size(traitDefinition_.generics_) !== ff_core_List.List_size(definition_.typeArguments_))) {
|
|
2265
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(definition_.at_, ((((("Wrong number of type arguments for " + traitName_) + ", expected ") + (ff_core_List.List_size(traitDefinition_.generics_) - 1)) + ", got ") + (ff_core_List.List_size(definition_.typeArguments_) - 1))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
2266
|
+
};
|
|
2267
|
+
const instantiationMap_ = ff_core_List.List_toMap(ff_core_List.List_zip(traitDefinition_.generics_, definition_.typeArguments_), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
2268
|
+
ff_core_List.List_each(traitDefinition_.methods_, ((traitMethod_) => {
|
|
2269
|
+
const found_ = ff_core_List.List_filter(definition_.methods_, ((_w1) => {
|
|
2270
|
+
return (_w1.signature_.name_ === traitMethod_.name_)
|
|
2271
|
+
}));
|
|
2272
|
+
if(ff_core_List.List_isEmpty(found_)) {
|
|
2273
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(definition_.at_, ("Missing instance method: " + traitMethod_.name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
2274
|
+
};
|
|
2275
|
+
ff_core_List.List_each(ff_core_List.List_dropFirst(found_, 1), ((duplicateMethod_) => {
|
|
2276
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(duplicateMethod_.at_, ("Duplicated instance method: " + traitMethod_.name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
2277
|
+
}))
|
|
2278
|
+
}));
|
|
2279
|
+
{
|
|
2280
|
+
const _1 = definition_;
|
|
2281
|
+
{
|
|
2282
|
+
const _c = _1;
|
|
2283
|
+
return ff_compiler_Syntax.DInstance(_c.at_, _c.generics_, _c.constraints_, _c.traitName_, _c.typeArguments_, _c.generatorArguments_, ff_core_List.List_map(definition_.methods_, ((instanceFunction_) => {
|
|
2284
|
+
const methodName_ = instanceFunction_.signature_.name_;
|
|
2285
|
+
const traitMethodName_ = (ff_core_String.String_reverse(ff_core_String.String_dropWhile(ff_core_String.String_reverse(traitName_), ((_w1) => {
|
|
2286
|
+
return (_w1 !== 46)
|
|
2287
|
+
}))) + methodName_);
|
|
2288
|
+
const traitMethodScheme_ = ff_core_Option.Option_else(ff_core_Map.Map_get(environment_.symbols_, traitMethodName_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String), (() => {
|
|
2289
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(instanceFunction_.at_, ((("Trait " + traitName_) + " has no such method: ") + methodName_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
2290
|
+
}));
|
|
2291
|
+
const parameters_ = ff_core_List.List_map(traitMethodScheme_.signature_.parameters_, ((p_) => {
|
|
2292
|
+
{
|
|
2293
|
+
const _1 = p_;
|
|
2294
|
+
{
|
|
2295
|
+
const _c = _1;
|
|
2296
|
+
return ff_compiler_Syntax.Parameter(_c.at_, _c.mutable_, _c.name_, ff_compiler_Unification.Unification_instantiate(self_.unification_, instantiationMap_, p_.valueType_), _c.default_)
|
|
2297
|
+
return
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
}));
|
|
2301
|
+
const returnType_ = ff_compiler_Unification.Unification_instantiate(self_.unification_, instantiationMap_, traitMethodScheme_.signature_.returnType_);
|
|
2302
|
+
ff_core_List.List_each(ff_core_List.List_dropFirst(instanceFunction_.signature_.parameters_, ff_core_List.List_size(parameters_)), ((instanceParameter_) => {
|
|
2303
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(instanceParameter_.at_, ("Unexpected parameter: " + instanceParameter_.name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
2304
|
+
}));
|
|
2305
|
+
ff_core_List.List_each(ff_core_List.List_dropFirst(parameters_, ff_core_List.List_size(instanceFunction_.signature_.parameters_)), ((traitParameter_) => {
|
|
2306
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(instanceFunction_.at_, ("Missing parameter: " + traitParameter_.name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
2307
|
+
}));
|
|
2308
|
+
ff_core_List.List_each(ff_core_List.List_zip(parameters_, instanceFunction_.signature_.parameters_), ((_1) => {
|
|
2309
|
+
{
|
|
2310
|
+
const traitParameter_ = _1.first_;
|
|
2311
|
+
const instanceParameter_ = _1.second_;
|
|
2312
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, instanceParameter_.valueType_.at_, traitParameter_.valueType_, instanceParameter_.valueType_)
|
|
2313
|
+
return
|
|
2314
|
+
}
|
|
2315
|
+
}));
|
|
2316
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, instanceFunction_.signature_.returnType_.at_, returnType_, instanceFunction_.signature_.returnType_);
|
|
2317
|
+
if((ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, instanceFunction_.at_) || ff_compiler_LspHook.LspHook_isDefinedAt(self_.lspHook_, traitMethodScheme_.signature_.at_))) {
|
|
2318
|
+
const symbolHook_ = ff_compiler_LspHook.SymbolHook(instanceFunction_.signature_.name_, instanceFunction_.at_, traitMethodScheme_.signature_.at_);
|
|
2319
|
+
const h_ = ff_compiler_LspHook.InferLookupHook(self_.unification_, environment_, instanceFunction_.signature_.returnType_, ff_core_Option.None(), ff_compiler_LspHook.Box(symbolHook_), ff_compiler_LspHook.Box(ff_core_Option.None()));
|
|
2320
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, h_)
|
|
2321
|
+
};
|
|
2322
|
+
return ff_compiler_Inference.Inference_inferFunctionDefinition(self_, environment_, instanceFunction_)
|
|
2323
|
+
})), _c.derived_)
|
|
2324
|
+
return
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
}))
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2331
|
+
export async function Inference_inferLetDefinition$(self_, environment_, definition_, $task) {
|
|
2332
|
+
const value_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, definition_.variableType_, definition_.value_);
|
|
2333
|
+
{
|
|
2334
|
+
const _1 = definition_;
|
|
2335
|
+
{
|
|
2336
|
+
const _c = _1;
|
|
2337
|
+
return ff_compiler_Syntax.DLet(_c.at_, _c.name_, _c.variableType_, value_)
|
|
2338
|
+
return
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
|
|
2343
|
+
export async function Inference_inferExtendDefinition$(self_, environment_, definition_, $task) {
|
|
2344
|
+
const selfParameter_ = ff_compiler_Syntax.Parameter(definition_.at_, false, definition_.name_, definition_.type_, ff_core_Option.None());
|
|
2345
|
+
const functions_ = ff_core_List.List_map(definition_.methods_, ((method_) => {
|
|
2346
|
+
const signature_ = (((_c) => {
|
|
2347
|
+
return ff_compiler_Syntax.Signature(_c.at_, _c.name_, _c.member_, ff_core_List.List_addAll(definition_.generics_, method_.signature_.generics_), ff_core_List.List_addAll(definition_.constraints_, method_.signature_.constraints_), ff_core_List.Link(selfParameter_, method_.signature_.parameters_), _c.returnType_, _c.effect_)
|
|
2348
|
+
}))(method_.signature_);
|
|
2349
|
+
const body_ = ff_compiler_Syntax.Target_mapFirefly(method_.body_, ((lambda_) => {
|
|
2350
|
+
{
|
|
2351
|
+
const _1 = lambda_;
|
|
2352
|
+
{
|
|
2353
|
+
const _c = _1;
|
|
2354
|
+
return ff_compiler_Syntax.Lambda(_c.at_, _c.effect_, ff_core_List.List_map(lambda_.cases_, ((case_) => {
|
|
2355
|
+
{
|
|
2356
|
+
const _1 = case_;
|
|
2357
|
+
{
|
|
2358
|
+
const _c = _1;
|
|
2359
|
+
return ff_compiler_Syntax.MatchCase(_c.at_, ff_core_List.Link(ff_compiler_Syntax.PVariable(method_.at_, ff_core_Option.None()), case_.patterns_), _c.guards_, _c.body_)
|
|
2360
|
+
return
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
})))
|
|
2364
|
+
return
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
}));
|
|
2368
|
+
const function_ = (((_c) => {
|
|
2369
|
+
return ff_compiler_Syntax.DFunction(_c.at_, signature_, body_)
|
|
2370
|
+
}))(method_);
|
|
2371
|
+
return ff_compiler_Inference.Inference_inferFunctionDefinition(self_, (((_c) => {
|
|
2372
|
+
return ff_compiler_Environment.Environment(_c.modulePrefix_, _c.symbols_, _c.traits_, _c.imports_, _c.effect_, ff_core_Option.Some(definition_.name_))
|
|
2373
|
+
}))(environment_), function_)
|
|
2374
|
+
}));
|
|
2375
|
+
{
|
|
2376
|
+
const _1 = definition_;
|
|
2377
|
+
{
|
|
2378
|
+
const _c = _1;
|
|
2379
|
+
return ff_compiler_Syntax.DExtend(_c.at_, _c.name_, _c.generics_, _c.constraints_, _c.type_, functions_)
|
|
2380
|
+
return
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2384
|
+
|
|
2385
|
+
export async function Inference_inferFunctionDefinition$(self_, environment_, definition_, $task) {
|
|
2386
|
+
if(ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, definition_.at_)) {
|
|
2387
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferFunctionDefinitionHook(self_.unification_, environment_, definition_, self_.missing_))
|
|
2388
|
+
};
|
|
2389
|
+
const parameters_ = ff_core_List.List_map(definition_.signature_.parameters_, ((p_) => {
|
|
2390
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(p_.at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
2391
|
+
const scheme_ = ff_compiler_Environment.Scheme(true, false, false, false, ff_compiler_Syntax.Signature(p_.at_, p_.name_, false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Empty(), p_.valueType_, noEffect_));
|
|
2392
|
+
if(ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, p_.at_)) {
|
|
2393
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferParameterHook(self_.unification_, environment_, p_, self_.missing_))
|
|
2394
|
+
};
|
|
2395
|
+
return ff_core_Pair.Pair(p_.name_, scheme_)
|
|
2396
|
+
}));
|
|
2397
|
+
const parameterMap_ = ff_core_List.List_toMap(parameters_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
2398
|
+
const environment2_ = (((_c) => {
|
|
2399
|
+
return ff_compiler_Environment.Environment(_c.modulePrefix_, ff_core_Map.Map_addAll(environment_.symbols_, parameterMap_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String), _c.traits_, _c.imports_, _c.effect_, _c.selfVariable_)
|
|
2400
|
+
}))(environment_);
|
|
2401
|
+
const parameterTypes_ = ff_core_List.List_map(parameters_, ((_w1) => {
|
|
2402
|
+
return _w1.second_.signature_.returnType_
|
|
2403
|
+
}));
|
|
2404
|
+
const functionType_ = ff_compiler_Syntax.TConstructor(definition_.at_, ("Function$" + ff_core_List.List_size(parameterTypes_)), ff_core_List.Link(definition_.signature_.effect_, ff_core_List.List_addAll(parameterTypes_, ff_core_List.Link(definition_.signature_.returnType_, ff_core_List.Empty()))));
|
|
2405
|
+
const instances_ = ff_compiler_Inference.constraintsToInstances_(definition_.signature_.constraints_);
|
|
2406
|
+
return ff_compiler_Unification.Unification_withLocalInstances(self_.unification_, instances_, (() => {
|
|
2407
|
+
{
|
|
2408
|
+
const _1 = definition_;
|
|
2409
|
+
{
|
|
2410
|
+
const _c = _1;
|
|
2411
|
+
return ff_compiler_Syntax.DFunction(_c.at_, _c.signature_, ff_compiler_Syntax.Target_mapFirefly(definition_.body_, ((_w1) => {
|
|
2412
|
+
return ff_compiler_Inference.Inference_inferLambda(self_, environment2_, functionType_, _w1)
|
|
2413
|
+
})))
|
|
2414
|
+
return
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
}))
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
export async function Inference_inferLambda$(self_, environment_, expected_, lambda_, $task) {
|
|
2421
|
+
const unitName_ = ff_compiler_Inference.core_("Unit");
|
|
2422
|
+
const returnsUnit_ = (((_1) => {
|
|
2423
|
+
{
|
|
2424
|
+
if(_1.TConstructor) {
|
|
2425
|
+
const name_ = _1.name_;
|
|
2426
|
+
const ts_ = _1.generics_;
|
|
2427
|
+
const _guard1 = ff_core_String.String_startsWith(name_, "Function$", 0);
|
|
2428
|
+
if(_guard1) {
|
|
2429
|
+
{
|
|
2430
|
+
const _1 = ff_core_List.List_grabLast(ts_);
|
|
2431
|
+
{
|
|
2432
|
+
if(_1.TConstructor) {
|
|
2433
|
+
const n_ = _1.name_;
|
|
2434
|
+
if(_1.generics_.Empty) {
|
|
2435
|
+
return (n_ === unitName_)
|
|
2436
|
+
return
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
{
|
|
2441
|
+
return false
|
|
2442
|
+
return
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
return
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
{
|
|
2450
|
+
return false
|
|
2451
|
+
return
|
|
2452
|
+
}
|
|
2453
|
+
}))(ff_compiler_Unification.Unification_substitute(self_.unification_, expected_));
|
|
2454
|
+
const cases_ = ((!returnsUnit_)
|
|
2455
|
+
? lambda_.cases_
|
|
2456
|
+
: ff_core_List.List_map(lambda_.cases_, ((c_) => {
|
|
2457
|
+
{
|
|
2458
|
+
const _1 = c_;
|
|
2459
|
+
{
|
|
2460
|
+
const _c = _1;
|
|
2461
|
+
return ff_compiler_Syntax.MatchCase(_c.at_, _c.patterns_, _c.guards_, ff_compiler_Syntax.ESequential(c_.at_, c_.body_, ff_compiler_Syntax.EVariant(c_.at_, unitName_, ff_core_List.Empty(), ff_core_Option.None())))
|
|
2462
|
+
return
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
})));
|
|
2466
|
+
const newEnvironment_ = (((_c) => {
|
|
2467
|
+
return ff_compiler_Environment.Environment(_c.modulePrefix_, _c.symbols_, _c.traits_, _c.imports_, lambda_.effect_, _c.selfVariable_)
|
|
2468
|
+
}))(environment_);
|
|
2469
|
+
{
|
|
2470
|
+
const _1 = lambda_;
|
|
2471
|
+
{
|
|
2472
|
+
const _c = _1;
|
|
2473
|
+
return ff_compiler_Syntax.Lambda(_c.at_, _c.effect_, ff_core_List.List_map(cases_, ((_w1) => {
|
|
2474
|
+
return ff_compiler_Inference.Inference_inferMatchCase(self_, newEnvironment_, expected_, _w1)
|
|
2475
|
+
})))
|
|
2476
|
+
return
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
|
|
2481
|
+
export async function Inference_inferMatchCase$(self_, environment_, expected_, case_, $task) {
|
|
2482
|
+
const parameterTypes_ = ff_core_List.List_map(case_.patterns_, ((_w1) => {
|
|
2483
|
+
return ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, _w1.at_)
|
|
2484
|
+
}));
|
|
2485
|
+
const returnType_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, case_.at_);
|
|
2486
|
+
const functionType_ = ff_compiler_Syntax.TConstructor(case_.at_, ("Function$" + ff_core_List.List_size(case_.patterns_)), ff_core_List.Link(environment_.effect_, ff_core_List.List_addAll(parameterTypes_, ff_core_List.Link(returnType_, ff_core_List.Empty()))));
|
|
2487
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, case_.at_, expected_, functionType_);
|
|
2488
|
+
const environment1_ = ff_core_List.List_foldLeft(ff_core_List.List_zip(parameterTypes_, case_.patterns_), environment_, ((_1, _2) => {
|
|
2489
|
+
{
|
|
2490
|
+
const environment1_ = _1;
|
|
2491
|
+
const t_ = _2.first_;
|
|
2492
|
+
const c_ = _2.second_;
|
|
2493
|
+
const symbols_ = ff_core_Map.Map_mapValues(ff_compiler_Inference.Inference_inferPattern(self_, environment_, t_, c_), ((_1, _2) => {
|
|
2494
|
+
{
|
|
2495
|
+
const name_ = _1;
|
|
2496
|
+
const at_ = _2.first_;
|
|
2497
|
+
const type_ = _2.second_;
|
|
2498
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
2499
|
+
return ff_compiler_Environment.Scheme(true, false, false, false, ff_compiler_Syntax.Signature(at_, name_, false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Empty(), type_, noEffect_))
|
|
2500
|
+
return
|
|
2501
|
+
}
|
|
2502
|
+
}), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
2503
|
+
{
|
|
2504
|
+
const _1 = environment_;
|
|
2505
|
+
{
|
|
2506
|
+
const _c = _1;
|
|
2507
|
+
return ff_compiler_Environment.Environment(_c.modulePrefix_, ff_core_Map.Map_addAll(environment1_.symbols_, symbols_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String), _c.traits_, _c.imports_, _c.effect_, _c.selfVariable_)
|
|
2508
|
+
return
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
return
|
|
2512
|
+
}
|
|
2513
|
+
}));
|
|
2514
|
+
let guards_ = ff_core_List.Empty();
|
|
2515
|
+
const environment3_ = ff_core_List.List_foldLeft(case_.guards_, environment1_, ((environment2_, g_) => {
|
|
2516
|
+
const guardType_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, g_.at_);
|
|
2517
|
+
const guardTerm_ = ff_compiler_Inference.Inference_inferTerm(self_, environment2_, guardType_, g_.term_);
|
|
2518
|
+
const symbols_ = ff_core_Map.Map_mapValues(ff_compiler_Inference.Inference_inferPattern(self_, environment2_, guardType_, g_.pattern_), ((_1, _2) => {
|
|
2519
|
+
{
|
|
2520
|
+
const name_ = _1;
|
|
2521
|
+
const at_ = _2.first_;
|
|
2522
|
+
const type_ = _2.second_;
|
|
2523
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
2524
|
+
return ff_compiler_Environment.Scheme(true, false, false, false, ff_compiler_Syntax.Signature(at_, name_, false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Empty(), type_, noEffect_))
|
|
2525
|
+
return
|
|
2526
|
+
}
|
|
2527
|
+
}), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
2528
|
+
guards_ = ff_core_List.Link((((_c) => {
|
|
2529
|
+
return ff_compiler_Syntax.MatchGuard(_c.at_, guardTerm_, _c.pattern_)
|
|
2530
|
+
}))(g_), guards_);
|
|
2531
|
+
{
|
|
2532
|
+
const _1 = environment2_;
|
|
2533
|
+
{
|
|
2534
|
+
const _c = _1;
|
|
2535
|
+
return ff_compiler_Environment.Environment(_c.modulePrefix_, ff_core_Map.Map_addAll(environment2_.symbols_, symbols_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String), _c.traits_, _c.imports_, _c.effect_, _c.selfVariable_)
|
|
2536
|
+
return
|
|
2537
|
+
}
|
|
2538
|
+
}
|
|
2539
|
+
}));
|
|
2540
|
+
{
|
|
2541
|
+
const _1 = case_;
|
|
2542
|
+
{
|
|
2543
|
+
const _c = _1;
|
|
2544
|
+
return ff_compiler_Syntax.MatchCase(_c.at_, _c.patterns_, ff_core_List.List_reverse(guards_), ff_compiler_Inference.Inference_inferTerm(self_, environment3_, returnType_, case_.body_))
|
|
2545
|
+
return
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2550
|
+
export async function Inference_inferPattern$(self_, environment_, expected_, pattern_, $task) {
|
|
2551
|
+
if(ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_)) {
|
|
2552
|
+
if((((_1) => {
|
|
2553
|
+
{
|
|
2554
|
+
if(_1.PVariantAs) {
|
|
2555
|
+
const at_ = _1.at_;
|
|
2556
|
+
const variableAt_ = _1.variableAt_;
|
|
2557
|
+
return ((ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, at_) || ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, variableAt_)) || ff_compiler_LspHook.LspHook_isDefinedAt(self_.lspHook_, variableAt_))
|
|
2558
|
+
return
|
|
2559
|
+
}
|
|
2560
|
+
}
|
|
2561
|
+
{
|
|
2562
|
+
if(_1.PAlias) {
|
|
2563
|
+
const at_ = _1.at_;
|
|
2564
|
+
return (ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, at_) || ff_compiler_LspHook.LspHook_isDefinedAt(self_.lspHook_, at_))
|
|
2565
|
+
return
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2568
|
+
{
|
|
2569
|
+
return ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, pattern_.at_)
|
|
2570
|
+
return
|
|
2571
|
+
}
|
|
2572
|
+
}))(pattern_)) {
|
|
2573
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferPatternHook(self_.unification_, environment_, expected_, pattern_))
|
|
2574
|
+
}
|
|
2575
|
+
};
|
|
2576
|
+
function literal_(coreTypeName_) {
|
|
2577
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, pattern_.at_, expected_, ff_compiler_Syntax.TConstructor(pattern_.at_, ff_compiler_Inference.core_(coreTypeName_), ff_core_List.Empty()));
|
|
2578
|
+
return ff_core_Map.empty_()
|
|
2579
|
+
}
|
|
2580
|
+
{
|
|
2581
|
+
const _1 = pattern_;
|
|
2582
|
+
{
|
|
2583
|
+
if(_1.PString) {
|
|
2584
|
+
return literal_("String")
|
|
2585
|
+
return
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
{
|
|
2589
|
+
if(_1.PInt) {
|
|
2590
|
+
return literal_("Int")
|
|
2591
|
+
return
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
{
|
|
2595
|
+
if(_1.PChar) {
|
|
2596
|
+
return literal_("Char")
|
|
2597
|
+
return
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
{
|
|
2601
|
+
if(_1.PVariable) {
|
|
2602
|
+
const at_ = _1.at_;
|
|
2603
|
+
if(_1.name_.None) {
|
|
2604
|
+
return ff_core_Map.empty_()
|
|
2605
|
+
return
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2609
|
+
{
|
|
2610
|
+
if(_1.PVariable) {
|
|
2611
|
+
const at_ = _1.at_;
|
|
2612
|
+
if(_1.name_.Some) {
|
|
2613
|
+
const name_ = _1.name_.value_;
|
|
2614
|
+
return ff_core_List.List_toMap(ff_core_List.Link(ff_core_Pair.Pair(name_, ff_core_Pair.Pair(at_, expected_)), ff_core_List.Empty()), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String)
|
|
2615
|
+
return
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
{
|
|
2620
|
+
if(_1.PAlias) {
|
|
2621
|
+
const at_ = _1.at_;
|
|
2622
|
+
const pattern_ = _1.pattern_;
|
|
2623
|
+
const variable_ = _1.variable_;
|
|
2624
|
+
return ff_core_Map.Map_add(ff_compiler_Inference.Inference_inferPattern(self_, environment_, expected_, pattern_), variable_, ff_core_Pair.Pair(at_, expected_), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String)
|
|
2625
|
+
return
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
{
|
|
2629
|
+
if(_1.PVariantAs) {
|
|
2630
|
+
const at_ = _1.at_;
|
|
2631
|
+
const name_ = _1.name_;
|
|
2632
|
+
const variableAt_ = _1.variableAt_;
|
|
2633
|
+
const variableOption_ = _1.variable_;
|
|
2634
|
+
const instantiated_ = ff_core_Option.Option_else(ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, at_, name_, ff_core_List.Empty(), ff_core_Option.None()), (() => {
|
|
2635
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(at_, ("No such variant: " + name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
2636
|
+
}));
|
|
2637
|
+
if(instantiated_.scheme_.isNewtype_) {
|
|
2638
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(at_, "This kind of pattern is not allowed for newtypes"), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
2639
|
+
};
|
|
2640
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, at_, expected_, instantiated_.scheme_.signature_.returnType_);
|
|
2641
|
+
const parameters_ = ff_core_List.List_sortBy(instantiated_.scheme_.signature_.parameters_, ((_w1) => {
|
|
2642
|
+
return _w1.name_
|
|
2643
|
+
}), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
2644
|
+
const recordType_ = ff_compiler_Syntax.TConstructor(at_, ("Record$" + ff_core_List.List_join(ff_core_List.List_map(parameters_, ((_w1) => {
|
|
2645
|
+
return _w1.name_
|
|
2646
|
+
})), "$")), ff_core_List.List_map(parameters_, ((_w1) => {
|
|
2647
|
+
return _w1.valueType_
|
|
2648
|
+
})));
|
|
2649
|
+
return ff_core_List.List_toMap(ff_core_List.List_map(ff_core_Option.Option_toList(variableOption_), ((_w1) => {
|
|
2650
|
+
return ff_core_Pair.Pair(_w1, ff_core_Pair.Pair(variableAt_, recordType_))
|
|
2651
|
+
})), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String)
|
|
2652
|
+
return
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
{
|
|
2656
|
+
if(_1.PVariant) {
|
|
2657
|
+
const at_ = _1.at_;
|
|
2658
|
+
const name_ = _1.name_;
|
|
2659
|
+
const patterns_ = _1.patterns_;
|
|
2660
|
+
const instantiated_ = ff_core_Option.Option_else(ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, at_, name_, ff_core_List.Empty(), ff_core_Option.None()), (() => {
|
|
2661
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(at_, ("No such variant: " + name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
2662
|
+
}));
|
|
2663
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, at_, expected_, instantiated_.scheme_.signature_.returnType_);
|
|
2664
|
+
if(((ff_core_List.List_size(patterns_) !== ff_core_List.List_size(instantiated_.scheme_.signature_.parameters_)) && (!ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_)))) {
|
|
2665
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(at_, (((("Wrong number of subpatterns, expected " + ff_core_List.List_size(instantiated_.scheme_.signature_.parameters_)) + ", got ") + ff_core_List.List_size(patterns_)) + ".")), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
2666
|
+
};
|
|
2667
|
+
return ff_core_List.List_foldLeft(ff_core_List.List_map(ff_core_List.List_zip(patterns_, instantiated_.scheme_.signature_.parameters_), ((_1) => {
|
|
2668
|
+
{
|
|
2669
|
+
const pattern_ = _1.first_;
|
|
2670
|
+
const parameter_ = _1.second_;
|
|
2671
|
+
return ff_compiler_Inference.Inference_inferPattern(self_, environment_, parameter_.valueType_, pattern_)
|
|
2672
|
+
return
|
|
2673
|
+
}
|
|
2674
|
+
})), ff_core_Map.empty_(), ((_w1, _w2) => {
|
|
2675
|
+
return ff_core_Map.Map_addAll(_w1, _w2, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String)
|
|
2676
|
+
}))
|
|
2677
|
+
return
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
|
|
2683
|
+
export async function Inference_inferTerm$(self_, environment_, expected_, term_, $task) {
|
|
2684
|
+
const hookRecordTypeBox_ = (ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, term_.at_)
|
|
2685
|
+
? ff_core_Option.Some((await (async function() {
|
|
2686
|
+
const box_ = ff_compiler_LspHook.Box(ff_core_Option.None());
|
|
2687
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferTermHook(self_.unification_, environment_, expected_, term_, box_, self_.missing_));
|
|
2688
|
+
return box_
|
|
2689
|
+
})()))
|
|
2690
|
+
: ff_core_Option.None());
|
|
2691
|
+
function literal_(coreTypeName_) {
|
|
2692
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, term_.at_, expected_, ff_compiler_Syntax.TConstructor(term_.at_, ff_compiler_Inference.core_(coreTypeName_), ff_core_List.Empty()));
|
|
2693
|
+
return term_
|
|
2694
|
+
}
|
|
2695
|
+
{
|
|
2696
|
+
const _1 = term_;
|
|
2697
|
+
{
|
|
2698
|
+
if(_1.EString) {
|
|
2699
|
+
return literal_("String")
|
|
2700
|
+
return
|
|
2701
|
+
}
|
|
2702
|
+
}
|
|
2703
|
+
{
|
|
2704
|
+
if(_1.EChar) {
|
|
2705
|
+
return literal_("Char")
|
|
2706
|
+
return
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2709
|
+
{
|
|
2710
|
+
if(_1.EInt) {
|
|
2711
|
+
return literal_("Int")
|
|
2712
|
+
return
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
{
|
|
2716
|
+
if(_1.EFloat) {
|
|
2717
|
+
return literal_("Float")
|
|
2718
|
+
return
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
{
|
|
2722
|
+
if(_1.EVariable) {
|
|
2723
|
+
const e_ = _1;
|
|
2724
|
+
return ff_core_Option.Option_else(ff_core_Option.Option_map(ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, e_.at_, e_.name_, ff_core_List.Empty(), ff_core_Option.None()), ((instantiated_) => {
|
|
2725
|
+
if(instantiated_.scheme_.isVariable_) {
|
|
2726
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, instantiated_.scheme_.signature_.returnType_);
|
|
2727
|
+
return term_
|
|
2728
|
+
} else {
|
|
2729
|
+
return ff_compiler_Inference.Inference_inferEtaExpansion(self_, environment_, expected_, e_.at_, instantiated_.scheme_.signature_, term_)
|
|
2730
|
+
}
|
|
2731
|
+
})), (() => {
|
|
2732
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ("Symbol not in scope: " + e_.name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
2733
|
+
}))
|
|
2734
|
+
return
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
{
|
|
2738
|
+
if(_1.EField) {
|
|
2739
|
+
const e_ = _1;
|
|
2740
|
+
const recordType_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_);
|
|
2741
|
+
if(ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, term_.at_)) {
|
|
2742
|
+
ff_core_Option.Option_each(hookRecordTypeBox_, ((_w1) => {
|
|
2743
|
+
_w1.value_ = ff_core_Option.Some(recordType_)
|
|
2744
|
+
}))
|
|
2745
|
+
};
|
|
2746
|
+
const record_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, recordType_, e_.record_);
|
|
2747
|
+
{
|
|
2748
|
+
const _1 = ff_compiler_Unification.Unification_substitute(self_.unification_, recordType_);
|
|
2749
|
+
{
|
|
2750
|
+
const t_ = _1;
|
|
2751
|
+
if(_1.TConstructor) {
|
|
2752
|
+
const name_ = _1.name_;
|
|
2753
|
+
const typeArguments_ = _1.generics_;
|
|
2754
|
+
const _guard1 = ff_core_String.String_startsWith(name_, "Record$", 0);
|
|
2755
|
+
if(_guard1) {
|
|
2756
|
+
if(ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, e_.at_)) {
|
|
2757
|
+
const symbolHook_ = ff_compiler_LspHook.SymbolHook(e_.field_, e_.at_, e_.at_);
|
|
2758
|
+
const noEffect_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_);
|
|
2759
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferRecordFieldHook(self_.unification_, environment_, expected_, t_, e_.field_))
|
|
2760
|
+
};
|
|
2761
|
+
const fieldNames_ = ff_core_List.List_dropFirst(ff_core_Array.Array_toList(ff_core_String.String_split(name_, 36)), 1);
|
|
2762
|
+
return ff_core_Option.Option_else(ff_core_Option.Option_elseIf(ff_core_Option.Option_map(ff_core_Option.Option_map(ff_core_List.List_find(ff_core_List.List_pairs(fieldNames_), ((_w1) => {
|
|
2763
|
+
return (_w1.second_ === e_.field_)
|
|
2764
|
+
})), ((_w1) => {
|
|
2765
|
+
return _w1.first_
|
|
2766
|
+
})), ((index_) => {
|
|
2767
|
+
const t1_ = ff_core_List.List_grab(typeArguments_, index_);
|
|
2768
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t1_);
|
|
2769
|
+
{
|
|
2770
|
+
const _1 = e_;
|
|
2771
|
+
{
|
|
2772
|
+
const _c = _1;
|
|
2773
|
+
return ff_compiler_Syntax.EField(_c.at_, _c.newtype_, record_, _c.field_)
|
|
2774
|
+
return
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
})), (() => {
|
|
2778
|
+
return ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_)
|
|
2779
|
+
}), (() => {
|
|
2780
|
+
return term_
|
|
2781
|
+
})), (() => {
|
|
2782
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ((("No such field " + e_.field_) + " on type: ") + ff_compiler_Syntax.Type_show(t_, ff_core_List.Empty()))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
2783
|
+
}))
|
|
2784
|
+
return
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
{
|
|
2789
|
+
const t_ = _1;
|
|
2790
|
+
if(_1.TConstructor) {
|
|
2791
|
+
const name_ = _1.name_;
|
|
2792
|
+
const typeArguments_ = _1.generics_;
|
|
2793
|
+
const memberPrefix_ = (name_ + "_");
|
|
2794
|
+
const memberName_ = (memberPrefix_ + e_.field_);
|
|
2795
|
+
{
|
|
2796
|
+
const _1 = ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, e_.at_, memberName_, typeArguments_, ff_core_Option.None());
|
|
2797
|
+
{
|
|
2798
|
+
if(_1.Some) {
|
|
2799
|
+
const instantiated_ = _1.value_;
|
|
2800
|
+
const _guard1 = (!instantiated_.scheme_.isVariable_);
|
|
2801
|
+
if(_guard1) {
|
|
2802
|
+
const signature_ = (((_c) => {
|
|
2803
|
+
return ff_compiler_Syntax.Signature(_c.at_, _c.name_, _c.member_, _c.generics_, _c.constraints_, ff_core_List.List_dropFirst(instantiated_.scheme_.signature_.parameters_, 1), _c.returnType_, _c.effect_)
|
|
2804
|
+
}))(instantiated_.scheme_.signature_);
|
|
2805
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, recordType_, ff_core_List.List_grab(instantiated_.scheme_.signature_.parameters_, 0).valueType_);
|
|
2806
|
+
return ff_compiler_Inference.Inference_inferEtaExpansion(self_, environment_, expected_, e_.at_, signature_, term_)
|
|
2807
|
+
return
|
|
2808
|
+
}
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2811
|
+
{
|
|
2812
|
+
if(_1.Some) {
|
|
2813
|
+
const instantiated_ = _1.value_;
|
|
2814
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, instantiated_.scheme_.signature_.returnType_);
|
|
2815
|
+
{
|
|
2816
|
+
const _1 = e_;
|
|
2817
|
+
{
|
|
2818
|
+
const _c = _1;
|
|
2819
|
+
return ff_compiler_Syntax.EField(_c.at_, instantiated_.scheme_.isNewtype_, record_, _c.field_)
|
|
2820
|
+
return
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
return
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
{
|
|
2827
|
+
if(_1.None) {
|
|
2828
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ((("No such field " + e_.field_) + " on type: ") + ff_compiler_Syntax.Type_show(t_, ff_core_List.Empty()))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
2829
|
+
return
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
return
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
{
|
|
2837
|
+
if(_1.TVariable) {
|
|
2838
|
+
const _guard1 = ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_);
|
|
2839
|
+
if(_guard1) {
|
|
2840
|
+
return term_
|
|
2841
|
+
return
|
|
2842
|
+
}
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
{
|
|
2846
|
+
if(_1.TVariable) {
|
|
2847
|
+
const index_ = _1.index_;
|
|
2848
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ((("No such field " + e_.field_) + " on unknown type: $") + index_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
2849
|
+
return
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2852
|
+
}
|
|
2853
|
+
return
|
|
2854
|
+
}
|
|
2855
|
+
}
|
|
2856
|
+
{
|
|
2857
|
+
if(_1.EWildcard) {
|
|
2858
|
+
const e_ = _1;
|
|
2859
|
+
return ff_core_Option.Option_grab(ff_core_Option.Option_map(ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, e_.at_, ("_w" + e_.index_), ff_core_List.Empty(), ff_core_Option.None()), ((instantiated_) => {
|
|
2860
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, instantiated_.scheme_.signature_.returnType_);
|
|
2861
|
+
return term_
|
|
2862
|
+
})))
|
|
2863
|
+
return
|
|
2864
|
+
}
|
|
2865
|
+
}
|
|
2866
|
+
{
|
|
2867
|
+
if(_1.EList) {
|
|
2868
|
+
const at_ = _1.at_;
|
|
2869
|
+
const t_ = _1.elementType_;
|
|
2870
|
+
const items_ = _1.items_;
|
|
2871
|
+
const listType_ = ff_compiler_Syntax.TConstructor(term_.at_, ff_compiler_Inference.core_("List"), ff_core_List.Link(t_, ff_core_List.Empty()));
|
|
2872
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, at_, expected_, listType_);
|
|
2873
|
+
return ff_compiler_Syntax.EList(at_, t_, ff_core_List.List_map(items_, ((_1) => {
|
|
2874
|
+
{
|
|
2875
|
+
const item_ = _1.first_;
|
|
2876
|
+
const spread_ = _1.second_;
|
|
2877
|
+
return ff_core_Pair.Pair(ff_compiler_Inference.Inference_inferTerm(self_, environment_, (spread_
|
|
2878
|
+
? listType_
|
|
2879
|
+
: t_), item_), spread_)
|
|
2880
|
+
return
|
|
2881
|
+
}
|
|
2882
|
+
})))
|
|
2883
|
+
return
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
{
|
|
2887
|
+
if(_1.ESequential) {
|
|
2888
|
+
const at_ = _1.at_;
|
|
2889
|
+
const before_ = _1.before_;
|
|
2890
|
+
const after_ = _1.after_;
|
|
2891
|
+
if(ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, before_.at_)) {
|
|
2892
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferSequentialStartHook(self_.unification_, term_, self_.missing_))
|
|
2893
|
+
};
|
|
2894
|
+
const newExpected_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, at_);
|
|
2895
|
+
{
|
|
2896
|
+
const _1 = before_;
|
|
2897
|
+
{
|
|
2898
|
+
if(_1.EPipe) {
|
|
2899
|
+
const at1_ = _1.at_;
|
|
2900
|
+
const value_ = _1.value_;
|
|
2901
|
+
const effect1_ = _1.effect_;
|
|
2902
|
+
if(_1.function_.ELambda) {
|
|
2903
|
+
const at2_ = _1.function_.at_;
|
|
2904
|
+
const at3_ = _1.function_.lambda_.at_;
|
|
2905
|
+
const effect3_ = _1.function_.lambda_.effect_;
|
|
2906
|
+
const cases_ = _1.function_.lambda_.cases_;
|
|
2907
|
+
const e_ = ff_compiler_Syntax.EVariant(at_, "ff:core/Unit.Unit", ff_core_List.Empty(), ff_core_Option.None());
|
|
2908
|
+
const newCases_ = ff_core_List.List_map(cases_, ((case_) => {
|
|
2909
|
+
{
|
|
2910
|
+
const _1 = case_;
|
|
2911
|
+
{
|
|
2912
|
+
const _c = _1;
|
|
2913
|
+
return ff_compiler_Syntax.MatchCase(_c.at_, _c.patterns_, _c.guards_, ff_compiler_Syntax.ESequential(case_.at_, case_.body_, e_))
|
|
2914
|
+
return
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
}));
|
|
2918
|
+
const newPipe_ = ff_compiler_Syntax.EPipe(at1_, value_, effect1_, ff_compiler_Syntax.ELambda(at2_, ff_compiler_Syntax.Lambda(at3_, effect3_, newCases_)));
|
|
2919
|
+
{
|
|
2920
|
+
const _1 = after_;
|
|
2921
|
+
{
|
|
2922
|
+
if(_1.EVariant) {
|
|
2923
|
+
const at_ = _1.at_;
|
|
2924
|
+
if(_1.name_ == "ff:core/Unit.Unit") {
|
|
2925
|
+
const unitType_ = ff_compiler_Syntax.TConstructor(at_, ff_compiler_Inference.core_("Unit"), ff_core_List.Empty());
|
|
2926
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, at_, expected_, unitType_);
|
|
2927
|
+
return ff_compiler_Inference.Inference_inferTerm(self_, environment_, newExpected_, newPipe_)
|
|
2928
|
+
return
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
}
|
|
2932
|
+
{
|
|
2933
|
+
return ff_compiler_Syntax.ESequential(at_, ff_compiler_Inference.Inference_inferTerm(self_, environment_, newExpected_, newPipe_), ff_compiler_Inference.Inference_inferTerm(self_, environment_, expected_, after_))
|
|
2934
|
+
return
|
|
2935
|
+
}
|
|
2936
|
+
}
|
|
2937
|
+
return
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2941
|
+
{
|
|
2942
|
+
return ff_compiler_Syntax.ESequential(at_, ff_compiler_Inference.Inference_inferTerm(self_, environment_, newExpected_, before_), ff_compiler_Inference.Inference_inferTerm(self_, environment_, expected_, after_))
|
|
2943
|
+
return
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2946
|
+
return
|
|
2947
|
+
}
|
|
2948
|
+
}
|
|
2949
|
+
{
|
|
2950
|
+
if(_1.ELet) {
|
|
2951
|
+
const e_ = _1;
|
|
2952
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(e_.at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
2953
|
+
const scheme_ = ff_compiler_Environment.Scheme(true, e_.mutable_, false, false, ff_compiler_Syntax.Signature(e_.at_, e_.name_, false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Empty(), e_.valueType_, noEffect_));
|
|
2954
|
+
const environment2_ = (((_c) => {
|
|
2955
|
+
return ff_compiler_Environment.Environment(_c.modulePrefix_, ff_core_Map.Map_add(environment_.symbols_, e_.name_, scheme_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String), _c.traits_, _c.imports_, _c.effect_, _c.selfVariable_)
|
|
2956
|
+
}))(environment_);
|
|
2957
|
+
{
|
|
2958
|
+
const _1 = e_;
|
|
2959
|
+
{
|
|
2960
|
+
const _c = _1;
|
|
2961
|
+
return ff_compiler_Syntax.ELet(_c.at_, _c.mutable_, _c.name_, _c.valueType_, ff_compiler_Inference.Inference_inferTerm(self_, environment_, e_.valueType_, e_.value_), ff_compiler_Inference.Inference_inferTerm(self_, environment2_, expected_, e_.body_))
|
|
2962
|
+
return
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
return
|
|
2966
|
+
}
|
|
2967
|
+
}
|
|
2968
|
+
{
|
|
2969
|
+
if(_1.ELambda) {
|
|
2970
|
+
const at_ = _1.at_;
|
|
2971
|
+
const l_ = _1.lambda_;
|
|
2972
|
+
do {
|
|
2973
|
+
const _1 = l_.cases_;
|
|
2974
|
+
{
|
|
2975
|
+
if(_1.Link) {
|
|
2976
|
+
if(_1.head_.patterns_.Empty) {
|
|
2977
|
+
if(_1.head_.guards_.Empty) {
|
|
2978
|
+
if(_1.head_.body_.EVariable) {
|
|
2979
|
+
const insideAt_ = _1.head_.body_.at_;
|
|
2980
|
+
if(_1.head_.body_.name_ == "") {
|
|
2981
|
+
if(_1.tail_.Empty) {
|
|
2982
|
+
const _guard1 = ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, insideAt_);
|
|
2983
|
+
if(_guard1) {
|
|
2984
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferLambdaStartHook(self_.unification_, environment_, expected_))
|
|
2985
|
+
break
|
|
2986
|
+
}
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
{
|
|
2995
|
+
if(_1.Link) {
|
|
2996
|
+
if(_1.head_.patterns_.Empty) {
|
|
2997
|
+
if(_1.head_.guards_.Empty) {
|
|
2998
|
+
if(_1.head_.body_.ESequential) {
|
|
2999
|
+
if(_1.head_.body_.before_.EVariable) {
|
|
3000
|
+
const insideAt_ = _1.head_.body_.before_.at_;
|
|
3001
|
+
if(_1.head_.body_.before_.name_ == "") {
|
|
3002
|
+
if(_1.head_.body_.after_.EVariant) {
|
|
3003
|
+
if(_1.head_.body_.after_.name_ == "ff:core/Unit.Unit") {
|
|
3004
|
+
if(_1.tail_.Empty) {
|
|
3005
|
+
const _guard1 = ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, insideAt_);
|
|
3006
|
+
if(_guard1) {
|
|
3007
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferLambdaStartHook(self_.unification_, environment_, expected_))
|
|
3008
|
+
break
|
|
3009
|
+
}
|
|
3010
|
+
}
|
|
3011
|
+
}
|
|
3012
|
+
}
|
|
3013
|
+
}
|
|
3014
|
+
}
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
}
|
|
3019
|
+
}
|
|
3020
|
+
{
|
|
3021
|
+
|
|
3022
|
+
break
|
|
3023
|
+
}
|
|
3024
|
+
} while(false);
|
|
3025
|
+
const lambda_ = ff_compiler_Inference.Inference_inferLambda(self_, environment_, expected_, l_);
|
|
3026
|
+
return ff_compiler_Syntax.ELambda(at_, lambda_)
|
|
3027
|
+
return
|
|
3028
|
+
}
|
|
3029
|
+
}
|
|
3030
|
+
{
|
|
3031
|
+
if(_1.EVariant) {
|
|
3032
|
+
const e_ = _1;
|
|
3033
|
+
const instantiated_ = ff_core_Option.Option_else(ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, e_.at_, e_.name_, e_.typeArguments_, e_.arguments_), (() => {
|
|
3034
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ("Symbol not in scope: " + e_.name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3035
|
+
}));
|
|
3036
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, instantiated_.scheme_.signature_.returnType_);
|
|
3037
|
+
const arguments_ = ff_core_Option.Option_map(e_.arguments_, ((_w1) => {
|
|
3038
|
+
return ff_compiler_Inference.Inference_inferArguments(self_, e_.at_, e_.name_, environment_, instantiated_.scheme_.signature_.parameters_, _w1)
|
|
3039
|
+
}));
|
|
3040
|
+
{
|
|
3041
|
+
const _1 = e_;
|
|
3042
|
+
{
|
|
3043
|
+
const _c = _1;
|
|
3044
|
+
return ff_compiler_Syntax.EVariant(_c.at_, _c.name_, ff_core_List.List_map(instantiated_.typeArguments_, ((_w1) => {
|
|
3045
|
+
return _w1.second_
|
|
3046
|
+
})), arguments_)
|
|
3047
|
+
return
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
return
|
|
3051
|
+
}
|
|
3052
|
+
}
|
|
3053
|
+
{
|
|
3054
|
+
if(_1.EVariantIs) {
|
|
3055
|
+
const e_ = _1;
|
|
3056
|
+
const instantiated_ = ff_core_Option.Option_else(ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, e_.at_, e_.name_, e_.typeArguments_, ff_core_Option.None()), (() => {
|
|
3057
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ("Symbol not in scope: " + e_.name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3058
|
+
}));
|
|
3059
|
+
const parameters_ = ff_core_List.List_sortBy(instantiated_.scheme_.signature_.parameters_, ((_w1) => {
|
|
3060
|
+
return _w1.name_
|
|
3061
|
+
}), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
3062
|
+
const recordType_ = ff_compiler_Syntax.TConstructor(e_.at_, ("Record$" + ff_core_List.List_join(ff_core_List.List_map(parameters_, ((_w1) => {
|
|
3063
|
+
return _w1.name_
|
|
3064
|
+
})), "$")), ff_core_List.List_map(parameters_, ((_w1) => {
|
|
3065
|
+
return _w1.valueType_
|
|
3066
|
+
})));
|
|
3067
|
+
const functionType_ = ff_compiler_Syntax.TConstructor(e_.at_, "Function$1", ff_core_List.Link(ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_), ff_core_List.Link(instantiated_.scheme_.signature_.returnType_, ff_core_List.Link(ff_compiler_Syntax.TConstructor(e_.at_, ff_compiler_Inference.core_("Option"), ff_core_List.Link(recordType_, ff_core_List.Empty())), ff_core_List.Empty()))));
|
|
3068
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, functionType_);
|
|
3069
|
+
{
|
|
3070
|
+
const _1 = e_;
|
|
3071
|
+
{
|
|
3072
|
+
const _c = _1;
|
|
3073
|
+
return ff_compiler_Syntax.EVariantIs(_c.at_, _c.name_, ff_core_List.List_map(instantiated_.typeArguments_, ((_w1) => {
|
|
3074
|
+
return _w1.second_
|
|
3075
|
+
})))
|
|
3076
|
+
return
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3079
|
+
return
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
{
|
|
3083
|
+
if(_1.ECopy) {
|
|
3084
|
+
const e_ = _1;
|
|
3085
|
+
const scheme_ = ff_core_Option.Option_else(ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, e_.at_, e_.name_, ff_core_List.Empty(), ff_core_Option.None()), (() => {
|
|
3086
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ("Symbol not in scope: " + e_.name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3087
|
+
})).scheme_;
|
|
3088
|
+
if(scheme_.isNewtype_) {
|
|
3089
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, "Newtypes can't be copied"), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3090
|
+
};
|
|
3091
|
+
const signature_ = scheme_.signature_;
|
|
3092
|
+
if(ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_)) {
|
|
3093
|
+
ff_core_List.List_each(ff_core_List.List_pairs(e_.arguments_), ((_1) => {
|
|
3094
|
+
{
|
|
3095
|
+
const i_ = _1.first_;
|
|
3096
|
+
const a_ = _1.second_;
|
|
3097
|
+
const p_ = ff_core_List.List_find(signature_.parameters_, ((_w1) => {
|
|
3098
|
+
return (_w1.name_ === a_.name_)
|
|
3099
|
+
}));
|
|
3100
|
+
if((ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, a_.at_) || ff_core_Option.Option_any(p_, ((_w1) => {
|
|
3101
|
+
return ff_compiler_LspHook.LspHook_isDefinedAt(self_.lspHook_, _w1.at_)
|
|
3102
|
+
})))) {
|
|
3103
|
+
const arguments_ = ff_core_List.List_map(e_.arguments_, ((f_) => {
|
|
3104
|
+
{
|
|
3105
|
+
const _1 = f_;
|
|
3106
|
+
{
|
|
3107
|
+
const _c = _1;
|
|
3108
|
+
return ff_compiler_Syntax.Argument(_c.at_, ff_core_Option.Some(f_.name_), _c.value_)
|
|
3109
|
+
return
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
}));
|
|
3113
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferArgumentHook(self_.unification_, environment_, true, term_.at_, e_.name_, signature_.parameters_, arguments_, i_))
|
|
3114
|
+
}
|
|
3115
|
+
return
|
|
3116
|
+
}
|
|
3117
|
+
}))
|
|
3118
|
+
};
|
|
3119
|
+
const parameterNames_ = ff_core_List.List_map(signature_.parameters_, ((_w1) => {
|
|
3120
|
+
return _w1.name_
|
|
3121
|
+
}));
|
|
3122
|
+
ff_core_Option.Option_each(ff_core_List.List_find(e_.arguments_, ((a_) => {
|
|
3123
|
+
return (!ff_core_List.List_any(parameterNames_, ((_w1) => {
|
|
3124
|
+
return (_w1 === a_.name_)
|
|
3125
|
+
})))
|
|
3126
|
+
})), ((_1) => {
|
|
3127
|
+
{
|
|
3128
|
+
const at_ = _1.at_;
|
|
3129
|
+
const name_ = _1.name_;
|
|
3130
|
+
const value_ = _1.value_;
|
|
3131
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(at_, ("Unknown parameter: " + name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3132
|
+
return
|
|
3133
|
+
}
|
|
3134
|
+
}));
|
|
3135
|
+
const arguments_ = ff_core_List.List_map(parameterNames_, ((name_) => {
|
|
3136
|
+
return ff_core_Option.Option_else(ff_core_Option.Option_map(ff_core_List.List_find(e_.arguments_, ((_w1) => {
|
|
3137
|
+
return (_w1.name_ === name_)
|
|
3138
|
+
})), ((_1) => {
|
|
3139
|
+
{
|
|
3140
|
+
const at_ = _1.at_;
|
|
3141
|
+
const value_ = _1.value_;
|
|
3142
|
+
return ff_compiler_Syntax.Argument(at_, ff_core_Option.Some(name_), value_)
|
|
3143
|
+
return
|
|
3144
|
+
}
|
|
3145
|
+
})), (() => {
|
|
3146
|
+
const at_ = (((_c) => {
|
|
3147
|
+
return ff_compiler_Syntax.Location((e_.at_.file_ + "/<copy>"), _c.line_, _c.column_)
|
|
3148
|
+
}))(e_.at_);
|
|
3149
|
+
return ff_compiler_Syntax.Argument(at_, ff_core_Option.Some(name_), ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "_c"), name_))
|
|
3150
|
+
}))
|
|
3151
|
+
}));
|
|
3152
|
+
const body_ = ff_compiler_Syntax.EVariant(e_.at_, e_.name_, ff_core_List.Empty(), ff_core_Option.Some(arguments_));
|
|
3153
|
+
const effect_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_);
|
|
3154
|
+
const e1_ = ff_compiler_Syntax.EPipe(e_.at_, e_.record_, effect_, ff_compiler_Syntax.ELambda(e_.at_, ff_compiler_Syntax.Lambda(e_.at_, effect_, ff_core_List.Link(ff_compiler_Syntax.MatchCase(e_.at_, ff_core_List.Link(ff_compiler_Syntax.PVariable(e_.at_, ff_core_Option.Some("_c")), ff_core_List.Empty()), ff_core_List.Empty(), body_), ff_core_List.Empty()))));
|
|
3155
|
+
return ff_compiler_Inference.Inference_inferTerm(self_, environment_, expected_, e1_)
|
|
3156
|
+
return
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
{
|
|
3160
|
+
if(_1.EPipe) {
|
|
3161
|
+
const e_ = _1;
|
|
3162
|
+
const valueType_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_);
|
|
3163
|
+
const functionType_ = ff_compiler_Syntax.TConstructor(e_.at_, "Function$1", ff_core_List.Link(e_.effect_, ff_core_List.Link(valueType_, ff_core_List.Link(expected_, ff_core_List.Empty()))));
|
|
3164
|
+
const value_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, valueType_, e_.value_);
|
|
3165
|
+
const function_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, functionType_, e_.function_);
|
|
3166
|
+
ff_compiler_Unification.Unification_affect(self_.unification_, term_.at_, e_.effect_, environment_.effect_);
|
|
3167
|
+
{
|
|
3168
|
+
const _1 = e_;
|
|
3169
|
+
{
|
|
3170
|
+
const _c = _1;
|
|
3171
|
+
return ff_compiler_Syntax.EPipe(_c.at_, value_, _c.effect_, function_)
|
|
3172
|
+
return
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
return
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
{
|
|
3179
|
+
if(_1.ECall) {
|
|
3180
|
+
const e_ = _1;
|
|
3181
|
+
if((ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_) && (((_1) => {
|
|
3182
|
+
{
|
|
3183
|
+
if(_1.StaticCall) {
|
|
3184
|
+
return true
|
|
3185
|
+
return
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
{
|
|
3189
|
+
return false
|
|
3190
|
+
return
|
|
3191
|
+
}
|
|
3192
|
+
}))(e_.target_))) {
|
|
3193
|
+
return term_
|
|
3194
|
+
} else {
|
|
3195
|
+
const call_ = (((_1) => {
|
|
3196
|
+
{
|
|
3197
|
+
if(_1.DynamicCall) {
|
|
3198
|
+
const call_ = _1;
|
|
3199
|
+
return call_
|
|
3200
|
+
return
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3203
|
+
{
|
|
3204
|
+
if(_1.StaticCall) {
|
|
3205
|
+
return ff_compiler_Inference.fail_(e_.at_, "Internal error: Static calls not expected in the Inference phase")
|
|
3206
|
+
return
|
|
3207
|
+
}
|
|
3208
|
+
}
|
|
3209
|
+
}))(e_.target_);
|
|
3210
|
+
{
|
|
3211
|
+
const _1 = call_.function_;
|
|
3212
|
+
{
|
|
3213
|
+
if(_1.EVariable) {
|
|
3214
|
+
const variableAt_ = _1.at_;
|
|
3215
|
+
const x_ = _1.name_;
|
|
3216
|
+
if(ff_core_Option.Option_any(ff_core_String.String_first(x_), ((c_) => {
|
|
3217
|
+
return ((c_ !== 95) && (!ff_core_Char.Char_isAsciiLetter(c_)))
|
|
3218
|
+
}))) {
|
|
3219
|
+
return ff_compiler_Inference.Inference_inferOperator(self_, environment_, expected_, x_, term_)
|
|
3220
|
+
} else {
|
|
3221
|
+
{
|
|
3222
|
+
const _1 = ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, e_.at_, x_, e_.typeArguments_, ff_core_Option.Some(e_.arguments_));
|
|
3223
|
+
{
|
|
3224
|
+
if(_1.Some) {
|
|
3225
|
+
const instantiated_ = _1.value_;
|
|
3226
|
+
if(instantiated_.scheme_.isVariable_) {
|
|
3227
|
+
return ff_compiler_Inference.Inference_inferLambdaCall(self_, environment_, expected_, term_)
|
|
3228
|
+
} else {
|
|
3229
|
+
const signature_ = instantiated_.scheme_.signature_;
|
|
3230
|
+
return ff_compiler_Inference.Inference_inferFunctionCall(self_, environment_, expected_, signature_, instantiated_.scheme_.isTraitMethod_, instantiated_.typeArguments_, term_, x_)
|
|
3231
|
+
}
|
|
3232
|
+
return
|
|
3233
|
+
}
|
|
3234
|
+
}
|
|
3235
|
+
{
|
|
3236
|
+
if(_1.None) {
|
|
3237
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(variableAt_, ("No such function: " + x_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3238
|
+
return
|
|
3239
|
+
}
|
|
3240
|
+
}
|
|
3241
|
+
}
|
|
3242
|
+
}
|
|
3243
|
+
return
|
|
3244
|
+
}
|
|
3245
|
+
}
|
|
3246
|
+
{
|
|
3247
|
+
if(_1.EField) {
|
|
3248
|
+
const f_ = _1;
|
|
3249
|
+
const recordType_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, f_.at_);
|
|
3250
|
+
if(ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, term_.at_)) {
|
|
3251
|
+
ff_core_Option.Option_each(hookRecordTypeBox_, ((_w1) => {
|
|
3252
|
+
_w1.value_ = ff_core_Option.Some(recordType_)
|
|
3253
|
+
}))
|
|
3254
|
+
};
|
|
3255
|
+
const record_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, recordType_, f_.record_);
|
|
3256
|
+
const e2_ = (((_c) => {
|
|
3257
|
+
return ff_compiler_Syntax.ECall(_c.at_, (((_c) => {
|
|
3258
|
+
return ff_compiler_Syntax.DynamicCall((((_c) => {
|
|
3259
|
+
return ff_compiler_Syntax.EField(_c.at_, _c.newtype_, record_, _c.field_)
|
|
3260
|
+
}))(f_), _c.tailCall_)
|
|
3261
|
+
}))(call_), _c.effect_, _c.typeArguments_, _c.arguments_, _c.dictionaries_)
|
|
3262
|
+
}))(e_);
|
|
3263
|
+
{
|
|
3264
|
+
const _1 = ff_compiler_Unification.Unification_substitute(self_.unification_, recordType_);
|
|
3265
|
+
{
|
|
3266
|
+
const t_ = _1;
|
|
3267
|
+
if(_1.TConstructor) {
|
|
3268
|
+
const name_ = _1.name_;
|
|
3269
|
+
const methodName_ = ((name_ + "_") + f_.field_);
|
|
3270
|
+
const arguments_ = ff_core_List.Link(ff_compiler_Syntax.Argument(f_.record_.at_, ff_core_Option.None(), f_.record_), e_.arguments_);
|
|
3271
|
+
{
|
|
3272
|
+
const _1 = ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, f_.at_, methodName_, ff_core_List.Empty(), ff_core_Option.Some(arguments_));
|
|
3273
|
+
{
|
|
3274
|
+
if(_1.Some) {
|
|
3275
|
+
const instantiated_ = _1.value_;
|
|
3276
|
+
const _guard1 = (!instantiated_.scheme_.isVariable_);
|
|
3277
|
+
if(_guard1) {
|
|
3278
|
+
return ff_compiler_Inference.Inference_inferMethodCall(self_, environment_, expected_, instantiated_.scheme_.signature_, instantiated_.typeArguments_, e2_, record_, recordType_, methodName_)
|
|
3279
|
+
return
|
|
3280
|
+
}
|
|
3281
|
+
}
|
|
3282
|
+
}
|
|
3283
|
+
{
|
|
3284
|
+
if(_1.Some) {
|
|
3285
|
+
const instantiated_ = _1.value_;
|
|
3286
|
+
return ff_compiler_Inference.Inference_inferLambdaCall(self_, environment_, expected_, e2_)
|
|
3287
|
+
return
|
|
3288
|
+
}
|
|
3289
|
+
}
|
|
3290
|
+
{
|
|
3291
|
+
if(_1.None) {
|
|
3292
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(f_.at_, ((("No such field " + f_.field_) + " on type: ") + ff_compiler_Syntax.Type_show(t_, ff_core_List.Empty()))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3293
|
+
return
|
|
3294
|
+
}
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
return
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
{
|
|
3301
|
+
if(_1.TVariable) {
|
|
3302
|
+
const _guard1 = ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_);
|
|
3303
|
+
if(_guard1) {
|
|
3304
|
+
return ff_compiler_Inference.Inference_inferLambdaCall(self_, environment_, expected_, e2_)
|
|
3305
|
+
return
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
}
|
|
3309
|
+
{
|
|
3310
|
+
if(_1.TVariable) {
|
|
3311
|
+
const index_ = _1.index_;
|
|
3312
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(f_.at_, ((("No such field " + f_.field_) + " on unknown type: $") + index_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3313
|
+
return
|
|
3314
|
+
}
|
|
3315
|
+
}
|
|
3316
|
+
}
|
|
3317
|
+
return
|
|
3318
|
+
}
|
|
3319
|
+
}
|
|
3320
|
+
{
|
|
3321
|
+
return ff_compiler_Inference.Inference_inferLambdaCall(self_, environment_, expected_, term_)
|
|
3322
|
+
return
|
|
3323
|
+
}
|
|
3324
|
+
}
|
|
3325
|
+
}
|
|
3326
|
+
return
|
|
3327
|
+
}
|
|
3328
|
+
}
|
|
3329
|
+
{
|
|
3330
|
+
if(_1.ERecord) {
|
|
3331
|
+
const e_ = _1;
|
|
3332
|
+
const fields_ = ff_core_List.List_sortBy(e_.fields_, ((_w1) => {
|
|
3333
|
+
return _w1.name_
|
|
3334
|
+
}), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
3335
|
+
const fieldTypes_ = ff_core_List.List_map(fields_, ((_w1) => {
|
|
3336
|
+
return ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, _w1.at_)
|
|
3337
|
+
}));
|
|
3338
|
+
const recordType_ = ff_compiler_Syntax.TConstructor(e_.at_, ("Record$" + ff_core_List.List_join(ff_core_List.List_map(fields_, ((_w1) => {
|
|
3339
|
+
return _w1.name_
|
|
3340
|
+
})), "$")), fieldTypes_);
|
|
3341
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, recordType_);
|
|
3342
|
+
const newFields_ = ff_core_List.List_map(ff_core_List.List_zip(fields_, fieldTypes_), ((_1) => {
|
|
3343
|
+
{
|
|
3344
|
+
const field_ = _1.first_;
|
|
3345
|
+
const t_ = _1.second_;
|
|
3346
|
+
{
|
|
3347
|
+
const _1 = field_;
|
|
3348
|
+
{
|
|
3349
|
+
const _c = _1;
|
|
3350
|
+
return ff_compiler_Syntax.Field(_c.at_, _c.name_, ff_compiler_Inference.Inference_inferTerm(self_, environment_, t_, field_.value_))
|
|
3351
|
+
return
|
|
3352
|
+
}
|
|
3353
|
+
}
|
|
3354
|
+
return
|
|
3355
|
+
}
|
|
3356
|
+
}));
|
|
3357
|
+
{
|
|
3358
|
+
const _1 = e_;
|
|
3359
|
+
{
|
|
3360
|
+
const _c = _1;
|
|
3361
|
+
return ff_compiler_Syntax.ERecord(_c.at_, newFields_)
|
|
3362
|
+
return
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
return
|
|
3366
|
+
}
|
|
3367
|
+
}
|
|
3368
|
+
{
|
|
3369
|
+
if(_1.EFunctions) {
|
|
3370
|
+
const at_ = _1.at_;
|
|
3371
|
+
const functions_ = _1.functions_;
|
|
3372
|
+
const body_ = _1.body_;
|
|
3373
|
+
const functionMap_ = ff_core_List.List_toMap(ff_core_List.List_map(functions_, ((f_) => {
|
|
3374
|
+
const scheme_ = ff_compiler_Environment.Scheme(false, false, false, false, f_.signature_);
|
|
3375
|
+
return ff_core_Pair.Pair(f_.signature_.name_, scheme_)
|
|
3376
|
+
})), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
3377
|
+
const environment2_ = (((_c) => {
|
|
3378
|
+
return ff_compiler_Environment.Environment(_c.modulePrefix_, ff_core_Map.Map_addAll(environment_.symbols_, functionMap_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String), _c.traits_, _c.imports_, _c.effect_, _c.selfVariable_)
|
|
3379
|
+
}))(environment_);
|
|
3380
|
+
const newFunctions_ = ff_core_List.List_map(functions_, ((_w1) => {
|
|
3381
|
+
return ff_compiler_Inference.Inference_inferFunctionDefinition(self_, environment2_, _w1)
|
|
3382
|
+
}));
|
|
3383
|
+
const newBody_ = ff_compiler_Inference.Inference_inferTerm(self_, environment2_, expected_, body_);
|
|
3384
|
+
return ff_compiler_Syntax.EFunctions(at_, newFunctions_, newBody_)
|
|
3385
|
+
return
|
|
3386
|
+
}
|
|
3387
|
+
}
|
|
3388
|
+
{
|
|
3389
|
+
if(_1.EAssign) {
|
|
3390
|
+
const e_ = _1;
|
|
3391
|
+
return ff_core_Option.Option_else(ff_core_Option.Option_map(ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, e_.at_, e_.variable_, ff_core_List.Empty(), ff_core_Option.None()), ((instantiated_) => {
|
|
3392
|
+
if((instantiated_.scheme_.isMutable_ || ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_))) {
|
|
3393
|
+
const value_ = ff_compiler_Inference.Inference_inferAssignment(self_, environment_, expected_, e_.at_, e_.operator_, e_.value_, instantiated_.scheme_.signature_);
|
|
3394
|
+
{
|
|
3395
|
+
const _1 = e_;
|
|
3396
|
+
{
|
|
3397
|
+
const _c = _1;
|
|
3398
|
+
return ff_compiler_Syntax.EAssign(_c.at_, _c.operator_, _c.variable_, value_)
|
|
3399
|
+
return
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
} else {
|
|
3403
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ("Symbol is not mutable: " + e_.variable_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3404
|
+
}
|
|
3405
|
+
})), (() => {
|
|
3406
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ("Symbol not in scope: " + e_.variable_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3407
|
+
}))
|
|
3408
|
+
return
|
|
3409
|
+
}
|
|
3410
|
+
}
|
|
3411
|
+
{
|
|
3412
|
+
if(_1.EAssignField) {
|
|
3413
|
+
const e_ = _1;
|
|
3414
|
+
const recordType_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_);
|
|
3415
|
+
const record_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, recordType_, e_.record_);
|
|
3416
|
+
{
|
|
3417
|
+
const _1 = ff_compiler_Unification.Unification_substitute(self_.unification_, recordType_);
|
|
3418
|
+
{
|
|
3419
|
+
const t_ = _1;
|
|
3420
|
+
if(_1.TConstructor) {
|
|
3421
|
+
const name_ = _1.name_;
|
|
3422
|
+
const typeArguments_ = _1.generics_;
|
|
3423
|
+
const _guard1 = ff_core_String.String_startsWith(name_, "Record$", 0);
|
|
3424
|
+
if(_guard1) {
|
|
3425
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ("Can't assign fields of anonymous records: " + e_.field_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3426
|
+
return
|
|
3427
|
+
}
|
|
3428
|
+
}
|
|
3429
|
+
}
|
|
3430
|
+
{
|
|
3431
|
+
const t_ = _1;
|
|
3432
|
+
if(_1.TConstructor) {
|
|
3433
|
+
const name_ = _1.name_;
|
|
3434
|
+
const typeArguments_ = _1.generics_;
|
|
3435
|
+
const methodName_ = ((name_ + "_") + e_.field_);
|
|
3436
|
+
{
|
|
3437
|
+
const _1 = ff_compiler_Inference.Inference_lookup(self_, environment_, expected_, e_.at_, methodName_, typeArguments_, ff_core_Option.None());
|
|
3438
|
+
{
|
|
3439
|
+
if(_1.Some) {
|
|
3440
|
+
const instantiated_ = _1.value_;
|
|
3441
|
+
const _guard1 = (instantiated_.scheme_.isMutable_ || ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_));
|
|
3442
|
+
if(_guard1) {
|
|
3443
|
+
const value_ = ff_compiler_Inference.Inference_inferAssignment(self_, environment_, expected_, e_.at_, e_.operator_, e_.value_, instantiated_.scheme_.signature_);
|
|
3444
|
+
{
|
|
3445
|
+
const _1 = e_;
|
|
3446
|
+
{
|
|
3447
|
+
const _c = _1;
|
|
3448
|
+
return ff_compiler_Syntax.EAssignField(_c.at_, _c.operator_, record_, _c.field_, value_)
|
|
3449
|
+
return
|
|
3450
|
+
}
|
|
3451
|
+
}
|
|
3452
|
+
return
|
|
3453
|
+
}
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
{
|
|
3457
|
+
if(_1.Some) {
|
|
3458
|
+
const instantiated_ = _1.value_;
|
|
3459
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ((("Can't assign an immutable field " + e_.field_) + " on type: ") + ff_compiler_Syntax.Type_show(t_, ff_core_List.Empty()))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3460
|
+
return
|
|
3461
|
+
}
|
|
3462
|
+
}
|
|
3463
|
+
{
|
|
3464
|
+
if(_1.None) {
|
|
3465
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ((("No such field " + e_.field_) + " on type: ") + ff_compiler_Syntax.Type_show(t_, ff_core_List.Empty()))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3466
|
+
return
|
|
3467
|
+
}
|
|
3468
|
+
}
|
|
3469
|
+
}
|
|
3470
|
+
return
|
|
3471
|
+
}
|
|
3472
|
+
}
|
|
3473
|
+
{
|
|
3474
|
+
if(_1.TVariable) {
|
|
3475
|
+
const _guard1 = ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_);
|
|
3476
|
+
if(_guard1) {
|
|
3477
|
+
return term_
|
|
3478
|
+
return
|
|
3479
|
+
}
|
|
3480
|
+
}
|
|
3481
|
+
}
|
|
3482
|
+
{
|
|
3483
|
+
if(_1.TVariable) {
|
|
3484
|
+
const index_ = _1.index_;
|
|
3485
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, ((("No such field " + e_.field_) + " on unknown type: $") + index_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3486
|
+
return
|
|
3487
|
+
}
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
return
|
|
3491
|
+
}
|
|
3492
|
+
}
|
|
3493
|
+
}
|
|
3494
|
+
}
|
|
3495
|
+
|
|
3496
|
+
export async function Inference_inferAssignment$(self_, environment_, expected_, at_, operator_, value_, signature_, $task) {
|
|
3497
|
+
const t_ = signature_.returnType_;
|
|
3498
|
+
if(((operator_ === "+") || (operator_ === "-"))) {
|
|
3499
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, at_, t_, ff_compiler_Syntax.TConstructor(at_, ff_compiler_Inference.core_("Int"), ff_core_List.Empty()))
|
|
3500
|
+
} else if((operator_ !== "")) {
|
|
3501
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(at_, (("Only +=, -= and = assignments are supported. Got: " + operator_) + "=")), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3502
|
+
} else {};
|
|
3503
|
+
const newValue_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t_, value_);
|
|
3504
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, at_, expected_, ff_compiler_Syntax.TConstructor(at_, ff_compiler_Inference.core_("Unit"), ff_core_List.Empty()));
|
|
3505
|
+
return newValue_
|
|
3506
|
+
}
|
|
3507
|
+
|
|
3508
|
+
export async function Inference_inferMethodCall$(self_, environment_, expected_, signature_, instantiation_, term_, record_, recordType_, name_, $task) {
|
|
3509
|
+
const e_ = (((_1) => {
|
|
3510
|
+
{
|
|
3511
|
+
if(_1.ECall) {
|
|
3512
|
+
const e_ = _1;
|
|
3513
|
+
return e_
|
|
3514
|
+
return
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
{
|
|
3518
|
+
return ff_compiler_Inference.fail_(term_.at_, "Call expected")
|
|
3519
|
+
return
|
|
3520
|
+
}
|
|
3521
|
+
}))(term_);
|
|
3522
|
+
const call_ = (((_1) => {
|
|
3523
|
+
{
|
|
3524
|
+
if(_1.DynamicCall) {
|
|
3525
|
+
const call_ = _1;
|
|
3526
|
+
return call_
|
|
3527
|
+
return
|
|
3528
|
+
}
|
|
3529
|
+
}
|
|
3530
|
+
{
|
|
3531
|
+
if(_1.StaticCall) {
|
|
3532
|
+
return ff_compiler_Inference.fail_(e_.at_, "Internal error: Static calls not expected in inferMethodCall")
|
|
3533
|
+
return
|
|
3534
|
+
}
|
|
3535
|
+
}
|
|
3536
|
+
}))(e_.target_);
|
|
3537
|
+
const selfParameter_ = ff_core_List.List_grabFirst(signature_.parameters_);
|
|
3538
|
+
const selfArgument_ = ff_compiler_Syntax.Argument(record_.at_, ff_core_Option.Some(selfParameter_.name_), record_);
|
|
3539
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, term_.at_, expected_, signature_.returnType_);
|
|
3540
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, term_.at_, selfParameter_.valueType_, recordType_);
|
|
3541
|
+
const arguments_ = ff_compiler_Inference.Inference_inferArguments(self_, term_.at_, name_, environment_, ff_core_List.List_dropFirst(signature_.parameters_, 1), e_.arguments_);
|
|
3542
|
+
ff_compiler_Unification.Unification_affect(self_.unification_, term_.at_, signature_.effect_, environment_.effect_);
|
|
3543
|
+
{
|
|
3544
|
+
const _1 = e_;
|
|
3545
|
+
{
|
|
3546
|
+
const _c = _1;
|
|
3547
|
+
return ff_compiler_Syntax.ECall(_c.at_, ff_compiler_Syntax.StaticCall(name_, call_.tailCall_, false), signature_.effect_, ff_core_List.List_map(instantiation_, ((_w1) => {
|
|
3548
|
+
return _w1.second_
|
|
3549
|
+
})), ff_core_List.Link(selfArgument_, arguments_), _c.dictionaries_)
|
|
3550
|
+
return
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
}
|
|
3554
|
+
|
|
3555
|
+
export async function Inference_inferFunctionCall$(self_, environment_, expected_, signature_, instanceCall_, instantiation_, term_, name_, $task) {
|
|
3556
|
+
const e_ = (((_1) => {
|
|
3557
|
+
{
|
|
3558
|
+
if(_1.ECall) {
|
|
3559
|
+
const e_ = _1;
|
|
3560
|
+
return e_
|
|
3561
|
+
return
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
{
|
|
3565
|
+
return ff_compiler_Inference.fail_(term_.at_, "Call expected")
|
|
3566
|
+
return
|
|
3567
|
+
}
|
|
3568
|
+
}))(term_);
|
|
3569
|
+
const call_ = (((_1) => {
|
|
3570
|
+
{
|
|
3571
|
+
if(_1.DynamicCall) {
|
|
3572
|
+
const call_ = _1;
|
|
3573
|
+
return call_
|
|
3574
|
+
return
|
|
3575
|
+
}
|
|
3576
|
+
}
|
|
3577
|
+
{
|
|
3578
|
+
if(_1.StaticCall) {
|
|
3579
|
+
return ff_compiler_Inference.fail_(e_.at_, "Internal error: Static calls not expected in inferFunctionCall")
|
|
3580
|
+
return
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
}))(e_.target_);
|
|
3584
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, signature_.returnType_);
|
|
3585
|
+
const arguments_ = ff_compiler_Inference.Inference_inferArguments(self_, e_.at_, name_, environment_, signature_.parameters_, e_.arguments_);
|
|
3586
|
+
ff_compiler_Unification.Unification_affect(self_.unification_, term_.at_, signature_.effect_, environment_.effect_);
|
|
3587
|
+
{
|
|
3588
|
+
const _1 = e_;
|
|
3589
|
+
{
|
|
3590
|
+
const _c = _1;
|
|
3591
|
+
return ff_compiler_Syntax.ECall(_c.at_, ff_compiler_Syntax.StaticCall(name_, call_.tailCall_, instanceCall_), signature_.effect_, ff_core_List.List_map(instantiation_, ((_w1) => {
|
|
3592
|
+
return _w1.second_
|
|
3593
|
+
})), arguments_, _c.dictionaries_)
|
|
3594
|
+
return
|
|
3595
|
+
}
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
|
|
3599
|
+
export async function Inference_inferLambdaCall$(self_, environment_, expected_, term_, $task) {
|
|
3600
|
+
const e_ = (((_1) => {
|
|
3601
|
+
{
|
|
3602
|
+
if(_1.ECall) {
|
|
3603
|
+
const e_ = _1;
|
|
3604
|
+
return e_
|
|
3605
|
+
return
|
|
3606
|
+
}
|
|
3607
|
+
}
|
|
3608
|
+
{
|
|
3609
|
+
return ff_compiler_Inference.fail_(term_.at_, "Call expected")
|
|
3610
|
+
return
|
|
3611
|
+
}
|
|
3612
|
+
}))(term_);
|
|
3613
|
+
const call_ = (((_1) => {
|
|
3614
|
+
{
|
|
3615
|
+
if(_1.DynamicCall) {
|
|
3616
|
+
const call_ = _1;
|
|
3617
|
+
const _guard1 = (!call_.tailCall_);
|
|
3618
|
+
if(_guard1) {
|
|
3619
|
+
return call_
|
|
3620
|
+
return
|
|
3621
|
+
}
|
|
3622
|
+
}
|
|
3623
|
+
}
|
|
3624
|
+
{
|
|
3625
|
+
if(_1.DynamicCall) {
|
|
3626
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, "Tailcalls not supported on lambda functions"), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3627
|
+
return
|
|
3628
|
+
}
|
|
3629
|
+
}
|
|
3630
|
+
{
|
|
3631
|
+
if(_1.StaticCall) {
|
|
3632
|
+
return ff_compiler_Inference.fail_(e_.at_, "Internal error: Static calls not expected in inferLambdaCall")
|
|
3633
|
+
return
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
}))(e_.target_);
|
|
3637
|
+
const effect_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, term_.at_);
|
|
3638
|
+
const argumentTypes_ = ff_core_List.List_map(e_.arguments_, ((_w1) => {
|
|
3639
|
+
return ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, _w1.at_)
|
|
3640
|
+
}));
|
|
3641
|
+
const functionType_ = ff_compiler_Syntax.TConstructor(e_.at_, ("Function$" + ff_core_List.List_size(e_.arguments_)), ff_core_List.Link(effect_, ff_core_List.List_addAll(argumentTypes_, ff_core_List.Link(expected_, ff_core_List.Empty()))));
|
|
3642
|
+
const function_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, functionType_, call_.function_);
|
|
3643
|
+
const arguments_ = ff_core_List.List_map(ff_core_List.List_zip(e_.arguments_, argumentTypes_), ((_1) => {
|
|
3644
|
+
{
|
|
3645
|
+
const argument_ = _1.first_;
|
|
3646
|
+
const t_ = _1.second_;
|
|
3647
|
+
ff_core_Option.Option_each(argument_.name_, ((name_) => {
|
|
3648
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(argument_.at_, ("Named argument not allowed here: " + name_)), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3649
|
+
}));
|
|
3650
|
+
{
|
|
3651
|
+
const _1 = argument_;
|
|
3652
|
+
{
|
|
3653
|
+
const _c = _1;
|
|
3654
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, ff_compiler_Inference.Inference_inferTerm(self_, environment_, t_, argument_.value_))
|
|
3655
|
+
return
|
|
3656
|
+
}
|
|
3657
|
+
}
|
|
3658
|
+
return
|
|
3659
|
+
}
|
|
3660
|
+
}));
|
|
3661
|
+
ff_core_Option.Option_each(ff_core_List.List_first(e_.typeArguments_), ((typeArgument_) => {
|
|
3662
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(typeArgument_.at_, "Type arguments not allowed here"), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3663
|
+
}));
|
|
3664
|
+
ff_compiler_Unification.Unification_affect(self_.unification_, term_.at_, effect_, environment_.effect_);
|
|
3665
|
+
{
|
|
3666
|
+
const _1 = e_;
|
|
3667
|
+
{
|
|
3668
|
+
const _c = _1;
|
|
3669
|
+
return ff_compiler_Syntax.ECall(_c.at_, (((_c) => {
|
|
3670
|
+
return ff_compiler_Syntax.DynamicCall(function_, _c.tailCall_)
|
|
3671
|
+
}))(call_), effect_, ff_core_List.Empty(), arguments_, _c.dictionaries_)
|
|
3672
|
+
return
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
}
|
|
3676
|
+
|
|
3677
|
+
export async function Inference_inferOperator$(self_, environment_, expected_, operator_, term_, $task) {
|
|
3678
|
+
const e_ = (((_1) => {
|
|
3679
|
+
{
|
|
3680
|
+
if(_1.ECall) {
|
|
3681
|
+
const e_ = _1;
|
|
3682
|
+
return e_
|
|
3683
|
+
return
|
|
3684
|
+
}
|
|
3685
|
+
}
|
|
3686
|
+
{
|
|
3687
|
+
return ff_compiler_Inference.fail_(term_.at_, "Call expected")
|
|
3688
|
+
return
|
|
3689
|
+
}
|
|
3690
|
+
}))(term_);
|
|
3691
|
+
const target_ = ff_compiler_Syntax.StaticCall(operator_, false, false);
|
|
3692
|
+
{
|
|
3693
|
+
const _1 = e_.arguments_;
|
|
3694
|
+
{
|
|
3695
|
+
if(_1.Link) {
|
|
3696
|
+
const a1_ = _1.head_;
|
|
3697
|
+
if(_1.tail_.Empty) {
|
|
3698
|
+
const _guard1 = (operator_ === "!");
|
|
3699
|
+
if(_guard1) {
|
|
3700
|
+
const t_ = ff_compiler_Syntax.TConstructor(e_.at_, ff_compiler_Inference.core_("Bool"), ff_core_List.Empty());
|
|
3701
|
+
const e1_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t_, a1_.value_);
|
|
3702
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t_);
|
|
3703
|
+
{
|
|
3704
|
+
const _1 = e_;
|
|
3705
|
+
{
|
|
3706
|
+
const _c = _1;
|
|
3707
|
+
return ff_compiler_Syntax.ECall(_c.at_, target_, _c.effect_, _c.typeArguments_, ff_core_List.Link((((_c) => {
|
|
3708
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, e1_)
|
|
3709
|
+
}))(a1_), ff_core_List.Empty()), _c.dictionaries_)
|
|
3710
|
+
return
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3713
|
+
return
|
|
3714
|
+
}
|
|
3715
|
+
}
|
|
3716
|
+
}
|
|
3717
|
+
}
|
|
3718
|
+
{
|
|
3719
|
+
if(_1.Link) {
|
|
3720
|
+
const a1_ = _1.head_;
|
|
3721
|
+
if(_1.tail_.Empty) {
|
|
3722
|
+
const _guard1 = (operator_ === "-");
|
|
3723
|
+
if(_guard1) {
|
|
3724
|
+
const t1_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_);
|
|
3725
|
+
const e1_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t1_, a1_.value_);
|
|
3726
|
+
do {
|
|
3727
|
+
const _1 = ff_compiler_Unification.Unification_substitute(self_.unification_, t1_);
|
|
3728
|
+
{
|
|
3729
|
+
if(_1.TConstructor) {
|
|
3730
|
+
const name_ = _1.name_;
|
|
3731
|
+
if(_1.generics_.Empty) {
|
|
3732
|
+
const _guard1 = (name_ === ff_compiler_Inference.core_("Float"));
|
|
3733
|
+
if(_guard1) {
|
|
3734
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t1_)
|
|
3735
|
+
break
|
|
3736
|
+
}
|
|
3737
|
+
}
|
|
3738
|
+
}
|
|
3739
|
+
}
|
|
3740
|
+
{
|
|
3741
|
+
if(_1.TConstructor) {
|
|
3742
|
+
const name_ = _1.name_;
|
|
3743
|
+
if(_1.generics_.Empty) {
|
|
3744
|
+
const _guard1 = (name_ === ff_compiler_Inference.core_("Int"));
|
|
3745
|
+
if(_guard1) {
|
|
3746
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t1_)
|
|
3747
|
+
break
|
|
3748
|
+
}
|
|
3749
|
+
}
|
|
3750
|
+
}
|
|
3751
|
+
}
|
|
3752
|
+
{
|
|
3753
|
+
const _guard1 = ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_);
|
|
3754
|
+
if(_guard1) {
|
|
3755
|
+
|
|
3756
|
+
break
|
|
3757
|
+
}
|
|
3758
|
+
}
|
|
3759
|
+
{
|
|
3760
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, "Operators on unknown types not currently supported"), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3761
|
+
break
|
|
3762
|
+
}
|
|
3763
|
+
} while(false);
|
|
3764
|
+
{
|
|
3765
|
+
const _1 = e_;
|
|
3766
|
+
{
|
|
3767
|
+
const _c = _1;
|
|
3768
|
+
return ff_compiler_Syntax.ECall(_c.at_, target_, _c.effect_, _c.typeArguments_, ff_core_List.Link((((_c) => {
|
|
3769
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, e1_)
|
|
3770
|
+
}))(a1_), ff_core_List.Empty()), _c.dictionaries_)
|
|
3771
|
+
return
|
|
3772
|
+
}
|
|
3773
|
+
}
|
|
3774
|
+
return
|
|
3775
|
+
}
|
|
3776
|
+
}
|
|
3777
|
+
}
|
|
3778
|
+
}
|
|
3779
|
+
{
|
|
3780
|
+
if(_1.Link) {
|
|
3781
|
+
const a1_ = _1.head_;
|
|
3782
|
+
if(_1.tail_.Link) {
|
|
3783
|
+
const a2_ = _1.tail_.head_;
|
|
3784
|
+
if(_1.tail_.tail_.Empty) {
|
|
3785
|
+
const _guard1 = ((operator_ === "||") || (operator_ === "&&"));
|
|
3786
|
+
if(_guard1) {
|
|
3787
|
+
const t_ = ff_compiler_Syntax.TConstructor(e_.at_, ff_compiler_Inference.core_("Bool"), ff_core_List.Empty());
|
|
3788
|
+
const e1_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t_, a1_.value_);
|
|
3789
|
+
const e2_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t_, a2_.value_);
|
|
3790
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t_);
|
|
3791
|
+
{
|
|
3792
|
+
const _1 = e_;
|
|
3793
|
+
{
|
|
3794
|
+
const _c = _1;
|
|
3795
|
+
return ff_compiler_Syntax.ECall(_c.at_, target_, _c.effect_, _c.typeArguments_, ff_core_List.Link((((_c) => {
|
|
3796
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, e1_)
|
|
3797
|
+
}))(a1_), ff_core_List.Link((((_c) => {
|
|
3798
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, e2_)
|
|
3799
|
+
}))(a2_), ff_core_List.Empty())), _c.dictionaries_)
|
|
3800
|
+
return
|
|
3801
|
+
}
|
|
3802
|
+
}
|
|
3803
|
+
return
|
|
3804
|
+
}
|
|
3805
|
+
}
|
|
3806
|
+
}
|
|
3807
|
+
}
|
|
3808
|
+
}
|
|
3809
|
+
{
|
|
3810
|
+
if(_1.Link) {
|
|
3811
|
+
const a1_ = _1.head_;
|
|
3812
|
+
if(_1.tail_.Link) {
|
|
3813
|
+
const a2_ = _1.tail_.head_;
|
|
3814
|
+
if(_1.tail_.tail_.Empty) {
|
|
3815
|
+
const _guard1 = ((operator_ === "===") || (operator_ === "!=="));
|
|
3816
|
+
if(_guard1) {
|
|
3817
|
+
const t1_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_);
|
|
3818
|
+
const e1_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t1_, a1_.value_);
|
|
3819
|
+
const e2_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t1_, a2_.value_);
|
|
3820
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, ff_compiler_Syntax.TConstructor(e_.at_, ff_compiler_Inference.core_("Bool"), ff_core_List.Empty()));
|
|
3821
|
+
{
|
|
3822
|
+
const _1 = e_;
|
|
3823
|
+
{
|
|
3824
|
+
const _c = _1;
|
|
3825
|
+
return ff_compiler_Syntax.ECall(_c.at_, target_, _c.effect_, _c.typeArguments_, ff_core_List.Link((((_c) => {
|
|
3826
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, e1_)
|
|
3827
|
+
}))(a1_), ff_core_List.Link((((_c) => {
|
|
3828
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, e2_)
|
|
3829
|
+
}))(a2_), ff_core_List.Empty())), _c.dictionaries_)
|
|
3830
|
+
return
|
|
3831
|
+
}
|
|
3832
|
+
}
|
|
3833
|
+
return
|
|
3834
|
+
}
|
|
3835
|
+
}
|
|
3836
|
+
}
|
|
3837
|
+
}
|
|
3838
|
+
}
|
|
3839
|
+
{
|
|
3840
|
+
if(_1.Link) {
|
|
3841
|
+
const a1_ = _1.head_;
|
|
3842
|
+
if(_1.tail_.Link) {
|
|
3843
|
+
const a2_ = _1.tail_.head_;
|
|
3844
|
+
if(_1.tail_.tail_.Empty) {
|
|
3845
|
+
const _guard1 = ((((((operator_ === "+") || (operator_ === "-")) || (operator_ === "*")) || (operator_ === "/")) || (operator_ === "%")) || (operator_ === "^"));
|
|
3846
|
+
if(_guard1) {
|
|
3847
|
+
const t1_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_);
|
|
3848
|
+
const t2_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, e_.at_);
|
|
3849
|
+
const e1_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t1_, a1_.value_);
|
|
3850
|
+
const e2_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t2_, a2_.value_);
|
|
3851
|
+
const magic_ = ((t_) => {
|
|
3852
|
+
{
|
|
3853
|
+
const _1 = ff_compiler_Unification.Unification_substitute(self_.unification_, t_);
|
|
3854
|
+
{
|
|
3855
|
+
if(_1.TConstructor) {
|
|
3856
|
+
const name_ = _1.name_;
|
|
3857
|
+
if(_1.generics_.Empty) {
|
|
3858
|
+
const _guard1 = (name_ === ff_compiler_Inference.core_("Float"));
|
|
3859
|
+
if(_guard1) {
|
|
3860
|
+
return ff_core_Option.Some("Float")
|
|
3861
|
+
return
|
|
3862
|
+
}
|
|
3863
|
+
}
|
|
3864
|
+
}
|
|
3865
|
+
}
|
|
3866
|
+
{
|
|
3867
|
+
if(_1.TConstructor) {
|
|
3868
|
+
const name_ = _1.name_;
|
|
3869
|
+
if(_1.generics_.Empty) {
|
|
3870
|
+
const _guard1 = (name_ === ff_compiler_Inference.core_("Int"));
|
|
3871
|
+
if(_guard1) {
|
|
3872
|
+
return ff_core_Option.Some("Int")
|
|
3873
|
+
return
|
|
3874
|
+
}
|
|
3875
|
+
}
|
|
3876
|
+
}
|
|
3877
|
+
}
|
|
3878
|
+
{
|
|
3879
|
+
if(_1.TConstructor) {
|
|
3880
|
+
const name_ = _1.name_;
|
|
3881
|
+
if(_1.generics_.Empty) {
|
|
3882
|
+
const _guard1 = ((operator_ === "+") && (name_ === ff_compiler_Inference.core_("String")));
|
|
3883
|
+
if(_guard1) {
|
|
3884
|
+
return ff_core_Option.Some("String")
|
|
3885
|
+
return
|
|
3886
|
+
}
|
|
3887
|
+
}
|
|
3888
|
+
}
|
|
3889
|
+
}
|
|
3890
|
+
{
|
|
3891
|
+
return ff_core_Option.None()
|
|
3892
|
+
return
|
|
3893
|
+
}
|
|
3894
|
+
}
|
|
3895
|
+
});
|
|
3896
|
+
const chooseType_ = ((_1, _2) => {
|
|
3897
|
+
{
|
|
3898
|
+
if(_1.Some) {
|
|
3899
|
+
if(_1.value_ == "String") {
|
|
3900
|
+
if(_2.Some) {
|
|
3901
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t1_)
|
|
3902
|
+
return
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3905
|
+
}
|
|
3906
|
+
}
|
|
3907
|
+
{
|
|
3908
|
+
if(_1.Some) {
|
|
3909
|
+
if(_2.Some) {
|
|
3910
|
+
if(_2.value_ == "String") {
|
|
3911
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t2_)
|
|
3912
|
+
return
|
|
3913
|
+
}
|
|
3914
|
+
}
|
|
3915
|
+
}
|
|
3916
|
+
}
|
|
3917
|
+
{
|
|
3918
|
+
if(_1.Some) {
|
|
3919
|
+
if(_1.value_ == "Float") {
|
|
3920
|
+
if(_2.Some) {
|
|
3921
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t1_)
|
|
3922
|
+
return
|
|
3923
|
+
}
|
|
3924
|
+
}
|
|
3925
|
+
}
|
|
3926
|
+
}
|
|
3927
|
+
{
|
|
3928
|
+
if(_1.Some) {
|
|
3929
|
+
if(_2.Some) {
|
|
3930
|
+
if(_2.value_ == "Float") {
|
|
3931
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t2_)
|
|
3932
|
+
return
|
|
3933
|
+
}
|
|
3934
|
+
}
|
|
3935
|
+
}
|
|
3936
|
+
}
|
|
3937
|
+
{
|
|
3938
|
+
if(_1.Some) {
|
|
3939
|
+
if(_1.value_ == "Int") {
|
|
3940
|
+
if(_2.Some) {
|
|
3941
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t1_)
|
|
3942
|
+
return
|
|
3943
|
+
}
|
|
3944
|
+
}
|
|
3945
|
+
}
|
|
3946
|
+
}
|
|
3947
|
+
{
|
|
3948
|
+
if(_1.Some) {
|
|
3949
|
+
if(_2.Some) {
|
|
3950
|
+
if(_2.value_ == "Int") {
|
|
3951
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t2_)
|
|
3952
|
+
return
|
|
3953
|
+
}
|
|
3954
|
+
}
|
|
3955
|
+
}
|
|
3956
|
+
}
|
|
3957
|
+
{
|
|
3958
|
+
if(_1.Some) {
|
|
3959
|
+
if(_2.None) {
|
|
3960
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, t1_, t2_);
|
|
3961
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t1_)
|
|
3962
|
+
return
|
|
3963
|
+
}
|
|
3964
|
+
}
|
|
3965
|
+
}
|
|
3966
|
+
{
|
|
3967
|
+
if(_1.None) {
|
|
3968
|
+
if(_2.Some) {
|
|
3969
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, t2_, t1_);
|
|
3970
|
+
ff_compiler_Unification.Unification_unify(self_.unification_, e_.at_, expected_, t2_)
|
|
3971
|
+
return
|
|
3972
|
+
}
|
|
3973
|
+
}
|
|
3974
|
+
}
|
|
3975
|
+
{
|
|
3976
|
+
const _guard1 = ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_);
|
|
3977
|
+
if(_guard1) {
|
|
3978
|
+
|
|
3979
|
+
return
|
|
3980
|
+
}
|
|
3981
|
+
}
|
|
3982
|
+
{
|
|
3983
|
+
if(_1.Some) {
|
|
3984
|
+
if(_2.Some) {
|
|
3985
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, "Operators on these types not currently supported"), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3986
|
+
return
|
|
3987
|
+
}
|
|
3988
|
+
}
|
|
3989
|
+
}
|
|
3990
|
+
{
|
|
3991
|
+
if(_1.None) {
|
|
3992
|
+
if(_2.None) {
|
|
3993
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(e_.at_, "Operators on unknown types not currently supported"), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3994
|
+
return
|
|
3995
|
+
}
|
|
3996
|
+
}
|
|
3997
|
+
}
|
|
3998
|
+
});
|
|
3999
|
+
chooseType_(magic_(t1_), magic_(t2_));
|
|
4000
|
+
{
|
|
4001
|
+
const _1 = e_;
|
|
4002
|
+
{
|
|
4003
|
+
const _c = _1;
|
|
4004
|
+
return ff_compiler_Syntax.ECall(_c.at_, target_, _c.effect_, _c.typeArguments_, ff_core_List.Link((((_c) => {
|
|
4005
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, e1_)
|
|
4006
|
+
}))(a1_), ff_core_List.Link((((_c) => {
|
|
4007
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, e2_)
|
|
4008
|
+
}))(a2_), ff_core_List.Empty())), _c.dictionaries_)
|
|
4009
|
+
return
|
|
4010
|
+
}
|
|
4011
|
+
}
|
|
4012
|
+
return
|
|
4013
|
+
}
|
|
4014
|
+
}
|
|
4015
|
+
}
|
|
4016
|
+
}
|
|
4017
|
+
}
|
|
4018
|
+
{
|
|
4019
|
+
const _guard1 = ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_);
|
|
4020
|
+
if(_guard1) {
|
|
4021
|
+
return term_
|
|
4022
|
+
return
|
|
4023
|
+
}
|
|
4024
|
+
}
|
|
4025
|
+
{
|
|
4026
|
+
return ff_compiler_Inference.fail_(e_.at_, ("Unknown operator: " + operator_))
|
|
4027
|
+
return
|
|
4028
|
+
}
|
|
4029
|
+
}
|
|
4030
|
+
}
|
|
4031
|
+
|
|
4032
|
+
export async function Inference_inferEtaExpansion$(self_, environment_, expected_, at_, signature_, term_, $task) {
|
|
4033
|
+
const parameters_ = ff_core_List.List_map(ff_core_List.List_filter(signature_.parameters_, ((_w1) => {
|
|
4034
|
+
return ff_core_Option.Option_isEmpty(_w1.default_)
|
|
4035
|
+
})), ((p_) => {
|
|
4036
|
+
return p_.name_
|
|
4037
|
+
}));
|
|
4038
|
+
const effect1_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, at_);
|
|
4039
|
+
const body_ = ff_compiler_Syntax.ECall(at_, ff_compiler_Syntax.DynamicCall(term_, false), effect1_, ff_core_List.Empty(), ff_core_List.List_map(parameters_, ((x_) => {
|
|
4040
|
+
return ff_compiler_Syntax.Argument(at_, ff_core_Option.Some(x_), ff_compiler_Syntax.EVariable(at_, x_))
|
|
4041
|
+
})), ff_core_List.Empty());
|
|
4042
|
+
const effect2_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, at_);
|
|
4043
|
+
const lambda_ = ff_compiler_Syntax.ELambda(at_, ff_compiler_Syntax.Lambda(at_, effect2_, ff_core_List.Link(ff_compiler_Syntax.MatchCase(at_, ff_core_List.List_map(parameters_, ((_w1) => {
|
|
4044
|
+
return ff_compiler_Syntax.PVariable(at_, ff_core_Option.Some(_w1))
|
|
4045
|
+
})), ff_core_List.Empty(), body_), ff_core_List.Empty())));
|
|
4046
|
+
return ff_compiler_Inference.Inference_inferTerm(self_, (((_c) => {
|
|
4047
|
+
return ff_compiler_Environment.Environment(_c.modulePrefix_, _c.symbols_, _c.traits_, _c.imports_, effect2_, _c.selfVariable_)
|
|
4048
|
+
}))(environment_), expected_, lambda_)
|
|
4049
|
+
}
|
|
4050
|
+
|
|
4051
|
+
export async function Inference_inferArguments$(self_, callAt_, callName_, environment_, parameters_, arguments_, $task) {
|
|
4052
|
+
if(ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_)) {
|
|
4053
|
+
ff_core_List.List_each(ff_core_List.List_pairs(arguments_), ((_1) => {
|
|
4054
|
+
{
|
|
4055
|
+
const i_ = _1.first_;
|
|
4056
|
+
const a_ = _1.second_;
|
|
4057
|
+
const p_ = ff_core_List.List_find(parameters_, ((p_) => {
|
|
4058
|
+
return ff_core_Option.Option_any(a_.name_, ((_w1) => {
|
|
4059
|
+
return (_w1 === p_.name_)
|
|
4060
|
+
}))
|
|
4061
|
+
}));
|
|
4062
|
+
if((ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, a_.at_) || ff_core_Option.Option_any(p_, ((_w1) => {
|
|
4063
|
+
return ff_compiler_LspHook.LspHook_isDefinedAt(self_.lspHook_, _w1.at_)
|
|
4064
|
+
})))) {
|
|
4065
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, ff_compiler_LspHook.InferArgumentHook(self_.unification_, environment_, false, callAt_, callName_, parameters_, arguments_, i_))
|
|
4066
|
+
}
|
|
4067
|
+
return
|
|
4068
|
+
}
|
|
4069
|
+
}))
|
|
4070
|
+
};
|
|
4071
|
+
let remainingArguments_ = arguments_;
|
|
4072
|
+
const newArguments_ = ff_core_List.List_map(parameters_, ((p_) => {
|
|
4073
|
+
const t_ = p_.valueType_;
|
|
4074
|
+
function defaultArgument_() {
|
|
4075
|
+
return ff_core_Option.Option_else(ff_core_Option.Option_map(p_.default_, ((e_) => {
|
|
4076
|
+
const e2_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t_, e_);
|
|
4077
|
+
return ff_compiler_Syntax.Argument(callAt_, ff_core_Option.Some(p_.name_), e2_)
|
|
4078
|
+
})), (() => {
|
|
4079
|
+
if((!ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_))) {
|
|
4080
|
+
return ff_compiler_Inference.fail_(callAt_, ("Missing argument: " + p_.name_))
|
|
4081
|
+
} else {
|
|
4082
|
+
return ff_compiler_Syntax.Argument(callAt_, ff_core_Option.Some(p_.name_), ff_compiler_Syntax.EVariable(callAt_, ""))
|
|
4083
|
+
}
|
|
4084
|
+
}))
|
|
4085
|
+
}
|
|
4086
|
+
{
|
|
4087
|
+
const _1 = remainingArguments_;
|
|
4088
|
+
{
|
|
4089
|
+
if(_1.Empty) {
|
|
4090
|
+
return defaultArgument_()
|
|
4091
|
+
return
|
|
4092
|
+
}
|
|
4093
|
+
}
|
|
4094
|
+
{
|
|
4095
|
+
if(_1.Link) {
|
|
4096
|
+
const at_ = _1.head_.at_;
|
|
4097
|
+
if(_1.head_.name_.None) {
|
|
4098
|
+
const e_ = _1.head_.value_;
|
|
4099
|
+
const remaining_ = _1.tail_;
|
|
4100
|
+
remainingArguments_ = remaining_;
|
|
4101
|
+
const e2_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t_, e_);
|
|
4102
|
+
return ff_compiler_Syntax.Argument(at_, ff_core_Option.Some(p_.name_), e2_)
|
|
4103
|
+
return
|
|
4104
|
+
}
|
|
4105
|
+
}
|
|
4106
|
+
}
|
|
4107
|
+
{
|
|
4108
|
+
return ff_core_Option.Option_else(ff_core_Option.Option_map(ff_core_List.List_find(remainingArguments_, ((_w1) => {
|
|
4109
|
+
return ff_core_Option.Option_contains(_w1.name_, p_.name_, ff_core_Equal.ff_core_Equal_Equal$ff_core_String_String)
|
|
4110
|
+
})), ((_1) => {
|
|
4111
|
+
{
|
|
4112
|
+
const at_ = _1.at_;
|
|
4113
|
+
const e_ = _1.value_;
|
|
4114
|
+
remainingArguments_ = ff_core_List.List_filter(remainingArguments_, ((_w1) => {
|
|
4115
|
+
return (!ff_core_Option.Option_contains(_w1.name_, p_.name_, ff_core_Equal.ff_core_Equal_Equal$ff_core_String_String))
|
|
4116
|
+
}));
|
|
4117
|
+
const e2_ = ff_compiler_Inference.Inference_inferTerm(self_, environment_, t_, e_);
|
|
4118
|
+
return ff_compiler_Syntax.Argument(at_, ff_core_Option.Some(p_.name_), e2_)
|
|
4119
|
+
return
|
|
4120
|
+
}
|
|
4121
|
+
})), (() => {
|
|
4122
|
+
return defaultArgument_()
|
|
4123
|
+
}))
|
|
4124
|
+
return
|
|
4125
|
+
}
|
|
4126
|
+
}
|
|
4127
|
+
}));
|
|
4128
|
+
if((!ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_))) {
|
|
4129
|
+
ff_core_Option.Option_each(ff_core_List.List_first(remainingArguments_), ((_1) => {
|
|
4130
|
+
{
|
|
4131
|
+
const callAt_ = _1.at_;
|
|
4132
|
+
if(_1.name_.None) {
|
|
4133
|
+
ff_compiler_Inference.fail_(callAt_, "Too many arguments")
|
|
4134
|
+
return
|
|
4135
|
+
}
|
|
4136
|
+
}
|
|
4137
|
+
{
|
|
4138
|
+
const callAt_ = _1.at_;
|
|
4139
|
+
if(_1.name_.Some) {
|
|
4140
|
+
const n_ = _1.name_.value_;
|
|
4141
|
+
ff_compiler_Inference.fail_(callAt_, ("Unknown argument: " + n_))
|
|
4142
|
+
return
|
|
4143
|
+
}
|
|
4144
|
+
}
|
|
4145
|
+
}));
|
|
4146
|
+
return newArguments_
|
|
4147
|
+
} else {
|
|
4148
|
+
return ff_core_List.List_addAll(newArguments_, ff_core_List.List_map(remainingArguments_, ((a_) => {
|
|
4149
|
+
{
|
|
4150
|
+
const _1 = a_;
|
|
4151
|
+
{
|
|
4152
|
+
const _c = _1;
|
|
4153
|
+
return ff_compiler_Syntax.Argument(_c.at_, _c.name_, ff_compiler_Inference.Inference_inferTerm(self_, environment_, ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, a_.at_), a_.value_))
|
|
4154
|
+
return
|
|
4155
|
+
}
|
|
4156
|
+
}
|
|
4157
|
+
})))
|
|
4158
|
+
}
|
|
4159
|
+
}
|
|
4160
|
+
|
|
4161
|
+
export async function Inference_lookup$(self_, environment_, expected_, at_, symbol_, typeArguments_, arguments_, $task) {
|
|
4162
|
+
return ff_core_Option.Option_elseIf(ff_compiler_Inference.Inference_lookupOption(self_, environment_, expected_, at_, symbol_, typeArguments_), (() => {
|
|
4163
|
+
return ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_)
|
|
4164
|
+
}), (() => {
|
|
4165
|
+
const instantiated_ = ff_compiler_Environment.Instantiated(ff_core_List.Empty(), ff_compiler_Environment.Scheme(ff_core_Option.Option_isEmpty(arguments_), false, false, false, ff_compiler_Syntax.Signature(at_, symbol_, false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.List_map(ff_core_List.List_pairs(ff_core_List.List_flatten(ff_core_Option.Option_toList(arguments_))), ((_1) => {
|
|
4166
|
+
{
|
|
4167
|
+
const i_ = _1.first_;
|
|
4168
|
+
const a_ = _1.second_;
|
|
4169
|
+
const t_ = ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, at_);
|
|
4170
|
+
return ff_compiler_Syntax.Parameter(a_.at_, false, ff_core_Option.Option_else(a_.name_, (() => {
|
|
4171
|
+
return ("_p" + i_)
|
|
4172
|
+
})), t_, ff_core_Option.None())
|
|
4173
|
+
return
|
|
4174
|
+
}
|
|
4175
|
+
})), ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, at_), ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, at_))));
|
|
4176
|
+
if(((!ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, at_)) && (!ff_core_StringMap.StringMap_has(self_.missing_, symbol_)))) {
|
|
4177
|
+
ff_core_StringMap.StringMap_set(self_.missing_, symbol_, ff_core_Pair.Pair(instantiated_, arguments_))
|
|
4178
|
+
};
|
|
4179
|
+
return instantiated_
|
|
4180
|
+
}))
|
|
4181
|
+
}
|
|
4182
|
+
|
|
4183
|
+
export async function Inference_lookupOption$(self_, environment_, expected_, at_, symbol_, typeArguments_, $task) {
|
|
4184
|
+
const hook_ = (ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, at_)
|
|
4185
|
+
? ff_core_Option.Some((await (async function() {
|
|
4186
|
+
const symbolHook_ = ff_compiler_LspHook.SymbolHook(symbol_, at_, at_);
|
|
4187
|
+
const selfName_ = environment_.selfVariable_;
|
|
4188
|
+
const h_ = ff_compiler_LspHook.InferLookupHook(self_.unification_, environment_, expected_, selfName_, ff_compiler_LspHook.Box(symbolHook_), ff_compiler_LspHook.Box(ff_core_Option.None()));
|
|
4189
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, h_);
|
|
4190
|
+
return h_
|
|
4191
|
+
})()))
|
|
4192
|
+
: ff_core_Option.None());
|
|
4193
|
+
return ff_core_Option.Option_map(ff_core_Map.Map_get(environment_.symbols_, symbol_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String), ((scheme_) => {
|
|
4194
|
+
const instantiation_ = ((!ff_core_List.List_isEmpty(typeArguments_))
|
|
4195
|
+
? (function() {
|
|
4196
|
+
const newTypeArguments_ = (((!scheme_.isVariable_) && ff_core_Option.Option_any(ff_core_List.List_first(scheme_.signature_.generics_), ((_w1) => {
|
|
4197
|
+
return (_w1 === "Q$")
|
|
4198
|
+
})))
|
|
4199
|
+
? ff_core_List.Link(ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, at_), typeArguments_)
|
|
4200
|
+
: typeArguments_);
|
|
4201
|
+
if(((ff_core_List.List_size(scheme_.signature_.generics_) !== ff_core_List.List_size(newTypeArguments_)) && (!ff_compiler_LspHook.LspHook_isEnabled(self_.lspHook_)))) {
|
|
4202
|
+
const extra_ = (ff_core_List.List_size(newTypeArguments_) - ff_core_List.List_size(typeArguments_));
|
|
4203
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(at_, ((((("Wrong number of type arguments for " + symbol_) + ", expected ") + (ff_core_List.List_size(scheme_.signature_.generics_) - extra_)) + ", got ") + (ff_core_List.List_size(newTypeArguments_) - extra_))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
4204
|
+
};
|
|
4205
|
+
return ff_core_List.List_zip(scheme_.signature_.generics_, newTypeArguments_)
|
|
4206
|
+
})()
|
|
4207
|
+
: ff_core_List.List_map(scheme_.signature_.generics_, ((name_) => {
|
|
4208
|
+
return ff_core_Pair.Pair(name_, ff_compiler_Unification.Unification_freshUnificationVariable(self_.unification_, at_))
|
|
4209
|
+
})));
|
|
4210
|
+
const instantiationMap_ = ff_core_List.List_toMap(instantiation_, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
4211
|
+
const parameters_ = ff_core_List.List_map(scheme_.signature_.parameters_, ((p_) => {
|
|
4212
|
+
{
|
|
4213
|
+
const _1 = p_;
|
|
4214
|
+
{
|
|
4215
|
+
const _c = _1;
|
|
4216
|
+
return ff_compiler_Syntax.Parameter(_c.at_, _c.mutable_, _c.name_, ff_compiler_Unification.Unification_instantiate(self_.unification_, instantiationMap_, p_.valueType_), _c.default_)
|
|
4217
|
+
return
|
|
4218
|
+
}
|
|
4219
|
+
}
|
|
4220
|
+
}));
|
|
4221
|
+
const returnType_ = ff_compiler_Unification.Unification_instantiate(self_.unification_, instantiationMap_, scheme_.signature_.returnType_);
|
|
4222
|
+
const effect_ = ff_compiler_Unification.Unification_instantiate(self_.unification_, instantiationMap_, scheme_.signature_.effect_);
|
|
4223
|
+
ff_core_List.List_each(scheme_.signature_.constraints_, ((c_) => {
|
|
4224
|
+
const generics_ = ff_core_List.List_map(c_.generics_, ((_w1) => {
|
|
4225
|
+
return ff_compiler_Unification.Unification_instantiate(self_.unification_, instantiationMap_, _w1)
|
|
4226
|
+
}));
|
|
4227
|
+
ff_compiler_Unification.Unification_constrain(self_.unification_, at_, ff_core_List.List_grabFirst(generics_), c_.name_, ff_core_List.List_dropFirst(generics_, 1))
|
|
4228
|
+
}));
|
|
4229
|
+
const signature_ = (((_c) => {
|
|
4230
|
+
return ff_compiler_Syntax.Signature(_c.at_, _c.name_, _c.member_, ff_core_List.Empty(), ff_core_List.Empty(), parameters_, returnType_, effect_)
|
|
4231
|
+
}))(scheme_.signature_);
|
|
4232
|
+
const instantiated_ = ff_compiler_Environment.Instantiated(instantiation_, (((_c) => {
|
|
4233
|
+
return ff_compiler_Environment.Scheme(_c.isVariable_, _c.isMutable_, _c.isNewtype_, _c.isTraitMethod_, signature_)
|
|
4234
|
+
}))(scheme_));
|
|
4235
|
+
if((ff_compiler_LspHook.LspHook_isAt(self_.lspHook_, at_) || ff_compiler_LspHook.LspHook_isDefinedAt(self_.lspHook_, scheme_.signature_.at_))) {
|
|
4236
|
+
const symbolHook_ = ff_compiler_LspHook.SymbolHook(symbol_, at_, scheme_.signature_.at_);
|
|
4237
|
+
const emittedHook_ = (((_1) => {
|
|
4238
|
+
{
|
|
4239
|
+
if(_1.InferLookupHook) {
|
|
4240
|
+
const h_ = _1;
|
|
4241
|
+
h_.symbol_.value_ = symbolHook_;
|
|
4242
|
+
h_.instantiated_.value_ = ff_core_Option.Some(instantiated_)
|
|
4243
|
+
return
|
|
4244
|
+
}
|
|
4245
|
+
}
|
|
4246
|
+
{
|
|
4247
|
+
|
|
4248
|
+
return
|
|
4249
|
+
}
|
|
4250
|
+
}))(ff_core_Option.Option_else(hook_, (() => {
|
|
4251
|
+
const selfName_ = environment_.selfVariable_;
|
|
4252
|
+
const h_ = ff_compiler_LspHook.InferLookupHook(self_.unification_, environment_, expected_, selfName_, ff_compiler_LspHook.Box(symbolHook_), ff_compiler_LspHook.Box(ff_core_Option.None()));
|
|
4253
|
+
ff_compiler_LspHook.LspHook_emit(self_.lspHook_, h_);
|
|
4254
|
+
return h_
|
|
4255
|
+
})));
|
|
4256
|
+
|
|
4257
|
+
};
|
|
4258
|
+
return instantiated_
|
|
4259
|
+
}))
|
|
4260
|
+
}
|
|
4261
|
+
|
|
4262
|
+
|
|
4263
|
+
|
|
4264
|
+
|