Update Repl.cpp

This commit is contained in:
NotDSF 2021-11-09 21:20:54 +00:00
parent ab48847e34
commit b69f38e6d1

View file

@ -13,6 +13,11 @@
#include <memory> #include <memory>
#ifdef _WIN32
#include <io.h>
#include <fcntl.h>
#endif
enum class CompileFormat enum class CompileFormat
{ {
Default, Default,
@ -399,7 +404,12 @@ static bool compileFile(const char* name, CompileFormat format)
printf("%s", bcb.dumpEverything().c_str()); printf("%s", bcb.dumpEverything().c_str());
break; break;
case CompileFormat::Binary: case CompileFormat::Binary:
printf("%s", bcb.getBytecode().data()); #ifdef _WIN32
_setmode(_fileno(stdout), _O_BINARY);
#endif
std::string Bytecode = bcb.getBytecode();
fwrite(Bytecode.c_str(), 1, Bytecode.size(), stdout);
break; break;
} }
@ -458,33 +468,16 @@ int main(int argc, char** argv)
return 0; return 0;
} }
if ((argc >= 2 && strcmp(argv[1], "--compile=text") == 0) || strcmp(argv[1], "--compile") == 0)
{
int failed = 0;
for (int i = 2; i < argc; ++i) if (argc >= 2 && strncmp(argv[1], "--compile", strlen("--compile")) == 0)
{
CompileFormat format = CompileFormat::Default;
if (strcmp(argv[1], "--compile=binary") == 0)
{ {
if (argv[i][0] == '-') format = CompileFormat::Binary;
continue;
if (isDirectory(argv[i]))
{
traverseDirectory(argv[i], [&](const std::string& name) {
if (name.length() > 4 && name.rfind(".lua") == name.length() - 4)
failed += !compileFile(name.c_str(), CompileFormat::Default);
});
}
else
{
failed += !compileFile(argv[i], CompileFormat::Default);
}
} }
return failed;
}
if (argc >= 2 && strcmp(argv[1], "--compile=binary") == 0)
{
int failed = 0; int failed = 0;
for (int i = 2; i < argc; ++i) for (int i = 2; i < argc; ++i)
@ -496,12 +489,12 @@ int main(int argc, char** argv)
{ {
traverseDirectory(argv[i], [&](const std::string& name) { traverseDirectory(argv[i], [&](const std::string& name) {
if (name.length() > 4 && name.rfind(".lua") == name.length() - 4) if (name.length() > 4 && name.rfind(".lua") == name.length() - 4)
failed += !compileFile(name.c_str(), CompileFormat::Binary); failed += !compileFile(name.c_str(), format);
}); });
} }
else else
{ {
failed += !compileFile(argv[i], CompileFormat::Binary); failed += !compileFile(argv[i], format);
} }
} }