diff --git a/krakenGrammer.kgm b/krakenGrammer.kgm index 4f0157e..2a12825 100644 --- a/krakenGrammer.kgm +++ b/krakenGrammer.kgm @@ -83,9 +83,8 @@ opt_parameter_list = parameter_list | ; parameter_list = parameter_list WS "," WS parameter | parameter ; parameter = boolean_expression ; -def_nonterm = "def" ; -obj_nonterm = "obj" ; -type_def = def_nonterm WS identifier WS type | obj_nonterm WS identifier WS template_dec WS "{" WS declaration_block WS "}" | obj_nonterm WS identifier WS "{" WS declaration_block WS "}" | obj_nonterm WS identifier WS template_dec WS traits WS "{" WS declaration_block WS "}" | obj_nonterm WS identifier WS traits WS "{" WS declaration_block WS "}" ; +obj_nonterm = "obj" | "uni" ; +type_def = obj_nonterm WS identifier WS template_dec WS "{" WS declaration_block WS "}" | obj_nonterm WS identifier WS "{" WS declaration_block WS "}" | obj_nonterm WS identifier WS template_dec WS traits WS "{" WS declaration_block WS "}" | obj_nonterm WS identifier WS traits WS "{" WS declaration_block WS "}" ; declaration_block = declaration_statement line_end WS declaration_block | function WS declaration_block | declaration_statement line_end | function | ; traits = "\(" WS trait_list WS "\)" ; diff --git a/stdlib/ast_nodes.krak b/stdlib/ast_nodes.krak index 310b170..69bd3b2 100644 --- a/stdlib/ast_nodes.krak +++ b/stdlib/ast_nodes.krak @@ -190,13 +190,13 @@ obj identifier (Object) { return name == other.name && type == other.type && enclosing_scope == other.enclosing_scope } } -fun ast_type_def_ptr(name: string): *ast_node { -/*fun ast_type_def_ptr(name: ref string): *ast_node {*/ - /*return ast_type_def_ptr(name, false)*/ -/*}*/ -/*fun ast_type_def_ptr(name: ref string, is_union: bool): *ast_node {*/ - /*var to_ret.construct(name, is_union): type_def*/ - var to_ret.construct(name): type_def +/*fun ast_type_def_ptr(name: string): *ast_node {*/ +fun ast_type_def_ptr(name: ref string): *ast_node { + return ast_type_def_ptr(name, false) +} +fun ast_type_def_ptr(name: ref string, is_union: bool): *ast_node { + var to_ret.construct(name, is_union): type_def + /*var to_ret.construct(name): type_def*/ var ptr = new() ptr->copy_construct(&ast_node::type_def(to_ret)) return ptr @@ -210,16 +210,16 @@ fun is_type_def(node: *ast_node): bool { obj type_def (Object) { var scope: map> var name: string - /*var is_union: bool*/ var self_type: *type var variables: vector<*ast_node> var methods: vector<*ast_node> - /*fun construct(nameIn: ref string, is_unionIn: bool): *type_def {*/ - fun construct(nameIn: ref string): *type_def { + var is_union: bool + fun construct(nameIn: ref string, is_unionIn: bool): *type_def { + /*fun construct(nameIn: ref string): *type_def {*/ /*fun construct(nameIn: string): *type_def {*/ scope.construct() name.copy_construct(&nameIn) - /*is_union = is_unionIn*/ + is_union = is_unionIn self_type = null() variables.construct() methods.construct() @@ -229,7 +229,7 @@ obj type_def (Object) { self_type = old->self_type scope.copy_construct(&old->scope) name.copy_construct(&old->name) - /*is_union = old->is_union*/ + is_union = old->is_union variables.copy_construct(&old->variables) methods.copy_construct(&old->methods) } @@ -244,8 +244,8 @@ obj type_def (Object) { copy_construct(&other) } fun operator==(other: ref type_def): bool { - /*return name == other.name && is_union == other.is_union && self_type == other.self_type && variables == other.variables && methods == other.methods*/ - return name == other.name && self_type == other.self_type && variables == other.variables && methods == other.methods + return name == other.name && is_union == other.is_union && self_type == other.self_type && variables == other.variables && methods == other.methods + /*return name == other.name && self_type == other.self_type && variables == other.variables && methods == other.methods*/ } } fun ast_adt_def_ptr(name: string): *ast_node { diff --git a/stdlib/ast_transformation.krak b/stdlib/ast_transformation.krak index 0623f3b..693e786 100644 --- a/stdlib/ast_transformation.krak +++ b/stdlib/ast_transformation.krak @@ -104,9 +104,9 @@ obj ast_transformation (Object) { return template } else { // pass in whether or not this is a union - /*var type_def_node = ast_type_def_ptr(name, concat_symbol_tree(get_node("obj_nonterm", child)) == "uni")*/ + var type_def_node = ast_type_def_ptr(name, concat_symbol_tree(get_node("obj_nonterm", child)) == "uni") /*var type_def_node = ast_type_def_ptr(name, false)*/ - var type_def_node = ast_type_def_ptr(name) + /*var type_def_node = ast_type_def_ptr(name)*/ type_def_node->type_def.self_type = type_ptr(type_def_node, transform_traits(get_node("traits", child))) ast_to_syntax.set(type_def_node, child) add_to_scope("~enclosing_scope", scope, type_def_node) diff --git a/stdlib/c_generator.krak b/stdlib/c_generator.krak index fcf16fa..b769faa 100644 --- a/stdlib/c_generator.krak +++ b/stdlib/c_generator.krak @@ -443,16 +443,15 @@ obj c_generator (Object) { }) }) type_poset.get_sorted().for_each(fun(vert: *ast_node) { - /*var base_name = vert->type_def.name*/ var base_name = get_name(vert) plain_typedefs += string("typedef ") - /*if (is_type_def(vert) && vert->type_def.is_union) {*/ - /*plain_typedefs += "union "*/ - /*structs += "union "*/ - /*} else {*/ + if (is_type_def(vert) && vert->type_def.is_union) { + plain_typedefs += "union " + structs += "union " + } else { plain_typedefs += "struct " structs += "struct " - /*}*/ + } plain_typedefs += base_name + "_dummy " + base_name + ";\n" structs += base_name + "_dummy {\n" if (is_type_def(vert)) {