C++ compiler written in Vanilla Javascript
Find a file
2023-05-04 18:06:57 -06:00
.gitignore feat(Target): Add fasm target 2023-05-04 17:35:57 -06:00
interpreter.js feat(Target): Add fasm target 2023-05-04 17:35:57 -06:00
main.cpp Cpp.js initial commit | cpp club 2023-04-22 18:57:55 -06:00
main.js feat(Target): Add fasm target 2023-05-04 17:35:57 -06:00
Makefile feat(Target): Add fasm target 2023-05-04 17:35:57 -06:00
package.json Cpp.js initial commit | cpp club 2023-04-22 18:57:55 -06:00
parser.js feat(Target): Add fasm target 2023-05-04 17:35:57 -06:00
README.md docs(README.md): Update README 2023-05-04 18:06:57 -06:00
run.sh Cpp.js initial commit | cpp club 2023-04-22 18:57:55 -06:00
stuff.js feat(command line arguments): Add --target and --help flags 2023-05-04 16:23:08 -06:00
utils.js Cpp.js initial commit | cpp club 2023-04-22 18:57:55 -06:00

Cpp.js

C++ compiler written in Vanilla Javascript

Features

  • Compiles c++ to Rust
  • Compiles c++ to Php (Not yet)

Motivation

Because I had no other choice.

Example

# node main.js <file>.cpp
# compiles main.cpp to main.rs
node main.js main.cpp

# compiles main.cpp to main.asm
# run node main.js --target list for valid targets
node main.js main.cpp --target x86_64-fasm-linux-gnu

# for more details
node main.js --help

Makefile

Build main.rs and run

make build-rs
make run

Build main.asm and run

make build-fasm
make run-fasm

Test rust code manually

# rustc <file>.rs -o <file>.out
rustc main.rs -o main.out

Support

  • // comments
  • printf("..."); it doesn't support more arguments (printf("%d", 10) doesn't work)
  • return
#include <cstdio>

int main()
{
    // This is comment
    printf("Hello from c++\n");
    return 0;
}