diff --git a/example.elna b/example.elna index 9526d90..9354c51 100644 --- a/example.elna +++ b/example.elna @@ -135,8 +135,29 @@ begin writei(x) end; +proc test_return_int(): Int; +begin + writei(""); + writei("Test return int:"); + return 5 +end; + proc exit(code: Int); extern; +proc test_add_pointer(); +var x: Int, p1: pointer to Int; +begin + writei(""); + writei("Test add pointer:"); + + x := 5; + p1 := @x; + writei(p1); + + p1 := p1 + 2; + writei(p1) +end; + begin test_primitive(); test_string(); @@ -149,6 +170,8 @@ begin test_param(8, 7); test_const_char(); test_union(); + writei(test_return_int()); + test_add_pointer(); exit(0) end. diff --git a/gcc/elna-convert.cc b/gcc/elna-convert.cc index b731494..d338150 100644 --- a/gcc/elna-convert.cc +++ b/gcc/elna-convert.cc @@ -10,5 +10,5 @@ tree convert(tree /* type */, tree expr) { - return expr; + return expr; } diff --git a/gcc/elna-diagnostic.cc b/gcc/elna-diagnostic.cc index fda487f..5693064 100644 --- a/gcc/elna-diagnostic.cc +++ b/gcc/elna-diagnostic.cc @@ -20,6 +20,10 @@ namespace gcc { return "Int"; } + else if (type == unsigned_type_node) + { + return "Word"; + } else if (type == boolean_type_node) { return "Bool"; diff --git a/gcc/elna-generic.cc b/gcc/elna-generic.cc index 1f0c3d7..0c38694 100644 --- a/gcc/elna-generic.cc +++ b/gcc/elna-generic.cc @@ -42,6 +42,10 @@ namespace gcc { format_number = "%d\n"; } + else if (argument_type == unsigned_type_node) + { + format_number = "%u\n"; + } else if (argument_type == double_type_node) { format_number = "%f\n"; @@ -316,6 +320,16 @@ namespace gcc tree_code operator_code = ERROR_MARK; tree target_type = error_mark_node; + if (is_pointer_type(left_type) + && (right_type == integer_type_node || right_type == unsigned_type_node) + && expression->operation() == source::binary_operator::sum) + { + tree convert_expression = build1_loc(expression_location, CONVERT_EXPR, + sizetype, right); + this->current_expression = build2_loc(expression_location, + POINTER_PLUS_EXPR, left_type, left, convert_expression); + return; + } if (left_type != right_type) { error_at(expression_location, diff --git a/gcc/elna-tree.cc b/gcc/elna-tree.cc index a4c3156..bca2a5b 100644 --- a/gcc/elna-tree.cc +++ b/gcc/elna-tree.cc @@ -74,6 +74,7 @@ namespace gcc std::make_shared>(); initial_table->enter("Int", source::make_info(integer_type_node)); + initial_table->enter("Word", source::make_info(unsigned_type_node)); initial_table->enter("Bool", source::make_info(boolean_type_node)); initial_table->enter("Float", source::make_info(double_type_node)); initial_table->enter("Char", source::make_info(elna_char_type_node));