diff options
57 files changed, 370 insertions, 398 deletions
@@ -9,4 +9,5 @@ gem 'rubocop-rake', '~> 0.7' gem 'faraday', '~> 2.14' gem 'faraday-follow_redirects', '~> 0.5' +gem 'ffi-clang', '~> 0.16.0' gem 'term-ansicolor', '~> 1.11' diff --git a/Gemfile.lock b/Gemfile.lock index 1c40795..2278bce 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,6 +12,10 @@ GEM faraday (>= 1, < 3) faraday-net_http (3.4.4) net-http (~> 0.5) + ffi (1.17.4) + ffi (1.17.4-x86_64-linux-gnu) + ffi-clang (0.16.0) + ffi io-console (0.9.4) irb (1.18.0) pp (>= 0.6.0) @@ -23,15 +27,18 @@ GEM lint_roller (1.1.0) logger (1.7.0) mize (0.6.1) - net-http (0.9.1) + net-http (0.10.0) + net-protocol (>= 0.3.0) uri (>= 0.11.1) + net-protocol (0.4.0) + timeout parallel (2.3.0) parser (3.3.12.0) ast (~> 2.4.1) racc pp (0.6.4) prettyprint - prettyprint (0.2.0) + prettyprint (0.2.1) prism (1.9.0) racc (1.8.1) rainbow (3.1.1) @@ -71,7 +78,8 @@ GEM sync (0.5.0) term-ansicolor (1.11.3) tins (~> 1) - tins (1.60.0) + timeout (0.6.1) + tins (1.60.1) bigdecimal irb mize (~> 0.6) @@ -81,7 +89,7 @@ GEM unicode-display_width (3.3.0) unicode-emoji (~> 4.3) unicode-emoji (4.3.0) - uri (1.1.1) + uri (1.1.2) PLATFORMS ruby @@ -90,6 +98,7 @@ PLATFORMS DEPENDENCIES faraday (~> 2.14) faraday-follow_redirects (~> 0.5) + ffi-clang (~> 0.16.0) rake (~> 13.4) rubocop (~> 1.91) rubocop-rake (~> 0.7) @@ -102,6 +111,9 @@ CHECKSUMS faraday (2.14.4) sha256=9bb4408c44621b0dbaaaa39e5dbfc4dbe58cc6751b6eb94d16ae9e1f2f2fab6e faraday-follow_redirects (0.5.0) sha256=5cde93c894b30943a5d2b93c2fe9284216a6b756f7af406a1e55f211d97d10ad faraday-net_http (3.4.4) sha256=0e78af151747ed1b00f33e25973b4bc220d7f16c00c39676817c8b12331eb588 + ffi (1.17.4) sha256=bcd1642e06f0d16fc9e09ac6d49c3a7298b9789bcb58127302f934e437d60acf + ffi (1.17.4-x86_64-linux-gnu) sha256=9d3db14c2eae074b382fa9c083fe95aec6e0a1451da249eab096c34002bc752d + ffi-clang (0.16.0) sha256=5c002fc3878200078ea33af5f1b145a1582a14798029caed4f3a504085cd9208 io-console (0.9.4) sha256=a403304f32928ee85e56d457b4612ca43f2703b561a3258844992bd24085fbb1 irb (1.18.0) sha256=de9454a0703a54704b9811a5ef31a60c86949fbf4013fcf244fabc7c775248e3 json (3.0.2) sha256=8e6d7e7b11384c21230430cef90b71f14849a34a1f4452796670f7c981bd19df @@ -109,11 +121,12 @@ CHECKSUMS lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87 logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203 mize (0.6.1) sha256=4031558979ff5426fda24c75a149b4e4c0faf4cacf2fae8938f83866ab94b780 - net-http (0.9.1) sha256=25ba0b67c63e89df626ed8fac771d0ad24ad151a858af2cc8e6a716ca4336996 + net-http (0.10.0) sha256=1a2ff6e37a05724973c43f2bf7bf105f59c36a4cd0a7e9b1c021a0a566987c27 + net-protocol (0.4.0) sha256=f9f90c8c6f64794a45160bf422177a336db12809de3beeeaa26b88fcd2e8c853 parallel (2.3.0) sha256=f75a3e904101ce6a1ccb6b8dc800cbafd42166d83330192438dcf29395167a6f parser (3.3.12.0) sha256=21a6d7f755d5a24dfbdc6e6b772e4e879a52e7631a88bc5a3a134606052c9828 pp (0.6.4) sha256=dfcb0fce700c41456265922884f9fe195d7fbb0674a3578e6c0f69588e82b570 - prettyprint (0.2.0) sha256=2bc9e15581a94742064a3cc8b0fb9d45aae3d03a1baa6ef80922627a0766f193 + prettyprint (0.2.1) sha256=d555d57ea6d7cf001d4774b693546a6bd88bec1e778ddffb5c60b68ceec4b7d4 prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85 racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f rainbow (3.1.1) sha256=039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a @@ -129,11 +142,12 @@ CHECKSUMS ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33 sync (0.5.0) sha256=668356cc07c59ac7ed9ecf34fec3929831f179c07adb1f3e1c3b7a1609a638fd term-ansicolor (1.11.3) sha256=8c01ec3abd095eb94dca8aed5a127d36e594239eb525eb306259c9e930534603 - tins (1.60.0) sha256=919f9b6e4cc3aa0d80fb37d43118c8fb093462a4482bbcf2728bde47d4a80791 + timeout (0.6.1) sha256=78f57368a7e7bbadec56971f78a3f5ecbcfb59b7fcbb0a3ed6ddc08a5094accb + tins (1.60.1) sha256=4eafea1c8e63aeb0a2302a59f3928cf4a2f99b9fd265fc33ca0a069dd3f716ea tsort (0.2.0) sha256=9650a793f6859a43b6641671278f79cfead60ac714148aabe4e3f0060480089f unicode-display_width (3.3.0) sha256=4b7aa66a4b11db50f6f7e98411215cd0dd10eaecb665d36eec5bcacb3fa0b613 unicode-emoji (4.3.0) sha256=11c02fa73290378c066bb0562cd4c87d8e1b706fbbe0059ca12746a4244de8ce - uri (1.1.1) sha256=379fa58d27ffb1387eaada68c749d1426738bd0f654d812fcc07e7568f5c57c6 + uri (1.1.2) sha256=89292e98eabbef6248b0a0ed5e7e398e152f83f17560023a6d94a7f492b169fb BUNDLED WITH 4.0.20 diff --git a/boot/ast.cc b/boot/ast.cc index b681695..edc10a7 100644 --- a/boot/ast.cc +++ b/boot/ast.cc @@ -217,11 +217,6 @@ namespace elna::boot __builtin_unreachable(); } - void empty_visitor::visit(literal<std::nullptr_t> *) - { - __builtin_unreachable(); - } - void empty_visitor::visit(literal<std::string> *) { __builtin_unreachable(); @@ -500,10 +495,6 @@ namespace elna::boot { } - void walking_visitor::visit(literal<std::nullptr_t> *) - { - } - void walking_visitor::visit(literal<std::string> *) { } diff --git a/boot/evaluator.cc b/boot/evaluator.cc index 18633ba..78eb4cd 100644 --- a/boot/evaluator.cc +++ b/boot/evaluator.cc @@ -280,10 +280,6 @@ namespace elna::boot { return constant_value{ character_subject->value }; } - else if (auto *pointer_subject = subject.is_a<std::nullptr_t>()) - { - return constant_value{ pointer_subject->value }; - } else if (auto *string_subject = subject.is_a<std::string>()) { return constant_value{ string_subject->value }; @@ -517,25 +513,10 @@ namespace elna::boot template<typename T> static std::optional<constant_value> evaluate_operation(binary_operator operation, const T& lhs, const T& rhs) { - if constexpr (std::is_same_v<T, std::nullptr_t>) - { - switch (operation) - { - using enum binary_operator; - case equals: - return constant_value{ true }; - case not_equals: - return constant_value{ false }; - default: - return std::nullopt; - } - } - else + switch (operation) { - switch (operation) - { - using enum binary_operator; - case sum: + using enum binary_operator; + case sum: if constexpr (std::is_same_v<T, integer_literal>) { if (auto result = lhs.add(rhs)) @@ -667,25 +648,29 @@ namespace elna::boot case not_equals: return constant_value{ lhs != rhs }; case less: - if constexpr (std::is_same_v<T, float_literal> || std::is_same_v<T, integer_literal>) + if constexpr (std::is_same_v<T, float_literal> || std::is_same_v<T, integer_literal> + || std::is_same_v<T, pointer_literal>) { return constant_value{ lhs < rhs }; } return std::nullopt; case greater: - if constexpr (std::is_same_v<T, float_literal> || std::is_same_v<T, integer_literal>) + if constexpr (std::is_same_v<T, float_literal> || std::is_same_v<T, integer_literal> + || std::is_same_v<T, pointer_literal>) { return constant_value{ lhs > rhs }; } return std::nullopt; case less_equal: - if constexpr (std::is_same_v<T, float_literal> || std::is_same_v<T, integer_literal>) + if constexpr (std::is_same_v<T, float_literal> || std::is_same_v<T, integer_literal> + || std::is_same_v<T, pointer_literal>) { return constant_value{ lhs <= rhs }; } return std::nullopt; case greater_equal: - if constexpr (std::is_same_v<T, float_literal> || std::is_same_v<T, integer_literal>) + if constexpr (std::is_same_v<T, float_literal> || std::is_same_v<T, integer_literal> + || std::is_same_v<T, pointer_literal>) { return constant_value{ lhs >= rhs }; } @@ -693,7 +678,6 @@ namespace elna::boot default: return std::nullopt; } - } } std::optional<constant_value> evaluator::evaluate_binary(binary_expression& subject) @@ -799,9 +783,9 @@ namespace elna::boot { return integer_constant(target_signed, target_size, static_cast<double>(source_value)); } - else if constexpr (std::is_same_v<T, std::nullptr_t>) + else if constexpr (std::is_same_v<T, pointer_literal>) { - return integer_constant(target_signed, target_size, 0.0); + return constant_value{ source_value.address.cast_to(target_signed, target_size) }; } else { @@ -834,10 +818,6 @@ namespace elna::boot return constant_value{ widened.cast_to(target_format) }; } - else if constexpr (std::is_same_v<T, std::nullptr_t>) - { - return constant_value{ float_literal::from(0.0).cast_to(target_format) }; - } else { return std::nullopt; @@ -866,9 +846,9 @@ namespace elna::boot { return constant_value{ source_value != 0U }; } - else if constexpr (std::is_same_v<T, std::nullptr_t>) + else if constexpr (std::is_same_v<T, pointer_literal>) { - return constant_value{ false }; + return constant_value{ !(source_value.address == std::size_t{ 0 }) }; } else { @@ -906,10 +886,6 @@ namespace elna::boot { return constant_value{ static_cast<std::uint32_t>(source_value) }; } - else if constexpr (std::is_same_v<T, std::nullptr_t>) - { - return constant_value{ std::uint32_t{ 0 } }; - } else { return std::nullopt; @@ -935,17 +911,15 @@ namespace elna::boot return value; } - std::optional<constant_value> evaluator::cast_to_pointer(const constant_value& source_expression) + std::optional<constant_value> evaluator::cast_to_pointer(const constant_value& source_expression) const { - if (std::holds_alternative<std::nullptr_t>(source_expression)) + if (const auto *address = std::get_if<integer_literal>(&source_expression)) { - return source_expression; + return constant_value{ pointer_literal{ address->cast_to(false, this->target.pointer_properties.size) } }; } - // Only the null pointer has a constant representation. - else if (const auto *address = std::get_if<integer_literal>(&source_expression); - *address == std::ptrdiff_t{ 0 }) + else if (std::holds_alternative<pointer_literal>(source_expression)) { - return constant_value{ nullptr }; + return source_expression; } return std::nullopt; } diff --git a/boot/lexer.ll b/boot/lexer.ll index c6a5498..90753ba 100644 --- a/boot/lexer.ll +++ b/boot/lexer.ll @@ -150,9 +150,6 @@ true { false { return yy::parser::make_BOOLEAN(false, this->location); } -nil { - return yy::parser::make_NIL(this->location); -} \& { return yy::parser::make_AND(this->location); } diff --git a/boot/materialization.cc b/boot/materialization.cc index 9e9d3ae..c7296f9 100644 --- a/boot/materialization.cc +++ b/boot/materialization.cc @@ -37,12 +37,8 @@ namespace elna::boot return "Local symbols cannot be exported"; case local_extern: return "Local symbols cannot be extern"; - case field_export: - return "Record fields cannot be exported"; case variable_generic: return "Variables cannot have generic parameters"; - case field_generic: - return "Record fields cannot have generic parameters"; } __builtin_unreachable(); } @@ -95,28 +91,6 @@ namespace elna::boot } } - void materialization_visitor::visit(record_type_expression *expression) - { - for (const auto& [field_identifiers, field_type] : expression->fields) - { - field_type->accept(this); - - for (const auto& field_identifier : field_identifiers) - { - if (field_identifier.exported()) - { - add_error<materialization_error>(field_identifier.id().position(), - materialization_error::kind::field_export); - } - if (!field_identifier.parameters.empty()) - { - add_error<materialization_error>(field_identifier.id().position(), - materialization_error::kind::field_generic); - } - } - } - } - void materialization_visitor::visit(literal<integer_literal> *literal) { switch (literal->wants_signed) diff --git a/boot/name_analysis.cc b/boot/name_analysis.cc index 17e15f6..9b3dec4 100644 --- a/boot/name_analysis.cc +++ b/boot/name_analysis.cc @@ -1236,12 +1236,6 @@ namespace elna::boot this->current_type = type(); } - void resolving_visitor::visit(literal<std::nullptr_t> *literal) - { - literal->type_decoration = lookup_primitive_type("Pointer"); - this->current_type = type(); - } - void resolving_visitor::visit(literal<std::string> *literal) { literal->type_decoration = type(std::make_shared<slice_type>( diff --git a/boot/parser.yy b/boot/parser.yy index 855cc76..9628443 100644 --- a/boot/parser.yy +++ b/boot/parser.yy @@ -95,7 +95,6 @@ along with GCC; see the file COPYING3. If not see COLON ":" SEMICOLON ";" DOT "." COMMA "," %token PROGRAM "program" MODULE "module" CAST "cast" - NIL "nil" CONST "const" VAR "var" THREADVAR "threadvar" PROCEDURE "proc" @@ -156,8 +155,8 @@ along with GCC; see the file COPYING3. If not see %type <std::vector<elna::boot::conditional_statements>> elsif_then_statements elsif_do_statements;; %type <std::unique_ptr<elna::boot::block>> else_statements block; %type <std::unique_ptr<elna::boot::identifier>> identifier with_counter; -%type <std::unique_ptr<elna::boot::identifier_definition>> identifier_definition attributed_identifier; -%type <std::vector<elna::boot::identifier_definition>> identifier_definitions; +%type <std::unique_ptr<elna::boot::identifier_definition>> identifier_definition attributed_identifier field_identifier; +%type <std::vector<elna::boot::identifier_definition>> identifier_definitions field_identifiers; %type <std::unique_ptr<elna::boot::attribute>> attribute; %type <std::vector<elna::boot::attribute>> attributes; %type <std::pair<std::vector<std::string>, bool>> import_declaration; @@ -406,11 +405,6 @@ literal: $$ = new boot::literal<std::uint32_t>(boot::make_position(@$), $1, boot::integer_sign::_unsigned); } - | "nil" - { - $$ = new boot::literal<std::nullptr_t>(boot::make_position(@$), - nullptr, boot::integer_sign::_unsigned); - } | STRING { $$ = new boot::literal<std::string>(boot::make_position(@$), @@ -631,8 +625,21 @@ statements: $$.insert($$.cend(), $3); } | statement { $$.push_back($1); } +field_identifier: + IDENTIFIER attributes + { + $$ = std::make_unique<boot::identifier_definition>($1, boot::make_position(@1), + false, std::vector<boot::identifier>{}, std::move($2)); + } +field_identifiers: + field_identifier "," field_identifiers + { + $$ = $3; + $$.emplace($$.cbegin(), std::move(*$1)); + } + | field_identifier { $$.emplace_back(std::move(*$1)); } field_declaration: - identifier_definitions ":" type_expression + field_identifiers ":" type_expression { $$ = std::make_pair($1, std::shared_ptr<boot::type_expression>($3)); } field_declarations: field_declaration ";" field_declarations diff --git a/boot/result.cc b/boot/result.cc index 71326c0..10fb9fe 100644 --- a/boot/result.cc +++ b/boot/result.cc @@ -603,3 +603,10 @@ std::size_t std::hash<elna::boot::float_literal>::operator()(const elna::boot::f // -0.0 and 0.0 compare equal, so their hashes must agree. return std::hash<double>{}(key == 0.0 ? 0.0 : key.value()); } + +std::size_t std::hash<elna::boot::pointer_literal>::operator()( + const elna::boot::pointer_literal& key) const noexcept +{ + return std::hash<elna::boot::integer_literal>{}(key.address); +} + diff --git a/boot/symbol.cc b/boot/symbol.cc index 2805839..ffefea4 100644 --- a/boot/symbol.cc +++ b/boot/symbol.cc @@ -411,8 +411,6 @@ namespace elna::boot result->enter("Char", std::make_shared<type_info>(type(std::make_shared<primitive_type>("Char", target.char_properties)))); - const type pointer = type(std::make_shared<primitive_type>("Pointer", target.pointer_properties)); - result->enter("Pointer", std::make_shared<type_info>(pointer)); result->enter("Single", std::make_shared<type_info>(type(std::make_shared<primitive_type>("Single", target.single_properties)))); result->enter("Double", @@ -831,8 +829,7 @@ namespace elna::boot bool is_any_pointer_type(const type& checked) { - return checked.get<pointer_type>() != nullptr - || is_primitive_type(checked, "Pointer"); + return checked.get<pointer_type>() != nullptr; } bool is_scalar_type(const type& checked) diff --git a/boot/type_check.cc b/boot/type_check.cc index 31e10f1..797282c 100644 --- a/boot/type_check.cc +++ b/boot/type_check.cc @@ -406,8 +406,7 @@ namespace elna::boot /* * Scaling an offset needs the pointee size, which neither an opaque type - * nor a type parameter has. Only a pointer_type scales; the generic - * Pointer advances byte-wise. + * nor a type parameter has. */ static std::optional<type> find_arithmetic_violation(binary_operator operation, const type& lhs, const type& rhs) @@ -505,45 +504,11 @@ namespace elna::boot } } - assign_check::verdict assign_check::guard_const_laundering() const - { - if (!is_primitive_type(ctx.aliased_assignee, "Pointer")) - { - return verdict::pass; - } - if (const auto ptr = ctx.aliased_assignment.get<pointer_type>(); - ptr != nullptr && resolve_aliases(ptr->base).get<constant_type>() != nullptr) - { - return verdict::reject; - } - if (const auto const_assign = ctx.aliased_assignment.get<constant_type>(); - const_assign != nullptr && is_primitive_type(const_assign->unqualified, "Pointer")) - { - return verdict::reject; - } - return verdict::pass; - } - assign_check::verdict assign_check::check_exact_match() const { return ctx.resolved_assignee == ctx.resolved_assignment ? verdict::accept : verdict::pass; } - assign_check::verdict assign_check::check_pointer_hatch() const - { - if (is_primitive_type(ctx.resolved_assignee, "Pointer") - && is_any_pointer_type(ctx.resolved_assignment)) - { - return verdict::accept; - } - if (is_primitive_type(ctx.resolved_assignment, "Pointer") - && is_any_pointer_type(ctx.resolved_assignee)) - { - return verdict::accept; - } - return verdict::pass; - } - assign_check::verdict assign_check::check_pointer_conversion() const { const std::shared_ptr<pointer_type> assignee_ptr = ctx.resolved_assignee.get<pointer_type>(); @@ -637,11 +602,9 @@ namespace elna::boot bool assign_check::run() { const std::initializer_list assign_handlers = { - &assign_check::guard_const_laundering, &assign_check::check_exact_match, &assign_check::check_slice_conversion, &assign_check::check_array_conversion, - &assign_check::check_pointer_hatch, &assign_check::check_pointer_conversion }; for (const auto handler : assign_handlers) @@ -1153,17 +1116,10 @@ namespace elna::boot } else if (const auto left_pointer = left.get<pointer_type>()) { - if (is_primitive_type(right, "Pointer")) - { - return true; - } - else - { - const std::shared_ptr<pointer_type> right_pointer = right.get<pointer_type>(); + const std::shared_ptr<pointer_type> right_pointer = right.get<pointer_type>(); - return right_pointer != nullptr - && bind_arguments(parameters, bindings, left_pointer->base, right_pointer->base); - } + return right_pointer != nullptr + && bind_arguments(parameters, bindings, left_pointer->base, right_pointer->base); } else if (const auto left_slice = left.get<slice_type>()) { diff --git a/gcc/gcc/elna-builtins.cc b/gcc/gcc/elna-builtins.cc index 8eb5ce1..69b8229 100644 --- a/gcc/gcc/elna-builtins.cc +++ b/gcc/gcc/elna-builtins.cc @@ -142,7 +142,6 @@ namespace elna::gcc declare_builtin_type(builtin_table, "Word64", unsigned_intDI_type_node); declare_builtin_type(builtin_table, "Char", elna_char_type_node); declare_builtin_type(builtin_table, "Bool", elna_bool_type_node); - declare_builtin_type(builtin_table, "Pointer", elna_pointer_type_node); declare_builtin_type(builtin_table, "Single", float_type_node); declare_builtin_type(builtin_table, "Double", double_type_node); diff --git a/gcc/gcc/elna-generic.cc b/gcc/gcc/elna-generic.cc index bb93270..bf4784b 100644 --- a/gcc/gcc/elna-generic.cc +++ b/gcc/gcc/elna-generic.cc @@ -662,12 +662,6 @@ namespace elna::gcc this->symbols, elna_char_type_node); } - void generic_visitor::visit(boot::literal<std::nullptr_t> *) - { - this->current_expression = constant_to_tree(boot::constant_value{ std::nullptr_t{} }, - this->symbols, elna_pointer_type_node); - } - void generic_visitor::visit(boot::literal<std::string> *string) { tree slice_type = get_inner_alias(string->type_decoration, symbols); diff --git a/gcc/gcc/elna-tree.cc b/gcc/gcc/elna-tree.cc index 0f94864..9612ae2 100644 --- a/gcc/gcc/elna-tree.cc +++ b/gcc/gcc/elna-tree.cc @@ -85,12 +85,9 @@ namespace elna::gcc return field_declaration; } - // The generic Pointer has no pointee size; it advances byte by byte. static tree pointer_stride(tree pointer_type, tree offset_type) { - return pointer_type == elna_pointer_type_node - ? size_one_node - : fold_convert(offset_type, size_in_bytes(TREE_TYPE(pointer_type))); + return fold_convert(offset_type, size_in_bytes(TREE_TYPE(pointer_type))); } tree do_pointer_arithmetic(boot::binary_operator binary_operator, @@ -293,9 +290,16 @@ namespace elna::gcc { return build_int_cstu(elna_char_type_node, std::get<std::uint32_t>(constant_value)); } - else if (std::holds_alternative<std::nullptr_t>(constant_value)) + else if (std::holds_alternative<boot::pointer_literal>(constant_value)) { - return null_pointer_node; + const boot::integer_literal& address = + std::get<boot::pointer_literal>(constant_value).address; + + if (auto converted = address.try_to<std::size_t>()) + { + return build_int_cstu(type, *converted); + } + return NULL_TREE; } else if (std::holds_alternative<std::string>(constant_value)) { diff --git a/include/elna/boot/ast.h b/include/elna/boot/ast.h index e7a77ac..8f8da13 100644 --- a/include/elna/boot/ast.h +++ b/include/elna/boot/ast.h @@ -99,15 +99,9 @@ namespace elna::boot }; template<> - struct literal_type_id<std::nullptr_t> - { - static constexpr int value = 5; - }; - - template<> struct literal_type_id<std::string> { - static constexpr int value = 6; + static constexpr int value = 5; }; template<typename T> @@ -219,7 +213,6 @@ namespace elna::boot virtual void visit(literal<float_literal> *) = 0; virtual void visit(literal<bool> *) = 0; virtual void visit(literal<std::uint32_t> *) = 0; - virtual void visit(literal<std::nullptr_t> *) = 0; virtual void visit(literal<std::string> *) = 0; }; @@ -271,7 +264,6 @@ namespace elna::boot [[noreturn]] void visit(literal<float_literal> *) override; [[noreturn]] void visit(literal<bool> *) override; [[noreturn]] void visit(literal<std::uint32_t> *) override; - [[noreturn]] void visit(literal<std::nullptr_t> *) override; [[noreturn]] void visit(literal<std::string> *) override; }; @@ -321,7 +313,6 @@ namespace elna::boot void visit(literal<float_literal> *) override; void visit(literal<bool> *) override; void visit(literal<std::uint32_t> *) override; - void visit(literal<std::nullptr_t> *) override; void visit(literal<std::string> *) override; }; diff --git a/include/elna/boot/evaluator.h b/include/elna/boot/evaluator.h index 6dc204f..72e1f21 100644 --- a/include/elna/boot/evaluator.h +++ b/include/elna/boot/evaluator.h @@ -97,7 +97,7 @@ namespace elna::boot static std::optional<constant_value> cast_to_char(const constant_value& source_expression); static std::optional<constant_value> cast_to_enumeration(const constant_value& source_expression, const enumeration_type& enumeration, std::size_t target_size); - static std::optional<constant_value> cast_to_pointer(const constant_value& source_expression); + std::optional<constant_value> cast_to_pointer(const constant_value& source_expression) const; public: std::optional<std::size_t> evaluate_index(expression& subject); diff --git a/include/elna/boot/materialization.h b/include/elna/boot/materialization.h index c4abb11..74b4133 100644 --- a/include/elna/boot/materialization.h +++ b/include/elna/boot/materialization.h @@ -30,9 +30,7 @@ namespace elna::boot real_overflow, local_export, local_extern, - field_export, - variable_generic, - field_generic + variable_generic }; materialization_error(const source_position position, kind error_kind); @@ -55,8 +53,6 @@ namespace elna::boot void visit(procedure_declaration *declaration) override; void visit(variable_declaration *declaration) override; - void visit(record_type_expression *expression) override; - void visit(literal<integer_literal> *literal) override; void visit(literal<float_literal> *literal) override; }; diff --git a/include/elna/boot/name_analysis.h b/include/elna/boot/name_analysis.h index 16734cd..62b91b4 100644 --- a/include/elna/boot/name_analysis.h +++ b/include/elna/boot/name_analysis.h @@ -399,7 +399,6 @@ namespace elna::boot void visit(literal<float_literal> *literal) override; void visit(literal<bool> *literal) override; void visit(literal<std::uint32_t> *literal) override; - void visit(literal<std::nullptr_t> *literal) override; void visit(literal<std::string> *literal) override; }; diff --git a/include/elna/boot/result.h b/include/elna/boot/result.h index 540307c..2239413 100644 --- a/include/elna/boot/result.h +++ b/include/elna/boot/result.h @@ -865,6 +865,14 @@ namespace elna::boot template<template<typename, typename> typename C, template<typename> typename Alloc = std::allocator> class constant_aggregate; + struct pointer_literal + { + integer_literal address; + + bool operator==(const pointer_literal& that) const = default; + auto operator<=>(const pointer_literal& that) const = default; + }; + /** * Typed constant value produced by the constant expression evaluator. * @@ -876,7 +884,7 @@ namespace elna::boot float_literal, bool, std::uint32_t, - std::nullptr_t, + pointer_literal, std::string, constant_aggregate<ordered_map>, constant_aggregate<std::vector> @@ -1014,6 +1022,12 @@ struct std::hash<elna::boot::constant_aggregate<elna::boot::ordered_map>> }; template<> +struct std::hash<elna::boot::pointer_literal> +{ + std::size_t operator()(const elna::boot::pointer_literal& key) const noexcept; +}; + +template<> struct std::hash<elna::boot::integer_literal> { std::size_t operator()(const elna::boot::integer_literal& key) const noexcept; diff --git a/include/elna/boot/type_check.h b/include/elna/boot/type_check.h index d9a07b9..98db843 100644 --- a/include/elna/boot/type_check.h +++ b/include/elna/boot/type_check.h @@ -248,15 +248,7 @@ namespace elna::boot }; context ctx; - /** - * Checks whether derived has base in its record parent chain. - * - * Base record type must not be null. Derived record type may be null. - */ - verdict guard_const_laundering() const; - verdict check_exact_match() const; - verdict check_pointer_hatch() const; verdict check_pointer_conversion() const; verdict check_slice_conversion() const; verdict check_array_conversion() const; diff --git a/include/elna/gcc/elna-generic.h b/include/elna/gcc/elna-generic.h index 54f320e..f942f81 100644 --- a/include/elna/gcc/elna-generic.h +++ b/include/elna/gcc/elna-generic.h @@ -89,7 +89,6 @@ namespace elna::gcc void visit(boot::literal<boot::float_literal> *literal) override; void visit(boot::literal<bool> *boolean) override; void visit(boot::literal<std::uint32_t> *character) override; - void visit(boot::literal<std::nullptr_t> *) override; void visit(boot::literal<std::string> *string) override; void visit(boot::traits_expression *trait) override; void visit(boot::binary_expression *expression) override; diff --git a/rakelib/treesitter.rake b/rakelib/treesitter.rake index ca0c8d0..8ccf48f 100644 --- a/rakelib/treesitter.rake +++ b/rakelib/treesitter.rake @@ -7,6 +7,7 @@ require 'rake/clean' TREE_SITTER_BUILD = Pathname.new 'build/tree-sitter' TREE_SITTER_TREE = Pathname.new 'tools/tree-sitter' +TREE_SITTER_EXT = RUBY_PLATFORM =~ /darwin/ ? 'dylib' : 'so' CLEAN.include TREE_SITTER_BUILD @@ -28,7 +29,7 @@ namespace :ts do File.symlink (TREE_SITTER_TREE / 'test' / 'corpus').relative_path_from(build_test), build_corpus end - file "#{TREE_SITTER_BUILD}/parser.so" => "#{TREE_SITTER_BUILD}/src/parser.c" do |t| + file "#{TREE_SITTER_BUILD}/parser.#{TREE_SITTER_EXT}" => "#{TREE_SITTER_BUILD}/src/parser.c" do |t| sh 'build/host/install/bin/gcc', '-O2', '-Wall', '-fPIC', '-shared', t.source, '-o', t.name end @@ -61,4 +62,4 @@ namespace :ts do end desc 'Build a tree-sitter parser' -task ts: ['ts:generate', "#{TREE_SITTER_BUILD}/parser.so"] +task ts: ['ts:generate', "#{TREE_SITTER_BUILD}/parser.#{TREE_SITTER_EXT}"] diff --git a/testsuite/compilable/assign_record_to_base.elna b/testsuite/compilable/assign_record_to_base.elna index 14bc3f5..3909386 100644 --- a/testsuite/compilable/assign_record_to_base.elna +++ b/testsuite/compilable/assign_record_to_base.elna @@ -8,8 +8,8 @@ type end var - x: ^B := nil - y: ^R := nil + x: ^B + y: ^R begin x := y diff --git a/testsuite/compilable/generic_alias.elna b/testsuite/compilable/generic_alias.elna index da9501a..8450253 100644 --- a/testsuite/compilable/generic_alias.elna +++ b/testsuite/compilable/generic_alias.elna @@ -22,7 +22,7 @@ var boxed: Boxed#[File] begin - chain.next := nil; + chain.next := cast(0u: ^Node#[File]); aliased := raw; raw := aliased; boxed.inner := @chain diff --git a/testsuite/compilable/generic_arguments.elna b/testsuite/compilable/generic_arguments.elna index 1cda57f..7312efe 100644 --- a/testsuite/compilable/generic_arguments.elna +++ b/testsuite/compilable/generic_arguments.elna @@ -20,7 +20,7 @@ return entry_ptr^.key begin entry.key := allocate#[File](#size(File)); - assert(#size(Pair#[File, Word8]) = #size(Pointer) * 2u); - assert(#offset(Pair#[File, Word8], value) = #size(Pointer)); + assert(#size(Pair#[File, Word8]) = #size(^Word8) * 2u); + assert(#offset(Pair#[File, Word8], value) = #size(^Word8)); assert(first#[File, Word8](@entry) = entry.key) end. diff --git a/testsuite/compilable/generic_const_inference.elna b/testsuite/compilable/generic_const_inference.elna index 7ce197f..c9be090 100644 --- a/testsuite/compilable/generic_const_inference.elna +++ b/testsuite/compilable/generic_const_inference.elna @@ -6,9 +6,9 @@ type var slice: []const Word8 - aliased: ConstAlias := nil - nested: NestedConst := nil - direct_const: const ^Word8 := nil + aliased: ConstAlias := cast(0u: ConstAlias) + nested: NestedConst := cast(0u: NestedConst) + direct_const: const ^Word8 := cast(0u: const ^Word8) proc write#[T](fd: Int; buf: ^T; count: Int) -> Int return 0 diff --git a/testsuite/compilable/generic_inference.elna b/testsuite/compilable/generic_inference.elna index 9d7fed6..e5e6e3b 100644 --- a/testsuite/compilable/generic_inference.elna +++ b/testsuite/compilable/generic_inference.elna @@ -25,5 +25,5 @@ return begin store(@files, @f); relay(@bytes, @b); - store(@files, nil) + store(@files, cast(0u: ^File)) end. diff --git a/testsuite/compilable/generic_pointee.elna b/testsuite/compilable/generic_pointee.elna index 5ecaedf..b9ee739 100644 --- a/testsuite/compilable/generic_pointee.elna +++ b/testsuite/compilable/generic_pointee.elna @@ -12,6 +12,5 @@ var f: ^File begin - f := allocate#[File](#size(File)); - assert(f = nil) + f := allocate#[File](#size(File)) end. diff --git a/testsuite/compilable/opaque_type.elna b/testsuite/compilable/opaque_type.elna index 6474337..751e6ce 100644 --- a/testsuite/compilable/opaque_type.elna +++ b/testsuite/compilable/opaque_type.elna @@ -4,7 +4,7 @@ type Alias = Handle var - handle: ^Handle := nil + handle: ^Handle alias: ^Alias proc take(h: ^Handle) -> ^Handle diff --git a/testsuite/compilable/pointer_cast.elna b/testsuite/compilable/pointer_cast.elna index 2b986c0..08f9fe7 100644 --- a/testsuite/compilable/pointer_cast.elna +++ b/testsuite/compilable/pointer_cast.elna @@ -1,9 +1,9 @@ program() var - c: ^Char := nil - p: Pointer := nil + c: ^Char + b: ^Word8 begin - p := c; - c := p + b := cast(c: ^Word8); + c := cast(b: ^Char) end. diff --git a/testsuite/compilable/traits_size.elna b/testsuite/compilable/traits_size.elna index ad49b61..282ff25 100644 --- a/testsuite/compilable/traits_size.elna +++ b/testsuite/compilable/traits_size.elna @@ -4,7 +4,7 @@ var s: Int := cast(#size(Int): Int) a: [10]Int as: Int := cast(#size([10]Int): Int) - p: Int := cast(#size(Pointer): Int) + p: Int := cast(#size(^Word8): Int) begin assert(s > 0); diff --git a/testsuite/fail_compilation/assign_const_to_pointer.elna b/testsuite/fail_compilation/assign_const_to_pointer.elna deleted file mode 100644 index 796b60c..0000000 --- a/testsuite/fail_compilation/assign_const_to_pointer.elna +++ /dev/null @@ -1,8 +0,0 @@ -program() -var - c: const Int := 2 - p: Pointer - -begin - p := @c (* @Error Expected type 'Pointer', but got '\^const Int' *) -end. diff --git a/testsuite/fail_compilation/assign_from_const_pointer.elna b/testsuite/fail_compilation/assign_from_const_pointer.elna deleted file mode 100644 index 64f7f5d..0000000 --- a/testsuite/fail_compilation/assign_from_const_pointer.elna +++ /dev/null @@ -1,8 +0,0 @@ -program() -var - cv: const Pointer := nil - p: Pointer - -begin - p := cv (* @Error Expected type 'Pointer', but got 'const Pointer' *) -end. diff --git a/testsuite/runnable/generic_base.elna b/testsuite/runnable/generic_base.elna index 161c59d..7b371ad 100644 --- a/testsuite/runnable/generic_base.elna +++ b/testsuite/runnable/generic_base.elna @@ -36,5 +36,5 @@ begin assert(jobs.count = 1u); assert(jobs.head = @f); assert(jobs.tail = @f); - assert(#size(Queue#[File]) = #size(Pointer) * 3u) + assert(#size(Queue#[File]) = #size(^Word8) * 3u) end. diff --git a/testsuite/runnable/generic_pointer_arithmetic.elna b/testsuite/runnable/generic_pointer_arithmetic.elna index 209287d..abbca4b 100644 --- a/testsuite/runnable/generic_pointer_arithmetic.elna +++ b/testsuite/runnable/generic_pointer_arithmetic.elna @@ -2,13 +2,13 @@ program() var base: [4]Int element: ^Int - first: Pointer - second: Pointer + first: ^Word8 + second: ^Word8 begin element := base.ptr; - first := element; + first := cast(element: ^Word8); second := first + 1; - assert(cast(second : Word) - cast(first : Word) = 1u); + assert(cast(second: Word) - cast(first: Word) = 1u); assert(second - 1 = first) end. diff --git a/testsuite/runnable/procedure_cast.elna b/testsuite/runnable/procedure_cast.elna index d724e38..0e8aa92 100644 --- a/testsuite/runnable/procedure_cast.elna +++ b/testsuite/runnable/procedure_cast.elna @@ -7,5 +7,5 @@ return 42 begin cb := cast(@probe_int: ^proc(x: ^Char) -> Int); - assert(cb^(nil) = 42) + assert(cb^(cast(0u: ^Char)) = 42) end. diff --git a/testsuite/runnable/recursive_record.elna b/testsuite/runnable/recursive_record.elna index 48fb873..1667bf4 100644 --- a/testsuite/runnable/recursive_record.elna +++ b/testsuite/runnable/recursive_record.elna @@ -10,10 +10,10 @@ var second: ^Node third: ^Node -proc malloc(size: Word) -> Pointer +proc malloc#[T](size: Word) -> ^T extern -proc free(ptr: Pointer) +proc free#[T](ptr: ^T) extern proc sum(node: ^Node) -> Int @@ -21,7 +21,7 @@ var result: Int begin result := 0; - if node = nil then + if node = cast(0u: ^Node) then result := 0 else result := node^.value + sum(node^.next) @@ -29,16 +29,16 @@ begin return result begin - first := malloc(#size(Node)); - second := malloc(#size(Node)); - third := malloc(#size(Node)); + first := malloc#[Node](#size(Node)); + second := malloc#[Node](#size(Node)); + third := malloc#[Node](#size(Node)); first^.value := 1; first^.next := second; second^.value := 2; second^.next := third; third^.value := 3; - third^.next := nil; + third^.next := cast(0u: ^Node); assert(sum(first) = 6); assert(first^.next^.next^.value = 3); diff --git a/tools/tree-sitter/grammar.js b/tools/tree-sitter/grammar.js index b854e82..9e62a78 100644 --- a/tools/tree-sitter/grammar.js +++ b/tools/tree-sitter/grammar.js @@ -102,13 +102,13 @@ module.exports = grammar({ type_declaration: $ => seq( field('name', $.identifier_definition), - optional(field('type_parameters', $.type_parameters)), '=', field('type', choice($._type_expression, 'extern')), ), identifier_definition: $ => seq( field('name', $.identifier), + optional(field('type_parameters', $.type_parameters)), optional(field('exported', '*')), repeat($.attribute), ), @@ -149,7 +149,6 @@ module.exports = grammar({ procedure_declaration: $ => seq( 'proc', field('name', $.identifier_definition), - optional(field('type_parameters', $.type_parameters)), field('parameters', $.parameter_list), repeat($.attribute), optional(seq('->', field('return_type', $._type_expression))), @@ -169,8 +168,13 @@ module.exports = grammar({ ')', ), + field_identifier: $ => seq( + field('name', $.identifier), + repeat($.attribute), + ), + field_declaration: $ => seq( - field('names', commaSep1($.identifier_definition)), + field('names', commaSep1($.field_identifier)), ':', field('type', $._type_expression), ), @@ -519,11 +523,9 @@ module.exports = grammar({ $.byte, $.character, $.boolean, - $.nil, ), boolean: $ => choice('true', 'false'), - nil: $ => 'nil', integer: $ => token(choice( seq(/0[xX][0-9a-fA-F]+/, optional(choice('u8', 'u16', 'u32', 'u64'))), diff --git a/tools/tree-sitter/queries/elna/highlights.scm b/tools/tree-sitter/queries/elna/highlights.scm index 4cb3f7c..d9acf8d 100644 --- a/tools/tree-sitter/queries/elna/highlights.scm +++ b/tools/tree-sitter/queries/elna/highlights.scm @@ -52,7 +52,6 @@ (integer) @number (float) @number.float (boolean) @boolean -(nil) @constant.builtin (string) @string (character) @character @@ -73,7 +72,7 @@ "Int8" "Int16" "Int32" "Int64" "Word8" "Word16" "Word32" "Word64" "Single" "Double" - "Char" "Pointer" "Bool")) + "Char" "Bool")) ; Declarations and Definitions (type_declaration @@ -112,12 +111,12 @@ exported: "*" @punctuation.special) (field_declaration - names: (identifier_definition + names: (field_identifier name: (identifier) @variable.member)) (parameter_list (field_declaration - names: (identifier_definition + names: (field_identifier name: (identifier) @variable.parameter))) (variable_declaration diff --git a/tools/tree-sitter/queries/elna/locals.scm b/tools/tree-sitter/queries/elna/locals.scm index 1e9bb70..ad0af7e 100644 --- a/tools/tree-sitter/queries/elna/locals.scm +++ b/tools/tree-sitter/queries/elna/locals.scm @@ -19,7 +19,7 @@ (parameter_list (field_declaration - names: (identifier_definition + names: (field_identifier name: (identifier) @local.definition))) (for_statement diff --git a/tools/tree-sitter/test/corpus/assign_record_to_base.txt b/tools/tree-sitter/test/corpus/assign_record_to_base.txt index 6488889..f0d44c6 100644 --- a/tools/tree-sitter/test/corpus/assign_record_to_base.txt +++ b/tools/tree-sitter/test/corpus/assign_record_to_base.txt @@ -12,8 +12,8 @@ type end var - x: ^B := nil - y: ^R := nil + x: ^B + y: ^R begin x := y @@ -29,7 +29,7 @@ end. (identifier)) (record_type (field_declaration - (identifier_definition + (field_identifier (identifier)) (identifier)))) (type_declaration @@ -38,7 +38,7 @@ end. (record_type (identifier) (field_declaration - (identifier_definition + (field_identifier (identifier)) (identifier))))) (var_section @@ -46,16 +46,12 @@ end. (identifier_definition (identifier)) (pointer_type - (identifier)) - (literal - (nil))) + (identifier))) (variable_declaration (identifier_definition (identifier)) (pointer_type - (identifier)) - (literal - (nil)))) + (identifier)))) (assignment_statement (identifier) (identifier)))) diff --git a/tools/tree-sitter/test/corpus/block_variables.txt b/tools/tree-sitter/test/corpus/block_variables.txt new file mode 100644 index 0000000..8c6698c --- /dev/null +++ b/tools/tree-sitter/test/corpus/block_variables.txt @@ -0,0 +1,25 @@ +================== +block_variables +================== + +program() + +begin + block b + var + x: Int + end +end. + +--- + +(source_file + (program_declaration + (block_statement + (identifier) + (block + (var_section + (variable_declaration + (identifier_definition + (identifier)) + (identifier))))))) diff --git a/tools/tree-sitter/test/corpus/comments.txt b/tools/tree-sitter/test/corpus/comments.txt index 8c933ea..2048f53 100644 --- a/tools/tree-sitter/test/corpus/comments.txt +++ b/tools/tree-sitter/test/corpus/comments.txt @@ -6,10 +6,10 @@ module (* This is multi-line - dockblock + docblock *) --- This is a one-line comment. +-- This is a single-line comment. end. diff --git a/tools/tree-sitter/test/corpus/generic_alias.txt b/tools/tree-sitter/test/corpus/generic_alias.txt index 54a8ea2..c335afa 100644 --- a/tools/tree-sitter/test/corpus/generic_alias.txt +++ b/tools/tree-sitter/test/corpus/generic_alias.txt @@ -26,7 +26,7 @@ var boxed: Boxed#[File] begin - chain.next := nil; + chain.next := cast(0u: ^Node#[File]); aliased := raw; raw := aliased; boxed.inner := @chain @@ -42,17 +42,17 @@ end. (identifier)) (record_type (field_declaration - (identifier_definition + (field_identifier (identifier)) (identifier)))) (type_declaration (identifier_definition - (identifier)) - (type_parameters - (identifier)) + (identifier) + (type_parameters + (identifier))) (record_type (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (generic_type @@ -60,25 +60,25 @@ end. (type_arguments (identifier))))) (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (identifier))))) (type_declaration (identifier_definition - (identifier)) - (type_parameters - (identifier)) + (identifier) + (type_parameters + (identifier))) (pointer_type (identifier))) (type_declaration (identifier_definition - (identifier)) - (type_parameters - (identifier)) + (identifier) + (type_parameters + (identifier))) (record_type (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (generic_type @@ -116,8 +116,14 @@ end. (field_expression (identifier) (identifier)) - (literal - (nil))) + (cast_expression + (literal + (integer)) + (pointer_type + (generic_type + (identifier) + (type_arguments + (identifier)))))) (assignment_statement (identifier) (identifier)) diff --git a/tools/tree-sitter/test/corpus/generic_arguments.txt b/tools/tree-sitter/test/corpus/generic_arguments.txt index 3f325de..227efd9 100644 --- a/tools/tree-sitter/test/corpus/generic_arguments.txt +++ b/tools/tree-sitter/test/corpus/generic_arguments.txt @@ -24,8 +24,8 @@ return entry_ptr^.key begin entry.key := allocate#[File](#size(File)); - assert(#size(Pair#[File, Word8]) = #size(Pointer) * 2u); - assert(#offset(Pair#[File, Word8], value) = #size(Pointer)); + assert(#size(Pair#[File, Word8]) = #size(^Word8) * 2u); + assert(#offset(Pair#[File, Word8], value) = #size(^Word8)); assert(first#[File, Word8](@entry) = entry.key) end. @@ -39,23 +39,23 @@ end. (identifier)) (record_type (field_declaration - (identifier_definition + (field_identifier (identifier)) (identifier)))) (type_declaration (identifier_definition - (identifier)) - (type_parameters (identifier) - (identifier)) + (type_parameters + (identifier) + (identifier))) (record_type (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (identifier))) (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (identifier)))))) @@ -70,25 +70,25 @@ end. (identifier))))) (procedure_declaration (identifier_definition - (identifier)) - (type_parameters - (identifier)) + (identifier) + (type_parameters + (identifier))) (parameter_list (field_declaration - (identifier_definition + (field_identifier (identifier)) (identifier))) (pointer_type (identifier))) (procedure_declaration (identifier_definition - (identifier)) - (type_parameters (identifier) - (identifier)) + (type_parameters + (identifier) + (identifier))) (parameter_list (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (generic_type @@ -131,7 +131,8 @@ end. (binary_expression (traits_expression (trait) - (identifier)) + (pointer_type + (identifier))) (literal (integer)))))) (call_expression @@ -148,7 +149,8 @@ end. (identifier)) (traits_expression (trait) - (identifier))))) + (pointer_type + (identifier)))))) (call_expression (identifier) (argument_list diff --git a/tools/tree-sitter/test/corpus/generic_base_chain.txt b/tools/tree-sitter/test/corpus/generic_base_chain.txt index 770b7db..c208c76 100644 --- a/tools/tree-sitter/test/corpus/generic_base_chain.txt +++ b/tools/tree-sitter/test/corpus/generic_base_chain.txt @@ -42,32 +42,32 @@ end. (identifier)) (record_type (field_declaration - (identifier_definition + (field_identifier (identifier)) (identifier)))) (type_declaration (identifier_definition - (identifier)) - (type_parameters (identifier) - (identifier)) + (type_parameters + (identifier) + (identifier))) (record_type (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (identifier))) (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (identifier))))) (type_declaration (identifier_definition - (identifier)) - (type_parameters (identifier) - (identifier)) + (type_parameters + (identifier) + (identifier))) (record_type (generic_type (identifier) @@ -75,7 +75,7 @@ end. (identifier) (identifier))) (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (identifier)))))) @@ -104,13 +104,13 @@ end. (identifier)))))) (procedure_declaration (identifier_definition - (identifier)) - (type_parameters (identifier) - (identifier)) + (type_parameters + (identifier) + (identifier))) (parameter_list (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (generic_type @@ -119,7 +119,7 @@ end. (identifier) (identifier))))) (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (identifier)))) diff --git a/tools/tree-sitter/test/corpus/generic_const_inference.txt b/tools/tree-sitter/test/corpus/generic_const_inference.txt index e4b5bf9..677db20 100644 --- a/tools/tree-sitter/test/corpus/generic_const_inference.txt +++ b/tools/tree-sitter/test/corpus/generic_const_inference.txt @@ -10,9 +10,9 @@ type var slice: []const Word8 - aliased: ConstAlias := nil - nested: NestedConst := nil - direct_const: const ^Word8 := nil + aliased: ConstAlias := cast(0u: ConstAlias) + nested: NestedConst := cast(0u: NestedConst) + direct_const: const ^Word8 := cast(0u: const ^Word8) proc write#[T](fd: Int; buf: ^T; count: Int) -> Int return 0 @@ -63,39 +63,47 @@ end. (identifier_definition (identifier)) (identifier) - (literal - (nil))) + (cast_expression + (literal + (integer)) + (identifier))) (variable_declaration (identifier_definition (identifier)) (identifier) - (literal - (nil))) + (cast_expression + (literal + (integer)) + (identifier))) (variable_declaration (identifier_definition (identifier)) (const_type (pointer_type (identifier))) - (literal - (nil)))) + (cast_expression + (literal + (integer)) + (const_type + (pointer_type + (identifier)))))) (procedure_declaration (identifier_definition - (identifier)) - (type_parameters - (identifier)) + (identifier) + (type_parameters + (identifier))) (parameter_list (field_declaration - (identifier_definition + (field_identifier (identifier)) (identifier)) (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (identifier))) (field_declaration - (identifier_definition + (field_identifier (identifier)) (identifier))) (identifier) @@ -105,22 +113,22 @@ end. (integer))))) (procedure_declaration (identifier_definition - (identifier)) - (type_parameters - (identifier)) + (identifier) + (type_parameters + (identifier))) (parameter_list (field_declaration - (identifier_definition + (field_identifier (identifier)) (identifier)) (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (const_type (identifier)))) (field_declaration - (identifier_definition + (field_identifier (identifier)) (identifier))) (identifier) diff --git a/tools/tree-sitter/test/corpus/generic_export.txt b/tools/tree-sitter/test/corpus/generic_export.txt new file mode 100644 index 0000000..52e767e --- /dev/null +++ b/tools/tree-sitter/test/corpus/generic_export.txt @@ -0,0 +1,53 @@ +================== +generic_export +================== + +module + +type + Stack#[T]* = record + item: ^T + end + +proc push#[T]*(s: ^Stack#[T]; item: ^T) +return + +end. + +--- + +(source_file + (module_declaration + (type_section + (type_declaration + (identifier_definition + (identifier) + (type_parameters + (identifier))) + (record_type + (field_declaration + (field_identifier + (identifier)) + (pointer_type + (identifier)))))) + (procedure_declaration + (identifier_definition + (identifier) + (type_parameters + (identifier))) + (parameter_list + (field_declaration + (field_identifier + (identifier)) + (pointer_type + (generic_type + (identifier) + (type_arguments + (identifier))))) + (field_declaration + (field_identifier + (identifier)) + (pointer_type + (identifier)))) + (procedure_body + (return_clause))))) diff --git a/tools/tree-sitter/test/corpus/generic_inference.txt b/tools/tree-sitter/test/corpus/generic_inference.txt index ccac55c..1ee0b71 100644 --- a/tools/tree-sitter/test/corpus/generic_inference.txt +++ b/tools/tree-sitter/test/corpus/generic_inference.txt @@ -29,7 +29,7 @@ return begin store(@files, @f); relay(@bytes, @b); - store(@files, nil) + store(@files, cast(0u: ^File)) end. --- @@ -42,17 +42,17 @@ end. (identifier)) (record_type (field_declaration - (identifier_definition + (field_identifier (identifier)) (identifier)))) (type_declaration (identifier_definition - (identifier)) - (type_parameters - (identifier)) + (identifier) + (type_parameters + (identifier))) (record_type (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (identifier)))))) @@ -81,12 +81,12 @@ end. (identifier))) (procedure_declaration (identifier_definition - (identifier)) - (type_parameters - (identifier)) + (identifier) + (type_parameters + (identifier))) (parameter_list (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (generic_type @@ -94,7 +94,7 @@ end. (type_arguments (identifier))))) (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (identifier)))) @@ -109,12 +109,12 @@ end. (return_clause))) (procedure_declaration (identifier_definition - (identifier)) - (type_parameters - (identifier)) + (identifier) + (type_parameters + (identifier))) (parameter_list (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (generic_type @@ -122,7 +122,7 @@ end. (type_arguments (identifier))))) (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (identifier)))) @@ -153,5 +153,8 @@ end. (argument_list (unary_expression (identifier)) - (literal - (nil)))))) + (cast_expression + (literal + (integer)) + (pointer_type + (identifier))))))) diff --git a/tools/tree-sitter/test/corpus/generic_pointee.txt b/tools/tree-sitter/test/corpus/generic_pointee.txt index 55f5a1a..515e985 100644 --- a/tools/tree-sitter/test/corpus/generic_pointee.txt +++ b/tools/tree-sitter/test/corpus/generic_pointee.txt @@ -16,8 +16,7 @@ var f: ^File begin - f := allocate#[File](#size(File)); - assert(f = nil) + f := allocate#[File](#size(File)) end. --- @@ -30,17 +29,17 @@ end. (identifier)) (record_type (field_declaration - (identifier_definition + (field_identifier (identifier)) (identifier))))) (procedure_declaration (identifier_definition - (identifier)) - (type_parameters - (identifier)) + (identifier) + (type_parameters + (identifier))) (parameter_list (field_declaration - (identifier_definition + (field_identifier (identifier)) (identifier))) (pointer_type @@ -61,11 +60,4 @@ end. (argument_list (traits_expression (trait) - (identifier))))) - (call_expression - (identifier) - (argument_list - (binary_expression - (identifier) - (literal - (nil))))))) + (identifier))))))) diff --git a/tools/tree-sitter/test/corpus/opaque_type.txt b/tools/tree-sitter/test/corpus/opaque_type.txt index 7182bb9..e4fba94 100644 --- a/tools/tree-sitter/test/corpus/opaque_type.txt +++ b/tools/tree-sitter/test/corpus/opaque_type.txt @@ -8,7 +8,7 @@ type Alias = Handle var - handle: ^Handle := nil + handle: ^Handle alias: ^Alias proc take(h: ^Handle) -> ^Handle @@ -35,9 +35,7 @@ end. (identifier_definition (identifier)) (pointer_type - (identifier)) - (literal - (nil))) + (identifier))) (variable_declaration (identifier_definition (identifier)) @@ -48,7 +46,7 @@ end. (identifier)) (parameter_list (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (identifier)))) diff --git a/tools/tree-sitter/test/corpus/pointer_cast.txt b/tools/tree-sitter/test/corpus/pointer_cast.txt index 63a28ab..42d66fa 100644 --- a/tools/tree-sitter/test/corpus/pointer_cast.txt +++ b/tools/tree-sitter/test/corpus/pointer_cast.txt @@ -4,12 +4,12 @@ pointer_cast program() var - c: ^Char := nil - p: Pointer := nil + c: ^Char + b: ^Word8 begin - p := c; - c := p + b := cast(c: ^Word8); + c := cast(b: ^Char) end. --- @@ -21,18 +21,21 @@ end. (identifier_definition (identifier)) (pointer_type - (identifier)) - (literal - (nil))) + (identifier))) (variable_declaration (identifier_definition (identifier)) - (identifier) - (literal - (nil)))) + (pointer_type + (identifier)))) (assignment_statement (identifier) - (identifier)) + (cast_expression + (identifier) + (pointer_type + (identifier)))) (assignment_statement (identifier) - (identifier)))) + (cast_expression + (identifier) + (pointer_type + (identifier)))))) diff --git a/tools/tree-sitter/test/corpus/pointer_subtraction.txt b/tools/tree-sitter/test/corpus/pointer_subtraction.txt index 3e28de8..9b9b687 100644 --- a/tools/tree-sitter/test/corpus/pointer_subtraction.txt +++ b/tools/tree-sitter/test/corpus/pointer_subtraction.txt @@ -18,9 +18,9 @@ end. (identifier)) (parameter_list (field_declaration - (identifier_definition + (field_identifier (identifier)) - (identifier_definition + (field_identifier (identifier)) (pointer_type (identifier)))) diff --git a/tools/tree-sitter/test/corpus/record_const_base.txt b/tools/tree-sitter/test/corpus/record_const_base.txt index e6f7cc6..2d7f96c 100644 --- a/tools/tree-sitter/test/corpus/record_const_base.txt +++ b/tools/tree-sitter/test/corpus/record_const_base.txt @@ -33,7 +33,7 @@ end. (identifier)) (record_type (field_declaration - (identifier_definition + (field_identifier (identifier)) (identifier)))) (type_declaration @@ -47,7 +47,7 @@ end. (record_type (identifier) (field_declaration - (identifier_definition + (field_identifier (identifier)) (identifier))))) (procedure_declaration diff --git a/tools/tree-sitter/test/corpus/self-referencing-record.txt b/tools/tree-sitter/test/corpus/self-referencing-record.txt index 02948f3..00a37e9 100644 --- a/tools/tree-sitter/test/corpus/self-referencing-record.txt +++ b/tools/tree-sitter/test/corpus/self-referencing-record.txt @@ -21,7 +21,7 @@ end. (identifier)) (record_type (field_declaration - (identifier_definition + (field_identifier (identifier)) (pointer_type (identifier)))))))) diff --git a/tools/tree-sitter/test/corpus/semicolon_parameter_separator.txt b/tools/tree-sitter/test/corpus/semicolon_parameter_separator.txt index f9c1f14..df5e335 100644 --- a/tools/tree-sitter/test/corpus/semicolon_parameter_separator.txt +++ b/tools/tree-sitter/test/corpus/semicolon_parameter_separator.txt @@ -18,11 +18,11 @@ end. (identifier)) (parameter_list (field_declaration - (identifier_definition + (field_identifier (identifier)) (identifier)) (field_declaration - (identifier_definition + (field_identifier (identifier)) (identifier))) (procedure_body diff --git a/tools/tree-sitter/test/corpus/traits_size.txt b/tools/tree-sitter/test/corpus/traits_size.txt index f566e0c..b9a96b0 100644 --- a/tools/tree-sitter/test/corpus/traits_size.txt +++ b/tools/tree-sitter/test/corpus/traits_size.txt @@ -8,7 +8,7 @@ var s: Int := cast(#size(Int): Int) a: [10]Int as: Int := cast(#size([10]Int): Int) - p: Int := cast(#size(Pointer): Int) + p: Int := cast(#size(^Word8): Int) begin assert(s > 0); @@ -62,7 +62,8 @@ end. (cast_expression (traits_expression (trait) - (identifier)) + (pointer_type + (identifier))) (identifier)))) (call_expression (identifier) |
