Basic veriadic, ext, and declaration only support, allowing us to use printf! Unifying with veriadic might need work (does it need ref treatment?)
This commit is contained in:
48
k.krak
48
k.krak
@@ -1016,6 +1016,7 @@ fun main(argc: int, argv: **char): int {
|
|||||||
var parameter_types = fun_type->_fun.first.first
|
var parameter_types = fun_type->_fun.first.first
|
||||||
var is_variadic = fun_type->_fun.second
|
var is_variadic = fun_type->_fun.second
|
||||||
var is_raw = fun_type->_fun.third
|
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 check is_ext for name mangling
|
||||||
// TODO ideally, we wouldn't worry about refs here, but until we have
|
// 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
|
// 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())
|
if (return_type.first == ref_type::_ref())
|
||||||
beginning_str += "*"
|
beginning_str += "*"
|
||||||
beginning_str += " " + fun_name + "("
|
beginning_str += " " + fun_name + "("
|
||||||
C_str += beginning_str
|
if (!is_just_dec)
|
||||||
|
C_str += beginning_str
|
||||||
C_declaration_str += beginning_str
|
C_declaration_str += beginning_str
|
||||||
for (var i = 0; i < parameter_types.size; i++;) {
|
for (var i = 0; i < parameter_types.size; i++;) {
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
C_str += ", "
|
if (!is_just_dec)
|
||||||
|
C_str += ", "
|
||||||
C_declaration_str += ", "
|
C_declaration_str += ", "
|
||||||
}
|
}
|
||||||
// TODO ditto about ref stuff above
|
// TODO ditto about ref stuff above
|
||||||
var parameter_type_str = to_c_type(parameter_types[i].second)
|
var parameter_type_str = to_c_type(parameter_types[i].second)
|
||||||
if (parameter_types[i].first == ref_type::_ref())
|
if (parameter_types[i].first == ref_type::_ref())
|
||||||
parameter_type_str += "*"
|
parameter_type_str += "*"
|
||||||
C_str += parameter_type_str + " "
|
if (!is_just_dec)
|
||||||
|
C_str += parameter_type_str + " "
|
||||||
C_declaration_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 (is_variadic) {
|
||||||
if (parameter_types.size != 0) {
|
if (parameter_types.size != 0) {
|
||||||
C_str += ", "
|
if (!is_just_dec)
|
||||||
|
C_str += ", "
|
||||||
C_declaration_str += ", "
|
C_declaration_str += ", "
|
||||||
}
|
}
|
||||||
C_str += "..."
|
if (!is_just_dec)
|
||||||
|
C_str += "..."
|
||||||
C_declaration_str += "..."
|
C_declaration_str += "..."
|
||||||
}
|
}
|
||||||
C_str += ") {\n"
|
if (!is_just_dec)
|
||||||
|
C_str += ") {\n"
|
||||||
C_declaration_str += ");\n"
|
C_declaration_str += ");\n"
|
||||||
for (var i = parameter_types.size; i < t->children.size; i++;) {
|
if !is_just_dec {
|
||||||
emit_C(t->children[i], level+1)
|
for (var i = parameter_types.size; i < t->children.size; i++;) {
|
||||||
C_str += ";\n"
|
emit_C(t->children[i], level+1)
|
||||||
|
C_str += ";\n"
|
||||||
|
}
|
||||||
|
C_str += "}\n"
|
||||||
}
|
}
|
||||||
C_str += "}\n"
|
|
||||||
}
|
}
|
||||||
ast::_template(b) { /* template should be ignored */ }
|
ast::_template(b) { /* template should be ignored */ }
|
||||||
ast::_declaration() {
|
ast::_declaration() {
|
||||||
@@ -1334,7 +1344,6 @@ fun syntax_to_ast(file_name: str, syntax: *tree<symbol>, import_paths: ref vec<s
|
|||||||
return make_pair(ref_type::_notref(), syntax_to_ast_helper(x, with_added_declared_template_types))
|
return make_pair(ref_type::_notref(), syntax_to_ast_helper(x, with_added_declared_template_types))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
var body = syntax_to_ast_helper(get_node("statement", syntax), with_added_declared_template_types)
|
|
||||||
var return_type = make_pair(ref_type::_unknown(), null<binding<type>>())
|
var return_type = make_pair(ref_type::_unknown(), null<binding<type>>())
|
||||||
var return_type_node = get_node("typed_return", syntax)
|
var return_type_node = get_node("typed_return", syntax)
|
||||||
if return_type_node != null<tree<symbol>>() {
|
if return_type_node != null<tree<symbol>>() {
|
||||||
@@ -1346,8 +1355,19 @@ fun syntax_to_ast(file_name: str, syntax: *tree<symbol>, import_paths: ref vec<s
|
|||||||
} else {
|
} else {
|
||||||
return_type = make_pair(ref_type::_notref(), binding_p(type::_void()))
|
return_type = make_pair(ref_type::_notref(), binding_p(type::_void()))
|
||||||
}
|
}
|
||||||
var function_type = binding_p(type::_fun(make_triple(make_pair(parameters.map(fun(i: pair<ref_type, *tree<ast>>): pair<ref_type, *binding<type>> return make_pair(i.first, i.second->data._identifier.second);), return_type), false, false)))
|
var function_type = binding_p(type::_fun(make_triple(
|
||||||
var n = _function(concat(get_node("func_identifier", syntax)), function_type, false, parameters.map(fun(i: pair<ref_type, *tree<ast>>): *tree<ast> return i.second;) + body)
|
make_pair(parameters.map(fun(i: pair<ref_type, *tree<ast>>): pair<ref_type, *binding<type>> return make_pair(i.first, i.second->data._identifier.second);),
|
||||||
|
return_type),
|
||||||
|
get_node("\"...\"", syntax) != null<tree<symbol>>(),
|
||||||
|
false /*get_node("\"run\"", syntax) != null<tree<symbol>>()*/)))
|
||||||
|
var body_syntax = get_node("statement", syntax)
|
||||||
|
var body = vec<*tree<ast>>()
|
||||||
|
if body_syntax != null<tree<symbol>>() {
|
||||||
|
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<tree<symbol>>(),
|
||||||
|
parameters.map(fun(i: pair<ref_type, *tree<ast>>): *tree<ast> return i.second;) + body)
|
||||||
if (new_template_type_map.size() > 0) {
|
if (new_template_type_map.size() > 0) {
|
||||||
return _template(n->data._function.first, new_template_type_map, vec(n))
|
return _template(n->data._function.first, new_template_type_map, vec(n))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ fun unify(t1: *binding<type>, t2: *binding<type>) {
|
|||||||
t1->bound_to->_fun.first.second.first = t2->bound_to->_fun.first.second.first
|
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())
|
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
|
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)
|
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())
|
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
|
t1->bound_to->_fun.first.first[i].first = t2->bound_to->_fun.first.first[i].first
|
||||||
|
|||||||
Reference in New Issue
Block a user