Actually implemented some sort of primitive hierarchy for the results of things like 1 + 2.0 as well as port test_functionMultipleTemplateTest.krak so we now have 5/71
This commit is contained in:
@@ -309,7 +309,7 @@ fun transform_value(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (contains_dot)
|
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
|
else
|
||||||
value_type = type_ptr(base_type::integer())
|
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>())
|
return ast_function_ptr(name, type_ptr(param_types, param_types[0]->clone_with_increased_indirection()), vector<*ast_node>())
|
||||||
if (name == "\\*")
|
if (name == "\\*")
|
||||||
return ast_function_ptr(name, type_ptr(param_types, param_types[0]->clone_with_decreased_indirection()), vector<*ast_node>())
|
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>())
|
return ast_function_ptr(name, type_ptr(param_types, param_types[0]), vector<*ast_node>())
|
||||||
}
|
}
|
||||||
fun find_or_instantiate_function_template(identifier: *tree<symbol>, template_inst: *tree<symbol>, scope: *ast_node, param_types: vector<*type>, template_replacements: map<string, *type>): *ast_node {
|
fun find_or_instantiate_function_template(identifier: *tree<symbol>, template_inst: *tree<symbol>, scope: *ast_node, param_types: vector<*type>, template_replacements: map<string, *type>): *ast_node {
|
||||||
var name = concat_symbol_tree(identifier)
|
var name = concat_symbol_tree(identifier)
|
||||||
|
println(string("trying to instantiate a template function: ") + name)
|
||||||
var results = scope_lookup(name, scope)
|
var results = scope_lookup(name, scope)
|
||||||
var real_types = get_nodes("type", template_inst).map(fun(t: *tree<symbol>): *type return transform_type(t, scope, template_replacements);)
|
var real_types = get_nodes("type", template_inst).map(fun(t: *tree<symbol>): *type return transform_type(t, scope, template_replacements);)
|
||||||
var real_types_deref = real_types.map(fun(t:*type):type return *t;)
|
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<symbol>, template_in
|
|||||||
|
|
||||||
if (function_satisfies_params(inst_func, param_types))
|
if (function_satisfies_params(inst_func, param_types))
|
||||||
return inst_func
|
return inst_func
|
||||||
|
else
|
||||||
|
println(string("this paticular ") + name + " did not satisfy params")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println("FREAK OUT MACHINE")
|
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++;) {
|
for (var j = 0; j < param_types.size; j++;) {
|
||||||
if (*func_param_types[j] != *param_types[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
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,6 +141,15 @@ obj type (Object) {
|
|||||||
}
|
}
|
||||||
return string("impossible type, indirection:") + indirection
|
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(): *type return clone_with_indirection(indirection+1);
|
||||||
fun clone_with_increased_indirection(more: int): *type return clone_with_indirection(indirection+more);
|
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);
|
fun clone_with_decreased_indirection(): *type return clone_with_indirection(indirection-1);
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
|
||||||
|
fun println() {
|
||||||
|
print("\n")
|
||||||
|
}
|
||||||
fun println(to_print: *char) {
|
fun println(to_print: *char) {
|
||||||
print(to_print)
|
print(to_print)
|
||||||
print("\n")
|
print("\n")
|
||||||
@@ -7,6 +10,14 @@ fun println(to_print: int) {
|
|||||||
print(to_print)
|
print(to_print)
|
||||||
print("\n")
|
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) {
|
fun print(to_print: *char) {
|
||||||
__if_comp__ __C__ simple_passthrough(to_print::) """
|
__if_comp__ __C__ simple_passthrough(to_print::) """
|
||||||
printf("%s", 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);
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import io:*;
|
import simple_print:*;
|
||||||
|
|
||||||
fun addAndPrint<T,J>(a: T, b: J): void {
|
fun addAndPrint<T,J>(a: T, b: J): void {
|
||||||
print(a+b);
|
print(a+b);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import io:*;
|
import simple_print:*;
|
||||||
|
|
||||||
obj NoTraits {};
|
obj NoTraits {};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user