reduce memory usage and cleanup code

This commit is contained in:
xensik
2022-01-19 20:01:12 +01:00
parent 9dbdd37f15
commit 9c8a67ff46
167 changed files with 25818 additions and 18774 deletions

View File

@ -23,6 +23,7 @@
#include <filesystem>
#include <functional>
#include <stdexcept>
#include <set>
#include <map>
#include <stack>
#include <array>

View File

@ -92,10 +92,24 @@ void assembler::assemble(const std::string& file, std::vector<std::uint8_t>& dat
data.erase(data.begin());
inst->data = std::move(data);
if (opcode(inst->opcode) == opcode::OP_endswitch)
switch (opcode(inst->opcode))
{
switchnum = static_cast<std::uint16_t>(std::stoi(inst->data[0]));
inst->size += 7 * switchnum;
case opcode::OP_GetLocalFunction:
case opcode::OP_ScriptLocalFunctionCall:
case opcode::OP_ScriptLocalFunctionCall2:
case opcode::OP_ScriptLocalMethodCall:
case opcode::OP_ScriptLocalThreadCall:
case opcode::OP_ScriptLocalChildThreadCall:
case opcode::OP_ScriptLocalMethodThreadCall:
case opcode::OP_ScriptLocalMethodChildThreadCall:
inst->data[0] = inst->data[0].substr(4);
break;
case opcode::OP_endswitch:
switchnum = static_cast<std::uint16_t>(std::stoi(inst->data[0]));
inst->size += 7 * switchnum;
break;
default:
break;
}
index += inst->size;
@ -126,9 +140,9 @@ void assembler::assemble_function(const function::ptr& func)
{
labels_ = func->labels;
stack_->write<std::uint32_t>(func->size);
func->id = resolver::token_id(func->name);
func->id = func->name.substr(0, 3) == "_ID" ? std::stoi(func->name.substr(3)) : resolver::token_id(func->name);
stack_->write<std::uint32_t>(func->size);
stack_->write<std::uint16_t>(func->id);
if (func->id == 0)
@ -379,24 +393,12 @@ void assembler::assemble_builtin_call(const instruction::ptr& inst, bool method,
{
script_->write<std::uint8_t>(static_cast<std::uint8_t>(inst->opcode));
std::uint16_t id = 0;
if (args)
{
script_->write<std::uint8_t>(static_cast<std::uint8_t>(std::stoi(inst->data[0])));
script_->write<std::uint8_t>(static_cast<std::uint8_t>(std::stoi(inst->data[1])));
}
if (method)
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::stoi(inst->data[1].substr(3)) : resolver::function_id(inst->data[1]);
}
else
{
if (method)
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::stoi(inst->data[0].substr(3)) : resolver::function_id(inst->data[0]);
}
const auto id = method ? resolver::method_id(inst->data[0]) : resolver::function_id(inst->data[0]);
script_->write<std::uint16_t>(id);
}
@ -405,9 +407,8 @@ void assembler::assemble_local_call(const instruction::ptr& inst, bool thread)
{
script_->write<std::uint8_t>(static_cast<std::uint8_t>(inst->opcode));
std::int32_t addr = resolve_function(inst->data[0]);
std::int32_t offset = addr - inst->index - 1;
const auto addr = resolve_function(inst->data[0]);
const auto offset = static_cast<std::int32_t>(addr - inst->index - 1);
assemble_offset(offset);
@ -423,33 +424,25 @@ void assembler::assemble_far_call(const instruction::ptr& inst, bool thread)
script_->write<std::uint8_t>(0);
script_->write<std::uint16_t>(0);
std::uint16_t file_id = 0;
std::uint16_t func_id = 0;
if (thread)
{
script_->write<std::uint8_t>(static_cast<std::uint8_t>(std::stoi(inst->data[0])));
script_->write<std::uint8_t>(static_cast<std::uint8_t>(std::stoi(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::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]);
}
const auto file_id = resolver::file_id(inst->data[0]);
const auto func_id = resolver::token_id(inst->data[1]);
stack_->write<std::uint16_t>(file_id);
if (file_id == 0) stack_->write_c_string(thread ? inst->data[1] : inst->data[0]);
if (file_id == 0) stack_->write_c_string(inst->data[0]);
stack_->write<std::uint16_t>(func_id);
if (func_id == 0) stack_->write_c_string(thread ? inst->data[2] : inst->data[1]);
if (func_id == 0) stack_->write_c_string(inst->data[1]);
}
void assembler::assemble_switch(const instruction::ptr& inst)
{
script_->write<std::uint8_t>(static_cast<std::uint8_t>(inst->opcode));
std::int32_t addr = resolve_label(inst->data[0]);
const auto addr = resolve_label(inst->data[0]);
script_->write<std::int32_t>(addr - inst->index - 4);
}
@ -458,22 +451,13 @@ void assembler::assemble_end_switch(const instruction::ptr& inst)
{
script_->write<std::uint8_t>(static_cast<std::uint8_t>(inst->opcode));
std::uint16_t casenum = 0;
const auto count = std::stoul(inst->data[0]);
if (utils::string::is_number(inst->data[0]))
{
casenum = std::stoi(inst->data[0]);
}
else
{
throw asm_error("invalid endswitch number!");
}
script_->write<std::uint16_t>(count);
script_->write<std::uint16_t>(casenum);
std::uint32_t index = inst->index + 3;
std::uint32_t internal_index = inst->index + 3;
for (std::uint16_t i = 0; i < casenum; i++)
for (auto i = 0u; i < count; i++)
{
if (inst->data[1 + (3 * i)] == "case")
{
@ -487,25 +471,26 @@ void assembler::assemble_end_switch(const instruction::ptr& inst)
stack_->write_c_string(utils::string::unquote(inst->data[1 + (3 * i) + 1]));
}
internal_index += 4;
index += 4;
std::int32_t addr = resolve_label(inst->data[1 + (3 * i) + 2]);
const auto addr = resolve_label(inst->data[1 + (3 * i) + 2]);
assemble_offset(addr - internal_index);
assemble_offset(addr - index);
internal_index += 3;
index += 3;
}
else if (inst->data[1 + (3 * i)] == "default")
{
script_->write<uint32_t>(0);
stack_->write_c_string("\x01");
internal_index += 4;
std::int32_t addr = resolve_label(inst->data[1 + (3 * i) + 1]);
index += 4;
assemble_offset(addr - internal_index);
const auto addr = resolve_label(inst->data[1 + (3 * i) + 1]);
internal_index += 3;
assemble_offset(addr - index);
index += 3;
}
}
}
@ -514,25 +499,13 @@ void assembler::assemble_field_variable(const instruction::ptr& inst)
{
script_->write<std::uint8_t>(static_cast<std::uint8_t>(inst->opcode));
std::uint16_t field_id = 0;
auto id = resolver::token_id(inst->data[0]);
if (inst->data[0].substr(0, 3) == "_ID")
{
field_id = (std::uint16_t)std::stoi(inst->data[0].substr(3));
}
else
{
field_id = resolver::token_id(inst->data[0]);
if (id == 0) id = 0xFFFF;
if (field_id == 0)
{
field_id = 0xFFFF;
}
}
script_->write<std::uint16_t>(id);
script_->write<std::uint16_t>(field_id);
if (field_id > 0xA7DC)
if (id > max_string_id)
{
stack_->write<std::uint16_t>(0);
stack_->write_c_string(inst->data[0]);
@ -543,7 +516,7 @@ void assembler::assemble_jump(const instruction::ptr& inst, bool expr, bool back
{
script_->write<std::uint8_t>(static_cast<std::uint8_t>(inst->opcode));
std::int32_t addr = resolve_label(inst->data[0]);
const auto addr = resolve_label(inst->data[0]);
if (expr)
{
@ -572,24 +545,22 @@ void assembler::assemble_offset(std::int32_t offset)
script_->write<std::uint8_t>(bytes[2]);
}
auto assembler::resolve_function(const std::string& name) -> std::uint32_t
auto assembler::resolve_function(const std::string& name) -> std::int32_t
{
auto temp = name.substr(0, 4) == "sub_" ? name.substr(4) : name;
for (const auto& func : functions_)
{
if (func->name == temp)
if (func->name == name)
{
return func->index;
}
}
throw asm_error("Couldn't resolve local function address of '" + temp + "'!");
throw asm_error("Couldn't resolve local function address of '" + name + "'!");
}
auto assembler::resolve_label(const std::string& name) -> std::uint32_t
auto assembler::resolve_label(const std::string& name) -> std::int32_t
{
for (auto& func : labels_)
for (const auto& func : labels_)
{
if (func.second == name)
{

View File

@ -33,8 +33,8 @@ private:
void assemble_field_variable(const instruction::ptr& inst);
void assemble_jump(const instruction::ptr& inst, bool expr, bool back);
void assemble_offset(std::int32_t offset);
auto resolve_function(const std::string& name) -> std::uint32_t;
auto resolve_label(const std::string& name) -> std::uint32_t;
auto resolve_function(const std::string& name) -> std::int32_t;
auto resolve_label(const std::string& name) -> std::int32_t;
};
} // namespace xsk::gsc::s1

View File

@ -57,7 +57,7 @@ auto compiler::parse_buffer(const std::string& file, std::vector<std::uint8_t>&
YY_BUFFER_STATE yybuffer = s1__scan_buffer(reinterpret_cast<char*>(data.data()), data.size(), scanner);
parser parser(scanner, &ctx, result);
if (parser.parse() || result == nullptr)
{
throw comp_error(ctx.loc, "An unknown error ocurred while parsing gsc file.");
@ -102,7 +102,7 @@ void compiler::compile_program(const ast::program::ptr& program)
for (const auto& declaration : program->declarations)
{
emit_declaration(declaration);
emit_declaration(declaration);
}
}
@ -393,9 +393,9 @@ void compiler::emit_stmt_endon(const ast::stmt_endon::ptr& stmt, const block::pt
void compiler::emit_stmt_notify(const ast::stmt_notify::ptr& stmt, const block::ptr& blk)
{
emit_opcode(opcode::OP_voidCodepos);
std::reverse(stmt->args->list.begin(), stmt->args->list.end());
for (const auto& arg : stmt->args->list)
{
emit_expr(arg, blk);
@ -534,7 +534,7 @@ void compiler::emit_stmt_while(const ast::stmt_while::ptr& stmt, const block::pt
stmt->blk->loc_continue = continue_loc;
emit_create_local_vars(stmt->blk);
blk->local_vars_create_count = stmt->blk->local_vars_create_count;
for (auto i = 0u; i < blk->local_vars_create_count; i++)
@ -588,7 +588,7 @@ void compiler::emit_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const block
stmt->blk->loc_continue = continue_loc;
emit_create_local_vars(stmt->blk);
blk->local_vars_create_count = stmt->blk->local_vars_create_count;
for (auto i = 0u; i < blk->local_vars_create_count; i++)
@ -734,7 +734,7 @@ void compiler::emit_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block
emit_expr_variable(stmt->key_expr, blk);
emit_opcode(opcode::OP_CallBuiltin1, "isdefined");
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
can_break_ = true;
can_continue_ = true;
@ -755,9 +755,9 @@ void compiler::emit_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const block
stmt->ctx_post->init_from_child(continue_blks_);
emit_expr_variable(stmt->key_expr, stmt->ctx_post);
emit_expr_variable(stmt->array, stmt->ctx_post);
emit_opcode(opcode::OP_CallBuiltin2, "getnextarraykey");
emit_expr_variable_ref(stmt->key_expr, stmt->ctx_post, true);
emit_expr_variable(stmt->array, stmt->ctx_post);
emit_opcode(opcode::OP_CallBuiltin2, "getnextarraykey");
emit_expr_variable_ref(stmt->key_expr, stmt->ctx_post, true);
emit_opcode(opcode::OP_jumpback, begin_loc);
insert_label(break_loc);
@ -847,7 +847,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block::
{
throw comp_error(entry.loc(), "missing case statement");
}
}
}
if (has_default)
{
@ -897,7 +897,7 @@ void compiler::emit_stmt_continue(const ast::stmt_continue::ptr& stmt, const blo
{
if (!can_continue_ || blk->abort != abort_t::abort_none || blk->loc_continue == "")
throw comp_error(stmt->loc(), "illegal continue statement");
continue_blks_.push_back(blk.get());
emit_remove_local_vars(blk);
blk->abort = abort_t::abort_continue;
@ -1055,7 +1055,7 @@ void compiler::emit_expr(const ast::expr& expr, const block::ptr& blk)
}
}
void compiler::emit_expr_assign(const ast::expr_assign::ptr& expr, const block::ptr& blk)
void compiler::emit_expr_assign(const ast::expr_assign::ptr& expr, const block::ptr& blk)
{
if (expr->kind() == ast::kind::expr_assign_equal)
{
@ -1109,7 +1109,7 @@ void compiler::emit_expr_assign(const ast::expr_assign::ptr& expr, const block::
throw comp_error(expr->loc(), "unknown assign operation");
}
emit_expr_variable_ref(expr->lvalue, blk, true);
emit_expr_variable_ref(expr->lvalue, blk, true);
}
void compiler::emit_expr_clear(const ast::expr& expr, const block::ptr& blk)
@ -1372,10 +1372,10 @@ void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, cons
emit_opcode(opcode::OP_ScriptFarFunctionCall2, { expr->path->value, expr->name->value });
break;
case ast::call::mode::thread:
emit_opcode(opcode::OP_ScriptFarThreadCall, { argcount, expr->path->value, expr->name->value });
emit_opcode(opcode::OP_ScriptFarThreadCall, { expr->path->value, expr->name->value, argcount });
break;
case ast::call::mode::childthread:
emit_opcode(opcode::OP_ScriptFarChildThreadCall, { argcount, expr->path->value, expr->name->value });
emit_opcode(opcode::OP_ScriptFarChildThreadCall, { expr->path->value, expr->name->value, argcount });
break;
case ast::call::mode::builtin:
// no far builtins
@ -1392,7 +1392,7 @@ void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, cons
case 0:
emit_opcode(opcode::OP_CallBuiltin0, expr->name->value);
break;
case 1:
case 1:
emit_opcode(opcode::OP_CallBuiltin1, expr->name->value);
break;
case 2:
@ -1408,7 +1408,7 @@ void compiler::emit_expr_call_function(const ast::expr_function::ptr& expr, cons
emit_opcode(opcode::OP_CallBuiltin5, expr->name->value);
break;
default:
emit_opcode(opcode::OP_CallBuiltin, { argcount, expr->name->value });
emit_opcode(opcode::OP_CallBuiltin, { expr->name->value, argcount });
break;
}
}
@ -1490,10 +1490,10 @@ void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, co
emit_opcode(opcode::OP_ScriptFarMethodCall, { expr->path->value, expr->name->value });
break;
case ast::call::mode::thread:
emit_opcode(opcode::OP_ScriptFarMethodThreadCall, { argcount, expr->path->value, expr->name->value });
emit_opcode(opcode::OP_ScriptFarMethodThreadCall, { expr->path->value, expr->name->value, argcount });
break;
case ast::call::mode::childthread:
emit_opcode(opcode::OP_ScriptFarMethodChildThreadCall, { argcount, expr->path->value, expr->name->value });
emit_opcode(opcode::OP_ScriptFarMethodChildThreadCall, { expr->path->value, expr->name->value, argcount });
break;
case ast::call::mode::builtin:
// no far builtins
@ -1510,7 +1510,7 @@ void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, co
case 0:
emit_opcode(opcode::OP_CallBuiltinMethod0, expr->name->value);
break;
case 1:
case 1:
emit_opcode(opcode::OP_CallBuiltinMethod1, expr->name->value);
break;
case 2:
@ -1526,7 +1526,7 @@ void compiler::emit_expr_method_function(const ast::expr_function::ptr& expr, co
emit_opcode(opcode::OP_CallBuiltinMethod5, expr->name->value);
break;
default:
emit_opcode(opcode::OP_CallBuiltinMethod, { argcount, expr->name->value });
emit_opcode(opcode::OP_CallBuiltinMethod, { expr->name->value, argcount });
break;
}
}
@ -1548,7 +1548,7 @@ void compiler::emit_expr_parameters(const ast::expr_parameters::ptr& expr, const
for (const auto& entry : expr->list)
{
initialize_variable(entry, blk);
emit_opcode(opcode::OP_SafeCreateVariableFieldCached, variable_create_index(entry, blk));
emit_opcode(opcode::OP_SafeCreateVariableFieldCached, variable_create_index(entry, blk));
}
emit_opcode(opcode::OP_checkclearparams);
@ -1624,7 +1624,7 @@ void compiler::emit_expr_array_ref(const ast::expr_array::ptr& expr, const block
case ast::kind::expr_array:
case ast::kind::expr_field:
emit_expr_variable_ref(expr->obj, blk, false);
emit_opcode(opcode::OP_EvalArrayRef);
emit_opcode(opcode::OP_EvalArrayRef);
if (set) emit_opcode(opcode::OP_SetVariableField);
break;
case ast::kind::expr_identifier:
@ -1791,7 +1791,7 @@ void compiler::emit_expr_field(const ast::expr_field::ptr& expr, const block::pt
case ast::kind::expr_array:
emit_expr_array(expr->obj.as_array, blk);
emit_opcode(opcode::OP_CastFieldObject);
emit_opcode(opcode::OP_EvalFieldVariable, field);
emit_opcode(opcode::OP_EvalFieldVariable, field);
break;
case ast::kind::expr_field:
emit_expr_field(expr->obj.as_field, blk);
@ -2082,7 +2082,7 @@ void compiler::emit_remove_local_vars(const block::ptr& blk)
void compiler::emit_opcode(opcode op)
{
function_->instructions.push_back(std::make_unique<instruction>());
auto& inst = function_->instructions.back();
inst->opcode = static_cast<std::uint8_t>(op);
inst->size = opcode_size(std::uint8_t(op));
@ -2094,7 +2094,7 @@ void compiler::emit_opcode(opcode op)
void compiler::emit_opcode(opcode op, const std::string& data)
{
function_->instructions.push_back(std::make_unique<instruction>());
auto& inst = function_->instructions.back();
inst->opcode = static_cast<std::uint8_t>(op);
inst->size = opcode_size(std::uint8_t(op));
@ -2107,7 +2107,7 @@ void compiler::emit_opcode(opcode op, const std::string& data)
void compiler::emit_opcode(opcode op, const std::vector<std::string>& data)
{
function_->instructions.push_back(std::make_unique<instruction>());
auto& inst = function_->instructions.back();
inst->opcode = static_cast<std::uint8_t>(op);
inst->size = opcode_size(std::uint8_t(op));
@ -2224,7 +2224,7 @@ void compiler::process_stmt_expr(const ast::stmt_expr::ptr& stmt, const block::p
throw comp_error(stmt->loc(), "unknown expr statement expression");
}
}
void compiler::process_stmt_assign(const ast::stmt_assign::ptr& stmt, const block::ptr& blk)
{
switch (stmt->expr.kind())
@ -2261,7 +2261,7 @@ void compiler::process_stmt_waittill(const ast::stmt_waittill::ptr& stmt, const
{
throw comp_error(entry.loc(), "illegal waittill param, must be a local variable");
}
register_variable(entry.as_identifier->value, blk);
}
}
@ -2304,7 +2304,7 @@ void compiler::process_stmt_ifelse(const ast::stmt_ifelse::ptr& stmt, const bloc
if (abort == abort_t::abort_none)
childs.push_back(stmt->blk_else.get());
}
if (blk->abort == abort_t::abort_none)
blk->abort = abort;
@ -2434,7 +2434,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
// calculate stmt variables & add missing array access as first stmt
process_expr(stmt->value_expr, stmt->ctx);
process_stmt(stmt->stmt, stmt->ctx);
continue_blks_.push_back(stmt->ctx.get());
for (auto i = 0; i < continue_blks_.size(); i++)
@ -2706,7 +2706,7 @@ auto compiler::variable_stack_index(const ast::expr_identifier::ptr& name, const
}
throw comp_error(name->loc(), "local variable '" + name->value + "' not initialized.");
}
}
}
throw comp_error(name->loc(), "local variable '" + name->value + "' not found.");
@ -2735,7 +2735,7 @@ auto compiler::variable_access_index(const ast::expr_identifier::ptr& name, cons
}
throw comp_error(name->loc(), "local variable '" + name->value + "' not initialized.");
}
}
}
throw comp_error(name->loc(), "local variable '" + name->value + "' not found.");

View File

@ -88,7 +88,7 @@ private:
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_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);

View File

@ -29,9 +29,9 @@ void decompiler::decompile(const std::string& file, std::vector<function::ptr>&
filename_ = file;
program_ = std::make_unique<ast::program>();
for (auto& func : funcs)
for (const auto& func : funcs)
{
auto name = std::make_unique<ast::expr_identifier>(func->name.substr(4));
auto name = std::make_unique<ast::expr_identifier>(func->name);
auto params = std::make_unique<ast::expr_parameters>();
auto block = std::make_unique<ast::stmt_list>();
func_ = std::make_unique<ast::decl_thread>(std::move(name), std::move(params), std::move(block));
@ -52,9 +52,9 @@ void decompiler::decompile(const std::string& file, std::vector<function::ptr>&
void decompiler::decompile_function(const function::ptr& func)
{
bool in_waittill_ = false;
in_waittill_ = false;
for (auto& inst : func->instructions)
for (const auto& inst : func->instructions)
{
decompile_instruction(inst);
}
@ -64,7 +64,7 @@ void decompiler::decompile_function(const function::ptr& func)
throw decomp_error("stack isn't emty at function end");
}
auto& stmt = func_->stmt;
const auto& stmt = func_->stmt;
block blk;
blk.loc_end = utils::string::va("loc_%X", stmt->list.back().as_node->loc().begin.line);
@ -114,7 +114,7 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
stack_.push(std::move(node));
}
break;
case opcode::OP_GetByte:
case opcode::OP_GetByte:
case opcode::OP_GetUnsignedShort:
case opcode::OP_GetInteger:
{
@ -244,14 +244,14 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
case opcode::OP_GetLocalFunction:
{
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0].substr(4));
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto node = std::make_unique<ast::expr_reference>(loc, std::move(path), std::move(name));
stack_.push(std::move(node));
}
break;
case opcode::OP_GetFarFunction:
{
auto path = std::make_unique<ast::expr_path>(loc, utils::string::backslash(inst->data[0]));
auto path = std::make_unique<ast::expr_path>(loc, inst->data[0]);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[1]);
auto node = std::make_unique<ast::expr_reference>(loc, std::move(path), std::move(name));
stack_.push(std::move(node));
@ -348,7 +348,7 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
auto key = ast::expr(std::move(stack_.top())); stack_.pop();
auto obj = ast::expr(std::make_unique<ast::asm_access>(loc, "0"));
auto node = std::make_unique<ast::expr_array>(key.loc(), std::move(obj), std::move(key));
stack_.push(std::move(node));
stack_.push(std::move(node));
}
break;
case opcode::OP_EvalLocalArrayRefCached:
@ -411,8 +411,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
case opcode::OP_ScriptLocalFunctionCall2:
{
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0].substr(4));
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto call = ast::call(std::make_unique<ast::expr_function>(loc, std::move(path), std::move(name), std::move(args), ast::call::mode::normal));
auto node = std::make_unique<ast::expr_call>(loc, std::move(call));
stack_.push(std::move(node));
@ -421,8 +421,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
case opcode::OP_ScriptLocalFunctionCall:
{
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0].substr(4));
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto var = std::move(stack_.top());
stack_.pop();
@ -447,8 +447,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
loc = obj.loc();
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0].substr(4));
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto var = std::move(stack_.top()); stack_.pop();
loc = var->loc();
@ -468,8 +468,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
case opcode::OP_ScriptLocalThreadCall:
{
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0].substr(4));
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
for (auto i = std::stoul(inst->data[1]); i > 0; i--)
{
@ -487,8 +487,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
case opcode::OP_ScriptLocalChildThreadCall:
{
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0].substr(4));
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
for (auto i = std::stoul(inst->data[1]); i > 0; i--)
{
@ -508,8 +508,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
loc = obj.loc();
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0].substr(4));
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
for (auto i = std::stoul(inst->data[1]); i > 0; i--)
{
@ -529,8 +529,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
loc = obj.loc();
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0].substr(4));
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
for (auto i = std::stoul(inst->data[1]); i > 0; i--)
{
@ -547,8 +547,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
case opcode::OP_ScriptFarFunctionCall2:
{
auto args = std::make_unique<ast::expr_arguments>(loc);
auto path = std::make_unique<ast::expr_path>(loc, inst->data[0]);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[1]);
auto path = std::make_unique<ast::expr_path>(loc, utils::string::backslash(inst->data[0]));
auto call = ast::call(std::make_unique<ast::expr_function>(loc, std::move(path), std::move(name), std::move(args), ast::call::mode::normal));
auto node = std::make_unique<ast::expr_call>(loc, std::move(call));
stack_.push(std::move(node));
@ -557,8 +557,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
case opcode::OP_ScriptFarFunctionCall:
{
auto args = std::make_unique<ast::expr_arguments>(loc);
auto path = std::make_unique<ast::expr_path>(loc, inst->data[0]);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[1]);
auto path = std::make_unique<ast::expr_path>(loc, utils::string::backslash(inst->data[0]));
auto var = std::move(stack_.top()); stack_.pop();
loc = var->loc();
@ -581,8 +581,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
loc = obj.as_node->loc();
auto args = std::make_unique<ast::expr_arguments>(loc);
auto path = std::make_unique<ast::expr_path>(loc, inst->data[0]);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[1]);
auto path = std::make_unique<ast::expr_path>(loc, utils::string::backslash(inst->data[0]));
auto var = std::move(stack_.top()); stack_.pop();
loc = var->loc();
@ -602,10 +602,10 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
case opcode::OP_ScriptFarThreadCall:
{
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[2]);
auto path = std::make_unique<ast::expr_path>(loc, utils::string::backslash(inst->data[1]));
auto path = std::make_unique<ast::expr_path>(loc, inst->data[0]);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[1]);
for (auto i = std::stoul(inst->data[0]); i > 0; i--)
for (auto i = std::stoul(inst->data[2]); i > 0; i--)
{
auto var = std::move(stack_.top()); stack_.pop();
loc = var->loc();
@ -620,10 +620,10 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
case opcode::OP_ScriptFarChildThreadCall:
{
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[2]);
auto path = std::make_unique<ast::expr_path>(loc, utils::string::backslash(inst->data[1]));
auto path = std::make_unique<ast::expr_path>(loc, inst->data[0]);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[1]);
for (auto i = std::stoul(inst->data[0]); i > 0; i--)
for (auto i = std::stoul(inst->data[2]); i > 0; i--)
{
auto var = std::move(stack_.top()); stack_.pop();
loc = var->loc();
@ -641,10 +641,10 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
loc = obj.as_node->loc();
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[2]);
auto path = std::make_unique<ast::expr_path>(loc, utils::string::backslash(inst->data[1]));
auto path = std::make_unique<ast::expr_path>(loc, inst->data[0]);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[1]);
for (auto i = std::stoul(inst->data[0]); i > 0; i--)
for (auto i = std::stoul(inst->data[2]); i > 0; i--)
{
auto var = std::move(stack_.top()); stack_.pop();
loc = var->loc();
@ -662,10 +662,10 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
loc = obj.as_node->loc();
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[2]);
auto path = std::make_unique<ast::expr_path>(loc, utils::string::backslash(inst->data[1]));
auto path = std::make_unique<ast::expr_path>(loc, inst->data[0]);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[1]);
for (auto i = std::stoul(inst->data[0]); i > 0; i--)
for (auto i = std::stoul(inst->data[2]); i > 0; i--)
{
auto var = std::move(stack_.top()); stack_.pop();
loc = var->loc();
@ -830,8 +830,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
case opcode::OP_CallBuiltin0:
{
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto call = ast::call(std::make_unique<ast::expr_function>(loc, std::move(path), std::move(name), std::move(args), ast::call::mode::builtin));
auto node = std::make_unique<ast::expr_call>(loc, std::move(call));
stack_.push(std::move(node));
@ -840,8 +840,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
case opcode::OP_CallBuiltin1:
{
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
for (auto i = 1u; i > 0; i--)
{
@ -849,7 +849,7 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
loc = var->loc();
args->list.push_back(std::move(var));
}
auto call = ast::call(std::make_unique<ast::expr_function>(loc, std::move(path), std::move(name), std::move(args), ast::call::mode::builtin));
auto node = std::make_unique<ast::expr_call>(loc, std::move(call));
stack_.push(std::move(node));
@ -858,8 +858,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
case opcode::OP_CallBuiltin2:
{
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
for (auto i = 2u; i > 0; i--)
{
@ -867,7 +867,7 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
loc = var->loc();
args->list.push_back(std::move(var));
}
auto call = ast::call(std::make_unique<ast::expr_function>(loc, std::move(path), std::move(name), std::move(args), ast::call::mode::builtin));
auto node = std::make_unique<ast::expr_call>(loc, std::move(call));
stack_.push(std::move(node));
@ -876,8 +876,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
case opcode::OP_CallBuiltin3:
{
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
for (auto i = 3u; i > 0; i--)
{
@ -885,7 +885,7 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
loc = var->loc();
args->list.push_back(std::move(var));
}
auto call = ast::call(std::make_unique<ast::expr_function>(loc, std::move(path), std::move(name), std::move(args), ast::call::mode::builtin));
auto node = std::make_unique<ast::expr_call>(loc, std::move(call));
stack_.push(std::move(node));
@ -894,8 +894,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
case opcode::OP_CallBuiltin4:
{
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
for (auto i = 4u; i > 0; i--)
{
@ -903,7 +903,7 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
loc = var->loc();
args->list.push_back(std::move(var));
}
auto call = ast::call(std::make_unique<ast::expr_function>(loc, std::move(path), std::move(name), std::move(args), ast::call::mode::builtin));
auto node = std::make_unique<ast::expr_call>(loc, std::move(call));
stack_.push(std::move(node));
@ -912,8 +912,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
case opcode::OP_CallBuiltin5:
{
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
for (auto i = 5u; i > 0; i--)
{
@ -921,7 +921,7 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
loc = var->loc();
args->list.push_back(std::move(var));
}
auto call = ast::call(std::make_unique<ast::expr_function>(loc, std::move(path), std::move(name), std::move(args), ast::call::mode::builtin));
auto node = std::make_unique<ast::expr_call>(loc, std::move(call));
stack_.push(std::move(node));
@ -930,10 +930,10 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
case opcode::OP_CallBuiltin:
{
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[1]);
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
for (auto i = std::stoul(inst->data[0]); i > 0; i--)
for (auto i = std::stoul(inst->data[1]); i > 0; i--)
{
auto var = std::move(stack_.top()); stack_.pop();
loc = var->loc();
@ -948,8 +948,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
case opcode::OP_CallBuiltinMethod0:
{
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto obj = ast::expr(std::move(stack_.top())); stack_.pop();
loc = obj.as_node->loc();
@ -962,8 +962,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
{
auto obj = ast::expr(std::move(stack_.top())); stack_.pop();
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
for (auto i = 1u; i > 0; i--)
{
@ -981,8 +981,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
{
auto obj = ast::expr(std::move(stack_.top())); stack_.pop();
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
for (auto i = 2u; i > 0; i--)
{
@ -1000,8 +1000,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
{
auto obj = ast::expr(std::move(stack_.top())); stack_.pop();
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
for (auto i = 3u; i > 0; i--)
{
@ -1019,8 +1019,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
{
auto obj = ast::expr(std::move(stack_.top())); stack_.pop();
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
for (auto i = 4u; i > 0; i--)
{
@ -1038,8 +1038,8 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
{
auto obj = ast::expr(std::move(stack_.top())); stack_.pop();
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
for (auto i = 5u; i > 0; i--)
{
@ -1056,12 +1056,12 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
case opcode::OP_CallBuiltinMethod:
{
auto args = std::make_unique<ast::expr_arguments>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[1]);
auto path = std::make_unique<ast::expr_path>(loc);
auto name = std::make_unique<ast::expr_identifier>(loc, inst->data[0]);
auto obj = ast::expr(std::move(stack_.top())); stack_.pop();
loc = obj.as_node->loc();
for (auto i = std::stoul(inst->data[0]); i > 0; i--)
for (auto i = std::stoul(inst->data[1]); i > 0; i--)
{
auto var = std::move(stack_.top()); stack_.pop();
loc = var->loc();
@ -1365,7 +1365,7 @@ void decompiler::decompile_instruction(const instruction::ptr& inst)
auto node = std::make_unique<ast::expr_size>(loc, std::move(lvalue));
stack_.push(std::move(node));
}
break;
break;
case opcode::OP_EvalLevelFieldVariable:
{
auto obj = ast::expr(std::make_unique<ast::expr_level>(loc));
@ -1846,7 +1846,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
if(entry == ast::kind::asm_jump_cond)
{
auto j = (entry.as_cond->value == blocks_.back().loc_end) ? (stmt->list.size() - 1) : (find_location_index(stmt, entry.as_cond->value) - 1);
auto j = (entry.as_cond->value == blocks_.back().loc_end) ? (stmt->list.size() - 1) : (find_location_index(stmt, entry.as_cond->value) - 1);
auto last_loc = blocks_.back().loc_end;
if (stmt->list.at(j) == ast::kind::asm_jump)
@ -1921,7 +1921,7 @@ void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
{
auto loc = block->list.at(i).loc();
auto jump_loc = block->list.at(i).as_jump->value;
if (jump_loc == blocks_.back().loc_continue)
{
block->list.erase(block->list.begin() + i);
@ -2057,7 +2057,7 @@ void decompiler::decompile_last_ifelse(const ast::stmt_list::ptr& stmt, std::uin
end = stmt->list.size() - 1;
else_blk.loc_end = stmt->list.at(end).loc().label();
auto else_stmt = std::make_unique<ast::stmt_list>(loc);
for (auto i = begin; i < end; i++)
@ -2164,11 +2164,11 @@ void decompiler::decompile_loop(const ast::stmt_list::ptr& block, std::uint32_t
{
decompile_for(block, start, end);
return;
}
}
}
}
}
decompile_while(block, start, end);
}
@ -2566,7 +2566,7 @@ void decompiler::process_stmt(const ast::stmt& stmt, const block::ptr& blk)
{
auto expr = ast::expr(std::make_unique<ast::asm_create>(stmt.as_asm_create->index));
process_var_create(expr, blk, true);
}
}
break;
default:
break;
@ -2685,7 +2685,7 @@ void decompiler::process_stmt_waittill(const ast::stmt_waittill::ptr& stmt, cons
{
process_expr(stmt->event ,blk);
process_expr(stmt->obj, blk);
for (auto& entry : stmt->args->list)
{
process_expr(entry, blk);
@ -3076,7 +3076,7 @@ void decompiler::process_expr_decrement(const ast::expr_decrement::ptr& expr, co
{
process_expr(expr->lvalue, blk);
}
void decompiler::process_expr_ternary(const ast::expr_ternary::ptr& expr, const block::ptr& blk)
{
process_expr(expr->test, blk);

View File

@ -21,7 +21,7 @@ auto disassembler::output_data() -> std::vector<std::uint8_t>
output_->write_string("// S1 GSC ASSEMBLY\n");
output_->write_string("// Disassembled by https://github.com/xensik/gsc-tool\n");
for (auto& func : functions_)
for (const auto& func : functions_)
{
print_function(func);
}
@ -46,12 +46,12 @@ void disassembler::disassemble(const std::string& file, std::vector<std::uint8_t
while (stack_->is_avail() && script_->is_avail())
{
functions_.push_back(std::make_unique<function>());
auto& func = functions_.back();
const auto& func = functions_.back();
func->index = static_cast<std::uint32_t>(script_->pos());
func->size = stack_->read<std::uint32_t>();
func->id = stack_->read<std::uint16_t>();
func->name = "sub_"s + (func->id == 0 ? stack_->read_c_string() : resolver::token_name(func->id));
func->name = func->id == 0 ? stack_->read_c_string() : resolver::token_name(func->id);
dissasemble_function(func);
@ -69,8 +69,8 @@ void disassembler::dissasemble_function(const function::ptr& func)
while (size > 0)
{
func->instructions.push_back(std::make_unique<instruction>());
auto& inst = func->instructions.back();
const auto& inst = func->instructions.back();
inst->index = static_cast<std::uint32_t>(script_->pos());
inst->opcode = script_->read<std::uint8_t>();
inst->size = opcode_size(inst->opcode);
@ -169,7 +169,7 @@ void disassembler::dissasemble_instruction(const instruction::ptr& inst)
break;
case opcode::OP_GetFloat:
{
auto val = script_->read<float>();
const auto val = script_->read<float>();
inst->data.push_back(utils::string::va("%g%s", val, val == int(val) ? ".0" : ""));
}
break;
@ -311,19 +311,14 @@ void disassembler::disassemble_builtin_call(const instruction::ptr& inst, bool m
inst->data.push_back(utils::string::va("%i", script_->read<std::uint8_t>()));
}
if (method)
{
inst->data.push_back(resolver::method_name(script_->read<std::uint16_t>()));
}
else
{
inst->data.push_back(resolver::function_name(script_->read<std::uint16_t>()));
}
const auto id = script_->read<std::uint16_t>();
const auto name = method ? resolver::method_name(id) : resolver::function_name(id);
inst->data.emplace(inst->data.begin(), name);
}
void disassembler::disassemble_local_call(const instruction::ptr& inst, bool thread)
{
std::int32_t offset = disassemble_offset();
const auto offset = disassemble_offset();
inst->data.push_back(utils::string::va("%X", offset + inst->index + 1));
@ -342,88 +337,43 @@ void disassembler::disassemble_far_call(const instruction::ptr& inst, bool threa
inst->data.push_back(utils::string::va("%i", script_->read<std::uint8_t>()));
}
auto file_id = stack_->read<std::uint16_t>();
auto file_name = file_id == 0 ? stack_->read_c_string() : resolver::file_name(file_id);
auto func_id = stack_->read<std::uint16_t>();
auto func_name = func_id == 0 ? stack_->read_c_string() : resolver::token_name(func_id);
const auto file_id = stack_->read<std::uint16_t>();
const auto file_name = file_id == 0 ? stack_->read_c_string() : resolver::file_name(file_id);
const auto func_id = stack_->read<std::uint16_t>();
const auto func_name = func_id == 0 ? stack_->read_c_string() : resolver::token_name(func_id);
inst->data.push_back(file_name != "" ? file_name : utils::string::va("_ID%i", file_id));
inst->data.push_back(func_name != "" ? func_name : utils::string::va("_ID%i", func_id));
}
void disassembler::disassemble_jump(const instruction::ptr& inst, bool expr, bool back)
{
std::int32_t addr;
std::string label;
if (expr)
{
addr = inst->index + 3 + script_->read<std::int16_t>();
label = utils::string::va("loc_%X", addr);
inst->data.push_back(label);
}
else if (back)
{
addr = inst->index + 3 - script_->read<std::uint16_t>();
label = utils::string::va("loc_%X", addr);
inst->data.push_back(label);
}
else
{
addr = inst->index + 5 + script_->read<std::int32_t>();
label = utils::string::va("loc_%X", addr);
inst->data.push_back(label);
}
labels_.insert({addr, label});
}
void disassembler::disassemble_field_variable(const instruction::ptr& inst)
{
std::uint16_t field_id = script_->read<std::uint16_t>();
std::string field_name;
if (field_id > 0xA7DC)
{
auto temp = stack_->read<std::uint16_t>();
field_name = temp == 0 ? stack_->read_c_string() : std::to_string(temp);
}
else
{
field_name = resolver::token_name(field_id);
}
inst->data.push_back(field_name != "" ? field_name : utils::string::va("_ID%i", field_id));
inst->data.emplace(inst->data.begin(), func_name);
inst->data.emplace(inst->data.begin(), file_name);
}
void disassembler::disassemble_switch(const instruction::ptr& inst)
{
std::int32_t addr = inst->index + 4 + script_->read<std::int32_t>();
std::string label = utils::string::va("loc_%X", addr);
const auto addr = inst->index + 4 + script_->read<std::int32_t>();
const auto label = utils::string::va("loc_%X", addr);
inst->data.push_back(label);
labels_.insert({addr, label});
labels_.insert({ addr, label });
}
void disassembler::disassemble_end_switch(const instruction::ptr& inst)
{
std::uint16_t case_num = script_->read<std::uint16_t>();
inst->data.push_back(utils::string::va("%i", case_num));
const auto count = script_->read<std::uint16_t>();
inst->data.push_back(utils::string::va("%i", count));
std::uint32_t internal_index = inst->index + 3;
std::uint32_t index = inst->index + 3;
if (case_num)
if (count)
{
for (auto i = case_num; i > 0; i--)
for (auto i = count; i > 0; i--)
{
std::uint32_t case_label = script_->read<std::uint32_t>();
const auto value = script_->read<std::uint32_t>();
if (case_label < 0x40000 && case_label > 0)
if (value < 0x40000 && value > 0)
{
inst->data.push_back("case");
inst->data.push_back(utils::string::quote(stack_->read_c_string(), false));
}
else if (case_label == 0)
else if (value == 0)
{
inst->data.push_back("default");
stack_->read<std::uint16_t>();
@ -431,24 +381,64 @@ void disassembler::disassemble_end_switch(const instruction::ptr& inst)
else
{
inst->data.push_back("case");
inst->data.push_back(utils::string::va("%i", (case_label - 0x800000) & 0xFFFFFF));
inst->data.push_back(utils::string::va("%i", (value - 0x800000) & 0xFFFFFF));
}
inst->size += 4;
internal_index += 4;
index += 4;
const auto addr = disassemble_offset() + index;
const auto label = utils::string::va("loc_%X", addr);
auto addr = disassemble_offset() + internal_index;
std::string label = utils::string::va("loc_%X", addr);
inst->data.push_back(label);
labels_.insert({ addr, label });
labels_.insert({addr, label});
inst->size += 3;
internal_index += 3;
index += 3;
inst->size += 7;
}
}
}
void disassembler::disassemble_field_variable(const instruction::ptr& inst)
{
const auto id = script_->read<std::uint16_t>();
std::string name;
if (id > max_string_id)
{
auto temp = stack_->read<std::uint16_t>();
name = temp == 0 ? stack_->read_c_string() : std::to_string(temp);
}
else
{
name = resolver::token_name(id);
}
inst->data.push_back(name);
}
void disassembler::disassemble_jump(const instruction::ptr& inst, bool expr, bool back)
{
std::int32_t addr;
if (expr)
{
addr = inst->index + 3 + script_->read<std::int16_t>();
}
else if (back)
{
addr = inst->index + 3 - script_->read<std::uint16_t>();
}
else
{
addr = inst->index + 5 + script_->read<std::int32_t>();
}
const auto label = utils::string::va("loc_%X", addr);
inst->data.push_back(label);
labels_.insert({ addr, label });
}
auto disassembler::disassemble_offset() -> std::int32_t
{
std::array<std::uint8_t, 4> bytes = {};
@ -458,7 +448,7 @@ auto disassembler::disassemble_offset() -> std::int32_t
bytes[i] = script_->read<std::uint8_t>();
}
std::int32_t offset = *reinterpret_cast<std::int32_t*>(bytes.data());
auto offset = *reinterpret_cast<std::int32_t*>(bytes.data());
offset = (offset << 8) >> 10;
@ -467,24 +457,24 @@ auto disassembler::disassemble_offset() -> std::int32_t
void disassembler::resolve_local_functions()
{
for (auto& func : functions_)
for (const auto& func : functions_)
{
for (auto& inst : func->instructions)
for (const auto& inst : func->instructions)
{
switch (opcode(inst->opcode))
{
case opcode::OP_GetLocalFunction:
case opcode::OP_ScriptLocalFunctionCall:
case opcode::OP_ScriptLocalFunctionCall2:
case opcode::OP_ScriptLocalMethodCall:
case opcode::OP_ScriptLocalThreadCall:
case opcode::OP_ScriptLocalChildThreadCall:
case opcode::OP_ScriptLocalMethodThreadCall:
case opcode::OP_ScriptLocalMethodChildThreadCall:
inst->data.at(0) = resolve_function(inst->data[0]);
break;
default:
break;
case opcode::OP_GetLocalFunction:
case opcode::OP_ScriptLocalFunctionCall:
case opcode::OP_ScriptLocalFunctionCall2:
case opcode::OP_ScriptLocalMethodCall:
case opcode::OP_ScriptLocalThreadCall:
case opcode::OP_ScriptLocalChildThreadCall:
case opcode::OP_ScriptLocalMethodThreadCall:
case opcode::OP_ScriptLocalMethodChildThreadCall:
inst->data[0] = resolve_function(inst->data[0]);
break;
default:
break;
}
}
}
@ -513,9 +503,9 @@ auto disassembler::resolve_function(const std::string& index) -> std::string
void disassembler::print_function(const function::ptr& func)
{
output_->write_string("\n");
output_->write_string(utils::string::va("%s\n", func->name.data()));
output_->write_string(utils::string::va("sub_%s\n", func->name.data()));
for (auto& inst : func->instructions)
for (const auto& inst : func->instructions)
{
const auto itr = func->labels.find(inst->index);
@ -533,40 +523,53 @@ void disassembler::print_function(const function::ptr& func)
void disassembler::print_instruction(const instruction::ptr& inst)
{
output_->write_string(utils::string::va("\t\t%s", resolver::opcode_name(inst->opcode).data()));
switch (opcode(inst->opcode))
{
case opcode::OP_endswitch:
output_->write_string(utils::string::va("\t\t%s", resolver::opcode_name(inst->opcode).data()));
output_->write_string(utils::string::va(" %s\n", inst->data[0].data()));
{
std::uint32_t totalcase = std::stoul(inst->data[0]);
auto index = 0;
for (auto casenum = 0u; casenum < totalcase; casenum++)
case opcode::OP_GetLocalFunction:
case opcode::OP_ScriptLocalFunctionCall:
case opcode::OP_ScriptLocalFunctionCall2:
case opcode::OP_ScriptLocalMethodCall:
output_->write_string(utils::string::va(" sub_%s", inst->data[0].data()));
break;
case opcode::OP_ScriptLocalThreadCall:
case opcode::OP_ScriptLocalChildThreadCall:
case opcode::OP_ScriptLocalMethodThreadCall:
case opcode::OP_ScriptLocalMethodChildThreadCall:
output_->write_string(utils::string::va(" sub_%s", inst->data[0].data()));
output_->write_string(utils::string::va(" %s", inst->data[1].data()));
break;
case opcode::OP_endswitch:
output_->write_string(utils::string::va(" %s\n", inst->data[0].data()));
{
if (inst->data[1 + index] == "case")
std::uint32_t totalcase = std::stoul(inst->data[0]);
auto index = 0;
for (auto casenum = 0u; casenum < totalcase; casenum++)
{
output_->write_string(utils::string::va("\t\t\t%s %s %s", inst->data[1 + index].data(), inst->data[1 + index + 1].data(), inst->data[1 + index + 2].data()));
index += 3;
}
else if (inst->data[1 + index] == "default")
{
output_->write_string(utils::string::va("\t\t\t%s %s", inst->data[1 + index].data(), inst->data[1 + index + 1].data()));
index += 2;
}
if (casenum != totalcase - 1)
{
output_->write_string("\n");
if (inst->data[1 + index] == "case")
{
output_->write_string(utils::string::va("\t\t\t%s %s %s", inst->data[1 + index].data(), inst->data[1 + index + 1].data(), inst->data[1 + index + 2].data()));
index += 3;
}
else if (inst->data[1 + index] == "default")
{
output_->write_string(utils::string::va("\t\t\t%s %s", inst->data[1 + index].data(), inst->data[1 + index + 1].data()));
index += 2;
}
if (casenum != totalcase - 1)
{
output_->write_string("\n");
}
}
}
}
break;
default:
output_->write_string(utils::string::va("\t\t%s", resolver::opcode_name(inst->opcode).data()));
for (auto& d : inst->data)
{
output_->write_string(utils::string::va(" %s", d.data()));
}
break;
break;
default:
for (auto& d : inst->data)
{
output_->write_string(utils::string::va(" %s", d.data()));
}
break;
}
output_->write_string("\n");

View File

@ -28,10 +28,10 @@ private:
void disassemble_builtin_call(const instruction::ptr& inst, bool method, bool args);
void disassemble_local_call(const instruction::ptr& inst, bool thread);
void disassemble_far_call(const instruction::ptr& inst, bool thread);
void disassemble_jump(const instruction::ptr& inst, bool expr, bool back);
void disassemble_field_variable(const instruction::ptr& inst);
void disassemble_switch(const instruction::ptr& inst);
void disassemble_end_switch(const instruction::ptr& inst);
void disassemble_field_variable(const instruction::ptr& inst);
void disassemble_jump(const instruction::ptr& inst, bool expr, bool back);
auto disassemble_offset() -> std::int32_t;
void resolve_local_functions();
auto resolve_function(const std::string& index) -> std::string;

View File

@ -555,8 +555,8 @@ static void yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner );
yyg->yy_hold_char = *yy_cp; \
*yy_cp = '\0'; \
yyg->yy_c_buf_p = yy_cp;
#define YY_NUM_RULES 111
#define YY_END_OF_BUFFER 112
#define YY_NUM_RULES 112
#define YY_END_OF_BUFFER 113
/* This struct is not used in this scanner,
but its presence is necessary. */
struct yy_trans_info
@ -566,24 +566,24 @@ struct yy_trans_info
};
static const flex_int16_t yy_accept[333] =
{ 0,
0, 0, 0, 0, 0, 0, 0, 0, 112, 110,
1, 2, 95, 110, 110, 94, 98, 110, 55, 56,
92, 90, 61, 91, 62, 93, 109, 109, 64, 65,
0, 0, 0, 0, 0, 0, 0, 0, 113, 111,
1, 2, 95, 111, 111, 94, 98, 111, 55, 56,
92, 90, 61, 91, 62, 93, 110, 110, 64, 65,
79, 89, 80, 66, 101, 59, 60, 99, 101, 101,
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
101, 101, 101, 101, 57, 97, 58, 96, 5, 6,
5, 12, 13, 12, 110, 92, 93, 76, 0, 103,
5, 12, 13, 12, 111, 92, 93, 76, 0, 103,
0, 15, 0, 0, 0, 0, 85, 0, 74, 0,
87, 0, 0, 8, 83, 67, 81, 68, 82, 105,
0, 11, 4, 3, 84, 105, 109, 106, 0, 0,
87, 0, 0, 8, 83, 67, 81, 68, 82, 106,
0, 11, 4, 3, 84, 106, 110, 107, 0, 0,
0, 0, 63, 71, 77, 75, 78, 72, 101, 88,
101, 101, 101, 101, 101, 101, 29, 101, 101, 101,
101, 101, 27, 33, 101, 101, 101, 101, 101, 101,
101, 101, 101, 101, 101, 86, 73, 7, 14, 10,
9, 0, 103, 0, 0, 0, 0, 0, 0, 102,
0, 0, 0, 0, 103, 0, 105, 0, 3, 105,
105, 106, 107, 108, 100, 69, 70, 101, 101, 101,
0, 0, 0, 0, 103, 0, 106, 0, 3, 106,
106, 107, 108, 109, 100, 69, 70, 101, 101, 101,
101, 101, 101, 101, 101, 101, 101, 31, 101, 101,
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
101, 104, 0, 0, 0, 0, 0, 102, 0, 0,
@ -595,7 +595,7 @@ static const flex_int16_t yy_accept[333] =
54, 101, 101, 101, 101, 101, 101, 101, 101, 101,
30, 0, 0, 0, 0, 0, 101, 101, 101, 101,
101, 21, 101, 101, 39, 34, 101, 43, 101, 101,
101, 104, 0, 0, 16, 0, 101, 101, 101, 36,
101, 105, 0, 0, 16, 0, 101, 101, 101, 36,
32, 101, 101, 101, 101, 101, 101, 0, 17, 0,
101, 101, 38, 101, 42, 101, 101, 101, 23, 19,
@ -1193,11 +1193,11 @@ YY_DECL
}
{
#line 43 "lexer.lpp"
#line 44 "lexer.lpp"
#line 47 "lexer.lpp"
#line 48 "lexer.lpp"
ctx->loc.step();
@ -1256,582 +1256,587 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
#line 50 "lexer.lpp"
#line 51 "lexer.lpp"
{ ctx->loc.step(); }
YY_BREAK
case 2:
/* rule 2 can match eol */
YY_RULE_SETUP
#line 51 "lexer.lpp"
#line 52 "lexer.lpp"
{ ctx->loc.lines(yyleng); ctx->loc.step(); }
YY_BREAK
case 3:
YY_RULE_SETUP
#line 53 "lexer.lpp"
#line 54 "lexer.lpp"
YY_BREAK
case 4:
YY_RULE_SETUP
#line 55 "lexer.lpp"
#line 56 "lexer.lpp"
{ BEGIN(COMMENT_STATE); }
YY_BREAK
case 5:
YY_RULE_SETUP
#line 56 "lexer.lpp"
#line 57 "lexer.lpp"
YY_BREAK
case 6:
/* rule 6 can match eol */
YY_RULE_SETUP
#line 57 "lexer.lpp"
#line 58 "lexer.lpp"
{ ctx->loc.lines(yyleng); ctx->loc.step(); }
YY_BREAK
case 7:
YY_RULE_SETUP
#line 58 "lexer.lpp"
#line 59 "lexer.lpp"
{ BEGIN(INITIAL); }
YY_BREAK
case YY_STATE_EOF(COMMENT_STATE):
#line 59 "lexer.lpp"
#line 60 "lexer.lpp"
{ throw s1::parser::syntax_error(ctx->loc, "unmatched multiline comment start ('/*')"); }
YY_BREAK
case 8:
YY_RULE_SETUP
#line 60 "lexer.lpp"
#line 61 "lexer.lpp"
{ throw s1::parser::syntax_error(ctx->loc, "unmatched multiline comment end ('*/')"); }
YY_BREAK
case 9:
YY_RULE_SETUP
#line 62 "lexer.lpp"
#line 63 "lexer.lpp"
{ throw s1::parser::syntax_error(ctx->loc, "cannot recurse devblock ('/#')"); }
YY_BREAK
case 10:
YY_RULE_SETUP
#line 63 "lexer.lpp"
#line 64 "lexer.lpp"
{ BEGIN(INITIAL); return s1::parser::make_DEVEND(ctx->loc); }
YY_BREAK
case YY_STATE_EOF(DEV_ON_STATE):
#line 64 "lexer.lpp"
#line 65 "lexer.lpp"
{ throw s1::parser::syntax_error(ctx->loc, "unmatched devblock start ('/#')"); }
YY_BREAK
case 11:
YY_RULE_SETUP
#line 66 "lexer.lpp"
#line 67 "lexer.lpp"
{ BEGIN(ctx->mode == xsk::gsc::build::dev ? DEV_ON_STATE : DEV_OFF_STATE); if(ctx->mode == xsk::gsc::build::dev) return s1::parser::make_DEVBEGIN(ctx->loc); }
YY_BREAK
case 12:
YY_RULE_SETUP
#line 67 "lexer.lpp"
#line 68 "lexer.lpp"
YY_BREAK
case 13:
/* rule 13 can match eol */
YY_RULE_SETUP
#line 68 "lexer.lpp"
#line 69 "lexer.lpp"
{ ctx->loc.lines(yyleng); ctx->loc.step(); }
YY_BREAK
case 14:
YY_RULE_SETUP
#line 69 "lexer.lpp"
#line 70 "lexer.lpp"
{ BEGIN(INITIAL); }
YY_BREAK
case YY_STATE_EOF(DEV_OFF_STATE):
#line 70 "lexer.lpp"
#line 71 "lexer.lpp"
{ throw s1::parser::syntax_error(ctx->loc, "unmatched devblock start ('/#')"); }
YY_BREAK
case 15:
YY_RULE_SETUP
#line 71 "lexer.lpp"
#line 72 "lexer.lpp"
{ throw s1::parser::syntax_error(ctx->loc, "unmatched devblock end ('#/')"); }
YY_BREAK
case 16:
YY_RULE_SETUP
#line 73 "lexer.lpp"
#line 74 "lexer.lpp"
{ return s1::parser::make_INLINE(ctx->loc); }
YY_BREAK
case 17:
YY_RULE_SETUP
#line 74 "lexer.lpp"
#line 75 "lexer.lpp"
{ return s1::parser::make_INCLUDE(ctx->loc); }
YY_BREAK
case 18:
YY_RULE_SETUP
#line 75 "lexer.lpp"
#line 76 "lexer.lpp"
{ return s1::parser::make_USINGTREE(ctx->loc); }
YY_BREAK
case 19:
YY_RULE_SETUP
#line 76 "lexer.lpp"
#line 77 "lexer.lpp"
{ return s1::parser::make_ANIMTREE(ctx->loc); }
YY_BREAK
case 20:
YY_RULE_SETUP
#line 77 "lexer.lpp"
#line 78 "lexer.lpp"
{ return s1::parser::make_ENDON(ctx->loc); }
YY_BREAK
case 21:
YY_RULE_SETUP
#line 78 "lexer.lpp"
#line 79 "lexer.lpp"
{ return s1::parser::make_NOTIFY(ctx->loc); }
YY_BREAK
case 22:
YY_RULE_SETUP
#line 79 "lexer.lpp"
#line 80 "lexer.lpp"
{ return s1::parser::make_WAIT(ctx->loc); }
YY_BREAK
case 23:
YY_RULE_SETUP
#line 80 "lexer.lpp"
#line 81 "lexer.lpp"
{ return s1::parser::make_WAITTILL(ctx->loc); }
YY_BREAK
case 24:
YY_RULE_SETUP
#line 81 "lexer.lpp"
#line 82 "lexer.lpp"
{ return s1::parser::make_WAITTILLMATCH(ctx->loc); }
YY_BREAK
case 25:
YY_RULE_SETUP
#line 82 "lexer.lpp"
#line 83 "lexer.lpp"
{ return s1::parser::make_WAITTILLFRAMEEND(ctx->loc); }
YY_BREAK
case 26:
YY_RULE_SETUP
#line 83 "lexer.lpp"
#line 84 "lexer.lpp"
{ return s1::parser::make_WAITFRAME(ctx->loc); }
YY_BREAK
case 27:
YY_RULE_SETUP
#line 84 "lexer.lpp"
#line 85 "lexer.lpp"
{ return s1::parser::make_IF(ctx->loc); }
YY_BREAK
case 28:
YY_RULE_SETUP
#line 85 "lexer.lpp"
#line 86 "lexer.lpp"
{ return s1::parser::make_ELSE(ctx->loc); }
YY_BREAK
case 29:
YY_RULE_SETUP
#line 86 "lexer.lpp"
#line 87 "lexer.lpp"
{ return s1::parser::make_DO(ctx->loc); }
YY_BREAK
case 30:
YY_RULE_SETUP
#line 87 "lexer.lpp"
#line 88 "lexer.lpp"
{ return s1::parser::make_WHILE(ctx->loc); }
YY_BREAK
case 31:
YY_RULE_SETUP
#line 88 "lexer.lpp"
#line 89 "lexer.lpp"
{ return s1::parser::make_FOR(ctx->loc); }
YY_BREAK
case 32:
YY_RULE_SETUP
#line 89 "lexer.lpp"
#line 90 "lexer.lpp"
{ return s1::parser::make_FOREACH(ctx->loc); }
YY_BREAK
case 33:
YY_RULE_SETUP
#line 90 "lexer.lpp"
#line 91 "lexer.lpp"
{ return s1::parser::make_IN(ctx->loc); }
YY_BREAK
case 34:
YY_RULE_SETUP
#line 91 "lexer.lpp"
#line 92 "lexer.lpp"
{ return s1::parser::make_SWITCH(ctx->loc); }
YY_BREAK
case 35:
YY_RULE_SETUP
#line 92 "lexer.lpp"
#line 93 "lexer.lpp"
{ return s1::parser::make_CASE(ctx->loc); }
YY_BREAK
case 36:
YY_RULE_SETUP
#line 93 "lexer.lpp"
#line 94 "lexer.lpp"
{ return s1::parser::make_DEFAULT(ctx->loc); }
YY_BREAK
case 37:
YY_RULE_SETUP
#line 94 "lexer.lpp"
#line 95 "lexer.lpp"
{ return s1::parser::make_BREAK(ctx->loc); }
YY_BREAK
case 38:
YY_RULE_SETUP
#line 95 "lexer.lpp"
#line 96 "lexer.lpp"
{ return s1::parser::make_CONTINUE(ctx->loc); }
YY_BREAK
case 39:
YY_RULE_SETUP
#line 96 "lexer.lpp"
#line 97 "lexer.lpp"
{ return s1::parser::make_RETURN(ctx->loc); }
YY_BREAK
case 40:
YY_RULE_SETUP
#line 97 "lexer.lpp"
#line 98 "lexer.lpp"
{ return s1::parser::make_BREAKPOINT(ctx->loc); }
YY_BREAK
case 41:
YY_RULE_SETUP
#line 98 "lexer.lpp"
#line 99 "lexer.lpp"
{ return s1::parser::make_PROFBEGIN(ctx->loc); }
YY_BREAK
case 42:
YY_RULE_SETUP
#line 99 "lexer.lpp"
#line 100 "lexer.lpp"
{ return s1::parser::make_PROFEND(ctx->loc); }
YY_BREAK
case 43:
YY_RULE_SETUP
#line 100 "lexer.lpp"
#line 101 "lexer.lpp"
{ return s1::parser::make_THREAD(ctx->loc); }
YY_BREAK
case 44:
YY_RULE_SETUP
#line 101 "lexer.lpp"
#line 102 "lexer.lpp"
{ return s1::parser::make_CHILDTHREAD(ctx->loc); }
YY_BREAK
case 45:
YY_RULE_SETUP
#line 102 "lexer.lpp"
#line 103 "lexer.lpp"
{ return s1::parser::make_THISTHREAD(ctx->loc); }
YY_BREAK
case 46:
YY_RULE_SETUP
#line 103 "lexer.lpp"
#line 104 "lexer.lpp"
{ return s1::parser::make_CALL(ctx->loc); }
YY_BREAK
case 47:
YY_RULE_SETUP
#line 104 "lexer.lpp"
#line 105 "lexer.lpp"
{ return s1::parser::make_TRUE(ctx->loc); }
YY_BREAK
case 48:
YY_RULE_SETUP
#line 105 "lexer.lpp"
#line 106 "lexer.lpp"
{ return s1::parser::make_FALSE(ctx->loc); }
YY_BREAK
case 49:
YY_RULE_SETUP
#line 106 "lexer.lpp"
#line 107 "lexer.lpp"
{ return s1::parser::make_UNDEFINED(ctx->loc); }
YY_BREAK
case 50:
YY_RULE_SETUP
#line 107 "lexer.lpp"
#line 108 "lexer.lpp"
{ return s1::parser::make_SIZE(ctx->loc); }
YY_BREAK
case 51:
YY_RULE_SETUP
#line 108 "lexer.lpp"
#line 109 "lexer.lpp"
{ return s1::parser::make_GAME(ctx->loc); }
YY_BREAK
case 52:
YY_RULE_SETUP
#line 109 "lexer.lpp"
#line 110 "lexer.lpp"
{ return s1::parser::make_SELF(ctx->loc); }
YY_BREAK
case 53:
YY_RULE_SETUP
#line 110 "lexer.lpp"
#line 111 "lexer.lpp"
{ return s1::parser::make_ANIM(ctx->loc); }
YY_BREAK
case 54:
YY_RULE_SETUP
#line 111 "lexer.lpp"
#line 112 "lexer.lpp"
{ return s1::parser::make_LEVEL(ctx->loc); }
YY_BREAK
case 55:
YY_RULE_SETUP
#line 112 "lexer.lpp"
#line 113 "lexer.lpp"
{ return s1::parser::make_LPAREN(ctx->loc); }
YY_BREAK
case 56:
YY_RULE_SETUP
#line 113 "lexer.lpp"
#line 114 "lexer.lpp"
{ return s1::parser::make_RPAREN(ctx->loc); }
YY_BREAK
case 57:
YY_RULE_SETUP
#line 114 "lexer.lpp"
#line 115 "lexer.lpp"
{ return s1::parser::make_LBRACE(ctx->loc); }
YY_BREAK
case 58:
YY_RULE_SETUP
#line 115 "lexer.lpp"
#line 116 "lexer.lpp"
{ return s1::parser::make_RBRACE(ctx->loc); }
YY_BREAK
case 59:
YY_RULE_SETUP
#line 116 "lexer.lpp"
#line 117 "lexer.lpp"
{ return s1::parser::make_LBRACKET(ctx->loc); }
YY_BREAK
case 60:
YY_RULE_SETUP
#line 117 "lexer.lpp"
#line 118 "lexer.lpp"
{ return s1::parser::make_RBRACKET(ctx->loc); }
YY_BREAK
case 61:
YY_RULE_SETUP
#line 118 "lexer.lpp"
#line 119 "lexer.lpp"
{ return s1::parser::make_COMMA(ctx->loc); }
YY_BREAK
case 62:
YY_RULE_SETUP
#line 119 "lexer.lpp"
#line 120 "lexer.lpp"
{ return s1::parser::make_DOT(ctx->loc); }
YY_BREAK
case 63:
YY_RULE_SETUP
#line 120 "lexer.lpp"
#line 121 "lexer.lpp"
{ return s1::parser::make_DOUBLECOLON(ctx->loc); }
YY_BREAK
case 64:
YY_RULE_SETUP
#line 121 "lexer.lpp"
#line 122 "lexer.lpp"
{ return s1::parser::make_COLON(ctx->loc); }
YY_BREAK
case 65:
YY_RULE_SETUP
#line 122 "lexer.lpp"
#line 123 "lexer.lpp"
{ return s1::parser::make_SEMICOLON(ctx->loc); }
YY_BREAK
case 66:
YY_RULE_SETUP
#line 123 "lexer.lpp"
#line 124 "lexer.lpp"
{ return s1::parser::make_QMARK(ctx->loc); }
YY_BREAK
case 67:
YY_RULE_SETUP
#line 124 "lexer.lpp"
#line 125 "lexer.lpp"
{ return s1::parser::make_INCREMENT(ctx->loc); }
YY_BREAK
case 68:
YY_RULE_SETUP
#line 125 "lexer.lpp"
#line 126 "lexer.lpp"
{ return s1::parser::make_DECREMENT(ctx->loc); }
YY_BREAK
case 69:
YY_RULE_SETUP
#line 126 "lexer.lpp"
#line 127 "lexer.lpp"
{ return s1::parser::make_ASSIGN_LSHIFT(ctx->loc); }
YY_BREAK
case 70:
YY_RULE_SETUP
#line 127 "lexer.lpp"
#line 128 "lexer.lpp"
{ return s1::parser::make_ASSIGN_RSHIFT(ctx->loc); }
YY_BREAK
case 71:
YY_RULE_SETUP
#line 128 "lexer.lpp"
#line 129 "lexer.lpp"
{ return s1::parser::make_LSHIFT(ctx->loc); }
YY_BREAK
case 72:
YY_RULE_SETUP
#line 129 "lexer.lpp"
#line 130 "lexer.lpp"
{ return s1::parser::make_RSHIFT(ctx->loc); }
YY_BREAK
case 73:
YY_RULE_SETUP
#line 130 "lexer.lpp"
#line 131 "lexer.lpp"
{ return s1::parser::make_OR(ctx->loc); }
YY_BREAK
case 74:
YY_RULE_SETUP
#line 131 "lexer.lpp"
#line 132 "lexer.lpp"
{ return s1::parser::make_AND(ctx->loc); }
YY_BREAK
case 75:
YY_RULE_SETUP
#line 132 "lexer.lpp"
#line 133 "lexer.lpp"
{ return s1::parser::make_EQUALITY(ctx->loc); }
YY_BREAK
case 76:
YY_RULE_SETUP
#line 133 "lexer.lpp"
#line 134 "lexer.lpp"
{ return s1::parser::make_INEQUALITY(ctx->loc); }
YY_BREAK
case 77:
YY_RULE_SETUP
#line 134 "lexer.lpp"
#line 135 "lexer.lpp"
{ return s1::parser::make_LESS_EQUAL(ctx->loc); }
YY_BREAK
case 78:
YY_RULE_SETUP
#line 135 "lexer.lpp"
#line 136 "lexer.lpp"
{ return s1::parser::make_GREATER_EQUAL(ctx->loc); }
YY_BREAK
case 79:
YY_RULE_SETUP
#line 136 "lexer.lpp"
#line 137 "lexer.lpp"
{ return s1::parser::make_LESS(ctx->loc); }
YY_BREAK
case 80:
YY_RULE_SETUP
#line 137 "lexer.lpp"
#line 138 "lexer.lpp"
{ return s1::parser::make_GREATER(ctx->loc); }
YY_BREAK
case 81:
YY_RULE_SETUP
#line 138 "lexer.lpp"
#line 139 "lexer.lpp"
{ return s1::parser::make_ASSIGN_ADD(ctx->loc); }
YY_BREAK
case 82:
YY_RULE_SETUP
#line 139 "lexer.lpp"
#line 140 "lexer.lpp"
{ return s1::parser::make_ASSIGN_SUB(ctx->loc); }
YY_BREAK
case 83:
YY_RULE_SETUP
#line 140 "lexer.lpp"
#line 141 "lexer.lpp"
{ return s1::parser::make_ASSIGN_MUL(ctx->loc); }
YY_BREAK
case 84:
YY_RULE_SETUP
#line 141 "lexer.lpp"
#line 142 "lexer.lpp"
{ return s1::parser::make_ASSIGN_DIV(ctx->loc); }
YY_BREAK
case 85:
YY_RULE_SETUP
#line 142 "lexer.lpp"
#line 143 "lexer.lpp"
{ return s1::parser::make_ASSIGN_MOD(ctx->loc); }
YY_BREAK
case 86:
YY_RULE_SETUP
#line 143 "lexer.lpp"
#line 144 "lexer.lpp"
{ return s1::parser::make_ASSIGN_BW_OR(ctx->loc); }
YY_BREAK
case 87:
YY_RULE_SETUP
#line 144 "lexer.lpp"
#line 145 "lexer.lpp"
{ return s1::parser::make_ASSIGN_BW_AND(ctx->loc); }
YY_BREAK
case 88:
YY_RULE_SETUP
#line 145 "lexer.lpp"
#line 146 "lexer.lpp"
{ return s1::parser::make_ASSIGN_BW_EXOR(ctx->loc); }
YY_BREAK
case 89:
YY_RULE_SETUP
#line 146 "lexer.lpp"
#line 147 "lexer.lpp"
{ return s1::parser::make_ASSIGN(ctx->loc); }
YY_BREAK
case 90:
YY_RULE_SETUP
#line 147 "lexer.lpp"
#line 148 "lexer.lpp"
{ return s1::parser::make_ADD(ctx->loc); }
YY_BREAK
case 91:
YY_RULE_SETUP
#line 148 "lexer.lpp"
#line 149 "lexer.lpp"
{ return s1::parser::make_SUB(ctx->loc); }
YY_BREAK
case 92:
YY_RULE_SETUP
#line 149 "lexer.lpp"
#line 150 "lexer.lpp"
{ return s1::parser::make_MUL(ctx->loc); }
YY_BREAK
case 93:
YY_RULE_SETUP
#line 150 "lexer.lpp"
#line 151 "lexer.lpp"
{ return s1::parser::make_DIV(ctx->loc); }
YY_BREAK
case 94:
YY_RULE_SETUP
#line 151 "lexer.lpp"
#line 152 "lexer.lpp"
{ return s1::parser::make_MOD(ctx->loc); }
YY_BREAK
case 95:
YY_RULE_SETUP
#line 152 "lexer.lpp"
#line 153 "lexer.lpp"
{ return s1::parser::make_NOT(ctx->loc); }
YY_BREAK
case 96:
YY_RULE_SETUP
#line 153 "lexer.lpp"
#line 154 "lexer.lpp"
{ return s1::parser::make_COMPLEMENT(ctx->loc); }
YY_BREAK
case 97:
YY_RULE_SETUP
#line 154 "lexer.lpp"
#line 155 "lexer.lpp"
{ return s1::parser::make_BITWISE_OR(ctx->loc); }
YY_BREAK
case 98:
YY_RULE_SETUP
#line 155 "lexer.lpp"
#line 156 "lexer.lpp"
{ return s1::parser::make_BITWISE_AND(ctx->loc); }
YY_BREAK
case 99:
YY_RULE_SETUP
#line 156 "lexer.lpp"
#line 157 "lexer.lpp"
{ return s1::parser::make_BITWISE_EXOR(ctx->loc); }
YY_BREAK
case 100:
YY_RULE_SETUP
#line 157 "lexer.lpp"
{ return s1::parser::make_PATH(xsk::utils::string::fordslash(yytext), ctx->loc); }
#line 158 "lexer.lpp"
{ return s1::parser::make_PATH(xsk::gsc::s1::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
YY_BREAK
case 101:
YY_RULE_SETUP
#line 158 "lexer.lpp"
{ return s1::parser::make_IDENTIFIER((std::string(yytext, 3) == "_ID") ? std::string(yytext) : xsk::utils::string::to_lower(yytext), ctx->loc); }
#line 159 "lexer.lpp"
{ return s1::parser::make_IDENTIFIER(xsk::gsc::s1::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
YY_BREAK
case 102:
/* rule 102 can match eol */
YY_RULE_SETUP
#line 159 "lexer.lpp"
{ return s1::parser::make_ISTRING(std::string(yytext).substr(1), ctx->loc); }
#line 160 "lexer.lpp"
{ return s1::parser::make_ISTRING(std::string(++yytext, --yyleng), ctx->loc); }
YY_BREAK
case 103:
/* rule 103 can match eol */
YY_RULE_SETUP
#line 160 "lexer.lpp"
#line 161 "lexer.lpp"
{ return s1::parser::make_STRING(std::string(yytext), ctx->loc); }
YY_BREAK
case 104:
YY_RULE_SETUP
#line 161 "lexer.lpp"
{ return s1::parser::make_COLOR(std::string(yytext).substr(1), ctx->loc); }
#line 162 "lexer.lpp"
{ return s1::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
YY_BREAK
case 105:
YY_RULE_SETUP
#line 162 "lexer.lpp"
{ return s1::parser::make_FLOAT(std::string(yytext), ctx->loc); }
#line 163 "lexer.lpp"
{ return s1::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
YY_BREAK
case 106:
YY_RULE_SETUP
#line 163 "lexer.lpp"
{ return s1::parser::make_INT_OCT(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
#line 164 "lexer.lpp"
{ return s1::parser::make_FLOAT(std::string(yytext), ctx->loc); }
YY_BREAK
case 107:
YY_RULE_SETUP
#line 164 "lexer.lpp"
{ return s1::parser::make_INT_BIN(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
#line 165 "lexer.lpp"
{ return s1::parser::make_INTEGER(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
YY_BREAK
case 108:
YY_RULE_SETUP
#line 165 "lexer.lpp"
{ return s1::parser::make_INT_HEX(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
#line 166 "lexer.lpp"
{ return s1::parser::make_INTEGER(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
YY_BREAK
case 109:
YY_RULE_SETUP
#line 166 "lexer.lpp"
{ return s1::parser::make_INT_DEC(std::string(yytext), ctx->loc); }
YY_BREAK
case YY_STATE_EOF(INITIAL):
#line 167 "lexer.lpp"
{ if(ctx->header_top > 0) s1_pop_header(ctx); else return s1::parser::make_S1EOF(ctx->loc); }
{ return s1::parser::make_INTEGER(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
YY_BREAK
case 110:
/* rule 110 can match eol */
YY_RULE_SETUP
#line 168 "lexer.lpp"
{ throw s1::parser::syntax_error(ctx->loc, "bad token: \'" + std::string(yytext) + "\'"); }
{ return s1::parser::make_INTEGER(std::string(yytext), ctx->loc); }
YY_BREAK
case YY_STATE_EOF(INITIAL):
#line 169 "lexer.lpp"
{ if(ctx->header_top > 0) s1_pop_header(ctx); else return s1::parser::make_S1EOF(ctx->loc); }
YY_BREAK
case 111:
/* rule 111 can match eol */
YY_RULE_SETUP
#line 170 "lexer.lpp"
{ throw s1::parser::syntax_error(ctx->loc, "bad token: \'" + std::string(yytext) + "\'"); }
YY_BREAK
case 112:
YY_RULE_SETUP
#line 172 "lexer.lpp"
ECHO;
YY_BREAK
#line 1834 "lexer.cpp"
#line 1839 "lexer.cpp"
case YY_END_OF_BUFFER:
{
@ -2961,65 +2966,65 @@ void yyfree (void * ptr , yyscan_t yyscanner)
#define YYTABLES_NAME "yytables"
#line 170 "lexer.lpp"
#line 172 "lexer.lpp"
void s1_push_header(xsk::gsc::context* ctx, const std::string& file)
{
try
try
{
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
ctx->header_top++;
ctx->header_top++;
char* buf_data = 0;
size_t buf_size = 0;
char* buf_data = 0;
size_t buf_size = 0;
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
{
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what());
}
@ -3027,9 +3032,9 @@ void s1_push_header(xsk::gsc::context* ctx, const std::string& file)
void s1_pop_header(xsk::gsc::context* ctx)
{
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
}

View File

@ -703,7 +703,7 @@ extern int yylex (yyscan_t yyscanner);
#undef yyTABLES_NAME
#endif
#line 170 "lexer.lpp"
#line 172 "lexer.lpp"
#line 709 "lexer.hpp"

File diff suppressed because it is too large Load Diff

View File

@ -624,10 +624,7 @@ namespace xsk { namespace gsc { namespace s1 {
// "localized string"
// "color"
// "float"
// "int"
// "octal int"
// "binary int"
// "hexadecimal int"
// "integer"
char dummy67[sizeof (std::string)];
};
@ -772,19 +769,16 @@ namespace xsk { namespace gsc { namespace s1 {
ISTRING = 92, // "localized string"
COLOR = 93, // "color"
FLOAT = 94, // "float"
INT_DEC = 95, // "int"
INT_OCT = 96, // "octal int"
INT_BIN = 97, // "binary int"
INT_HEX = 98, // "hexadecimal int"
ADD_ARRAY = 99, // ADD_ARRAY
THEN = 100, // THEN
TERN = 101, // TERN
NEG = 102, // NEG
ANIMREF = 103, // ANIMREF
PREINC = 104, // PREINC
PREDEC = 105, // PREDEC
POSTINC = 106, // POSTINC
POSTDEC = 107 // POSTDEC
INTEGER = 95, // "integer"
ADD_ARRAY = 96, // ADD_ARRAY
THEN = 97, // THEN
TERN = 98, // TERN
NEG = 99, // NEG
ANIMREF = 100, // ANIMREF
PREINC = 101, // PREINC
PREDEC = 102, // PREDEC
POSTINC = 103, // POSTINC
POSTDEC = 104 // POSTDEC
};
/// Backward compatibility alias (Bison 3.6).
typedef token_kind_type yytokentype;
@ -801,7 +795,7 @@ namespace xsk { namespace gsc { namespace s1 {
{
enum symbol_kind_type
{
YYNTOKENS = 108, ///< Number of tokens.
YYNTOKENS = 105, ///< Number of tokens.
S_YYEMPTY = -2,
S_YYEOF = 0, // "end of file"
S_YYerror = 1, // error
@ -898,100 +892,97 @@ namespace xsk { namespace gsc { namespace s1 {
S_ISTRING = 92, // "localized string"
S_COLOR = 93, // "color"
S_FLOAT = 94, // "float"
S_INT_DEC = 95, // "int"
S_INT_OCT = 96, // "octal int"
S_INT_BIN = 97, // "binary int"
S_INT_HEX = 98, // "hexadecimal int"
S_ADD_ARRAY = 99, // ADD_ARRAY
S_THEN = 100, // THEN
S_TERN = 101, // TERN
S_NEG = 102, // NEG
S_ANIMREF = 103, // ANIMREF
S_PREINC = 104, // PREINC
S_PREDEC = 105, // PREDEC
S_POSTINC = 106, // POSTINC
S_POSTDEC = 107, // POSTDEC
S_YYACCEPT = 108, // $accept
S_root = 109, // root
S_program = 110, // program
S_inline = 111, // inline
S_include = 112, // include
S_declaration = 113, // declaration
S_decl_usingtree = 114, // decl_usingtree
S_decl_constant = 115, // decl_constant
S_decl_thread = 116, // decl_thread
S_stmt = 117, // stmt
S_stmt_dev = 118, // stmt_dev
S_stmt_block = 119, // stmt_block
S_stmt_list = 120, // stmt_list
S_stmt_expr = 121, // stmt_expr
S_stmt_call = 122, // stmt_call
S_stmt_assign = 123, // stmt_assign
S_stmt_endon = 124, // stmt_endon
S_stmt_notify = 125, // stmt_notify
S_stmt_wait = 126, // stmt_wait
S_stmt_waittill = 127, // stmt_waittill
S_stmt_waittillmatch = 128, // stmt_waittillmatch
S_stmt_waittillframeend = 129, // stmt_waittillframeend
S_stmt_waitframe = 130, // stmt_waitframe
S_stmt_if = 131, // stmt_if
S_stmt_ifelse = 132, // stmt_ifelse
S_stmt_while = 133, // stmt_while
S_stmt_dowhile = 134, // stmt_dowhile
S_stmt_for = 135, // stmt_for
S_stmt_foreach = 136, // stmt_foreach
S_stmt_switch = 137, // stmt_switch
S_stmt_case = 138, // stmt_case
S_stmt_default = 139, // stmt_default
S_stmt_break = 140, // stmt_break
S_stmt_continue = 141, // stmt_continue
S_stmt_return = 142, // stmt_return
S_stmt_breakpoint = 143, // stmt_breakpoint
S_stmt_prof_begin = 144, // stmt_prof_begin
S_stmt_prof_end = 145, // stmt_prof_end
S_expr = 146, // expr
S_expr_or_empty = 147, // expr_or_empty
S_expr_assign = 148, // expr_assign
S_expr_increment = 149, // expr_increment
S_expr_decrement = 150, // expr_decrement
S_expr_ternary = 151, // expr_ternary
S_expr_binary = 152, // expr_binary
S_expr_primitive = 153, // expr_primitive
S_expr_complement = 154, // expr_complement
S_expr_not = 155, // expr_not
S_expr_call = 156, // expr_call
S_expr_method = 157, // expr_method
S_expr_function = 158, // expr_function
S_expr_pointer = 159, // expr_pointer
S_expr_add_array = 160, // expr_add_array
S_expr_parameters = 161, // expr_parameters
S_expr_arguments = 162, // expr_arguments
S_expr_arguments_no_empty = 163, // expr_arguments_no_empty
S_expr_reference = 164, // expr_reference
S_expr_array = 165, // expr_array
S_expr_field = 166, // expr_field
S_expr_size = 167, // expr_size
S_expr_paren = 168, // expr_paren
S_expr_object = 169, // expr_object
S_expr_thisthread = 170, // expr_thisthread
S_expr_empty_array = 171, // expr_empty_array
S_expr_undefined = 172, // expr_undefined
S_expr_game = 173, // expr_game
S_expr_self = 174, // expr_self
S_expr_anim = 175, // expr_anim
S_expr_level = 176, // expr_level
S_expr_animation = 177, // expr_animation
S_expr_animtree = 178, // expr_animtree
S_expr_identifier = 179, // expr_identifier
S_expr_path = 180, // expr_path
S_expr_istring = 181, // expr_istring
S_expr_string = 182, // expr_string
S_expr_color = 183, // expr_color
S_expr_vector = 184, // expr_vector
S_expr_float = 185, // expr_float
S_expr_integer = 186, // expr_integer
S_expr_false = 187, // expr_false
S_expr_true = 188 // expr_true
S_INTEGER = 95, // "integer"
S_ADD_ARRAY = 96, // ADD_ARRAY
S_THEN = 97, // THEN
S_TERN = 98, // TERN
S_NEG = 99, // NEG
S_ANIMREF = 100, // ANIMREF
S_PREINC = 101, // PREINC
S_PREDEC = 102, // PREDEC
S_POSTINC = 103, // POSTINC
S_POSTDEC = 104, // POSTDEC
S_YYACCEPT = 105, // $accept
S_root = 106, // root
S_program = 107, // program
S_inline = 108, // inline
S_include = 109, // include
S_declaration = 110, // declaration
S_decl_usingtree = 111, // decl_usingtree
S_decl_constant = 112, // decl_constant
S_decl_thread = 113, // decl_thread
S_stmt = 114, // stmt
S_stmt_dev = 115, // stmt_dev
S_stmt_block = 116, // stmt_block
S_stmt_list = 117, // stmt_list
S_stmt_expr = 118, // stmt_expr
S_stmt_call = 119, // stmt_call
S_stmt_assign = 120, // stmt_assign
S_stmt_endon = 121, // stmt_endon
S_stmt_notify = 122, // stmt_notify
S_stmt_wait = 123, // stmt_wait
S_stmt_waittill = 124, // stmt_waittill
S_stmt_waittillmatch = 125, // stmt_waittillmatch
S_stmt_waittillframeend = 126, // stmt_waittillframeend
S_stmt_waitframe = 127, // stmt_waitframe
S_stmt_if = 128, // stmt_if
S_stmt_ifelse = 129, // stmt_ifelse
S_stmt_while = 130, // stmt_while
S_stmt_dowhile = 131, // stmt_dowhile
S_stmt_for = 132, // stmt_for
S_stmt_foreach = 133, // stmt_foreach
S_stmt_switch = 134, // stmt_switch
S_stmt_case = 135, // stmt_case
S_stmt_default = 136, // stmt_default
S_stmt_break = 137, // stmt_break
S_stmt_continue = 138, // stmt_continue
S_stmt_return = 139, // stmt_return
S_stmt_breakpoint = 140, // stmt_breakpoint
S_stmt_prof_begin = 141, // stmt_prof_begin
S_stmt_prof_end = 142, // stmt_prof_end
S_expr = 143, // expr
S_expr_or_empty = 144, // expr_or_empty
S_expr_assign = 145, // expr_assign
S_expr_increment = 146, // expr_increment
S_expr_decrement = 147, // expr_decrement
S_expr_ternary = 148, // expr_ternary
S_expr_binary = 149, // expr_binary
S_expr_primitive = 150, // expr_primitive
S_expr_complement = 151, // expr_complement
S_expr_not = 152, // expr_not
S_expr_call = 153, // expr_call
S_expr_method = 154, // expr_method
S_expr_function = 155, // expr_function
S_expr_pointer = 156, // expr_pointer
S_expr_add_array = 157, // expr_add_array
S_expr_parameters = 158, // expr_parameters
S_expr_arguments = 159, // expr_arguments
S_expr_arguments_no_empty = 160, // expr_arguments_no_empty
S_expr_reference = 161, // expr_reference
S_expr_array = 162, // expr_array
S_expr_field = 163, // expr_field
S_expr_size = 164, // expr_size
S_expr_paren = 165, // expr_paren
S_expr_object = 166, // expr_object
S_expr_thisthread = 167, // expr_thisthread
S_expr_empty_array = 168, // expr_empty_array
S_expr_undefined = 169, // expr_undefined
S_expr_game = 170, // expr_game
S_expr_self = 171, // expr_self
S_expr_anim = 172, // expr_anim
S_expr_level = 173, // expr_level
S_expr_animation = 174, // expr_animation
S_expr_animtree = 175, // expr_animtree
S_expr_identifier = 176, // expr_identifier
S_expr_path = 177, // expr_path
S_expr_istring = 178, // expr_istring
S_expr_string = 179, // expr_string
S_expr_color = 180, // expr_color
S_expr_vector = 181, // expr_vector
S_expr_float = 182, // expr_float
S_expr_integer = 183, // expr_integer
S_expr_false = 184, // expr_false
S_expr_true = 185 // expr_true
};
};
@ -1310,10 +1301,7 @@ namespace xsk { namespace gsc { namespace s1 {
case symbol_kind::S_ISTRING: // "localized string"
case symbol_kind::S_COLOR: // "color"
case symbol_kind::S_FLOAT: // "float"
case symbol_kind::S_INT_DEC: // "int"
case symbol_kind::S_INT_OCT: // "octal int"
case symbol_kind::S_INT_BIN: // "binary int"
case symbol_kind::S_INT_HEX: // "hexadecimal int"
case symbol_kind::S_INTEGER: // "integer"
value.move< std::string > (std::move (that.value));
break;
@ -2582,10 +2570,7 @@ switch (yykind)
case symbol_kind::S_ISTRING: // "localized string"
case symbol_kind::S_COLOR: // "color"
case symbol_kind::S_FLOAT: // "float"
case symbol_kind::S_INT_DEC: // "int"
case symbol_kind::S_INT_OCT: // "octal int"
case symbol_kind::S_INT_BIN: // "binary int"
case symbol_kind::S_INT_HEX: // "hexadecimal int"
case symbol_kind::S_INTEGER: // "integer"
value.template destroy< std::string > ();
break;
@ -2695,7 +2680,7 @@ switch (yykind)
: super_type(token_type (tok), v, l)
#endif
{
S1_ASSERT ((token::PATH <= tok && tok <= token::INT_HEX));
S1_ASSERT ((token::PATH <= tok && tok <= token::INTEGER));
}
};
@ -4173,61 +4158,16 @@ switch (yykind)
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_INT_DEC (std::string v, location_type l)
make_INTEGER (std::string v, location_type l)
{
return symbol_type (token::INT_DEC, std::move (v), std::move (l));
return symbol_type (token::INTEGER, std::move (v), std::move (l));
}
#else
static
symbol_type
make_INT_DEC (const std::string& v, const location_type& l)
make_INTEGER (const std::string& v, const location_type& l)
{
return symbol_type (token::INT_DEC, v, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_INT_OCT (std::string v, location_type l)
{
return symbol_type (token::INT_OCT, std::move (v), std::move (l));
}
#else
static
symbol_type
make_INT_OCT (const std::string& v, const location_type& l)
{
return symbol_type (token::INT_OCT, v, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_INT_BIN (std::string v, location_type l)
{
return symbol_type (token::INT_BIN, std::move (v), std::move (l));
}
#else
static
symbol_type
make_INT_BIN (const std::string& v, const location_type& l)
{
return symbol_type (token::INT_BIN, v, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_INT_HEX (std::string v, location_type l)
{
return symbol_type (token::INT_HEX, std::move (v), std::move (l));
}
#else
static
symbol_type
make_INT_HEX (const std::string& v, const location_type& l)
{
return symbol_type (token::INT_HEX, v, l);
return symbol_type (token::INTEGER, v, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
@ -4709,7 +4649,7 @@ switch (yykind)
/// Constants.
enum
{
yylast_ = 2254, ///< Last index in yytable_.
yylast_ = 2191, ///< Last index in yytable_.
yynnts_ = 81, ///< Number of nonterminal symbols.
yyfinal_ = 21 ///< Termination state number.
};
@ -5020,10 +4960,7 @@ switch (yykind)
case symbol_kind::S_ISTRING: // "localized string"
case symbol_kind::S_COLOR: // "color"
case symbol_kind::S_FLOAT: // "float"
case symbol_kind::S_INT_DEC: // "int"
case symbol_kind::S_INT_OCT: // "octal int"
case symbol_kind::S_INT_BIN: // "binary int"
case symbol_kind::S_INT_HEX: // "hexadecimal int"
case symbol_kind::S_INTEGER: // "integer"
value.copy< std::string > (YY_MOVE (that.value));
break;
@ -5338,10 +5275,7 @@ switch (yykind)
case symbol_kind::S_ISTRING: // "localized string"
case symbol_kind::S_COLOR: // "color"
case symbol_kind::S_FLOAT: // "float"
case symbol_kind::S_INT_DEC: // "int"
case symbol_kind::S_INT_OCT: // "octal int"
case symbol_kind::S_INT_BIN: // "binary int"
case symbol_kind::S_INT_HEX: // "hexadecimal int"
case symbol_kind::S_INTEGER: // "integer"
value.move< std::string > (YY_MOVE (s.value));
break;
@ -5408,7 +5342,7 @@ switch (yykind)
#line 13 "parser.ypp"
} } } // xsk::gsc::s1
#line 5412 "parser.hpp"
#line 5346 "parser.hpp"

View File

@ -9,16 +9,16 @@
namespace xsk::gsc::s1
{
std::unordered_map<std::uint8_t, std::string> opcode_map;
std::unordered_map<std::uint16_t, std::string> function_map;
std::unordered_map<std::uint16_t, std::string> method_map;
std::unordered_map<std::uint16_t, std::string> file_map;
std::unordered_map<std::uint16_t, std::string> token_map;
std::unordered_map<std::string, std::uint8_t> opcode_map_rev;
std::unordered_map<std::string, std::uint16_t> function_map_rev;
std::unordered_map<std::string, std::uint16_t> method_map_rev;
std::unordered_map<std::string, std::uint16_t> file_map_rev;
std::unordered_map<std::string, std::uint16_t> token_map_rev;
std::unordered_map<std::uint8_t, std::string_view> opcode_map;
std::unordered_map<std::uint16_t, std::string_view> function_map;
std::unordered_map<std::uint16_t, std::string_view> method_map;
std::unordered_map<std::uint16_t, std::string_view> file_map;
std::unordered_map<std::uint16_t, std::string_view> token_map;
std::unordered_map<std::string_view, std::uint8_t> opcode_map_rev;
std::unordered_map<std::string_view, std::uint16_t> function_map_rev;
std::unordered_map<std::string_view, std::uint16_t> method_map_rev;
std::unordered_map<std::string_view, std::uint16_t> file_map_rev;
std::unordered_map<std::string_view, std::uint16_t> token_map_rev;
auto resolver::opcode_id(const std::string& name) -> std::uint8_t
{
@ -38,7 +38,7 @@ auto resolver::opcode_name(std::uint8_t id) -> std::string
if (itr != opcode_map.end())
{
return itr->second;
return std::string(itr->second);
}
throw error(utils::string::va("Couldn't resolve opcode name for id '0x%hhX'!", id));
@ -46,6 +46,11 @@ auto resolver::opcode_name(std::uint8_t id) -> std::string
auto resolver::function_id(const std::string& name) -> std::uint16_t
{
if(name.starts_with("_func_"))
{
return std::stoul(name.substr(6), nullptr, 16);
}
const auto itr = function_map_rev.find(name);
if (itr != function_map_rev.end())
@ -62,14 +67,19 @@ auto resolver::function_name(std::uint16_t id) -> std::string
if (itr != function_map.end())
{
return itr->second;
return std::string(itr->second);
}
throw error(utils::string::va("Couldn't resolve builtin function name for id '%i'!", id));
return utils::string::va("_func_%04X", id);
}
auto resolver::method_id(const std::string& name) -> std::uint16_t
{
if(name.starts_with("_meth_"))
{
return std::stoul(name.substr(6), nullptr, 16);
}
const auto itr = method_map_rev.find(name);
if (itr != method_map_rev.end())
@ -86,14 +96,19 @@ auto resolver::method_name(std::uint16_t id) -> std::string
if (itr != method_map.end())
{
return itr->second;
return std::string(itr->second);
}
throw error(utils::string::va("Couldn't resolve builtin method name for id '%i'!", id));
return utils::string::va("_meth_%04X", id);
}
auto resolver::file_id(const std::string& name) -> std::uint16_t
{
if(name.starts_with("_id_"))
{
return std::stoul(name.substr(4), nullptr, 16);
}
const auto itr = file_map_rev.find(name);
if (itr != file_map_rev.end())
@ -110,14 +125,19 @@ auto resolver::file_name(std::uint16_t id) -> std::string
if (itr != file_map.end())
{
return itr->second;
return std::string(itr->second);
}
return utils::string::va("_ID%i", id);
return utils::string::va("_id_%04X", id);
}
auto resolver::token_id(const std::string& name) -> std::uint16_t
{
if(name.starts_with("_id_"))
{
return std::stoul(name.substr(4), nullptr, 16);
}
const auto itr = token_map_rev.find(name);
if (itr != token_map_rev.end())
@ -134,14 +154,16 @@ auto resolver::token_name(std::uint16_t id) -> std::string
if (itr != token_map.end())
{
return itr->second;
return std::string(itr->second);
}
return utils::string::va("_ID%i", id);
return utils::string::va("_id_%04X", id);
}
auto resolver::find_function(const std::string& name) -> bool
{
if(name.starts_with("_func_")) return true;
const auto itr = function_map_rev.find(name);
if (itr != function_map_rev.end())
@ -154,6 +176,8 @@ auto resolver::find_function(const std::string& name) -> bool
auto resolver::find_method(const std::string& name) -> bool
{
if(name.starts_with("_meth_")) return true;
const auto itr = method_map_rev.find(name);
if (itr != method_map_rev.end())
@ -164,165 +188,183 @@ auto resolver::find_method(const std::string& name) -> bool
return false;
}
const std::array<pair_8C, 154> opcode_list
auto resolver::make_token(std::string_view str) -> std::string
{
if(str.starts_with("_id_") || str.starts_with("_func_") || str.starts_with("_meth_"))
{
return std::string(str);
}
auto data = std::string(str.begin(), str.end());
for (std::size_t i = 0; i < data.size(); i++)
{
data[i] = std::tolower(str[i]);
if (data[i] == '\\') data[i] = '/';
}
return data;
}
const std::array<std::pair<std::uint8_t, const char*>, 154> opcode_list
{{
{ std::uint8_t(opcode::OP_End),"END" },
{ std::uint8_t(opcode::OP_Return),"RETN" },
{ std::uint8_t(opcode::OP_GetByte),"GET_BYTE" },
{ std::uint8_t(opcode::OP_GetNegByte),"GET_NBYTE" },
{ std::uint8_t(opcode::OP_GetUnsignedShort),"GET_USHORT" },
{ std::uint8_t(opcode::OP_GetNegUnsignedShort),"GET_NUSHORT" },
{ std::uint8_t(opcode::OP_GetInteger),"GET_INT" },
{ std::uint8_t(opcode::OP_GetBuiltinFunction),"GET_BUILTIN_FUNC" },
{ std::uint8_t(opcode::OP_GetBuiltinMethod),"GET_BUILTIN_METHOD" },
{ std::uint8_t(opcode::OP_GetFloat),"GET_FLOAT" },
{ std::uint8_t(opcode::OP_GetString),"GET_STRING" },
{ std::uint8_t(opcode::OP_GetUndefined),"GET_UNDEFINED" },
{ std::uint8_t(opcode::OP_GetZero),"GET_ZERO" },
{ std::uint8_t(opcode::OP_waittillFrameEnd),"WAITTILLFRAMEEND" },
{ std::uint8_t(opcode::OP_CreateLocalVariable),"CREATE_LOCAL_VARIABLE" },
{ std::uint8_t(opcode::OP_RemoveLocalVariables),"REMOVE_LOCAL_VARIABLES" },
{ std::uint8_t(opcode::OP_EvalLocalVariableCached0),"EVAL_LOCAL_VARIABLE_CACHED0" },
{ std::uint8_t(opcode::OP_EvalLocalVariableCached1),"EVAL_LOCAL_VARIABLE_CACHED1" },
{ std::uint8_t(opcode::OP_EvalLocalVariableCached2),"EVAL_LOCAL_VARIABLE_CACHED2" },
{ std::uint8_t(opcode::OP_EvalLocalVariableCached3),"EVAL_LOCAL_VARIABLE_CACHED3" },
{ std::uint8_t(opcode::OP_EvalLocalVariableCached4),"EVAL_LOCAL_VARIABLE_CACHED4" },
{ std::uint8_t(opcode::OP_EvalLocalVariableCached5),"EVAL_LOCAL_VARIABLE_CACHED5" },
{ std::uint8_t(opcode::OP_EvalLocalVariableCached),"EVAL_LOCAL_VARIABLE_CACHED" },
{ std::uint8_t(opcode::OP_EvalLocalArrayCached),"EVAL_LOCAL_ARRAY_CACHED" },
{ std::uint8_t(opcode::OP_EvalArray),"EVAL_ARRAY" },
{ std::uint8_t(opcode::OP_EvalNewLocalArrayRefCached0),"EVAL_NEW_LOCAL_ARRAY_REF_CACHED0" },
{ std::uint8_t(opcode::OP_EvalLocalArrayRefCached0),"EVAL_LOCAL_ARRAY_REF_CACHED0" },
{ std::uint8_t(opcode::OP_EvalLocalArrayRefCached),"EVAL_LOCAL_ARRAY_REF_CACHED" },
{ std::uint8_t(opcode::OP_EvalArrayRef),"EVAL_ARRAY_REF" },
{ std::uint8_t(opcode::OP_ClearArray),"CLEAR_ARRAY" },
{ std::uint8_t(opcode::OP_EmptyArray),"EMPTY_ARRAY" },
{ std::uint8_t(opcode::OP_AddArray),"ADD_ARRAY" },
{ std::uint8_t(opcode::OP_PreScriptCall),"PRE_CALL" },
{ std::uint8_t(opcode::OP_ScriptLocalFunctionCall2),"CALL_LOCAL_FUNC2" },
{ std::uint8_t(opcode::OP_ScriptLocalFunctionCall),"CALL_LOCAL_FUNC" },
{ std::uint8_t(opcode::OP_ScriptLocalMethodCall),"CALL_LOCAL_METHOD" },
{ std::uint8_t(opcode::OP_ScriptLocalThreadCall),"CALL_LOCAL_FUNC_THREAD" },
{ std::uint8_t(opcode::OP_ScriptLocalChildThreadCall),"CALL_LOCAL_FUNC_CHILD_THREAD" },
{ std::uint8_t(opcode::OP_ScriptLocalMethodThreadCall),"CALL_LOCAL_METHOD_THREAD" },
{ std::uint8_t(opcode::OP_ScriptLocalMethodChildThreadCall),"CALL_LOCAL_METHOD_CHILD_THREAD" },
{ std::uint8_t(opcode::OP_ScriptFarFunctionCall2),"CALL_FAR_FUNC2" },
{ std::uint8_t(opcode::OP_ScriptFarFunctionCall),"CALL_FAR_FUNC" },
{ std::uint8_t(opcode::OP_ScriptFarMethodCall),"CALL_FAR_METHOD" },
{ std::uint8_t(opcode::OP_ScriptFarThreadCall),"CALL_FAR_FUNC_THREAD" },
{ std::uint8_t(opcode::OP_ScriptFarChildThreadCall),"CALL_FAR_FUNC_CHILD_THREAD"},
{ std::uint8_t(opcode::OP_ScriptFarMethodThreadCall),"CALL_FAR_METHOD_THEAD" },
{ std::uint8_t(opcode::OP_ScriptFarMethodChildThreadCall),"CALL_FAR_METHOD_CHILD_THEAD" },
{ std::uint8_t(opcode::OP_ScriptFunctionCallPointer),"CALL_FUNC_POINTER" },
{ std::uint8_t(opcode::OP_ScriptMethodCallPointer),"CALL_METHOD_POINTER" },
{ std::uint8_t(opcode::OP_ScriptThreadCallPointer),"CALL_FUNC_THREAD_POINTER" },
{ std::uint8_t(opcode::OP_ScriptChildThreadCallPointer),"CALL_FUNC_CHILD_THREAD_POINTER" },
{ std::uint8_t(opcode::OP_ScriptMethodThreadCallPointer),"CALL_METHOD_THREAD_POINTER" },
{ std::uint8_t(opcode::OP_ScriptMethodChildThreadCallPointer),"CALL_METHOD_CHILD_THREAD_POINTER" },
{ std::uint8_t(opcode::OP_CallBuiltinPointer),"CALL_BUILTIN_FUNC_POINTER" },
{ std::uint8_t(opcode::OP_CallBuiltinMethodPointer),"CALL_BUILTIN_METHOD_POINTER" },
{ std::uint8_t(opcode::OP_GetIString),"GET_ISTRING" },
{ std::uint8_t(opcode::OP_GetVector),"GET_VECTOR" },
{ std::uint8_t(opcode::OP_GetLevelObject),"GET_LEVEL_OBJ" },
{ std::uint8_t(opcode::OP_GetAnimObject),"GET_ANIM_OBJ" },
{ std::uint8_t(opcode::OP_GetSelf),"GET_SELF" },
{ std::uint8_t(opcode::OP_GetThisthread),"GET_THISTHREAD" },
{ std::uint8_t(opcode::OP_GetLevel),"GET_LEVEL" },
{ std::uint8_t(opcode::OP_GetGame),"GET_GAME" },
{ std::uint8_t(opcode::OP_GetAnim),"GET_ANIM" },
{ std::uint8_t(opcode::OP_GetAnimation),"GET_ANIMATION" },
{ std::uint8_t(opcode::OP_GetGameRef),"GET_GAME_REF" },
{ std::uint8_t(opcode::OP_inc),"INC" },
{ std::uint8_t(opcode::OP_dec),"DEC" },
{ std::uint8_t(opcode::OP_bit_or),"BIT_OR" },
{ std::uint8_t(opcode::OP_JumpOnFalseExpr),"JMP_EXPR_FALSE" },
{ std::uint8_t(opcode::OP_bit_ex_or),"BIT_EXOR" },
{ std::uint8_t(opcode::OP_bit_and),"BIT_AND" },
{ std::uint8_t(opcode::OP_equality),"EQUALITY" },
{ std::uint8_t(opcode::OP_inequality),"INEQUALITY" },
{ std::uint8_t(opcode::OP_less),"LESS" },
{ std::uint8_t(opcode::OP_greater),"GREATER" },
{ std::uint8_t(opcode::OP_JumpOnTrueExpr),"JMP_EXPR_TRUE" },
{ std::uint8_t(opcode::OP_less_equal),"LESSEQUAL" },
{ std::uint8_t(opcode::OP_jumpback),"JMP_BACK" },
{ std::uint8_t(opcode::OP_waittillmatch2),"WAITTILLMATCH2" },
{ std::uint8_t(opcode::OP_waittill),"WAITTILL" },
{ std::uint8_t(opcode::OP_notify),"NOTIFY" },
{ std::uint8_t(opcode::OP_endon),"ENDON" },
{ std::uint8_t(opcode::OP_voidCodepos),"VOIDCODEPOS" },
{ std::uint8_t(opcode::OP_switch),"SWITCH" },
{ std::uint8_t(opcode::OP_endswitch),"ENDSWITCH" },
{ std::uint8_t(opcode::OP_vector),"VECTOR" },
{ std::uint8_t(opcode::OP_JumpOnFalse),"JMP_FALSE" },
{ std::uint8_t(opcode::OP_greater_equal),"GREATEREQUAL" },
{ std::uint8_t(opcode::OP_shift_left),"SHIFT_LEFT" },
{ std::uint8_t(opcode::OP_shift_right),"SHIFT_RIGHT" },
{ std::uint8_t(opcode::OP_plus),"PLUS" },
{ std::uint8_t(opcode::OP_jump),"JMP" },
{ std::uint8_t(opcode::OP_minus),"MINUS" },
{ std::uint8_t(opcode::OP_multiply),"MULT" },
{ std::uint8_t(opcode::OP_divide),"DIV" },
{ std::uint8_t(opcode::OP_mod),"MOD" },
{ std::uint8_t(opcode::OP_JumpOnTrue),"JMP_TRUE" },
{ std::uint8_t(opcode::OP_size),"SIZE" },
{ std::uint8_t(opcode::OP_waittillmatch),"WAITTILLMATCH" },
{ std::uint8_t(opcode::OP_GetLocalFunction),"GET_LOCAL_FUNC" },
{ std::uint8_t(opcode::OP_GetFarFunction),"GET_FAR_FUNC" },
{ std::uint8_t(opcode::OP_GetSelfObject),"GET_SELF_OBJ" },
{ std::uint8_t(opcode::OP_EvalLevelFieldVariable),"EVAL_LEVEL_FIELD_VARIABLE" },
{ std::uint8_t(opcode::OP_EvalAnimFieldVariable),"EVAL_ANIM_FIELD_VARIABLE" },
{ std::uint8_t(opcode::OP_EvalSelfFieldVariable),"EVAL_SELF_FIELD_VARIABLE" },
{ std::uint8_t(opcode::OP_EvalFieldVariable),"EVAL_FIELD_VARIABLE" },
{ std::uint8_t(opcode::OP_EvalLevelFieldVariableRef),"EVAL_LEVEL_FIELD_VARIABLE_REF" },
{ std::uint8_t(opcode::OP_EvalAnimFieldVariableRef),"EVAL_ANIM_FIELD_VARIABLE_REF" },
{ std::uint8_t(opcode::OP_EvalSelfFieldVariableRef),"EVAL_SELF_FIELD_VARIABLE_REF" },
{ std::uint8_t(opcode::OP_EvalFieldVariableRef),"EVAL_FIELD_VARIABLE_REF" },
{ std::uint8_t(opcode::OP_ClearFieldVariable),"CLEAR_FIELD_VARIABLE" },
{ std::uint8_t(opcode::OP_SafeCreateVariableFieldCached),"SAFE_CREATE_VARIABLE_FIELD_CACHED" },
{ std::uint8_t(opcode::OP_SafeSetVariableFieldCached0),"SAFE_SET_VARIABLE_FIELD_CACHED0" },
{ std::uint8_t(opcode::OP_SafeSetVariableFieldCached),"SAFE_SET_VARIABLE_FIELD_CACHED" },
{ std::uint8_t(opcode::OP_SafeSetWaittillVariableFieldCached),"SAFE_SET_WAITTILL_VARIABLE_FIELD_CACHED" },
{ std::uint8_t(opcode::OP_GetAnimTree),"GET_ANIMTREE" },
{ std::uint8_t(opcode::OP_clearparams),"CLEAR_PARAMS" },
{ std::uint8_t(opcode::OP_checkclearparams),"CHECK_CLEAR_PARAMS" },
{ std::uint8_t(opcode::OP_EvalLocalVariableRefCached0),"EVAL_LOCAL_VARIABLE_REF_CACHED0" },
{ std::uint8_t(opcode::OP_EvalNewLocalVariableRefCached0),"EVAL_NEW_LOCAL_VARIABLE_REF_CACHED0" },
{ std::uint8_t(opcode::OP_EvalLocalVariableRefCached),"EVAL_LOCAL_VARIABLE_REF_CACHED" },
{ std::uint8_t(opcode::OP_SetLevelFieldVariableField),"SET_LEVEL_FIELD_VARIABLE_FIELD" },
{ std::uint8_t(opcode::OP_SetVariableField),"SET_VARIABLE_FIELD" },
{ std::uint8_t(opcode::OP_ClearVariableField),"CLEAR_VARIABLE_FIELD" },
{ std::uint8_t(opcode::OP_SetAnimFieldVariableField),"SET_ANIM_FIELD_VARIABLE_FIELD" },
{ std::uint8_t(opcode::OP_SetSelfFieldVariableField),"SET_SELF_FIELD_VARIABLE_FIELD" },
{ std::uint8_t(opcode::OP_SetLocalVariableFieldCached0),"SET_LOCAL_VARIABLE_FIELD_CACHED0" },
{ std::uint8_t(opcode::OP_SetNewLocalVariableFieldCached0),"SET_NEW_LOCAL_VARIABLE_FIELD_CACHED0" },
{ std::uint8_t(opcode::OP_SetLocalVariableFieldCached),"SET_LOCAL_VARIABLE_FIELD_CACHED" },
{ std::uint8_t(opcode::OP_ClearLocalVariableFieldCached),"CLEAR_LOCAL_VARIABLE_FIELD_CACHED" },
{ std::uint8_t(opcode::OP_ClearLocalVariableFieldCached0),"CLEAR_LOCAL_VARIABLE_FIELD_CACHED0" },
{ std::uint8_t(opcode::OP_CallBuiltin0),"CALL_BUILTIN_FUNC_0" },
{ std::uint8_t(opcode::OP_CallBuiltin1),"CALL_BUILTIN_FUNC_1" },
{ std::uint8_t(opcode::OP_CallBuiltin2),"CALL_BUILTIN_FUNC_2" },
{ std::uint8_t(opcode::OP_CallBuiltin3),"CALL_BUILTIN_FUNC_3" },
{ std::uint8_t(opcode::OP_CallBuiltin4),"CALL_BUILTIN_FUNC_4" },
{ std::uint8_t(opcode::OP_CallBuiltin5),"CALL_BUILTIN_FUNC_5" },
{ std::uint8_t(opcode::OP_CallBuiltin),"CALL_BUILTIN_FUNC" },
{ std::uint8_t(opcode::OP_CallBuiltinMethod0),"CALL_BUILTIN_METHOD_0" },
{ std::uint8_t(opcode::OP_CallBuiltinMethod1),"CALL_BUILTIN_METHOD_1" },
{ std::uint8_t(opcode::OP_CallBuiltinMethod2),"CALL_BUILTIN_METHOD_2" },
{ std::uint8_t(opcode::OP_CallBuiltinMethod3),"CALL_BUILTIN_METHOD_3" },
{ std::uint8_t(opcode::OP_CallBuiltinMethod4),"CALL_BUILTIN_METHOD_4" },
{ std::uint8_t(opcode::OP_CallBuiltinMethod5),"CALL_BUILTIN_METHOD_5" },
{ std::uint8_t(opcode::OP_CallBuiltinMethod),"CALL_BUILTIN_METHOD" },
{ std::uint8_t(opcode::OP_wait),"WAIT" },
{ std::uint8_t(opcode::OP_DecTop),"DEC_TOP" },
{ std::uint8_t(opcode::OP_CastFieldObject),"CAST_FIELD_OBJ" },
{ std::uint8_t(opcode::OP_EvalLocalVariableObjectCached),"EVAL_LOCAL_VARIABLE_OBJECT_CACHED" },
{ std::uint8_t(opcode::OP_CastBool),"CAST_BOOL" },
{ std::uint8_t(opcode::OP_BoolNot),"BOOL_NOT" },
{ std::uint8_t(opcode::OP_BoolComplement),"BOOL_COMPLEMENT" },
{ std::uint8_t(opcode::OP_waitFrame), "WAITFRAME" },
{ 0x17, "SET_NEW_LOCAL_VARIABLE_FIELD_CACHED0" },
{ 0x18, "EVAL_SELF_FIELD_VARIABLE" },
{ 0x19, "RETN" },
{ 0x1A, "CALL_BUILTIN_FUNC_0" },
{ 0x1B, "CALL_BUILTIN_FUNC_1" },
{ 0x1C, "CALL_BUILTIN_FUNC_2" },
{ 0x1D, "CALL_BUILTIN_FUNC_3" },
{ 0x1E, "CALL_BUILTIN_FUNC_4" },
{ 0x1F, "CALL_BUILTIN_FUNC_5" },
{ 0x20, "CALL_BUILTIN_FUNC" },
{ 0x21, "BOOL_NOT" },
{ 0x22, "CALL_FAR_METHOD_THEAD" },
{ 0x23, "JMP_EXPR_TRUE" },
{ 0x24, "SET_LEVEL_FIELD_VARIABLE_FIELD" },
{ 0x25, "CAST_BOOL" },
{ 0x26, "EVAL_NEW_LOCAL_ARRAY_REF_CACHED0" },
{ 0x27, "CALL_BUILTIN_FUNC_POINTER" },
{ 0x28, "INEQUALITY" },
{ 0x29, "GET_THISTHREAD" },
{ 0x2A, "CLEAR_FIELD_VARIABLE" },
{ 0x2B, "GET_FLOAT" },
{ 0x2C, "SAFE_CREATE_VARIABLE_FIELD_CACHED" },
{ 0x2D, "CALL_FAR_FUNC2" },
{ 0x2E, "CALL_FAR_FUNC" },
{ 0x2F, "CALL_FAR_FUNC_CHILD_THREAD" },
{ 0x30, "CLEAR_LOCAL_VARIABLE_FIELD_CACHED0" },
{ 0x31, "CLEAR_LOCAL_VARIABLE_FIELD_CACHED" },
{ 0x32, "CHECK_CLEAR_PARAMS" },
{ 0x33, "CAST_FIELD_OBJ" },
{ 0x34, "END" },
{ 0x35, "SIZE" },
{ 0x36, "EMPTY_ARRAY" },
{ 0x37, "BIT_AND" },
{ 0x38, "LESSEQUAL" },
{ 0x39, "VOIDCODEPOS" },
{ 0x3A, "CALL_METHOD_THREAD_POINTER" },
{ 0x3B, "ENDSWITCH" },
{ 0x3C, "CLEAR_VARIABLE_FIELD" },
{ 0x3D, "DIV" },
{ 0x3E, "CALL_FAR_METHOD_CHILD_THEAD" },
{ 0x3F, "GET_USHORT" },
{ 0x40, "JMP_TRUE" },
{ 0x41, "GET_SELF" },
{ 0x42, "CALL_FAR_FUNC_THREAD" },
{ 0x43, "CALL_LOCAL_FUNC_THREAD" },
{ 0x44, "SET_LOCAL_VARIABLE_FIELD_CACHED0" },
{ 0x45, "SET_LOCAL_VARIABLE_FIELD_CACHED" },
{ 0x46, "PLUS" },
{ 0x47, "BOOL_COMPLEMENT" },
{ 0x48, "CALL_METHOD_POINTER" },
{ 0x49, "INC" },
{ 0x4A, "REMOVE_LOCAL_VARIABLES" },
{ 0x4B, "JMP_EXPR_FALSE" },
{ 0x4C, "SWITCH" },
{ 0x4D, "CLEAR_PARAMS" },
{ 0x4E, "EVAL_LOCAL_VARIABLE_REF_CACHED0" },
{ 0x4F, "EVAL_LOCAL_VARIABLE_REF_CACHED" },
{ 0x50, "CALL_LOCAL_METHOD" },
{ 0x51, "EVAL_FIELD_VARIABLE" },
{ 0x52, "EVAL_FIELD_VARIABLE_REF" },
{ 0x53, "GET_STRING" },
{ 0x54, "CALL_FUNC_POINTER" },
{ 0x55, "EVAL_LEVEL_FIELD_VARIABLE" },
{ 0x56, "GET_VECTOR" },
{ 0x57, "ENDON" },
{ 0x58, "GREATEREQUAL" },
{ 0x59, "GET_SELF_OBJ" },
{ 0x5A, "SET_ANIM_FIELD_VARIABLE_FIELD" },
{ 0x5B, "SET_VARIABLE_FIELD" },
{ 0x5C, "CALL_LOCAL_FUNC2" },
{ 0x5D, "CALL_LOCAL_FUNC" },
{ 0x5E, "EVAL_LOCAL_ARRAY_REF_CACHED0" },
{ 0x5F, "EVAL_LOCAL_ARRAY_REF_CACHED" },
{ 0x60, "GET_FAR_FUNC" },
{ 0x61, "LESS" },
{ 0x62, "GET_GAME_REF" },
{ 0x63, "WAITFRAME" },
{ 0x64, "WAITTILLFRAMEEND" },
{ 0x65, "SAFE_SET_VARIABLE_FIELD_CACHED0" },
{ 0x66, "SAFE_SET_VARIABLE_FIELD_CACHED" },
{ 0x67, "CALL_METHOD_CHILD_THREAD_POINTER" },
{ 0x68, "GET_LEVEL" },
{ 0x69, "NOTIFY" },
{ 0x6A, "DEC_TOP" },
{ 0x6B, "SHIFT_LEFT" },
{ 0x6C, "CALL_LOCAL_METHOD_THREAD" },
{ 0x6D, "CALL_LOCAL_METHOD_CHILD_THREAD" },
{ 0x6E, "GREATER" },
{ 0x6F, "EVAL_LOCAL_VARIABLE_CACHED0" },
{ 0x70, "EVAL_LOCAL_VARIABLE_CACHED1" },
{ 0x71, "EVAL_LOCAL_VARIABLE_CACHED2" },
{ 0x72, "EVAL_LOCAL_VARIABLE_CACHED3" },
{ 0x73, "EVAL_LOCAL_VARIABLE_CACHED4" },
{ 0x74, "EVAL_LOCAL_VARIABLE_CACHED5" },
{ 0x75, "EVAL_LOCAL_VARIABLE_CACHED" },
{ 0x76, "SAFE_SET_WAITTILL_VARIABLE_FIELD_CACHED" },
{ 0x77, "JMP" },
{ 0x78, "CALL_FUNC_THREAD_POINTER" },
{ 0x79, "GET_ZERO" },
{ 0x7A, "WAIT" },
{ 0x7B, "MINUS" },
{ 0x7C, "SET_SELF_FIELD_VARIABLE_FIELD" },
{ 0x7D, "EVAL_NEW_LOCAL_VARIABLE_REF_CACHED0" },
{ 0x7E, "MULT" },
{ 0x7F, "CREATE_LOCAL_VARIABLE" },
{ 0x80, "CALL_LOCAL_FUNC_CHILD_THREAD" },
{ 0x81, "GET_INT" },
{ 0x82, "MOD" },
{ 0x83, "EVAL_ANIM_FIELD_VARIABLE_REF" },
{ 0x84, "GET_BUILTIN_FUNC" },
{ 0x85, "GET_GAME" },
{ 0x86, "WAITTILL" },
{ 0x87, "DEC" },
{ 0x88, "EVAL_LOCAL_VARIABLE_OBJECT_CACHED" },
{ 0x89, "PRE_CALL" },
{ 0x8A, "GET_ANIM" },
{ 0x8B, "GET_UNDEFINED" },
{ 0x8C, "EVAL_LEVEL_FIELD_VARIABLE_REF" },
{ 0x8D, "GET_ANIM_OBJ" },
{ 0x8E, "GET_LEVEL_OBJ" },
{ 0x8F, "BIT_EXOR" },
{ 0x90, "EQUALITY" },
{ 0x91, "CLEAR_ARRAY" },
{ 0x92, "JMP_BACK" },
{ 0x93, "GET_ANIMATION" },
{ 0x94, "EVAL_ANIM_FIELD_VARIABLE" },
{ 0x95, "GET_ANIMTREE" },
{ 0x96, "GET_ISTRING" },
{ 0x97, "EVAL_ARRAY_REF" },
{ 0x98, "EVAL_SELF_FIELD_VARIABLE_REF" },
{ 0x99, "GET_NBYTE" },
{ 0x9A, "GET_BUILTIN_METHOD" },
{ 0x9B, "CALL_BUILTIN_METHOD_POINTER" },
{ 0x9C, "EVAL_ARRAY" },
{ 0x9D, "VECTOR" },
{ 0x9E, "CALL_FAR_METHOD" },
{ 0x9F, "EVAL_LOCAL_ARRAY_CACHED" },
{ 0xA0, "GET_BYTE" },
{ 0xA1, "CALL_FUNC_CHILD_THREAD_POINTER" },
{ 0xA2, "BIT_OR" },
{ 0xA3, "ADD_ARRAY" },
{ 0xA4, "WAITTILLMATCH2" },
{ 0xA5, "WAITTILLMATCH" },
{ 0xA6, "GET_LOCAL_FUNC" },
{ 0xA7, "GET_NUSHORT" },
{ 0xA8, "SHIFT_RIGHT" },
{ 0xA9, "CALL_BUILTIN_METHOD_0" },
{ 0xAA, "CALL_BUILTIN_METHOD_1" },
{ 0xAB, "CALL_BUILTIN_METHOD_2" },
{ 0xAC, "CALL_BUILTIN_METHOD_3" },
{ 0xAD, "CALL_BUILTIN_METHOD_4" },
{ 0xAE, "CALL_BUILTIN_METHOD_5" },
{ 0xAF, "CALL_BUILTIN_METHOD" },
{ 0xB0, "JMP_FALSE" },
}};
const std::array<pair_16C, 735> function_list
const std::array<std::pair<std::uint16_t, const char*>, 735> function_list
{{
{ 0x001, "precacheturret" },
{ 0x002, "getweaponarray" },
@ -511,7 +553,7 @@ const std::array<pair_16C, 735> function_list
{ 0x0B9, "int" },
{ 0x0BA, "float" },
{ 0x0BB, "abs" },
{ 0x0BC, "min" }, // check!
{ 0x0BC, "min" },
{ 0x0BD, "objective_additionalcurrent" },
{ 0x0BE, "objective_ring" },
{ 0x0BF, "objective_setpointertextoverride" },
@ -545,7 +587,7 @@ const std::array<pair_16C, 735> function_list
{ 0x0DB, "_func_0DB" }, // SP 0x14025BF20
{ 0x0DC, "_func_0DC" }, // empty
{ 0x0DD, "_func_0DD" }, // SP 0x14025C0E0
{ 0x0DE, "max" }, // check!
{ 0x0DE, "max" },
{ 0x0DF, "floor" },
{ 0x0E0, "ceil" },
{ 0x0E1, "exp" },
@ -1061,7 +1103,7 @@ const std::array<pair_16C, 735> function_list
{ 0x2DF, "_func_2DF" }, // MP 0x140331E00
}};
const std::array<pair_16C, 1389> method_list
const std::array<std::pair<std::uint16_t, const char*>, 1389> method_list
{{
{ 0x8000, "_meth_8000" }, // SP 0x140243FC0, MP 0x140321BF0
{ 0x8001, "_meth_8001" }, // SP 0x14025D290
@ -2454,7 +2496,7 @@ const std::array<pair_16C, 1389> method_list
{ 0x856C, "_meth_856C" }, // MP 0x140333710
}};
const std::array<pair_16C, 13> file_list
const std::array<std::pair<std::uint16_t, const char*>, 13> file_list
{{
{ 0x053D, "codescripts/delete" },
{ 0x053E, "codescripts/struct" },
@ -2469,11 +2511,15 @@ const std::array<pair_16C, 13> file_list
{ 42735, "maps/createart/mp_vlobby_room_art" },
{ 42736, "maps/createart/mp_vlobby_room_fog" },
{ 42737, "maps/createart/mp_vlobby_room_fog_hdr" },
}};
const std::array<pair_16C, 25> token_list
const std::array<std::pair<std::uint16_t, const char*>, 30> token_list
{{
{ 0x00, "" },
{ 0x01, "pl#" },
{ 0x02, "-" },
{ 0x03, "radius`" },
{ 0x04, "note:" },
{ 180, "CodeCallback_BulletHitEntity" },
{ 181, "CodeCallback_CodeEndGame" },
{ 182, "CodeCallback_EntityDamage" },
@ -2524,32 +2570,32 @@ struct __init__
for(const auto& entry : opcode_list)
{
opcode_map.insert({ entry.key, entry.value });
opcode_map_rev.insert({ entry.value, entry.key });
opcode_map.insert({ entry.first, entry.second });
opcode_map_rev.insert({ entry.second, entry.first });
}
for(const auto& entry : function_list)
{
function_map.insert({ entry.key, entry.value });
function_map_rev.insert({ utils::string::to_lower(entry.value), entry.key });
function_map.insert({ entry.first, entry.second });
function_map_rev.insert({ entry.second, entry.first });
}
for(const auto& entry : method_list)
{
method_map.insert({ entry.key, entry.value });
method_map_rev.insert({ utils::string::to_lower(entry.value), entry.key });
method_map.insert({ entry.first, entry.second });
method_map_rev.insert({ entry.second, entry.first });
}
for(const auto& entry : file_list)
{
file_map.insert({ entry.key, entry.value });
file_map_rev.insert({ utils::string::to_lower(entry.value), entry.key });
file_map.insert({ entry.first, entry.second });
file_map_rev.insert({ entry.second, entry.first });
}
for(const auto& entry : token_list)
{
token_map.insert({ entry.key, entry.value });
token_map_rev.insert({ utils::string::to_lower(entry.value), entry.key });
token_map.insert({ entry.first, entry.second });
token_map_rev.insert({ entry.second, entry.first });
}
}
};

View File

@ -28,6 +28,8 @@ public:
static auto find_function(const std::string& name) -> bool;
static auto find_method(const std::string& name) -> bool;
static auto make_token(std::string_view str) -> std::string;
};
} // namespace xsk::gsc::s1

View File

@ -16,6 +16,8 @@
namespace xsk::gsc::s1
{
constexpr std::uint16_t max_string_id = 0xA7DC;
enum class opcode : std::uint8_t
{
OP_SetNewLocalVariableFieldCached0 = 0x17,