mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-05 22:48:43 +00:00
other symbol for reference types, any references in reference type
This commit is contained in:
parent
fe6507ae12
commit
7f3dfd71a1
6 changed files with 14 additions and 16 deletions
2
deps/tree-sitter-lang
vendored
2
deps/tree-sitter-lang
vendored
|
|
@ -1 +1 @@
|
||||||
Subproject commit 17a67d236113bf22fa516c08d2872f35b06dae9c
|
Subproject commit 6b093311dfb371cf67a218a8c97779ae5e15e234
|
||||||
|
|
@ -174,18 +174,19 @@ parser::ParseTree::Node collect_symbol_doc_nodes(
|
||||||
return current_node;
|
return current_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
// definition_info? annotation_info* '^'? (simple_type_identifier | typeclass)
|
// definition_info? annotation_info* '<>'? (simple_type_identifier | typeclass)
|
||||||
// (argument_type* '=' type)? ';'
|
// (argument_type* '=' type)? ';'
|
||||||
nodes::TypeDefinition build_type_definition(parser::ParseTree::Node parser_node,
|
nodes::TypeDefinition build_type_definition(parser::ParseTree::Node parser_node,
|
||||||
nodes::TypeStorage &type_storage) {
|
nodes::TypeStorage &type_storage) {
|
||||||
bool is_on_heap = parser_node.nth_child(0).get_value() == "^";
|
|
||||||
|
|
||||||
std::optional<parser::ParseTree::Node> description_node;
|
std::optional<parser::ParseTree::Node> description_node;
|
||||||
std::vector<parser::ParseTree::Node> annotation_nodes;
|
std::vector<parser::ParseTree::Node> annotation_nodes;
|
||||||
|
|
||||||
auto name_node = collect_symbol_doc_nodes(parser_node.nth_named_child(0),
|
auto name_node = collect_symbol_doc_nodes(parser_node.nth_named_child(0),
|
||||||
description_node, annotation_nodes);
|
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);
|
nodes::Identifier name = build_identifier(name_node);
|
||||||
|
|
||||||
bool is_typeclass = (name.get_type() == nodes::Identifier::TYPECLASS);
|
bool is_typeclass = (name.get_type() == nodes::Identifier::TYPECLASS);
|
||||||
|
|
|
||||||
|
|
@ -87,13 +87,12 @@ nodes::TypeProxy build_array_type(parser::ParseTree::Node parser_node,
|
||||||
build_node(parser_node));
|
build_node(parser_node));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add different reference types
|
// _reference_ type
|
||||||
// '^' type
|
|
||||||
nodes::TypeProxy build_reference_type(parser::ParseTree::Node parser_node,
|
nodes::TypeProxy build_reference_type(parser::ParseTree::Node parser_node,
|
||||||
nodes::TypeStorage &type_storage) {
|
nodes::TypeStorage &type_storage) {
|
||||||
nodes::TypeProxy type =
|
nodes::TypeProxy type =
|
||||||
build_type(parser_node.nth_named_child(0), type_storage);
|
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;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ void print_type_definition(const nodes::TypeDefinition &statement,
|
||||||
print_docs(*statement.get_docs(), printer);
|
print_docs(*statement.get_docs(), printer);
|
||||||
|
|
||||||
if (statement.is_on_heap()) {
|
if (statement.is_on_heap()) {
|
||||||
printer.print("^");
|
printer.print("<> ");
|
||||||
}
|
}
|
||||||
|
|
||||||
print_identifier(*statement.get_name(), printer);
|
print_identifier(*statement.get_name(), printer);
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,8 @@ namespace printers {
|
||||||
|
|
||||||
// TODO: better printing format for builtin types
|
// TODO: better printing format for builtin types
|
||||||
void print_type(const nodes::Type &type, printers::Printer &printer) {
|
void print_type(const nodes::Type &type, printers::Printer &printer) {
|
||||||
// TODO: more modifier types
|
if (type.get_modifier() != nodes::Modifier::CONST) {
|
||||||
if (type.get_modifier() == nodes::Modifier::REF) {
|
print_modifier(type.get_modifier(), printer);
|
||||||
printer.print("^");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.get_annotation().has_value()) {
|
if (type.get_annotation().has_value()) {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
#!/usr/bin/env lang
|
#!/usr/bin/env lang
|
||||||
|
|
||||||
:: module; // import module to current namespace
|
:: 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
|
: object allocated by unique reference by default
|
||||||
^TreeNode 'Key 'Value =
|
<> TreeNode 'Key 'Value =
|
||||||
& @key Key
|
& @key Key
|
||||||
& @value Value
|
& @value Value
|
||||||
& @left ^TreeNode['Key 'Value]
|
& @left <> TreeNode['Key 'Value]
|
||||||
& @right ^TreeNode['Key 'Value];
|
& @right <> TreeNode['Key 'Value];
|
||||||
|
|
||||||
.new = do_something; // static methods
|
.new = do_something; // static methods
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue