Skip to content

Commit ac8d1b6

Browse files
committed
types
1 parent f779160 commit ac8d1b6

File tree

11 files changed

+88
-124
lines changed

11 files changed

+88
-124
lines changed

doc/language/data_model.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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

doc/language/syntax/argument_declaration.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22

33
## Syntax
44

5-
[_binding_mode_](binding_mode.md)__?__ [_name_](name.md) [_type_declaration_](type_declaration.md)__?__
6-
__(__ `=` [_expression_](expression.md) __)?__ __|__\
5+
[_binding_mode_]__?__ [_name_] [_type-annotation_]__?__ __(__ `=` [_expression_] __)?__ __|__\
76

8-
[_literal_](literal.md) [_type_declaration_](type_declaration.md)__?__ __|__\
7+
[_literal_] [_type-annotation_]__?__ __|__\
98

10-
`(` [_expression_](expression.md) `)` [_type_declaration_](type_declaration.md)__?__ __|__\
9+
`(` [_expression_] `)` [_type-annotation_]__?__ __|__\
1110

12-
[_binding_mode_](binding_mode.md)__?__ [_name_](name.md)`...` [_type_declaration_](type_declaration.md)__?__
11+
[_binding_mode_]__?__ [_name_]`...` [_type-annotation_]__?__
1312

13+
[_type-annotation_]: type_annotation.md
14+
[_binding_mode_]: binding_mode.md
15+
[_expression_]: expression.md
16+
[_literal_]: literal.md
17+
[_name_]: name.md
1418

1519
## Semantics
1620
Declares an argument for a function or lambda with a [_name_](name.md)

doc/language/syntax/attributes.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,19 @@ This function will not return.
4040
An implementation must terminate the application if the function does
4141
return. Or proof that the function will not return.
4242

43-
### pre()
43+
### pre(expression)
4444
Pre-condition is checked before calling the function.
4545

46-
### post()
46+
### post(expression)
4747
Post-condition is checked after calling the function.
4848

4949
A post-condition on a type will run after an object is modified.
5050

51+
### constrain(expression)
52+
A condition that is checked when matching if the template arguments
53+
are valid for this specific overload in the overload-set.
54+
55+
Constrain can also contain guard conditions.
5156

5257
### std.no_inline
5358
Calls to this function are never inlined.

doc/language/syntax/enum_definition.md

Lines changed: 0 additions & 55 deletions
This file was deleted.

doc/language/syntax/enum_name.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

doc/language/syntax/enum_name_list.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

doc/language/syntax/expression.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[_tag_](tag.md) __|__
99
[_context-argument_](context_argument.md) __|__
1010
[_positional-argument_](positional_argument.md) __|__
11-
[_variable-declaration_](variable_declaration.md) __|__
11+
[_variable-definition_](variable_definition.md) __|__
1212
[_operator-expression_](operator_expression.md) __|__
1313
[_if-control-expression_](if_control_expression.md) __|__
1414
[_while-control-expression_](while_control_expression.md) __|__
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# type-declaration
1+
# type-annotation
22

33
## Syntax
44

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# type-members
2+
3+
## Syntax
4+
5+
[_function-definition_](function_definition.md) __|__
6+
[_type-definition_](type_definition.md) __|__
7+
[_variant-definition_](variant_definition.md) __|__
8+
[_variable-definition_](variable_definition.md)

doc/language/syntax/variable_declaration.md renamed to doc/language/syntax/variable_definition.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# variable-declaration
1+
# variable-definition
22

33
## Syntax
44

0 commit comments

Comments
 (0)