From f34b0f1f6a54eda1ad328576e48d92b96ad160ac Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Fri, 15 Sep 2017 18:15:00 +0300 Subject: [PATCH] =?utf8?q?=D0=A0=D0=B0=D0=B7=D1=80=D0=B5=D1=88=D0=B5=D0=BD?= =?utf8?q?=D0=BE=20=D0=BF=D0=BE=D0=B2=D1=82=D0=BE=D1=80=D0=BD=D0=BE=20?= =?utf8?q?=D0=BE=D0=B1=D1=8A=D1=8F=D0=B2=D0=BB=D1=8F=D1=82=D1=8C=20=D0=B1?= =?utf8?q?=D0=BB=D0=BE=D0=BA=D0=B8=20CONST=20TYPE=20VAR,=20=D0=BF=D0=BE?= =?utf8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=BE=20=D1=81=D1=80?= =?utf8?q?=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B0=D1=81?= =?utf8?q?=D1=81=D0=B8=D0=B2=D0=BE=D0=B2=20=D1=81=D0=B8=D0=BC=D0=B2=D0=BE?= =?utf8?q?=D0=BB=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Test.obn | 19 +++++--------- obn-run-tests.sh | 1 + src/backends/jvm/generator-jvm.c | 4 +-- src/oberon-common.h | 11 ++++---- src/oberon.c | 43 ++++++++++++++++---------------- tests/Test28.obn | 16 ++++++++++++ 6 files changed, 53 insertions(+), 41 deletions(-) create mode 100644 tests/Test28.obn diff --git a/Test.obn b/Test.obn index ecfde58..950aa0a 100644 --- a/Test.obn +++ b/Test.obn @@ -1,21 +1,14 @@ MODULE Test; -TYPE - A = POINTER TO RECORD B : B; END; +IMPORT Out; - B = POINTER TO RECORD x : A END; +TYPE + Name = ARRAY 16 OF CHAR; VAR - a : A; - -PROCEDURE Do; - TYPE - ListPtr = POINTER TO ListNode; - ListNode = RECORD next: ListPtr END; -BEGIN -END Do; + key : ARRAY 128 OF Name; + name : Name; BEGIN - NEW(a); - a.B := NIL; + IF name > name THEN Out.Ln; END; END Test. diff --git a/obn-run-tests.sh b/obn-run-tests.sh index 88b5c6d..8db6f37 100755 --- a/obn-run-tests.sh +++ b/obn-run-tests.sh @@ -100,3 +100,4 @@ maketest Test24 maketest Test25 maketest Test26 maketest Test27 +maketest Test28 diff --git a/src/backends/jvm/generator-jvm.c b/src/backends/jvm/generator-jvm.c index 26a0b55..7da9b61 100644 --- a/src/backends/jvm/generator-jvm.c +++ b/src/backends/jvm/generator-jvm.c @@ -9,6 +9,7 @@ #include #include "../../oberon-internals.h" +#include "../../oberon-type-compat.h" #include "../../generator.h" #include "generator-jvm.h" #include "generator-jvm-abi.h" @@ -1454,8 +1455,7 @@ jvm_generate_compare_op(gen_proc_t * p, oberon_type_t * t, int op) } else if(prefix == 'a') { - if(t -> class == OBERON_TYPE_STRING - || (t -> class == OBERON_TYPE_POINTER && t -> base -> class == OBERON_TYPE_CHAR)) + if(oberon_is_array_of_char_type(t) || oberon_is_string_type(t)) { jvm_generate(p, 2, 1, "invokestatic SYSTEM/STRCMP([B[B)I"); jvm_generate(p, 1, 0, "if%s L%i", cmpop, label_true); diff --git a/src/oberon-common.h b/src/oberon-common.h index ccbe6e1..d4988a4 100644 --- a/src/oberon-common.h +++ b/src/oberon-common.h @@ -5,7 +5,6 @@ enum { SEMICOLON, END, DOT, - VAR, COLON, BEGIN, ASSIGN, @@ -29,11 +28,8 @@ enum { MOD, AND, NOT, - PROCEDURE, COMMA, RETURN, - CONST, - TYPE, ARRAY, OF, LBRACK, @@ -64,7 +60,12 @@ enum { DOTDOT, CASE, BAR, - WITH + WITH, + + CONST, + TYPE, + VAR, + PROCEDURE }; void diff --git a/src/oberon.c b/src/oberon.c index 04eaf8c..5abb209 100644 --- a/src/oberon.c +++ b/src/oberon.c @@ -3141,33 +3141,34 @@ oberon_prevent_undeclarated_procedures(oberon_context_t * ctx) static void oberon_decl_seq(oberon_context_t * ctx) { - if(ctx -> token == CONST) + while(ctx -> token >= CONST && ctx -> token <= VAR) { - oberon_assert_token(ctx, CONST); - while(ctx -> token == IDENT) + if(ctx -> token == CONST) { - oberon_const_decl(ctx); - oberon_assert_token(ctx, SEMICOLON); + oberon_assert_token(ctx, CONST); + while(ctx -> token == IDENT) + { + oberon_const_decl(ctx); + oberon_assert_token(ctx, SEMICOLON); + } } - } - - if(ctx -> token == TYPE) - { - oberon_assert_token(ctx, TYPE); - while(ctx -> token == IDENT) + else if(ctx -> token == TYPE) { - oberon_type_decl(ctx); - oberon_assert_token(ctx, SEMICOLON); + oberon_assert_token(ctx, TYPE); + while(ctx -> token == IDENT) + { + oberon_type_decl(ctx); + oberon_assert_token(ctx, SEMICOLON); + } } - } - - if(ctx -> token == VAR) - { - oberon_assert_token(ctx, VAR); - while(ctx -> token == IDENT) + else if(ctx -> token == VAR) { - oberon_var_decl(ctx); - oberon_assert_token(ctx, SEMICOLON); + oberon_assert_token(ctx, VAR); + while(ctx -> token == IDENT) + { + oberon_var_decl(ctx); + oberon_assert_token(ctx, SEMICOLON); + } } } diff --git a/tests/Test28.obn b/tests/Test28.obn new file mode 100644 index 0000000..7f9a7ea --- /dev/null +++ b/tests/Test28.obn @@ -0,0 +1,16 @@ +MODULE Test28; + +IMPORT Out; + +TYPE + Name = ARRAY 16 OF CHAR; + +VAR + key : ARRAY 128 OF Name; + name : Name; + +BEGIN + IF key[0] > name THEN Out.Ln; END; +END Test28. + +Тест сравнения массивов символов. -- 2.29.2