https://github.com/vanyle/nimtocpp
A package to convert nim code to "readable" C code that can be submitted for competitive programming
https://github.com/vanyle/nimtocpp
Last synced: 6 months ago
JSON representation
A package to convert nim code to "readable" C code that can be submitted for competitive programming
- Host: GitHub
- URL: https://github.com/vanyle/nimtocpp
- Owner: vanyle
- License: mit
- Created: 2022-09-22T22:25:27.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-09-22T22:31:33.000Z (about 3 years ago)
- Last Synced: 2023-02-28T09:13:18.073Z (over 2 years ago)
- Language: C++
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NimToCpp
Let's say you enjoy competitive programming.
You want to solve some challenging program from an only website like [cses](https://cses.fi/) for example.The issue is that these website only accept Python, C and C++ as valid languages for their inputs!
You start by writing your solution in Python because it's convenient, but turn's out it's a bit
too slow and you want that 80x boost from C++ so you rewrite everything in C++ and it works but you just
wasted your time.What if you would write your program in a fast but expressive language, like Nim, convert the Nim code
to a self-contained C++ file and submit that file?Well, now, you can!
## Usage
To install:
- Clone this repo.
- `nimble build -d:release`
- Put the executable in your path with the `nimbase.h` fileUse with: `NimToCpp `
This will create a file named: `.nim_clean.cpp`
You can them compile this C++ file yourself or submit it to a competitive programming website!
```
λ nimtocpp .\test\t1.nim
C++ code available at: .\test\t1.nim_clean.cpp
λ g++ -Os .\test\t1.nim_clean.cpp -o t1.exe
[Warnings ...]
λ ./t1
[Program gets executed]
```## Requirements
You need to have the nim compiler in your path.
## Limitation and technical details
The GC is not available in the C++ file so that the generate code is not too long.
There is not a lot of testing done, but it seem to work with `seq`, `Table`, `string` and most
element you'd need to solve most elements you'd need to program competitively.The "readability" of the C++ code produced is not great, don't expect something like:
```
#includevoid main(){
printf("Hello, world");
}
```but more like:
```
#include
// ...1000 lines of junk...
STRING_LITERAL(TM__Ms59a0hH9a45nWiQHsSBSqKw_3, "Hello, world", 12);
static NIM_CONST tyArray__nHXaesL0DJZHyVS07ARPRA TM__Ms59a0hH9a45nWiQHsSBSqKw_2 = {((NimStringDesc*) &TM__Ms59a0hH9a45nWiQHsSBSqKw_3)}
;// More junk
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
{
echoBinSafe(TM__Ms59a0hH9a45nWiQHsSBSqKw_2, 1);
}// Even more junk
```