Move byte for unyped pointers
This commit is contained in:
parent
4011adbe2b
commit
5108016d39
@ -32,7 +32,7 @@ namespace gcc
|
|||||||
{
|
{
|
||||||
return "Float";
|
return "Float";
|
||||||
}
|
}
|
||||||
else if (type == elna_char_type_node)
|
else if (type == unsigned_char_type_node)
|
||||||
{
|
{
|
||||||
return "Char";
|
return "Char";
|
||||||
}
|
}
|
||||||
|
@ -246,7 +246,9 @@ namespace gcc
|
|||||||
|
|
||||||
void generic_visitor::visit(boot::number_literal<unsigned char> *character)
|
void generic_visitor::visit(boot::number_literal<unsigned char> *character)
|
||||||
{
|
{
|
||||||
this->current_expression = build_int_cstu(elna_char_type_node, character->number());
|
auto symbol = this->symbol_map->lookup("Char");
|
||||||
|
|
||||||
|
this->current_expression = build_int_cstu(symbol->payload, character->number());
|
||||||
}
|
}
|
||||||
|
|
||||||
void generic_visitor::visit(boot::number_literal<nullptr_t> *)
|
void generic_visitor::visit(boot::number_literal<nullptr_t> *)
|
||||||
|
@ -10,10 +10,8 @@ namespace gcc
|
|||||||
{
|
{
|
||||||
void init_ttree()
|
void init_ttree()
|
||||||
{
|
{
|
||||||
elna_char_type_node = make_unsigned_type(8);
|
|
||||||
elna_string_type_node = build_pointer_type(
|
elna_string_type_node = build_pointer_type(
|
||||||
build_qualified_type(char_type_node, TYPE_QUAL_CONST)); /* const char* */
|
build_qualified_type(char_type_node, TYPE_QUAL_CONST)); /* const char* */
|
||||||
TYPE_STRING_FLAG(elna_char_type_node) = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_pointer_type(tree type)
|
bool is_pointer_type(tree type)
|
||||||
@ -77,7 +75,8 @@ namespace gcc
|
|||||||
initial_table->enter("Word", boot::make_info(size_type_node));
|
initial_table->enter("Word", boot::make_info(size_type_node));
|
||||||
initial_table->enter("Bool", boot::make_info(boolean_type_node));
|
initial_table->enter("Bool", boot::make_info(boolean_type_node));
|
||||||
initial_table->enter("Float", boot::make_info(double_type_node));
|
initial_table->enter("Float", boot::make_info(double_type_node));
|
||||||
initial_table->enter("Char", boot::make_info(elna_char_type_node));
|
initial_table->enter("Char", boot::make_info(unsigned_char_type_node));
|
||||||
|
initial_table->enter("Byte", boot::make_info(make_unsigned_type(8)));
|
||||||
initial_table->enter("String", boot::make_info(elna_string_type_node));
|
initial_table->enter("String", boot::make_info(elna_string_type_node));
|
||||||
|
|
||||||
return initial_table;
|
return initial_table;
|
||||||
|
@ -10,14 +10,12 @@
|
|||||||
|
|
||||||
enum elna_tree_index
|
enum elna_tree_index
|
||||||
{
|
{
|
||||||
ELNA_TI_CHAR_TYPE,
|
|
||||||
ELNA_TI_STRING_TYPE,
|
ELNA_TI_STRING_TYPE,
|
||||||
ELNA_TI_MAX
|
ELNA_TI_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
extern GTY(()) tree elna_global_trees[ELNA_TI_MAX];
|
extern GTY(()) tree elna_global_trees[ELNA_TI_MAX];
|
||||||
|
|
||||||
#define elna_char_type_node elna_global_trees[ELNA_TI_CHAR_TYPE]
|
|
||||||
#define elna_string_type_node elna_global_trees[ELNA_TI_STRING_TYPE]
|
#define elna_string_type_node elna_global_trees[ELNA_TI_STRING_TYPE]
|
||||||
|
|
||||||
namespace elna
|
namespace elna
|
||||||
|
@ -38,7 +38,7 @@ const
|
|||||||
TOKEN_PLUS = 43, TOKEN_MINUS = 44, TOKEN_MULTIPLICATION = 45, TOKEN_DIVISION = 46,
|
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_REMAINDER = 47, TOKEN_ASSIGNMENT = 48, TOKEN_COLON = 49, TOKEN_HAT = 50,
|
||||||
TOKEN_AT = 51, TOKEN_COMMENT = 52, TOKEN_INTEGER = 53, TOKEN_WORD = 54,
|
TOKEN_AT = 51, TOKEN_COMMENT = 52, TOKEN_INTEGER = 53, TOKEN_WORD = 54,
|
||||||
TOKEN_CHARACTER = 55;
|
TOKEN_CHARACTER = 55, TOKEN_STRING = 56;
|
||||||
|
|
||||||
(*
|
(*
|
||||||
External procedures.
|
External procedures.
|
||||||
@ -47,19 +47,19 @@ proc fopen(pathname: String, mode: String): pointer to FILE; extern;
|
|||||||
proc fclose(stream: pointer to FILE): Int; extern;
|
proc fclose(stream: pointer to FILE): Int; extern;
|
||||||
proc fseek(stream: pointer to FILE, off: Int, whence: Int): Int; extern;
|
proc fseek(stream: pointer to FILE, off: Int, whence: Int): Int; extern;
|
||||||
proc ftell(stream: pointer to FILE): Int; extern;
|
proc ftell(stream: pointer to FILE): Int; extern;
|
||||||
proc fread(ptr: pointer to Char, size: Int, nmemb: Int, stream: pointer to FILE): Int; extern;
|
proc fread(ptr: pointer to Byte, size: Word, nmemb: Word, stream: pointer to FILE): Word; extern;
|
||||||
proc write(fd: Int, buf: pointer to Char, count: Int): Int; extern;
|
proc write(fd: Int, buf: pointer to Byte, Word: Int): Int; extern;
|
||||||
|
|
||||||
proc malloc(size: Int): pointer to Char; extern;
|
proc malloc(size: Word): pointer to Byte; extern;
|
||||||
proc free(ptr: pointer to Char); extern;
|
proc free(ptr: pointer to Byte); extern;
|
||||||
proc calloc(nmemb: Int, size: Int): pointer to Char; extern;
|
proc calloc(nmemb: Word, size: Word): pointer to Byte; extern;
|
||||||
proc realloc(ptr: pointer to Char, size: Word): pointer to Char; extern;
|
proc realloc(ptr: pointer to Byte, size: Word): pointer to Byte; extern;
|
||||||
|
proc reallocarray(ptr: pointer to Byte, n: Word, size: Word): pointer to Byte; extern;
|
||||||
|
|
||||||
proc memset(ptr: pointer to Char, c: Int, n: Int): pointer to Char; extern;
|
proc memset(ptr: pointer to Char, c: Int, n: Int): pointer to Char; extern;
|
||||||
|
|
||||||
proc strncmp(s1: pointer to Char, s2: pointer to Char, n: Word): Int; extern;
|
proc strncmp(s1: pointer to Char, s2: pointer to Char, n: Word): Int; extern;
|
||||||
proc strncpy(dst: pointer to Char, src: pointer to Char, dsize: Word): pointer to Char; extern;
|
proc strncpy(dst: pointer to Char, src: pointer to Char, dsize: Word): pointer to Char; extern;
|
||||||
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 strlen(ptr: pointer to Char): Word; extern;
|
||||||
|
|
||||||
proc strtol(nptr: pointer to Char, endptr: pointer to pointer to Char, base: Int): Int; extern;
|
proc strtol(nptr: pointer to Char, endptr: pointer to pointer to Char, base: Int): Int; extern;
|
||||||
@ -169,7 +169,7 @@ proc read_source(filename: String): pointer to Char;
|
|||||||
var
|
var
|
||||||
input_file: pointer to FILE,
|
input_file: pointer to FILE,
|
||||||
source_size: Int,
|
source_size: Int,
|
||||||
input: pointer to Char;
|
input: pointer to Byte;
|
||||||
begin
|
begin
|
||||||
input_file := fopen(filename, "rb");
|
input_file := fopen(filename, "rb");
|
||||||
|
|
||||||
@ -260,6 +260,20 @@ begin
|
|||||||
return nil
|
return nil
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
proc lex_character(input: pointer to Char, current_token: pointer to Token): pointer to Char;
|
||||||
|
begin
|
||||||
|
if input^ = '\\' then
|
||||||
|
input := input + 1;
|
||||||
|
if escape_char(input^, @current_token^.value.char_value) then
|
||||||
|
input := input + 1
|
||||||
|
end
|
||||||
|
elsif input^ <> '\0' then
|
||||||
|
current_token^.value.char_value := input^;
|
||||||
|
input := input + 1
|
||||||
|
end;
|
||||||
|
return input
|
||||||
|
end;
|
||||||
|
|
||||||
proc print_tokens(tokens: pointer to Token, tokens_size: Word);
|
proc print_tokens(tokens: pointer to Token, tokens_size: Word);
|
||||||
var
|
var
|
||||||
current_token: pointer to Token,
|
current_token: pointer to Token,
|
||||||
@ -389,10 +403,12 @@ begin
|
|||||||
write_c('<');
|
write_c('<');
|
||||||
write_i(current_token^.value.char_value);
|
write_i(current_token^.value.char_value);
|
||||||
write_s("c>")
|
write_s("c>")
|
||||||
|
elsif current_token^.kind = TOKEN_STRING then
|
||||||
|
write_s("\"...\"")
|
||||||
else
|
else
|
||||||
write_s("UNKNOWN<");
|
write_s("UNKNOWN<");
|
||||||
write_i(current_token^.kind);
|
write_i(current_token^.kind);
|
||||||
write_s('>')
|
write_c('>')
|
||||||
end;
|
end;
|
||||||
write_c(' ');
|
write_c(' ');
|
||||||
|
|
||||||
@ -534,17 +550,12 @@ begin
|
|||||||
current_token^.kind := TOKEN_RIGHT_PAREN;
|
current_token^.kind := TOKEN_RIGHT_PAREN;
|
||||||
input_pointer := input_pointer + 1
|
input_pointer := input_pointer + 1
|
||||||
elsif input_pointer^ = '\'' then
|
elsif input_pointer^ = '\'' then
|
||||||
input_pointer := input_pointer + 1;
|
token_end := lex_character(input_pointer + 1, current_token);
|
||||||
if input_pointer^ = '\\' then
|
|
||||||
input_pointer := input_pointer + 1;
|
if token_end^ = '\'' then
|
||||||
if escape_char(input_pointer^, @current_token^.value.char_value) then
|
|
||||||
input_pointer := input_pointer + 1
|
|
||||||
end
|
|
||||||
elsif input_pointer^ <> '\0' then
|
|
||||||
current_token^.value.char_value := input_pointer^
|
|
||||||
end;
|
|
||||||
if input_pointer^ = '\'' then
|
|
||||||
current_token^.kind := TOKEN_CHARACTER;
|
current_token^.kind := TOKEN_CHARACTER;
|
||||||
|
input_pointer := token_end + 1
|
||||||
|
else
|
||||||
input_pointer := input_pointer + 1
|
input_pointer := input_pointer + 1
|
||||||
end
|
end
|
||||||
elsif input_pointer^ = '[' then
|
elsif input_pointer^ = '[' then
|
Loading…
x
Reference in New Issue
Block a user