From: DeaDDooMER Date: Mon, 24 Jul 2017 19:25:58 +0000 (+0300) Subject: Добавлены указатели X-Git-Url: http://deadsoftware.ru/gitweb?p=dsw-obn.git;a=commitdiff_plain;h=8520fd72cf3c1daeabbb8da91290dae85fc39c91 Добавлены указатели --- diff --git a/generator.c b/generator.c index e4970fd..f65b066 100644 --- a/generator.c +++ b/generator.c @@ -79,25 +79,6 @@ oberon_generator_init_type(oberon_context_t * ctx, oberon_type_t * type) { gcc_type = gcc_jit_context_get_type(gcc_context, GCC_JIT_TYPE_BOOL); } - else if(type -> class == OBERON_TYPE_PROCEDURE) - { - int num_params = type -> num_decl; - gcc_jit_type * params[num_params]; - oberon_object_t * o = type -> decl; - for(int i = 0; i < num_params; i++) - { - gen_type_t * gen_type = o -> type -> gen_type; - params[i] = gen_type -> gcc_type; - o = o -> next; - } - - gen_type_t * base = type -> base -> gen_type; - gcc_jit_type * result_type = base -> gcc_type; - - gcc_type = gcc_jit_context_new_function_ptr_type( - gcc_context, NULL, result_type, num_params, params, 0 - ); - } else if(type -> class == OBERON_TYPE_ARRAY) { if(type -> dim != 1) @@ -128,11 +109,37 @@ oberon_generator_init_type(oberon_context_t * ctx, oberon_type_t * type) gcc_struct = gcc_jit_context_new_struct_type(gcc_context, NULL, "", num_fields, fields); gcc_type = gcc_jit_struct_as_type(gcc_struct); } + else if(type -> class == OBERON_TYPE_POINTER) + { + gen_type_t * gen_base = type -> base -> gen_type; + gcc_jit_type * gcc_base = gen_base -> gcc_type; + gcc_type = gcc_jit_type_get_pointer(gcc_base); + } + else if(type -> class == OBERON_TYPE_PROCEDURE) + { + int num_params = type -> num_decl; + gcc_jit_type * params[num_params]; + oberon_object_t * o = type -> decl; + for(int i = 0; i < num_params; i++) + { + gen_type_t * gen_type = o -> type -> gen_type; + params[i] = gen_type -> gcc_type; + o = o -> next; + } + + gen_type_t * base = type -> base -> gen_type; + gcc_jit_type * result_type = base -> gcc_type; + + gcc_type = gcc_jit_context_new_function_ptr_type( + gcc_context, NULL, result_type, num_params, params, 0 + ); + } else { oberon_error(ctx, "oberon_generator_init_type: invalid type class %i", type -> class); } + assert(gcc_type); gen_type -> gcc_type = gcc_type; gen_type -> gcc_struct = gcc_struct; } diff --git a/notes b/notes index 0d9dbdc..0be804b 100644 --- a/notes +++ b/notes @@ -1,7 +1,14 @@ -- нету автокаста в присвоении и передачи параметров -- нету локальных объявлений в процедурах -- нету свёртки констант -- нету не работает присваивание к переменным-процедурам. -- нету указателей -- нету расширения типа -- нету var-параметров в генераторе +- нету процедуры NEW +- не реализовано расширение типа record +- не реализовано преждевременное объявление типа +- не реализованы многомерные массивы + +- не реализованы локальные объявления в процедурах +- не работает присваивание к переменным-процедурам. +- не понятен результат присваивания статических структур (* reca := recb; *) +- не реализованы var-параметры в генераторе +- не реализованы процедуры "наперёд" + +- не реализована свёртка констант +- не реализован автокаст (libgccjit сам разруливает) +- не протестированы типы разнных размеров diff --git a/oberon.c b/oberon.c index bd5498b..7ca600e 100644 --- a/oberon.c +++ b/oberon.c @@ -48,7 +48,9 @@ enum { OF, LBRACE, RBRACE, - RECORD + RECORD, + POINTER, + TO }; // ======================================================================= @@ -387,6 +389,14 @@ oberon_read_ident(oberon_context_t * ctx) { ctx -> token = RECORD; } + else if(strcmp(ident, "POINTER") == 0) + { + ctx -> token = POINTER; + } + else if(strcmp(ident, "TO") == 0) + { + ctx -> token = TO; + } } static void @@ -1227,6 +1237,31 @@ oberon_field_list(oberon_context_t * ctx, oberon_type_t * rec) } } +static oberon_type_t * +oberon_make_pointer(oberon_context_t * ctx, oberon_type_t * type) +{ + if(type -> class == OBERON_TYPE_POINTER) + { + return type; + } + + if(type -> class == OBERON_TYPE_INTEGER + || type -> class == OBERON_TYPE_BOOLEAN + || type -> class == OBERON_TYPE_PROCEDURE + || type -> class == OBERON_TYPE_VOID) + { + oberon_error(ctx, "oberon not support pointers to non structure types"); + } + + oberon_type_t * newtype; + newtype = oberon_new_type_ptr(OBERON_TYPE_POINTER); + newtype -> base = type; + + oberon_generator_init_type(ctx, newtype); + + return newtype; +} + static oberon_type_t * oberon_opt_formal_pars(oberon_context_t * ctx, int class); static oberon_type_t * @@ -1268,6 +1303,13 @@ oberon_type(oberon_context_t * ctx) type -> decl = type -> decl -> next; oberon_generator_init_type(ctx, type); } + else if(ctx -> token == POINTER) + { + oberon_assert_token(ctx, POINTER); + oberon_assert_token(ctx, TO); + type = oberon_type(ctx); + type = oberon_make_pointer(ctx, type); + } else if(ctx -> token == PROCEDURE) { oberon_assert_token(ctx, PROCEDURE); diff --git a/oberon.h b/oberon.h index 69ee927..16044d4 100644 --- a/oberon.h +++ b/oberon.h @@ -72,6 +72,7 @@ enum OBERON_TYPE_PROCEDURE, OBERON_TYPE_ARRAY, OBERON_TYPE_RECORD, + OBERON_TYPE_POINTER }; /* diff --git a/test.c b/test.c index 178327e..8f3edc4 100644 --- a/test.c +++ b/test.c @@ -7,10 +7,13 @@ static const char source[] = "" "TYPE" " MyInt = INTEGER;" - " MyRec = RECORD" + " MyRec = POINTER TO RECORD" " a : MyInt;" + " next : MyRec;" " END;" - " MyRecPtr = POINTER TO MyRec;" + "" + "VAR" + " r : MyRec;" "" "BEGIN" " "