Skip to content

Commit

Permalink
refactor: code cleanup (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
xensik authored Nov 18, 2024
1 parent bf397fe commit 9ff3b87
Show file tree
Hide file tree
Showing 49 changed files with 2,308 additions and 2,383 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
uses: microsoft/setup-msbuild@v2

- name: Add premake5 to PATH
uses: abel0b/setup-premake@v2.3
uses: abel0b/setup-premake@v2.4
with:
version: ${{ env.PREMAKE_VERSION }}

Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
echo "/usr/local/opt/llvm/bin" >> $GITHUB_PATH
- name: Add premake5 to PATH
uses: abel0b/setup-premake@v2.3
uses: abel0b/setup-premake@v2.4
with:
version: ${{ env.PREMAKE_VERSION }}

Expand Down Expand Up @@ -152,7 +152,7 @@ jobs:
# run: sudo apt-get install crossbuild-essential-arm64 -y

- name: Add premake5 to PATH
uses: abel0b/setup-premake@v2.3
uses: abel0b/setup-premake@v2.4
with:
version: ${{ env.PREMAKE_VERSION }}

Expand Down
4 changes: 2 additions & 2 deletions gen/arc/parser.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace xsk::arc { class preprocessor; }
#include "xsk/arc/preprocessor.hpp"
using namespace xsk::arc;
namespace xsk::arc
{
{
auto ARClex(context const* ctx_, preprocessor& ppr) -> parser::symbol_type;
auto parse_switch(stmt_switch& stm) -> void;
}
Expand Down Expand Up @@ -530,7 +530,7 @@ stmt_foreach

stmt_switch
: SWITCH LPAREN expr RPAREN stmt_comp
{ $$ = stmt_switch::make(@$, std::move($3), std::move($5));
{ $$ = stmt_switch::make(@$, std::move($3), std::move($5));
parse_switch(*$$);
}
;
Expand Down
41 changes: 34 additions & 7 deletions gen/gsc/parser.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace xsk::gsc { class preprocessor; }
#include "xsk/gsc/preprocessor.hpp"
using namespace xsk::gsc;
namespace xsk::gsc
{
{
auto GSClex(context const* ctx_, preprocessor& ppr) -> parser::symbol_type;
auto parse_switch(stmt_switch& stm) -> void;
}
Expand Down Expand Up @@ -207,6 +207,8 @@ namespace xsk::gsc
%type <call::ptr> expr_function
%type <call::ptr> expr_pointer
%type <expr_add_array::ptr> expr_add_array
%type <expr::ptr> expr_bracket_double
%type <expr::ptr> expr_bracket_comma
%type <expr_parameters::ptr> expr_parameters
%type <expr_arguments::ptr> expr_arguments
%type <expr_arguments::ptr> expr_arguments_no_empty
Expand Down Expand Up @@ -244,6 +246,7 @@ namespace xsk::gsc
%nonassoc SIZEOF
%nonassoc ADD_ARRAY
%nonassoc RBRACKET
%nonassoc COMMA
%nonassoc THEN
%nonassoc ELSE
%nonassoc INCREMENT DECREMENT
Expand Down Expand Up @@ -320,7 +323,7 @@ decl_usingtree
decl_constant
: expr_identifier ASSIGN expr SEMICOLON
{
ppr.ban_header(@$); $$ = decl_constant::make(@$, std::move($1), std::move($3));
ppr.ban_header(@$); $$ = decl_constant::make(@$, std::move($1), std::move($3));
printf("%s" , std::format("{}: constants deprecated, use #define instead\n", @$.print()).data());
}
;
Expand Down Expand Up @@ -510,7 +513,7 @@ stmt_foreach

stmt_switch
: SWITCH LPAREN expr RPAREN stmt_comp
{ $$ = stmt_switch::make(@$, std::move($3), std::move($5));
{ $$ = stmt_switch::make(@$, std::move($3), std::move($5));
parse_switch(*$$);
}
;
Expand Down Expand Up @@ -762,8 +765,8 @@ expr_function
;

expr_pointer
: LBRACKET LBRACKET expr RBRACKET RBRACKET LPAREN expr_arguments RPAREN
{ $$ = expr_pointer::make(@$, std::move($3), std::move($7), call::mode::normal); }
: expr_bracket_double LPAREN expr_arguments RPAREN
{ $$ = expr_pointer::make(@$, std::move($1), std::move($3), call::mode::normal); }
| THREAD LBRACKET LBRACKET expr RBRACKET RBRACKET LPAREN expr_arguments RPAREN
{ $$ = expr_pointer::make(@$, std::move($4), std::move($8), call::mode::thread); }
| CHILDTHREAD LBRACKET LBRACKET expr RBRACKET RBRACKET LPAREN expr_arguments RPAREN
Expand All @@ -773,10 +776,34 @@ expr_pointer
;

expr_add_array
: LBRACKET expr_arguments_no_empty RBRACKET
: expr_bracket_double
{
auto args1 = expr_arguments::make(@$); args1->list.push_back(std::move($1));
auto array = expr_add_array::make(@$, std::move(args1));
auto args2 = expr_arguments::make(@$); args2->list.push_back(std::move(array));
$$ = expr_add_array::make(@$, std::move(args2));
}
| expr_bracket_comma expr_arguments_no_empty RBRACKET
{
auto args1 = expr_arguments::make(@$); args1->list.push_back(std::move($1));
auto array = expr_add_array::make(@$, std::move(args1));
auto args2 = std::move($2); args2->list.emplace(args2->list.begin(), std::move(array));
$$ = expr_add_array::make(@$, std::move(args2));
}
| LBRACKET expr_arguments_no_empty RBRACKET
{ $$ = expr_add_array::make(@$, std::move($2)); }
;

expr_bracket_double
: LBRACKET LBRACKET expr RBRACKET RBRACKET
{ $$ = std::move($3); }
;

expr_bracket_comma
: LBRACKET LBRACKET expr RBRACKET COMMA
{ $$ = std::move($3); }
;

expr_parameters
: expr_parameters COMMA expr_identifier
{ $$ = std::move($1); $$->list.push_back(std::move($3)); }
Expand All @@ -794,7 +821,7 @@ expr_arguments
;

expr_arguments_no_empty
: expr_arguments COMMA expr
: expr_arguments_no_empty COMMA expr
{ $$ = std::move($1); $$->list.push_back(std::move($3)); }
| expr %prec ADD_ARRAY
{ $$ = expr_arguments::make(@$); $$->list.push_back(std::move($1)); }
Expand Down
10 changes: 5 additions & 5 deletions include/xsk/arc/assembler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ class assembler
auto assemble_localvars(instruction const& inst) -> void;
auto assemble_jump(instruction const& inst) -> void;
auto assemble_switch(instruction const& inst) -> void;
auto assemble_end_switch(instruction const& inst) -> void;
auto assemble_switch_table(instruction const& inst) -> void;
auto process_string(std::string const& data) -> void;
auto process_function(function const& func) -> void;
auto process_instruction(instruction const& inst) -> void;
auto align_instruction(instruction& inst) -> void;
auto resolve_label(std::string const& name) -> i32;
auto resolve_label(std::string const& name) -> usize;
auto resolve_string(std::string const& name) -> u16;
void add_stringref(std::string const& str, string_type type, u32 ref);
void add_importref(std::vector<std::string> const& data, u32 ref);
void add_animref(std::vector<std::string> const& data, u32 ref);
auto add_stringref(std::string const& str, string_type type, u32 ref) -> void;
auto add_importref(std::vector<std::string> const& data, u32 ref) -> void;
auto add_animref(std::vector<std::string> const& data, u32 ref) -> void;
};

} // namespace xsk::arc
10 changes: 5 additions & 5 deletions include/xsk/arc/common/assembly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ struct instruction
{
using ptr = std::unique_ptr<instruction>;

u32 index;
u32 size;
usize index;
usize size;
sourcepos pos;
opcode opcode;
std::vector<std::string> data;
Expand All @@ -184,14 +184,14 @@ struct function
{
using ptr = std::unique_ptr<function>;

u32 index;
u32 size;
usize index;
usize size;
u8 params;
u8 flags;
std::string name;
std::string space;
std::vector<instruction::ptr> instructions;
std::unordered_map<u32, std::string> labels;
std::unordered_map<usize, std::string> labels;

static auto make() -> function::ptr
{
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/arc/common/token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct token
DOUBLEDOT, ELLIPSIS, SEMICOLON, DOUBLECOLON, LBRACKET, RBRACKET, LBRACE, RBRACE, LPAREN, RPAREN,

NAME, PATH, STRING, ISTRING, HASHSTR, INT, FLT,

DEVBEGIN, DEVEND, INLINE, INCLUDE, USINGTREE, ANIMTREE, AUTOEXEC, CODECALL, PRIVATE,
ENDON, NOTIFY, WAIT, WAITREALTIME, WAITTILL, WAITTILLMATCH, WAITTILLFRAMEEND, IF, ELSE,
DO, WHILE, FOR, FOREACH, IN, SWITCH, CASE, DEFAULT, BREAK, CONTINUE, RETURN, PROFBEGIN,
Expand Down
5 changes: 2 additions & 3 deletions include/xsk/arc/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class compiler
std::unordered_map<std::string, expr const*> constants_;
std::string animtree_;
sourcepos debug_pos_;
u32 index_;
u32 label_idx_;
usize index_;
usize label_idx_;
bool can_break_;
bool can_continue_;
bool developer_thread_;
Expand Down Expand Up @@ -69,7 +69,6 @@ class compiler
auto emit_expr_const(expr_const const& exp) -> void;
auto emit_expr_assign(expr_assign const& exp) -> void;
auto emit_expr_clear(expr const& exp) -> void;
auto emit_expr_clear_local(expr_identifier const& exp) -> void;
auto emit_expr_increment(expr_increment const& exp, bool is_stmt) -> void;
auto emit_expr_decrement(expr_decrement const& exp, bool is_stmt) -> void;
auto emit_expr_ternary(expr_ternary const& exp) -> void;
Expand Down
4 changes: 2 additions & 2 deletions include/xsk/arc/decompiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class decompiler
program::ptr program_;
decl_function::ptr func_;
std::unordered_set<std::string> vars_;
std::unordered_map<u32, std::string> labels_;
std::unordered_map<usize, std::string> labels_;
std::vector<std::string> expr_labels_;
std::vector<std::string> tern_labels_;
std::vector<std::string> locals_;
Expand Down Expand Up @@ -55,7 +55,7 @@ class decompiler
auto find_location_index(stmt_list const& stm, std::string const& loc) -> usize;
auto last_location_index(stmt_list const& stm, usize index) -> bool;
auto lvalues_match(stmt_expr const& stm1, stmt_expr const& stm2) -> bool;
auto resolve_label(std::string const& name) -> u32;
auto resolve_label(std::string const& name) -> usize;
auto process_function(decl_function& func) -> void;
auto process_stmt(stmt& stm) -> void;
auto process_stmt_list(stmt_list& stm) -> void;
Expand Down
6 changes: 3 additions & 3 deletions include/xsk/arc/disassembler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class disassembler
function::ptr func_;
assembly::ptr assembly_;
utils::reader script_;
std::map<u32, import_ref::ptr> import_refs_;
std::map<u32, string_ref::ptr> string_refs_;
std::map<u32, animtree_ref::ptr> anim_refs_;
std::map<usize, import_ref::ptr> import_refs_;
std::map<usize, string_ref::ptr> string_refs_;
std::map<usize, animtree_ref::ptr> anim_refs_;

public:
disassembler(context const* ctx);
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/arc/preprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class preprocessor
u32 skip_;

public:
preprocessor(context* ctx, std::string const& name, char const* data, usize size);
preprocessor(context* ctx, std::string const& name, u8 const* data, usize size);
auto process() -> token;
auto push_header(std::string const& file) -> void;
auto pop_header() -> void;
Expand Down
19 changes: 10 additions & 9 deletions include/xsk/gsc/assembler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ class assembler
private:
auto assemble_function(function const& func) -> void;
auto assemble_instruction(instruction const& inst) -> void;
auto assemble_builtin_call(instruction const& inst, bool method, bool args) -> void;
auto assemble_local_call(instruction const& inst, bool thread) -> void;
auto assemble_far_call(instruction const& inst, bool thread) -> void;
auto assemble_switch(instruction const& inst) -> void;
auto assemble_end_switch(instruction const& inst) -> void;
auto assemble_field_variable(instruction const& inst) -> void;
auto assemble_formal_params(instruction const& inst) -> void;
auto assemble_field(instruction const& inst) -> void;
auto assemble_params(instruction const& inst) -> void;
auto assemble_call_far(instruction const& inst, bool thread) -> void;
auto assemble_call_far2(instruction const& inst, bool thread) -> void;
auto assemble_call_local(instruction const& inst, bool thread) -> void;
auto assemble_call_builtin(instruction const& inst, bool method, bool args) -> void;
auto assemble_jump(instruction const& inst, bool expr, bool back) -> void;
auto assemble_switch(instruction const& inst) -> void;
auto assemble_switch_table(instruction const& inst) -> void;
auto assemble_offset(i32 offs) -> void;
auto resolve_function(std::string const& name) -> i32;
auto resolve_label(std::string const& name) -> i32;
auto resolve_function(std::string const& name) -> usize;
auto resolve_label(std::string const& name) -> usize;
auto encrypt_string(std::string const& str) -> std::string;
};

Expand Down
10 changes: 5 additions & 5 deletions include/xsk/gsc/common/assembly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ struct instruction
{
using ptr = std::unique_ptr<instruction>;

u32 index;
u32 size;
usize index;
usize size;
sourcepos pos;
opcode opcode;
std::vector<std::string> data;
Expand All @@ -246,12 +246,12 @@ struct function
{
using ptr = std::unique_ptr<function>;

u32 index;
u32 size;
usize index;
usize size;
u32 id;
std::string name;
std::vector<instruction::ptr> instructions;
std::unordered_map<u32, std::string> labels;
std::unordered_map<usize, std::string> labels;

static auto make() -> function::ptr
{
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/gsc/common/token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct token
DOUBLEDOT, ELLIPSIS, SEMICOLON, DOUBLECOLON, LBRACKET, RBRACKET, LBRACE, RBRACE, LPAREN, RPAREN,

NAME, PATH, STRING, ISTRING, INT, FLT,

DEVBEGIN, DEVEND, INLINE, INCLUDE, USINGTREE, ANIMTREE, ENDON, NOTIFY, WAIT,
WAITTILL, WAITTILLMATCH, WAITTILLFRAMEEND, WAITFRAME, IF, ELSE, DO, WHILE,
FOR, FOREACH, IN, SWITCH, CASE, DEFAULT, BREAK, CONTINUE, RETURN, BREAKPOINT,
Expand Down
4 changes: 2 additions & 2 deletions include/xsk/gsc/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class compiler
std::vector<scope*> continue_blks_;
std::string animname_;
sourcepos debug_pos_;
u32 index_;
u32 label_idx_;
usize index_;
usize label_idx_;
bool can_break_;
bool can_continue_;
bool developer_thread_;
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/gsc/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class context

auto engine_name() const -> std::string_view;

auto opcode_size(opcode op) const -> u32;
auto opcode_size(opcode op) const -> usize;

auto opcode_id(opcode op) const -> u8;

Expand Down
2 changes: 1 addition & 1 deletion include/xsk/gsc/decompiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class decompiler
context const* ctx_;
program::ptr program_;
decl_function::ptr func_;
std::unordered_map<u32, std::string> labels_;
std::unordered_map<usize, std::string> labels_;
std::vector<std::string> expr_labels_;
std::vector<std::string> tern_labels_;
std::stack<node::ptr> stack_;
Expand Down
16 changes: 9 additions & 7 deletions include/xsk/gsc/disassembler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ class disassembler
private:
auto dissasemble_function(function& func) -> void;
auto dissasemble_instruction(instruction& inst) -> void;
auto disassemble_builtin_call(instruction& inst, bool method, bool args) -> void;
auto disassemble_local_call(instruction& inst, bool thread) -> void;
auto disassemble_far_call(instruction& inst, bool thread) -> void;
auto disassemble_switch(instruction& inst) -> void;
auto disassemble_end_switch(instruction& inst) -> void;
auto disassemble_field_variable(instruction& inst) -> void;
auto disassemble_formal_params(instruction& inst) -> void;
auto disassemble_field(instruction& inst) -> void;
auto disassemble_params(instruction& inst) -> void;
auto disassemble_call_far(instruction& inst, bool thread) -> void;
auto disassemble_call_far2(instruction& inst, bool thread) -> void;
auto disassemble_call_local(instruction& inst, bool thread) -> void;
auto disassemble_call_builtin(instruction& inst, bool method, bool args) -> void;
auto disassemble_call_builtin2(instruction& inst, bool method, bool args) -> void;
auto disassemble_jump(instruction& inst, bool expr, bool back) -> void;
auto disassemble_switch(instruction& inst) -> void;
auto disassemble_switch_table(instruction& inst) -> void;
auto disassemble_offset() -> i32;
auto resolve_functions() -> void;
auto resolve_function(std::string const& index) -> std::string;
Expand Down
Loading

0 comments on commit 9ff3b87

Please sign in to comment.