I can currently write Ruby code in C, using Ruby's C API. This is much faster 
than native Ruby code and allows me to use the C-code from within the Ruby 
object model. For this to work, the C code must be structured in a certain way, 
and using pre-defined types, macros and function signatures, example 
[here](https://gitlab.com/snippets/1661089) .

I would like to be able to produce this code from Nim. My question is: how can 
I do this? The way I see it, I have 3 options:

  * Modify the Nim compiler. May be create a cgen-like module that understands 
the Ruby C-API semantics and generates appropriate C code. Then I could do 
something like


    
    
    nim c --cc:gcc --ext:rb mycode
    
    

  * Create a new DSL (macro) library that generates Ruby-structured C code from 
templates (a bit like [emerald](https://flyx.github.io/emerald) I guess)


  * Create a token-based generator that formats C-code according to 
tokens/annotations (a bit like the docgen tool)



I'm thinking out loud here and any opinions / suggestions are welcome.

cheers

Reply via email to