From 8a5f063bc3aadbc2c9c15e29a4675a3cd97e9b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B0=D1=85=D0=B0=D1=80=20=D0=97=D0=B0=D1=85=D0=B0?= =?UTF-8?q?=D1=80=D0=BE=D0=B2?= Date: Tue, 10 Jan 2023 11:41:36 +0300 Subject: [PATCH 1/7] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B1=D0=B0=D0=B3=20=D1=81=20=D0=BE=D0=B1=D0=BB=D0=B0?= =?UTF-8?q?=D1=81=D1=82=D1=8C=D1=8E=20=D0=B2=D0=B8=D0=B4=D0=B8=D0=BC=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 ++++ libs/compiler/syntax.c | 6 ++++-- libs/compiler/syntax.h | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 94bed1a45..58bd3f19e 100644 --- a/.gitignore +++ b/.gitignore @@ -74,6 +74,7 @@ install_manifest.txt compile_commands.json CTestTestfile.cmake _deps +cmake-build-default*/ # VSCode .vscode/* @@ -93,6 +94,9 @@ Release/ *.perspectivev3 *.xcodeproj +# CLion +*.idea + # Windows desktop.ini diff --git a/libs/compiler/syntax.c b/libs/compiler/syntax.c index b212beec7..27c65d2bd 100644 --- a/libs/compiler/syntax.c +++ b/libs/compiler/syntax.c @@ -220,7 +220,7 @@ static void ident_init(syntax *const sx) builtin_add(sx, U"fputc", U"фписать_символ", type_function(sx, TYPE_INTEGER, "iP")); builtin_add(sx, U"fclose", U"фзакрыть", type_function(sx, TYPE_INTEGER, "P")); builtin_add(sx, U"exit", U"выход", type_function(sx, TYPE_VOID, "i")); - + builtin_add(sx, U"printf", U"печатьф", type_function(sx, TYPE_INTEGER, "s.")); builtin_add(sx, U"print", U"печать", type_function(sx, TYPE_VOID, ".")); builtin_add(sx, U"printid", U"печатьид", type_function(sx, TYPE_VOID, ".")); @@ -858,8 +858,9 @@ scope scope_block_enter(syntax *const sx) return (scope){ ITEM_MAX, ITEM_MAX }; } + size_t prev_cur_id = sx->cur_id; sx->cur_id = vector_size(&sx->identifiers); - return (scope){ sx->displ, sx->lg }; + return (scope){ sx->displ, sx->lg, prev_cur_id }; } int scope_block_exit(syntax *const sx, const scope scp) @@ -877,6 +878,7 @@ int scope_block_exit(syntax *const sx, const scope scp) sx->displ = scp.displ; sx->lg = scp.lg; + sx->cur_id = scp.cur_id; return 0; } diff --git a/libs/compiler/syntax.h b/libs/compiler/syntax.h index 81f8a3c83..082d0db69 100644 --- a/libs/compiler/syntax.h +++ b/libs/compiler/syntax.h @@ -93,6 +93,7 @@ typedef struct scope { item_t displ; item_t lg; + size_t cur_id; } scope; From 996aeaa9327e7d2ce4f983ce2cd290f2f23da652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B0=D1=85=D0=B0=D1=80=20=D0=97=D0=B0=D1=85=D0=B0?= =?UTF-8?q?=D1=80=D0=BE=D0=B2?= Date: Tue, 10 Jan 2023 12:13:53 +0300 Subject: [PATCH 2/7] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=82=D0=B5=D1=81=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../input/getid/math/gauss/no-llvm/temprorary/pronyushkin.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/codegen/input/getid/math/gauss/no-llvm/temprorary/pronyushkin.c b/tests/codegen/input/getid/math/gauss/no-llvm/temprorary/pronyushkin.c index 45d623966..998077834 100644 --- a/tests/codegen/input/getid/math/gauss/no-llvm/temprorary/pronyushkin.c +++ b/tests/codegen/input/getid/math/gauss/no-llvm/temprorary/pronyushkin.c @@ -5,9 +5,8 @@ void main() getid(N); printid(N); + float A[N][N], B[N], X[N]; { - float A[N][N], B[N], X[N]; - getid(A); printid(A); From 8bb5f0ae2b246c74c64565b090937288261ee8ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B0=D1=85=D0=B0=D1=80=20=D0=97=D0=B0=D1=85=D0=B0?= =?UTF-8?q?=D1=80=D0=BE=D0=B2?= Date: Tue, 10 Jan 2023 12:31:14 +0300 Subject: [PATCH 3/7] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81?= =?UTF-8?q?=20=D1=82=D0=B5=D1=81=D1=82=20=D0=B2=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/multiple_errors/pronyushkin.c | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/multiple_errors/pronyushkin.c diff --git a/tests/multiple_errors/pronyushkin.c b/tests/multiple_errors/pronyushkin.c new file mode 100644 index 000000000..35faf627b --- /dev/null +++ b/tests/multiple_errors/pronyushkin.c @@ -0,0 +1,44 @@ +void main() +{ + int N, i, j, k; + float t, S; + + getid(N); + printid(N); + { + float A[N][N], B[N], X[N]; + getid(A); + printid(A); + + getid(B); + printid(B); + for (i = 0; i < N; i++) + { + for (j = i + 1; j < N; j++) + { + t = A[j][i] / A[i][i]; + + for (k = i; k < N; k++) + { + A[j][k] = A[j][k] - t * A[i][k]; + } + + B[j] = B[j] - t * B[i]; + } + } + + for (i = N - 1; i > -1; i--) + { + t = 0; + for (j = i + 1; j < N; j++) + { + S = A[i][j] * X[j]; + t = t + S; + } + + X[i] = (B[i] - t) / A[i][i]; + } + } + + print (X); +} \ No newline at end of file From 3e6bf64d36d652dee28bd2f9cfac61236bd46e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B0=D1=85=D0=B0=D1=80=20=D0=97=D0=B0=D1=85=D0=B0?= =?UTF-8?q?=D1=80=D0=BE=D0=B2?= Date: Tue, 10 Jan 2023 13:47:05 +0300 Subject: [PATCH 4/7] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81?= =?UTF-8?q?=20=D1=82=D0=B5=D1=81=D1=82=20=D0=B2=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../executable/errors/no-llvm/temprorary}/pronyushkin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/{multiple_errors => codegen/executable/errors/no-llvm/temprorary}/pronyushkin.c (94%) diff --git a/tests/multiple_errors/pronyushkin.c b/tests/codegen/executable/errors/no-llvm/temprorary/pronyushkin.c similarity index 94% rename from tests/multiple_errors/pronyushkin.c rename to tests/codegen/executable/errors/no-llvm/temprorary/pronyushkin.c index 35faf627b..998077834 100644 --- a/tests/multiple_errors/pronyushkin.c +++ b/tests/codegen/executable/errors/no-llvm/temprorary/pronyushkin.c @@ -5,8 +5,8 @@ void main() getid(N); printid(N); + float A[N][N], B[N], X[N]; { - float A[N][N], B[N], X[N]; getid(A); printid(A); From b5b861d20766dc22a6921cd17c519fc592f96bbc Mon Sep 17 00:00:00 2001 From: Zakhar Date: Thu, 19 Jan 2023 14:01:05 +0300 Subject: [PATCH 5/7] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81?= =?UTF-8?q?=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usage_behind_the_scope}/pronyushkin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/{codegen/executable/errors/no-llvm/temprorary => semantics/usage_behind_the_scope}/pronyushkin.c (94%) diff --git a/tests/codegen/executable/errors/no-llvm/temprorary/pronyushkin.c b/tests/semantics/usage_behind_the_scope/pronyushkin.c similarity index 94% rename from tests/codegen/executable/errors/no-llvm/temprorary/pronyushkin.c rename to tests/semantics/usage_behind_the_scope/pronyushkin.c index 998077834..35faf627b 100644 --- a/tests/codegen/executable/errors/no-llvm/temprorary/pronyushkin.c +++ b/tests/semantics/usage_behind_the_scope/pronyushkin.c @@ -5,8 +5,8 @@ void main() getid(N); printid(N); - float A[N][N], B[N], X[N]; { + float A[N][N], B[N], X[N]; getid(A); printid(A); From d2fe3263941ae6db3417d38d39ba021c35270ad3 Mon Sep 17 00:00:00 2001 From: Zakhar Date: Thu, 19 Jan 2023 14:09:28 +0300 Subject: [PATCH 6/7] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81?= =?UTF-8?q?=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/semantics/usage_behind_the_scope/pronyushkin.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/semantics/usage_behind_the_scope/pronyushkin.c b/tests/semantics/usage_behind_the_scope/pronyushkin.c index 35faf627b..867c6e8d3 100644 --- a/tests/semantics/usage_behind_the_scope/pronyushkin.c +++ b/tests/semantics/usage_behind_the_scope/pronyushkin.c @@ -1,17 +1,11 @@ void main() { - int N, i, j, k; + int N = 10, i, j, k; float t, S; - getid(N); - printid(N); { float A[N][N], B[N], X[N]; - getid(A); - printid(A); - - getid(B); - printid(B); + for (i = 0; i < N; i++) { for (j = i + 1; j < N; j++) From e884fa9de32525e955247c98e328c360bcd7c747 Mon Sep 17 00:00:00 2001 From: Zakhar Date: Thu, 19 Jan 2023 14:16:21 +0300 Subject: [PATCH 7/7] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81?= =?UTF-8?q?=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usage_behind_the_scope/pronyushkin.c | 38 ------------------- .../use_begind_the_scope.c | 15 ++++++++ 2 files changed, 15 insertions(+), 38 deletions(-) delete mode 100644 tests/semantics/usage_behind_the_scope/pronyushkin.c create mode 100644 tests/semantics/use_of_undeclared_identifier/use_begind_the_scope.c diff --git a/tests/semantics/usage_behind_the_scope/pronyushkin.c b/tests/semantics/usage_behind_the_scope/pronyushkin.c deleted file mode 100644 index 867c6e8d3..000000000 --- a/tests/semantics/usage_behind_the_scope/pronyushkin.c +++ /dev/null @@ -1,38 +0,0 @@ -void main() -{ - int N = 10, i, j, k; - float t, S; - - { - float A[N][N], B[N], X[N]; - - for (i = 0; i < N; i++) - { - for (j = i + 1; j < N; j++) - { - t = A[j][i] / A[i][i]; - - for (k = i; k < N; k++) - { - A[j][k] = A[j][k] - t * A[i][k]; - } - - B[j] = B[j] - t * B[i]; - } - } - - for (i = N - 1; i > -1; i--) - { - t = 0; - for (j = i + 1; j < N; j++) - { - S = A[i][j] * X[j]; - t = t + S; - } - - X[i] = (B[i] - t) / A[i][i]; - } - } - - print (X); -} \ No newline at end of file diff --git a/tests/semantics/use_of_undeclared_identifier/use_begind_the_scope.c b/tests/semantics/use_of_undeclared_identifier/use_begind_the_scope.c new file mode 100644 index 000000000..ab66e2be5 --- /dev/null +++ b/tests/semantics/use_of_undeclared_identifier/use_begind_the_scope.c @@ -0,0 +1,15 @@ +// Use of undeclared identifier. +// More scopes. + +void main() +{ + int N = 10, i, j, k; + { + float A[N][N], B[N], X[N]; + { + float t, S; + } + } + + print (X); +} \ No newline at end of file