r/Compilers • • Oct 27 '26

kura: A compiled, declarative and functional programming language for real-time renderer UIs

https://github.com/s0cks/kura

All,

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

0 Upvotes

2 comments sorted by

3

u/AustinVelonaut Oct 27 '26

Nice to see another functional language implementation out there (too bad about the Claude co-authoring, though: I'd rather study code written by a human!)

In your README example, you show:

type Message = 
  Increment
| Decrement

fn update(msg: Message, state: State): State =>
  match msg {
    Increment => { count: state.count + 1 }
    Decrement => { count: state.count - 1 }
    _ => { count: 0 }

}

Since Message only has Increment and Decrement as constructors, why do you show a (presumably) wildcard match after them -- is it to just show that it is available? Do you do exhaustiveness / reachability analysis on the match arms, and if so, does this example report the unreachable pattern?

-2

u/Honest_Medium_2872 Oct 27 '26

It's a combo of human and Claude code - I've been mainly using claude in incremental ways to increase velocity. though every contribution claude has made is marked in the commit graph and I thoroughly review via patch files before merging in.

I've built so many different toy langs, compilers, jits, gcs over the last decade that at this point i might as well just make a lib to reuse code and tricks:

and many more that have been privated and archived. my first lang was a JVM one back when I was 16 and my first real lang with a x86_64 JIT I hand rolled was a year or two later (well before llvm was even popular)

----

Regarding the question, the match is supposed to be exhaustive. No implicit return None (null) and the "_" (wildcard / catch all) is superfluous in this example and is ignored by basic block pruning but also there to demonstrate (though that was not really the intent when I wrote the example). there is no reporting on unreachable arms - probably useful to have but sometimes warns like those can be noise rather than helpful.

---

Also as mentioned it is not supposed to be turing complete but it is supposed to be functional. I love me some fp