diff --git a/src/h1/xsk/compiler.cpp b/src/h1/xsk/compiler.cpp index 09a62092..6446e4a4 100644 --- a/src/h1/xsk/compiler.cpp +++ b/src/h1/xsk/compiler.cpp @@ -323,21 +323,11 @@ void compiler::emit_stmt_expr(const ast::stmt_expr::ptr& stmt, const block::ptr& void compiler::emit_stmt_call(const ast::stmt_call::ptr& stmt, const block::ptr& blk) { if (stmt->expr == ast::kind::expr_call) - { - if (mode_ != gsc::build::dev && stmt->expr.as_call->call == ast::kind::expr_function) - { - const auto& name = stmt->expr.as_call->call.as_function->name->value; - if (name == "assert" || name == "assertex" || name == "assertmsg") return; - } - - emit_expr_call(stmt->expr.as_call, blk); - } + emit_expr_call(stmt->expr.as_call, blk, true); else if (stmt->expr == ast::kind::expr_method) - emit_expr_method(stmt->expr.as_method, blk); + emit_expr_method(stmt->expr.as_method, blk, true); else throw comp_error(stmt->loc(), "unknown call statement expression"); - - emit_opcode(opcode::OP_DecTop); } void compiler::emit_stmt_assign(const ast::stmt_assign::ptr& stmt, const block::ptr& blk) @@ -960,10 +950,10 @@ void compiler::emit_expr(const ast::expr& expr, const block::ptr& blk) emit_expr_not(expr.as_not, blk); break; case ast::kind::expr_call: - emit_expr_call(expr.as_call, blk); + emit_expr_call(expr.as_call, blk, false); break; case ast::kind::expr_method: - emit_expr_method(expr.as_method, blk); + emit_expr_method(expr.as_method, blk, false); break; case ast::kind::expr_reference: emit_expr_reference(expr.as_reference, blk); @@ -1127,9 +1117,9 @@ void compiler::emit_expr_clear_local(const ast::expr_identifier::ptr& expr, cons emit_opcode(opcode::OP_ClearLocalVariableFieldCached, variable_access_index(expr, blk)); } -void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool fromstmt) +void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool is_stmt) { - if (fromstmt) + if (is_stmt) { emit_expr_variable_ref(expr->lvalue, blk, false); emit_opcode(opcode::OP_inc); @@ -1141,9 +1131,9 @@ void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const b } } -void compiler::emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool fromstmt) +void compiler::emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool is_stmt) { - if (fromstmt) + if (is_stmt) { emit_expr_variable_ref(expr->lvalue, blk, false); emit_opcode(opcode::OP_dec); @@ -1275,17 +1265,17 @@ void compiler::emit_expr_not(const ast::expr_not::ptr& expr, const block::ptr& b emit_opcode(opcode::OP_BoolNot); } -void compiler::emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->call == ast::kind::expr_pointer) - emit_expr_call_pointer(expr->call.as_pointer, blk); + emit_expr_call_pointer(expr->call.as_pointer, blk, is_stmt); else if (expr->call == ast::kind::expr_function) - emit_expr_call_function(expr->call.as_function, blk); + emit_expr_call_function(expr->call.as_function, blk, is_stmt); else throw comp_error(expr->loc(), "unknown function call expression"); } -void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->mode == ast::call::mode::normal) emit_opcode(opcode::OP_PreScriptCall); @@ -1310,10 +1300,19 @@ void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const emit_opcode(opcode::OP_CallBuiltinPointer, argcount); break; } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk, bool is_stmt) { + if (is_stmt && mode_ == gsc::build::prod) + { + const auto& name = expr->name->value; + if (name == "assert" || name == "assertex" || name == "assertmsg") return; + } + auto type = resolve_function_type(expr); if (type != ast::call::type::builtin && expr->mode == ast::call::mode::normal && expr->args->list.size() > 0) @@ -1395,19 +1394,22 @@ void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, cons break; } } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->call == ast::kind::expr_pointer) - emit_expr_method_pointer(expr->call.as_pointer, expr->obj, blk); + emit_expr_method_pointer(expr->call.as_pointer, expr->obj, blk, is_stmt); else if (expr->call == ast::kind::expr_function) - emit_expr_method_function(expr->call.as_function, expr->obj, blk); + emit_expr_method_function(expr->call.as_function, expr->obj, blk, is_stmt); else throw comp_error(expr->loc(), "unknown method call expression"); } -void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk) +void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt) { if (expr->mode == ast::call::mode::normal) emit_opcode(opcode::OP_PreScriptCall); @@ -1433,9 +1435,12 @@ void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, cons emit_opcode(opcode::OP_CallBuiltinMethodPointer, argcount); break; } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk) +void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt) { auto type = resolve_function_type(expr); @@ -1513,6 +1518,9 @@ void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, co break; } } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } void compiler::emit_expr_add_array(const ast::expr_add_array::ptr& expr, const block::ptr& blk) @@ -1671,13 +1679,13 @@ void compiler::emit_expr_field_ref(const ast::expr_field::ptr& expr, const block if (set) emit_opcode(opcode::OP_SetVariableField); break; case ast::kind::expr_call: - emit_expr_call(expr->obj.as_call, blk); + emit_expr_call(expr->obj.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariableRef, field); if (set) emit_opcode(opcode::OP_SetVariableField); break; case ast::kind::expr_method: - emit_expr_method(expr->obj.as_method, blk); + emit_expr_method(expr->obj.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariableRef, field); if (set) emit_opcode(opcode::OP_SetVariableField); @@ -1782,12 +1790,12 @@ void compiler::emit_expr_field(const ast::expr_field::ptr& expr, const block::pt emit_opcode(opcode::OP_EvalFieldVariable, field); break; case ast::kind::expr_call: - emit_expr_call(expr->obj.as_call, blk); + emit_expr_call(expr->obj.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariable, field); break; case ast::kind::expr_method: - emit_expr_method(expr->obj.as_method, blk); + emit_expr_method(expr->obj.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariable, field); break; @@ -1863,11 +1871,11 @@ void compiler::emit_expr_object(const ast::expr& expr, const block::ptr& blk) emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_call: - emit_expr_call(expr.as_call, blk); + emit_expr_call(expr.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_method: - emit_expr_method(expr.as_method, blk); + emit_expr_method(expr.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_identifier: @@ -1939,7 +1947,7 @@ void compiler::emit_expr_animtree(const ast::expr_animtree::ptr& expr) { if (animtrees_.size() == 0) { - throw comp_error( expr->loc(), "trying to use animtree without specified using animtree"); + throw comp_error(expr->loc(), "trying to use animtree without specified using animtree"); } auto& tree = animtrees_.back(); diff --git a/src/h1/xsk/compiler.hpp b/src/h1/xsk/compiler.hpp index 31330e26..ab85fa79 100644 --- a/src/h1/xsk/compiler.hpp +++ b/src/h1/xsk/compiler.hpp @@ -76,20 +76,20 @@ private: void emit_expr_assign(const ast::expr_assign::ptr& expr, const block::ptr& blk); void emit_expr_clear(const ast::expr& expr, const block::ptr& blk); void emit_expr_clear_local(const ast::expr_identifier::ptr& expr, const block::ptr& blk); - void emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool stmt); - void emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool stmt); + void emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool is_stmt); void emit_expr_ternary(const ast::expr_ternary::ptr& expr, const block::ptr& blk); void emit_expr_binary(const ast::expr_binary::ptr& expr, const block::ptr& blk); void emit_expr_and(const ast::expr_and::ptr& expr, const block::ptr& blk); void emit_expr_or(const ast::expr_or::ptr& expr, const block::ptr& blk); void emit_expr_complement(const ast::expr_complement::ptr& expr, const block::ptr& blk); void emit_expr_not(const ast::expr_not::ptr& expr, const block::ptr& blk); - void emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk); - void emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk); - void emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk); - void emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk); - void emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk); - void emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk); + void emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt); + void emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt); void emit_expr_add_array(const ast::expr_add_array::ptr& expr, const block::ptr& blk); void emit_expr_parameters(const ast::expr_parameters::ptr& expr, const block::ptr& blk); void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk); diff --git a/src/h2/xsk/compiler.cpp b/src/h2/xsk/compiler.cpp index ce45a101..b8bc5fa2 100644 --- a/src/h2/xsk/compiler.cpp +++ b/src/h2/xsk/compiler.cpp @@ -323,21 +323,11 @@ void compiler::emit_stmt_expr(const ast::stmt_expr::ptr& stmt, const block::ptr& void compiler::emit_stmt_call(const ast::stmt_call::ptr& stmt, const block::ptr& blk) { if (stmt->expr == ast::kind::expr_call) - { - if (mode_ != gsc::build::dev && stmt->expr.as_call->call == ast::kind::expr_function) - { - const auto& name = stmt->expr.as_call->call.as_function->name->value; - if (name == "assert" || name == "assertex" || name == "assertmsg") return; - } - - emit_expr_call(stmt->expr.as_call, blk); - } + emit_expr_call(stmt->expr.as_call, blk, true); else if (stmt->expr == ast::kind::expr_method) - emit_expr_method(stmt->expr.as_method, blk); + emit_expr_method(stmt->expr.as_method, blk, true); else throw comp_error(stmt->loc(), "unknown call statement expression"); - - emit_opcode(opcode::OP_DecTop); } void compiler::emit_stmt_assign(const ast::stmt_assign::ptr& stmt, const block::ptr& blk) @@ -960,10 +950,10 @@ void compiler::emit_expr(const ast::expr& expr, const block::ptr& blk) emit_expr_not(expr.as_not, blk); break; case ast::kind::expr_call: - emit_expr_call(expr.as_call, blk); + emit_expr_call(expr.as_call, blk, false); break; case ast::kind::expr_method: - emit_expr_method(expr.as_method, blk); + emit_expr_method(expr.as_method, blk, false); break; case ast::kind::expr_reference: emit_expr_reference(expr.as_reference, blk); @@ -1127,9 +1117,9 @@ void compiler::emit_expr_clear_local(const ast::expr_identifier::ptr& expr, cons emit_opcode(opcode::OP_ClearLocalVariableFieldCached, variable_access_index(expr, blk)); } -void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool fromstmt) +void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool is_stmt) { - if (fromstmt) + if (is_stmt) { emit_expr_variable_ref(expr->lvalue, blk, false); emit_opcode(opcode::OP_inc); @@ -1141,9 +1131,9 @@ void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const b } } -void compiler::emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool fromstmt) +void compiler::emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool is_stmt) { - if (fromstmt) + if (is_stmt) { emit_expr_variable_ref(expr->lvalue, blk, false); emit_opcode(opcode::OP_dec); @@ -1275,17 +1265,17 @@ void compiler::emit_expr_not(const ast::expr_not::ptr& expr, const block::ptr& b emit_opcode(opcode::OP_BoolNot); } -void compiler::emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->call == ast::kind::expr_pointer) - emit_expr_call_pointer(expr->call.as_pointer, blk); + emit_expr_call_pointer(expr->call.as_pointer, blk, is_stmt); else if (expr->call == ast::kind::expr_function) - emit_expr_call_function(expr->call.as_function, blk); + emit_expr_call_function(expr->call.as_function, blk, is_stmt); else throw comp_error(expr->loc(), "unknown function call expression"); } -void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->mode == ast::call::mode::normal) emit_opcode(opcode::OP_PreScriptCall); @@ -1310,10 +1300,19 @@ void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const emit_opcode(opcode::OP_CallBuiltinPointer, argcount); break; } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk, bool is_stmt) { + if (is_stmt && mode_ == gsc::build::prod) + { + const auto& name = expr->name->value; + if (name == "assert" || name == "assertex" || name == "assertmsg") return; + } + auto type = resolve_function_type(expr); if (type != ast::call::type::builtin && expr->mode == ast::call::mode::normal && expr->args->list.size() > 0) @@ -1395,19 +1394,22 @@ void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, cons break; } } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->call == ast::kind::expr_pointer) - emit_expr_method_pointer(expr->call.as_pointer, expr->obj, blk); + emit_expr_method_pointer(expr->call.as_pointer, expr->obj, blk, is_stmt); else if (expr->call == ast::kind::expr_function) - emit_expr_method_function(expr->call.as_function, expr->obj, blk); + emit_expr_method_function(expr->call.as_function, expr->obj, blk, is_stmt); else throw comp_error(expr->loc(), "unknown method call expression"); } -void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk) +void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt) { if (expr->mode == ast::call::mode::normal) emit_opcode(opcode::OP_PreScriptCall); @@ -1433,9 +1435,12 @@ void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, cons emit_opcode(opcode::OP_CallBuiltinMethodPointer, argcount); break; } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk) +void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt) { auto type = resolve_function_type(expr); @@ -1513,6 +1518,9 @@ void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, co break; } } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } void compiler::emit_expr_add_array(const ast::expr_add_array::ptr& expr, const block::ptr& blk) @@ -1671,13 +1679,13 @@ void compiler::emit_expr_field_ref(const ast::expr_field::ptr& expr, const block if (set) emit_opcode(opcode::OP_SetVariableField); break; case ast::kind::expr_call: - emit_expr_call(expr->obj.as_call, blk); + emit_expr_call(expr->obj.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariableRef, field); if (set) emit_opcode(opcode::OP_SetVariableField); break; case ast::kind::expr_method: - emit_expr_method(expr->obj.as_method, blk); + emit_expr_method(expr->obj.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariableRef, field); if (set) emit_opcode(opcode::OP_SetVariableField); @@ -1782,12 +1790,12 @@ void compiler::emit_expr_field(const ast::expr_field::ptr& expr, const block::pt emit_opcode(opcode::OP_EvalFieldVariable, field); break; case ast::kind::expr_call: - emit_expr_call(expr->obj.as_call, blk); + emit_expr_call(expr->obj.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariable, field); break; case ast::kind::expr_method: - emit_expr_method(expr->obj.as_method, blk); + emit_expr_method(expr->obj.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariable, field); break; @@ -1863,11 +1871,11 @@ void compiler::emit_expr_object(const ast::expr& expr, const block::ptr& blk) emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_call: - emit_expr_call(expr.as_call, blk); + emit_expr_call(expr.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_method: - emit_expr_method(expr.as_method, blk); + emit_expr_method(expr.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_identifier: @@ -1939,7 +1947,7 @@ void compiler::emit_expr_animtree(const ast::expr_animtree::ptr& expr) { if (animtrees_.size() == 0) { - throw comp_error( expr->loc(), "trying to use animtree without specified using animtree"); + throw comp_error(expr->loc(), "trying to use animtree without specified using animtree"); } auto& tree = animtrees_.back(); diff --git a/src/h2/xsk/compiler.hpp b/src/h2/xsk/compiler.hpp index 4c302b03..d86c68df 100644 --- a/src/h2/xsk/compiler.hpp +++ b/src/h2/xsk/compiler.hpp @@ -76,20 +76,20 @@ private: void emit_expr_assign(const ast::expr_assign::ptr& expr, const block::ptr& blk); void emit_expr_clear(const ast::expr& expr, const block::ptr& blk); void emit_expr_clear_local(const ast::expr_identifier::ptr& expr, const block::ptr& blk); - void emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool stmt); - void emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool stmt); + void emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool is_stmt); void emit_expr_ternary(const ast::expr_ternary::ptr& expr, const block::ptr& blk); void emit_expr_binary(const ast::expr_binary::ptr& expr, const block::ptr& blk); void emit_expr_and(const ast::expr_and::ptr& expr, const block::ptr& blk); void emit_expr_or(const ast::expr_or::ptr& expr, const block::ptr& blk); void emit_expr_complement(const ast::expr_complement::ptr& expr, const block::ptr& blk); void emit_expr_not(const ast::expr_not::ptr& expr, const block::ptr& blk); - void emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk); - void emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk); - void emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk); - void emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk); - void emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk); - void emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk); + void emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt); + void emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt); void emit_expr_add_array(const ast::expr_add_array::ptr& expr, const block::ptr& blk); void emit_expr_parameters(const ast::expr_parameters::ptr& expr, const block::ptr& blk); void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk); diff --git a/src/iw5/xsk/compiler.cpp b/src/iw5/xsk/compiler.cpp index 8f1322c0..81f3eebf 100644 --- a/src/iw5/xsk/compiler.cpp +++ b/src/iw5/xsk/compiler.cpp @@ -320,21 +320,11 @@ void compiler::emit_stmt_expr(const ast::stmt_expr::ptr& stmt, const block::ptr& void compiler::emit_stmt_call(const ast::stmt_call::ptr& stmt, const block::ptr& blk) { if (stmt->expr == ast::kind::expr_call) - { - if (mode_ != gsc::build::dev && stmt->expr.as_call->call == ast::kind::expr_function) - { - const auto& name = stmt->expr.as_call->call.as_function->name->value; - if (name == "assert" || name == "assertex" || name == "assertmsg") return; - } - - emit_expr_call(stmt->expr.as_call, blk); - } + emit_expr_call(stmt->expr.as_call, blk, true); else if (stmt->expr == ast::kind::expr_method) - emit_expr_method(stmt->expr.as_method, blk); + emit_expr_method(stmt->expr.as_method, blk, true); else throw comp_error(stmt->loc(), "unknown call statement expression"); - - emit_opcode(opcode::OP_DecTop); } void compiler::emit_stmt_assign(const ast::stmt_assign::ptr& stmt, const block::ptr& blk) @@ -952,10 +942,10 @@ void compiler::emit_expr(const ast::expr& expr, const block::ptr& blk) emit_expr_not(expr.as_not, blk); break; case ast::kind::expr_call: - emit_expr_call(expr.as_call, blk); + emit_expr_call(expr.as_call, blk, false); break; case ast::kind::expr_method: - emit_expr_method(expr.as_method, blk); + emit_expr_method(expr.as_method, blk, false); break; case ast::kind::expr_reference: emit_expr_reference(expr.as_reference, blk); @@ -1119,9 +1109,9 @@ void compiler::emit_expr_clear_local(const ast::expr_identifier::ptr& expr, cons emit_opcode(opcode::OP_ClearLocalVariableFieldCached, variable_access_index(expr, blk)); } -void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool fromstmt) +void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool is_stmt) { - if (fromstmt) + if (is_stmt) { emit_expr_variable_ref(expr->lvalue, blk, false); emit_opcode(opcode::OP_inc); @@ -1133,9 +1123,9 @@ void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const b } } -void compiler::emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool fromstmt) +void compiler::emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool is_stmt) { - if (fromstmt) + if (is_stmt) { emit_expr_variable_ref(expr->lvalue, blk, false); emit_opcode(opcode::OP_dec); @@ -1267,17 +1257,17 @@ void compiler::emit_expr_not(const ast::expr_not::ptr& expr, const block::ptr& b emit_opcode(opcode::OP_BoolNot); } -void compiler::emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->call == ast::kind::expr_pointer) - emit_expr_call_pointer(expr->call.as_pointer, blk); + emit_expr_call_pointer(expr->call.as_pointer, blk, is_stmt); else if (expr->call == ast::kind::expr_function) - emit_expr_call_function(expr->call.as_function, blk); + emit_expr_call_function(expr->call.as_function, blk, is_stmt); else throw comp_error(expr->loc(), "unknown function call expression"); } -void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->mode == ast::call::mode::normal) emit_opcode(opcode::OP_PreScriptCall); @@ -1302,10 +1292,19 @@ void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const emit_opcode(opcode::OP_CallBuiltinPointer, argcount); break; } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk, bool is_stmt) { + if (is_stmt && mode_ == gsc::build::prod) + { + const auto& name = expr->name->value; + if (name == "assert" || name == "assertex" || name == "assertmsg") return; + } + auto type = resolve_function_type(expr); if (type != ast::call::type::builtin && expr->mode == ast::call::mode::normal && expr->args->list.size() > 0) @@ -1387,19 +1386,22 @@ void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, cons break; } } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->call == ast::kind::expr_pointer) - emit_expr_method_pointer(expr->call.as_pointer, expr->obj, blk); + emit_expr_method_pointer(expr->call.as_pointer, expr->obj, blk, is_stmt); else if (expr->call == ast::kind::expr_function) - emit_expr_method_function(expr->call.as_function, expr->obj, blk); + emit_expr_method_function(expr->call.as_function, expr->obj, blk, is_stmt); else throw comp_error(expr->loc(), "unknown method call expression"); } -void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk) +void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt) { if (expr->mode == ast::call::mode::normal) emit_opcode(opcode::OP_PreScriptCall); @@ -1425,9 +1427,12 @@ void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, cons emit_opcode(opcode::OP_CallBuiltinMethodPointer, argcount); break; } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk) +void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt) { auto type = resolve_function_type(expr); @@ -1505,6 +1510,9 @@ void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, co break; } } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } void compiler::emit_expr_add_array(const ast::expr_add_array::ptr& expr, const block::ptr& blk) @@ -1663,13 +1671,13 @@ void compiler::emit_expr_field_ref(const ast::expr_field::ptr& expr, const block if (set) emit_opcode(opcode::OP_SetVariableField); break; case ast::kind::expr_call: - emit_expr_call(expr->obj.as_call, blk); + emit_expr_call(expr->obj.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariableRef, field); if (set) emit_opcode(opcode::OP_SetVariableField); break; case ast::kind::expr_method: - emit_expr_method(expr->obj.as_method, blk); + emit_expr_method(expr->obj.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariableRef, field); if (set) emit_opcode(opcode::OP_SetVariableField); @@ -1774,12 +1782,12 @@ void compiler::emit_expr_field(const ast::expr_field::ptr& expr, const block::pt emit_opcode(opcode::OP_EvalFieldVariable, field); break; case ast::kind::expr_call: - emit_expr_call(expr->obj.as_call, blk); + emit_expr_call(expr->obj.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariable, field); break; case ast::kind::expr_method: - emit_expr_method(expr->obj.as_method, blk); + emit_expr_method(expr->obj.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariable, field); break; @@ -1855,11 +1863,11 @@ void compiler::emit_expr_object(const ast::expr& expr, const block::ptr& blk) emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_call: - emit_expr_call(expr.as_call, blk); + emit_expr_call(expr.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_method: - emit_expr_method(expr.as_method, blk); + emit_expr_method(expr.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_identifier: @@ -1931,7 +1939,7 @@ void compiler::emit_expr_animtree(const ast::expr_animtree::ptr& expr) { if (animtrees_.size() == 0) { - throw comp_error( expr->loc(), "trying to use animtree without specified using animtree"); + throw comp_error(expr->loc(), "trying to use animtree without specified using animtree"); } auto& tree = animtrees_.back(); diff --git a/src/iw5/xsk/compiler.hpp b/src/iw5/xsk/compiler.hpp index 00b90cb6..ed1aa952 100644 --- a/src/iw5/xsk/compiler.hpp +++ b/src/iw5/xsk/compiler.hpp @@ -75,20 +75,20 @@ private: void emit_expr_assign(const ast::expr_assign::ptr& expr, const block::ptr& blk); void emit_expr_clear(const ast::expr& expr, const block::ptr& blk); void emit_expr_clear_local(const ast::expr_identifier::ptr& expr, const block::ptr& blk); - void emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool stmt); - void emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool stmt); + void emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool is_stmt); void emit_expr_ternary(const ast::expr_ternary::ptr& expr, const block::ptr& blk); void emit_expr_binary(const ast::expr_binary::ptr& expr, const block::ptr& blk); void emit_expr_and(const ast::expr_and::ptr& expr, const block::ptr& blk); void emit_expr_or(const ast::expr_or::ptr& expr, const block::ptr& blk); void emit_expr_complement(const ast::expr_complement::ptr& expr, const block::ptr& blk); void emit_expr_not(const ast::expr_not::ptr& expr, const block::ptr& blk); - void emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk); - void emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk); - void emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk); - void emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk); - void emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk); - void emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk); + void emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt); + void emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt); void emit_expr_add_array(const ast::expr_add_array::ptr& expr, const block::ptr& blk); void emit_expr_parameters(const ast::expr_parameters::ptr& expr, const block::ptr& blk); void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk); diff --git a/src/iw6/xsk/compiler.cpp b/src/iw6/xsk/compiler.cpp index b9b2365c..5c73ab9c 100644 --- a/src/iw6/xsk/compiler.cpp +++ b/src/iw6/xsk/compiler.cpp @@ -320,21 +320,11 @@ void compiler::emit_stmt_expr(const ast::stmt_expr::ptr& stmt, const block::ptr& void compiler::emit_stmt_call(const ast::stmt_call::ptr& stmt, const block::ptr& blk) { if (stmt->expr == ast::kind::expr_call) - { - if (mode_ != gsc::build::dev && stmt->expr.as_call->call == ast::kind::expr_function) - { - const auto& name = stmt->expr.as_call->call.as_function->name->value; - if (name == "assert" || name == "assertex" || name == "assertmsg") return; - } - - emit_expr_call(stmt->expr.as_call, blk); - } + emit_expr_call(stmt->expr.as_call, blk, true); else if (stmt->expr == ast::kind::expr_method) - emit_expr_method(stmt->expr.as_method, blk); + emit_expr_method(stmt->expr.as_method, blk, true); else throw comp_error(stmt->loc(), "unknown call statement expression"); - - emit_opcode(opcode::OP_DecTop); } void compiler::emit_stmt_assign(const ast::stmt_assign::ptr& stmt, const block::ptr& blk) @@ -952,10 +942,10 @@ void compiler::emit_expr(const ast::expr& expr, const block::ptr& blk) emit_expr_not(expr.as_not, blk); break; case ast::kind::expr_call: - emit_expr_call(expr.as_call, blk); + emit_expr_call(expr.as_call, blk, false); break; case ast::kind::expr_method: - emit_expr_method(expr.as_method, blk); + emit_expr_method(expr.as_method, blk, false); break; case ast::kind::expr_reference: emit_expr_reference(expr.as_reference, blk); @@ -1119,9 +1109,9 @@ void compiler::emit_expr_clear_local(const ast::expr_identifier::ptr& expr, cons emit_opcode(opcode::OP_ClearLocalVariableFieldCached, variable_access_index(expr, blk)); } -void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool fromstmt) +void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool is_stmt) { - if (fromstmt) + if (is_stmt) { emit_expr_variable_ref(expr->lvalue, blk, false); emit_opcode(opcode::OP_inc); @@ -1133,9 +1123,9 @@ void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const b } } -void compiler::emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool fromstmt) +void compiler::emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool is_stmt) { - if (fromstmt) + if (is_stmt) { emit_expr_variable_ref(expr->lvalue, blk, false); emit_opcode(opcode::OP_dec); @@ -1267,17 +1257,17 @@ void compiler::emit_expr_not(const ast::expr_not::ptr& expr, const block::ptr& b emit_opcode(opcode::OP_BoolNot); } -void compiler::emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->call == ast::kind::expr_pointer) - emit_expr_call_pointer(expr->call.as_pointer, blk); + emit_expr_call_pointer(expr->call.as_pointer, blk, is_stmt); else if (expr->call == ast::kind::expr_function) - emit_expr_call_function(expr->call.as_function, blk); + emit_expr_call_function(expr->call.as_function, blk, is_stmt); else throw comp_error(expr->loc(), "unknown function call expression"); } -void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->mode == ast::call::mode::normal) emit_opcode(opcode::OP_PreScriptCall); @@ -1302,10 +1292,19 @@ void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const emit_opcode(opcode::OP_CallBuiltinPointer, argcount); break; } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk, bool is_stmt) { + if (is_stmt && mode_ == gsc::build::prod) + { + const auto& name = expr->name->value; + if (name == "assert" || name == "assertex" || name == "assertmsg") return; + } + auto type = resolve_function_type(expr); if (type != ast::call::type::builtin && expr->mode == ast::call::mode::normal && expr->args->list.size() > 0) @@ -1387,19 +1386,22 @@ void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, cons break; } } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->call == ast::kind::expr_pointer) - emit_expr_method_pointer(expr->call.as_pointer, expr->obj, blk); + emit_expr_method_pointer(expr->call.as_pointer, expr->obj, blk, is_stmt); else if (expr->call == ast::kind::expr_function) - emit_expr_method_function(expr->call.as_function, expr->obj, blk); + emit_expr_method_function(expr->call.as_function, expr->obj, blk, is_stmt); else throw comp_error(expr->loc(), "unknown method call expression"); } -void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk) +void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt) { if (expr->mode == ast::call::mode::normal) emit_opcode(opcode::OP_PreScriptCall); @@ -1425,9 +1427,12 @@ void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, cons emit_opcode(opcode::OP_CallBuiltinMethodPointer, argcount); break; } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk) +void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt) { auto type = resolve_function_type(expr); @@ -1505,6 +1510,9 @@ void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, co break; } } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } void compiler::emit_expr_add_array(const ast::expr_add_array::ptr& expr, const block::ptr& blk) @@ -1663,13 +1671,13 @@ void compiler::emit_expr_field_ref(const ast::expr_field::ptr& expr, const block if (set) emit_opcode(opcode::OP_SetVariableField); break; case ast::kind::expr_call: - emit_expr_call(expr->obj.as_call, blk); + emit_expr_call(expr->obj.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariableRef, field); if (set) emit_opcode(opcode::OP_SetVariableField); break; case ast::kind::expr_method: - emit_expr_method(expr->obj.as_method, blk); + emit_expr_method(expr->obj.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariableRef, field); if (set) emit_opcode(opcode::OP_SetVariableField); @@ -1774,12 +1782,12 @@ void compiler::emit_expr_field(const ast::expr_field::ptr& expr, const block::pt emit_opcode(opcode::OP_EvalFieldVariable, field); break; case ast::kind::expr_call: - emit_expr_call(expr->obj.as_call, blk); + emit_expr_call(expr->obj.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariable, field); break; case ast::kind::expr_method: - emit_expr_method(expr->obj.as_method, blk); + emit_expr_method(expr->obj.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariable, field); break; @@ -1855,11 +1863,11 @@ void compiler::emit_expr_object(const ast::expr& expr, const block::ptr& blk) emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_call: - emit_expr_call(expr.as_call, blk); + emit_expr_call(expr.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_method: - emit_expr_method(expr.as_method, blk); + emit_expr_method(expr.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_identifier: @@ -1931,7 +1939,7 @@ void compiler::emit_expr_animtree(const ast::expr_animtree::ptr& expr) { if (animtrees_.size() == 0) { - throw comp_error( expr->loc(), "trying to use animtree without specified using animtree"); + throw comp_error(expr->loc(), "trying to use animtree without specified using animtree"); } auto& tree = animtrees_.back(); diff --git a/src/iw6/xsk/compiler.hpp b/src/iw6/xsk/compiler.hpp index d09d6eef..18d91301 100644 --- a/src/iw6/xsk/compiler.hpp +++ b/src/iw6/xsk/compiler.hpp @@ -75,20 +75,20 @@ private: void emit_expr_assign(const ast::expr_assign::ptr& expr, const block::ptr& blk); void emit_expr_clear(const ast::expr& expr, const block::ptr& blk); void emit_expr_clear_local(const ast::expr_identifier::ptr& expr, const block::ptr& blk); - void emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool stmt); - void emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool stmt); + void emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool is_stmt); void emit_expr_ternary(const ast::expr_ternary::ptr& expr, const block::ptr& blk); void emit_expr_binary(const ast::expr_binary::ptr& expr, const block::ptr& blk); void emit_expr_and(const ast::expr_and::ptr& expr, const block::ptr& blk); void emit_expr_or(const ast::expr_or::ptr& expr, const block::ptr& blk); void emit_expr_complement(const ast::expr_complement::ptr& expr, const block::ptr& blk); void emit_expr_not(const ast::expr_not::ptr& expr, const block::ptr& blk); - void emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk); - void emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk); - void emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk); - void emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk); - void emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk); - void emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk); + void emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt); + void emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt); void emit_expr_add_array(const ast::expr_add_array::ptr& expr, const block::ptr& blk); void emit_expr_parameters(const ast::expr_parameters::ptr& expr, const block::ptr& blk); void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk); diff --git a/src/iw7/xsk/compiler.cpp b/src/iw7/xsk/compiler.cpp index 54b68cc4..67c120b1 100644 --- a/src/iw7/xsk/compiler.cpp +++ b/src/iw7/xsk/compiler.cpp @@ -320,21 +320,11 @@ void compiler::emit_stmt_expr(const ast::stmt_expr::ptr& stmt, const block::ptr& void compiler::emit_stmt_call(const ast::stmt_call::ptr& stmt, const block::ptr& blk) { if (stmt->expr == ast::kind::expr_call) - { - if (mode_ != gsc::build::dev && stmt->expr.as_call->call == ast::kind::expr_function) - { - const auto& name = stmt->expr.as_call->call.as_function->name->value; - if (name == "assert" || name == "assertex" || name == "assertmsg") return; - } - - emit_expr_call(stmt->expr.as_call, blk); - } + emit_expr_call(stmt->expr.as_call, blk, true); else if (stmt->expr == ast::kind::expr_method) - emit_expr_method(stmt->expr.as_method, blk); + emit_expr_method(stmt->expr.as_method, blk, true); else throw comp_error(stmt->loc(), "unknown call statement expression"); - - emit_opcode(opcode::OP_DecTop); } void compiler::emit_stmt_assign(const ast::stmt_assign::ptr& stmt, const block::ptr& blk) @@ -952,10 +942,10 @@ void compiler::emit_expr(const ast::expr& expr, const block::ptr& blk) emit_expr_not(expr.as_not, blk); break; case ast::kind::expr_call: - emit_expr_call(expr.as_call, blk); + emit_expr_call(expr.as_call, blk, false); break; case ast::kind::expr_method: - emit_expr_method(expr.as_method, blk); + emit_expr_method(expr.as_method, blk, false); break; case ast::kind::expr_reference: emit_expr_reference(expr.as_reference, blk); @@ -1119,9 +1109,9 @@ void compiler::emit_expr_clear_local(const ast::expr_identifier::ptr& expr, cons emit_opcode(opcode::OP_ClearLocalVariableFieldCached, variable_access_index(expr, blk)); } -void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool fromstmt) +void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool is_stmt) { - if (fromstmt) + if (is_stmt) { emit_expr_variable_ref(expr->lvalue, blk, false); emit_opcode(opcode::OP_inc); @@ -1133,9 +1123,9 @@ void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const b } } -void compiler::emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool fromstmt) +void compiler::emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool is_stmt) { - if (fromstmt) + if (is_stmt) { emit_expr_variable_ref(expr->lvalue, blk, false); emit_opcode(opcode::OP_dec); @@ -1267,17 +1257,17 @@ void compiler::emit_expr_not(const ast::expr_not::ptr& expr, const block::ptr& b emit_opcode(opcode::OP_BoolNot); } -void compiler::emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->call == ast::kind::expr_pointer) - emit_expr_call_pointer(expr->call.as_pointer, blk); + emit_expr_call_pointer(expr->call.as_pointer, blk, is_stmt); else if (expr->call == ast::kind::expr_function) - emit_expr_call_function(expr->call.as_function, blk); + emit_expr_call_function(expr->call.as_function, blk, is_stmt); else throw comp_error(expr->loc(), "unknown function call expression"); } -void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->mode == ast::call::mode::normal) emit_opcode(opcode::OP_PreScriptCall); @@ -1302,10 +1292,19 @@ void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const emit_opcode(opcode::OP_CallBuiltinPointer, argcount); break; } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk, bool is_stmt) { + if (is_stmt && mode_ == gsc::build::prod) + { + const auto& name = expr->name->value; + if (name == "assert" || name == "assertex" || name == "assertmsg") return; + } + auto type = resolve_function_type(expr); if (type != ast::call::type::builtin && expr->mode == ast::call::mode::normal && expr->args->list.size() > 0) @@ -1387,19 +1386,22 @@ void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, cons break; } } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->call == ast::kind::expr_pointer) - emit_expr_method_pointer(expr->call.as_pointer, expr->obj, blk); + emit_expr_method_pointer(expr->call.as_pointer, expr->obj, blk, is_stmt); else if (expr->call == ast::kind::expr_function) - emit_expr_method_function(expr->call.as_function, expr->obj, blk); + emit_expr_method_function(expr->call.as_function, expr->obj, blk, is_stmt); else throw comp_error(expr->loc(), "unknown method call expression"); } -void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk) +void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt) { if (expr->mode == ast::call::mode::normal) emit_opcode(opcode::OP_PreScriptCall); @@ -1425,9 +1427,12 @@ void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, cons emit_opcode(opcode::OP_CallBuiltinMethodPointer, argcount); break; } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk) +void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt) { auto type = resolve_function_type(expr); @@ -1505,6 +1510,9 @@ void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, co break; } } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } void compiler::emit_expr_add_array(const ast::expr_add_array::ptr& expr, const block::ptr& blk) @@ -1663,13 +1671,13 @@ void compiler::emit_expr_field_ref(const ast::expr_field::ptr& expr, const block if (set) emit_opcode(opcode::OP_SetVariableField); break; case ast::kind::expr_call: - emit_expr_call(expr->obj.as_call, blk); + emit_expr_call(expr->obj.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariableRef, field); if (set) emit_opcode(opcode::OP_SetVariableField); break; case ast::kind::expr_method: - emit_expr_method(expr->obj.as_method, blk); + emit_expr_method(expr->obj.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariableRef, field); if (set) emit_opcode(opcode::OP_SetVariableField); @@ -1774,12 +1782,12 @@ void compiler::emit_expr_field(const ast::expr_field::ptr& expr, const block::pt emit_opcode(opcode::OP_EvalFieldVariable, field); break; case ast::kind::expr_call: - emit_expr_call(expr->obj.as_call, blk); + emit_expr_call(expr->obj.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariable, field); break; case ast::kind::expr_method: - emit_expr_method(expr->obj.as_method, blk); + emit_expr_method(expr->obj.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariable, field); break; @@ -1855,11 +1863,11 @@ void compiler::emit_expr_object(const ast::expr& expr, const block::ptr& blk) emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_call: - emit_expr_call(expr.as_call, blk); + emit_expr_call(expr.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_method: - emit_expr_method(expr.as_method, blk); + emit_expr_method(expr.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_identifier: @@ -1931,7 +1939,7 @@ void compiler::emit_expr_animtree(const ast::expr_animtree::ptr& expr) { if (animtrees_.size() == 0) { - throw comp_error( expr->loc(), "trying to use animtree without specified using animtree"); + throw comp_error(expr->loc(), "trying to use animtree without specified using animtree"); } auto& tree = animtrees_.back(); diff --git a/src/iw7/xsk/compiler.hpp b/src/iw7/xsk/compiler.hpp index ed872751..f717c496 100644 --- a/src/iw7/xsk/compiler.hpp +++ b/src/iw7/xsk/compiler.hpp @@ -75,20 +75,20 @@ private: void emit_expr_assign(const ast::expr_assign::ptr& expr, const block::ptr& blk); void emit_expr_clear(const ast::expr& expr, const block::ptr& blk); void emit_expr_clear_local(const ast::expr_identifier::ptr& expr, const block::ptr& blk); - void emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool stmt); - void emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool stmt); + void emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool is_stmt); void emit_expr_ternary(const ast::expr_ternary::ptr& expr, const block::ptr& blk); void emit_expr_binary(const ast::expr_binary::ptr& expr, const block::ptr& blk); void emit_expr_and(const ast::expr_and::ptr& expr, const block::ptr& blk); void emit_expr_or(const ast::expr_or::ptr& expr, const block::ptr& blk); void emit_expr_complement(const ast::expr_complement::ptr& expr, const block::ptr& blk); void emit_expr_not(const ast::expr_not::ptr& expr, const block::ptr& blk); - void emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk); - void emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk); - void emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk); - void emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk); - void emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk); - void emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk); + void emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt); + void emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt); void emit_expr_add_array(const ast::expr_add_array::ptr& expr, const block::ptr& blk); void emit_expr_parameters(const ast::expr_parameters::ptr& expr, const block::ptr& blk); void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk); diff --git a/src/iw8/xsk/compiler.cpp b/src/iw8/xsk/compiler.cpp index 77084f03..042566a0 100644 --- a/src/iw8/xsk/compiler.cpp +++ b/src/iw8/xsk/compiler.cpp @@ -323,21 +323,11 @@ void compiler::emit_stmt_expr(const ast::stmt_expr::ptr& stmt, const block::ptr& void compiler::emit_stmt_call(const ast::stmt_call::ptr& stmt, const block::ptr& blk) { if (stmt->expr == ast::kind::expr_call) - { - if (mode_ != gsc::build::dev && stmt->expr.as_call->call == ast::kind::expr_function) - { - const auto& name = stmt->expr.as_call->call.as_function->name->value; - if (name == "assert" || name == "assertex" || name == "assertmsg") return; - } - - emit_expr_call(stmt->expr.as_call, blk); - } + emit_expr_call(stmt->expr.as_call, blk, true); else if (stmt->expr == ast::kind::expr_method) - emit_expr_method(stmt->expr.as_method, blk); + emit_expr_method(stmt->expr.as_method, blk, true); else throw comp_error(stmt->loc(), "unknown call statement expression"); - - emit_opcode(opcode::OP_DecTop); } void compiler::emit_stmt_assign(const ast::stmt_assign::ptr& stmt, const block::ptr& blk) @@ -960,10 +950,10 @@ void compiler::emit_expr(const ast::expr& expr, const block::ptr& blk) emit_expr_not(expr.as_not, blk); break; case ast::kind::expr_call: - emit_expr_call(expr.as_call, blk); + emit_expr_call(expr.as_call, blk, false); break; case ast::kind::expr_method: - emit_expr_method(expr.as_method, blk); + emit_expr_method(expr.as_method, blk, false); break; case ast::kind::expr_isdefined: emit_expr_isdefined(expr.as_isdefined, blk); @@ -1133,9 +1123,9 @@ void compiler::emit_expr_clear_local(const ast::expr_identifier::ptr& expr, cons emit_opcode(opcode::OP_ClearLocalVariableFieldCached, variable_access_index(expr, blk)); } -void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool fromstmt) +void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool is_stmt) { - if (fromstmt) + if (is_stmt) { emit_expr_variable_ref(expr->lvalue, blk, false); emit_opcode(opcode::OP_inc); @@ -1147,9 +1137,9 @@ void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const b } } -void compiler::emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool fromstmt) +void compiler::emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool is_stmt) { - if (fromstmt) + if (is_stmt) { emit_expr_variable_ref(expr->lvalue, blk, false); emit_opcode(opcode::OP_dec); @@ -1299,17 +1289,17 @@ void compiler::emit_expr_not(const ast::expr_not::ptr& expr, const block::ptr& b emit_opcode(opcode::OP_BoolNot); } -void compiler::emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->call == ast::kind::expr_pointer) - emit_expr_call_pointer(expr->call.as_pointer, blk); + emit_expr_call_pointer(expr->call.as_pointer, blk, is_stmt); else if (expr->call == ast::kind::expr_function) - emit_expr_call_function(expr->call.as_function, blk); + emit_expr_call_function(expr->call.as_function, blk, is_stmt); else throw comp_error(expr->loc(), "unknown function call expression"); } -void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->mode == ast::call::mode::normal) emit_opcode(opcode::OP_PreScriptCall); @@ -1334,10 +1324,19 @@ void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const emit_opcode(opcode::OP_CallBuiltinPointer, argcount); break; } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk, bool is_stmt) { + if (is_stmt && mode_ == gsc::build::prod) + { + const auto& name = expr->name->value; + if (name == "assert" || name == "assertex" || name == "assertmsg") return; + } + auto type = resolve_function_type(expr); if (type != ast::call::type::builtin && expr->mode == ast::call::mode::normal && expr->args->list.size() > 0) @@ -1419,19 +1418,22 @@ void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, cons break; } } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->call == ast::kind::expr_pointer) - emit_expr_method_pointer(expr->call.as_pointer, expr->obj, blk); + emit_expr_method_pointer(expr->call.as_pointer, expr->obj, blk, is_stmt); else if (expr->call == ast::kind::expr_function) - emit_expr_method_function(expr->call.as_function, expr->obj, blk); + emit_expr_method_function(expr->call.as_function, expr->obj, blk, is_stmt); else throw comp_error(expr->loc(), "unknown method call expression"); } -void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk) +void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt) { if (expr->mode == ast::call::mode::normal) emit_opcode(opcode::OP_PreScriptCall); @@ -1457,9 +1459,12 @@ void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, cons emit_opcode(opcode::OP_CallBuiltinMethodPointer, argcount); break; } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk) +void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt) { auto type = resolve_function_type(expr); @@ -1537,6 +1542,9 @@ void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, co break; } } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } void compiler::emit_expr_add_array(const ast::expr_add_array::ptr& expr, const block::ptr& blk) @@ -1722,13 +1730,13 @@ void compiler::emit_expr_field_ref(const ast::expr_field::ptr& expr, const block if (set) emit_opcode(opcode::OP_SetVariableField); break; case ast::kind::expr_call: - emit_expr_call(expr->obj.as_call, blk); + emit_expr_call(expr->obj.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariableRef, field); if (set) emit_opcode(opcode::OP_SetVariableField); break; case ast::kind::expr_method: - emit_expr_method(expr->obj.as_method, blk); + emit_expr_method(expr->obj.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariableRef, field); if (set) emit_opcode(opcode::OP_SetVariableField); @@ -1833,12 +1841,12 @@ void compiler::emit_expr_field(const ast::expr_field::ptr& expr, const block::pt emit_opcode(opcode::OP_EvalFieldVariable, field); break; case ast::kind::expr_call: - emit_expr_call(expr->obj.as_call, blk); + emit_expr_call(expr->obj.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariable, field); break; case ast::kind::expr_method: - emit_expr_method(expr->obj.as_method, blk); + emit_expr_method(expr->obj.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariable, field); break; @@ -1914,11 +1922,11 @@ void compiler::emit_expr_object(const ast::expr& expr, const block::ptr& blk) emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_call: - emit_expr_call(expr.as_call, blk); + emit_expr_call(expr.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_method: - emit_expr_method(expr.as_method, blk); + emit_expr_method(expr.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_identifier: @@ -1990,7 +1998,7 @@ void compiler::emit_expr_animtree(const ast::expr_animtree::ptr& expr) { if (animtrees_.size() == 0) { - throw comp_error( expr->loc(), "trying to use animtree without specified using animtree"); + throw comp_error(expr->loc(), "trying to use animtree without specified using animtree"); } auto& tree = animtrees_.back(); diff --git a/src/iw8/xsk/compiler.hpp b/src/iw8/xsk/compiler.hpp index d44d78c2..f27c0860 100644 --- a/src/iw8/xsk/compiler.hpp +++ b/src/iw8/xsk/compiler.hpp @@ -76,20 +76,20 @@ private: void emit_expr_assign(const ast::expr_assign::ptr& expr, const block::ptr& blk); void emit_expr_clear(const ast::expr& expr, const block::ptr& blk); void emit_expr_clear_local(const ast::expr_identifier::ptr& expr, const block::ptr& blk); - void emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool stmt); - void emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool stmt); + void emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool is_stmt); void emit_expr_ternary(const ast::expr_ternary::ptr& expr, const block::ptr& blk); void emit_expr_binary(const ast::expr_binary::ptr& expr, const block::ptr& blk); void emit_expr_and(const ast::expr_and::ptr& expr, const block::ptr& blk); void emit_expr_or(const ast::expr_or::ptr& expr, const block::ptr& blk); void emit_expr_complement(const ast::expr_complement::ptr& expr, const block::ptr& blk); void emit_expr_not(const ast::expr_not::ptr& expr, const block::ptr& blk); - void emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk); - void emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk); - void emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk); - void emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk); - void emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk); - void emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk); + void emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt); + void emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt); void emit_expr_add_array(const ast::expr_add_array::ptr& expr, const block::ptr& blk); void emit_expr_parameters(const ast::expr_parameters::ptr& expr, const block::ptr& blk); void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk); diff --git a/src/s1/xsk/compiler.cpp b/src/s1/xsk/compiler.cpp index e1d381c7..d32681a8 100644 --- a/src/s1/xsk/compiler.cpp +++ b/src/s1/xsk/compiler.cpp @@ -323,21 +323,11 @@ void compiler::emit_stmt_expr(const ast::stmt_expr::ptr& stmt, const block::ptr& void compiler::emit_stmt_call(const ast::stmt_call::ptr& stmt, const block::ptr& blk) { if (stmt->expr == ast::kind::expr_call) - { - if (mode_ != gsc::build::dev && stmt->expr.as_call->call == ast::kind::expr_function) - { - const auto& name = stmt->expr.as_call->call.as_function->name->value; - if (name == "assert" || name == "assertex" || name == "assertmsg") return; - } - - emit_expr_call(stmt->expr.as_call, blk); - } + emit_expr_call(stmt->expr.as_call, blk, true); else if (stmt->expr == ast::kind::expr_method) - emit_expr_method(stmt->expr.as_method, blk); + emit_expr_method(stmt->expr.as_method, blk, true); else throw comp_error(stmt->loc(), "unknown call statement expression"); - - emit_opcode(opcode::OP_DecTop); } void compiler::emit_stmt_assign(const ast::stmt_assign::ptr& stmt, const block::ptr& blk) @@ -960,10 +950,10 @@ void compiler::emit_expr(const ast::expr& expr, const block::ptr& blk) emit_expr_not(expr.as_not, blk); break; case ast::kind::expr_call: - emit_expr_call(expr.as_call, blk); + emit_expr_call(expr.as_call, blk, false); break; case ast::kind::expr_method: - emit_expr_method(expr.as_method, blk); + emit_expr_method(expr.as_method, blk, false); break; case ast::kind::expr_reference: emit_expr_reference(expr.as_reference, blk); @@ -1127,9 +1117,9 @@ void compiler::emit_expr_clear_local(const ast::expr_identifier::ptr& expr, cons emit_opcode(opcode::OP_ClearLocalVariableFieldCached, variable_access_index(expr, blk)); } -void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool fromstmt) +void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool is_stmt) { - if (fromstmt) + if (is_stmt) { emit_expr_variable_ref(expr->lvalue, blk, false); emit_opcode(opcode::OP_inc); @@ -1141,9 +1131,9 @@ void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const b } } -void compiler::emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool fromstmt) +void compiler::emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool is_stmt) { - if (fromstmt) + if (is_stmt) { emit_expr_variable_ref(expr->lvalue, blk, false); emit_opcode(opcode::OP_dec); @@ -1275,17 +1265,17 @@ void compiler::emit_expr_not(const ast::expr_not::ptr& expr, const block::ptr& b emit_opcode(opcode::OP_BoolNot); } -void compiler::emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->call == ast::kind::expr_pointer) - emit_expr_call_pointer(expr->call.as_pointer, blk); + emit_expr_call_pointer(expr->call.as_pointer, blk, is_stmt); else if (expr->call == ast::kind::expr_function) - emit_expr_call_function(expr->call.as_function, blk); + emit_expr_call_function(expr->call.as_function, blk, is_stmt); else throw comp_error(expr->loc(), "unknown function call expression"); } -void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->mode == ast::call::mode::normal) emit_opcode(opcode::OP_PreScriptCall); @@ -1310,10 +1300,19 @@ void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const emit_opcode(opcode::OP_CallBuiltinPointer, argcount); break; } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk, bool is_stmt) { + if (is_stmt && mode_ == gsc::build::prod) + { + const auto& name = expr->name->value; + if (name == "assert" || name == "assertex" || name == "assertmsg") return; + } + auto type = resolve_function_type(expr); if (type != ast::call::type::builtin && expr->mode == ast::call::mode::normal && expr->args->list.size() > 0) @@ -1395,19 +1394,22 @@ void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, cons break; } } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->call == ast::kind::expr_pointer) - emit_expr_method_pointer(expr->call.as_pointer, expr->obj, blk); + emit_expr_method_pointer(expr->call.as_pointer, expr->obj, blk, is_stmt); else if (expr->call == ast::kind::expr_function) - emit_expr_method_function(expr->call.as_function, expr->obj, blk); + emit_expr_method_function(expr->call.as_function, expr->obj, blk, is_stmt); else throw comp_error(expr->loc(), "unknown method call expression"); } -void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk) +void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt) { if (expr->mode == ast::call::mode::normal) emit_opcode(opcode::OP_PreScriptCall); @@ -1433,9 +1435,12 @@ void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, cons emit_opcode(opcode::OP_CallBuiltinMethodPointer, argcount); break; } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk) +void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt) { auto type = resolve_function_type(expr); @@ -1513,6 +1518,9 @@ void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, co break; } } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } void compiler::emit_expr_add_array(const ast::expr_add_array::ptr& expr, const block::ptr& blk) @@ -1671,13 +1679,13 @@ void compiler::emit_expr_field_ref(const ast::expr_field::ptr& expr, const block if (set) emit_opcode(opcode::OP_SetVariableField); break; case ast::kind::expr_call: - emit_expr_call(expr->obj.as_call, blk); + emit_expr_call(expr->obj.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariableRef, field); if (set) emit_opcode(opcode::OP_SetVariableField); break; case ast::kind::expr_method: - emit_expr_method(expr->obj.as_method, blk); + emit_expr_method(expr->obj.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariableRef, field); if (set) emit_opcode(opcode::OP_SetVariableField); @@ -1782,12 +1790,12 @@ void compiler::emit_expr_field(const ast::expr_field::ptr& expr, const block::pt emit_opcode(opcode::OP_EvalFieldVariable, field); break; case ast::kind::expr_call: - emit_expr_call(expr->obj.as_call, blk); + emit_expr_call(expr->obj.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariable, field); break; case ast::kind::expr_method: - emit_expr_method(expr->obj.as_method, blk); + emit_expr_method(expr->obj.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariable, field); break; @@ -1863,11 +1871,11 @@ void compiler::emit_expr_object(const ast::expr& expr, const block::ptr& blk) emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_call: - emit_expr_call(expr.as_call, blk); + emit_expr_call(expr.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_method: - emit_expr_method(expr.as_method, blk); + emit_expr_method(expr.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_identifier: @@ -1939,7 +1947,7 @@ void compiler::emit_expr_animtree(const ast::expr_animtree::ptr& expr) { if (animtrees_.size() == 0) { - throw comp_error( expr->loc(), "trying to use animtree without specified using animtree"); + throw comp_error(expr->loc(), "trying to use animtree without specified using animtree"); } auto& tree = animtrees_.back(); diff --git a/src/s1/xsk/compiler.hpp b/src/s1/xsk/compiler.hpp index 0332f57d..49ae5b87 100644 --- a/src/s1/xsk/compiler.hpp +++ b/src/s1/xsk/compiler.hpp @@ -76,20 +76,20 @@ private: void emit_expr_assign(const ast::expr_assign::ptr& expr, const block::ptr& blk); void emit_expr_clear(const ast::expr& expr, const block::ptr& blk); void emit_expr_clear_local(const ast::expr_identifier::ptr& expr, const block::ptr& blk); - void emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool stmt); - void emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool stmt); + void emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool is_stmt); void emit_expr_ternary(const ast::expr_ternary::ptr& expr, const block::ptr& blk); void emit_expr_binary(const ast::expr_binary::ptr& expr, const block::ptr& blk); void emit_expr_and(const ast::expr_and::ptr& expr, const block::ptr& blk); void emit_expr_or(const ast::expr_or::ptr& expr, const block::ptr& blk); void emit_expr_complement(const ast::expr_complement::ptr& expr, const block::ptr& blk); void emit_expr_not(const ast::expr_not::ptr& expr, const block::ptr& blk); - void emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk); - void emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk); - void emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk); - void emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk); - void emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk); - void emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk); + void emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt); + void emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt); void emit_expr_add_array(const ast::expr_add_array::ptr& expr, const block::ptr& blk); void emit_expr_parameters(const ast::expr_parameters::ptr& expr, const block::ptr& blk); void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk); diff --git a/src/s2/xsk/compiler.cpp b/src/s2/xsk/compiler.cpp index dda744ca..2a66f76e 100644 --- a/src/s2/xsk/compiler.cpp +++ b/src/s2/xsk/compiler.cpp @@ -323,21 +323,11 @@ void compiler::emit_stmt_expr(const ast::stmt_expr::ptr& stmt, const block::ptr& void compiler::emit_stmt_call(const ast::stmt_call::ptr& stmt, const block::ptr& blk) { if (stmt->expr == ast::kind::expr_call) - { - if (mode_ != gsc::build::dev && stmt->expr.as_call->call == ast::kind::expr_function) - { - const auto& name = stmt->expr.as_call->call.as_function->name->value; - if (name == "assert" || name == "assertex" || name == "assertmsg") return; - } - - emit_expr_call(stmt->expr.as_call, blk); - } + emit_expr_call(stmt->expr.as_call, blk, true); else if (stmt->expr == ast::kind::expr_method) - emit_expr_method(stmt->expr.as_method, blk); + emit_expr_method(stmt->expr.as_method, blk, true); else throw comp_error(stmt->loc(), "unknown call statement expression"); - - emit_opcode(opcode::OP_DecTop); } void compiler::emit_stmt_assign(const ast::stmt_assign::ptr& stmt, const block::ptr& blk) @@ -960,10 +950,10 @@ void compiler::emit_expr(const ast::expr& expr, const block::ptr& blk) emit_expr_not(expr.as_not, blk); break; case ast::kind::expr_call: - emit_expr_call(expr.as_call, blk); + emit_expr_call(expr.as_call, blk, false); break; case ast::kind::expr_method: - emit_expr_method(expr.as_method, blk); + emit_expr_method(expr.as_method, blk, false); break; case ast::kind::expr_reference: emit_expr_reference(expr.as_reference, blk); @@ -1127,9 +1117,9 @@ void compiler::emit_expr_clear_local(const ast::expr_identifier::ptr& expr, cons emit_opcode(opcode::OP_ClearLocalVariableFieldCached, variable_access_index(expr, blk)); } -void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool fromstmt) +void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool is_stmt) { - if (fromstmt) + if (is_stmt) { emit_expr_variable_ref(expr->lvalue, blk, false); emit_opcode(opcode::OP_inc); @@ -1141,9 +1131,9 @@ void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const b } } -void compiler::emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool fromstmt) +void compiler::emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool is_stmt) { - if (fromstmt) + if (is_stmt) { emit_expr_variable_ref(expr->lvalue, blk, false); emit_opcode(opcode::OP_dec); @@ -1275,17 +1265,17 @@ void compiler::emit_expr_not(const ast::expr_not::ptr& expr, const block::ptr& b emit_opcode(opcode::OP_BoolNot); } -void compiler::emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->call == ast::kind::expr_pointer) - emit_expr_call_pointer(expr->call.as_pointer, blk); + emit_expr_call_pointer(expr->call.as_pointer, blk, is_stmt); else if (expr->call == ast::kind::expr_function) - emit_expr_call_function(expr->call.as_function, blk); + emit_expr_call_function(expr->call.as_function, blk, is_stmt); else throw comp_error(expr->loc(), "unknown function call expression"); } -void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->mode == ast::call::mode::normal) emit_opcode(opcode::OP_PreScriptCall); @@ -1310,10 +1300,19 @@ void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const emit_opcode(opcode::OP_CallBuiltinPointer, argcount); break; } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk, bool is_stmt) { + if (is_stmt && mode_ == gsc::build::prod) + { + const auto& name = expr->name->value; + if (name == "assert" || name == "assertex" || name == "assertmsg") return; + } + auto type = resolve_function_type(expr); if (type != ast::call::type::builtin && expr->mode == ast::call::mode::normal && expr->args->list.size() > 0) @@ -1395,19 +1394,22 @@ void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, cons break; } } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->call == ast::kind::expr_pointer) - emit_expr_method_pointer(expr->call.as_pointer, expr->obj, blk); + emit_expr_method_pointer(expr->call.as_pointer, expr->obj, blk, is_stmt); else if (expr->call == ast::kind::expr_function) - emit_expr_method_function(expr->call.as_function, expr->obj, blk); + emit_expr_method_function(expr->call.as_function, expr->obj, blk, is_stmt); else throw comp_error(expr->loc(), "unknown method call expression"); } -void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk) +void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt) { if (expr->mode == ast::call::mode::normal) emit_opcode(opcode::OP_PreScriptCall); @@ -1433,9 +1435,12 @@ void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, cons emit_opcode(opcode::OP_CallBuiltinMethodPointer, argcount); break; } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk) +void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt) { auto type = resolve_function_type(expr); @@ -1513,6 +1518,9 @@ void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, co break; } } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } void compiler::emit_expr_add_array(const ast::expr_add_array::ptr& expr, const block::ptr& blk) @@ -1671,13 +1679,13 @@ void compiler::emit_expr_field_ref(const ast::expr_field::ptr& expr, const block if (set) emit_opcode(opcode::OP_SetVariableField); break; case ast::kind::expr_call: - emit_expr_call(expr->obj.as_call, blk); + emit_expr_call(expr->obj.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariableRef, field); if (set) emit_opcode(opcode::OP_SetVariableField); break; case ast::kind::expr_method: - emit_expr_method(expr->obj.as_method, blk); + emit_expr_method(expr->obj.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariableRef, field); if (set) emit_opcode(opcode::OP_SetVariableField); @@ -1782,12 +1790,12 @@ void compiler::emit_expr_field(const ast::expr_field::ptr& expr, const block::pt emit_opcode(opcode::OP_EvalFieldVariable, field); break; case ast::kind::expr_call: - emit_expr_call(expr->obj.as_call, blk); + emit_expr_call(expr->obj.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariable, field); break; case ast::kind::expr_method: - emit_expr_method(expr->obj.as_method, blk); + emit_expr_method(expr->obj.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariable, field); break; @@ -1863,11 +1871,11 @@ void compiler::emit_expr_object(const ast::expr& expr, const block::ptr& blk) emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_call: - emit_expr_call(expr.as_call, blk); + emit_expr_call(expr.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_method: - emit_expr_method(expr.as_method, blk); + emit_expr_method(expr.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_identifier: @@ -1939,7 +1947,7 @@ void compiler::emit_expr_animtree(const ast::expr_animtree::ptr& expr) { if (animtrees_.size() == 0) { - throw comp_error( expr->loc(), "trying to use animtree without specified using animtree"); + throw comp_error(expr->loc(), "trying to use animtree without specified using animtree"); } auto& tree = animtrees_.back(); diff --git a/src/s2/xsk/compiler.hpp b/src/s2/xsk/compiler.hpp index 9d0e1f9b..e02e0cc7 100644 --- a/src/s2/xsk/compiler.hpp +++ b/src/s2/xsk/compiler.hpp @@ -76,20 +76,20 @@ private: void emit_expr_assign(const ast::expr_assign::ptr& expr, const block::ptr& blk); void emit_expr_clear(const ast::expr& expr, const block::ptr& blk); void emit_expr_clear_local(const ast::expr_identifier::ptr& expr, const block::ptr& blk); - void emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool stmt); - void emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool stmt); + void emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool is_stmt); void emit_expr_ternary(const ast::expr_ternary::ptr& expr, const block::ptr& blk); void emit_expr_binary(const ast::expr_binary::ptr& expr, const block::ptr& blk); void emit_expr_and(const ast::expr_and::ptr& expr, const block::ptr& blk); void emit_expr_or(const ast::expr_or::ptr& expr, const block::ptr& blk); void emit_expr_complement(const ast::expr_complement::ptr& expr, const block::ptr& blk); void emit_expr_not(const ast::expr_not::ptr& expr, const block::ptr& blk); - void emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk); - void emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk); - void emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk); - void emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk); - void emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk); - void emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk); + void emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt); + void emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt); void emit_expr_add_array(const ast::expr_add_array::ptr& expr, const block::ptr& blk); void emit_expr_parameters(const ast::expr_parameters::ptr& expr, const block::ptr& blk); void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk); diff --git a/src/s4/xsk/compiler.cpp b/src/s4/xsk/compiler.cpp index 02435d60..aef5e3dc 100644 --- a/src/s4/xsk/compiler.cpp +++ b/src/s4/xsk/compiler.cpp @@ -323,21 +323,11 @@ void compiler::emit_stmt_expr(const ast::stmt_expr::ptr& stmt, const block::ptr& void compiler::emit_stmt_call(const ast::stmt_call::ptr& stmt, const block::ptr& blk) { if (stmt->expr == ast::kind::expr_call) - { - if (mode_ != gsc::build::dev && stmt->expr.as_call->call == ast::kind::expr_function) - { - const auto& name = stmt->expr.as_call->call.as_function->name->value; - if (name == "assert" || name == "assertex" || name == "assertmsg") return; - } - - emit_expr_call(stmt->expr.as_call, blk); - } + emit_expr_call(stmt->expr.as_call, blk, true); else if (stmt->expr == ast::kind::expr_method) - emit_expr_method(stmt->expr.as_method, blk); + emit_expr_method(stmt->expr.as_method, blk, true); else throw comp_error(stmt->loc(), "unknown call statement expression"); - - emit_opcode(opcode::OP_DecTop); } void compiler::emit_stmt_assign(const ast::stmt_assign::ptr& stmt, const block::ptr& blk) @@ -960,10 +950,10 @@ void compiler::emit_expr(const ast::expr& expr, const block::ptr& blk) emit_expr_not(expr.as_not, blk); break; case ast::kind::expr_call: - emit_expr_call(expr.as_call, blk); + emit_expr_call(expr.as_call, blk, false); break; case ast::kind::expr_method: - emit_expr_method(expr.as_method, blk); + emit_expr_method(expr.as_method, blk, false); break; case ast::kind::expr_isdefined: emit_expr_isdefined(expr.as_isdefined, blk); @@ -1133,9 +1123,9 @@ void compiler::emit_expr_clear_local(const ast::expr_identifier::ptr& expr, cons emit_opcode(opcode::OP_ClearLocalVariableFieldCached, variable_access_index(expr, blk)); } -void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool fromstmt) +void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool is_stmt) { - if (fromstmt) + if (is_stmt) { emit_expr_variable_ref(expr->lvalue, blk, false); emit_opcode(opcode::OP_inc); @@ -1147,9 +1137,9 @@ void compiler::emit_expr_increment(const ast::expr_increment::ptr& expr, const b } } -void compiler::emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool fromstmt) +void compiler::emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool is_stmt) { - if (fromstmt) + if (is_stmt) { emit_expr_variable_ref(expr->lvalue, blk, false); emit_opcode(opcode::OP_dec); @@ -1299,17 +1289,17 @@ void compiler::emit_expr_not(const ast::expr_not::ptr& expr, const block::ptr& b emit_opcode(opcode::OP_BoolNot); } -void compiler::emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->call == ast::kind::expr_pointer) - emit_expr_call_pointer(expr->call.as_pointer, blk); + emit_expr_call_pointer(expr->call.as_pointer, blk, is_stmt); else if (expr->call == ast::kind::expr_function) - emit_expr_call_function(expr->call.as_function, blk); + emit_expr_call_function(expr->call.as_function, blk, is_stmt); else throw comp_error(expr->loc(), "unknown function call expression"); } -void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->mode == ast::call::mode::normal) emit_opcode(opcode::OP_PreScriptCall); @@ -1334,10 +1324,19 @@ void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const emit_opcode(opcode::OP_CallBuiltinPointer, argcount); break; } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk, bool is_stmt) { + if (is_stmt && mode_ == gsc::build::prod) + { + const auto& name = expr->name->value; + if (name == "assert" || name == "assertex" || name == "assertmsg") return; + } + auto type = resolve_function_type(expr); if (type != ast::call::type::builtin && expr->mode == ast::call::mode::normal && expr->args->list.size() > 0) @@ -1419,19 +1418,22 @@ void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, cons break; } } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk) +void compiler::emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk, bool is_stmt) { if (expr->call == ast::kind::expr_pointer) - emit_expr_method_pointer(expr->call.as_pointer, expr->obj, blk); + emit_expr_method_pointer(expr->call.as_pointer, expr->obj, blk, is_stmt); else if (expr->call == ast::kind::expr_function) - emit_expr_method_function(expr->call.as_function, expr->obj, blk); + emit_expr_method_function(expr->call.as_function, expr->obj, blk, is_stmt); else throw comp_error(expr->loc(), "unknown method call expression"); } -void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk) +void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt) { if (expr->mode == ast::call::mode::normal) emit_opcode(opcode::OP_PreScriptCall); @@ -1457,9 +1459,12 @@ void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, cons emit_opcode(opcode::OP_CallBuiltinMethodPointer, argcount); break; } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } -void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk) +void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt) { auto type = resolve_function_type(expr); @@ -1537,6 +1542,9 @@ void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, co break; } } + + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } void compiler::emit_expr_add_array(const ast::expr_add_array::ptr& expr, const block::ptr& blk) @@ -1722,13 +1730,13 @@ void compiler::emit_expr_field_ref(const ast::expr_field::ptr& expr, const block if (set) emit_opcode(opcode::OP_SetVariableField); break; case ast::kind::expr_call: - emit_expr_call(expr->obj.as_call, blk); + emit_expr_call(expr->obj.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariableRef, field); if (set) emit_opcode(opcode::OP_SetVariableField); break; case ast::kind::expr_method: - emit_expr_method(expr->obj.as_method, blk); + emit_expr_method(expr->obj.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariableRef, field); if (set) emit_opcode(opcode::OP_SetVariableField); @@ -1833,12 +1841,12 @@ void compiler::emit_expr_field(const ast::expr_field::ptr& expr, const block::pt emit_opcode(opcode::OP_EvalFieldVariable, field); break; case ast::kind::expr_call: - emit_expr_call(expr->obj.as_call, blk); + emit_expr_call(expr->obj.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariable, field); break; case ast::kind::expr_method: - emit_expr_method(expr->obj.as_method, blk); + emit_expr_method(expr->obj.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); emit_opcode(opcode::OP_EvalFieldVariable, field); break; @@ -1914,11 +1922,11 @@ void compiler::emit_expr_object(const ast::expr& expr, const block::ptr& blk) emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_call: - emit_expr_call(expr.as_call, blk); + emit_expr_call(expr.as_call, blk, false); emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_method: - emit_expr_method(expr.as_method, blk); + emit_expr_method(expr.as_method, blk, false); emit_opcode(opcode::OP_CastFieldObject); break; case ast::kind::expr_identifier: diff --git a/src/s4/xsk/compiler.hpp b/src/s4/xsk/compiler.hpp index a0607ec0..1745bc67 100644 --- a/src/s4/xsk/compiler.hpp +++ b/src/s4/xsk/compiler.hpp @@ -76,20 +76,20 @@ private: void emit_expr_assign(const ast::expr_assign::ptr& expr, const block::ptr& blk); void emit_expr_clear(const ast::expr& expr, const block::ptr& blk); void emit_expr_clear_local(const ast::expr_identifier::ptr& expr, const block::ptr& blk); - void emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool stmt); - void emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool stmt); + void emit_expr_increment(const ast::expr_increment::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_decrement(const ast::expr_decrement::ptr& expr, const block::ptr& blk, bool is_stmt); void emit_expr_ternary(const ast::expr_ternary::ptr& expr, const block::ptr& blk); void emit_expr_binary(const ast::expr_binary::ptr& expr, const block::ptr& blk); void emit_expr_and(const ast::expr_and::ptr& expr, const block::ptr& blk); void emit_expr_or(const ast::expr_or::ptr& expr, const block::ptr& blk); void emit_expr_complement(const ast::expr_complement::ptr& expr, const block::ptr& blk); void emit_expr_not(const ast::expr_not::ptr& expr, const block::ptr& blk); - void emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk); - void emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk); - void emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk); - void emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk); - void emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk); - void emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk); + void emit_expr_call(const ast::expr_call::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_call_function(const ast::expr_function::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_method(const ast::expr_method::ptr& expr, const block::ptr& blk, bool is_stmt); + void emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt); + void emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, const block::ptr& blk, bool is_stmt); void emit_expr_add_array(const ast::expr_add_array::ptr& expr, const block::ptr& blk); void emit_expr_parameters(const ast::expr_parameters::ptr& expr, const block::ptr& blk); void emit_expr_arguments(const ast::expr_arguments::ptr& expr, const block::ptr& blk); diff --git a/src/t6/xsk/compiler.cpp b/src/t6/xsk/compiler.cpp index 66d81807..5bfb7a4a 100644 --- a/src/t6/xsk/compiler.cpp +++ b/src/t6/xsk/compiler.cpp @@ -1196,7 +1196,8 @@ void compiler::emit_expr_call_pointer(const ast::expr_pointer::ptr& expr, bool i break; } - if (is_stmt) emit_opcode(opcode::OP_DecTop); + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, bool is_stmt) @@ -1252,7 +1253,8 @@ void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, bool break; } - if (is_stmt) emit_opcode(opcode::OP_DecTop); + if (is_stmt) + emit_opcode(opcode::OP_DecTop); if (as_dev) { @@ -1292,7 +1294,8 @@ void compiler::emit_expr_method_pointer(const ast::expr_pointer::ptr& expr, cons break; } - if (is_stmt) emit_opcode(opcode::OP_DecTop); + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, const ast::expr& obj, bool is_stmt) @@ -1339,7 +1342,8 @@ void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, co break; } - if (is_stmt) emit_opcode(opcode::OP_DecTop); + if (is_stmt) + emit_opcode(opcode::OP_DecTop); } void compiler::emit_expr_parameters(const ast::expr_parameters::ptr&)