Mark @ nodes addressable

This commit is contained in:
Eugen Wissner 2025-01-30 23:09:51 +01:00
parent 1b90829299
commit 45898bb95f
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
5 changed files with 68 additions and 21 deletions

View File

@ -61,7 +61,7 @@ statement_list = statement {";" statement };
condition = "odd" expression |
expression ("="|"#"|"<"|"<="|">"|">=") expression;
comparison_operator = "=", "/=", "<", ">", "<=", ">=";
comparison_operator = "=", "<>", "<", ">", "<=", ">=";
unary_prefix = "not", "@";
expression = logical_operand { ("and" | "or") logical_operand };

View File

@ -27,7 +27,7 @@ const
TOKEN_SEMICOLON = 40, TOKEN_DOT = 41, TOKEN_COMMA = 42,
TOKEN_PLUS = 43, TOKEN_MINUS = 44, TOKEN_MULTIPLICATION = 45, TOKEN_DIVISION = 46,
TOKEN_REMAINDER = 47, TOKEN_ASSIGNMENT = 48, TOKEN_COLON = 49, TOKEN_HAT = 50,
TOKEN_AT = 51;
TOKEN_AT = 51, TOKEN_COMMENT = 52, TOKEN_INTEGER = 53;
(*
External procedures.
@ -51,6 +51,8 @@ proc strncpy(dst: pointer to Char, src: pointer to Char, dsize: Word): pointer t
proc strncpy(dst: pointer to Char, src: pointer to Char, dsize: Word): pointer to Char; extern;
proc strlen(ptr: pointer to Char): Word; extern;
proc strtol(nptr: pointer to Char, endptr: pointer to pointer to Char, base: Int): Int; extern;
proc exit(code: Int); extern;
(*
@ -185,6 +187,22 @@ begin
return input
end;
proc lex_comment(input: pointer to Char): pointer to Char;
var
current: pointer to Char,
next: pointer to Char;
begin
while input^ <> '\0' do
next := input + 1;
if input^ = '*' and next^ = ')' then
return next + 1
end;
input := input + 1
end;
return nil
end;
proc print_tokens(tokens: pointer to Token, tokens_size: Int);
var
current_token: pointer to Token,
@ -300,6 +318,12 @@ begin
write_s("^")
elsif current_token^.kind = TOKEN_AT then
write_s("@")
elsif current_token^.kind = TOKEN_COMMENT then
write_s("COMMENT")
elsif current_token^.kind = TOKEN_INTEGER then
write_c('<');
write_i(current_token^.value.int_value);
write_c('>')
else
write_s("UNKNOWN<");
write_i(current_token^.kind);
@ -411,10 +435,30 @@ begin
current_token^ := categorize_identifier(input_pointer, token_length);
input_pointer := token_end
elsif is_digit(input_pointer^) then
token_end := cast(nil as pointer to Char);
current_token^.value.int_value := strtol(input_pointer, @token_end, 10);
current_token^.kind := TOKEN_INTEGER;
input_pointer := token_end
elsif input_pointer^ = '(' then
current_token^.kind := TOKEN_LEFT_PAREN;
input_pointer := input_pointer + 1
input_pointer := input_pointer + 1;
if input_pointer^ = '*' then
token_end := lex_comment(input_pointer + 1);
if token_end <> cast(nil as pointer to Char) then
token_length := cast(token_end as Int) - cast(input_pointer as Int);
current_token^.value.string_value := cast(calloc(token_length + 1, 1) as pointer to Char);
strncpy(current_token^.value.string_value, input_pointer, token_length);
current_token^.kind := TOKEN_COMMENT;
input_pointer := token_end
else
current_token^.kind := 0
end
else
current_token^.kind := TOKEN_LEFT_PAREN
end
elsif input_pointer^ = ')' then
current_token^.kind := TOKEN_RIGHT_PAREN;
input_pointer := input_pointer + 1

View File

@ -9,6 +9,7 @@
#include "realmpfr.h"
#include "stor-layout.h"
#include "varasm.h"
#include "fold-const.h"
#include <set>
namespace elna
@ -393,9 +394,11 @@ namespace gcc
switch (expression->operation())
{
case source::unary_operator::reference:
this->current_expression = build1_loc(get_location(&expression->position()), ADDR_EXPR,
build_pointer_type_for_mode(TREE_TYPE(this->current_expression), VOIDmode, true),
this->current_expression);
TREE_ADDRESSABLE(this->current_expression) = 1;
this->current_expression = build_fold_addr_expr_with_type_loc(get_location(&expression->position()),
this->current_expression,
build_pointer_type_for_mode(TREE_TYPE(this->current_expression), VOIDmode, true));
TREE_NO_TRAMPOLINE(this->current_expression) = 1;
break;
case source::unary_operator::negation:
this->current_expression = build1_loc(get_location(&expression->position()), TRUTH_NOT_EXPR,

View File

@ -962,7 +962,7 @@ namespace source
case binary_operator::equals:
return "=";
case binary_operator::not_equals:
return "/=";
return "<>";
case binary_operator::less:
return "<";
case binary_operator::less_equal: