20 if (
m_args.inputFile.empty())
22 std::cerr <<
"Error: No input file provided\n";
29 std::cerr <<
"DEBUG: Loading bytecode from: " <<
m_args.inputFile << std::endl;
36 std::cerr <<
"DEBUG: Bytecode loaded successfully" << std::endl;
37 std::cerr <<
"DEBUG: Instructions: " << bytecode.
instructions.size() << std::endl;
38 std::cerr <<
"DEBUG: Constants: " << bytecode.
constants.size() << std::endl;
41 auto vm = std::make_unique<VM>();
47 vm->initFFI(
"plugins");
48#elif defined(__APPLE__)
49 vm->initFFI(
"/Library/Application Support/org.Phasor.Phasor/plugins");
50#elif defined(__linux__)
51 vm->initFFI(
"/usr/lib/phasor/plugins/");
54 vm->setImportHandler([](
const std::filesystem::path &path) {
55 throw std::runtime_error(
"Imports not supported in pure binary runtime yet: " + path.string());
59 std::cerr <<
"DEBUG: About to run bytecode" << std::endl;
61 int status = vm->run(bytecode);
64 std::cerr <<
"DEBUG: Bytecode execution complete with return " << status << std::endl;
68 catch (
const std::exception &e)
77 int defaultArgLocation = 1;
78 for (
int i = 1; i < argc; i++)
80 std::string arg = argv[i];
82 if (arg ==
"-v" || arg ==
"--verbose")
86 else if (arg ==
"-h" || arg ==
"--help")
93 defaultArgLocation = i;
98 m_args.scriptArgv = argv + defaultArgLocation;
99 m_args.scriptArgc = argc - defaultArgLocation;
104 std::string filename = std::filesystem::path(programName).filename().string();
105 std::println(
"Phasor Runtime v{}\n"
106 "(C) 2026 Daniel McGuire - Licensed under Apache 2.0\n\n"
108 " {} [options] <file.phsb> [...script args]\n\n"
110 " -v, --verbose Enable verbose output\n"
111 " -h, --help Show this help message",
112 PHASOR_VERSION_STRING, filename);
struct Phasor::BinaryRuntime::Args m_args
BinaryRuntime(int argc, char *argv[])
void parseArguments(int argc, char *argv[])
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.
The Phasor Programming Language and Runtime.
Complete bytecode structure.
std::vector< Instruction > instructions
List of instructions.
std::vector< Value > constants
Constant pool.