diff --git a/stdlib/ast_transformation.krak b/stdlib/ast_transformation.krak index b93a450..60217ba 100644 --- a/stdlib/ast_transformation.krak +++ b/stdlib/ast_transformation.krak @@ -309,7 +309,7 @@ fun transform_value(node: *tree, scope: *ast_node): *ast_node { } } if (contains_dot) - value_type = type_ptr(base_type::floating()) + value_type = type_ptr(base_type::double_precision()) //value_type = type_ptr(base_type::floating()) else value_type = type_ptr(base_type::integer()) } @@ -491,10 +491,13 @@ fun get_builtin_function(name: string, param_types: vector<*type>): *ast_node { return ast_function_ptr(name, type_ptr(param_types, param_types[0]->clone_with_increased_indirection()), vector<*ast_node>()) if (name == "\\*") return ast_function_ptr(name, type_ptr(param_types, param_types[0]->clone_with_decreased_indirection()), vector<*ast_node>()) + if (param_types.size > 1 && param_types[1]->rank() > param_types[0]->rank()) + return ast_function_ptr(name, type_ptr(param_types, param_types[1]), vector<*ast_node>()) return ast_function_ptr(name, type_ptr(param_types, param_types[0]), vector<*ast_node>()) } fun find_or_instantiate_function_template(identifier: *tree, template_inst: *tree, scope: *ast_node, param_types: vector<*type>, template_replacements: map): *ast_node { var name = concat_symbol_tree(identifier) + println(string("trying to instantiate a template function: ") + name) var results = scope_lookup(name, scope) var real_types = get_nodes("type", template_inst).map(fun(t: *tree): *type return transform_type(t, scope, template_replacements);) var real_types_deref = real_types.map(fun(t:*type):type return *t;) @@ -535,6 +538,8 @@ fun find_or_instantiate_function_template(identifier: *tree, template_in if (function_satisfies_params(inst_func, param_types)) return inst_func + else + println(string("this paticular ") + name + " did not satisfy params") } } println("FREAK OUT MACHINE") @@ -550,6 +555,7 @@ fun function_satisfies_params(node: *ast_node, param_types: vector<*type>): bool } for (var j = 0; j < param_types.size; j++;) { if (*func_param_types[j] != *param_types[j]) { + println(string("types don't match") + func_param_types[j]->to_string() + " with needed " + param_types[j]->to_string()) return false } } diff --git a/stdlib/type.krak b/stdlib/type.krak index 1cc04ff..5931c48 100644 --- a/stdlib/type.krak +++ b/stdlib/type.krak @@ -141,6 +141,15 @@ obj type (Object) { } return string("impossible type, indirection:") + indirection } + fun rank(): int { + match (base) { + base_type::character() return 1 + base_type::integer() return 2 + base_type::floating() return 3 + base_type::double_precision() return 4 + } + return 0 + } fun clone_with_increased_indirection(): *type return clone_with_indirection(indirection+1); fun clone_with_increased_indirection(more: int): *type return clone_with_indirection(indirection+more); fun clone_with_decreased_indirection(): *type return clone_with_indirection(indirection-1); diff --git a/tests/simple_print.krak b/tests/simple_print.krak index 788462b..7fa5643 100644 --- a/tests/simple_print.krak +++ b/tests/simple_print.krak @@ -1,4 +1,7 @@ +fun println() { + print("\n") +} fun println(to_print: *char) { print(to_print) print("\n") @@ -7,6 +10,14 @@ fun println(to_print: int) { print(to_print) print("\n") } +fun println(to_print: float) { + print(to_print) + print("\n") +} +fun println(to_print: double) { + print(to_print) + print("\n") +} fun print(to_print: *char) { __if_comp__ __C__ simple_passthrough(to_print::) """ printf("%s", to_print); @@ -18,3 +29,14 @@ fun print(to_print: int) { """ } +fun print(to_print: float) { + __if_comp__ __C__ simple_passthrough(to_print::) """ + printf("%f", to_print); + """ +} +fun print(to_print: double) { + __if_comp__ __C__ simple_passthrough(to_print::) """ + printf("%f", to_print); + """ +} + diff --git a/tests/test_functionMultipleTemplateTest.krak b/tests/test_functionMultipleTemplateTest.krak index c496e49..62ae12a 100644 --- a/tests/test_functionMultipleTemplateTest.krak +++ b/tests/test_functionMultipleTemplateTest.krak @@ -1,4 +1,4 @@ -import io:*; +import simple_print:*; fun addAndPrint(a: T, b: J): void { print(a+b); diff --git a/tests/test_traitsTest.krak b/tests/test_traitsTest.krak index ea198e2..9916381 100644 --- a/tests/test_traitsTest.krak +++ b/tests/test_traitsTest.krak @@ -1,4 +1,4 @@ -import io:*; +import simple_print:*; obj NoTraits {};