@@ -16,47 +16,47 @@ Here are a couple of rules in this language:
1616
1717## Templates
1818
19- Function and type definitions are always templates in this language.
19+ All function-, type- and (global) variables-definitions are templates. One or more
20+ definitions with different signatures with the same name form a overload-set.
21+
22+ Each of the following functions form the ` foo ` overload-set:
23+ ```
24+ fn foo(x: int) { return x + 42 }
25+ fn foo(x) { return x + 1 }
26+ fn foo() { return 0 }
27+ ```
28+
29+ Both of the following type-templates form the ` bar ` overload-set:
30+ ```
31+ struct bar[T: type] { var x : T }
32+ struct bar { var x : int }
33+ ```
34+
35+ Both of the following global variable-templates form the ` qux ` overload-set.
36+ ` qux_init() ` is evaluated at compile time if possible:
37+ ```
38+ var[T: type] qux : T = qux_init(T)
39+ var qux : int = qux_init(int)
40+ ```
41+
42+ An overload set is lazilly evaluated, which means they may be modified after the
43+ definition. This makes it possible to add members to a type after its definition
44+ and even by a different module or repository. After a overload set is frozen
45+ it can no longer be modified.
46+
47+ ### Freezing
48+
49+ These are the main ways that a overload-set becomes frozen:
50+ - Code-statements at file level will cause overload-sets that are used
51+ to be frozen.
52+ - After a ` program ` is parsed the ` main() ` function is compiled and
53+ overload-sets that are used will be frozen.
54+ - After a ` library ` is parsed all the exported functions and
55+ global-variables are compiled and overload-sets that are used will be frozen.
56+ - Recursively all type annotations used in the signatures of an overload
57+ set are frozen.
2058
2159
22- ## Overload sets
23-
24-
25-
26-
27- ## Compilation Order
28-
29- The compilation order is important when we are describing how the compiler
30- knows which types are visible and complete.
31-
32- Compilation starts after the prologue-scan which will read every source file
33- in the repository and each imported repository.
34-
35- Each file is then compiled in random order while satisfying that all imported
36- modules of a file are compiled first. In incremental/language server mode,
37- files may trigger recompilation of files and their dependent files.
38-
39- Each file is compiled statement-by-statement, as-if they executed in a
40- interpreter, for example:
41- - type-template definition.
42- - function-template definition.
43- - global variable definition.
44- - executable statements
45-
46- > [ !NOTE]
47- > All types and function declarations are templates in this language.
48-
49- At this time function and type declarations remain in their "modifiable" state,
50- this means:
51- - Other versions of type and functions can be added to the overload set.
52- - It is possible to modify types by removing and adding members to types,
53- as-if types are mutable values.
54-
55- During the statement-by-statement compilation there may also be normal code
56- statments at file scope that will be executed that for example can make these
57- modifications of types. These code statements can cause types and functions
58- to transition to "frozen" and "instantiated" state.
59-
6060
6161
6262## Functions
0 commit comments