diff --git a/src/h1/xsk/assembler.cpp b/src/h1/xsk/assembler.cpp index 106c22d1..83d50e41 100644 --- a/src/h1/xsk/assembler.cpp +++ b/src/h1/xsk/assembler.cpp @@ -384,19 +384,19 @@ void assembler::assemble_builtin_call(const gsc::instruction_ptr& inst, bool met if (arg_num) { - script_->write(static_cast(std::stol(inst->data[0]))); + script_->write(static_cast(std::stoi(inst->data[0]))); if (method) - id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::method_id(inst->data[1]); + id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::method_id(inst->data[1]); else - id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::function_id(inst->data[1]); + id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::function_id(inst->data[1]); } else { if (method) - id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::method_id(inst->data[0]); + id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::method_id(inst->data[0]); else - id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::function_id(inst->data[0]); + id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::function_id(inst->data[0]); } script_->write(id); @@ -414,7 +414,7 @@ void assembler::assemble_local_call(const gsc::instruction_ptr& inst, bool threa if (thread) { - script_->write(static_cast(std::stol(inst->data[1]))); + script_->write(static_cast(std::stoi(inst->data[1]))); } } @@ -429,15 +429,15 @@ void assembler::assemble_far_call(const gsc::instruction_ptr& inst, bool thread) if (thread) { - script_->write(static_cast(std::stol(inst->data[0]))); + script_->write(static_cast(std::stoi(inst->data[0]))); - file_id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::file_id(inst->data[1]); - func_id = inst->data[2].substr(0, 3) == "_ID" ? std::stol(inst->data[2].substr(3)) : resolver::token_id(inst->data[2]); + file_id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::file_id(inst->data[1]); + func_id = inst->data[2].substr(0, 3) == "_ID" ? std::stoi(inst->data[2].substr(3)) : resolver::token_id(inst->data[2]); } else { - file_id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::file_id(inst->data[0]); - func_id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::token_id(inst->data[1]); + file_id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::file_id(inst->data[0]); + func_id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::token_id(inst->data[1]); } stack_->write(file_id); @@ -463,7 +463,7 @@ void assembler::assemble_end_switch(const gsc::instruction_ptr& inst) if (utils::string::is_number(inst->data[0])) { - casenum = std::stol(inst->data[0]); + casenum = std::stoi(inst->data[0]); } else { @@ -480,7 +480,7 @@ void assembler::assemble_end_switch(const gsc::instruction_ptr& inst) { if (utils::string::is_number(inst->data[1 + (3 * i) + 1])) { - script_->write((std::stol(inst->data[1 + (3 * i) + 1]) & 0xFFFFFF) + 0x800000); + script_->write((std::stoi(inst->data[1 + (3 * i) + 1]) & 0xFFFFFF) + 0x800000); } else { @@ -519,7 +519,7 @@ void assembler::assemble_field_variable(const gsc::instruction_ptr& inst) if (inst->data[0].substr(0, 3) == "_ID") { - field_id = (std::uint16_t)std::stol(inst->data[0].substr(3)); + field_id = (std::uint16_t)std::stoi(inst->data[0].substr(3)); } else { diff --git a/src/h1/xsk/compiler.cpp b/src/h1/xsk/compiler.cpp index 7246c4a0..9ebe436b 100644 --- a/src/h1/xsk/compiler.cpp +++ b/src/h1/xsk/compiler.cpp @@ -1140,6 +1140,10 @@ void compiler::emit_expr_function(const gsc::context_ptr& ctx, const gsc::expr_f { far = true; } + else if(is_include_call(name, file)) + { + far = true; + } else if(is_builtin_method(name)) { builtin = true; @@ -1153,6 +1157,10 @@ void compiler::emit_expr_function(const gsc::context_ptr& ctx, const gsc::expr_f { local = true; } + else + { + throw gsc::comp_error(expr->loc, "couldn't determine function reference type"); + } if(local) { @@ -1634,7 +1642,7 @@ void compiler::emit_integer(const gsc::context_ptr& ctx, const gsc::integer_ptr& { emit_opcode(ctx, opcode::OP_GetNegByte, num->value.substr(1)); } - else if(value < 65536) + else if(value > 0 && value < 65536) { emit_opcode(ctx, opcode::OP_GetUnsignedShort, num->value); } @@ -2203,6 +2211,23 @@ auto compiler::variable_initialized(const gsc::context_ptr& ctx, const gsc::name throw gsc::comp_error(name->loc, "local variable '" + name->value + "' not found."); } +auto compiler::is_include_call(const std::string& name, std::string& file) -> bool +{ + for(const auto& inc : includes_) + { + for(const auto& fun : inc.funcs) + { + if(name == fun) + { + file = inc.name; + return true; + } + } + } + + return false; +} + auto compiler::is_local_call(const std::string& name) -> bool { for(const auto& f : local_functions_) diff --git a/src/h1/xsk/compiler.hpp b/src/h1/xsk/compiler.hpp index cdf6c4c1..283e2a9d 100644 --- a/src/h1/xsk/compiler.hpp +++ b/src/h1/xsk/compiler.hpp @@ -131,6 +131,7 @@ private: auto variable_create_index(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> std::string; auto variable_access_index(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> std::string; auto variable_initialized(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> bool; + auto is_include_call(const std::string& name, std::string& file) -> bool; auto is_local_call(const std::string& name) -> bool; auto is_builtin_call(const std::string& name) -> bool; auto is_builtin_func(const std::string& name) -> bool; diff --git a/src/h2/xsk/assembler.cpp b/src/h2/xsk/assembler.cpp index e328d9cd..36dfce75 100644 --- a/src/h2/xsk/assembler.cpp +++ b/src/h2/xsk/assembler.cpp @@ -384,19 +384,19 @@ void assembler::assemble_builtin_call(const gsc::instruction_ptr& inst, bool met if (arg_num) { - script_->write(static_cast(std::stol(inst->data[0]))); + script_->write(static_cast(std::stoi(inst->data[0]))); if (method) - id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::method_id(inst->data[1]); + id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::method_id(inst->data[1]); else - id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::function_id(inst->data[1]); + id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::function_id(inst->data[1]); } else { if (method) - id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::method_id(inst->data[0]); + id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::method_id(inst->data[0]); else - id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::function_id(inst->data[0]); + id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::function_id(inst->data[0]); } script_->write(id); @@ -414,7 +414,7 @@ void assembler::assemble_local_call(const gsc::instruction_ptr& inst, bool threa if (thread) { - script_->write(static_cast(std::stol(inst->data[1]))); + script_->write(static_cast(std::stoi(inst->data[1]))); } } @@ -429,15 +429,15 @@ void assembler::assemble_far_call(const gsc::instruction_ptr& inst, bool thread) if (thread) { - script_->write(static_cast(std::stol(inst->data[0]))); + script_->write(static_cast(std::stoi(inst->data[0]))); - file_id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::file_id(inst->data[1]); - func_id = inst->data[2].substr(0, 3) == "_ID" ? std::stol(inst->data[2].substr(3)) : resolver::token_id(inst->data[2]); + file_id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::file_id(inst->data[1]); + func_id = inst->data[2].substr(0, 3) == "_ID" ? std::stoi(inst->data[2].substr(3)) : resolver::token_id(inst->data[2]); } else { - file_id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::file_id(inst->data[0]); - func_id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::token_id(inst->data[1]); + file_id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::file_id(inst->data[0]); + func_id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::token_id(inst->data[1]); } stack_->write(file_id); @@ -463,7 +463,7 @@ void assembler::assemble_end_switch(const gsc::instruction_ptr& inst) if (utils::string::is_number(inst->data[0])) { - casenum = std::stol(inst->data[0]); + casenum = std::stoi(inst->data[0]); } else { @@ -480,7 +480,7 @@ void assembler::assemble_end_switch(const gsc::instruction_ptr& inst) { if (utils::string::is_number(inst->data[1 + (3 * i) + 1])) { - script_->write((std::stol(inst->data[1 + (3 * i) + 1]) & 0xFFFFFF) + 0x800000); + script_->write((std::stoi(inst->data[1 + (3 * i) + 1]) & 0xFFFFFF) + 0x800000); } else { @@ -519,7 +519,7 @@ void assembler::assemble_field_variable(const gsc::instruction_ptr& inst) if (inst->data[0].substr(0, 3) == "_ID") { - field_id = (std::uint16_t)std::stol(inst->data[0].substr(3)); + field_id = (std::uint16_t)std::stoi(inst->data[0].substr(3)); } else { diff --git a/src/h2/xsk/compiler.cpp b/src/h2/xsk/compiler.cpp index 61fe9f67..8874be42 100644 --- a/src/h2/xsk/compiler.cpp +++ b/src/h2/xsk/compiler.cpp @@ -1140,6 +1140,10 @@ void compiler::emit_expr_function(const gsc::context_ptr& ctx, const gsc::expr_f { far = true; } + else if(is_include_call(name, file)) + { + far = true; + } else if(is_builtin_method(name)) { builtin = true; @@ -1153,6 +1157,10 @@ void compiler::emit_expr_function(const gsc::context_ptr& ctx, const gsc::expr_f { local = true; } + else + { + throw gsc::comp_error(expr->loc, "couldn't determine function reference type"); + } if(local) { @@ -1634,7 +1642,7 @@ void compiler::emit_integer(const gsc::context_ptr& ctx, const gsc::integer_ptr& { emit_opcode(ctx, opcode::OP_GetNegByte, num->value.substr(1)); } - else if(value < 65536) + else if(value > 0 && value < 65536) { emit_opcode(ctx, opcode::OP_GetUnsignedShort, num->value); } @@ -2203,6 +2211,23 @@ auto compiler::variable_initialized(const gsc::context_ptr& ctx, const gsc::name throw gsc::comp_error(name->loc, "local variable '" + name->value + "' not found."); } +auto compiler::is_include_call(const std::string& name, std::string& file) -> bool +{ + for(const auto& inc : includes_) + { + for(const auto& fun : inc.funcs) + { + if(name == fun) + { + file = inc.name; + return true; + } + } + } + + return false; +} + auto compiler::is_local_call(const std::string& name) -> bool { for(const auto& f : local_functions_) diff --git a/src/h2/xsk/compiler.hpp b/src/h2/xsk/compiler.hpp index 19deb47a..f517d986 100644 --- a/src/h2/xsk/compiler.hpp +++ b/src/h2/xsk/compiler.hpp @@ -131,6 +131,7 @@ private: auto variable_create_index(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> std::string; auto variable_access_index(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> std::string; auto variable_initialized(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> bool; + auto is_include_call(const std::string& name, std::string& file) -> bool; auto is_local_call(const std::string& name) -> bool; auto is_builtin_call(const std::string& name) -> bool; auto is_builtin_func(const std::string& name) -> bool; diff --git a/src/iw5/xsk/assembler.cpp b/src/iw5/xsk/assembler.cpp index b29cf76c..2067b4ae 100644 --- a/src/iw5/xsk/assembler.cpp +++ b/src/iw5/xsk/assembler.cpp @@ -261,7 +261,7 @@ void assembler::assemble_instruction(const gsc::instruction_ptr& inst) break; case opcode::OP_waittillmatch: script_->write(static_cast(inst->opcode)); - script_->write(static_cast(std::stol(inst->data[0]))); + script_->write(static_cast(std::stoi(inst->data[0]))); break; case opcode::OP_CreateLocalVariable: case opcode::OP_RemoveLocalVariables: @@ -278,7 +278,7 @@ void assembler::assemble_instruction(const gsc::instruction_ptr& inst) case opcode::OP_ClearLocalVariableFieldCached: case opcode::OP_EvalLocalVariableObjectCached: script_->write(static_cast(inst->opcode)); - script_->write(static_cast(std::stol(inst->data[0]))); + script_->write(static_cast(std::stoi(inst->data[0]))); break; case opcode::OP_EvalLevelFieldVariable: case opcode::OP_EvalAnimFieldVariable: @@ -301,7 +301,7 @@ void assembler::assemble_instruction(const gsc::instruction_ptr& inst) case opcode::OP_CallBuiltinPointer: case opcode::OP_CallBuiltinMethodPointer: script_->write(static_cast(inst->opcode)); - script_->write(static_cast(std::stol(inst->data[0]))); + script_->write(static_cast(std::stoi(inst->data[0]))); break; case opcode::OP_ScriptLocalFunctionCall2: case opcode::OP_ScriptLocalFunctionCall: @@ -382,19 +382,19 @@ void assembler::assemble_builtin_call(const gsc::instruction_ptr& inst, bool met if (arg_num) { - script_->write(static_cast(std::stol(inst->data[0]))); + script_->write(static_cast(std::stoi(inst->data[0]))); if (method) - id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::method_id(inst->data[1]); + id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::method_id(inst->data[1]); else - id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::function_id(inst->data[1]); + id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::function_id(inst->data[1]); } else { if (method) - id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::method_id(inst->data[0]); + id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::method_id(inst->data[0]); else - id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::function_id(inst->data[0]); + id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::function_id(inst->data[0]); } script_->write(id); @@ -412,7 +412,7 @@ void assembler::assemble_local_call(const gsc::instruction_ptr& inst, bool threa if (thread) { - script_->write(static_cast(std::stol(inst->data[1]))); + script_->write(static_cast(std::stoi(inst->data[1]))); } } @@ -427,15 +427,15 @@ void assembler::assemble_far_call(const gsc::instruction_ptr& inst, bool thread) if (thread) { - script_->write(static_cast(std::stol(inst->data[0]))); + script_->write(static_cast(std::stoi(inst->data[0]))); - file_id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::file_id(inst->data[1]); - func_id = inst->data[2].substr(0, 3) == "_ID" ? std::stol(inst->data[2].substr(3)) : resolver::token_id(inst->data[2]); + file_id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::file_id(inst->data[1]); + func_id = inst->data[2].substr(0, 3) == "_ID" ? std::stoi(inst->data[2].substr(3)) : resolver::token_id(inst->data[2]); } else { - file_id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::file_id(inst->data[0]); - func_id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::token_id(inst->data[1]); + file_id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::file_id(inst->data[0]); + func_id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::token_id(inst->data[1]); } stack_->write(file_id); @@ -462,7 +462,7 @@ void assembler::assemble_end_switch(const gsc::instruction_ptr& inst) throw asm_error("invalid endswitch number!"); } - std::uint16_t casenum = std::stol(inst->data[0]); + std::uint16_t casenum = std::stoi(inst->data[0]); script_->write(casenum); @@ -474,7 +474,7 @@ void assembler::assemble_end_switch(const gsc::instruction_ptr& inst) { if (utils::string::is_number(inst->data[1 + (3 * i) + 1])) { - script_->write((std::stol(inst->data[1 + (3 * i) + 1]) & 0xFFFFFF) + 0x800000); + script_->write((std::stoi(inst->data[1 + (3 * i) + 1]) & 0xFFFFFF) + 0x800000); } else { @@ -513,7 +513,7 @@ void assembler::assemble_field_variable(const gsc::instruction_ptr& inst) if (inst->data[0].substr(0, 3) == "_ID") { - field_id = (std::uint16_t)std::stol(inst->data[0].substr(3)); + field_id = (std::uint16_t)std::stoi(inst->data[0].substr(3)); } else { diff --git a/src/iw5/xsk/compiler.cpp b/src/iw5/xsk/compiler.cpp index 3f4448c4..6771216a 100644 --- a/src/iw5/xsk/compiler.cpp +++ b/src/iw5/xsk/compiler.cpp @@ -1134,6 +1134,10 @@ void compiler::emit_expr_function(const gsc::context_ptr& ctx, const gsc::expr_f { far = true; } + else if(is_include_call(name, file)) + { + far = true; + } else if(is_builtin_method(name)) { builtin = true; @@ -1147,6 +1151,10 @@ void compiler::emit_expr_function(const gsc::context_ptr& ctx, const gsc::expr_f { local = true; } + else + { + throw gsc::comp_error(expr->loc, "couldn't determine function reference type"); + } if(local) { @@ -1628,7 +1636,7 @@ void compiler::emit_integer(const gsc::context_ptr& ctx, const gsc::integer_ptr& { emit_opcode(ctx, opcode::OP_GetNegByte, num->value.substr(1)); } - else if(value < 65536) + else if(value > 0 && value < 65536) { emit_opcode(ctx, opcode::OP_GetUnsignedShort, num->value); } @@ -2197,6 +2205,23 @@ auto compiler::variable_initialized(const gsc::context_ptr& ctx, const gsc::name throw gsc::comp_error(name->loc, "local variable '" + name->value + "' not found."); } +auto compiler::is_include_call(const std::string& name, std::string& file) -> bool +{ + for(const auto& inc : includes_) + { + for(const auto& fun : inc.funcs) + { + if(name == fun) + { + file = inc.name; + return true; + } + } + } + + return false; +} + auto compiler::is_local_call(const std::string& name) -> bool { for(const auto& f : local_functions_) @@ -2812,6 +2837,61 @@ gsc::include_t compiler::include_common_scripts_utility_ = } }; +gsc::include_t compiler::include_maps_mp_gametypes_hud_util_ = +{ + "maps/mp/gametypes/_hud_util", + { + "setparent", + "getparent", + "addchild", + "removechild", + "setpoint", + "setpointbar", + "updatebar", + "updatebarscale", + "createfontstring", + "createserverfontstring", + "createservertimer", + "createtimer", + "createicon", + "createservericon", + "createserverbar", + "createbar", + "getcurrentfraction", + "createprimaryprogressbar", + "createprimaryprogressbartext", + "createteamprogressbar", + "createteamprogressbartext", + "setflashfrac", + "hideelem", + "showelem", + "flashthread", + "destroyelem", + "seticonshader", + "geticonshader", + "seticonsize", + "setwidth", + "setheight", + "setsize", + "updatechildren", + "transitionreset", + "transitionzoomin", + "transitionpulsefxin", + "transitionslidein", + "transitionslideout", + "transitionzoomout", + "transitionfadein", + "transitionfadeout", + "getweeklyref", + "getdailyref", + "ch_getprogress", + "ch_getstate", + "ch_setprogress", + "ch_setstate", + "ch_gettarget", + } +}; + auto compiler::map_known_includes(const std::string& include) -> bool { if(include == "maps/mp/_utility") @@ -2829,6 +2909,11 @@ auto compiler::map_known_includes(const std::string& include) -> bool includes_.push_back(include_common_scripts_createfx_); return true; } + else if(include == "maps/mp/gametypes/_hud_util") + { + includes_.push_back(include_maps_mp_gametypes_hud_util_); + return true; + } return false; } diff --git a/src/iw5/xsk/compiler.hpp b/src/iw5/xsk/compiler.hpp index 179961a3..e2b96739 100644 --- a/src/iw5/xsk/compiler.hpp +++ b/src/iw5/xsk/compiler.hpp @@ -130,6 +130,7 @@ private: auto variable_create_index(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> std::string; auto variable_access_index(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> std::string; auto variable_initialized(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> bool; + auto is_include_call(const std::string& name, std::string& file) -> bool; auto is_local_call(const std::string& name) -> bool; auto is_builtin_call(const std::string& name) -> bool; auto is_builtin_func(const std::string& name) -> bool; @@ -142,6 +143,7 @@ private: static gsc::include_t include_maps_mp_utility_; static gsc::include_t include_common_scripts_utility_; static gsc::include_t include_common_scripts_createfx_; + static gsc::include_t include_maps_mp_gametypes_hud_util_; auto map_known_includes(const std::string& include) -> bool; // debug diff --git a/src/iw6/xsk/assembler.cpp b/src/iw6/xsk/assembler.cpp index c30fb59e..602d59c5 100644 --- a/src/iw6/xsk/assembler.cpp +++ b/src/iw6/xsk/assembler.cpp @@ -383,19 +383,19 @@ void assembler::assemble_builtin_call(const gsc::instruction_ptr& inst, bool met if (arg_num) { - script_->write(static_cast(std::stol(inst->data[0]))); + script_->write(static_cast(std::stoi(inst->data[0]))); if (method) - id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::method_id(inst->data[1]); + id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::method_id(inst->data[1]); else - id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::function_id(inst->data[1]); + id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::function_id(inst->data[1]); } else { if (method) - id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::method_id(inst->data[0]); + id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::method_id(inst->data[0]); else - id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::function_id(inst->data[0]); + id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::function_id(inst->data[0]); } script_->write(id); @@ -413,7 +413,7 @@ void assembler::assemble_local_call(const gsc::instruction_ptr& inst, bool threa if (thread) { - script_->write(static_cast(std::stol(inst->data[1]))); + script_->write(static_cast(std::stoi(inst->data[1]))); } } @@ -428,15 +428,15 @@ void assembler::assemble_far_call(const gsc::instruction_ptr& inst, bool thread) if (thread) { - script_->write(static_cast(std::stol(inst->data[0]))); + script_->write(static_cast(std::stoi(inst->data[0]))); - file_id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::file_id(inst->data[1]); - func_id = inst->data[2].substr(0, 3) == "_ID" ? std::stol(inst->data[2].substr(3)) : resolver::token_id(inst->data[2]); + file_id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::file_id(inst->data[1]); + func_id = inst->data[2].substr(0, 3) == "_ID" ? std::stoi(inst->data[2].substr(3)) : resolver::token_id(inst->data[2]); } else { - file_id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::file_id(inst->data[0]); - func_id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::token_id(inst->data[1]); + file_id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::file_id(inst->data[0]); + func_id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::token_id(inst->data[1]); } stack_->write(file_id); @@ -462,7 +462,7 @@ void assembler::assemble_end_switch(const gsc::instruction_ptr& inst) if (utils::string::is_number(inst->data[0])) { - casenum = std::stol(inst->data[0]); + casenum = std::stoi(inst->data[0]); } else { @@ -479,7 +479,7 @@ void assembler::assemble_end_switch(const gsc::instruction_ptr& inst) { if (utils::string::is_number(inst->data[1 + (3 * i) + 1])) { - script_->write((std::stol(inst->data[1 + (3 * i) + 1]) & 0xFFFFFF) + 0x800000); + script_->write((std::stoi(inst->data[1 + (3 * i) + 1]) & 0xFFFFFF) + 0x800000); } else { @@ -518,7 +518,7 @@ void assembler::assemble_field_variable(const gsc::instruction_ptr& inst) if (inst->data[0].substr(0, 3) == "_ID") { - field_id = (std::uint16_t)std::stol(inst->data[0].substr(3)); + field_id = (std::uint16_t)std::stoi(inst->data[0].substr(3)); } else { diff --git a/src/iw6/xsk/compiler.cpp b/src/iw6/xsk/compiler.cpp index abd159ed..7a130ba6 100644 --- a/src/iw6/xsk/compiler.cpp +++ b/src/iw6/xsk/compiler.cpp @@ -1134,6 +1134,10 @@ void compiler::emit_expr_function(const gsc::context_ptr& ctx, const gsc::expr_f { far = true; } + else if(is_include_call(name, file)) + { + far = true; + } else if(is_builtin_method(name)) { builtin = true; @@ -1147,6 +1151,10 @@ void compiler::emit_expr_function(const gsc::context_ptr& ctx, const gsc::expr_f { local = true; } + else + { + throw gsc::comp_error(expr->loc, "couldn't determine function reference type"); + } if(local) { @@ -1628,7 +1636,7 @@ void compiler::emit_integer(const gsc::context_ptr& ctx, const gsc::integer_ptr& { emit_opcode(ctx, opcode::OP_GetNegByte, num->value.substr(1)); } - else if(value < 65536) + else if(value > 0 && value < 65536) { emit_opcode(ctx, opcode::OP_GetUnsignedShort, num->value); } @@ -2197,6 +2205,23 @@ auto compiler::variable_initialized(const gsc::context_ptr& ctx, const gsc::name throw gsc::comp_error(name->loc, "local variable '" + name->value + "' not found."); } +auto compiler::is_include_call(const std::string& name, std::string& file) -> bool +{ + for(const auto& inc : includes_) + { + for(const auto& fun : inc.funcs) + { + if(name == fun) + { + file = inc.name; + return true; + } + } + } + + return false; +} + auto compiler::is_local_call(const std::string& name) -> bool { for(const auto& f : local_functions_) diff --git a/src/iw6/xsk/compiler.hpp b/src/iw6/xsk/compiler.hpp index f3068538..ae6ec24a 100644 --- a/src/iw6/xsk/compiler.hpp +++ b/src/iw6/xsk/compiler.hpp @@ -130,6 +130,7 @@ private: auto variable_create_index(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> std::string; auto variable_access_index(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> std::string; auto variable_initialized(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> bool; + auto is_include_call(const std::string& name, std::string& file) -> bool; auto is_local_call(const std::string& name) -> bool; auto is_builtin_call(const std::string& name) -> bool; auto is_builtin_func(const std::string& name) -> bool; diff --git a/src/iw7/xsk/assembler.cpp b/src/iw7/xsk/assembler.cpp index aeb29d2b..d310c914 100644 --- a/src/iw7/xsk/assembler.cpp +++ b/src/iw7/xsk/assembler.cpp @@ -388,19 +388,19 @@ void assembler::assemble_builtin_call(const gsc::instruction_ptr& inst, bool met if (arg_num) { - script_->write(static_cast(std::stol(inst->data[0]))); + script_->write(static_cast(std::stoi(inst->data[0]))); if (method) - id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::method_id(inst->data[1]); + id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::method_id(inst->data[1]); else - id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::function_id(inst->data[1]); + id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::function_id(inst->data[1]); } else { if (method) - id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::method_id(inst->data[0]); + id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::method_id(inst->data[0]); else - id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::function_id(inst->data[0]); + id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::function_id(inst->data[0]); } script_->write(id); @@ -418,7 +418,7 @@ void assembler::assemble_local_call(const gsc::instruction_ptr& inst, bool threa if (thread) { - script_->write(static_cast(std::stol(inst->data[1]))); + script_->write(static_cast(std::stoi(inst->data[1]))); } } @@ -433,15 +433,15 @@ void assembler::assemble_far_call(const gsc::instruction_ptr& inst, bool thread) if (thread) { - script_->write(static_cast(std::stol(inst->data[0]))); + script_->write(static_cast(std::stoi(inst->data[0]))); - file_id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::file_id(inst->data[1]); - func_id = inst->data[2].substr(0, 3) == "_ID" ? std::stol(inst->data[2].substr(3)) : resolver::token_id(inst->data[2]); + file_id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::file_id(inst->data[1]); + func_id = inst->data[2].substr(0, 3) == "_ID" ? std::stoi(inst->data[2].substr(3)) : resolver::token_id(inst->data[2]); } else { - file_id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::file_id(inst->data[0]); - func_id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::token_id(inst->data[1]); + file_id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::file_id(inst->data[0]); + func_id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::token_id(inst->data[1]); } stack_->write(file_id); @@ -467,7 +467,7 @@ void assembler::assemble_end_switch(const gsc::instruction_ptr& inst) if (utils::string::is_number(inst->data[0])) { - casenum = std::stol(inst->data[0]); + casenum = std::stoi(inst->data[0]); } else { @@ -484,7 +484,7 @@ void assembler::assemble_end_switch(const gsc::instruction_ptr& inst) { if (utils::string::is_number(inst->data[1 + (3 * i) + 1])) { - script_->write((std::stol(inst->data[1 + (3 * i) + 1]) & 0xFFFFFF) + 0x800000); + script_->write((std::stoi(inst->data[1 + (3 * i) + 1]) & 0xFFFFFF) + 0x800000); } else { @@ -523,7 +523,7 @@ void assembler::assemble_field_variable(const gsc::instruction_ptr& inst) if (inst->data[0].substr(0, 3) == "_ID") { - field_id = std::stoul(inst->data[0].substr(3)); + field_id = std::stoi(inst->data[0].substr(3)); } else { diff --git a/src/iw7/xsk/compiler.cpp b/src/iw7/xsk/compiler.cpp index ea2213c0..869b0505 100644 --- a/src/iw7/xsk/compiler.cpp +++ b/src/iw7/xsk/compiler.cpp @@ -1134,6 +1134,10 @@ void compiler::emit_expr_function(const gsc::context_ptr& ctx, const gsc::expr_f { far = true; } + else if(is_include_call(name, file)) + { + far = true; + } else if(is_builtin_method(name)) { builtin = true; @@ -1147,6 +1151,10 @@ void compiler::emit_expr_function(const gsc::context_ptr& ctx, const gsc::expr_f { local = true; } + else + { + throw gsc::comp_error(expr->loc, "couldn't determine function reference type"); + } if(local) { @@ -1628,7 +1636,7 @@ void compiler::emit_integer(const gsc::context_ptr& ctx, const gsc::integer_ptr& { emit_opcode(ctx, opcode::OP_GetNegByte, num->value.substr(1)); } - else if(value < 65536) + else if(value > 0 && value < 65536) { emit_opcode(ctx, opcode::OP_GetUnsignedShort, num->value); } @@ -2197,6 +2205,23 @@ auto compiler::variable_initialized(const gsc::context_ptr& ctx, const gsc::name throw gsc::comp_error(name->loc, "local variable '" + name->value + "' not found."); } +auto compiler::is_include_call(const std::string& name, std::string& file) -> bool +{ + for(const auto& inc : includes_) + { + for(const auto& fun : inc.funcs) + { + if(name == fun) + { + file = inc.name; + return true; + } + } + } + + return false; +} + auto compiler::is_local_call(const std::string& name) -> bool { for(const auto& f : local_functions_) diff --git a/src/iw7/xsk/compiler.hpp b/src/iw7/xsk/compiler.hpp index 3285f3e1..69738927 100644 --- a/src/iw7/xsk/compiler.hpp +++ b/src/iw7/xsk/compiler.hpp @@ -130,6 +130,7 @@ private: auto variable_create_index(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> std::string; auto variable_access_index(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> std::string; auto variable_initialized(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> bool; + auto is_include_call(const std::string& name, std::string& file) -> bool; auto is_local_call(const std::string& name) -> bool; auto is_builtin_call(const std::string& name) -> bool; auto is_builtin_func(const std::string& name) -> bool; diff --git a/src/s1/xsk/assembler.cpp b/src/s1/xsk/assembler.cpp index 8fc6a21c..4ebbce83 100644 --- a/src/s1/xsk/assembler.cpp +++ b/src/s1/xsk/assembler.cpp @@ -384,19 +384,19 @@ void assembler::assemble_builtin_call(const gsc::instruction_ptr& inst, bool met if (arg_num) { - script_->write(static_cast(std::stol(inst->data[0]))); + script_->write(static_cast(std::stoi(inst->data[0]))); if (method) - id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::method_id(inst->data[1]); + id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::method_id(inst->data[1]); else - id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::function_id(inst->data[1]); + id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::function_id(inst->data[1]); } else { if (method) - id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::method_id(inst->data[0]); + id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::method_id(inst->data[0]); else - id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::function_id(inst->data[0]); + id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::function_id(inst->data[0]); } script_->write(id); @@ -414,7 +414,7 @@ void assembler::assemble_local_call(const gsc::instruction_ptr& inst, bool threa if (thread) { - script_->write(static_cast(std::stol(inst->data[1]))); + script_->write(static_cast(std::stoi(inst->data[1]))); } } @@ -429,15 +429,15 @@ void assembler::assemble_far_call(const gsc::instruction_ptr& inst, bool thread) if (thread) { - script_->write(static_cast(std::stol(inst->data[0]))); + script_->write(static_cast(std::stoi(inst->data[0]))); - file_id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::file_id(inst->data[1]); - func_id = inst->data[2].substr(0, 3) == "_ID" ? std::stol(inst->data[2].substr(3)) : resolver::token_id(inst->data[2]); + file_id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::file_id(inst->data[1]); + func_id = inst->data[2].substr(0, 3) == "_ID" ? std::stoi(inst->data[2].substr(3)) : resolver::token_id(inst->data[2]); } else { - file_id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::file_id(inst->data[0]); - func_id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::token_id(inst->data[1]); + file_id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::file_id(inst->data[0]); + func_id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::token_id(inst->data[1]); } stack_->write(file_id); @@ -463,7 +463,7 @@ void assembler::assemble_end_switch(const gsc::instruction_ptr& inst) if (utils::string::is_number(inst->data[0])) { - casenum = std::stol(inst->data[0]); + casenum = std::stoi(inst->data[0]); } else { @@ -480,7 +480,7 @@ void assembler::assemble_end_switch(const gsc::instruction_ptr& inst) { if (utils::string::is_number(inst->data[1 + (3 * i) + 1])) { - script_->write((std::stol(inst->data[1 + (3 * i) + 1]) & 0xFFFFFF) + 0x800000); + script_->write((std::stoi(inst->data[1 + (3 * i) + 1]) & 0xFFFFFF) + 0x800000); } else { @@ -519,7 +519,7 @@ void assembler::assemble_field_variable(const gsc::instruction_ptr& inst) if (inst->data[0].substr(0, 3) == "_ID") { - field_id = (std::uint16_t)std::stol(inst->data[0].substr(3)); + field_id = (std::uint16_t)std::stoi(inst->data[0].substr(3)); } else { diff --git a/src/s1/xsk/compiler.cpp b/src/s1/xsk/compiler.cpp index 11716032..962e2208 100644 --- a/src/s1/xsk/compiler.cpp +++ b/src/s1/xsk/compiler.cpp @@ -1140,6 +1140,10 @@ void compiler::emit_expr_function(const gsc::context_ptr& ctx, const gsc::expr_f { far = true; } + else if(is_include_call(name, file)) + { + far = true; + } else if(is_builtin_method(name)) { builtin = true; @@ -1153,6 +1157,10 @@ void compiler::emit_expr_function(const gsc::context_ptr& ctx, const gsc::expr_f { local = true; } + else + { + throw gsc::comp_error(expr->loc, "couldn't determine function reference type"); + } if(local) { @@ -1634,7 +1642,7 @@ void compiler::emit_integer(const gsc::context_ptr& ctx, const gsc::integer_ptr& { emit_opcode(ctx, opcode::OP_GetNegByte, num->value.substr(1)); } - else if(value < 65536) + else if(value > 0 && value < 65536) { emit_opcode(ctx, opcode::OP_GetUnsignedShort, num->value); } @@ -2203,6 +2211,23 @@ auto compiler::variable_initialized(const gsc::context_ptr& ctx, const gsc::name throw gsc::comp_error(name->loc, "local variable '" + name->value + "' not found."); } +auto compiler::is_include_call(const std::string& name, std::string& file) -> bool +{ + for(const auto& inc : includes_) + { + for(const auto& fun : inc.funcs) + { + if(name == fun) + { + file = inc.name; + return true; + } + } + } + + return false; +} + auto compiler::is_local_call(const std::string& name) -> bool { for(const auto& f : local_functions_) diff --git a/src/s1/xsk/compiler.hpp b/src/s1/xsk/compiler.hpp index d173ca79..849df41a 100644 --- a/src/s1/xsk/compiler.hpp +++ b/src/s1/xsk/compiler.hpp @@ -131,6 +131,7 @@ private: auto variable_create_index(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> std::string; auto variable_access_index(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> std::string; auto variable_initialized(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> bool; + auto is_include_call(const std::string& name, std::string& file) -> bool; auto is_local_call(const std::string& name) -> bool; auto is_builtin_call(const std::string& name) -> bool; auto is_builtin_func(const std::string& name) -> bool; diff --git a/src/s2/xsk/assembler.cpp b/src/s2/xsk/assembler.cpp index f42f495d..29d775df 100644 --- a/src/s2/xsk/assembler.cpp +++ b/src/s2/xsk/assembler.cpp @@ -385,19 +385,19 @@ void assembler::assemble_builtin_call(const gsc::instruction_ptr& inst, bool met if (arg_num) { - script_->write(static_cast(std::stol(inst->data[0]))); + script_->write(static_cast(std::stoi(inst->data[0]))); if (method) - id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::method_id(inst->data[1]); + id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::method_id(inst->data[1]); else - id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::function_id(inst->data[1]); + id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::function_id(inst->data[1]); } else { if (method) - id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::method_id(inst->data[0]); + id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::method_id(inst->data[0]); else - id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::function_id(inst->data[0]); + id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::function_id(inst->data[0]); } script_->write(id); @@ -415,7 +415,7 @@ void assembler::assemble_local_call(const gsc::instruction_ptr& inst, bool threa if (thread) { - script_->write(static_cast(std::stol(inst->data[1]))); + script_->write(static_cast(std::stoi(inst->data[1]))); } } @@ -430,15 +430,15 @@ void assembler::assemble_far_call(const gsc::instruction_ptr& inst, bool thread) if (thread) { - script_->write(static_cast(std::stol(inst->data[0]))); + script_->write(static_cast(std::stoi(inst->data[0]))); - file_id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::file_id(inst->data[1]); - func_id = inst->data[2].substr(0, 3) == "_ID" ? std::stol(inst->data[2].substr(3)) : resolver::token_id(inst->data[2]); + file_id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::file_id(inst->data[1]); + func_id = inst->data[2].substr(0, 3) == "_ID" ? std::stoi(inst->data[2].substr(3)) : resolver::token_id(inst->data[2]); } else { - file_id = inst->data[0].substr(0, 3) == "_ID" ? std::stol(inst->data[0].substr(3)) : resolver::file_id(inst->data[0]); - func_id = inst->data[1].substr(0, 3) == "_ID" ? std::stol(inst->data[1].substr(3)) : resolver::token_id(inst->data[1]); + file_id = inst->data[0].substr(0, 3) == "_ID" ? std::stoi(inst->data[0].substr(3)) : resolver::file_id(inst->data[0]); + func_id = inst->data[1].substr(0, 3) == "_ID" ? std::stoi(inst->data[1].substr(3)) : resolver::token_id(inst->data[1]); } stack_->write(file_id); @@ -464,7 +464,7 @@ void assembler::assemble_end_switch(const gsc::instruction_ptr& inst) if (utils::string::is_number(inst->data[0])) { - casenum = std::stol(inst->data[0]); + casenum = std::stoi(inst->data[0]); } else { @@ -481,7 +481,7 @@ void assembler::assemble_end_switch(const gsc::instruction_ptr& inst) { if (utils::string::is_number(inst->data[1 + (3 * i) + 1])) { - script_->write((std::stol(inst->data[1 + (3 * i) + 1]) & 0xFFFFFF) + 0x800000); + script_->write((std::stoi(inst->data[1 + (3 * i) + 1]) & 0xFFFFFF) + 0x800000); } else { @@ -520,7 +520,7 @@ void assembler::assemble_field_variable(const gsc::instruction_ptr& inst) if (inst->data[0].substr(0, 3) == "_ID") { - field_id = (std::uint16_t)std::stol(inst->data[0].substr(3)); + field_id = (std::uint16_t)std::stoi(inst->data[0].substr(3)); } else { diff --git a/src/s2/xsk/compiler.cpp b/src/s2/xsk/compiler.cpp index a39985d6..836463a3 100644 --- a/src/s2/xsk/compiler.cpp +++ b/src/s2/xsk/compiler.cpp @@ -1140,6 +1140,10 @@ void compiler::emit_expr_function(const gsc::context_ptr& ctx, const gsc::expr_f { far = true; } + else if(is_include_call(name, file)) + { + far = true; + } else if(is_builtin_method(name)) { builtin = true; @@ -1153,6 +1157,10 @@ void compiler::emit_expr_function(const gsc::context_ptr& ctx, const gsc::expr_f { local = true; } + else + { + throw gsc::comp_error(expr->loc, "couldn't determine function reference type"); + } if(local) { @@ -1634,7 +1642,7 @@ void compiler::emit_integer(const gsc::context_ptr& ctx, const gsc::integer_ptr& { emit_opcode(ctx, opcode::OP_GetNegByte, num->value.substr(1)); } - else if(value < 65536) + else if(value > 0 && value < 65536) { emit_opcode(ctx, opcode::OP_GetUnsignedShort, num->value); } @@ -2203,6 +2211,23 @@ auto compiler::variable_initialized(const gsc::context_ptr& ctx, const gsc::name throw gsc::comp_error(name->loc, "local variable '" + name->value + "' not found."); } +auto compiler::is_include_call(const std::string& name, std::string& file) -> bool +{ + for(const auto& inc : includes_) + { + for(const auto& fun : inc.funcs) + { + if(name == fun) + { + file = inc.name; + return true; + } + } + } + + return false; +} + auto compiler::is_local_call(const std::string& name) -> bool { for(const auto& f : local_functions_) diff --git a/src/s2/xsk/compiler.hpp b/src/s2/xsk/compiler.hpp index 0c94c58c..af851f92 100644 --- a/src/s2/xsk/compiler.hpp +++ b/src/s2/xsk/compiler.hpp @@ -131,6 +131,7 @@ private: auto variable_create_index(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> std::string; auto variable_access_index(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> std::string; auto variable_initialized(const gsc::context_ptr& ctx, const gsc::name_ptr& name) -> bool; + auto is_include_call(const std::string& name, std::string& file) -> bool; auto is_local_call(const std::string& name) -> bool; auto is_builtin_call(const std::string& name) -> bool; auto is_builtin_func(const std::string& name) -> bool; diff --git a/src/utils/xsk/gsc/nodetree.hpp b/src/utils/xsk/gsc/nodetree.hpp index 5bad21ab..0f5dc85f 100644 --- a/src/utils/xsk/gsc/nodetree.hpp +++ b/src/utils/xsk/gsc/nodetree.hpp @@ -1954,7 +1954,7 @@ struct node_stmt_for : public node } else { - data += "for ( " + pre_expr.as_node->print() + " " + expr.as_node->print() + "; " + post_expr.as_node->print() + " )"; + data += "for ( " + pre_expr.as_node->print() + " " + expr.as_node->print() + "; " + post_expr.as_assign->expr->print() + " )"; data += "\n"; }