Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is pretty cool. What are the use cases?



I’ve wanted something like this to compile XML business rules to native code on the fly.

I would have a script that converted the XML to C and then turn that into machine code that I’d load directly from the .text section of the binary (shellcode style).

Turns out this is error prone because compilers can emit things like jump tables into the .rodata section, so you need that too. It’s easier to just create a shared library.


XML business rules? Is it xml-oriented-programming again? They were doing it in Java 25 years ago


compile c++ code at runtime for instance. Lots of use cases, most obvious one specializing/instantiating dense computational kernels on values only known at runtime... but so many more things would be possible if the compiler was just a reusable library.


This is something Common Lisp got really right.


well being homoiconic and dynamic helps quite a bit... This being said, if you squint a bit and get used to the syntax, c++ variadic templates are just a compile-time lisp (really templates are just generalized functions over types) and the template mechanism is 100% pure, with a runtime capability of evaluating those pure monadic computational effects defined at compile-time to runtime, there is no more boundary (not saying it's a thing that should be done all the time). The main advantage then over functional languages is the fact that c++ optimizing compilers are already pretty good at optimization so assuming that you can afford to re-compile at runtime the tight inner loops or critical paths (say at "configuration time" when adding some latency might not be a big deal), a lot of otherwise impossible optimizations could probably be done better (thinking of loop invariants, polyhedral, unrolling, constant propagation, aliasing, row major to column major etc etc) probably the result would also be better than what a JIT compiler and profiler would be able to achieve too.


> template mechanism is 100% pure

Let's say 99.99%. You underestimate the resourcefulness of C++ (meta-)programmers and their ability to leverage implementations or specification bugs for "useful" purposes: https://b.atch.se/posts/non-constant-constant-expressions/


REPL and JIT come to mind.


I think this is exactly how Zig compiler does under the hood for C/C++ sources. So I guess you can do a similar thing for your own programming languages to support interop.




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

Search: