24 std::println(
"Pulsar Compiler\n(C) 2026 Daniel McGuire\n");
27 std::println(std::cerr,
"Error: No input file provided");
41 std::println(std::cerr,
"Error: Cannot compile a bytecode file");
52 std::stringstream buffer;
53 buffer << file.rdbuf();
54 std::string source = buffer.str();
60 auto program = parser.
parse();
62 auto bytecode = codegen.
generate(*program);
68 path.replace_extension(
".phsb");
75 std::println(std::cerr,
"Failed to save bytecode to: {}",
m_args.
outputFile);
83 catch (
const std::exception &e)
85 std::println(std::cerr,
"Compilation Error: {}", e.what());
94 std::println(std::cerr,
"Error: Cannot compile a Phasor IR file");
105 std::stringstream buffer;
106 buffer << file.rdbuf();
107 std::string source = buffer.str();
113 auto program = parser.
parse();
115 auto bytecode = codegen.
generate(*program);
121 path.replace_extension(
".phir");
127 std::println(std::cerr,
"Failed to save Phasor IR to: {}",
m_args.
outputFile);
134 catch (
const std::exception &e)
136 std::println(std::cerr,
"Compilation Error: {}", e.what());
143 int defaultArgLocation = 1;
144 for (
int i = 1; i < argc; i++)
146 std::string arg = argv[i];
148 if (arg ==
"-v" || arg ==
"--verbose")
152 else if (arg ==
"--no-logo")
156 else if (arg ==
"-o" || arg ==
"--output")
164 std::println(std::cerr,
"Error: {} requires an argument", arg);
168 else if (arg ==
"-i" || arg ==
"--ir")
172 else if (arg ==
"-h" || arg ==
"--help")
179 defaultArgLocation = i;
190 std::string filename = std::filesystem::path(programName).filename().string();
191 std::println(
"Pulsar Compiler\n\n"
193 " {} [options] <file>\n\n"
195 " -o, --output FILE Specify output file\n"
196 " -i, --ir Compile to IR format (.phir) instead of bytecode\n"
197 " -v, --verbose Enable verbose output\n"
198 " -h, --help Show this help message", filename);
Bytecode binary format serializer.
bool saveToFile(const Bytecode &bytecode, const std::filesystem::path &filename)
Save bytecode to .phsb file.
Code generator for Phasor VM.
Bytecode generate(const AST::Program &program, const std::map< std::string, int > &existingVars={}, int nextVarIdx=0, bool replMode=false)
Generate bytecode from program.
struct Phasor::Compiler::Args m_args
void parseArguments(int argc, char *argv[])
void showHelp(const std::string &programName)
std::vector< Token > tokenize()
std::unique_ptr< AST::Program > parse()
static bool saveToFile(const Bytecode &bytecode, const std::filesystem::path &filename)
Save bytecode to .phir file.
Compiler(int argc, char *argv[], char *envp[])
The Pulsar Scripting Language.