1 | Features:
|
---|
2 | * Struct, function (no inline), variables
|
---|
3 | * The only definition we need to handle exporting here is struct. typedef, traits, forall, inline functions, we'll look into those later
|
---|
4 | * Also no `export import` (ie. modules that export other module's contents automatically)
|
---|
5 | * int, int*, const int
|
---|
6 | * No extra built-in types considered here
|
---|
7 | * No `#include`
|
---|
8 | * No manual control over headers demonstrated in example, everything handled in `module`, `import`, `export`
|
---|
9 | * No forward decls
|
---|
10 | * All definitions within modules, with declarations automatically hoisted to the top
|
---|
11 | * Note: this requires top-level declarations to be context-free
|
---|
12 |
|
---|
13 | Stylistic choices:
|
---|
14 | * `module;` doesn't specify a namespace (prefix with file path)
|
---|
15 | * folder files like `graph.cfa` are outside their folders (simplifies the import file discovery algorithm)
|
---|
16 | * `import` uses no quotes/angle brackets (unlike `#include`)
|
---|
17 | * `import` automatically opens the namespace (keeping it closed can be tricky with transitive dependencies)
|
---|
18 | * `stdio` and other standard C libraries have `import` versions
|
---|
19 | * `main.cfa` is not a module (avoid module namespacing interfering with `main()` symbol discovery)
|
---|
20 |
|
---|
21 | Step-by-step:
|
---|
22 | * `0_initial` is the code that is written by the developer
|
---|
23 | * Note how modules seem to have circular dependencies (eg. `graph/node.c` imports `graph/edge.c` and vice versa)
|
---|
24 | * Top-level declarations within modules can also be declared out-of-order (eg. using `a` before `const int a = 4;`)
|
---|
25 | * `1_size_analysis` describes a mechanism for figuring out sizes and alignments of types
|
---|
26 | * There could also be an attribute system for indicating a desired size and alignment for a given type (not shown here)
|
---|
27 | * `2_tshell` generates the type shell headers
|
---|
28 | * These allow importers to avoid unnecessary dependencies to other modules
|
---|
29 | * eg. if module `A` imports `B`, and `B` imports `C`, then a change to a function in `C` should not cause `A` to recompile
|
---|
30 | * `3_export` generates the headers that are imported
|
---|
31 | * Type shells are used in the functions, variables, type definitions
|
---|
32 | * The actual type comes with an implicit zero-cost conversion between it and its type shell
|
---|
33 | * Also note an expansion of the constant `max_edges_per_node` in `graph/node__export.h`
|
---|
34 | * `4_impl` generates the implementations
|
---|
35 | * Insert conversions whenever fields of a type are accessed (read or write, though constructors are tricky)
|
---|
36 | * Note that type-punning (eg. `(*(struct S*)&a)`) may not be safe due to [strict aliasing](https://cellperformance.beyond3d.com/articles/2006/06/understanding-strict-aliasing.html) and size/alignment rules not being enforced by the spec
|
---|
37 | * I also don't think I caught every cast (it's enough to compile)
|
---|
38 | * We also move constants and type definitions not already in `__export.h` to the top, as well as adding function declarations
|
---|
39 | * This is what allows top-level declarations to be out-of-order
|
---|
40 | * `5_tweaking` alters the library imports to make it compile
|
---|
41 | * ie. `#include <stdio.h>` instead of `#include <stdio__export.h>`
|
---|
42 |
|
---|
43 | Advanced considerations:
|
---|
44 | * No private fields, though opaque types can be made
|
---|
45 | * Hoisting occuring at top-level, what about within functions?
|
---|
46 | * How does update logic work?
|
---|
47 | * No module interface logic here (ie. strong module split)
|
---|
48 | * How much of compilation is centrally controlled (ie. by a file that keeps track of the entire project's dependencies)?
|
---|
49 | * `__tshell.h` changes every time a new type is added, but a central file can check if importing files actually need recompilation
|
---|
50 | * Extra details: How to perform a unity build? Static/dynamic library generation and management?
|
---|
51 | * Aside: Uniform function call syntax
|
---|