Skip to content

Commit

Permalink
fix(t6): anim namespaces & assetmsg devblocks (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
xensik authored Nov 1, 2024
1 parent acd865b commit ab42b44
Show file tree
Hide file tree
Showing 8 changed files with 722 additions and 682 deletions.
4 changes: 3 additions & 1 deletion gen/arc/parser.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,9 @@ expr_level

expr_animation
: MOD IDENTIFIER %prec ANIMREF
{ $$ = expr_animation::make(@$, $2); };
{ $$ = expr_animation::make(@$, "", $2); };
| MOD IDENTIFIER DOUBLECOLON IDENTIFIER %prec ANIMREF
{ $$ = expr_animation::make(@$, $2, $4); };
;

expr_animtree
Expand Down
3 changes: 2 additions & 1 deletion include/xsk/arc/common/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,10 @@ struct expr_animation : public expr
{
using ptr = std::unique_ptr<expr_animation>;

std::string space;
std::string value;

expr_animation(location const& loc, std::string const& value);
expr_animation(location const& loc, std::string const& space, std::string const& value);
friend auto operator==(expr_animation const& lhs, expr_animation const& rhs) -> bool;
XSK_ARC_AST_MAKE(expr_animation)
};
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/arc/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5482,7 +5482,7 @@ switch (yykind)
/// Constants.
enum
{
yylast_ = 3307, ///< Last index in yytable_.
yylast_ = 3337, ///< Last index in yytable_.
yynnts_ = 102, ///< Number of nonterminal symbols.
yyfinal_ = 28 ///< Termination state number.
};
Expand Down
4 changes: 2 additions & 2 deletions src/arc/common/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ expr_animtree::expr_animtree(location const& loc) : expr{ type::expr_animtree, l
{
}

expr_animation::expr_animation(location const& loc, std::string const& value) : expr{ type::expr_animation, loc }, value{ value }
expr_animation::expr_animation(location const& loc, std::string const& space, std::string const& value) : expr{ type::expr_animation, loc }, space{ space }, value{ value }
{
}

Expand Down Expand Up @@ -986,7 +986,7 @@ auto operator==(expr_animtree const&, expr_animtree const&) -> bool

auto operator==(expr_animation const& lhs, expr_animation const& rhs) -> bool
{
return lhs.value == rhs.value;
return lhs.space == rhs.space && lhs.value == rhs.value;
}

auto operator==(expr_classes const&, expr_classes const&) -> bool
Expand Down
9 changes: 6 additions & 3 deletions src/arc/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ auto compiler::emit_expr_call_function(expr_function const& exp, bool is_stmt) -
bool as_dev = false;
std::string end;

if (!developer_thread_ && is_stmt && exp.name->value == "assert")
if (!developer_thread_ && is_stmt && (exp.name->value == "assert" || exp.name->value == "assertmsg"))
{
as_dev = true;
developer_thread_ = true;
Expand Down Expand Up @@ -1804,12 +1804,15 @@ auto compiler::emit_expr_vector(expr_vector const& exp) -> void

auto compiler::emit_expr_animation(expr_animation const& exp) -> void
{
if (animtree_.empty())
if (exp.space == "" && animtree_.empty())
{
throw comp_error(exp.loc(), "trying to use animation without specified using animtree");
}

emit_opcode(opcode::OP_GetAnimation, { animtree_, exp.value });
if (exp.space != "")
emit_opcode(opcode::OP_GetAnimation, { exp.space, exp.value });
else
emit_opcode(opcode::OP_GetAnimation, { animtree_, exp.value });
}

auto compiler::emit_expr_animtree(expr_animtree const& exp) -> void
Expand Down
27 changes: 23 additions & 4 deletions src/arc/decompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,23 +241,40 @@ auto decompiler::decompile_instruction(instruction const& inst, bool last) -> vo
case opcode::OP_GetAnimation:
{
auto found = false;
auto space = ""s;

for (auto i = program_->declarations.rbegin(); i != program_->declarations.rend(); i++)
{
if ((*i)->is<decl_usingtree>())
{
found = (*i)->as<decl_usingtree>().name->value == inst.data[0];
space = (*i)->as<decl_usingtree>().name->value;
break;
}
}

if (!found)
{
auto dec = decl_usingtree::make(loc, expr_string::make(loc, inst.data[0]));
program_->declarations.push_back(std::move(dec));
if (space == "")
{
auto dec = decl_usingtree::make(loc, expr_string::make(loc, inst.data[0]));
program_->declarations.push_back(std::move(dec));
stack_.push(expr_animation::make(loc, "", inst.data[1]));
}
else
{
stack_.push(expr_animation::make(loc, inst.data[0], inst.data[1]));
}
}
else if (space == inst.data[0])
{
stack_.push(expr_animation::make(loc, "", inst.data[1]));
}
else
{
stack_.push(expr_animation::make(loc, inst.data[0], inst.data[1]));
}

stack_.push(expr_animation::make(loc, inst.data[1]));
break;
}
case opcode::OP_GetFunction:
Expand Down Expand Up @@ -1462,7 +1479,9 @@ auto decompiler::decompile_devblocks(stmt_list& stm) -> void

if (st->as<stmt_expr>().value->is<expr_call>() && st->as<stmt_expr>().value->as<expr_call>().value->is<expr_function>())
{
if (st->as<stmt_expr>().value->as<expr_call>().value->as<expr_function>().name->value == "assert")
auto func = st->as<stmt_expr>().value->as<expr_call>().value->as<expr_function>().name->value;

if (func == "assert" || func == "assertmsg")
{
stm.list.insert(stm.list.begin() + i, std::move(list_stmt->list.at(0)));
continue;
Expand Down
Loading

0 comments on commit ab42b44

Please sign in to comment.