diff --git a/k.krak b/k.krak index e6ff74c..1c244b0 100644 --- a/k.krak +++ b/k.krak @@ -1016,6 +1016,7 @@ fun main(argc: int, argv: **char): int { var parameter_types = fun_type->_fun.first.first var is_variadic = fun_type->_fun.second var is_raw = fun_type->_fun.third + var is_just_dec = parameter_types.size == t->children.size // TODO check is_ext for name mangling // TODO ideally, we wouldn't worry about refs here, but until we have // per pass trees / bindings and stuff, we can't change the functions @@ -1025,36 +1026,45 @@ fun main(argc: int, argv: **char): int { if (return_type.first == ref_type::_ref()) beginning_str += "*" beginning_str += " " + fun_name + "(" - C_str += beginning_str + if (!is_just_dec) + C_str += beginning_str C_declaration_str += beginning_str for (var i = 0; i < parameter_types.size; i++;) { if (i != 0) { - C_str += ", " + if (!is_just_dec) + C_str += ", " C_declaration_str += ", " } // TODO ditto about ref stuff above var parameter_type_str = to_c_type(parameter_types[i].second) if (parameter_types[i].first == ref_type::_ref()) parameter_type_str += "*" - C_str += parameter_type_str + " " + if (!is_just_dec) + C_str += parameter_type_str + " " C_declaration_str += parameter_type_str - emit_C(t->children[i], 0) + if (!is_just_dec) + emit_C(t->children[i], 0) } if (is_variadic) { if (parameter_types.size != 0) { - C_str += ", " + if (!is_just_dec) + C_str += ", " C_declaration_str += ", " } - C_str += "..." + if (!is_just_dec) + C_str += "..." C_declaration_str += "..." } - C_str += ") {\n" + if (!is_just_dec) + C_str += ") {\n" C_declaration_str += ");\n" - for (var i = parameter_types.size; i < t->children.size; i++;) { - emit_C(t->children[i], level+1) - C_str += ";\n" + if !is_just_dec { + for (var i = parameter_types.size; i < t->children.size; i++;) { + emit_C(t->children[i], level+1) + C_str += ";\n" + } + C_str += "}\n" } - C_str += "}\n" } ast::_template(b) { /* template should be ignored */ } ast::_declaration() { @@ -1334,7 +1344,6 @@ fun syntax_to_ast(file_name: str, syntax: *tree, import_paths: ref vec>()) var return_type_node = get_node("typed_return", syntax) if return_type_node != null>() { @@ -1346,8 +1355,19 @@ fun syntax_to_ast(file_name: str, syntax: *tree, import_paths: ref vec>): pair> return make_pair(i.first, i.second->data._identifier.second);), return_type), false, false))) - var n = _function(concat(get_node("func_identifier", syntax)), function_type, false, parameters.map(fun(i: pair>): *tree return i.second;) + body) + var function_type = binding_p(type::_fun(make_triple( + make_pair(parameters.map(fun(i: pair>): pair> return make_pair(i.first, i.second->data._identifier.second);), + return_type), + get_node("\"...\"", syntax) != null>(), + false /*get_node("\"run\"", syntax) != null>()*/))) + var body_syntax = get_node("statement", syntax) + var body = vec<*tree>() + if body_syntax != null>() { + body = vec(syntax_to_ast_helper(body_syntax, with_added_declared_template_types)) + } + var n = _function(concat(get_node("func_identifier", syntax)), + function_type, get_node("\"ext\"", syntax) != null>(), + parameters.map(fun(i: pair>): *tree return i.second;) + body) if (new_template_type_map.size() > 0) { return _template(n->data._function.first, new_template_type_map, vec(n)) } else { diff --git a/stdlib/type2.krak b/stdlib/type2.krak index 63bbc57..8ffc5a5 100644 --- a/stdlib/type2.krak +++ b/stdlib/type2.krak @@ -55,7 +55,8 @@ fun unify(t1: *binding, t2: *binding) { t1->bound_to->_fun.first.second.first = t2->bound_to->_fun.first.second.first if (t2->bound_to->_fun.first.second.first == ref_type::_unknown()) t2->bound_to->_fun.first.second.first = t1->bound_to->_fun.first.second.first - for (var i = 0; i < t1->bound_to->_fun.first.first.size; i++;) { + // might be veradic... + for (var i = 0; i < t1->bound_to->_fun.first.first.size && i < t2->bound_to->_fun.first.first.size; i++;) { unify(t1->bound_to->_fun.first.first[i].second, t2->bound_to->_fun.first.first[i].second) if (t1->bound_to->_fun.first.first[i].first == ref_type::_unknown()) t1->bound_to->_fun.first.first[i].first = t2->bound_to->_fun.first.first[i].first