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

Compiling JavaScript to C source code #46

Closed
jarble opened this issue Apr 8, 2019 · 11 comments
Closed

Compiling JavaScript to C source code #46

jarble opened this issue Apr 8, 2019 · 11 comments

Comments

@jarble
Copy link

jarble commented Apr 8, 2019

Since NectarJS is able to compile JavaScript into WebAssembly, it may be possible to compile JavaScript into C source code using a compiler like wasmdec. Does NectarJS have this feature yet?

@adrien-thierry
Copy link
Contributor

You can directly compile JS to c/c++ with NectarJS

@jarble
Copy link
Author

jarble commented Jun 4, 2019

Does the documentation explain how to compile JavaScript to C or C++?

@adrien-thierry
Copy link
Contributor

Not yet,

you have to use njs --gen your_file.js in the core/nativejs folder

@votecoffee
Copy link

Where is the core/nativejs folder?
Compiling from the js file directory throws the following exception:

/usr/local/lib/node_modules/nectarjs/node_modules/eslint/lib/cli-engine/cli-engine.js:406
} catch {
^

SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (/usr/local/lib/node_modules/nectarjs/node_modules/eslint/lib/cli-engine/index.js:3:23)

@adrien-thierry
Copy link
Contributor

There is no more core/nativejs, did you update NectarJS ?

@votecoffee
Copy link

I recently installed it. I was looking for a transpiler to convert javascript to c++. I'm guessing that's no longer a supported feature then?

@adrien-thierry
Copy link
Contributor

Compiling to c++ is one of the main feature, so it's supported

Did you install it with npm ?

npm i -g nectarjs

@DuncanMacWeb
Copy link

Hi @adrien-thierry, I have installed NectarJS globally using npm i -g nectarjs:

$ nectar --version
NectarJS v0.7.99

What is the correct way to generate C/C++ output from NectarJS? Many thanks!

@adrien-thierry
Copy link
Contributor

Hi @DuncanMacWeb !

Thank you for your interest in NectarJS, to generate c++, use the --generate flag

To generate the code in a specific path, use --tmp with a path : --tmp mypath

@adrien-thierry
Copy link
Contributor

To just compile the app, use njs myapp.js

@DuncanMacWeb
Copy link

Got it, thanks!

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

No branches or pull requests

4 participants