inital commit
This commit is contained in:
1 parent
e9773c9161
commit
e8b8565773
36 files changed
+40468
No files matched your search
@@ -0,0 +1,50 @@
|
||||
#include <iostream>
|
||||
#include <dlang.hpp>
|
||||
#include <cstring>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
DlangVM vm;
|
||||
OpenStandardLibs(&vm);
|
||||
|
||||
if (argc == 2)
|
||||
{
|
||||
std::filesystem::path inputPath(argv[1]);
|
||||
auto ext = inputPath.extension().string();
|
||||
|
||||
if (ext == ".bdlang")
|
||||
vm.RunBinaryFile(argv[1]);
|
||||
else if (ext == ".dlang")
|
||||
vm.RunFile(argv[1]);
|
||||
else
|
||||
printf("Must be a .dlang or .bdlang file!");
|
||||
|
||||
}
|
||||
else if (argc == 3)
|
||||
{
|
||||
if (strcmp(argv[2], "--compile") == 0)
|
||||
{
|
||||
std::vector<double> bytecode = {};
|
||||
vm.RunFile(argv[1], &bytecode);
|
||||
|
||||
std::filesystem::path inputPath(argv[1]);
|
||||
std::filesystem::path outputPath = inputPath.replace_extension(".bdlang");
|
||||
std::ofstream file(outputPath, std::ios::binary);
|
||||
|
||||
if (file.is_open())
|
||||
{
|
||||
file.write(reinterpret_cast<const char*>(bytecode.data()), bytecode.size() * sizeof(double));
|
||||
file.close();
|
||||
|
||||
std::cout << "Compiled to: " << outputPath.string() << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Failed to create file: " << outputPath.string() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("%s [filename] [--compile]\n", argv[0]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user