6 ms·
Compiling at Compile Time
- windsurfer 7y agoThis is horrifying and awesome.
- sansnomme 7y agoIn Nim: https://howistart.org/posts/nim/1/ https://howistart.org/posts/nim/1/
- jeff_ciesielski 7y agoI wrote something similar a while back (also in nim): https://github.com/Jeff-Ciesielski/synesthesia https://github.com/Jeff-Ciesielski/synesthesia When I stop being so darn busy, I do want to revisit my original project of doing the same thing for a FORTH derivative.
- rurban 7y agoOnly lisp macros, no magic
- keyle 7y agoPosts like these is why I read HN religiously!
- gnulinux 7y agoHah, remember doing this in C++ templates when I learned C++ metaprogramming is Turing complete, back in high school. Named my library yabi "yet another brainfuck implementation". Simpler times.
- rgoulter 7y agoSee also: Compile-Time Snake https://github.com/mattbierner/STT-C-Compile-Time-Snake https://github.com/mattbierner/STT-C-Compile-Time-Snake
- hr0m 7y agoIn D with D "mixins": https://github.com/m3m0ry/drainfuck https://github.com/m3m0ry/drainfuck
- Doxin 7y agoYou might be better off linking directly to the source code: https://github.com/m3m0ry/drainfuck/blob/master/source/app.d https://github.com/m3m0ry/drainfuck/blob/master/source/app.d For people unfamiliar with D, a mixin is essentially equivalent to compile-time eval. you call mixin() with a string, that call then gets replaced with that string compiled as D code. Combine that with the fact that you can run arbitrary code at compile time in D and you get brainfuck-as-a-DSL in 27 lines of code.
- w-m 7y agoAnd then there's this compile-time C compiler implemented as C++14 constant expressions of course: https://github.com/keiichiw/constexpr-8cc https://github.com/keiichiw/constexpr-8cc Can be only months now, until somebody combines a constexpr compile-time C-to-WASM compiler with a constexpr compile-time WASM interpreter to run any software ever written, at compile time..
- lonelappde 7y agoThat would require emulating all syscalls (side-effects) to get a mock of the Real World inside the compile time environment.
- enriquto 7y agothe path to glory is a long and arduous one
- ephaeton 7y ago"At runtime, we could use cond for that, but since that is a macro as well, we can’t use it at compile time." D'oh. Who writes a lisp with macros where you can't use macros at macro-expansion-time??