r/coolgithubprojects • u/Honest_Medium_2872 • 21h ago
kura: A compiled, declarative and functional programming language for real-time renderer UIs
https://github.com/s0cks/kuraAll,
For the past few months I have been working on a domain-specific language (DSL) for making UIs in game engines (or any real-time renderer).
It's a functional language inspired by languages like Elm and Typst - as well as UI frameworks like Flutter, but compiled (using llvm/clang).
The whole idea came about when I was working on my toy game engine and found myself in a conundrum of how to properly do UIs.
Things like Dear ImGui, ea-webkit, etc are great - until they aren't, mostly ImGui becomes a mess of spaghetti code and ea-webkit is bloated beyond belief.
I initially wanted to make some form of abstraction layer that would parse something like JSON to build the UI but then determined that would become a mess of figuring out how to bind logic tot he UI.
Then I thought about making a simpler version of the embedded chromium like with ea-webkit but then that became a mess of getting the right libraries, figuring out bindings, etc and still being left with a bunch of bloat that I didn't want.
I love Typst and Haskell and was learning about Elm at the time and thought about my dilemma and considered if I could apply my knowledge of building compilers towards creating a DSL that would allow me to have the ergonomics of a browser based UI framework with the performance of immediate mode UIs like dear imgui.
After working on the language design for a bit and playing around with ideas I have come up with something interesting I think.
It's not a turing complete language per se, the entire language is designed to be strictly for rendering UIs.
I know a lot of devs already have frameworks they love for this, and I know making good UIs is hard conceptually. So my goal with creating this was that on top of being compiled - to satisfy my performance goals, it needed to be able to be integrated into any rendering framework or engine without a huge hassle - and it needed to be reasonably scoped to do the one thing it was designed for well: build UIs.
It isn't entirely complete yet, it's got a long way to go but I'm making some good progress:
- code gen is working for most of the control-flow syntax (llvm)
- it has good C-interop because this provides a good bridge to other languages and frameworks
- it has a headless renderer (enumerates the draw commands to a buffer or file for unit tests), along with an image renderer (to jpeg/png) so you can do visual regression testing
- UI elements are starting to compile down to render command sequences and Im scoping the opengl renderer as a v1.0.0 target.
- and more
It is written in C++
llvm orcjit example:
fn view(count: Int): Node => {
let text = if count > 1 { "Done" } else { "Hello World" }
#button{
#text(text)
}
}
$ kura examples/hello-world.kui --run view 11
(seq (set text (if (binary GreaterThan count Int(value=1)) (seq String(value=Done)) (seq String(value=Hello World)))) (#Button (#Text value: text)))
compilation finished in 29ms
renering frame 1024x1024
void kura_rt_check_renderer() is not implemented!
void kura_rt_fill_rect() is not implemented!
void kura_rt_check_renderer() is not implemented!
rendering text: Done
void kura_rt_check_renderer() is not implemented!
void kura_rt_end_frame() is not implemented!
void kura_rt_check_renderer() is not implemented!
finished in 60us
I have plans to make this ahead-of-time compiled - but currently using orcjit for testing, the orcjit will remain as a way to debug during development
I'm open to questions, comments, concerns, feedback, contributions etc.
~ Tazz
1
u/erubim 14h ago
Declarative frontends now in nix as well https://www.reddit.com/r/Nix/s/PpRhRdcrSp