Transpiler doesn't include built-ins
Closed this issue · 3 comments
thatmagicalcat commented
The generated C++ code is incorrect
File main.sw
print("Hello World")
The generated main.cpp
file in __swirl_cache__
:
int main() {
print("Hello World");}
same with
if true {
print("Hello")
} else {
print("Bye")
}
Generated C++ code:
(missing }
)
int main() {
if (true ){print("Hello");}else{print("Bye");}
- OS: windows 11
- Swirl version: v0.0.2-alpha
0x4c756e61 commented
Just test on linux (I don't have windows running rn) and the generated code looks correct for printing "hello world" as the print template is defined in the cache
#include <iostream>
#define elif else if
template < typename Const >
void print(Const __Obj, const std::string& __End = "\n", bool __Flush = true) {
if (__Flush) std::cout << __Obj << __End << std::flush;
else std::cout << __Obj << __End;
}
std::string input(std::string __Prompt) {
std::string ret;
std::cout << __Prompt << std::flush;
std::getline(std::cin, ret);
return ret;
}
int main() {
print("Hello world !!!");}
0x4c756e61 commented
The conditional also works as intended on linux. So it is weird that this only happens on windows. Note that our primary developing platform is linux.
The generated c++ code
#include <iostream>
#define elif else if
template < typename Const >
void print(Const __Obj, const std::string& __End = "\n", bool __Flush = true) {
if (__Flush) std::cout << __Obj << __End << std::flush;
else std::cout << __Obj << __End;
}
std::string input(std::string __Prompt) {
std::string ret;
std::cout << __Prompt << std::flush;
std::getline(std::cin, ret);
return ret;
}
int main() {
if (true ){print("Hello");}else{print("Bye");}}
0x4c756e61 commented
I tested in my windows partition and looks like the issue comes from the compiled binary we released, building swirl from mysys2 it works fine. Have you tried building it yourself ? See the docs to compile it from source.