From: DeaDDooMER Date: Wed, 9 Aug 2017 17:17:37 +0000 (+0300) Subject: TRUE и FALSE теперь определены как константы X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=844ae6c007ac4606ad4ac3938876b67c014bb5eb;p=dsw-obn.git TRUE и FALSE теперь определены как константы --- diff --git a/Test.obn b/Test.obn index 0b020f7..682b0a0 100644 --- 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. diff --git a/src/backends/jvm/generator-jvm.c b/src/backends/jvm/generator-jvm.c index 1ec731f..065d963 100644 --- a/src/backends/jvm/generator-jvm.c +++ b/src/backends/jvm/generator-jvm.c @@ -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; diff --git a/src/oberon-internals.h b/src/oberon-internals.h index 3963146..fa9b5d5 100644 --- a/src/oberon-internals.h +++ b/src/oberon-internals.h @@ -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; diff --git a/src/oberon.c b/src/oberon.c index 064cfb1..f1fe451 100644 --- a/src/oberon.c +++ b/src/oberon.c @@ -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);