DEADSOFTWARE

TRUE и FALSE теперь определены как константы
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Wed, 9 Aug 2017 17:17:37 +0000 (20:17 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Wed, 9 Aug 2017 17:17:37 +0000 (20:17 +0300)
Test.obn
src/backends/jvm/generator-jvm.c
src/oberon-internals.h
src/oberon.c

index 0b020f71a79862e5a3510e07528b982ea6a21749..682b0a049b547a2b7d2497bb118f985e1492fafa 100644 (file)
--- a/Test.obn
+++ b/Test.obn
@@ -6,6 +6,8 @@ IMPORT
 
 BEGIN
   Out.Open;
-  Out.String("Hello World!"); Out.Ln;
+  IF FALSE THEN
+    Out.String("Hello World!"); Out.Ln;
+  END;
   System.Halt(1);
 END Test.
index 1ec731f8eb37d275a3114ed050bbd262fd2a9615..065d9634c48a73b4b3900e63a17fd3e6f5a7ff6e 100644 (file)
@@ -1175,13 +1175,11 @@ push_item(gen_proc_t * p, oberon_item_t * item)
                        }
                        break;
                case MODE_INTEGER:
+               case MODE_BOOLEAN:
                case MODE_CHAR:
                case MODE_SET:
                        jvm_generate_push_int_size(p, item -> integer, item -> result -> size);
                        break;
-               case MODE_BOOLEAN:
-                       jvm_generate_push_int_size(p, item -> boolean, item -> result -> size);
-                       break;
                case MODE_CALL:
                        jvm_generate_call_proc(p, item);
                        break;
index 3963146d4ee87f2d1cb65c0ecb807ffbde9f4e8d..fa9b5d5280903bf0ea16496170cb3e81fcb69045 100644 (file)
@@ -225,7 +225,6 @@ struct oberon_item_t
        enum oberon_mode_kind mode;
        long integer;
        double real;
-       int boolean;
        char * string;
        oberon_object_t * var;
 
index 064cfb10bd0b24955eb0b23655c12ee68d62cf52..f1fe4518a135c6e9369e877ac2c08d13575fb12a 100644 (file)
@@ -24,8 +24,6 @@ enum {
        BEGIN,
        ASSIGN,
        INTEGER,
-       TRUE,
-       FALSE,
        LPAREN,
        RPAREN,
        EQUAL,
@@ -344,14 +342,6 @@ oberon_read_ident(oberon_context_t * ctx)
        {
                ctx -> token = BEGIN;
        }
-       else if(strcmp(ident, "TRUE") == 0)
-       {
-               ctx -> token = TRUE;
-       }
-       else if(strcmp(ident, "FALSE") == 0)
-       {
-               ctx -> token = FALSE;
-       }
        else if(strcmp(ident, "OR") == 0)
        {
                ctx -> token = OR;
@@ -1364,9 +1354,7 @@ oberon_make_call_proc(oberon_context_t * ctx, oberon_item_t * item, int num_args
        || ((x) == STRING) \
        || ((x) == NIL) \
        || ((x) == LPAREN) \
-       || ((x) == NOT) \
-       || ((x) == TRUE) \
-       || ((x) == FALSE)) 
+       || ((x) == NOT))
 
 static oberon_expr_t *
 oberno_make_dereferencing(oberon_context_t * ctx, oberon_expr_t * expr)
@@ -1770,6 +1758,15 @@ oberon_set(oberon_context_t * ctx)
        return set;
 }
 
+static oberon_expr_t *
+oberon_make_boolean(oberon_context_t * ctx, bool cond)
+{
+       oberon_expr_t * expr;
+       expr = oberon_new_item(MODE_BOOLEAN, ctx -> bool_type, true);
+       expr -> item.integer = cond;
+       return expr;
+}
+
 static oberon_expr_t *
 oberon_factor(oberon_context_t * ctx)
 {
@@ -1804,16 +1801,6 @@ oberon_factor(oberon_context_t * ctx)
                        expr -> item.real = ctx -> real;
                        oberon_assert_token(ctx, REAL);
                        break;
-               case TRUE:
-                       expr = oberon_new_item(MODE_BOOLEAN, ctx -> bool_type, true);
-                       expr -> item.boolean = true;
-                       oberon_assert_token(ctx, TRUE);
-                       break;
-               case FALSE:
-                       expr = oberon_new_item(MODE_BOOLEAN, ctx -> bool_type, true);
-                       expr -> item.boolean = false;
-                       oberon_assert_token(ctx, FALSE);
-                       break;
                case LBRACE:
                        expr = oberon_set(ctx);
                        break;
@@ -4038,6 +4025,15 @@ oberon_make_new_call(oberon_context_t * ctx, int num_args, oberon_expr_t * list_
        oberon_assign(ctx, src, dst);
 }
 
+static void
+oberon_new_const(oberon_context_t * ctx, char * name, oberon_expr_t * expr)
+{
+       oberon_object_t * constant;
+       constant = oberon_define_object(ctx -> decl, name, OBERON_CLASS_CONST, true, false, false);
+       oberon_check_const(ctx, expr);
+       constant -> value = (oberon_item_t *) expr;
+}
+
 oberon_context_t *
 oberon_create_context(ModuleImportCallback import_module)
 {
@@ -4053,6 +4049,10 @@ oberon_create_context(ModuleImportCallback import_module)
 
        register_default_types(ctx);
 
+       /* Constants */
+       oberon_new_const(ctx, "TRUE", oberon_make_boolean(ctx, true));
+       oberon_new_const(ctx, "FALSE", oberon_make_boolean(ctx, false));
+
        /* Functions */
        oberon_new_intrinsic(ctx, "ABS", oberon_make_abs_call, NULL);
        oberon_new_intrinsic(ctx, "MIN", oberon_make_min_call, NULL);