You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -49,12 +46,13 @@ I'm no famous artist but this is my magnum opus, so it'll not be abandoned anyti
49
46
- Operator overloading
50
47
- Generic functions and types
51
48
- Type inference (including for generics)
49
+
- Full compile-time execution (of arbitrary code)
52
50
53
51
-----------------------------------------------
54
52
55
53
56
54
### Language Syntax
57
-
- See https://flax-lang.github.io (incomplete)
55
+
- See https://flax-lang.github.io (incomplete, outdated, obsolete, etc. etc.)
58
56
59
57
-----------------------------------------------
60
58
@@ -96,36 +94,33 @@ do {
96
94
### Building the Flax compiler
97
95
98
96
#### Dependencies ####
99
-
- LLVM 7, mostly due to their obsession with changing the IR interface every damn version (6 does not work, 8 does not work)
97
+
- LLVM 7, mostly due to their obsession with changing the IR interface every damn version
100
98
- GMP/MPIR
101
99
- MPFR
100
+
- libffi
102
101
103
102
104
103
#### macOS / Linux
105
104
106
-
- Flax uses a makefile; most likely some form of GNU-compatible `make` will work.
107
-
- LLVM needs to be installed. On macOS, `brew install llvm@7` should work. (note: llvm 8 and up seems to have changed some JIT-related things)
108
-
- For macOS people, simply call `make`.
109
-
- Linux people, call `make linux`.
105
+
- The `makefile` is the preferred way to build on UNIX systems.
106
+
- LLVM needs to be installed. On macOS, `brew install llvm@7` should work, and you might need to do some PPA fiddling for Debian-based distros.
110
107
- A *C++17*-compatible compiler should be used.
111
108
- Find the `flaxc` executable in `build/sysroot/usr/local/bin`
112
109
- Additionally, the (admittedly limited) standard library will be copied from `./libs` to `./build/sysroot/usr/local/lib/flaxlibs/`
113
110
114
111
115
112
#### Windows
116
113
117
-
##### Option 1
118
-
- Install [meson](https://mesonbuild.com/)
119
-
- Edit `meson.build` variables to tell it where to find the libraries -- notably, these are needed: [`libmpir`](http://mpir.org), [`libmpfr`](http://mpfr.org), and most importantly, [`libllvm`](http://llvm.org). Follow the build instructions for each library, preferably generating both Debug and Release *static* libraries.
120
-
- Run `meson build\meson-dbg` (where ever you want, really), followed by `ninja -C build\meson-dbg`.
121
-
-`flaxc.exe` will be in `build\meson-dbg`.
122
-
- Build and profit, hopefully.
114
+
- Install [meson](https://mesonbuild.com/).
115
+
- Run `env MPIR_ROOT_DIR=... LLVM_ROOT_DIR=... meson meson-build-dir` to set the locations for the dependencies (see `meson.build` for the names, there are 4) and configure the build.
116
+
- Optionally, pass `--buildtype=release` to build a release-mode compiler (highly recommended)
117
+
- Run `ninja -C meson-build-dir`.
118
+
-`flaxc.exe` will be found in the build directory.
119
+
120
+
##### Libraries
121
+
- Download the [prebuilt binaries](https://github.com/flax-lang/flax/releases/tag/win-build-deps) for the 4 dependencies, and place them somewhere.
122
+
- Note: the folder structure of the libraries should be `(llvm|mpir|mpfr|libffi)/(Release|Debug)/(include|lib)/...`
123
123
124
-
##### Option 2
125
-
- Download the [prebuilt binaries](https://github.com/flax-lang/flax/releases/download/win-build-deps/libraries.zip) for LLVM, MPIR, and MPFR.
126
-
- Set the following environment variables: `DEPS_DBG_INCLUDES_DIR`, `DEPS_DBG_LIBS_DIR`, `DEPS_REL_INCLUDES_DIR`, and `DEPS_REL_LIBS_DIR`. Point them to the location of the libraries you just downloaded. (Look in `appveyor.yml` to see what they should contain -- essentially the include and library paths for `msbuild` to find)
127
-
- Note: the folder structure of the libraries should be `(llvm|mpir|mpfr)/Release/(include|lib)/...`
128
-
- Run `msbuild /p:Configuration=Release`
129
124
130
125
-----------------------------------------------
131
126
@@ -142,55 +137,7 @@ do {
142
137
143
138
### Contributing
144
139
145
-
- Found a bug? Want a feature? Just submit a pull request!
146
-
147
-
148
-
-----------------------------------------------
149
-
150
-
151
-
### Compiler Architecture
152
-
153
-
Some stuff about the compiler itself, now. As any noob looking to build a compiler would do, I used the [LLVM Kaleidoscope tutorial](http://llvm.org/docs/tutorial/) as a starting point. Naturally, it being a tutorial did no favours for the code cleanliness and organisation of the Flax compiler.
154
-
155
-
Flax itself has 4 main passes -- Lexing, Parsing, Typechecking, and finally Codegen. Yes that's right, the shitty typecheck-and-codegen-at-the-same-time architecture of old has been completely replaced!
156
-
157
-
158
-
#### Tokenising and Lexing
159
-
160
-
This isn't terribly complicated. Each file is naturally only looked at once, and a list of tokens and raw lines are stored somewhere. There's always a nagging feeling that token location reporting is flawed, and it probably is.
161
-
162
-
EDIT: It is.
163
-
164
-
165
-
#### Parsing
166
-
167
-
Broadly speaking this is a recursive descent parser, handwritten. Not terribly efficient, but whatever. This step creates the AST nodes for the next step, although there are some hacks to enable custom operators, which should probably be reimplemented sometime soon.
168
-
169
-
170
-
171
-
#### Typechecking
172
-
173
-
At this stage, each AST node that the parser produced is traversed, at the file-level. AST nodes are transformed through a typechecking phase into SST nodes (the original meaning of this initialism has been lost). This typechecking consists of solidifying `pts::Type`s into `fir::Type`s; given that the former is simply a stripped-down version of the latter, this is natural.
174
-
175
-
SST nodes are just AST nodes with refinements; identifiers are resolved to their targets, and function calls also find their intended target here.
176
-
177
-
Before the rewrite, this used to happen in an intertwined fashion with code generation, which definitely wasn't pretty.
178
-
179
-
180
-
181
-
#### Code Generation
182
-
183
-
After each file is typechecked, the collector forcibly squishes them together into a single unit, combining the necessary definitions from other files that were imported -- code generation happens at the program level.
184
-
185
-
During code generation, we output 'Flax Intermediate Representation', or 'FIR'. It's basically a layer on top of LLVM that preserves much of its interface, with some light abstractions built on top. This is where AST nodes actually get transformed into instructions.
186
-
187
-
Part of the purpose for FIR was to decouple from LLVM, and partly to allow compile-time execution in the future, which would definitely be easier with our own IR (mainly to send and retrieve values across the compiler <> IR boundary).
188
-
189
-
190
-
191
-
#### Translation
192
-
193
-
After a `fir::Module` is produced by the code generator, we 'translate' this into LLVM code. The entire process can be seen in `source/backend/llvm/translator.cpp`, and clearly we basically cloned the LLVM interface here, which makes it easy to translate into LLVM.
140
+
- Any and all issues and pull requests are welcome!
0 commit comments