3 ms·
Ask HN: Automating multi-lang communication with a meta programming language
I was thinking about a project that I can describe as:
an `inline` language (
rust! {
// Rust Code
}
c! {
// C code
}
)
But what is the overall point of just doing some "inlining" for all languages (I feel this is kind of a bad version of org-mode babel [0])
Just inlining code doesn't do that much but managing the code smartly by a compiler would be nice. What do I mean?
let rust_result = rust! {
return "[RUST]";
}
// below means send the variable `rust_result` to C
// and scoop up the c call result into `c_result`
[rust_result] -> [c_result]
c! {
printf("rust_result: %s\n", rust_result); // prints "[RUST]"
return "[C]";
}
I am seeking for you guys feedback on the project in general (also possible hard cases that can occur)
I think I may try to build an IPC - Shared memory stuff based on the target language.
But there are some philosophical differences between programming languages (e.g types!) which would make it insanely difficult to bridge between them (let me know do you have a solution) but some are similar which makes transpilation-like operations a lot easier.
Overall:
Do you thing this is doable?
Do you have some pathway to suggest?
Do you like it?
-----------------------------------------
[0]: https://orgmode.org/worg/org-contrib/babel/
- smoldesu 3y ago> Do you thing this is doable? It would be a lot of work, but I think it's possible. (Please do trash my theories if you think I'm wrong though =p) > Do you have some pathway to suggest? LLVM generates a bytecode called "IR" for many different languages (Rust and C included). Try and experiment with that, see if you can get bytecode from two languages to run in one binary. From there, the rest should be logistics! > Do you like it? Yes! But as a primarily Rust-based dev, I'm not entirely sure what I'd use other languages for. LLVM generates IR for a lot of languages though, so if you can get them working the value prop would increase exponentially.
- utfeight 3y agoThank you for your opinion. I know that you can generate IR using LLVM tools (clang, rust, zig etc.) but the "well-known" languages generally restrict you with some: - Static & Dynamic Typed Languages (which makes it almost impossible [0]) - Philosophies: e.g some languages embrace OOP-like systems for their general program design philosophy while others may not - These two are some of the cavities in my mind but simple primitive types wouldn't be that hard I think Even If It's just primitive types I think this can be a tool for automatic configration wrapper which would help a lot when integrating a new language to a program (e.g lua for neovim & awesomewm) -------------- [0]: I'm thinking some run-time checked generic type implementation but I need to figure A LOT for this. (something like rust's dynamic dispatch but more enhancable?) (maybe an enum for all edge cases? like Function, Struct, Class ...)