mirror of
https://github.com/open-goal/jak-project
synced 2026-07-07 14:13:45 -04:00
pass filename through (#1080)
This commit is contained in:
@@ -217,9 +217,11 @@ std::optional<Object> Reader::read_from_stdin(const std::string& prompt, ReplWra
|
||||
/*!
|
||||
* Read a string.
|
||||
*/
|
||||
Object Reader::read_from_string(const std::string& str, bool add_top_level) {
|
||||
Object Reader::read_from_string(const std::string& str,
|
||||
bool add_top_level,
|
||||
const std::optional<std::string>& string_name) {
|
||||
// create text fragment and add to the DB
|
||||
auto textFrag = std::make_shared<ProgramString>(str);
|
||||
auto textFrag = std::make_shared<ProgramString>(str, string_name.value_or("Program string"));
|
||||
db.insert(textFrag);
|
||||
|
||||
// perform read
|
||||
|
||||
@@ -72,7 +72,9 @@ struct Token {
|
||||
class Reader {
|
||||
public:
|
||||
Reader();
|
||||
Object read_from_string(const std::string& str, bool add_top_level = true);
|
||||
Object read_from_string(const std::string& str,
|
||||
bool add_top_level = true,
|
||||
const std::optional<std::string>& string_name = {});
|
||||
std::optional<Object> read_from_stdin(const std::string& prompt, ReplWrapper& repl);
|
||||
Object read_from_file(const std::vector<std::string>& file_path, bool check_encoding = false);
|
||||
bool check_string_is_valid(const std::string& str) const;
|
||||
|
||||
@@ -65,9 +65,14 @@ class ReplText : public SourceText {
|
||||
*/
|
||||
class ProgramString : public SourceText {
|
||||
public:
|
||||
explicit ProgramString(const std::string& text_) : SourceText(text_) {}
|
||||
std::string get_description() override { return "Program string"; }
|
||||
explicit ProgramString(const std::string& text_,
|
||||
const std::string& string_name = "Program string")
|
||||
: SourceText(text_), m_string_name(string_name) {}
|
||||
std::string get_description() override { return m_string_name; }
|
||||
~ProgramString() = default;
|
||||
|
||||
private:
|
||||
std::string m_string_name;
|
||||
};
|
||||
|
||||
/*!
|
||||
|
||||
@@ -428,8 +428,9 @@ void Compiler::run_front_end_on_file(const std::vector<std::string>& path) {
|
||||
* Run the entire compilation process on the input source code. Will generate an object file, but
|
||||
* won't save it anywhere.
|
||||
*/
|
||||
void Compiler::run_full_compiler_on_string_no_save(const std::string& src) {
|
||||
auto code = m_goos.reader.read_from_string({src});
|
||||
void Compiler::run_full_compiler_on_string_no_save(const std::string& src,
|
||||
const std::optional<std::string>& string_name) {
|
||||
auto code = m_goos.reader.read_from_string(src, true, string_name);
|
||||
auto compiled = compile_object_file("run-on-string", code, true);
|
||||
color_object_file(compiled);
|
||||
codegen_object_file(compiled);
|
||||
|
||||
@@ -42,7 +42,8 @@ class Compiler {
|
||||
void compile_and_send_from_string(const std::string& source_code);
|
||||
void run_front_end_on_string(const std::string& src);
|
||||
void run_front_end_on_file(const std::vector<std::string>& path);
|
||||
void run_full_compiler_on_string_no_save(const std::string& src);
|
||||
void run_full_compiler_on_string_no_save(const std::string& src,
|
||||
const std::optional<std::string>& string_name);
|
||||
void shutdown_target();
|
||||
void enable_throw_on_redefines() { m_throw_on_define_extern_redefinition = true; }
|
||||
void add_ignored_define_extern_symbol(const std::string& name) {
|
||||
|
||||
@@ -327,7 +327,7 @@ bool compile(Decompiler& dc,
|
||||
try {
|
||||
const auto& src = data.output_with_skips;
|
||||
total_lines += line_count(src);
|
||||
compiler.run_full_compiler_on_string_no_save(src);
|
||||
compiler.run_full_compiler_on_string_no_save(src, file.name_in_dgo);
|
||||
} catch (const std::exception& e) {
|
||||
fmt::print("Compiler exception: {}\n", e.what());
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user