Closed pepe closed 2 years ago
I tried to also add non-top form Janet reverted it, as I am using print-ir
which works only for the top forms.
After some more time spent with this feature, I guess it could be working this way. So I guess I can polish it in the coming days with:
print-ir
for the emit-top
If you think it makes sense at all.
Interesting, thanks for the work here!
The emit-janet
form looks really flexible and useful for codegen - as for the loader, that is an interesting idea - is the idea to be able to use a .cgen file like a C template, taking advantage of the new $
directive? If that is the case, perhaps it would make sense if the render
function could take arguments besides where to write to.
Merging for now
Thank you very much. I have not yet used cgen as a template, yet it is very easy to add. I will attempt it tomorrow as i am in transit today.
I have two examples of code usage with loader https://git.sr.ht/~pepe/shriek/tree/master/item/chriek.cgen and https://git.sr.ht/~pepe/jfzy/tree/cgen/item/fzy-reduced.cgen
I must say that even as I am just starting to scratch the surface of possibilities I am very happy with the outcomes.
And as always the work and ideas are mostly yours i am just following your path.
This PR shows the possibility of using Janet loaders to import the cgen file and render the C source file from the template.
It also adds a new top directive,
$
, which will compile and execute code and print the result into the output file. Implementation restricts the evaluation to one form, but that would be an easy fix, and maybe it is the better way?