feat(compiler): produce a developer source map (#167)

Co-authored-by: xensik <xensik@pm.me>
This commit is contained in:
INeedGames
2024-01-07 06:07:34 -06:00
committed by GitHub
parent 50ebfd2b25
commit 3896ec0e4e
13 changed files with 92 additions and 25 deletions

View File

@ -17,15 +17,17 @@ class assembler
function const* func_;
assembly const* assembly_;
utils::writer script_;
utils::writer devmap_;
std::unordered_map<std::string, u16> strpool_;
std::vector<export_ref> exports_;
std::vector<import_ref> imports_;
std::vector<string_ref> strings_;
std::vector<animtree_ref> anims_;
u32 devmap_count_;
public:
assembler(context const* ctx);
auto assemble(assembly const& data, std::string const& name = {}) -> buffer;
auto assemble(assembly const& data, std::string const& name = {}) -> std::pair<buffer, buffer>;
private:
auto assemble_function(function& func) -> void;

View File

@ -158,12 +158,19 @@ enum class opcode : u8
OP_Count,
};
struct sourcepos
{
u16 line;
u16 column;
};
struct instruction
{
using ptr = std::unique_ptr<instruction>;
u32 index;
u32 size;
sourcepos pos;
opcode opcode;
std::vector<std::string> data;

View File

@ -12,7 +12,7 @@ class position
{
public:
typedef const std::string filename_type;
typedef int counter_type;
typedef u16 counter_type;
filename_type *filename;
counter_type line;

View File

@ -20,6 +20,7 @@ class compiler
std::vector<scope> scopes_;
std::unordered_map<std::string, expr const*> constants_;
std::string animtree_;
sourcepos debug_pos_;
u32 index_;
u32 label_idx_;
bool can_break_;

View File

@ -18,10 +18,12 @@ class assembler
assembly const* assembly_;
utils::writer script_;
utils::writer stack_;
utils::writer devmap_;
u32 devmap_count_;
public:
assembler(context const* ctx);
auto assemble(assembly const& data) -> std::pair<buffer, buffer>;
auto assemble(assembly const& data) -> std::tuple<buffer, buffer, buffer>;
private:
auto assemble_function(function const& func) -> void;

View File

@ -220,12 +220,19 @@ enum class opcode : u8
OP_count,
};
struct sourcepos
{
u16 line;
u16 column;
};
struct instruction
{
using ptr = std::unique_ptr<instruction>;
u32 index;
u32 size;
sourcepos pos;
opcode opcode;
std::vector<std::string> data;

View File

@ -12,7 +12,7 @@ class position
{
public:
typedef const std::string filename_type;
typedef int counter_type;
typedef u16 counter_type;
filename_type *filename;
counter_type line;

View File

@ -22,6 +22,7 @@ class compiler
std::vector<scope*> break_blks_;
std::vector<scope*> continue_blks_;
std::string animname_;
sourcepos debug_pos_;
u32 index_;
u32 label_idx_;
bool can_break_;