From fdf5ab34b9d87a72d0680caddf62116118a6cbd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E4=BA=91?= <71159641+littlewhitecloud@users.noreply.github.com> Date: Sat, 16 Dec 2023 15:01:00 +0800 Subject: [PATCH 01/18] add three tests --- tests/syntax_error/missing_end_quote_in_byte.jou | 6 ++++++ tests/syntax_error/missing_end_quote_in_string.jou | 6 ++++++ tests/syntax_error/string_continue_on_next_line.jou | 8 ++++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/syntax_error/missing_end_quote_in_byte.jou create mode 100644 tests/syntax_error/missing_end_quote_in_string.jou create mode 100644 tests/syntax_error/string_continue_on_next_line.jou diff --git a/tests/syntax_error/missing_end_quote_in_byte.jou b/tests/syntax_error/missing_end_quote_in_byte.jou new file mode 100644 index 00000000..52fe3caf --- /dev/null +++ b/tests/syntax_error/missing_end_quote_in_byte.jou @@ -0,0 +1,6 @@ +import "stdlib/io.jou" + +# Output: compiler error in file "tests/syntax_error/missing_end_quote_in_byte.jou", line 5: missing ' to end the byte literal +def main() -> int: + printf('?) + return 0 diff --git a/tests/syntax_error/missing_end_quote_in_string.jou b/tests/syntax_error/missing_end_quote_in_string.jou new file mode 100644 index 00000000..a860da4c --- /dev/null +++ b/tests/syntax_error/missing_end_quote_in_string.jou @@ -0,0 +1,6 @@ +import "stdlib/io.jou" + +# Output: compiler error in file "tests/syntax_error/missing_end_quote_in_string.jou", line 5: missing " to end the string +def main() -> int: + printf("Hello) + return 0 diff --git a/tests/syntax_error/string_continue_on_next_line.jou b/tests/syntax_error/string_continue_on_next_line.jou new file mode 100644 index 00000000..c9fc5d5d --- /dev/null +++ b/tests/syntax_error/string_continue_on_next_line.jou @@ -0,0 +1,8 @@ +import "stdlib/io.jou" + +# Output: compiler error in file "tests/syntax_error/string_continue_on_next_line.jou", line 5: missing ' to end the byte literal +def main() -> int: + a = '\ + 't\'' + printf(a) + return 0 From 2afa867230d8b9738222c41b33a51f78b3eb2090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E4=BA=91?= <71159641+littlewhitecloud@users.noreply.github.com> Date: Sat, 16 Dec 2023 15:03:07 +0800 Subject: [PATCH 02/18] rm trai space --- tests/syntax_error/missing_end_quote_in_byte.jou | 2 +- tests/syntax_error/missing_end_quote_in_string.jou | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/syntax_error/missing_end_quote_in_byte.jou b/tests/syntax_error/missing_end_quote_in_byte.jou index 52fe3caf..3483fa58 100644 --- a/tests/syntax_error/missing_end_quote_in_byte.jou +++ b/tests/syntax_error/missing_end_quote_in_byte.jou @@ -2,5 +2,5 @@ import "stdlib/io.jou" # Output: compiler error in file "tests/syntax_error/missing_end_quote_in_byte.jou", line 5: missing ' to end the byte literal def main() -> int: - printf('?) + printf('?) return 0 diff --git a/tests/syntax_error/missing_end_quote_in_string.jou b/tests/syntax_error/missing_end_quote_in_string.jou index a860da4c..991f6b74 100644 --- a/tests/syntax_error/missing_end_quote_in_string.jou +++ b/tests/syntax_error/missing_end_quote_in_string.jou @@ -2,5 +2,5 @@ import "stdlib/io.jou" # Output: compiler error in file "tests/syntax_error/missing_end_quote_in_string.jou", line 5: missing " to end the string def main() -> int: - printf("Hello) + printf("Hello) return 0 From 7bb1480a3c33d2b4855369d6b5fda83477edf442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E4=BA=91?= <71159641+littlewhitecloud@users.noreply.github.com> Date: Sat, 16 Dec 2023 18:06:26 +0800 Subject: [PATCH 03/18] test --- self_hosted/tokenizer.jou | 1 + 1 file changed, 1 insertion(+) diff --git a/self_hosted/tokenizer.jou b/self_hosted/tokenizer.jou index 7edc1fa3..001bc310 100644 --- a/self_hosted/tokenizer.jou +++ b/self_hosted/tokenizer.jou @@ -276,6 +276,7 @@ class Tokenizer: if c == '\\': after_backslash = self->read_byte() if after_backslash == '\0' or after_backslash == '\n': + self->location.lineno-- fail(self->location, "missing ' to end the byte literal") elif after_backslash == 'n': c = '\n' From c35210c1a15bf7f3a1bc75f66f93fc50c6278e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E4=BA=91?= <71159641+littlewhitecloud@users.noreply.github.com> Date: Sat, 16 Dec 2023 18:26:45 +0800 Subject: [PATCH 04/18] emm? --- tests/should_succeed/newline_and_space_at_eof.jou | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/should_succeed/newline_and_space_at_eof.jou diff --git a/tests/should_succeed/newline_and_space_at_eof.jou b/tests/should_succeed/newline_and_space_at_eof.jou new file mode 100644 index 00000000..3d98ec03 --- /dev/null +++ b/tests/should_succeed/newline_and_space_at_eof.jou @@ -0,0 +1,3 @@ +def main() -> int: + return 0 + \ No newline at end of file From 4b1207e2be49728de9cb474eb09f31b8ab6b192a Mon Sep 17 00:00:00 2001 From: littlewhitecloud Date: Sat, 16 Dec 2023 10:27:11 +0000 Subject: [PATCH 05/18] Change files to use LF line endings --- tests/should_succeed/newline_and_space_at_eof.jou | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/should_succeed/newline_and_space_at_eof.jou b/tests/should_succeed/newline_and_space_at_eof.jou index 3d98ec03..5a847337 100644 --- a/tests/should_succeed/newline_and_space_at_eof.jou +++ b/tests/should_succeed/newline_and_space_at_eof.jou @@ -1,3 +1,3 @@ -def main() -> int: - return 0 +def main() -> int: + return 0 \ No newline at end of file From 710562315a84e694661aa4aeba4f5a58148442ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E4=BA=91?= <71159641+littlewhitecloud@users.noreply.github.com> Date: Sat, 16 Dec 2023 18:27:29 +0800 Subject: [PATCH 06/18] rm some todo --- src/tokenize.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tokenize.c b/src/tokenize.c index c7d6cbed..6de30e6b 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -295,7 +295,6 @@ static char *read_string(struct State *st, char quote, int *len) case '\n': // \ at end of line, string continues on next line if (quote == '\'') { - // TODO: tests st->location.lineno--; // to get error at the correct line number goto missing_end_quote; } @@ -321,7 +320,6 @@ static char *read_string(struct State *st, char quote, int *len) return result.ptr; missing_end_quote: - // TODO: tests if (quote == '"') fail_with_error(st->location, "missing \" to end the string"); else From 2ac58cc87f999fe77e5087a5106d5086a773d9c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E4=BA=91?= <71159641+littlewhitecloud@users.noreply.github.com> Date: Sat, 16 Dec 2023 18:30:07 +0800 Subject: [PATCH 07/18] ____ this file is hidden --- .editorconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.editorconfig b/.editorconfig index 71c40829..ff048379 100644 --- a/.editorconfig +++ b/.editorconfig @@ -19,3 +19,6 @@ indent_size = 3 [tests/syntax_error/indentation_not4.jou] indent_size = 2 + +[tests/should_succeed/newline_and_space_at_eof.jou] +indent_size = unset From 265c148805e31d1f88c595144d2fe8ed3326e53d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E4=BA=91?= <71159641+littlewhitecloud@users.noreply.github.com> Date: Sat, 16 Dec 2023 18:38:32 +0800 Subject: [PATCH 08/18] =?UTF-8?q?=E7=BB=99=E4=BD=A0=E6=90=9E=E8=B5=B7?= =?UTF-8?q?=E6=9D=A5=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .editorconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/.editorconfig b/.editorconfig index ff048379..b0e4dabd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -21,4 +21,5 @@ indent_size = 3 indent_size = 2 [tests/should_succeed/newline_and_space_at_eof.jou] +trim_trailing_whitespace = false indent_size = unset From 78155a94427a946d76f7be720fd5e51b2322c2cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E4=BA=91?= <71159641+littlewhitecloud@users.noreply.github.com> Date: Sat, 16 Dec 2023 19:46:24 +0800 Subject: [PATCH 09/18] after a couple of test, it is impossible to get the error --- src/typecheck.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/typecheck.c b/src/typecheck.c index 029d7fe4..d8f6edda 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -86,9 +86,6 @@ static const char *short_type_description(const Type *t) return "a number type"; case TYPE_ARRAY: return "an array type"; - case TYPE_BOOL: - // TODO: Is it possible to get this in an error message? - return "the built-in bool type"; } } From 5b31ecb85e1b2cd0e2e486a49cc00aac07bde7d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E4=BA=91?= <71159641+littlewhitecloud@users.noreply.github.com> Date: Sat, 16 Dec 2023 19:54:21 +0800 Subject: [PATCH 10/18] self-hosted compiler already takes parameters --- src/typecheck.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/typecheck.c b/src/typecheck.c index d8f6edda..3ed29370 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -243,8 +243,6 @@ static Signature handle_signature(FileTypes *ft, const AstSignature *astsig, con else sig.returntype = type_from_ast(ft, &astsig->returntype); - // TODO: validate main() parameters - // TODO: test main() taking parameters if (!self_type && !strcmp(sig.name, "main") && sig.returntype != intType) { fail_with_error(astsig->returntype.location, "the main() function must return int"); } From 68ee90596ac4da9f8b42502110fd56ec07576bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E4=BA=91?= <71159641+littlewhitecloud@users.noreply.github.com> Date: Sat, 16 Dec 2023 20:01:50 +0800 Subject: [PATCH 11/18] emm --- src/tokenize.c | 1 - src/typecheck.c | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tokenize.c b/src/tokenize.c index 6de30e6b..c744617c 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -126,7 +126,6 @@ static int read_indentation_level_for_newline_token(struct State *st) consume_rest_of_line(st); else if (c == '\0') { // Ignore newline+spaces at end of file. Do not validate 4 spaces. - // TODO: test case return 0; } else { unread_byte(st, c); diff --git a/src/typecheck.c b/src/typecheck.c index 3ed29370..2d5b4e09 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -86,7 +86,9 @@ static const char *short_type_description(const Type *t) return "a number type"; case TYPE_ARRAY: return "an array type"; - } + case TYPE_BOOL: + assert(0); + } } ExportSymbol *typecheck_stage1_create_types(FileTypes *ft, const AstFile *ast) From 697cd9481da5efbdce95248e6315dda296c7a9dc Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 16 Dec 2023 16:36:26 +0200 Subject: [PATCH 12/18] Use double quotes in string continue test --- tests/syntax_error/string_continue_on_next_line.jou | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/syntax_error/string_continue_on_next_line.jou b/tests/syntax_error/string_continue_on_next_line.jou index c9fc5d5d..925e19d4 100644 --- a/tests/syntax_error/string_continue_on_next_line.jou +++ b/tests/syntax_error/string_continue_on_next_line.jou @@ -1,8 +1,8 @@ import "stdlib/io.jou" -# Output: compiler error in file "tests/syntax_error/string_continue_on_next_line.jou", line 5: missing ' to end the byte literal +# Output: compiler error in file "tests/syntax_error/string_continue_on_next_line.jou", line 6: missing " to end the string def main() -> int: - a = '\ - 't\'' + a = "\ + asdf printf(a) return 0 From 84beaf39b5ddda1fd573bd4d29e01c85363a9a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E4=BA=91?= <71159641+littlewhitecloud@users.noreply.github.com> Date: Sun, 17 Dec 2023 08:49:13 +0800 Subject: [PATCH 13/18] Update typecheck.c --- src/typecheck.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/typecheck.c b/src/typecheck.c index 2d5b4e09..d30f2390 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -87,7 +87,7 @@ static const char *short_type_description(const Type *t) case TYPE_ARRAY: return "an array type"; case TYPE_BOOL: - assert(0); + return "a bool type"; } } From 2f587a4c009ba894bd0e78467dfc34832b9108bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E4=BA=91?= <71159641+littlewhitecloud@users.noreply.github.com> Date: Sun, 17 Dec 2023 08:53:14 +0800 Subject: [PATCH 14/18] writing test without jou env to test --- tests/already_exists_error/bool.jou | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tests/already_exists_error/bool.jou diff --git a/tests/already_exists_error/bool.jou b/tests/already_exists_error/bool.jou new file mode 100644 index 00000000..6bd869c4 --- /dev/null +++ b/tests/already_exists_error/bool.jou @@ -0,0 +1,2 @@ +def foo() -> None: + x = True.asdf() # Error: a bool type named 'True' already exists From 942689030e113825e7d0c8b3022d496f3f984730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E4=BA=91?= <71159641+littlewhitecloud@users.noreply.github.com> Date: Sun, 17 Dec 2023 09:04:11 +0800 Subject: [PATCH 15/18] not this error --- tests/already_exists_error/bool.jou | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/already_exists_error/bool.jou b/tests/already_exists_error/bool.jou index 6bd869c4..e56ef163 100644 --- a/tests/already_exists_error/bool.jou +++ b/tests/already_exists_error/bool.jou @@ -1,2 +1,2 @@ def foo() -> None: - x = True.asdf() # Error: a bool type named 'True' already exists + x = True.asdf() # Error: type bool does not have any methods because it is a bool type, not a class From 8804e48a2d8ae5fe1c78c2180fbd0e1c73c070bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E4=BA=91?= <71159641+littlewhitecloud@users.noreply.github.com> Date: Sun, 17 Dec 2023 09:17:39 +0800 Subject: [PATCH 16/18] just default --- src/typecheck.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/typecheck.c b/src/typecheck.c index d30f2390..d924b0aa 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -87,8 +87,8 @@ static const char *short_type_description(const Type *t) case TYPE_ARRAY: return "an array type"; case TYPE_BOOL: - return "a bool type"; - } + return "the built-in bool type"; + } } ExportSymbol *typecheck_stage1_create_types(FileTypes *ft, const AstFile *ast) From eef664fda394de1401a35032778c584ebfd9ffc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E4=BA=91?= <71159641+littlewhitecloud@users.noreply.github.com> Date: Sun, 17 Dec 2023 09:28:06 +0800 Subject: [PATCH 17/18] Update bool.jou --- tests/already_exists_error/bool.jou | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/already_exists_error/bool.jou b/tests/already_exists_error/bool.jou index e56ef163..38f92a5d 100644 --- a/tests/already_exists_error/bool.jou +++ b/tests/already_exists_error/bool.jou @@ -1,2 +1,2 @@ def foo() -> None: - x = True.asdf() # Error: type bool does not have any methods because it is a bool type, not a class + x = True.asdf() # Error: type bool does not have any methods because it is the built-in bool type, not a class From ae93ec5bb0cfb6b70098a125b188995d441bb43e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E4=BA=91?= <71159641+littlewhitecloud@users.noreply.github.com> Date: Sun, 17 Dec 2023 21:03:04 +0800 Subject: [PATCH 18/18] Update typecheck.c --- src/typecheck.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/typecheck.c b/src/typecheck.c index d924b0aa..a4941721 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -245,6 +245,8 @@ static Signature handle_signature(FileTypes *ft, const AstSignature *astsig, con else sig.returntype = type_from_ast(ft, &astsig->returntype); + // TODO: validate main() parameters + // TODO: test main() taking parameters if (!self_type && !strcmp(sig.name, "main") && sig.returntype != intType) { fail_with_error(astsig->returntype.location, "the main() function must return int"); }