11#define error(msg) MessageBoxA(NULL, std::string(msg).c_str(), "Phasor Runtime Error", MB_OK | MB_ICONERROR)
13#define error(msg) std::cerr << "Error: " << msg << std::endl
27 if (
m_args.inputFile.empty())
29 std::cerr <<
"Error: No input file provided\n";
36 std::cerr <<
"DEBUG: Loading bytecode from: " <<
m_args.inputFile << std::endl;
43 std::cerr <<
"DEBUG: Bytecode loaded successfully" << std::endl;
44 std::cerr <<
"DEBUG: Instructions: " << bytecode.
instructions.size() << std::endl;
45 std::cerr <<
"DEBUG: Constants: " << bytecode.
constants.size() << std::endl;
48 auto vm = std::make_unique<VM>();
55 FFI ffi(
"plugins", vm.get());
56#elif defined(__APPLE__)
57 FFI ffi(
"/Library/Application Support/org.Phasor.Phasor/plugins", vm.get());
58#elif defined(__linux__)
59 FFI ffi(
"/opt/Phasor/plugins", vm.get());
62 vm->setImportHandler([](
const std::filesystem::path &path) {
63 throw std::runtime_error(
"Imports not supported in pure binary runtime yet: " + path.string());
67 std::cerr <<
"DEBUG: About to run bytecode" << std::endl;
72 std::cerr <<
"DEBUG: Bytecode execution complete" << std::endl;
76 catch (
const std::exception &e)
85 int defaultArgLocation = 1;
86 for (
int i = 1; i < argc; i++)
88 std::string arg = argv[i];
90 if (arg ==
"-v" || arg ==
"--verbose")
94 else if (arg ==
"-h" || arg ==
"--help")
101 defaultArgLocation = i;
106 m_args.scriptArgv = argv + defaultArgLocation;
107 m_args.scriptArgc = argc - defaultArgLocation;
112 std::string filename = std::filesystem::path(programName).filename().string();
113 std::cout <<
"Phasor Binary Runtime\n\n";
114 std::cout <<
"Usage:\n";
115 std::cout <<
" " << filename <<
" [options] <file.phsb> [...script args]\n\n";
116 std::cout <<
"Options:\n";
117 std::cout <<
" -v, --verbose Enable verbose output\n";
118 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.
Manages loading, registering, and unloading native FFI plugins.
static void registerFunctions(VM &vm)
Register all standard library functions.
static char ** argv
Command line arguments.
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.