ts2c icon indicating copy to clipboard operation
ts2c copied to clipboard

Support C++

Open KubaO opened this issue 6 years ago • 3 comments

It'd be nice if C++ support was also available. I was specifically thinking of supporting Arduino libraries from Typescript, and those are all C++. I was going to take a stab at it at first by replacing C templates and support code with C++ one, incrementally, see what falls out and then figure out how to merge the two.

But perhaps you have some idea of how the split would be best implemented, and I would then try and follow this path from the beginning.

KubaO avatar Feb 26 '18 04:02 KubaO

My universal-transpiler tool can already compile a subset of TypeScript into C++.

It would also be possible to convert JavaScript into C++ by combining a TypeScript-to-Python compiler with a Python-to-C compiler.

jarble avatar Mar 20 '18 03:03 jarble

The JS-to-C++ via Python is a crazy route. I specifically want a translation that looks nice :) The universal transpiler seems like a very general tool - is it ever supposed to support what ts2c does already?

KubaO avatar Mar 20 '18 05:03 KubaO

The JS-to-C++ via Python is a crazy route

Agree! There are quite a few ways to compile JS to C++ through some other language. For example, I tested ts2hx project and some others and it worked more or less fine. However, size and quality of resulting code is very bad, and considering the huge overhead such compilation brings, I wonder if there is a real scenario where it makes sense to use it.

My universal-transpiler tool can already compile a subset of TypeScript into C++.

Universal-transpiler seems to be a good project, but for now it fails to compile even very basic examples - e.g. concatenation of strings, simple array operations, etc.. Considering my experience with TS2C, it's still a long way until something usable. Nevertheless, good start, keep it up! 👍

It'd be nice if C++ support was also available. I was specifically thinking of supporting Arduino libraries from Typescript, and those are all C++.

Yes, I was thinking of supporting several different transpilation targets, and Arduino and friends (including e.g. ESP8266) were among the primary candidates. But understand me correctly: there are so many shades of C++, and I don't want to go there. What I am talking of here is a tailored transpilation target, so it produces functions "setup()" and "loop()", uses Arduino's String class for working with strings, and so on.

For now I don't have any concrete approach of how to implement this. I was thinking of template overrides, so some of the templates can be overriden depending on the transpilation target (Code Templating used in ts2c explained here). There are many tricky things there though. For example, I'm not sure how RAll would play out with escape analysis I am using for memory management. Type recognition also changes a bit when we introduce those C++ classes.

Have to say, my personal current goal is to bring coverage of ES3 up to 96-99%, and only after this I will start improving other areas, so it's still a long way until transpilation targets engine (unless community contributes this part sooner).

andrei-markeev avatar Mar 30 '18 17:03 andrei-markeev