From afdfb61e64fb9c7d05a7612812739aa0d9a560fc Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Thu, 31 Aug 2017 18:46:39 +0300 Subject: [PATCH] =?utf8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?utf8?q?=D0=BD=D0=BE=20=D0=BE=D0=B1=D1=80=D0=B0=D1=89=D0=B5=D0=BD=D0=B8?= =?utf8?q?=D0=B5=20=D0=BA=20=D0=BF=D0=BE=D0=BB=D1=8F=D0=BC=20=D0=BF=D1=80?= =?utf8?q?=D0=B8=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2?= =?utf8?q?=D0=B0=D0=BD=D0=B8=D0=B8=20=D0=BA=D0=B0=D1=81=D1=82=D0=B0.=20?= =?utf8?q?=D0=9F=D1=80=D0=BE=D1=86=D0=B5=D0=B4=D1=83=D1=80=D1=8B=20INC/DEC?= =?utf8?q?=20=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=B5=20=D0=BD=D0=B5=20=D1=82?= =?utf8?q?=D1=80=D0=B5=D0=B1=D1=83=D1=8E=D1=82=20=D0=BA=D0=BE=D0=BD=D1=81?= =?utf8?q?=D1=82=D0=B0=D0=BD=D1=82=20=D0=B4=D0=BB=D1=8F=20=D0=B2=D1=82?= =?utf8?q?=D0=BE=D1=80=D0=BE=D0=B3=D0=BE=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC?= =?utf8?q?=D0=B5=D1=82=D1=80=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- notes | 1 + obn-run-tests.sh | 2 ++ src/backends/jvm/generator-jvm.c | 4 ++++ src/oberon-internals.h | 3 ++- src/oberon.c | 8 ++++++-- tests/Test25.obn | 21 +++++++++++++++++++++ tests/Test26.obn | 11 +++++++++++ 7 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 tests/Test25.obn create mode 100644 tests/Test26.obn diff --git a/notes b/notes index bdd35e2..d2a263f 100644 --- a/notes +++ b/notes @@ -1,6 +1,7 @@ - Jasmin создаёт ошибку в float константах, надо как-то порешать. - Нужно делать проверку границ при касте индекса массива с типом HUGEINT +- Секции CONST/TYPE/VAR сейчас нельзя повторять (что не по стандарту) - Нужно передавать информацию о файле и строках в кодогенератор. - Нет процедур привязанных к типм (10.2) - Не полная реализация модуля Files diff --git a/obn-run-tests.sh b/obn-run-tests.sh index 813e6e5..a5ea198 100755 --- a/obn-run-tests.sh +++ b/obn-run-tests.sh @@ -97,3 +97,5 @@ makecomp Test23A makefail Test23B maketest Test24 +maketest Test25 +maketest Test26 diff --git a/src/backends/jvm/generator-jvm.c b/src/backends/jvm/generator-jvm.c index 79da2b9..48db180 100644 --- a/src/backends/jvm/generator-jvm.c +++ b/src/backends/jvm/generator-jvm.c @@ -1351,6 +1351,10 @@ push_item(gen_proc_t * p, oberon_item_t * item) jvm_generate_array_len(p, item -> integer); jvm_generate_cast_prefix(p, 'i', jvm_get_postfix(item -> result)); break; + case MODE_AS: + push_item(p, item -> parent); + jvm_generate_cast_type(p, item -> parent -> result, item -> result); + break; default: gen_error("push_item: unk mode %i", item -> mode); break; diff --git a/src/oberon-internals.h b/src/oberon-internals.h index d4f3cf2..d9f3119 100644 --- a/src/oberon-internals.h +++ b/src/oberon-internals.h @@ -208,7 +208,8 @@ enum oberon_mode_kind MODE_TYPE, MODE_SET, MODE_LEN, - MODE_SYSBYTE + MODE_SYSBYTE, + MODE_AS }; enum oberon_operator_kind diff --git a/src/oberon.c b/src/oberon.c index 83f39cd..1b7f5d9 100644 --- a/src/oberon.c +++ b/src/oberon.c @@ -1088,6 +1088,12 @@ oberon_cast_expr(oberon_context_t * ctx, oberon_expr_t * expr, oberon_type_t * p cast = oberon_new_item(MODE_CHAR, ctx -> char_type, true); cast -> item.integer = expr -> item.string[0]; } + else if(oberon_is_record_type(pref) || oberon_is_pointer_to_record(pref)) + { + assert(expr -> is_item); + cast = oberon_new_item(MODE_AS, pref, expr -> read_only); + cast -> item.parent = (oberon_item_t *) expr; + } else if(!oberon_is_some_types(expr -> result, pref)) { cast = oberon_new_operator(OP_CAST, pref, expr, NULL); @@ -3940,7 +3946,6 @@ oberon_make_inc_call(oberon_context_t * ctx, int num_args, oberon_expr_t * list_ { 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"); @@ -4055,7 +4060,6 @@ oberon_make_dec_call(oberon_context_t * ctx, int num_args, oberon_expr_t * list_ { 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"); diff --git a/tests/Test25.obn b/tests/Test25.obn new file mode 100644 index 0000000..87d50c2 --- /dev/null +++ b/tests/Test25.obn @@ -0,0 +1,21 @@ +MODULE Test25; + +TYPE + X = POINTER TO XDesc; + XDesc = RECORD END; + + Y = POINTER TO RECORD (XDesc) x : INTEGER END; + +VAR + x : X; + y : Y; + i : INTEGER; + +BEGIN + NEW(y); + x := y; + i := y.x; + i := x(Y).x; +END Test25. + +Тест приведения типа с обращением к полю. diff --git a/tests/Test26.obn b/tests/Test26.obn new file mode 100644 index 0000000..8fb9997 --- /dev/null +++ b/tests/Test26.obn @@ -0,0 +1,11 @@ +MODULE Test26; + +VAR + x : SHORTINT; + y : LONGINT; + +BEGIN + y := x + SHORT(y); +END Test26. + +Тест приведения типа. -- 2.29.2