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,1166 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import * as ff_compiler_Deriver from "../../ff/compiler/Deriver.mjs"
|
|
4
|
+
|
|
5
|
+
import * as ff_compiler_Syntax from "../../ff/compiler/Syntax.mjs"
|
|
6
|
+
|
|
7
|
+
import * as ff_core_Any from "../../ff/core/Any.mjs"
|
|
8
|
+
|
|
9
|
+
import * as ff_core_Array from "../../ff/core/Array.mjs"
|
|
10
|
+
|
|
11
|
+
import * as ff_core_AssetSystem from "../../ff/core/AssetSystem.mjs"
|
|
12
|
+
|
|
13
|
+
import * as ff_core_Atomic from "../../ff/core/Atomic.mjs"
|
|
14
|
+
|
|
15
|
+
import * as ff_core_Bool from "../../ff/core/Bool.mjs"
|
|
16
|
+
|
|
17
|
+
import * as ff_core_BrowserSystem from "../../ff/core/BrowserSystem.mjs"
|
|
18
|
+
|
|
19
|
+
import * as ff_core_Buffer from "../../ff/core/Buffer.mjs"
|
|
20
|
+
|
|
21
|
+
import * as ff_core_BuildSystem from "../../ff/core/BuildSystem.mjs"
|
|
22
|
+
|
|
23
|
+
import * as ff_core_Channel from "../../ff/core/Channel.mjs"
|
|
24
|
+
|
|
25
|
+
import * as ff_core_Char from "../../ff/core/Char.mjs"
|
|
26
|
+
|
|
27
|
+
import * as ff_core_Core from "../../ff/core/Core.mjs"
|
|
28
|
+
|
|
29
|
+
import * as ff_core_Duration from "../../ff/core/Duration.mjs"
|
|
30
|
+
|
|
31
|
+
import * as ff_core_Equal from "../../ff/core/Equal.mjs"
|
|
32
|
+
|
|
33
|
+
import * as ff_core_Error from "../../ff/core/Error.mjs"
|
|
34
|
+
|
|
35
|
+
import * as ff_core_FileHandle from "../../ff/core/FileHandle.mjs"
|
|
36
|
+
|
|
37
|
+
import * as ff_core_Float from "../../ff/core/Float.mjs"
|
|
38
|
+
|
|
39
|
+
import * as ff_core_HttpClient from "../../ff/core/HttpClient.mjs"
|
|
40
|
+
|
|
41
|
+
import * as ff_core_Instant from "../../ff/core/Instant.mjs"
|
|
42
|
+
|
|
43
|
+
import * as ff_core_Int from "../../ff/core/Int.mjs"
|
|
44
|
+
|
|
45
|
+
import * as ff_core_IntMap from "../../ff/core/IntMap.mjs"
|
|
46
|
+
|
|
47
|
+
import * as ff_core_JsSystem from "../../ff/core/JsSystem.mjs"
|
|
48
|
+
|
|
49
|
+
import * as ff_core_JsValue from "../../ff/core/JsValue.mjs"
|
|
50
|
+
|
|
51
|
+
import * as ff_core_List from "../../ff/core/List.mjs"
|
|
52
|
+
|
|
53
|
+
import * as ff_core_Lock from "../../ff/core/Lock.mjs"
|
|
54
|
+
|
|
55
|
+
import * as ff_core_Log from "../../ff/core/Log.mjs"
|
|
56
|
+
|
|
57
|
+
import * as ff_core_Map from "../../ff/core/Map.mjs"
|
|
58
|
+
|
|
59
|
+
import * as ff_core_NodeSystem from "../../ff/core/NodeSystem.mjs"
|
|
60
|
+
|
|
61
|
+
import * as ff_core_Nothing from "../../ff/core/Nothing.mjs"
|
|
62
|
+
|
|
63
|
+
import * as ff_core_Option from "../../ff/core/Option.mjs"
|
|
64
|
+
|
|
65
|
+
import * as ff_core_Ordering from "../../ff/core/Ordering.mjs"
|
|
66
|
+
|
|
67
|
+
import * as ff_core_Pair from "../../ff/core/Pair.mjs"
|
|
68
|
+
|
|
69
|
+
import * as ff_core_Path from "../../ff/core/Path.mjs"
|
|
70
|
+
|
|
71
|
+
import * as ff_core_Serializable from "../../ff/core/Serializable.mjs"
|
|
72
|
+
|
|
73
|
+
import * as ff_core_Set from "../../ff/core/Set.mjs"
|
|
74
|
+
|
|
75
|
+
import * as ff_core_Show from "../../ff/core/Show.mjs"
|
|
76
|
+
|
|
77
|
+
import * as ff_core_Stack from "../../ff/core/Stack.mjs"
|
|
78
|
+
|
|
79
|
+
import * as ff_core_Stream from "../../ff/core/Stream.mjs"
|
|
80
|
+
|
|
81
|
+
import * as ff_core_String from "../../ff/core/String.mjs"
|
|
82
|
+
|
|
83
|
+
import * as ff_core_StringMap from "../../ff/core/StringMap.mjs"
|
|
84
|
+
|
|
85
|
+
import * as ff_core_Task from "../../ff/core/Task.mjs"
|
|
86
|
+
|
|
87
|
+
import * as ff_core_Try from "../../ff/core/Try.mjs"
|
|
88
|
+
|
|
89
|
+
import * as ff_core_Unit from "../../ff/core/Unit.mjs"
|
|
90
|
+
|
|
91
|
+
// type Deriver
|
|
92
|
+
const Deriver$ = {Deriver: true};
|
|
93
|
+
export function Deriver() {
|
|
94
|
+
return Deriver$;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
export function make_() {
|
|
100
|
+
return ff_compiler_Deriver.Deriver()
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function fail_(at_, message_) {
|
|
104
|
+
return ff_core_Core.panic_(((message_ + " ") + ff_compiler_Syntax.Location_show(at_)))
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export async function make_$($task) {
|
|
108
|
+
return ff_compiler_Deriver.Deriver()
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export async function fail_$(at_, message_, $task) {
|
|
112
|
+
return ff_core_Core.panic_(((message_ + " ") + ff_compiler_Syntax.Location_show(at_)))
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function Deriver_deriveModule(self_, module_) {
|
|
116
|
+
const modulePrefix_ = ((ff_compiler_Syntax.PackagePair_groupName(module_.packagePair_, ":") + "/") + ff_core_String.String_dropLast(module_.file_, 3));
|
|
117
|
+
{
|
|
118
|
+
const _1 = module_;
|
|
119
|
+
{
|
|
120
|
+
const _c = _1;
|
|
121
|
+
return ff_compiler_Syntax.Module(_c.file_, _c.packagePair_, _c.imports_, _c.types_, _c.traits_, ff_core_List.List_addAll(module_.instances_, ff_core_List.List_addAll(ff_compiler_Deriver.Deriver_makeHasAnyTagInstances(self_, modulePrefix_, module_), ff_core_List.List_addAll(ff_compiler_Deriver.Deriver_makeShowInstances(self_, modulePrefix_, module_), ff_core_List.List_addAll(ff_compiler_Deriver.Deriver_makeEqualInstances(self_, modulePrefix_, module_), ff_core_List.List_addAll(ff_compiler_Deriver.Deriver_makeOrderingInstances(self_, modulePrefix_, module_), ff_compiler_Deriver.Deriver_makeSerializableInstances(self_, modulePrefix_, module_)))))), _c.extends_, _c.lets_, _c.functions_)
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function Deriver_makeHasAnyTagInstances(self_, modulePrefix_, module_) {
|
|
128
|
+
const coreWhitelist_ = ff_core_List.List_toSet(ff_core_List.Link("ff:core/Serializable.DeserializationChecksumException", ff_core_List.Link("ff:core/Core.GrabException", ff_core_List.Empty())), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
129
|
+
const missingInstance_ = ff_compiler_Deriver.Deriver_findTypesThatNeedInstances(self_, "ff:core/Any.HasAnyTag", modulePrefix_, coreWhitelist_, true, module_);
|
|
130
|
+
return ff_core_List.List_map(missingInstance_, ((_w1) => {
|
|
131
|
+
return ff_compiler_Deriver.Deriver_makeHasAnyTagInstance(self_, modulePrefix_, _w1)
|
|
132
|
+
}))
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function Deriver_makeHasAnyTagInstance(self_, modulePrefix_, declaration_) {
|
|
136
|
+
const at_ = (((_c) => {
|
|
137
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
138
|
+
}))(declaration_.at_);
|
|
139
|
+
const constraints_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
140
|
+
return ff_compiler_Syntax.Constraint(at_, "ff:core/Any.HasAnyTag", ff_core_List.Link(ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty()), ff_core_List.Empty()))
|
|
141
|
+
}));
|
|
142
|
+
const typeArguments_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
143
|
+
return ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty())
|
|
144
|
+
}));
|
|
145
|
+
const selfTypeName_ = ((modulePrefix_ + ".") + declaration_.name_);
|
|
146
|
+
const selfType_ = ff_compiler_Syntax.TConstructor(at_, selfTypeName_, typeArguments_);
|
|
147
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
148
|
+
const signature_ = ff_compiler_Syntax.Signature(at_, "anyTag", false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Empty(), ff_compiler_Syntax.TConstructor(at_, "ff:core/Any.AnyTag", ff_core_List.Link(selfType_, ff_core_List.Empty())), noEffect_);
|
|
149
|
+
const typeArgumentStrings_ = ff_core_List.List_map(typeArguments_, ((_w1) => {
|
|
150
|
+
return ff_compiler_Deriver.Deriver_makeMethodCall(self_, at_, ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Any.anyTag", ff_core_List.Empty(), ff_core_List.Link(_w1, ff_core_List.Empty())), "show", ff_core_List.Empty())
|
|
151
|
+
}));
|
|
152
|
+
const strings_ = ff_core_List.Link(ff_compiler_Syntax.EString(at_, "\"[\""), ff_core_List.List_addAll(ff_core_List.List_insertBetween(typeArgumentStrings_, ff_core_List.Link(ff_compiler_Syntax.EString(at_, "\",\""), ff_core_List.Empty())), ff_core_List.Link(ff_compiler_Syntax.EString(at_, "\"]\""), ff_core_List.Empty())));
|
|
153
|
+
const body_ = ff_compiler_Syntax.FireflyTarget(ff_compiler_Syntax.Lambda(at_, noEffect_, ff_core_List.Link(ff_compiler_Syntax.MatchCase(at_, ff_core_List.Empty(), ff_core_List.Empty(), ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Any.internalAnyTag", ff_core_List.Link(ff_core_List.List_foldLeft(strings_, ff_compiler_Syntax.EString(at_, (("\"" + selfTypeName_) + "\"")), ((a_, b_) => {
|
|
154
|
+
return ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "+", ff_core_List.Link(a_, ff_core_List.Link(b_, ff_core_List.Empty())), ff_core_List.Empty())
|
|
155
|
+
})), ff_core_List.Empty()), ff_core_List.Empty())), ff_core_List.Empty())));
|
|
156
|
+
const method_ = ff_compiler_Syntax.DFunction(at_, signature_, body_);
|
|
157
|
+
return ff_compiler_Syntax.DInstance(at_, declaration_.generics_, constraints_, "ff:core/Any.HasAnyTag", ff_core_List.Link(selfType_, ff_core_List.Empty()), ff_core_List.Empty(), ff_core_List.Link(method_, ff_core_List.Empty()), true)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function Deriver_makeShowInstances(self_, modulePrefix_, module_) {
|
|
161
|
+
const coreWhitelist_ = ff_core_List.List_toSet(ff_core_List.Link("ff:core/Option.Option", ff_core_List.Empty()), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
162
|
+
const missingInstance_ = ff_compiler_Deriver.Deriver_findTypesThatNeedInstances(self_, "ff:core/Show.Show", modulePrefix_, coreWhitelist_, true, module_);
|
|
163
|
+
return ff_core_List.List_map(missingInstance_, ((_w1) => {
|
|
164
|
+
return ff_compiler_Deriver.Deriver_makeShowInstance(self_, modulePrefix_, _w1)
|
|
165
|
+
}))
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function Deriver_makeShowInstance(self_, modulePrefix_, declaration_) {
|
|
169
|
+
const at_ = (((_c) => {
|
|
170
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
171
|
+
}))(declaration_.at_);
|
|
172
|
+
const constraints_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
173
|
+
return ff_compiler_Syntax.Constraint(at_, "ff:core/Show.Show", ff_core_List.Link(ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty()), ff_core_List.Empty()))
|
|
174
|
+
}));
|
|
175
|
+
const typeArguments_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
176
|
+
return ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty())
|
|
177
|
+
}));
|
|
178
|
+
const selfType_ = ff_compiler_Syntax.TConstructor(at_, ((modulePrefix_ + ".") + declaration_.name_), typeArguments_);
|
|
179
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
180
|
+
const signature_ = ff_compiler_Syntax.Signature(at_, "show", false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Link(ff_compiler_Syntax.Parameter(at_, false, "value", selfType_, ff_core_Option.None()), ff_core_List.Empty()), ff_compiler_Syntax.TConstructor(at_, "ff:core/String.String", ff_core_List.Empty()), noEffect_);
|
|
181
|
+
const body_ = ff_compiler_Syntax.FireflyTarget(ff_compiler_Syntax.Lambda(at_, noEffect_, ff_compiler_Deriver.Deriver_makeShowCases(self_, modulePrefix_, declaration_, selfType_)));
|
|
182
|
+
const showMethod_ = ff_compiler_Syntax.DFunction(at_, signature_, body_);
|
|
183
|
+
return ff_compiler_Syntax.DInstance(at_, declaration_.generics_, constraints_, "ff:core/Show.Show", ff_core_List.Link(selfType_, ff_core_List.Empty()), ff_core_List.Empty(), ff_core_List.Link(showMethod_, ff_core_List.Empty()), true)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function Deriver_makeShowCases(self_, modulePrefix_, declaration_, selfType_) {
|
|
187
|
+
const at_ = (((_c) => {
|
|
188
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
189
|
+
}))(declaration_.at_);
|
|
190
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
191
|
+
const wildcardPattern_ = ff_compiler_Syntax.PVariable(at_, ff_core_Option.None());
|
|
192
|
+
{
|
|
193
|
+
const _1 = declaration_.variants_;
|
|
194
|
+
{
|
|
195
|
+
const variants_ = _1;
|
|
196
|
+
return ff_core_List.List_map(variants_, ((variant_) => {
|
|
197
|
+
const variantName_ = ((modulePrefix_ + ".") + variant_.name_);
|
|
198
|
+
const fields_ = ff_core_List.List_addAll(declaration_.commonFields_, variant_.fields_);
|
|
199
|
+
const strings_ = ((ff_core_List.List_size(fields_) === 0)
|
|
200
|
+
? ff_core_List.Empty()
|
|
201
|
+
: ff_core_List.Link(ff_compiler_Syntax.EString(at_, "\"(\""), ff_core_List.List_addAll(ff_core_List.List_insertBetween(ff_core_List.List_map(fields_, ((field_) => {
|
|
202
|
+
return ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Show.show", ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "z"), field_.name_), ff_core_List.Empty()), ff_core_List.Empty())
|
|
203
|
+
})), ff_core_List.Link(ff_compiler_Syntax.EString(at_, "\", \""), ff_core_List.Empty())), ff_core_List.Link(ff_compiler_Syntax.EString(at_, "\")\""), ff_core_List.Empty()))));
|
|
204
|
+
return ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(ff_compiler_Syntax.PVariantAs(at_, variantName_, at_, ff_core_Option.Some("z")), ff_core_List.Empty()), ff_core_List.Empty(), ff_core_List.List_foldLeft(strings_, ff_compiler_Syntax.EString(at_, (("\"" + variant_.name_) + "\"")), ((a_, b_) => {
|
|
205
|
+
return ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "+", ff_core_List.Link(a_, ff_core_List.Link(b_, ff_core_List.Empty())), ff_core_List.Empty())
|
|
206
|
+
})))
|
|
207
|
+
}))
|
|
208
|
+
return
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export function Deriver_makeOrderingInstances(self_, modulePrefix_, module_) {
|
|
214
|
+
const coreWhitelist_ = ff_core_List.List_toSet(ff_core_List.Link("ff:core/Option.Option", ff_core_List.Empty()), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
215
|
+
const missingInstance_ = ff_compiler_Deriver.Deriver_findTypesThatNeedInstances(self_, "ff:core/Ordering.Order", modulePrefix_, coreWhitelist_, true, module_);
|
|
216
|
+
return ff_core_List.List_map(missingInstance_, ((_w1) => {
|
|
217
|
+
return ff_compiler_Deriver.Deriver_makeOrderingInstance(self_, modulePrefix_, _w1)
|
|
218
|
+
}))
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export function Deriver_makeOrderingInstance(self_, modulePrefix_, declaration_) {
|
|
222
|
+
const at_ = (((_c) => {
|
|
223
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
224
|
+
}))(declaration_.at_);
|
|
225
|
+
const constraints_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
226
|
+
return ff_compiler_Syntax.Constraint(at_, "ff:core/Ordering.Order", ff_core_List.Link(ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty()), ff_core_List.Empty()))
|
|
227
|
+
}));
|
|
228
|
+
const typeArguments_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
229
|
+
return ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty())
|
|
230
|
+
}));
|
|
231
|
+
const selfType_ = ff_compiler_Syntax.TConstructor(at_, ((modulePrefix_ + ".") + declaration_.name_), typeArguments_);
|
|
232
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
233
|
+
const signature_ = ff_compiler_Syntax.Signature(at_, "compare", false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Link(ff_compiler_Syntax.Parameter(at_, false, "x", selfType_, ff_core_Option.None()), ff_core_List.Link(ff_compiler_Syntax.Parameter(at_, false, "y", selfType_, ff_core_Option.None()), ff_core_List.Empty())), ff_compiler_Syntax.TConstructor(at_, "ff:core/Ordering.Ordering", ff_core_List.Empty()), noEffect_);
|
|
234
|
+
const body_ = ff_compiler_Syntax.FireflyTarget(ff_compiler_Syntax.Lambda(at_, noEffect_, ff_compiler_Deriver.Deriver_makeOrderingCases(self_, modulePrefix_, declaration_, selfType_)));
|
|
235
|
+
const compareMethod_ = ff_compiler_Syntax.DFunction(at_, signature_, body_);
|
|
236
|
+
return ff_compiler_Syntax.DInstance(at_, declaration_.generics_, constraints_, "ff:core/Ordering.Order", ff_core_List.Link(selfType_, ff_core_List.Empty()), ff_core_List.Empty(), ff_core_List.Link(compareMethod_, ff_core_List.Empty()), true)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function Deriver_makeOrderingCases(self_, modulePrefix_, declaration_, selfType_) {
|
|
240
|
+
const at_ = (((_c) => {
|
|
241
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
242
|
+
}))(declaration_.at_);
|
|
243
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
244
|
+
const wildcardPattern_ = ff_compiler_Syntax.PVariable(at_, ff_core_Option.None());
|
|
245
|
+
const sameCase_ = ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(wildcardPattern_, ff_core_List.Link(wildcardPattern_, ff_core_List.Empty())), ff_core_List.Link(ff_compiler_Syntax.MatchGuard(at_, ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "===", ff_core_List.Link(ff_compiler_Syntax.EVariable(at_, "x"), ff_core_List.Link(ff_compiler_Syntax.EVariable(at_, "y"), ff_core_List.Empty())), ff_core_List.Empty()), ff_compiler_Syntax.PVariant(at_, "ff:core/Bool.True", ff_core_List.Empty())), ff_core_List.Empty()), ff_compiler_Syntax.EVariant(at_, "ff:core/Ordering.OrderingSame", ff_core_List.Empty(), ff_core_Option.None()));
|
|
246
|
+
{
|
|
247
|
+
const _1 = declaration_.variants_;
|
|
248
|
+
{
|
|
249
|
+
if(_1.Link) {
|
|
250
|
+
const variant_ = _1.head_;
|
|
251
|
+
if(_1.tail_.Empty) {
|
|
252
|
+
const fields_ = ff_core_List.List_addAll(declaration_.commonFields_, variant_.fields_);
|
|
253
|
+
return ff_core_List.Link(sameCase_, ff_core_List.Link(ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(wildcardPattern_, ff_core_List.Link(wildcardPattern_, ff_core_List.Empty())), ff_core_List.Empty(), ff_compiler_Deriver.Deriver_makeOrderingFields(self_, modulePrefix_, declaration_, fields_)), ff_core_List.Empty()))
|
|
254
|
+
return
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
{
|
|
259
|
+
const variants_ = _1;
|
|
260
|
+
const variantsWithFields_ = ff_core_List.List_filter(variants_, ((variant_) => {
|
|
261
|
+
return ((!ff_core_List.List_isEmpty(declaration_.commonFields_)) || (!ff_core_List.List_isEmpty(variant_.fields_)))
|
|
262
|
+
}));
|
|
263
|
+
const sameVariantCases_ = ff_core_List.List_map(variantsWithFields_, ((variant_) => {
|
|
264
|
+
const variantName_ = ((modulePrefix_ + ".") + variant_.name_);
|
|
265
|
+
const fields_ = ff_core_List.List_addAll(declaration_.commonFields_, variant_.fields_);
|
|
266
|
+
return ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(ff_compiler_Syntax.PVariantAs(at_, variantName_, at_, ff_core_Option.Some("x")), ff_core_List.Link(ff_compiler_Syntax.PVariantAs(at_, variantName_, at_, ff_core_Option.Some("y")), ff_core_List.Empty())), ff_core_List.Empty(), ff_compiler_Deriver.Deriver_makeOrderingFields(self_, modulePrefix_, declaration_, fields_))
|
|
267
|
+
}));
|
|
268
|
+
const intType_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Int.Int", ff_core_List.Empty());
|
|
269
|
+
const numberSignature_ = ff_compiler_Syntax.Signature(at_, "number", false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Link(ff_compiler_Syntax.Parameter(at_, false, "z", selfType_, ff_core_Option.None()), ff_core_List.Empty()), intType_, noEffect_);
|
|
270
|
+
const numberCases_ = ff_core_List.List_map(ff_core_List.List_pairs(declaration_.variants_), ((_1) => {
|
|
271
|
+
{
|
|
272
|
+
const index_ = _1.first_;
|
|
273
|
+
const variant_ = _1.second_;
|
|
274
|
+
const variantName_ = ((modulePrefix_ + ".") + variant_.name_);
|
|
275
|
+
return ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(ff_compiler_Syntax.PVariantAs(at_, variantName_, at_, ff_core_Option.None()), ff_core_List.Empty()), ff_core_List.Empty(), ff_compiler_Syntax.EInt(at_, ("" + index_)))
|
|
276
|
+
return
|
|
277
|
+
}
|
|
278
|
+
}));
|
|
279
|
+
const differentVariant_ = ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(wildcardPattern_, ff_core_List.Link(wildcardPattern_, ff_core_List.Empty())), ff_core_List.Empty(), ff_compiler_Syntax.EFunctions(at_, ff_core_List.Link(ff_compiler_Syntax.DFunction(at_, numberSignature_, ff_compiler_Syntax.FireflyTarget(ff_compiler_Syntax.Lambda(at_, noEffect_, numberCases_))), ff_core_List.Empty()), ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Ordering.compare", ff_core_List.Link(ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "number", ff_core_List.Link(ff_compiler_Syntax.EVariable(at_, "x"), ff_core_List.Empty()), ff_core_List.Empty()), ff_core_List.Link(ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "number", ff_core_List.Link(ff_compiler_Syntax.EVariable(at_, "y"), ff_core_List.Empty()), ff_core_List.Empty()), ff_core_List.Empty())), ff_core_List.Empty())));
|
|
280
|
+
return ff_core_List.Link(sameCase_, ff_core_List.List_addAll(sameVariantCases_, ff_core_List.Link(differentVariant_, ff_core_List.Empty())))
|
|
281
|
+
return
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function Deriver_makeOrderingFields(self_, modulePrefix_, declaration_, fields_) {
|
|
287
|
+
const at_ = (((_c) => {
|
|
288
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
289
|
+
}))(declaration_.at_);
|
|
290
|
+
const orderingType_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Ordering.Ordering", ff_core_List.Empty());
|
|
291
|
+
const orderingSame_ = ff_compiler_Syntax.EVariant(at_, "ff:core/Ordering.OrderingSame", ff_core_List.Empty(), ff_core_Option.None());
|
|
292
|
+
function go_(fields_) {
|
|
293
|
+
{
|
|
294
|
+
const fields_a = fields_;
|
|
295
|
+
{
|
|
296
|
+
if(fields_a.Empty) {
|
|
297
|
+
return orderingSame_
|
|
298
|
+
return
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
{
|
|
302
|
+
if(fields_a.Link) {
|
|
303
|
+
const head_ = fields_a.head_;
|
|
304
|
+
const tail_ = fields_a.tail_;
|
|
305
|
+
const variableName_ = (head_.name_ + "Ordering");
|
|
306
|
+
const compareTerm_ = ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Ordering.compare", ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "x"), head_.name_), ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "y"), head_.name_), ff_core_List.Empty())), ff_core_List.Empty());
|
|
307
|
+
const notEqualTerm_ = ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "!==", ff_core_List.Link(ff_compiler_Syntax.EVariable(at_, variableName_), ff_core_List.Link(orderingSame_, ff_core_List.Empty())), ff_core_List.Empty());
|
|
308
|
+
const ifTerm_ = ff_compiler_Deriver.Deriver_makeIf(self_, at_, notEqualTerm_, ff_compiler_Syntax.EVariable(at_, variableName_), go_(tail_));
|
|
309
|
+
return ff_compiler_Syntax.ELet(at_, false, variableName_, orderingType_, compareTerm_, ifTerm_)
|
|
310
|
+
return
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return go_(fields_)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export function Deriver_makeEqualInstances(self_, modulePrefix_, module_) {
|
|
319
|
+
const coreWhitelist_ = ff_core_List.List_toSet(ff_core_List.Link("ff:core/Option.Option", ff_core_List.Link("ff:core/List.List", ff_core_List.Link("ff:core/Pair.Pair", ff_core_List.Empty()))), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
320
|
+
const missingInstance_ = ff_compiler_Deriver.Deriver_findTypesThatNeedInstances(self_, "ff:core/Equal.Equal", modulePrefix_, coreWhitelist_, true, module_);
|
|
321
|
+
return ff_core_List.List_map(missingInstance_, ((_w1) => {
|
|
322
|
+
return ff_compiler_Deriver.Deriver_makeEqualInstance(self_, modulePrefix_, _w1)
|
|
323
|
+
}))
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export function Deriver_makeEqualInstance(self_, modulePrefix_, declaration_) {
|
|
327
|
+
const at_ = (((_c) => {
|
|
328
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
329
|
+
}))(declaration_.at_);
|
|
330
|
+
const constraints_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
331
|
+
return ff_compiler_Syntax.Constraint(at_, "ff:core/Equal.Equal", ff_core_List.Link(ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty()), ff_core_List.Empty()))
|
|
332
|
+
}));
|
|
333
|
+
const typeArguments_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
334
|
+
return ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty())
|
|
335
|
+
}));
|
|
336
|
+
const selfType_ = ff_compiler_Syntax.TConstructor(at_, ((modulePrefix_ + ".") + declaration_.name_), typeArguments_);
|
|
337
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
338
|
+
const signature_ = ff_compiler_Syntax.Signature(at_, "equals", false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Link(ff_compiler_Syntax.Parameter(at_, false, "x", selfType_, ff_core_Option.None()), ff_core_List.Link(ff_compiler_Syntax.Parameter(at_, false, "y", selfType_, ff_core_Option.None()), ff_core_List.Empty())), ff_compiler_Syntax.TConstructor(at_, "ff:core/Bool.Bool", ff_core_List.Empty()), noEffect_);
|
|
339
|
+
const body_ = ff_compiler_Syntax.FireflyTarget(ff_compiler_Syntax.Lambda(at_, noEffect_, ff_compiler_Deriver.Deriver_makeEqualsCases(self_, modulePrefix_, declaration_, selfType_)));
|
|
340
|
+
const equalsMethod_ = ff_compiler_Syntax.DFunction(at_, signature_, body_);
|
|
341
|
+
return ff_compiler_Syntax.DInstance(at_, declaration_.generics_, constraints_, "ff:core/Equal.Equal", ff_core_List.Link(selfType_, ff_core_List.Empty()), ff_core_List.Empty(), ff_core_List.Link(equalsMethod_, ff_core_List.Empty()), true)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export function Deriver_makeEqualsCases(self_, modulePrefix_, declaration_, selfType_) {
|
|
345
|
+
const at_ = (((_c) => {
|
|
346
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
347
|
+
}))(declaration_.at_);
|
|
348
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
349
|
+
const wildcardPattern_ = ff_compiler_Syntax.PVariable(at_, ff_core_Option.None());
|
|
350
|
+
const sameCase_ = ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(wildcardPattern_, ff_core_List.Link(wildcardPattern_, ff_core_List.Empty())), ff_core_List.Link(ff_compiler_Syntax.MatchGuard(at_, ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "===", ff_core_List.Link(ff_compiler_Syntax.EVariable(at_, "x"), ff_core_List.Link(ff_compiler_Syntax.EVariable(at_, "y"), ff_core_List.Empty())), ff_core_List.Empty()), ff_compiler_Syntax.PVariant(at_, "ff:core/Bool.True", ff_core_List.Empty())), ff_core_List.Empty()), ff_compiler_Syntax.EVariant(at_, "ff:core/Bool.True", ff_core_List.Empty(), ff_core_Option.None()));
|
|
351
|
+
{
|
|
352
|
+
const _1 = declaration_.variants_;
|
|
353
|
+
{
|
|
354
|
+
if(_1.Link) {
|
|
355
|
+
const variant_ = _1.head_;
|
|
356
|
+
if(_1.tail_.Empty) {
|
|
357
|
+
const fields_ = ff_core_List.List_addAll(declaration_.commonFields_, variant_.fields_);
|
|
358
|
+
return ff_core_List.Link(sameCase_, ff_core_List.Link(ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(wildcardPattern_, ff_core_List.Link(wildcardPattern_, ff_core_List.Empty())), ff_core_List.Empty(), ff_compiler_Deriver.Deriver_makeEqualFields(self_, modulePrefix_, declaration_, fields_)), ff_core_List.Empty()))
|
|
359
|
+
return
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
{
|
|
364
|
+
const variants_ = _1;
|
|
365
|
+
const variantsWithFields_ = ff_core_List.List_filter(variants_, ((variant_) => {
|
|
366
|
+
return ((!ff_core_List.List_isEmpty(declaration_.commonFields_)) || (!ff_core_List.List_isEmpty(variant_.fields_)))
|
|
367
|
+
}));
|
|
368
|
+
const sameVariantCases_ = ff_core_List.List_map(variantsWithFields_, ((variant_) => {
|
|
369
|
+
const variantName_ = ((modulePrefix_ + ".") + variant_.name_);
|
|
370
|
+
const fields_ = ff_core_List.List_addAll(declaration_.commonFields_, variant_.fields_);
|
|
371
|
+
return ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(ff_compiler_Syntax.PVariantAs(at_, variantName_, at_, ff_core_Option.Some("x")), ff_core_List.Link(ff_compiler_Syntax.PVariantAs(at_, variantName_, at_, ff_core_Option.Some("y")), ff_core_List.Empty())), ff_core_List.Empty(), ff_compiler_Deriver.Deriver_makeEqualFields(self_, modulePrefix_, declaration_, fields_))
|
|
372
|
+
}));
|
|
373
|
+
const differentVariant_ = ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(wildcardPattern_, ff_core_List.Link(wildcardPattern_, ff_core_List.Empty())), ff_core_List.Empty(), ff_compiler_Syntax.EVariant(at_, "ff:core/Bool.False", ff_core_List.Empty(), ff_core_Option.None()));
|
|
374
|
+
return ff_core_List.Link(sameCase_, ff_core_List.List_addAll(sameVariantCases_, ff_core_List.Link(differentVariant_, ff_core_List.Empty())))
|
|
375
|
+
return
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export function Deriver_makeEqualFields(self_, modulePrefix_, declaration_, fields_) {
|
|
381
|
+
const at_ = (((_c) => {
|
|
382
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
383
|
+
}))(declaration_.at_);
|
|
384
|
+
function go_(fields_) {
|
|
385
|
+
{
|
|
386
|
+
const fields_a = fields_;
|
|
387
|
+
{
|
|
388
|
+
if(fields_a.Empty) {
|
|
389
|
+
return ff_compiler_Syntax.EVariant(at_, "ff:core/Bool.True", ff_core_List.Empty(), ff_core_Option.None())
|
|
390
|
+
return
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
{
|
|
394
|
+
if(fields_a.Link) {
|
|
395
|
+
const head_ = fields_a.head_;
|
|
396
|
+
if(fields_a.tail_.Empty) {
|
|
397
|
+
return ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Equal.equals", ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "x"), head_.name_), ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "y"), head_.name_), ff_core_List.Empty())), ff_core_List.Empty())
|
|
398
|
+
return
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
{
|
|
403
|
+
if(fields_a.Link) {
|
|
404
|
+
const head_ = fields_a.head_;
|
|
405
|
+
const tail_ = fields_a.tail_;
|
|
406
|
+
const equalsTerm_ = ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Equal.equals", ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "x"), head_.name_), ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "y"), head_.name_), ff_core_List.Empty())), ff_core_List.Empty());
|
|
407
|
+
return ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "&&", ff_core_List.Link(equalsTerm_, ff_core_List.Link(go_(tail_), ff_core_List.Empty())), ff_core_List.Empty())
|
|
408
|
+
return
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return go_(fields_)
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
export function Deriver_makeSerializableInstances(self_, modulePrefix_, module_) {
|
|
417
|
+
const coreWhitelist_ = ff_core_List.List_toSet(ff_core_List.Link("ff:core/Option.Option", ff_core_List.Link("ff:core/Pair.Pair", ff_core_List.Empty())), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
418
|
+
const missingInstance_ = ff_compiler_Deriver.Deriver_findTypesThatNeedInstances(self_, "ff:core/Serializable.Serializable", modulePrefix_, coreWhitelist_, true, module_);
|
|
419
|
+
return ff_core_List.List_map(missingInstance_, ((_w1) => {
|
|
420
|
+
return ff_compiler_Deriver.Deriver_makeSerializableInstance(self_, modulePrefix_, _w1)
|
|
421
|
+
}))
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export function Deriver_makeSerializableInstance(self_, modulePrefix_, declaration_) {
|
|
425
|
+
const at_ = (((_c) => {
|
|
426
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
427
|
+
}))(declaration_.at_);
|
|
428
|
+
const constraints_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
429
|
+
return ff_compiler_Syntax.Constraint(at_, "ff:core/Serializable.Serializable", ff_core_List.Link(ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty()), ff_core_List.Empty()))
|
|
430
|
+
}));
|
|
431
|
+
const typeArguments_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
432
|
+
return ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty())
|
|
433
|
+
}));
|
|
434
|
+
const selfType_ = ff_compiler_Syntax.TConstructor(at_, ((modulePrefix_ + ".") + declaration_.name_), typeArguments_);
|
|
435
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
436
|
+
const serializationType_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Serializable.Serialization", ff_core_List.Empty());
|
|
437
|
+
const serializeSignature_ = ff_compiler_Syntax.Signature(at_, "serializeUsing", false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Link(ff_compiler_Syntax.Parameter(at_, false, "serialization", serializationType_, ff_core_Option.None()), ff_core_List.Link(ff_compiler_Syntax.Parameter(at_, false, "value", selfType_, ff_core_Option.None()), ff_core_List.Empty())), ff_compiler_Syntax.TConstructor(at_, "ff:core/Unit.Unit", ff_core_List.Empty()), noEffect_);
|
|
438
|
+
const deserializeSignature_ = ff_compiler_Syntax.Signature(at_, "deserializeUsing", false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Link(ff_compiler_Syntax.Parameter(at_, false, "serialization", serializationType_, ff_core_Option.None()), ff_core_List.Empty()), selfType_, noEffect_);
|
|
439
|
+
const wildcardPattern_ = ff_compiler_Syntax.PVariable(at_, ff_core_Option.None());
|
|
440
|
+
const serializeBody_ = ff_compiler_Syntax.FireflyTarget(ff_compiler_Syntax.Lambda(at_, noEffect_, ff_compiler_Deriver.Deriver_makeSerializeBody(self_, modulePrefix_, declaration_, selfType_)));
|
|
441
|
+
const deserializeBody_ = ff_compiler_Syntax.FireflyTarget(ff_compiler_Syntax.Lambda(at_, noEffect_, ff_core_List.Link(ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(wildcardPattern_, ff_core_List.Empty()), ff_core_List.Empty(), ff_compiler_Deriver.Deriver_makeDeserializeBody(self_, modulePrefix_, declaration_, selfType_)), ff_core_List.Empty())));
|
|
442
|
+
return ff_compiler_Syntax.DInstance(at_, declaration_.generics_, constraints_, "ff:core/Serializable.Serializable", ff_core_List.Link(selfType_, ff_core_List.Empty()), ff_core_List.Empty(), ff_core_List.Link(ff_compiler_Syntax.DFunction(at_, serializeSignature_, serializeBody_), ff_core_List.Link(ff_compiler_Syntax.DFunction(at_, deserializeSignature_, deserializeBody_), ff_core_List.Empty())), true)
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export function Deriver_makeSerializeBody(self_, modulePrefix_, declaration_, selfType_) {
|
|
446
|
+
const at_ = (((_c) => {
|
|
447
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
448
|
+
}))(declaration_.at_);
|
|
449
|
+
const wildcardPattern_ = ff_compiler_Syntax.PVariable(at_, ff_core_Option.None());
|
|
450
|
+
return ff_core_List.List_map(ff_core_List.List_pairs(declaration_.variants_), ((_1) => {
|
|
451
|
+
{
|
|
452
|
+
const index_ = _1.first_;
|
|
453
|
+
const variant_ = _1.second_;
|
|
454
|
+
const variantName_ = ((modulePrefix_ + ".") + variant_.name_);
|
|
455
|
+
const fields_ = ff_core_List.List_addAll(declaration_.commonFields_, variant_.fields_);
|
|
456
|
+
const updateChecksum_ = ff_compiler_Deriver.Deriver_makeUpdateChecksum(self_, at_, variantName_, declaration_, variant_);
|
|
457
|
+
const setVariantIndex_ = ff_compiler_Deriver.Deriver_makeMethodCall(self_, at_, ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "serialization"), "buffer"), "setUint8", ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "serialization"), "offset"), ff_core_List.Link(ff_compiler_Syntax.EInt(at_, ("" + index_)), ff_core_List.Empty())));
|
|
458
|
+
const fieldSerializations_ = ff_core_List.List_map(fields_, ((field_) => {
|
|
459
|
+
return ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Serializable.serializeUsing", ff_core_List.Link(ff_compiler_Syntax.EVariable(at_, "serialization"), ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "v"), field_.name_), ff_core_List.Empty())), ff_core_List.Empty())
|
|
460
|
+
}));
|
|
461
|
+
return ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(wildcardPattern_, ff_core_List.Link(ff_compiler_Syntax.PVariantAs(at_, variantName_, at_, ff_core_Option.Some("v")), ff_core_List.Empty())), ff_core_List.Empty(), ff_core_List.List_foldLeft(ff_core_List.Link(setVariantIndex_, ff_core_List.Link(ff_compiler_Syntax.EAssignField(at_, "+", ff_compiler_Syntax.EVariable(at_, "serialization"), "offset", ff_compiler_Syntax.EInt(at_, "1")), fieldSerializations_)), updateChecksum_, ((_w1, _w2) => {
|
|
462
|
+
return ff_compiler_Syntax.ESequential(at_, _w1, _w2)
|
|
463
|
+
})))
|
|
464
|
+
return
|
|
465
|
+
}
|
|
466
|
+
}))
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
export function Deriver_makeDeserializeBody(self_, modulePrefix_, declaration_, selfType_) {
|
|
470
|
+
const at_ = (((_c) => {
|
|
471
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
472
|
+
}))(declaration_.at_);
|
|
473
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
474
|
+
const wildcardPattern_ = ff_compiler_Syntax.PVariable(at_, ff_core_Option.None());
|
|
475
|
+
const grabVariantIndex_ = ff_compiler_Deriver.Deriver_makeMethodCall(self_, at_, ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "serialization"), "buffer"), "grabUint8", ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "serialization"), "offset"), ff_core_List.Empty()));
|
|
476
|
+
const intType_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Int.Int", ff_core_List.Empty());
|
|
477
|
+
const incrementOffset_ = ff_compiler_Syntax.EAssignField(at_, "+", ff_compiler_Syntax.EVariable(at_, "serialization"), "offset", ff_compiler_Syntax.EInt(at_, "1"));
|
|
478
|
+
const cases_ = ff_core_List.List_map(ff_core_List.List_pairs(declaration_.variants_), ((_1) => {
|
|
479
|
+
{
|
|
480
|
+
const index_ = _1.first_;
|
|
481
|
+
const variant_ = _1.second_;
|
|
482
|
+
const variantName_ = ((modulePrefix_ + ".") + variant_.name_);
|
|
483
|
+
const fields_ = ff_core_List.List_addAll(declaration_.commonFields_, variant_.fields_);
|
|
484
|
+
const fieldValues_ = ff_core_List.List_map(fields_, ((field_) => {
|
|
485
|
+
return ff_compiler_Syntax.Argument(at_, ff_core_Option.None(), ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Serializable.deserializeUsing", ff_core_List.Link(ff_compiler_Syntax.EVariable(at_, "serialization"), ff_core_List.Empty()), ff_core_List.Empty()))
|
|
486
|
+
}));
|
|
487
|
+
const updateChecksum_ = ff_compiler_Deriver.Deriver_makeUpdateChecksum(self_, at_, variantName_, declaration_, variant_);
|
|
488
|
+
const makeVariant_ = ff_compiler_Syntax.EVariant(at_, variantName_, ff_core_List.Empty(), ff_core_Option.Some(fieldValues_));
|
|
489
|
+
return ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(ff_compiler_Syntax.PInt(at_, ("" + index_)), ff_core_List.Empty()), ff_core_List.Empty(), ff_compiler_Syntax.ESequential(at_, updateChecksum_, makeVariant_))
|
|
490
|
+
return
|
|
491
|
+
}
|
|
492
|
+
}));
|
|
493
|
+
const otherwiseCase_ = ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(wildcardPattern_, ff_core_List.Empty()), ff_core_List.Empty(), ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Core.throw", ff_core_List.Link(ff_compiler_Syntax.EVariant(at_, "ff:core/Serializable.DeserializationChecksumException", ff_core_List.Empty(), ff_core_Option.None()), ff_core_List.Empty()), ff_core_List.Empty()));
|
|
494
|
+
const matchLambda_ = ff_compiler_Syntax.ELambda(at_, ff_compiler_Syntax.Lambda(at_, noEffect_, ff_core_List.List_addAll(cases_, ff_core_List.Link(otherwiseCase_, ff_core_List.Empty()))));
|
|
495
|
+
const match_ = ff_compiler_Syntax.EPipe(at_, ff_compiler_Syntax.EVariable(at_, "variantIndex"), noEffect_, matchLambda_);
|
|
496
|
+
return ff_compiler_Syntax.ELet(at_, false, "variantIndex", intType_, grabVariantIndex_, ff_compiler_Syntax.ESequential(at_, incrementOffset_, match_))
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export function Deriver_makeUpdateChecksum(self_, at_, variantName_, declaration_, variant_) {
|
|
500
|
+
const fields_ = ff_core_List.List_addAll(declaration_.commonFields_, variant_.fields_);
|
|
501
|
+
const variantChecksum_ = ff_core_String.String_size(variantName_);
|
|
502
|
+
return ff_compiler_Syntax.EAssignField(at_, "", ff_compiler_Syntax.EVariable(at_, "serialization"), "checksum", ff_compiler_Deriver.Deriver_makeMethodCall(self_, at_, ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "+", ff_core_List.Link(ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "*", ff_core_List.Link(ff_compiler_Syntax.EInt(at_, "31"), ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "serialization"), "checksum"), ff_core_List.Empty())), ff_core_List.Empty()), ff_core_List.Link(ff_compiler_Syntax.EInt(at_, ("" + variantChecksum_)), ff_core_List.Empty())), ff_core_List.Empty()), "bitOr", ff_core_List.Link(ff_compiler_Syntax.EInt(at_, "0"), ff_core_List.Empty())))
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
export function Deriver_findTypesThatNeedInstances(self_, traitName_, modulePrefix_, coreWhitelist_, allowGenerics_, module_) {
|
|
506
|
+
const typesWithInstance_ = ff_core_List.List_toSet(ff_core_List.List_collect(module_.instances_, ((_1) => {
|
|
507
|
+
{
|
|
508
|
+
const instance_ = _1;
|
|
509
|
+
const _guard1 = ff_core_List.List_first(instance_.typeArguments_);
|
|
510
|
+
if(_guard1.Some) {
|
|
511
|
+
if(_guard1.value_.TConstructor) {
|
|
512
|
+
const name_ = _guard1.value_.name_;
|
|
513
|
+
if((instance_.traitName_ === traitName_)) {
|
|
514
|
+
return ff_core_Option.Some(name_)
|
|
515
|
+
} else return ff_core_Option.None()
|
|
516
|
+
return
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
{
|
|
521
|
+
return ff_core_Option.None()
|
|
522
|
+
return
|
|
523
|
+
}
|
|
524
|
+
})), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
525
|
+
return ff_core_List.List_filter(module_.types_, ((t_) => {
|
|
526
|
+
return (((((((ff_compiler_Syntax.PackagePair_groupName(module_.packagePair_, ":") !== "ff:core") || ff_core_Set.Set_contains(coreWhitelist_, ((modulePrefix_ + ".") + t_.name_), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String)) && (!ff_core_Option.Option_any(ff_core_List.List_first(t_.generics_), ((_w1) => {
|
|
527
|
+
return (_w1 === "Q$")
|
|
528
|
+
})))) && (allowGenerics_ || ff_core_List.List_isEmpty(t_.generics_))) && t_.data_) && (!t_.newtype_)) && (!ff_core_Set.Set_contains(typesWithInstance_, ((modulePrefix_ + ".") + t_.name_), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String)))
|
|
529
|
+
}))
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export function Deriver_makeSimpleCall(self_, at_, name_, arguments_, typeArguments_ = ff_core_List.Empty()) {
|
|
533
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
534
|
+
const callTarget_ = ff_compiler_Syntax.DynamicCall(ff_compiler_Syntax.EVariable(at_, name_), false);
|
|
535
|
+
return ff_compiler_Syntax.ECall(at_, callTarget_, noEffect_, typeArguments_, ff_core_List.List_map(arguments_, ((e_) => {
|
|
536
|
+
return ff_compiler_Syntax.Argument(at_, ff_core_Option.None(), e_)
|
|
537
|
+
})), ff_core_List.Empty())
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
export function Deriver_makeMethodCall(self_, at_, target_, methodName_, arguments_) {
|
|
541
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
542
|
+
const method_ = ff_compiler_Syntax.EField(at_, false, target_, methodName_);
|
|
543
|
+
return ff_compiler_Syntax.ECall(at_, ff_compiler_Syntax.DynamicCall(method_, false), noEffect_, ff_core_List.Empty(), ff_core_List.List_map(arguments_, ((_w1) => {
|
|
544
|
+
return ff_compiler_Syntax.Argument(at_, ff_core_Option.None(), _w1)
|
|
545
|
+
})), ff_core_List.Empty())
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
export function Deriver_makeIf(self_, at_, condition_, then_, else_) {
|
|
549
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
550
|
+
const target_ = ff_compiler_Syntax.DynamicCall(ff_compiler_Syntax.EVariable(at_, "ff:core/Core.if"), false);
|
|
551
|
+
const option_ = ff_compiler_Syntax.ECall(at_, target_, noEffect_, ff_core_List.Empty(), ff_core_List.Link(ff_compiler_Syntax.Argument(at_, ff_core_Option.None(), condition_), ff_core_List.Link(ff_compiler_Syntax.Argument(at_, ff_core_Option.None(), ff_compiler_Syntax.ELambda(at_, ff_compiler_Syntax.Lambda(at_, noEffect_, ff_core_List.Link(ff_compiler_Syntax.MatchCase(at_, ff_core_List.Empty(), ff_core_List.Empty(), then_), ff_core_List.Empty())))), ff_core_List.Empty())), ff_core_List.Empty());
|
|
552
|
+
return ff_compiler_Syntax.ECall(at_, ff_compiler_Syntax.DynamicCall(ff_compiler_Syntax.EField(at_, false, option_, "else"), false), noEffect_, ff_core_List.Empty(), ff_core_List.Link(ff_compiler_Syntax.Argument(at_, ff_core_Option.None(), ff_compiler_Syntax.ELambda(at_, ff_compiler_Syntax.Lambda(at_, noEffect_, ff_core_List.Link(ff_compiler_Syntax.MatchCase(at_, ff_core_List.Empty(), ff_core_List.Empty(), else_), ff_core_List.Empty())))), ff_core_List.Empty()), ff_core_List.Empty())
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
export async function Deriver_deriveModule$(self_, module_, $task) {
|
|
556
|
+
const modulePrefix_ = ((ff_compiler_Syntax.PackagePair_groupName(module_.packagePair_, ":") + "/") + ff_core_String.String_dropLast(module_.file_, 3));
|
|
557
|
+
{
|
|
558
|
+
const _1 = module_;
|
|
559
|
+
{
|
|
560
|
+
const _c = _1;
|
|
561
|
+
return ff_compiler_Syntax.Module(_c.file_, _c.packagePair_, _c.imports_, _c.types_, _c.traits_, ff_core_List.List_addAll(module_.instances_, ff_core_List.List_addAll(ff_compiler_Deriver.Deriver_makeHasAnyTagInstances(self_, modulePrefix_, module_), ff_core_List.List_addAll(ff_compiler_Deriver.Deriver_makeShowInstances(self_, modulePrefix_, module_), ff_core_List.List_addAll(ff_compiler_Deriver.Deriver_makeEqualInstances(self_, modulePrefix_, module_), ff_core_List.List_addAll(ff_compiler_Deriver.Deriver_makeOrderingInstances(self_, modulePrefix_, module_), ff_compiler_Deriver.Deriver_makeSerializableInstances(self_, modulePrefix_, module_)))))), _c.extends_, _c.lets_, _c.functions_)
|
|
562
|
+
return
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
export async function Deriver_makeHasAnyTagInstances$(self_, modulePrefix_, module_, $task) {
|
|
568
|
+
const coreWhitelist_ = ff_core_List.List_toSet(ff_core_List.Link("ff:core/Serializable.DeserializationChecksumException", ff_core_List.Link("ff:core/Core.GrabException", ff_core_List.Empty())), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
569
|
+
const missingInstance_ = ff_compiler_Deriver.Deriver_findTypesThatNeedInstances(self_, "ff:core/Any.HasAnyTag", modulePrefix_, coreWhitelist_, true, module_);
|
|
570
|
+
return ff_core_List.List_map(missingInstance_, ((_w1) => {
|
|
571
|
+
return ff_compiler_Deriver.Deriver_makeHasAnyTagInstance(self_, modulePrefix_, _w1)
|
|
572
|
+
}))
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
export async function Deriver_makeHasAnyTagInstance$(self_, modulePrefix_, declaration_, $task) {
|
|
576
|
+
const at_ = (((_c) => {
|
|
577
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
578
|
+
}))(declaration_.at_);
|
|
579
|
+
const constraints_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
580
|
+
return ff_compiler_Syntax.Constraint(at_, "ff:core/Any.HasAnyTag", ff_core_List.Link(ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty()), ff_core_List.Empty()))
|
|
581
|
+
}));
|
|
582
|
+
const typeArguments_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
583
|
+
return ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty())
|
|
584
|
+
}));
|
|
585
|
+
const selfTypeName_ = ((modulePrefix_ + ".") + declaration_.name_);
|
|
586
|
+
const selfType_ = ff_compiler_Syntax.TConstructor(at_, selfTypeName_, typeArguments_);
|
|
587
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
588
|
+
const signature_ = ff_compiler_Syntax.Signature(at_, "anyTag", false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Empty(), ff_compiler_Syntax.TConstructor(at_, "ff:core/Any.AnyTag", ff_core_List.Link(selfType_, ff_core_List.Empty())), noEffect_);
|
|
589
|
+
const typeArgumentStrings_ = ff_core_List.List_map(typeArguments_, ((_w1) => {
|
|
590
|
+
return ff_compiler_Deriver.Deriver_makeMethodCall(self_, at_, ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Any.anyTag", ff_core_List.Empty(), ff_core_List.Link(_w1, ff_core_List.Empty())), "show", ff_core_List.Empty())
|
|
591
|
+
}));
|
|
592
|
+
const strings_ = ff_core_List.Link(ff_compiler_Syntax.EString(at_, "\"[\""), ff_core_List.List_addAll(ff_core_List.List_insertBetween(typeArgumentStrings_, ff_core_List.Link(ff_compiler_Syntax.EString(at_, "\",\""), ff_core_List.Empty())), ff_core_List.Link(ff_compiler_Syntax.EString(at_, "\"]\""), ff_core_List.Empty())));
|
|
593
|
+
const body_ = ff_compiler_Syntax.FireflyTarget(ff_compiler_Syntax.Lambda(at_, noEffect_, ff_core_List.Link(ff_compiler_Syntax.MatchCase(at_, ff_core_List.Empty(), ff_core_List.Empty(), ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Any.internalAnyTag", ff_core_List.Link(ff_core_List.List_foldLeft(strings_, ff_compiler_Syntax.EString(at_, (("\"" + selfTypeName_) + "\"")), ((a_, b_) => {
|
|
594
|
+
return ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "+", ff_core_List.Link(a_, ff_core_List.Link(b_, ff_core_List.Empty())), ff_core_List.Empty())
|
|
595
|
+
})), ff_core_List.Empty()), ff_core_List.Empty())), ff_core_List.Empty())));
|
|
596
|
+
const method_ = ff_compiler_Syntax.DFunction(at_, signature_, body_);
|
|
597
|
+
return ff_compiler_Syntax.DInstance(at_, declaration_.generics_, constraints_, "ff:core/Any.HasAnyTag", ff_core_List.Link(selfType_, ff_core_List.Empty()), ff_core_List.Empty(), ff_core_List.Link(method_, ff_core_List.Empty()), true)
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
export async function Deriver_makeShowInstances$(self_, modulePrefix_, module_, $task) {
|
|
601
|
+
const coreWhitelist_ = ff_core_List.List_toSet(ff_core_List.Link("ff:core/Option.Option", ff_core_List.Empty()), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
602
|
+
const missingInstance_ = ff_compiler_Deriver.Deriver_findTypesThatNeedInstances(self_, "ff:core/Show.Show", modulePrefix_, coreWhitelist_, true, module_);
|
|
603
|
+
return ff_core_List.List_map(missingInstance_, ((_w1) => {
|
|
604
|
+
return ff_compiler_Deriver.Deriver_makeShowInstance(self_, modulePrefix_, _w1)
|
|
605
|
+
}))
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
export async function Deriver_makeShowInstance$(self_, modulePrefix_, declaration_, $task) {
|
|
609
|
+
const at_ = (((_c) => {
|
|
610
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
611
|
+
}))(declaration_.at_);
|
|
612
|
+
const constraints_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
613
|
+
return ff_compiler_Syntax.Constraint(at_, "ff:core/Show.Show", ff_core_List.Link(ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty()), ff_core_List.Empty()))
|
|
614
|
+
}));
|
|
615
|
+
const typeArguments_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
616
|
+
return ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty())
|
|
617
|
+
}));
|
|
618
|
+
const selfType_ = ff_compiler_Syntax.TConstructor(at_, ((modulePrefix_ + ".") + declaration_.name_), typeArguments_);
|
|
619
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
620
|
+
const signature_ = ff_compiler_Syntax.Signature(at_, "show", false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Link(ff_compiler_Syntax.Parameter(at_, false, "value", selfType_, ff_core_Option.None()), ff_core_List.Empty()), ff_compiler_Syntax.TConstructor(at_, "ff:core/String.String", ff_core_List.Empty()), noEffect_);
|
|
621
|
+
const body_ = ff_compiler_Syntax.FireflyTarget(ff_compiler_Syntax.Lambda(at_, noEffect_, ff_compiler_Deriver.Deriver_makeShowCases(self_, modulePrefix_, declaration_, selfType_)));
|
|
622
|
+
const showMethod_ = ff_compiler_Syntax.DFunction(at_, signature_, body_);
|
|
623
|
+
return ff_compiler_Syntax.DInstance(at_, declaration_.generics_, constraints_, "ff:core/Show.Show", ff_core_List.Link(selfType_, ff_core_List.Empty()), ff_core_List.Empty(), ff_core_List.Link(showMethod_, ff_core_List.Empty()), true)
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
export async function Deriver_makeShowCases$(self_, modulePrefix_, declaration_, selfType_, $task) {
|
|
627
|
+
const at_ = (((_c) => {
|
|
628
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
629
|
+
}))(declaration_.at_);
|
|
630
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
631
|
+
const wildcardPattern_ = ff_compiler_Syntax.PVariable(at_, ff_core_Option.None());
|
|
632
|
+
{
|
|
633
|
+
const _1 = declaration_.variants_;
|
|
634
|
+
{
|
|
635
|
+
const variants_ = _1;
|
|
636
|
+
return ff_core_List.List_map(variants_, ((variant_) => {
|
|
637
|
+
const variantName_ = ((modulePrefix_ + ".") + variant_.name_);
|
|
638
|
+
const fields_ = ff_core_List.List_addAll(declaration_.commonFields_, variant_.fields_);
|
|
639
|
+
const strings_ = ((ff_core_List.List_size(fields_) === 0)
|
|
640
|
+
? ff_core_List.Empty()
|
|
641
|
+
: ff_core_List.Link(ff_compiler_Syntax.EString(at_, "\"(\""), ff_core_List.List_addAll(ff_core_List.List_insertBetween(ff_core_List.List_map(fields_, ((field_) => {
|
|
642
|
+
return ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Show.show", ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "z"), field_.name_), ff_core_List.Empty()), ff_core_List.Empty())
|
|
643
|
+
})), ff_core_List.Link(ff_compiler_Syntax.EString(at_, "\", \""), ff_core_List.Empty())), ff_core_List.Link(ff_compiler_Syntax.EString(at_, "\")\""), ff_core_List.Empty()))));
|
|
644
|
+
return ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(ff_compiler_Syntax.PVariantAs(at_, variantName_, at_, ff_core_Option.Some("z")), ff_core_List.Empty()), ff_core_List.Empty(), ff_core_List.List_foldLeft(strings_, ff_compiler_Syntax.EString(at_, (("\"" + variant_.name_) + "\"")), ((a_, b_) => {
|
|
645
|
+
return ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "+", ff_core_List.Link(a_, ff_core_List.Link(b_, ff_core_List.Empty())), ff_core_List.Empty())
|
|
646
|
+
})))
|
|
647
|
+
}))
|
|
648
|
+
return
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
export async function Deriver_makeOrderingInstances$(self_, modulePrefix_, module_, $task) {
|
|
654
|
+
const coreWhitelist_ = ff_core_List.List_toSet(ff_core_List.Link("ff:core/Option.Option", ff_core_List.Empty()), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
655
|
+
const missingInstance_ = ff_compiler_Deriver.Deriver_findTypesThatNeedInstances(self_, "ff:core/Ordering.Order", modulePrefix_, coreWhitelist_, true, module_);
|
|
656
|
+
return ff_core_List.List_map(missingInstance_, ((_w1) => {
|
|
657
|
+
return ff_compiler_Deriver.Deriver_makeOrderingInstance(self_, modulePrefix_, _w1)
|
|
658
|
+
}))
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
export async function Deriver_makeOrderingInstance$(self_, modulePrefix_, declaration_, $task) {
|
|
662
|
+
const at_ = (((_c) => {
|
|
663
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
664
|
+
}))(declaration_.at_);
|
|
665
|
+
const constraints_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
666
|
+
return ff_compiler_Syntax.Constraint(at_, "ff:core/Ordering.Order", ff_core_List.Link(ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty()), ff_core_List.Empty()))
|
|
667
|
+
}));
|
|
668
|
+
const typeArguments_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
669
|
+
return ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty())
|
|
670
|
+
}));
|
|
671
|
+
const selfType_ = ff_compiler_Syntax.TConstructor(at_, ((modulePrefix_ + ".") + declaration_.name_), typeArguments_);
|
|
672
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
673
|
+
const signature_ = ff_compiler_Syntax.Signature(at_, "compare", false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Link(ff_compiler_Syntax.Parameter(at_, false, "x", selfType_, ff_core_Option.None()), ff_core_List.Link(ff_compiler_Syntax.Parameter(at_, false, "y", selfType_, ff_core_Option.None()), ff_core_List.Empty())), ff_compiler_Syntax.TConstructor(at_, "ff:core/Ordering.Ordering", ff_core_List.Empty()), noEffect_);
|
|
674
|
+
const body_ = ff_compiler_Syntax.FireflyTarget(ff_compiler_Syntax.Lambda(at_, noEffect_, ff_compiler_Deriver.Deriver_makeOrderingCases(self_, modulePrefix_, declaration_, selfType_)));
|
|
675
|
+
const compareMethod_ = ff_compiler_Syntax.DFunction(at_, signature_, body_);
|
|
676
|
+
return ff_compiler_Syntax.DInstance(at_, declaration_.generics_, constraints_, "ff:core/Ordering.Order", ff_core_List.Link(selfType_, ff_core_List.Empty()), ff_core_List.Empty(), ff_core_List.Link(compareMethod_, ff_core_List.Empty()), true)
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
export async function Deriver_makeOrderingCases$(self_, modulePrefix_, declaration_, selfType_, $task) {
|
|
680
|
+
const at_ = (((_c) => {
|
|
681
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
682
|
+
}))(declaration_.at_);
|
|
683
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
684
|
+
const wildcardPattern_ = ff_compiler_Syntax.PVariable(at_, ff_core_Option.None());
|
|
685
|
+
const sameCase_ = ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(wildcardPattern_, ff_core_List.Link(wildcardPattern_, ff_core_List.Empty())), ff_core_List.Link(ff_compiler_Syntax.MatchGuard(at_, ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "===", ff_core_List.Link(ff_compiler_Syntax.EVariable(at_, "x"), ff_core_List.Link(ff_compiler_Syntax.EVariable(at_, "y"), ff_core_List.Empty())), ff_core_List.Empty()), ff_compiler_Syntax.PVariant(at_, "ff:core/Bool.True", ff_core_List.Empty())), ff_core_List.Empty()), ff_compiler_Syntax.EVariant(at_, "ff:core/Ordering.OrderingSame", ff_core_List.Empty(), ff_core_Option.None()));
|
|
686
|
+
{
|
|
687
|
+
const _1 = declaration_.variants_;
|
|
688
|
+
{
|
|
689
|
+
if(_1.Link) {
|
|
690
|
+
const variant_ = _1.head_;
|
|
691
|
+
if(_1.tail_.Empty) {
|
|
692
|
+
const fields_ = ff_core_List.List_addAll(declaration_.commonFields_, variant_.fields_);
|
|
693
|
+
return ff_core_List.Link(sameCase_, ff_core_List.Link(ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(wildcardPattern_, ff_core_List.Link(wildcardPattern_, ff_core_List.Empty())), ff_core_List.Empty(), ff_compiler_Deriver.Deriver_makeOrderingFields(self_, modulePrefix_, declaration_, fields_)), ff_core_List.Empty()))
|
|
694
|
+
return
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
{
|
|
699
|
+
const variants_ = _1;
|
|
700
|
+
const variantsWithFields_ = ff_core_List.List_filter(variants_, ((variant_) => {
|
|
701
|
+
return ((!ff_core_List.List_isEmpty(declaration_.commonFields_)) || (!ff_core_List.List_isEmpty(variant_.fields_)))
|
|
702
|
+
}));
|
|
703
|
+
const sameVariantCases_ = ff_core_List.List_map(variantsWithFields_, ((variant_) => {
|
|
704
|
+
const variantName_ = ((modulePrefix_ + ".") + variant_.name_);
|
|
705
|
+
const fields_ = ff_core_List.List_addAll(declaration_.commonFields_, variant_.fields_);
|
|
706
|
+
return ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(ff_compiler_Syntax.PVariantAs(at_, variantName_, at_, ff_core_Option.Some("x")), ff_core_List.Link(ff_compiler_Syntax.PVariantAs(at_, variantName_, at_, ff_core_Option.Some("y")), ff_core_List.Empty())), ff_core_List.Empty(), ff_compiler_Deriver.Deriver_makeOrderingFields(self_, modulePrefix_, declaration_, fields_))
|
|
707
|
+
}));
|
|
708
|
+
const intType_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Int.Int", ff_core_List.Empty());
|
|
709
|
+
const numberSignature_ = ff_compiler_Syntax.Signature(at_, "number", false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Link(ff_compiler_Syntax.Parameter(at_, false, "z", selfType_, ff_core_Option.None()), ff_core_List.Empty()), intType_, noEffect_);
|
|
710
|
+
const numberCases_ = ff_core_List.List_map(ff_core_List.List_pairs(declaration_.variants_), ((_1) => {
|
|
711
|
+
{
|
|
712
|
+
const index_ = _1.first_;
|
|
713
|
+
const variant_ = _1.second_;
|
|
714
|
+
const variantName_ = ((modulePrefix_ + ".") + variant_.name_);
|
|
715
|
+
return ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(ff_compiler_Syntax.PVariantAs(at_, variantName_, at_, ff_core_Option.None()), ff_core_List.Empty()), ff_core_List.Empty(), ff_compiler_Syntax.EInt(at_, ("" + index_)))
|
|
716
|
+
return
|
|
717
|
+
}
|
|
718
|
+
}));
|
|
719
|
+
const differentVariant_ = ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(wildcardPattern_, ff_core_List.Link(wildcardPattern_, ff_core_List.Empty())), ff_core_List.Empty(), ff_compiler_Syntax.EFunctions(at_, ff_core_List.Link(ff_compiler_Syntax.DFunction(at_, numberSignature_, ff_compiler_Syntax.FireflyTarget(ff_compiler_Syntax.Lambda(at_, noEffect_, numberCases_))), ff_core_List.Empty()), ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Ordering.compare", ff_core_List.Link(ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "number", ff_core_List.Link(ff_compiler_Syntax.EVariable(at_, "x"), ff_core_List.Empty()), ff_core_List.Empty()), ff_core_List.Link(ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "number", ff_core_List.Link(ff_compiler_Syntax.EVariable(at_, "y"), ff_core_List.Empty()), ff_core_List.Empty()), ff_core_List.Empty())), ff_core_List.Empty())));
|
|
720
|
+
return ff_core_List.Link(sameCase_, ff_core_List.List_addAll(sameVariantCases_, ff_core_List.Link(differentVariant_, ff_core_List.Empty())))
|
|
721
|
+
return
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
export async function Deriver_makeOrderingFields$(self_, modulePrefix_, declaration_, fields_, $task) {
|
|
727
|
+
const at_ = (((_c) => {
|
|
728
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
729
|
+
}))(declaration_.at_);
|
|
730
|
+
const orderingType_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Ordering.Ordering", ff_core_List.Empty());
|
|
731
|
+
const orderingSame_ = ff_compiler_Syntax.EVariant(at_, "ff:core/Ordering.OrderingSame", ff_core_List.Empty(), ff_core_Option.None());
|
|
732
|
+
function go_(fields_) {
|
|
733
|
+
{
|
|
734
|
+
const fields_a = fields_;
|
|
735
|
+
{
|
|
736
|
+
if(fields_a.Empty) {
|
|
737
|
+
return orderingSame_
|
|
738
|
+
return
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
{
|
|
742
|
+
if(fields_a.Link) {
|
|
743
|
+
const head_ = fields_a.head_;
|
|
744
|
+
const tail_ = fields_a.tail_;
|
|
745
|
+
const variableName_ = (head_.name_ + "Ordering");
|
|
746
|
+
const compareTerm_ = ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Ordering.compare", ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "x"), head_.name_), ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "y"), head_.name_), ff_core_List.Empty())), ff_core_List.Empty());
|
|
747
|
+
const notEqualTerm_ = ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "!==", ff_core_List.Link(ff_compiler_Syntax.EVariable(at_, variableName_), ff_core_List.Link(orderingSame_, ff_core_List.Empty())), ff_core_List.Empty());
|
|
748
|
+
const ifTerm_ = ff_compiler_Deriver.Deriver_makeIf(self_, at_, notEqualTerm_, ff_compiler_Syntax.EVariable(at_, variableName_), go_(tail_));
|
|
749
|
+
return ff_compiler_Syntax.ELet(at_, false, variableName_, orderingType_, compareTerm_, ifTerm_)
|
|
750
|
+
return
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
return go_(fields_)
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
export async function Deriver_makeEqualInstances$(self_, modulePrefix_, module_, $task) {
|
|
759
|
+
const coreWhitelist_ = ff_core_List.List_toSet(ff_core_List.Link("ff:core/Option.Option", ff_core_List.Link("ff:core/List.List", ff_core_List.Link("ff:core/Pair.Pair", ff_core_List.Empty()))), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
760
|
+
const missingInstance_ = ff_compiler_Deriver.Deriver_findTypesThatNeedInstances(self_, "ff:core/Equal.Equal", modulePrefix_, coreWhitelist_, true, module_);
|
|
761
|
+
return ff_core_List.List_map(missingInstance_, ((_w1) => {
|
|
762
|
+
return ff_compiler_Deriver.Deriver_makeEqualInstance(self_, modulePrefix_, _w1)
|
|
763
|
+
}))
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
export async function Deriver_makeEqualInstance$(self_, modulePrefix_, declaration_, $task) {
|
|
767
|
+
const at_ = (((_c) => {
|
|
768
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
769
|
+
}))(declaration_.at_);
|
|
770
|
+
const constraints_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
771
|
+
return ff_compiler_Syntax.Constraint(at_, "ff:core/Equal.Equal", ff_core_List.Link(ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty()), ff_core_List.Empty()))
|
|
772
|
+
}));
|
|
773
|
+
const typeArguments_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
774
|
+
return ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty())
|
|
775
|
+
}));
|
|
776
|
+
const selfType_ = ff_compiler_Syntax.TConstructor(at_, ((modulePrefix_ + ".") + declaration_.name_), typeArguments_);
|
|
777
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
778
|
+
const signature_ = ff_compiler_Syntax.Signature(at_, "equals", false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Link(ff_compiler_Syntax.Parameter(at_, false, "x", selfType_, ff_core_Option.None()), ff_core_List.Link(ff_compiler_Syntax.Parameter(at_, false, "y", selfType_, ff_core_Option.None()), ff_core_List.Empty())), ff_compiler_Syntax.TConstructor(at_, "ff:core/Bool.Bool", ff_core_List.Empty()), noEffect_);
|
|
779
|
+
const body_ = ff_compiler_Syntax.FireflyTarget(ff_compiler_Syntax.Lambda(at_, noEffect_, ff_compiler_Deriver.Deriver_makeEqualsCases(self_, modulePrefix_, declaration_, selfType_)));
|
|
780
|
+
const equalsMethod_ = ff_compiler_Syntax.DFunction(at_, signature_, body_);
|
|
781
|
+
return ff_compiler_Syntax.DInstance(at_, declaration_.generics_, constraints_, "ff:core/Equal.Equal", ff_core_List.Link(selfType_, ff_core_List.Empty()), ff_core_List.Empty(), ff_core_List.Link(equalsMethod_, ff_core_List.Empty()), true)
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
export async function Deriver_makeEqualsCases$(self_, modulePrefix_, declaration_, selfType_, $task) {
|
|
785
|
+
const at_ = (((_c) => {
|
|
786
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
787
|
+
}))(declaration_.at_);
|
|
788
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
789
|
+
const wildcardPattern_ = ff_compiler_Syntax.PVariable(at_, ff_core_Option.None());
|
|
790
|
+
const sameCase_ = ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(wildcardPattern_, ff_core_List.Link(wildcardPattern_, ff_core_List.Empty())), ff_core_List.Link(ff_compiler_Syntax.MatchGuard(at_, ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "===", ff_core_List.Link(ff_compiler_Syntax.EVariable(at_, "x"), ff_core_List.Link(ff_compiler_Syntax.EVariable(at_, "y"), ff_core_List.Empty())), ff_core_List.Empty()), ff_compiler_Syntax.PVariant(at_, "ff:core/Bool.True", ff_core_List.Empty())), ff_core_List.Empty()), ff_compiler_Syntax.EVariant(at_, "ff:core/Bool.True", ff_core_List.Empty(), ff_core_Option.None()));
|
|
791
|
+
{
|
|
792
|
+
const _1 = declaration_.variants_;
|
|
793
|
+
{
|
|
794
|
+
if(_1.Link) {
|
|
795
|
+
const variant_ = _1.head_;
|
|
796
|
+
if(_1.tail_.Empty) {
|
|
797
|
+
const fields_ = ff_core_List.List_addAll(declaration_.commonFields_, variant_.fields_);
|
|
798
|
+
return ff_core_List.Link(sameCase_, ff_core_List.Link(ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(wildcardPattern_, ff_core_List.Link(wildcardPattern_, ff_core_List.Empty())), ff_core_List.Empty(), ff_compiler_Deriver.Deriver_makeEqualFields(self_, modulePrefix_, declaration_, fields_)), ff_core_List.Empty()))
|
|
799
|
+
return
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
{
|
|
804
|
+
const variants_ = _1;
|
|
805
|
+
const variantsWithFields_ = ff_core_List.List_filter(variants_, ((variant_) => {
|
|
806
|
+
return ((!ff_core_List.List_isEmpty(declaration_.commonFields_)) || (!ff_core_List.List_isEmpty(variant_.fields_)))
|
|
807
|
+
}));
|
|
808
|
+
const sameVariantCases_ = ff_core_List.List_map(variantsWithFields_, ((variant_) => {
|
|
809
|
+
const variantName_ = ((modulePrefix_ + ".") + variant_.name_);
|
|
810
|
+
const fields_ = ff_core_List.List_addAll(declaration_.commonFields_, variant_.fields_);
|
|
811
|
+
return ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(ff_compiler_Syntax.PVariantAs(at_, variantName_, at_, ff_core_Option.Some("x")), ff_core_List.Link(ff_compiler_Syntax.PVariantAs(at_, variantName_, at_, ff_core_Option.Some("y")), ff_core_List.Empty())), ff_core_List.Empty(), ff_compiler_Deriver.Deriver_makeEqualFields(self_, modulePrefix_, declaration_, fields_))
|
|
812
|
+
}));
|
|
813
|
+
const differentVariant_ = ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(wildcardPattern_, ff_core_List.Link(wildcardPattern_, ff_core_List.Empty())), ff_core_List.Empty(), ff_compiler_Syntax.EVariant(at_, "ff:core/Bool.False", ff_core_List.Empty(), ff_core_Option.None()));
|
|
814
|
+
return ff_core_List.Link(sameCase_, ff_core_List.List_addAll(sameVariantCases_, ff_core_List.Link(differentVariant_, ff_core_List.Empty())))
|
|
815
|
+
return
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
export async function Deriver_makeEqualFields$(self_, modulePrefix_, declaration_, fields_, $task) {
|
|
821
|
+
const at_ = (((_c) => {
|
|
822
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
823
|
+
}))(declaration_.at_);
|
|
824
|
+
function go_(fields_) {
|
|
825
|
+
{
|
|
826
|
+
const fields_a = fields_;
|
|
827
|
+
{
|
|
828
|
+
if(fields_a.Empty) {
|
|
829
|
+
return ff_compiler_Syntax.EVariant(at_, "ff:core/Bool.True", ff_core_List.Empty(), ff_core_Option.None())
|
|
830
|
+
return
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
{
|
|
834
|
+
if(fields_a.Link) {
|
|
835
|
+
const head_ = fields_a.head_;
|
|
836
|
+
if(fields_a.tail_.Empty) {
|
|
837
|
+
return ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Equal.equals", ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "x"), head_.name_), ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "y"), head_.name_), ff_core_List.Empty())), ff_core_List.Empty())
|
|
838
|
+
return
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
{
|
|
843
|
+
if(fields_a.Link) {
|
|
844
|
+
const head_ = fields_a.head_;
|
|
845
|
+
const tail_ = fields_a.tail_;
|
|
846
|
+
const equalsTerm_ = ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Equal.equals", ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "x"), head_.name_), ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "y"), head_.name_), ff_core_List.Empty())), ff_core_List.Empty());
|
|
847
|
+
return ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "&&", ff_core_List.Link(equalsTerm_, ff_core_List.Link(go_(tail_), ff_core_List.Empty())), ff_core_List.Empty())
|
|
848
|
+
return
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
return go_(fields_)
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
export async function Deriver_makeSerializableInstances$(self_, modulePrefix_, module_, $task) {
|
|
857
|
+
const coreWhitelist_ = ff_core_List.List_toSet(ff_core_List.Link("ff:core/Option.Option", ff_core_List.Link("ff:core/Pair.Pair", ff_core_List.Empty())), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
858
|
+
const missingInstance_ = ff_compiler_Deriver.Deriver_findTypesThatNeedInstances(self_, "ff:core/Serializable.Serializable", modulePrefix_, coreWhitelist_, true, module_);
|
|
859
|
+
return ff_core_List.List_map(missingInstance_, ((_w1) => {
|
|
860
|
+
return ff_compiler_Deriver.Deriver_makeSerializableInstance(self_, modulePrefix_, _w1)
|
|
861
|
+
}))
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
export async function Deriver_makeSerializableInstance$(self_, modulePrefix_, declaration_, $task) {
|
|
865
|
+
const at_ = (((_c) => {
|
|
866
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
867
|
+
}))(declaration_.at_);
|
|
868
|
+
const constraints_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
869
|
+
return ff_compiler_Syntax.Constraint(at_, "ff:core/Serializable.Serializable", ff_core_List.Link(ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty()), ff_core_List.Empty()))
|
|
870
|
+
}));
|
|
871
|
+
const typeArguments_ = ff_core_List.List_map(declaration_.generics_, ((t_) => {
|
|
872
|
+
return ff_compiler_Syntax.TConstructor(at_, t_, ff_core_List.Empty())
|
|
873
|
+
}));
|
|
874
|
+
const selfType_ = ff_compiler_Syntax.TConstructor(at_, ((modulePrefix_ + ".") + declaration_.name_), typeArguments_);
|
|
875
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
876
|
+
const serializationType_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Serializable.Serialization", ff_core_List.Empty());
|
|
877
|
+
const serializeSignature_ = ff_compiler_Syntax.Signature(at_, "serializeUsing", false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Link(ff_compiler_Syntax.Parameter(at_, false, "serialization", serializationType_, ff_core_Option.None()), ff_core_List.Link(ff_compiler_Syntax.Parameter(at_, false, "value", selfType_, ff_core_Option.None()), ff_core_List.Empty())), ff_compiler_Syntax.TConstructor(at_, "ff:core/Unit.Unit", ff_core_List.Empty()), noEffect_);
|
|
878
|
+
const deserializeSignature_ = ff_compiler_Syntax.Signature(at_, "deserializeUsing", false, ff_core_List.Empty(), ff_core_List.Empty(), ff_core_List.Link(ff_compiler_Syntax.Parameter(at_, false, "serialization", serializationType_, ff_core_Option.None()), ff_core_List.Empty()), selfType_, noEffect_);
|
|
879
|
+
const wildcardPattern_ = ff_compiler_Syntax.PVariable(at_, ff_core_Option.None());
|
|
880
|
+
const serializeBody_ = ff_compiler_Syntax.FireflyTarget(ff_compiler_Syntax.Lambda(at_, noEffect_, ff_compiler_Deriver.Deriver_makeSerializeBody(self_, modulePrefix_, declaration_, selfType_)));
|
|
881
|
+
const deserializeBody_ = ff_compiler_Syntax.FireflyTarget(ff_compiler_Syntax.Lambda(at_, noEffect_, ff_core_List.Link(ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(wildcardPattern_, ff_core_List.Empty()), ff_core_List.Empty(), ff_compiler_Deriver.Deriver_makeDeserializeBody(self_, modulePrefix_, declaration_, selfType_)), ff_core_List.Empty())));
|
|
882
|
+
return ff_compiler_Syntax.DInstance(at_, declaration_.generics_, constraints_, "ff:core/Serializable.Serializable", ff_core_List.Link(selfType_, ff_core_List.Empty()), ff_core_List.Empty(), ff_core_List.Link(ff_compiler_Syntax.DFunction(at_, serializeSignature_, serializeBody_), ff_core_List.Link(ff_compiler_Syntax.DFunction(at_, deserializeSignature_, deserializeBody_), ff_core_List.Empty())), true)
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
export async function Deriver_makeSerializeBody$(self_, modulePrefix_, declaration_, selfType_, $task) {
|
|
886
|
+
const at_ = (((_c) => {
|
|
887
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
888
|
+
}))(declaration_.at_);
|
|
889
|
+
const wildcardPattern_ = ff_compiler_Syntax.PVariable(at_, ff_core_Option.None());
|
|
890
|
+
return ff_core_List.List_map(ff_core_List.List_pairs(declaration_.variants_), ((_1) => {
|
|
891
|
+
{
|
|
892
|
+
const index_ = _1.first_;
|
|
893
|
+
const variant_ = _1.second_;
|
|
894
|
+
const variantName_ = ((modulePrefix_ + ".") + variant_.name_);
|
|
895
|
+
const fields_ = ff_core_List.List_addAll(declaration_.commonFields_, variant_.fields_);
|
|
896
|
+
const updateChecksum_ = ff_compiler_Deriver.Deriver_makeUpdateChecksum(self_, at_, variantName_, declaration_, variant_);
|
|
897
|
+
const setVariantIndex_ = ff_compiler_Deriver.Deriver_makeMethodCall(self_, at_, ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "serialization"), "buffer"), "setUint8", ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "serialization"), "offset"), ff_core_List.Link(ff_compiler_Syntax.EInt(at_, ("" + index_)), ff_core_List.Empty())));
|
|
898
|
+
const fieldSerializations_ = ff_core_List.List_map(fields_, ((field_) => {
|
|
899
|
+
return ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Serializable.serializeUsing", ff_core_List.Link(ff_compiler_Syntax.EVariable(at_, "serialization"), ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "v"), field_.name_), ff_core_List.Empty())), ff_core_List.Empty())
|
|
900
|
+
}));
|
|
901
|
+
return ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(wildcardPattern_, ff_core_List.Link(ff_compiler_Syntax.PVariantAs(at_, variantName_, at_, ff_core_Option.Some("v")), ff_core_List.Empty())), ff_core_List.Empty(), ff_core_List.List_foldLeft(ff_core_List.Link(setVariantIndex_, ff_core_List.Link(ff_compiler_Syntax.EAssignField(at_, "+", ff_compiler_Syntax.EVariable(at_, "serialization"), "offset", ff_compiler_Syntax.EInt(at_, "1")), fieldSerializations_)), updateChecksum_, ((_w1, _w2) => {
|
|
902
|
+
return ff_compiler_Syntax.ESequential(at_, _w1, _w2)
|
|
903
|
+
})))
|
|
904
|
+
return
|
|
905
|
+
}
|
|
906
|
+
}))
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
export async function Deriver_makeDeserializeBody$(self_, modulePrefix_, declaration_, selfType_, $task) {
|
|
910
|
+
const at_ = (((_c) => {
|
|
911
|
+
return ff_compiler_Syntax.Location((declaration_.at_.file_ + "/<derived>"), _c.line_, _c.column_)
|
|
912
|
+
}))(declaration_.at_);
|
|
913
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
914
|
+
const wildcardPattern_ = ff_compiler_Syntax.PVariable(at_, ff_core_Option.None());
|
|
915
|
+
const grabVariantIndex_ = ff_compiler_Deriver.Deriver_makeMethodCall(self_, at_, ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "serialization"), "buffer"), "grabUint8", ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "serialization"), "offset"), ff_core_List.Empty()));
|
|
916
|
+
const intType_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Int.Int", ff_core_List.Empty());
|
|
917
|
+
const incrementOffset_ = ff_compiler_Syntax.EAssignField(at_, "+", ff_compiler_Syntax.EVariable(at_, "serialization"), "offset", ff_compiler_Syntax.EInt(at_, "1"));
|
|
918
|
+
const cases_ = ff_core_List.List_map(ff_core_List.List_pairs(declaration_.variants_), ((_1) => {
|
|
919
|
+
{
|
|
920
|
+
const index_ = _1.first_;
|
|
921
|
+
const variant_ = _1.second_;
|
|
922
|
+
const variantName_ = ((modulePrefix_ + ".") + variant_.name_);
|
|
923
|
+
const fields_ = ff_core_List.List_addAll(declaration_.commonFields_, variant_.fields_);
|
|
924
|
+
const fieldValues_ = ff_core_List.List_map(fields_, ((field_) => {
|
|
925
|
+
return ff_compiler_Syntax.Argument(at_, ff_core_Option.None(), ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Serializable.deserializeUsing", ff_core_List.Link(ff_compiler_Syntax.EVariable(at_, "serialization"), ff_core_List.Empty()), ff_core_List.Empty()))
|
|
926
|
+
}));
|
|
927
|
+
const updateChecksum_ = ff_compiler_Deriver.Deriver_makeUpdateChecksum(self_, at_, variantName_, declaration_, variant_);
|
|
928
|
+
const makeVariant_ = ff_compiler_Syntax.EVariant(at_, variantName_, ff_core_List.Empty(), ff_core_Option.Some(fieldValues_));
|
|
929
|
+
return ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(ff_compiler_Syntax.PInt(at_, ("" + index_)), ff_core_List.Empty()), ff_core_List.Empty(), ff_compiler_Syntax.ESequential(at_, updateChecksum_, makeVariant_))
|
|
930
|
+
return
|
|
931
|
+
}
|
|
932
|
+
}));
|
|
933
|
+
const otherwiseCase_ = ff_compiler_Syntax.MatchCase(at_, ff_core_List.Link(wildcardPattern_, ff_core_List.Empty()), ff_core_List.Empty(), ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "ff:core/Core.throw", ff_core_List.Link(ff_compiler_Syntax.EVariant(at_, "ff:core/Serializable.DeserializationChecksumException", ff_core_List.Empty(), ff_core_Option.None()), ff_core_List.Empty()), ff_core_List.Empty()));
|
|
934
|
+
const matchLambda_ = ff_compiler_Syntax.ELambda(at_, ff_compiler_Syntax.Lambda(at_, noEffect_, ff_core_List.List_addAll(cases_, ff_core_List.Link(otherwiseCase_, ff_core_List.Empty()))));
|
|
935
|
+
const match_ = ff_compiler_Syntax.EPipe(at_, ff_compiler_Syntax.EVariable(at_, "variantIndex"), noEffect_, matchLambda_);
|
|
936
|
+
return ff_compiler_Syntax.ELet(at_, false, "variantIndex", intType_, grabVariantIndex_, ff_compiler_Syntax.ESequential(at_, incrementOffset_, match_))
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
export async function Deriver_makeUpdateChecksum$(self_, at_, variantName_, declaration_, variant_, $task) {
|
|
940
|
+
const fields_ = ff_core_List.List_addAll(declaration_.commonFields_, variant_.fields_);
|
|
941
|
+
const variantChecksum_ = ff_core_String.String_size(variantName_);
|
|
942
|
+
return ff_compiler_Syntax.EAssignField(at_, "", ff_compiler_Syntax.EVariable(at_, "serialization"), "checksum", ff_compiler_Deriver.Deriver_makeMethodCall(self_, at_, ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "+", ff_core_List.Link(ff_compiler_Deriver.Deriver_makeSimpleCall(self_, at_, "*", ff_core_List.Link(ff_compiler_Syntax.EInt(at_, "31"), ff_core_List.Link(ff_compiler_Syntax.EField(at_, false, ff_compiler_Syntax.EVariable(at_, "serialization"), "checksum"), ff_core_List.Empty())), ff_core_List.Empty()), ff_core_List.Link(ff_compiler_Syntax.EInt(at_, ("" + variantChecksum_)), ff_core_List.Empty())), ff_core_List.Empty()), "bitOr", ff_core_List.Link(ff_compiler_Syntax.EInt(at_, "0"), ff_core_List.Empty())))
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
export async function Deriver_findTypesThatNeedInstances$(self_, traitName_, modulePrefix_, coreWhitelist_, allowGenerics_, module_, $task) {
|
|
946
|
+
const typesWithInstance_ = ff_core_List.List_toSet(ff_core_List.List_collect(module_.instances_, ((_1) => {
|
|
947
|
+
{
|
|
948
|
+
const instance_ = _1;
|
|
949
|
+
const _guard1 = ff_core_List.List_first(instance_.typeArguments_);
|
|
950
|
+
if(_guard1.Some) {
|
|
951
|
+
if(_guard1.value_.TConstructor) {
|
|
952
|
+
const name_ = _guard1.value_.name_;
|
|
953
|
+
if((instance_.traitName_ === traitName_)) {
|
|
954
|
+
return ff_core_Option.Some(name_)
|
|
955
|
+
} else return ff_core_Option.None()
|
|
956
|
+
return
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
{
|
|
961
|
+
return ff_core_Option.None()
|
|
962
|
+
return
|
|
963
|
+
}
|
|
964
|
+
})), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
|
|
965
|
+
return ff_core_List.List_filter(module_.types_, ((t_) => {
|
|
966
|
+
return (((((((ff_compiler_Syntax.PackagePair_groupName(module_.packagePair_, ":") !== "ff:core") || ff_core_Set.Set_contains(coreWhitelist_, ((modulePrefix_ + ".") + t_.name_), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String)) && (!ff_core_Option.Option_any(ff_core_List.List_first(t_.generics_), ((_w1) => {
|
|
967
|
+
return (_w1 === "Q$")
|
|
968
|
+
})))) && (allowGenerics_ || ff_core_List.List_isEmpty(t_.generics_))) && t_.data_) && (!t_.newtype_)) && (!ff_core_Set.Set_contains(typesWithInstance_, ((modulePrefix_ + ".") + t_.name_), ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String)))
|
|
969
|
+
}))
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
export async function Deriver_makeSimpleCall$(self_, at_, name_, arguments_, typeArguments_ = ff_core_List.Empty(), $task) {
|
|
973
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
974
|
+
const callTarget_ = ff_compiler_Syntax.DynamicCall(ff_compiler_Syntax.EVariable(at_, name_), false);
|
|
975
|
+
return ff_compiler_Syntax.ECall(at_, callTarget_, noEffect_, typeArguments_, ff_core_List.List_map(arguments_, ((e_) => {
|
|
976
|
+
return ff_compiler_Syntax.Argument(at_, ff_core_Option.None(), e_)
|
|
977
|
+
})), ff_core_List.Empty())
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
export async function Deriver_makeMethodCall$(self_, at_, target_, methodName_, arguments_, $task) {
|
|
981
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
982
|
+
const method_ = ff_compiler_Syntax.EField(at_, false, target_, methodName_);
|
|
983
|
+
return ff_compiler_Syntax.ECall(at_, ff_compiler_Syntax.DynamicCall(method_, false), noEffect_, ff_core_List.Empty(), ff_core_List.List_map(arguments_, ((_w1) => {
|
|
984
|
+
return ff_compiler_Syntax.Argument(at_, ff_core_Option.None(), _w1)
|
|
985
|
+
})), ff_core_List.Empty())
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
export async function Deriver_makeIf$(self_, at_, condition_, then_, else_, $task) {
|
|
989
|
+
const noEffect_ = ff_compiler_Syntax.TConstructor(at_, "ff:core/Nothing.Nothing", ff_core_List.Empty());
|
|
990
|
+
const target_ = ff_compiler_Syntax.DynamicCall(ff_compiler_Syntax.EVariable(at_, "ff:core/Core.if"), false);
|
|
991
|
+
const option_ = ff_compiler_Syntax.ECall(at_, target_, noEffect_, ff_core_List.Empty(), ff_core_List.Link(ff_compiler_Syntax.Argument(at_, ff_core_Option.None(), condition_), ff_core_List.Link(ff_compiler_Syntax.Argument(at_, ff_core_Option.None(), ff_compiler_Syntax.ELambda(at_, ff_compiler_Syntax.Lambda(at_, noEffect_, ff_core_List.Link(ff_compiler_Syntax.MatchCase(at_, ff_core_List.Empty(), ff_core_List.Empty(), then_), ff_core_List.Empty())))), ff_core_List.Empty())), ff_core_List.Empty());
|
|
992
|
+
return ff_compiler_Syntax.ECall(at_, ff_compiler_Syntax.DynamicCall(ff_compiler_Syntax.EField(at_, false, option_, "else"), false), noEffect_, ff_core_List.Empty(), ff_core_List.Link(ff_compiler_Syntax.Argument(at_, ff_core_Option.None(), ff_compiler_Syntax.ELambda(at_, ff_compiler_Syntax.Lambda(at_, noEffect_, ff_core_List.Link(ff_compiler_Syntax.MatchCase(at_, ff_core_List.Empty(), ff_core_List.Empty(), else_), ff_core_List.Empty())))), ff_core_List.Empty()), ff_core_List.Empty())
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
export const ff_core_Any_HasAnyTag$ff_compiler_Deriver_Deriver = {
|
|
996
|
+
anyTag_() {
|
|
997
|
+
return ff_core_Any.internalAnyTag_((("ff:compiler/Deriver.Deriver" + "[") + "]"))
|
|
998
|
+
},
|
|
999
|
+
async anyTag_$($task) {
|
|
1000
|
+
return ff_core_Any.internalAnyTag_((("ff:compiler/Deriver.Deriver" + "[") + "]"))
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
|
|
1004
|
+
export const ff_core_Show_Show$ff_compiler_Deriver_Deriver = {
|
|
1005
|
+
show_(value_) {
|
|
1006
|
+
{
|
|
1007
|
+
const value_a = value_;
|
|
1008
|
+
{
|
|
1009
|
+
const z_ = value_a;
|
|
1010
|
+
return "Deriver"
|
|
1011
|
+
return
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
},
|
|
1015
|
+
async show_$(value_, $task) {
|
|
1016
|
+
{
|
|
1017
|
+
const value_a = value_;
|
|
1018
|
+
{
|
|
1019
|
+
const z_ = value_a;
|
|
1020
|
+
return "Deriver"
|
|
1021
|
+
return
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
};
|
|
1026
|
+
|
|
1027
|
+
export const ff_core_Equal_Equal$ff_compiler_Deriver_Deriver = {
|
|
1028
|
+
equals_(x_, y_) {
|
|
1029
|
+
{
|
|
1030
|
+
const x_a = x_;
|
|
1031
|
+
const y_a = y_;
|
|
1032
|
+
{
|
|
1033
|
+
const _guard1 = (x_ === y_);
|
|
1034
|
+
if(_guard1) {
|
|
1035
|
+
return true
|
|
1036
|
+
return
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
{
|
|
1040
|
+
return true
|
|
1041
|
+
return
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
},
|
|
1045
|
+
async equals_$(x_, y_, $task) {
|
|
1046
|
+
{
|
|
1047
|
+
const x_a = x_;
|
|
1048
|
+
const y_a = y_;
|
|
1049
|
+
{
|
|
1050
|
+
const _guard1 = (x_ === y_);
|
|
1051
|
+
if(_guard1) {
|
|
1052
|
+
return true
|
|
1053
|
+
return
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
{
|
|
1057
|
+
return true
|
|
1058
|
+
return
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
};
|
|
1063
|
+
|
|
1064
|
+
export const ff_core_Ordering_Order$ff_compiler_Deriver_Deriver = {
|
|
1065
|
+
compare_(x_, y_) {
|
|
1066
|
+
{
|
|
1067
|
+
const x_a = x_;
|
|
1068
|
+
const y_a = y_;
|
|
1069
|
+
{
|
|
1070
|
+
const _guard1 = (x_ === y_);
|
|
1071
|
+
if(_guard1) {
|
|
1072
|
+
return ff_core_Ordering.OrderingSame()
|
|
1073
|
+
return
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
{
|
|
1077
|
+
return ff_core_Ordering.OrderingSame()
|
|
1078
|
+
return
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
},
|
|
1082
|
+
async compare_$(x_, y_, $task) {
|
|
1083
|
+
{
|
|
1084
|
+
const x_a = x_;
|
|
1085
|
+
const y_a = y_;
|
|
1086
|
+
{
|
|
1087
|
+
const _guard1 = (x_ === y_);
|
|
1088
|
+
if(_guard1) {
|
|
1089
|
+
return ff_core_Ordering.OrderingSame()
|
|
1090
|
+
return
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
{
|
|
1094
|
+
return ff_core_Ordering.OrderingSame()
|
|
1095
|
+
return
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
|
|
1101
|
+
export const ff_core_Serializable_Serializable$ff_compiler_Deriver_Deriver = {
|
|
1102
|
+
serializeUsing_(serialization_, value_) {
|
|
1103
|
+
{
|
|
1104
|
+
const serialization_a = serialization_;
|
|
1105
|
+
const value_a = value_;
|
|
1106
|
+
{
|
|
1107
|
+
const v_ = value_a;
|
|
1108
|
+
serialization_.checksum_ = ff_core_Int.Int_bitOr(((31 * serialization_.checksum_) + 27), 0);
|
|
1109
|
+
ff_core_Buffer.Buffer_setUint8(serialization_.buffer_, serialization_.offset_, 0);
|
|
1110
|
+
serialization_.offset_ += 1
|
|
1111
|
+
return
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
},
|
|
1115
|
+
deserializeUsing_(serialization_) {
|
|
1116
|
+
const variantIndex_ = ff_core_Buffer.Buffer_grabUint8(serialization_.buffer_, serialization_.offset_);
|
|
1117
|
+
serialization_.offset_ += 1;
|
|
1118
|
+
{
|
|
1119
|
+
const _1 = variantIndex_;
|
|
1120
|
+
{
|
|
1121
|
+
if(_1 == 0) {
|
|
1122
|
+
serialization_.checksum_ = ff_core_Int.Int_bitOr(((31 * serialization_.checksum_) + 27), 0);
|
|
1123
|
+
return ff_compiler_Deriver.Deriver()
|
|
1124
|
+
return
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
{
|
|
1128
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_core_Serializable.DeserializationChecksumException(), ff_core_Serializable.ff_core_Any_HasAnyTag$ff_core_Serializable_DeserializationChecksumException)})
|
|
1129
|
+
return
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
},
|
|
1133
|
+
async serializeUsing_$(serialization_, value_, $task) {
|
|
1134
|
+
{
|
|
1135
|
+
const serialization_a = serialization_;
|
|
1136
|
+
const value_a = value_;
|
|
1137
|
+
{
|
|
1138
|
+
const v_ = value_a;
|
|
1139
|
+
serialization_.checksum_ = ff_core_Int.Int_bitOr(((31 * serialization_.checksum_) + 27), 0);
|
|
1140
|
+
ff_core_Buffer.Buffer_setUint8(serialization_.buffer_, serialization_.offset_, 0);
|
|
1141
|
+
serialization_.offset_ += 1
|
|
1142
|
+
return
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
},
|
|
1146
|
+
async deserializeUsing_$(serialization_, $task) {
|
|
1147
|
+
const variantIndex_ = ff_core_Buffer.Buffer_grabUint8(serialization_.buffer_, serialization_.offset_);
|
|
1148
|
+
serialization_.offset_ += 1;
|
|
1149
|
+
{
|
|
1150
|
+
const _1 = variantIndex_;
|
|
1151
|
+
{
|
|
1152
|
+
if(_1 == 0) {
|
|
1153
|
+
serialization_.checksum_ = ff_core_Int.Int_bitOr(((31 * serialization_.checksum_) + 27), 0);
|
|
1154
|
+
return ff_compiler_Deriver.Deriver()
|
|
1155
|
+
return
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
{
|
|
1159
|
+
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_core_Serializable.DeserializationChecksumException(), ff_core_Serializable.ff_core_Any_HasAnyTag$ff_core_Serializable_DeserializationChecksumException)})
|
|
1160
|
+
return
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
};
|
|
1165
|
+
|
|
1166
|
+
|