DEADSOFTWARE

Исправлено создание локальных типов и констант;
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Mon, 21 Aug 2017 10:31:01 +0000 (13:31 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Mon, 21 Aug 2017 10:31:01 +0000 (13:31 +0300)
Исправлен пропуск переводов строк в комментариях;
Исправлены операторы DIV и MOD;
Добавлены типы SYSTEM.INT32 и SYSTEM.SET32;
Процедуры INC и DEC могут принимать второй аргумент.

notes
src/backends/jvm/generator-jvm.c
src/oberon.c

diff --git a/notes b/notes
index 71fcaf3866a440c895be254c267961ed0f61be79..a2ff96c5b781f03a344c6a7374ce978734a71abd 100644 (file)
--- a/notes
+++ b/notes
@@ -3,6 +3,8 @@
 - Не полная реализация модуля Files 
     * Не реализована запись в файл
 
+- Разршить отсутсвие RETURN в функциях без BEGIN
+    С вкорячиванием трапа, естественно.
 - Нужно передлать кодогенератор что бы складировать код в структурах а не напрямую срать в файлы
 
 - Не полная реализация модуля Strings 
index be8c9292dd0444f3f50c0ce116baee2ad660f254..c389ebce731e08fd36d13c36fceff9083f2308b9 100644 (file)
@@ -871,10 +871,12 @@ jvm_generate_local_object(gen_proc_t * p, oberon_object_t * x)
                case OBERON_CLASS_VAR:
                        jvm_generate_var(v);
                        break;
+               case OBERON_CLASS_CONST:
+               case OBERON_CLASS_TYPE:
                case OBERON_CLASS_PROC:
                        break;
                default:
-                       gen_error("jvm_generate_local_initialization: wat");
+                       gen_error("jvm_generate_local_initialization: wat class %i", x -> class);
                        break;
        }
 }
@@ -899,10 +901,12 @@ jvm_generate_local_initialization(gen_proc_t * p, oberon_object_t * x)
                case OBERON_CLASS_VAR:
                        jvm_generate_var_initialization(p, v);
                        break;
+               case OBERON_CLASS_CONST:
+               case OBERON_CLASS_TYPE:
                case OBERON_CLASS_PROC:
                        break;
                default:
-                       gen_error("jvm_generate_local_initialization: wat");
+                       gen_error("jvm_generate_local_initialization: wat class %i", x -> class);
                        break;
        }
 
index ebcaa990f9640d227f34c139844e63b26e5defee..72bf1c68b5a1f774c8284b4cab65a17c6adfc788 100644 (file)
@@ -693,9 +693,9 @@ oberon_read_number(oberon_context_t * ctx)
 }
 
 static void
-oberon_skip_space(oberon_context_t * ctx)
+oberon_get_lined_char(oberon_context_t * ctx)
 {
-       while(isspace(ctx -> c))
+       do
        {
                if(ctx -> c == 0xD)
                {
@@ -717,6 +717,15 @@ oberon_skip_space(oberon_context_t * ctx)
                {
                        oberon_get_char(ctx);
                }
+       } while(ctx -> c == 0xD || ctx -> c == 0xA);
+}
+
+static void
+oberon_skip_space(oberon_context_t * ctx)
+{
+       while(isspace(ctx -> c))
+       {
+               oberon_get_lined_char(ctx);
        }
 }
 
@@ -728,19 +737,19 @@ oberon_read_comment(oberon_context_t * ctx)
        {
                if(ctx -> c == '(')
                {
-                       oberon_get_char(ctx);
+                       oberon_get_lined_char(ctx);
                        if(ctx -> c == '*')
                        {
-                               oberon_get_char(ctx);
+                               oberon_get_lined_char(ctx);
                                nesting += 1;
                        }
                }
                else if(ctx -> c == '*')
                {
-                       oberon_get_char(ctx);
+                       oberon_get_lined_char(ctx);
                        if(ctx -> c == ')')
                        {
-                               oberon_get_char(ctx);
+                               oberon_get_lined_char(ctx);
                                nesting -= 1;
                        }
                }
@@ -750,7 +759,7 @@ oberon_read_comment(oberon_context_t * ctx)
                }
                else
                {
-                       oberon_get_char(ctx);
+                       oberon_get_lined_char(ctx);
                }
        }
 }
@@ -1150,8 +1159,6 @@ oberon_autocast_call(oberon_context_t * ctx, oberon_item_t * desig)
        int num_args = desig -> num_args;
        int num_decl = fn -> num_decl;
 
-       printf("oberon_autocast_call: num_args %i num_decl %i\n", num_args, num_decl);
-
        if(num_args < num_decl)
        {
                oberon_error(ctx, "too few arguments");
@@ -1952,7 +1959,7 @@ oberon_make_bin_op(oberon_context_t * ctx, int token, oberon_expr_t * a, oberon_
                                                break;
                                }
                        }
