Allow anonymous parameters
This commit is contained in:
parent
5dc6e8ca16
commit
3f61e3749e
@ -86,7 +86,10 @@ namespace AST {
|
||||
for (auto& param : this->m_params) {
|
||||
if (counter++ > 0)
|
||||
out << ", ";
|
||||
out << param.second->formatted() << " " << param.first;
|
||||
out << param.second->formatted();
|
||||
if (param.first) {
|
||||
out << " " << *param.first;
|
||||
}
|
||||
}
|
||||
|
||||
out << ") -> ";
|
||||
|
||||
@ -175,14 +175,14 @@ namespace AST {
|
||||
class Function : public TopLevelStatement {
|
||||
private:
|
||||
std::unique_ptr<types::Type> m_return_ty;
|
||||
std::vector<std::pair<std::string, std::unique_ptr<types::Type>>> m_params;
|
||||
std::vector<std::pair<std::optional<std::string>, std::unique_ptr<types::Type>>> m_params;
|
||||
std::string m_name;
|
||||
std::optional<std::vector<std::unique_ptr<Statement>>> m_statements;
|
||||
public:
|
||||
Function(
|
||||
token::Metadata meta,
|
||||
std::unique_ptr<types::Type> return_ty,
|
||||
std::vector<std::pair<std::string, std::unique_ptr<types::Type>>> params,
|
||||
std::vector<std::pair<std::optional<std::string>, std::unique_ptr<types::Type>>> params,
|
||||
std::string name,
|
||||
std::optional<std::vector<std::unique_ptr<Statement>>> statements)
|
||||
: TopLevelStatement{ meta }
|
||||
|
||||
@ -209,11 +209,13 @@ namespace AST {
|
||||
for (auto& param : this->m_params) {
|
||||
auto param_ty_ptr = param_ty_ptrs[counter];
|
||||
auto arg = function->getArg(counter++);
|
||||
arg->setName(param.first);
|
||||
inner_scope.values[param.first] = codegen::StackValue{
|
||||
arg,
|
||||
param_ty_ptr,
|
||||
};
|
||||
if (param.first) {
|
||||
arg->setName(*param.first);
|
||||
inner_scope.values[*param.first] = codegen::StackValue{
|
||||
arg,
|
||||
param_ty_ptr,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& statement : *this->m_statements) {
|
||||
|
||||
@ -274,14 +274,17 @@ namespace parsing {
|
||||
auto name_token = inner.expect(token::Type::Ident);
|
||||
inner.expect(token::Type::Symbol, "(");
|
||||
|
||||
std::vector<std::pair<std::string, std::unique_ptr<types::Type>>> params;
|
||||
std::vector<std::pair<std::optional<std::string>, std::unique_ptr<types::Type>>> params;
|
||||
while (inner.peek().content != ")") {
|
||||
if (params.size() > 0) {
|
||||
inner.expect(token::Type::Symbol, ",");
|
||||
}
|
||||
auto param_ty = parse_type(inner).unwrap();
|
||||
auto param_name = inner.expect(token::Type::Ident);
|
||||
params.push_back(std::pair(param_name.content, std::move(param_ty)));
|
||||
std::optional<std::string> param_name{};
|
||||
if (inner.peek().type == token::Type::Ident) {
|
||||
param_name = inner.expect(token::Type::Ident).content;
|
||||
}
|
||||
params.push_back(std::pair(param_name, std::move(param_ty)));
|
||||
}
|
||||
|
||||
inner.expect(token::Type::Symbol, ")");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user