diff --git a/cpp/src/codegen.cpp b/cpp/src/codegen.cpp index a592661..6bf10cd 100644 --- a/cpp/src/codegen.cpp +++ b/cpp/src/codegen.cpp @@ -975,11 +975,12 @@ namespace code value function_call(const data& d, ast::function_call payload) { const semal::function_t* func = d.state.try_find_function(payload.function_name); + d.ctx.assert_that(func != nullptr, error_code::codegen, "call to undefined function \"{}\"", payload.function_name); + d.ctx.assert_that(!func->is_method, error_code::codegen, "call to method as \"{}.{}\" if it were a free function.", func->method_owner_struct_name, payload.function_name); if(func->is_builtin) { return codegen_builtin(d, payload, try_find_builtin(payload.function_name)); } - d.ctx.assert_that(func != nullptr, error_code::codegen, "call to undefined function \"{}\"", payload.function_name); auto* llvm_func = static_cast(func->userdata); d.ctx.assert_that(llvm_func != nullptr, error_code::ice, "function \"{}\" had a nullptr userdata, implying it has not been codegen'd", payload.function_name); std::vector llvm_params = {}; diff --git a/cpp/src/semal.cpp b/cpp/src/semal.cpp index 458d51e..3366948 100644 --- a/cpp/src/semal.cpp +++ b/cpp/src/semal.cpp @@ -174,7 +174,7 @@ namespace semal { for(const auto& [mthname, mthdata] : structdata.methods) { - if(mthname == name) + if(mangle_method_name(mthname) == name) { return &mthdata; } @@ -206,6 +206,10 @@ namespace semal const std::string& function_name = std::get(ancestor.payload).func_name; const function_t* found_func = this->try_find_function(function_name.c_str()); if(found_func == nullptr) + { + found_func = this->try_find_function(semal::mangle_method_name(function_name)); + } + if(found_func == nullptr) { diag::ice("at: {}: internal compiler error: found a parent function of an AST node (named \"{}\"), but could not then retrieve the function data from semantic analysis state.", ancestor.meta.to_string(), function_name); } @@ -485,6 +489,11 @@ namespace semal return ret; } + std::string mangle_method_name(std::string method_name) + { + return "__method_" + method_name; + } + type output::get_type_from_payload(const ast::node::payload_t& payload, const ast& tree, const ast::path_t& path) const { return generic({.state = const_cast(*this), .path = path, .tree = tree}, payload); diff --git a/cpp/src/semal.hpp b/cpp/src/semal.hpp index ffdc3c8..58e721e 100644 --- a/cpp/src/semal.hpp +++ b/cpp/src/semal.hpp @@ -34,6 +34,7 @@ namespace semal } } }; + struct local_variable_t { type ty; @@ -99,6 +100,7 @@ namespace semal output analyse_predecl(const ast& tree); output analyse_full(const ast& tree, output predecl = {}); + std::string mangle_method_name(std::string method_name); struct state {