-                       else if(oberon_is_number_type(result))
+                       else if(oberon_is_real_type(result))
                        {
                                switch(token)
                                {
@@ -1966,6 +1973,32 @@ oberon_make_bin_op(oberon_context_t * ctx, int token, oberon_expr_t * a, oberon_
                                                expr = oberon_new_operator(OP_MUL, result, a, b);
                                                break;
                                        default:
+                                               printf("token %i line %i\n", token, ctx -> loc.line);
+                                               assert(0);
+                                               break;
+                               }
+                       }
+                       else if(oberon_is_integer_type(result))
+                       {
+                               switch(token)
+                               {
+                                       case PLUS:
+                                               expr = oberon_new_operator(OP_ADD, result, a, b);
+                                               break;
+                                       case MINUS:
+                                               expr = oberon_new_operator(OP_SUB, result, a, b);
+                                               break;
+                                       case STAR:
+                                               expr = oberon_new_operator(OP_MUL, result, a, b);
+                                               break;
+                                       case DIV:
+                                               expr = oberon_new_operator(OP_DIV, result, a, b);
+                                               break;
+                                       case MOD:
+                                               expr = oberon_new_operator(OP_DIV, result, a, b);
+                                               break;
+                                       default:
+                                               printf("token %i line %i\n", token, ctx -> loc.line);
                                                assert(0);
                                                break;
                                }
@@ -3855,7 +3888,7 @@ oberon_make_abs_call(oberon_context_t * ctx, int num_args, oberon_expr_t * list_
        arg = list_args;
        oberon_check_src(ctx, arg);
 
-       if(oberon_is_number_type(arg -> result))
+       if(!oberon_is_number_type(arg -> result))
        {
                oberon_error(ctx, "ABS accepts only numbers");
        }
@@ -3889,7 +3922,7 @@ oberon_make_inc_call(oberon_context_t * ctx, int num_args, oberon_expr_t * list_
                oberon_error(ctx, "too few arguments");
        }
 
-       if(num_args > 1)
+       if(num_args > 2)
        {
                oberon_error(ctx, "too mach arguments");
        }
@@ -3903,8 +3936,24 @@ oberon_make_inc_call(oberon_context_t * ctx, int num_args, oberon_expr_t * list_
                oberon_error(ctx, "expect integer");
        }
 
+       oberon_expr_t * step;
+       if(num_args == 2)
+       {
+               step = list_args -> next;
+               oberon_check_src(ctx, step);
+               oberon_check_const(ctx, step);
+               if(!oberon_is_integer_type(step -> result))
+               {
+                       oberon_error(ctx, "expect integer");
+               }
+       }
+       else
+       {
+               step = oberon_make_integer(ctx, 1);
+       }
+
        oberon_expr_t * expr;
-       expr = oberon_make_bin_op(ctx, PLUS, dst, oberon_make_integer(ctx, 1));
+       expr = oberon_make_bin_op(ctx, PLUS, dst, step);
        oberon_assign(ctx, expr, dst);
 }
 
@@ -3988,7 +4037,7 @@ oberon_make_dec_call(oberon_context_t * ctx, int num_args, oberon_expr_t * list_
                oberon_error(ctx, "too few arguments");
        }
 
-       if(num_args > 1)
+       if(num_args > 2)
        {
                oberon_error(ctx, "too mach arguments");
        }
@@ -4002,8 +4051,24 @@ oberon_make_dec_call(oberon_context_t * ctx, int num_args, oberon_expr_t * list_
                oberon_error(ctx, "expect integer");
        }
 
+       oberon_expr_t * step;
+       if(num_args == 2)
+       {
+               step = list_args -> next;
+               oberon_check_src(ctx, step);
+               oberon_check_const(ctx, step);
+               if(!oberon_is_integer_type(step -> result))
+               {
+                       oberon_error(ctx, "expect integer");
+               }
+       }
+       else
+       {
+               step = oberon_make_integer(ctx, 1);
+       }
+
        oberon_expr_t * expr;
-       expr = oberon_make_bin_op(ctx, MINUS, dst, oberon_make_integer(ctx, 1));
+       expr = oberon_make_bin_op(ctx, MINUS, dst, step);
        oberon_assign(ctx, expr, dst);
 }
 
@@ -4896,6 +4961,8 @@ oberon_create_context(ModuleImportCallback import_module)
                /* Types */
                oberon_new_intrinsic_type(ctx, "BYTE", ctx -> system_byte_type);
                oberon_new_intrinsic_type(ctx, "PTR", ctx -> system_ptr_type);
+               oberon_new_intrinsic_type(ctx, "INT32", ctx -> int_type);
+               oberon_new_intrinsic_type(ctx, "SET32", ctx -> set_type);
 
                /* Functions */
                oberon_new_intrinsic(ctx, "CC", oberon_make_cc_call, NULL);