Hacker News new | past | comments | ask | show | jobs | submit login
Compiling at Compile Time (veitheller.de)
95 points by luu on Nov 7, 2019 | hide | past | favorite | 15 comments



"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??



I wrote something similar a while back (also in nim): 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.


This is horrifying and awesome.



Hah, 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.



You might be better off linking directly to the source code: 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.


And then there's this compile-time C compiler implemented as C++14 constant expressions of course:

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..


That would require emulating all syscalls (side-effects) to get a mock of the Real World inside the compile time environment.


the path to glory is a long and arduous one


Only lisp macros, no magic


in lisp lambda is the definition of magic


no, macros are


Posts like these is why I read HN religiously!




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: