21 if (
m_args.inputFile.empty())
23 std::cerr <<
"Error: No input file provided\n";
30 std::cerr <<
"DEBUG: Loading bytecode from: " <<
m_args.inputFile << std::endl;
37 std::cerr <<
"DEBUG: Bytecode loaded successfully" << std::endl;
38 std::cerr <<
"DEBUG: Instructions: " << bytecode.
instructions.size() << std::endl;
39 std::cerr <<
"DEBUG: Constants: " << bytecode.
constants.size() << std::endl;
42 auto vm = std::make_unique<VM>();
49 vm->initFFI(
"plugins");
50#elif defined(__APPLE__)
51 vm->initFFI(
"/Library/Application Support/org.Phasor.Phasor/plugins");
52#elif defined(__linux__)
53 vm->initFFI(
"/usr/lib/phasor/plugins/");
56 vm->setImportHandler([](
const std::filesystem::path &path) {
57 throw std::runtime_error(
"Imports not supported in pure binary runtime yet: " + path.string());
61 std::cerr <<
"DEBUG: About to run bytecode" << std::endl;
63 int status = vm->run(bytecode);
66 std::cerr <<
"DEBUG: Bytecode execution complete with return " << status << std::endl;
70 catch (
const std::exception &e)
79 int defaultArgLocation = 1;
80 for (
int i = 1; i < argc; i++)
82 std::string arg = argv[i];
84 if (arg ==
"-v" || arg ==
"--verbose")
88 else if (arg ==
"-h" || arg ==
"--help")
95 defaultArgLocation = i;
100 m_args.scriptArgv = argv + defaultArgLocation;
101 m_args.scriptArgc = argc - defaultArgLocation;
106 std::string filename = std::filesystem::path(programName).filename().string();
107 std::cout <<
"Phasor Binary Runtime\n\n";
108 std::cout <<
"Usage:\n";
109 std::cout <<
" " << filename <<
" [options] <file.phsb> [...script args]\n\n";
110 std::cout <<
"Options:\n";
111 std::cout <<
" -v, --verbose Enable verbose output\n";
112 std::cout <<
" -h, --help Show this help message\n";
struct Phasor::BinaryRuntime::Args m_args
void parseArguments(int argc, char *argv[])
BinaryRuntime(int argc, char *argv[], char *envp[])
void showHelp(const std::string &programName)
Bytecode binary format deserializer.
Bytecode loadFromFile(const std::filesystem::path &filename)
Load bytecode from .phsb file.
static char ** argv
Command line arguments.
static void registerFunctions(VM &vm)
static int argc
Number of command line arguments.
static char ** envp
Environment variables.
The Phasor Programming Language and Runtime.
Complete bytecode structure.
std::vector< Value > constants
Constant pool.
std::vector< Instruction > instructions
List of instructions.