other symbol for reference types, any references in reference type

This commit is contained in:
ProgramSnail 2023-08-13 16:19:47 +03:00
parent fe6507ae12
commit 7f3dfd71a1
6 changed files with 14 additions and 16 deletions

@ -1 +1 @@
Subproject commit 17a67d236113bf22fa516c08d2872f35b06dae9c
Subproject commit 6b093311dfb371cf67a218a8c97779ae5e15e234

View file

@ -174,18 +174,19 @@ parser::ParseTree::Node collect_symbol_doc_nodes(
return current_node;
}
// definition_info? annotation_info* '^'? (simple_type_identifier | typeclass)
// definition_info? annotation_info* '<>'? (simple_type_identifier | typeclass)
// (argument_type* '=' type)? ';'
nodes::TypeDefinition build_type_definition(parser::ParseTree::Node parser_node,
nodes::TypeStorage &type_storage) {
bool is_on_heap = parser_node.nth_child(0).get_value() == "^";
std::optional<parser::ParseTree::Node> description_node;
std::vector<parser::ParseTree::Node> annotation_nodes;
auto name_node = collect_symbol_doc_nodes(parser_node.nth_named_child(0),
description_node, annotation_nodes);
bool is_on_heap = !name_node.previous_sibling().is_null() &&
name_node.previous_sibling().get_value() == "<>";
nodes::Identifier name = build_identifier(name_node);
bool is_typeclass = (name.get_type() == nodes::Identifier::TYPECLASS);

View file

@ -87,13 +87,12 @@ nodes::TypeProxy build_array_type(parser::ParseTree::Node parser_node,
build_node(parser_node));
}
// TODO: add different reference types
// '^' type
// _reference_ type
nodes::TypeProxy build_reference_type(parser::ParseTree::Node parser_node,
nodes::TypeStorage &type_storage) {
nodes::TypeProxy type =
build_type(parser_node.nth_named_child(0), type_storage);
type.get()->set_modifier(nodes::Modifier::REF);
type.get()->set_modifier(build_modifier(parser_node.nth_child(0)));
return type;
}

View file

@ -87,7 +87,7 @@ void print_type_definition(const nodes::TypeDefinition &statement,
print_docs(*statement.get_docs(), printer);
if (statement.is_on_heap()) {
printer.print("^");
printer.print("<> ");
}
print_identifier(*statement.get_name(), printer);

View file

@ -7,9 +7,8 @@ namespace printers {
// TODO: better printing format for builtin types
void print_type(const nodes::Type &type, printers::Printer &printer) {
// TODO: more modifier types
if (type.get_modifier() == nodes::Modifier::REF) {
printer.print("^");
if (type.get_modifier() != nodes::Modifier::CONST) {
print_modifier(type.get_modifier(), printer);
}
if (type.get_annotation().has_value()) {

View file

@ -1,4 +1,3 @@
#!/usr/bin/env lang
:: module; // import module to current namespace
@ -146,13 +145,13 @@ bubble_sort_2 'arr : ref Array['A] = {
};
}
: example of ^ and generics. ^ used to denote that this object allocated on heap
: example of <> and generics. <> (in type definition) used to denote that this object allocated on heap
: object allocated by unique reference by default
^TreeNode 'Key 'Value =
<> TreeNode 'Key 'Value =
& @key Key
& @value Value
& @left ^TreeNode['Key 'Value]
& @right ^TreeNode['Key 'Value];
& @left <> TreeNode['Key 'Value]
& @right <> TreeNode['Key 'Value];
.new = do_something; // static methods