mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-06 06:58:45 +00:00
dynamic array type expression changed: 0 -> _
This commit is contained in:
parent
3815f8259b
commit
d6e6d5cc2c
4 changed files with 42 additions and 20 deletions
|
|
@ -1 +1 @@
|
|||
Subproject commit 8e69e96520290fab76a98e620d58a4478e9d0861
|
||||
Subproject commit e2f0ef7b83e0bb5cc370fe365dd4fa871a44342c
|
||||
|
|
@ -1481,32 +1481,52 @@ void BuildVisitor::Visit(TypeExpression* node) {
|
|||
|
||||
auto suffix_node1 = current_node_.NextSibling();
|
||||
|
||||
// TODO: better structure // TODO: check
|
||||
// TODO: refactor ?? // TODO: check
|
||||
if (!suffix_node1.IsNull()) {
|
||||
auto suffix_node2 = suffix_node1.NextSibling();
|
||||
if (!suffix_node2.IsNull()) {
|
||||
auto suffix_node3 = suffix_node2.NextSibling();
|
||||
if (!suffix_node3.IsNull()) {
|
||||
if (suffix_node2.GetValue() == "_") {
|
||||
node->array_size = 0; // dynamic array
|
||||
} else {
|
||||
current_node_ = suffix_node2;
|
||||
NumberLiteral size_literal;
|
||||
Visit(&size_literal);
|
||||
node->array_size = size_literal.value;
|
||||
|
||||
NumberLiteral literal;
|
||||
Visit(&literal);
|
||||
node->array_size = literal.value;
|
||||
++excluded_child_count;
|
||||
if (size_literal.value == 0) {
|
||||
error_handling::HandleParsingError("Can't have zero sized arrays with constant length",
|
||||
node->base.start_position,
|
||||
node->base.end_position);
|
||||
}
|
||||
|
||||
++excluded_child_count; // literal is named child
|
||||
}
|
||||
|
||||
node->is_optional = true;
|
||||
} else {
|
||||
if (suffix_node1.GetValue() == "`" && suffix_node2.GetValue() == "?") {
|
||||
node->array_size = 0;
|
||||
|
||||
node->is_optional = true;
|
||||
error_handling::HandleInternalError("Array suffix should have size parameter or _",
|
||||
"BuildVisitor.TypeExpression",
|
||||
std::nullopt);
|
||||
} else if (suffix_node1.GetValue() == "`") {
|
||||
if (suffix_node2.GetValue() == "_") {
|
||||
node->array_size = 0; // dynamic array
|
||||
} else {
|
||||
current_node_ = suffix_node2;
|
||||
NumberLiteral size_literal;
|
||||
Visit(&size_literal);
|
||||
node->array_size = size_literal.value;
|
||||
|
||||
NumberLiteral literal;
|
||||
Visit(&literal);
|
||||
node->array_size = literal.value;
|
||||
++excluded_child_count;
|
||||
if (size_literal.value == 0) {
|
||||
error_handling::HandleParsingError("Can't have zero sized arrays with constant length",
|
||||
node->base.start_position,
|
||||
node->base.end_position);
|
||||
}
|
||||
|
||||
++excluded_child_count; // literal is named child
|
||||
}
|
||||
} else {
|
||||
error_handling::HandleInternalError("Undefined suffix (2 elements)",
|
||||
"BuildVisitor.TypeExpression",
|
||||
|
|
@ -1515,7 +1535,9 @@ void BuildVisitor::Visit(TypeExpression* node) {
|
|||
}
|
||||
} else {
|
||||
if (suffix_node1.GetValue() == "`") {
|
||||
node->array_size = 0;
|
||||
error_handling::HandleInternalError("Array suffix should have size parameter or _",
|
||||
"BuildVisitor.TypeExpression",
|
||||
std::nullopt);
|
||||
} else if (suffix_node1.GetValue() == "?") {
|
||||
node->is_optional = true;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
struct \struct-with-ref =
|
||||
& @\int`0
|
||||
& @\int`_
|
||||
|
||||
decl test-memory : -> \unit
|
||||
def test-memory = {
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ typeclass \enum =
|
|||
|
||||
//
|
||||
|
||||
decl ( -- ) : \int -> \int -> \int`0
|
||||
decl ( -- ) : \int -> \int -> \int`_
|
||||
def ( -- ) : begin end = {
|
||||
var current = begin
|
||||
return (while current < end do {
|
||||
|
|
@ -252,10 +252,10 @@ def print-anything : x = \io..print: (x..show:)
|
|||
// return a-copy
|
||||
// }
|
||||
|
||||
struct \array 'a = & 'a`0
|
||||
struct \array 'a = & 'a`_
|
||||
|
||||
namespace \array {
|
||||
decl of : 'a`0 -> \array['a]
|
||||
decl of : 'a`_ -> \array['a]
|
||||
def of : x = $array['a] & x
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue