Object templates starting to work, don't do methods properly yet, likely all have the same name
This commit is contained in:
@@ -18,7 +18,7 @@ adt ast_node {
|
|||||||
type_def: type_def,
|
type_def: type_def,
|
||||||
adt_def: adt_def,
|
adt_def: adt_def,
|
||||||
function: function,
|
function: function,
|
||||||
function_template: function_template,
|
template: template,
|
||||||
code_block: code_block,
|
code_block: code_block,
|
||||||
statement: statement,
|
statement: statement,
|
||||||
if_statement: if_statement,
|
if_statement: if_statement,
|
||||||
@@ -306,19 +306,19 @@ obj function (Object) {
|
|||||||
return name == name && type == other.type && parameters == other.parameters && body_statement == other.body_statement
|
return name == name && type == other.type && parameters == other.parameters && body_statement == other.body_statement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun ast_function_template_ptr(name: string, syntax_node: *tree<symbol>, template_types: vector<string>, template_type_replacements: map<string, *type>): *ast_node {
|
fun ast_template_ptr(name: string, syntax_node: *tree<symbol>, template_types: vector<string>, template_type_replacements: map<string, *type>, is_function: bool): *ast_node {
|
||||||
var to_ret.construct(name, syntax_node, template_types, template_type_replacements): function_template
|
var to_ret.construct(name, syntax_node, template_types, template_type_replacements, is_function): template
|
||||||
var ptr = new<ast_node>()
|
var ptr = new<ast_node>()
|
||||||
ptr->copy_construct(&ast_node::function_template(to_ret))
|
ptr->copy_construct(&ast_node::template(to_ret))
|
||||||
return ptr
|
return ptr
|
||||||
}
|
}
|
||||||
fun is_function_template(node: *ast_node): bool {
|
fun is_template(node: *ast_node): bool {
|
||||||
match(*node) {
|
match(*node) {
|
||||||
ast_node::function_template(backing) return true
|
ast_node::template(backing) return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
obj function_template (Object) {
|
obj template (Object) {
|
||||||
var name: string
|
var name: string
|
||||||
var syntax_node: *tree<symbol>
|
var syntax_node: *tree<symbol>
|
||||||
var instantiated: vector<*ast_node>
|
var instantiated: vector<*ast_node>
|
||||||
@@ -326,7 +326,8 @@ obj function_template (Object) {
|
|||||||
var template_type_replacements: map<string, *type>
|
var template_type_replacements: map<string, *type>
|
||||||
var instantiated_map: map<vector<type>, *ast_node>
|
var instantiated_map: map<vector<type>, *ast_node>
|
||||||
var scope: map<string, vector<*ast_node>>
|
var scope: map<string, vector<*ast_node>>
|
||||||
fun construct(name_in: string, syntax_node_in: *tree<symbol>, template_types_in: vector<string>, template_type_replacements_in: map<string, *type>): *function_template {
|
var is_function: bool
|
||||||
|
fun construct(name_in: string, syntax_node_in: *tree<symbol>, template_types_in: vector<string>, template_type_replacements_in: map<string, *type>, is_function: bool): *template {
|
||||||
name.copy_construct(&name_in)
|
name.copy_construct(&name_in)
|
||||||
syntax_node = syntax_node_in
|
syntax_node = syntax_node_in
|
||||||
instantiated.construct()
|
instantiated.construct()
|
||||||
@@ -334,9 +335,10 @@ obj function_template (Object) {
|
|||||||
template_type_replacements.copy_construct(&template_type_replacements_in)
|
template_type_replacements.copy_construct(&template_type_replacements_in)
|
||||||
instantiated_map.construct()
|
instantiated_map.construct()
|
||||||
scope.construct()
|
scope.construct()
|
||||||
|
template::is_function = is_function
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
fun copy_construct(old: *function_template) {
|
fun copy_construct(old: *template) {
|
||||||
name.copy_construct(&old->name)
|
name.copy_construct(&old->name)
|
||||||
syntax_node = old->syntax_node
|
syntax_node = old->syntax_node
|
||||||
instantiated.copy_construct(&old->instantiated)
|
instantiated.copy_construct(&old->instantiated)
|
||||||
@@ -344,6 +346,7 @@ obj function_template (Object) {
|
|||||||
template_type_replacements.copy_construct(&old->template_type_replacements)
|
template_type_replacements.copy_construct(&old->template_type_replacements)
|
||||||
instantiated_map.copy_construct(&old->instantiated_map)
|
instantiated_map.copy_construct(&old->instantiated_map)
|
||||||
scope.copy_construct(&old->scope)
|
scope.copy_construct(&old->scope)
|
||||||
|
is_function = old->is_function
|
||||||
}
|
}
|
||||||
fun destruct() {
|
fun destruct() {
|
||||||
name.destruct()
|
name.destruct()
|
||||||
@@ -353,14 +356,14 @@ obj function_template (Object) {
|
|||||||
instantiated_map.destruct()
|
instantiated_map.destruct()
|
||||||
scope.destruct()
|
scope.destruct()
|
||||||
}
|
}
|
||||||
fun operator=(other: ref function_template) {
|
fun operator=(other: ref template) {
|
||||||
destruct()
|
destruct()
|
||||||
copy_construct(&other)
|
copy_construct(&other)
|
||||||
}
|
}
|
||||||
fun operator==(other: ref function_template): bool {
|
fun operator==(other: ref template): bool {
|
||||||
return name == name && syntax_node == other.syntax_node && instantiated == other.instantiated &&
|
return name == name && syntax_node == other.syntax_node && instantiated == other.instantiated &&
|
||||||
scope == other.scope && template_types == other.template_types && template_type_replacements == other.template_type_replacements &&
|
scope == other.scope && template_types == other.template_types && template_type_replacements == other.template_type_replacements &&
|
||||||
instantiated_map == other.instantiated_map
|
instantiated_map == other.instantiated_map && is_function == other.is_function
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun ast_code_block_ptr(): *ast_node {
|
fun ast_code_block_ptr(): *ast_node {
|
||||||
@@ -949,7 +952,7 @@ fun get_ast_children(node: *ast_node): vector<*ast_node> {
|
|||||||
ast_node::type_def(backing) return backing.variables + backing.methods
|
ast_node::type_def(backing) return backing.variables + backing.methods
|
||||||
ast_node::adt_def(backing) return vector<*ast_node>()
|
ast_node::adt_def(backing) return vector<*ast_node>()
|
||||||
ast_node::function(backing) return backing.parameters + backing.body_statement
|
ast_node::function(backing) return backing.parameters + backing.body_statement
|
||||||
ast_node::function_template(backing) return backing.instantiated
|
ast_node::template(backing) return backing.instantiated
|
||||||
ast_node::code_block(backing) return backing.children
|
ast_node::code_block(backing) return backing.children
|
||||||
ast_node::statement(backing) return vector<*ast_node>(backing.child)
|
ast_node::statement(backing) return vector<*ast_node>(backing.child)
|
||||||
ast_node::if_statement(backing) return vector(backing.condition, backing.then_part, backing.else_part)
|
ast_node::if_statement(backing) return vector(backing.condition, backing.then_part, backing.else_part)
|
||||||
@@ -976,7 +979,7 @@ fun get_ast_name(node: *ast_node): string {
|
|||||||
ast_node::type_def(backing) return string("type_def: ") + backing.name
|
ast_node::type_def(backing) return string("type_def: ") + backing.name
|
||||||
ast_node::adt_def(backing) return string("adt_def: ") + backing.name
|
ast_node::adt_def(backing) return string("adt_def: ") + backing.name
|
||||||
ast_node::function(backing) return string("function: ") + backing.name + ": " + backing.type->to_string()
|
ast_node::function(backing) return string("function: ") + backing.name + ": " + backing.type->to_string()
|
||||||
ast_node::function_template(backing) return string("function_template: ") + backing.name
|
ast_node::template(backing) return string("template: ") + backing.name
|
||||||
ast_node::code_block(backing) return string("code_block")
|
ast_node::code_block(backing) return string("code_block")
|
||||||
ast_node::statement(backing) return string("statement")
|
ast_node::statement(backing) return string("statement")
|
||||||
ast_node::if_statement(backing) return string("if_statement")
|
ast_node::if_statement(backing) return string("if_statement")
|
||||||
@@ -1003,7 +1006,7 @@ fun get_ast_scope(node: *ast_node): *map<string,vector<*ast_node>> {
|
|||||||
ast_node::type_def() return &node->type_def.scope
|
ast_node::type_def() return &node->type_def.scope
|
||||||
ast_node::adt_def() return &node->adt_def.scope
|
ast_node::adt_def() return &node->adt_def.scope
|
||||||
ast_node::function() return &node->function.scope
|
ast_node::function() return &node->function.scope
|
||||||
ast_node::function_template() return &node->function_template.scope
|
ast_node::template() return &node->template.scope
|
||||||
ast_node::code_block() return &node->code_block.scope
|
ast_node::code_block() return &node->code_block.scope
|
||||||
ast_node::statement() return &node->statement.scope
|
ast_node::statement() return &node->statement.scope
|
||||||
ast_node::if_statement() return &node->if_statement.scope
|
ast_node::if_statement() return &node->if_statement.scope
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -154,11 +154,20 @@ obj c_generator (Object) {
|
|||||||
// check for and add to parameters if a closure
|
// check for and add to parameters if a closure
|
||||||
generate_function_definition(child, null<ast_node>())
|
generate_function_definition(child, null<ast_node>())
|
||||||
}
|
}
|
||||||
ast_node::function_template(backing) {
|
ast_node::template(backing) {
|
||||||
backing.scope.for_each(fun(key: string, value: vector<*ast_node>) {
|
backing.scope.for_each(fun(key: string, value: vector<*ast_node>) {
|
||||||
value.for_each(fun(node: *ast_node) {
|
value.for_each(fun(node: *ast_node) {
|
||||||
if (is_function(node))
|
match (*node) {
|
||||||
generate_function_definition(node, null<ast_node>())
|
ast_node::function(backing) generate_function_definition(node, null<ast_node>())
|
||||||
|
ast_node::type_def(backing) {
|
||||||
|
type_poset.add_vertex(node)
|
||||||
|
backing.variables.for_each(fun(i: *ast_node) {
|
||||||
|
var var_type = get_ast_type(i->declaration_statement.identifier)
|
||||||
|
if (!var_type->indirection && var_type->type_def)
|
||||||
|
type_poset.add_relationship(node, var_type->type_def)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,22 +37,31 @@ fun return_something_p_1(it: Something): Something {
|
|||||||
return it
|
return it
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
fun id<T>(in: *T): *T return in;
|
/*fun id<T>(in: *T): *T return in;*/
|
||||||
/*fun id<T>(in: T): T return in;*/
|
/*fun id<T>(in: T): T return in;*/
|
||||||
|
/*
|
||||||
fun other_id<T>(in: T): T {
|
fun other_id<T>(in: T): T {
|
||||||
var a: T
|
var a: T
|
||||||
a = in
|
a = in
|
||||||
println(id<T>(in))
|
println(id<T>(in))
|
||||||
|
println(id(in))
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
fun some_function(): int return 0;
|
fun some_function(): int return 0;
|
||||||
fun some_other_function(in: bool): float {
|
fun some_other_function(in: bool): float {
|
||||||
return 0.0
|
return 0.0
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
obj SimpleContainer<T> {
|
||||||
|
var data: T
|
||||||
|
}
|
||||||
fun main(): int {
|
fun main(): int {
|
||||||
println(id("Wooo function template inference"))
|
var it: SimpleContainer<*char>
|
||||||
|
it.data = "Wooo object template"
|
||||||
|
println(it.data)
|
||||||
|
/*println(other_id("Wooo function template inference"))*/
|
||||||
/*var a = id<int>(7)*/
|
/*var a = id<int>(7)*/
|
||||||
/*println(a)*/
|
/*println(a)*/
|
||||||
/*var b = id<int>(8)*/
|
/*var b = id<int>(8)*/
|
||||||
|
|||||||
Reference in New Issue
Block a user