Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support C++ #13

Open
KubaO opened this issue Feb 26, 2018 · 3 comments
Open

Support C++ #13

KubaO opened this issue Feb 26, 2018 · 3 comments

Comments

@KubaO
Copy link

KubaO commented Feb 26, 2018

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.

@jarble
Copy link

jarble commented Mar 20, 2018

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.

@KubaO
Copy link
Author

KubaO commented Mar 20, 2018

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?

@andrei-markeev
Copy link
Owner

andrei-markeev commented Mar 30, 2018

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants