Implemented function values when type inferenced (not explicit types or lambdas)
This commit is contained in:
@@ -370,7 +370,9 @@ obj ast_transformation (Object) {
|
|||||||
}
|
}
|
||||||
match (searching_for) {
|
match (searching_for) {
|
||||||
search_type::none() return identifier_lookup(name, scope)
|
search_type::none() return identifier_lookup(name, scope)
|
||||||
search_type::function(type_vec) return function_lookup(name, scope, type_vec)
|
search_type::function(type_vec) {
|
||||||
|
return function_lookup(name, scope, type_vec)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
println("FAILED SEARCH FOR")
|
println("FAILED SEARCH FOR")
|
||||||
return null<ast_node>()
|
return null<ast_node>()
|
||||||
@@ -378,7 +380,7 @@ obj ast_transformation (Object) {
|
|||||||
fun transform_value(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
fun transform_value(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||||
var value_str = concat_symbol_tree(node)
|
var value_str = concat_symbol_tree(node)
|
||||||
var value_type = null<type>()
|
var value_type = null<type>()
|
||||||
if (value_str[0] == '"')
|
if (value_str[0] == '"') // " // Comment hack for emacs now
|
||||||
value_type = type_ptr(base_type::character(), 1)
|
value_type = type_ptr(base_type::character(), 1)
|
||||||
else if (value_str[0] == '\'') //'// lol, comment hack for vim syntax highlighting (my fault, of course)
|
else if (value_str[0] == '\'') //'// lol, comment hack for vim syntax highlighting (my fault, of course)
|
||||||
value_type = type_ptr(base_type::character())
|
value_type = type_ptr(base_type::character())
|
||||||
@@ -535,13 +537,13 @@ obj ast_transformation (Object) {
|
|||||||
var func_name = string()
|
var func_name = string()
|
||||||
var parameters = vector<*ast_node>()
|
var parameters = vector<*ast_node>()
|
||||||
if (node->children.size == 1) {
|
if (node->children.size == 1) {
|
||||||
var possible_func = transform(node->children[0], scope, searching_for, template_replacements)
|
var possible_value = transform(node->children[0], scope, searching_for, template_replacements)
|
||||||
if (!possible_func) match (searching_for) {
|
if (!possible_value) match (searching_for) {
|
||||||
search_type::function(type_vec) possible_func = find_or_instantiate_template_function(node->children[0], null<tree<symbol>>(), scope, type_vec, template_replacements, map<string, *type>());
|
search_type::function(type_vec) possible_value = find_or_instantiate_template_function(node->children[0], null<tree<symbol>>(), scope, type_vec, template_replacements, map<string, *type>());
|
||||||
}
|
}
|
||||||
if (!possible_func)
|
if (!possible_value)
|
||||||
println(concat_symbol_tree(node) + ": HAS NO POSSIBLE FUNCTION OR FUNCTION TEMPLATE SOLUTIONS")
|
println(concat_symbol_tree(node) + ": HAS NO POSSIBLE FUNCTION OR FUNCTION TEMPLATE SOLUTIONS")
|
||||||
return possible_func
|
return possible_value
|
||||||
} else if (node->children.size == 2) {
|
} else if (node->children.size == 2) {
|
||||||
var template_inst = get_node("template_inst", node)
|
var template_inst = get_node("template_inst", node)
|
||||||
if (template_inst) {
|
if (template_inst) {
|
||||||
@@ -759,7 +761,7 @@ fun function_lookup(name: string, scope: *ast_node, param_types: vector<*type>):
|
|||||||
var results = scope_lookup(name, scope)
|
var results = scope_lookup(name, scope)
|
||||||
print(results.size); println(" number of results")
|
print(results.size); println(" number of results")
|
||||||
for (var i = 0; i < results.size; i++;) {
|
for (var i = 0; i < results.size; i++;) {
|
||||||
if (is_function(results[i]) && function_satisfies_params(results[i], param_types)) {
|
if ((is_function(results[i]) || is_identifier(results[i])) && function_satisfies_params(results[i], param_types)) {
|
||||||
return results[i]
|
return results[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ obj code_triple (Object) {
|
|||||||
obj c_generator (Object) {
|
obj c_generator (Object) {
|
||||||
var id_counter: int
|
var id_counter: int
|
||||||
var ast_name_map: map<*ast_node, string>
|
var ast_name_map: map<*ast_node, string>
|
||||||
|
var function_typedef_string: string
|
||||||
fun construct(): *c_generator {
|
fun construct(): *c_generator {
|
||||||
id_counter = 0
|
id_counter = 0
|
||||||
ast_name_map.construct()
|
ast_name_map.construct()
|
||||||
@@ -100,8 +101,7 @@ obj c_generator (Object) {
|
|||||||
var top_level_c_passthrough: string = ""
|
var top_level_c_passthrough: string = ""
|
||||||
var variable_extern_declarations: string = ""
|
var variable_extern_declarations: string = ""
|
||||||
var structs: string = "\n/**Type Structs**/\n"
|
var structs: string = "\n/**Type Structs**/\n"
|
||||||
var function_typedef_string_pre: string = ""
|
function_typedef_string.construct()
|
||||||
var function_typedef_string: string = ""
|
|
||||||
var function_prototypes: string = "\n/**Function Prototypes**/\n"
|
var function_prototypes: string = "\n/**Function Prototypes**/\n"
|
||||||
var function_definitions: string = "\n/**Function Definitions**/\n"
|
var function_definitions: string = "\n/**Function Definitions**/\n"
|
||||||
var variable_declarations: string = "\n/**Variable Declarations**/\n"
|
var variable_declarations: string = "\n/**Variable Declarations**/\n"
|
||||||
@@ -199,7 +199,7 @@ obj c_generator (Object) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return make_pair(prequal+plain_typedefs+top_level_c_passthrough+variable_extern_declarations+structs+function_typedef_string_pre+function_typedef_string+function_prototypes+variable_declarations+function_definitions + "\n", linker_string)
|
return make_pair(prequal+plain_typedefs+top_level_c_passthrough+variable_extern_declarations+structs+function_typedef_string+function_prototypes+variable_declarations+function_definitions + "\n", linker_string)
|
||||||
}
|
}
|
||||||
fun generate_if_comp(node: *ast_node, enclosing_object: *ast_node, defer_stack: *stack<pair<bool,stack<*ast_node>>>): code_triple {
|
fun generate_if_comp(node: *ast_node, enclosing_object: *ast_node, defer_stack: *stack<pair<bool,stack<*ast_node>>>): code_triple {
|
||||||
if (node->if_comp.wanted_generator == "__C__")
|
if (node->if_comp.wanted_generator == "__C__")
|
||||||
@@ -508,9 +508,18 @@ obj c_generator (Object) {
|
|||||||
return get_name(type->type_def) + indirection
|
return get_name(type->type_def) + indirection
|
||||||
}
|
}
|
||||||
base_type::function() {
|
base_type::function() {
|
||||||
var temp = indirection + string("function: (")
|
var temp_name = string("temp") + get_id()
|
||||||
type->parameter_types.for_each(fun(parameter_type: *type) temp += parameter_type->to_string() + " ";)
|
var temp = temp_name + ")("
|
||||||
return temp + ")" + type->return_type->to_string()
|
var first = true
|
||||||
|
type->parameter_types.for_each(fun(parameter_type: *type) {
|
||||||
|
if (!first) {
|
||||||
|
temp += ", "
|
||||||
|
}
|
||||||
|
first = false
|
||||||
|
temp += type_to_c(parameter_type) + " "
|
||||||
|
})
|
||||||
|
function_typedef_string += string("typedef ") + type_to_c(type->return_type) + " (*" + temp + ");"
|
||||||
|
return temp_name + indirection
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return string("impossible type") + indirection
|
return string("impossible type") + indirection
|
||||||
|
|||||||
@@ -1,29 +1,12 @@
|
|||||||
import simple_print: *
|
import simple_print: *
|
||||||
|
fun print_and_return(data: int): int {
|
||||||
obj SimpleContainer<T> {
|
|
||||||
var data: T
|
|
||||||
fun print_data() {
|
|
||||||
var indirection: T
|
|
||||||
indirection = data
|
|
||||||
println(indirection)
|
|
||||||
}
|
|
||||||
fun with_other<U>(other: U) {
|
|
||||||
var indirection: U
|
|
||||||
indirection = other
|
|
||||||
println(data)
|
println(data)
|
||||||
println(other)
|
|
||||||
}
|
|
||||||
fun return_as<U>(): U {
|
|
||||||
var indirection: T
|
|
||||||
indirection = data
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
fun construct(dataIn: T) data = dataIn
|
|
||||||
}
|
|
||||||
fun main(): int {
|
fun main(): int {
|
||||||
var it: SimpleContainer<int>
|
var v = print_and_return
|
||||||
it.data = 8
|
println(v(7))
|
||||||
it.with_other("Wooo object template")
|
// println(print_and_return(7))
|
||||||
println(it.return_as<float>())
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user