{"id":16847608,"url":"https://github.com/fabiosantoscode/js2cpp","last_synced_at":"2025-08-14T00:15:27.158Z","repository":{"id":28466774,"uuid":"31982613","full_name":"fabiosantoscode/js2cpp","owner":"fabiosantoscode","description":"A toy js -\u003e c++ compiler written in coffeescript. Uses escodegen to write c++ and tern to figure out types.","archived":false,"fork":false,"pushed_at":"2022-12-07T15:17:39.000Z","size":148,"stargazers_count":113,"open_issues_count":7,"forks_count":11,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-02T03:51:09.431Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fabiosantoscode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-10T21:23:38.000Z","updated_at":"2025-03-07T15:42:45.000Z","dependencies_parsed_at":"2023-01-14T08:52:21.720Z","dependency_job_id":null,"html_url":"https://github.com/fabiosantoscode/js2cpp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fabiosantoscode/js2cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiosantoscode%2Fjs2cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiosantoscode%2Fjs2cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiosantoscode%2Fjs2cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiosantoscode%2Fjs2cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fabiosantoscode","download_url":"https://codeload.github.com/fabiosantoscode/js2cpp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiosantoscode%2Fjs2cpp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270337673,"owners_count":24566970,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-13T02:00:09.904Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T13:08:30.970Z","updated_at":"2025-08-14T00:15:26.889Z","avatar_url":"https://github.com/fabiosantoscode.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/fabiosantoscode/js2cpp.svg?branch=master)](https://travis-ci.org/fabiosantoscode/js2cpp)\n\n# What's this?\n\nIt's the product of the crazy idea of using the very excellent tern.js project to figure out the types of things and use them!\n\njs2cpp doesn't have a garbage collector yet. But it is usable and can run some JavaScript code as is!\n\n# How can I use it?\n\nYeah, it actually does some things. This is how js2cpp handles strings:\n\n    $ echo '\"lol\" + \"lel\"' | bin/js2cpp\n    #include \"js2c.h\"\n    #include \u003cstring\u003e\n\n    String(\"lol\") + String(\"lel\");\n\nAnd here's console.log!\n\n    $ echo 'console.log(1, 2, \"3\")' | bin/js2cpp\n    #include \"js2c.h\"\n    #include \u003cstring\u003e\n    \n    console.log(1, 2, String(\"3\"));\n\nIt works because there's a \"console\" instance of a \"Console\" class with a variadic \"log\" function.\n\nHere is tern.js figuring out a couple of types.\n\n    $ echo 'var aNumber = 1; var aString = \"1\";' | bin/js2cpp\n    #include \"js2c.h\"\n    #include \u003cstring\u003e\n    \n    double aNumber = 1;\n    String aString = String(\"1\");\n\n# How do I run this? (Usage)\n\n```\n ~ ♥  bin/js2cpp -h\nUsage: js2cpp --run (run javascript from stdin)\nUsage: js2cpp --run filename.js\nUsage: js2cpp (compile from stdin)\nUsage: js2cpp filename.js (compile)\n\nenvironment variables:\n ~ $ RUN_VALGRIND=1 js2cpp --run ...    - Run the compiled program with `valgrind`\n ~ $ GPP_BINARY=/path/to/g++ js2cpp ... - Select what g++ binary to use (defaults to `g++`)\n```\n\n * First, you need to update your compiler to a version that supports C++14. Your system probably already has this. If not, install linuxbrew or homebrew and just run `brew install gcc`\n * Then, clone this repo and run `npm install`\n * Optionally `npm test` just to make sure it works on your machine ;) If it doesn't please make an issue about it and I'll try to look into it. It tries to use the `g++` binary from your PATH. If you want to use another binary specify it with the `GPP_BINARY` environment variable, like so: `GPP_BINARY=g++-5 npm test`.\n * To compile some javascript, run `./bin/js2cpp \u003c your-javascript.js \u003e your-cee-plus-plus.cpp`.\n * To run it, run `./bin/js2cpp --run your-javascript.js`, or `./bin/js2cpp --run`, type in javascript, then press ^D when you're done. The `GPP_BINARY` variable also applies here.\n\n# Dumbjs\n\njs2cpp is kind of a frontend to fabiosantoscode/dumbjs, a javascript simplifier. It turns javascript that looks like this:\n\n```\nfunction foo(x) {\n    x++\n    return function () { return x }\n}\nconsole.log(foo(0)())\n```\n\nInto something like this:\n\n```\nvar _flatten_0 = function (_closure) {\n    return _closure.x\n}\nvar foo = function (x) {\n    var _closure_0 = {}\n    _closure_0.x = x\n    _closure_0.x++\n    return BIND(_flatten_0, _closure_0)\n}\nvar main = function () {\n    console.log(foo(0)())\n}\n```\n(the BIND function must be defined elsewhere, in this case in js2cpp)\n\nIts features are closure simulation, main-ification (put stuff in a main() function), function de-nesting, and more will come.\n\nSince all of it is a much simpler form of javascript, it takes a huge weight off the shoulders of js2cpp and makes sure its code remains (somewhat) understandable by not mixing up concerns.\n\nThis also means that you can use dumbjs to transpile javascript to other languages. Most of its features are switchable, because not every transpilation target language will need you to do things like wrapping things in a main() function or simulating closures.\n\n\n# Roadmap\n\n(unordered)\n\nThe main objective of this project is to implement at least 80% of the parts of javascript you use every day.\n\nThis means that, like a lot of npm modules which accidentally work in the browser when browserified, a lot of npm modules should accidentally work natively when js2cpp-ified.\n\nAll of the following features may be implemented in dumbjs, in this project, or in both at the same time, depending on whether they apply to each project.\n\n - Plug in the [Boehm-Demers-Weiser conservative garbage collector](http://www.hboehm.info/gc/) (which works in C and C++, it seems!)\n - Rewrite this and dumbjs in pure javascript\n - Implement `arguments` and `this`\n - Import the most common modules from node core (mostly depends on the above), rewrite parts of them in C++ if necessary.\n - Implement promises\n - Implement boxed types, for those variables which can have 2 or more types\n - Implement `JSON.parse()` and `JSON.stringify()` (depends on the above)\n - Implement libuv bindings and shim, fake and steal node's IO APIs\n - Implement ES5-style classes (possibly by turning them into ES6-style classes first)\n - Implement or fake commonJS (`require()`, `module.exports`) modules.\n - Implement several javascript APIs such as Date, Symbol, and Array (which currently is simply a C++ `std::vector`).\n\n# Hey this is AMAZING I WANNA FORK IT SELL IT OR WHATEVER WHAT IS TEH LICENSSSS\n\nJust have fun with it! WTFPL\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabiosantoscode%2Fjs2cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffabiosantoscode%2Fjs2cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabiosantoscode%2Fjs2cpp/lists"}