Javelin is a Python3 to C++11 transpiler written in C++11. When possible, it implies types automatically in Python.
Fibonacci is a nice example of how recursive calls are compiled.
def fib(n):
if n == 0 or n == 1:
return 1
return fib(n - 1) + fib(n - 2)
i = 0
while i < 10:
print("Fibonacci number " + str(i) + ": " + str(fib(i)))
i = i + 1
Will transpile into:
#include "inc/javelin.h"
int fib(int n);
int main() {
int i = 0;
while (i < 10) {
std::cout << std::string("Fibonacci number ") +
std::to_string(i) + std::string(": ") +
std::to_string(fib(i)) << std::endl;
i = i + 1;
}
}
int fib(int n) {
if (n == 0 || n == 1) {
return 1;
}
return fib(n - 1) + fib(n - 2);
}
We currently support limited list functionality:
i = [[1, 2, 3], [4, 5, 6, 7]]
for foo in i:
for bar in foo:
print(bar)
print(" ")
Compiles into:
#include "inc/javelin.h"
int main() {
std::vector<std::vector<int>> i = {{1,2,3},{4,5,6,7}};
for (std::vector<int> foo : i) {
for (int bar : foo) {
std::cout << bar << std::endl;
}
std::cout << std::string(" ") << std::endl;
}
}