Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You have a lot of questions, so go to https://www.reddit.com/r/ProgrammingLanguages/

Some possible answers:

> . Unfortunately I also designed a language with top-level execution and nested functions - neither of which I could come up with a good compilation model for if I wanted to preserve the single-pass, no AST, no IR design of the compiler.

- This is the major PITA of C: Is an actual terrible target for transpilers that have aspirations and sophisticated features like Strings, some decent type system, or whatever. So, your option is to target something that is as close to semantics of your language (Basically, any other language that is not C), to the point where your target is MORE sophisticated than your own lang.

- I think Zig (for speed/apparent simplicity) and Rust could be good targets instead of C (I wish Rust were way faster to compile!). Assuming Zig, it will simplify other aspects like cross compiling

- I don't think is totally possible to avoid have a semi-interpreter for the transpiler, where you at most need a prelude with some hand-crafted functions that do the lifting. With this I mean things like `fn int(I:Int):Int'` so your code output is like `plus(int(1), int(2))`. Langs like APL/J use this for great effects and basically side-step the need for a vm/opcode. (see also: Compiling with closures)



> where your target is MORE sophisticated than your own lang.

I.. hadn't thought of this. I mean I wouldn't transpile to a slow lang like python but choosing Zig or C++ is tempting. Zig maybe not as it's unfinished. But C++ instead of C would make my life easier (for ex. implementing classes).

> prelude with some hand-crafted functions that do the lifting. With this I mean things like `fn int(I:Int):Int'` so your code output is like `plus(int(1), int(2))`

Curious what you mean here. Is it `1+2` -> ast Binop{'+', left, right} -> gen `plus(1,2)` ?? Sorry it's late here and I should sleep..



I've been down this path. Code generation is great; but the downside to this approach is that making the language debug-able is pretty much impossible. (An MPEG-SA structured audio compiler with a C++ back end).


> Curious what you mean here. Is it `1+2` -> ast Binop{'+', left, right} -> gen `plus(1,2)` ?? Sorry it's late here and I should sleep..

Yes, `plus(1,2)`. The problem will become more apparent when you find things like `plus` need some overloading support/macros/generics/etc, so thing like `print` too.

So, eventually you need to think in macros, multiple versions of the same thing, or, if you craft things very carefully, only support things your target support so you can avoid it (but I wonder how much is feasible)


> Zig maybe not as it’s unfinished

But, but, but…

They share the same two start letters! They were clearly meant to cohabitate!

Zinc on Zig, what a Zing!

(Just a casual at-a-distance zig fan)


this subreddit suffers from insufferable admins that purged any useful activity and sense of community from this sub


Nearly all of reddit is presently political spam, and bot spam - often political bot spam. Every subreddit has to some degree been infiltrated by political spam - even subs that have absolutely nothing to do with politics.

It's really unfortunate... reddit used to make me laugh - now it just makes me angry.


> Nearly all of reddit is presently political spam

The good (or at least barely tolerable) sane politics/econ subs hide in plain sight. (Also, enn cee dee?)


How do you mean?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: