Skip to content

Commit 28c6ca0

Browse files
committed
merge dev
2 parents 04c65c5 + 3c726e5 commit 28c6ca0

File tree

203 files changed

+169
-397
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

203 files changed

+169
-397
lines changed

README.md

+11-34

.clang-format cpp/.clang-format

File renamed without changes.

CMakeLists.txt cpp/CMakeLists.txt

File renamed without changes.

cpp/README.md

+23
File renamed without changes.

doc/use/ESC.md cpp/doc/use/ESC.md

doc/use/TDB.md cpp/doc/use/TDB.md

doc/use/use.md cpp/doc/use/use.md

File renamed without changes.
File renamed without changes.
File renamed without changes.

script/clang_format.py cpp/script/clang_format.py

-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,3 @@
99
if tmp == ".hpp" or tmp == ".cpp" or tmp == ".h" or tmp == ".cppm":
1010
path = os.path.join(root, i)
1111
os.system("clang-format -i --style=file %s" % path)
12-
13-
input("ok")
File renamed without changes.

script/easy.py cpp/script/easy.py

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
/**
2-
* @file test_filesys.cpp
3-
* @brief 测试filesys模块
4-
* @date 2022-05-03
5-
*
6-
* @copyright Copyright (c) 2022
7-
*
8-
*/
9-
10-
#include <gtest/gtest.h>
11-
#include <list>
12-
#include <string>
13-
import filesys;
14-
import filesys_tools;
15-
16-
using namespace trc;
17-
18-
static void test_readfile(const char* path, const char* expect) {
19-
std::string filedata;
20-
utils::readcode(filedata, tools::redefine_path(path));
21-
EXPECT_STREQ(filedata.c_str(), expect);
22-
}
23-
24-
// 测试读取文件的函数
25-
TEST(filesys, readfile) {
26-
// 测试读取多行文件
27-
test_readfile("filesys/readfile/readwithlines.in",
28-
"\n\n\nreadwithlines\n\nreadwithlines\n");
29-
// 测试读取空文件
30-
test_readfile("filesys/readfile/readempty.in", "");
31-
// 测试读取英文文件
32-
test_readfile("filesys/readfile/readenglish.in",
33-
"abcd\nefgh\nijkl\nmnop\nqrst\nuvwx\nyz\n");
34-
// 测试读取中文文件
35-
test_readfile("filesys/readfile/readchinese.in",
36-
"生活就像海洋,只有意志坚强的人才能到达彼岸\n");
37-
std::string filedata;
38-
// 测试读取不存在文件
39-
EXPECT_EQ(1,
40-
utils::readcode_with_code(
41-
filedata, tools::redefine_path("filesys/readfile/failtoread")));
42-
// 测试成功读取文件
43-
filedata.clear();
44-
EXPECT_EQ(0,
45-
utils::readcode_with_code(
46-
filedata, tools::redefine_path("filesys/readfile/readenglish.in")));
47-
// 测试读取超大文件
48-
std::string expect_big_data;
49-
char basestr[] = "pppppppppppp\n";
50-
expect_big_data.reserve(sizeof(basestr) * 10240);
51-
for (int i = 0; i < 10240; ++i) {
52-
expect_big_data += basestr;
53-
}
54-
test_readfile("filesys/readfile/readlonglong.in", expect_big_data.c_str());
55-
}
1+
/**
2+
* @file test_filesys.cpp
3+
* @brief 测试filesys模块
4+
* @date 2022-05-03
5+
*
6+
* @copyright Copyright (c) 2022
7+
*
8+
*/
9+
10+
#include <gtest/gtest.h>
11+
#include <list>
12+
#include <string>
13+
import filesys;
14+
import filesys_tools;
15+
16+
using namespace trc;
17+
18+
static void test_readfile(const char* path, const char* expect) {
19+
std::string filedata;
20+
utils::readcode(filedata, tools::redefine_path(path));
21+
EXPECT_STREQ(filedata.c_str(), expect);
22+
}
23+
24+
// 测试读取文件的函数
25+
TEST(filesys, readfile) {
26+
// 测试读取多行文件
27+
test_readfile("filesys/readfile/readwithlines.in",
28+
"\n\n\nreadwithlines\n\nreadwithlines\n");
29+
// 测试读取空文件
30+
test_readfile("filesys/readfile/readempty.in", "");
31+
// 测试读取英文文件
32+
test_readfile("filesys/readfile/readenglish.in",
33+
"abcd\nefgh\nijkl\nmnop\nqrst\nuvwx\nyz\n");
34+
// 测试读取中文文件
35+
test_readfile("filesys/readfile/readchinese.in",
36+
"生活就像海洋,只有意志坚强的人才能到达彼岸\n");
37+
std::string filedata;
38+
// 测试读取不存在文件
39+
EXPECT_EQ(1,
40+
utils::readcode_with_code(
41+
filedata, tools::redefine_path("filesys/readfile/failtoread")));
42+
// 测试成功读取文件
43+
filedata.clear();
44+
EXPECT_EQ(0,
45+
utils::readcode_with_code(
46+
filedata, tools::redefine_path("filesys/readfile/readenglish.in")));
47+
// 测试读取超大文件
48+
std::string expect_big_data;
49+
char basestr[] = "pppppppppppp\n";
50+
expect_big_data.reserve(sizeof(basestr) * 10240);
51+
for (int i = 0; i < 10240; ++i) {
52+
expect_big_data += basestr;
53+
}
54+
test_readfile("filesys/readfile/readlonglong.in", expect_big_data.c_str());
55+
}
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
/**
2-
* 测试自己封装的io库
3-
*/
4-
5-
#include <cstdio>
6-
#include <cstdlib>
7-
#include <gtest/gtest.h>
8-
#include <string>
9-
#include <vector>
10-
import io;
11-
import filesys_tools;
12-
13-
using namespace trc;
14-
15-
static void check_readstr(
16-
const char* path, const std::vector<const char*>& expectstr) {
17-
FILE* file
18-
= tools::fopen_with_check(tools::redefine_path(path).c_str(), "r");
19-
char* raw_str;
20-
// -1是为了避开最后一个false(eof)值
21-
for (size_t i = 0, n = expectstr.size(); i < n - 1; ++i) {
22-
EXPECT_TRUE(io::readstr(raw_str, file));
23-
EXPECT_STREQ(raw_str, expectstr[i]);
24-
free(raw_str);
25-
}
26-
io::readstr(raw_str, file);
27-
EXPECT_STREQ(raw_str, expectstr.back());
28-
free(raw_str);
29-
fclose(file);
30-
}
31-
32-
// 测试字符串读入
33-
TEST(io, readstr) {
34-
// 测试普通正常多行文件
35-
check_readstr("io/readstr1.in", { "abcdef", "opiuy", "pploi" });
36-
// 测试结尾不为换行符的文件
37-
check_readstr("io/readstr_eof.in", { "io", "ploip" });
38-
// 测试空文件读入
39-
check_readstr("io/readstr_empty.in", { "" });
40-
// 测试长字符串读入
41-
check_readstr("io/readstr_long.in",
42-
{ std::string(120, 'u').c_str(), std::string(120, 'v').c_str() });
43-
}
1+
/**
2+
* 测试自己封装的io库
3+
*/
4+
5+
#include <cstdio>
6+
#include <cstdlib>
7+
#include <gtest/gtest.h>
8+
#include <string>
9+
#include <vector>
10+
import io;
11+
import filesys_tools;
12+
13+
using namespace trc;
14+
15+
static void check_readstr(
16+
const char* path, const std::vector<const char*>& expectstr) {
17+
FILE* file
18+
= tools::fopen_with_check(tools::redefine_path(path).c_str(), "r");
19+
char* raw_str;
20+
// -1是为了避开最后一个false(eof)值
21+
for (size_t i = 0, n = expectstr.size(); i < n - 1; ++i) {
22+
EXPECT_TRUE(io::readstr(raw_str, file));
23+
EXPECT_STREQ(raw_str, expectstr[i]);
24+
free(raw_str);
25+
}
26+
io::readstr(raw_str, file);
27+
EXPECT_STREQ(raw_str, expectstr.back());
28+
free(raw_str);
29+
fclose(file);
30+
}
31+
32+
// 测试字符串读入
33+
TEST(io, readstr) {
34+
// 测试普通正常多行文件
35+
check_readstr("io/readstr1.in", { "abcdef", "opiuy", "pploi" });
36+
// 测试结尾不为换行符的文件
37+
check_readstr("io/readstr_eof.in", { "io", "ploip" });
38+
// 测试空文件读入
39+
check_readstr("io/readstr_empty.in", { "" });
40+
// 测试长字符串读入
41+
check_readstr("io/readstr_long.in",
42+
{ std::string(120, 'u').c_str(), std::string(120, 'v').c_str() });
43+
}
File renamed without changes.

xmake.lua cpp/xmake.lua

File renamed without changes.

rust/src/compiler/ast.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,22 @@ impl<'a> AstBuilder<'a> {
3030

3131
fn statement(&mut self, mut t: Token) -> RunResult<()> {
3232
match t.tp {
33-
super::token::TokenType::ID => {}
33+
super::token::TokenType::ID => {
34+
t = self.token_lexer.next_token()?;
35+
match t.tp {
36+
super::token::TokenType::Assign => {}
37+
super::token::TokenType::Store => {}
38+
_ => {
39+
return Err(RuntimeError::new(
40+
Box::new(self.token_lexer.compiler_data.content.clone()),
41+
ErrorInfo::new(
42+
gettextrs::gettext(SYNTAX_ERROR),
43+
gettext!(UNEXPECTED_TOKEN, t.tp.to_string()),
44+
),
45+
))
46+
}
47+
}
48+
}
3449
_ => {
3550
return Err(RuntimeError::new(
3651
Box::new(self.token_lexer.compiler_data.content.clone()),
@@ -47,15 +62,12 @@ impl<'a> AstBuilder<'a> {
4762
pub fn generate_code(&mut self) -> RunResult<()> {
4863
loop {
4964
let token = self.token_lexer.next_token()?;
50-
match token {
51-
Some(token) => {
52-
self.statement(token)?;
53-
}
54-
None => {
55-
return Ok(());
56-
}
65+
if token.tp == super::token::TokenType::EndOfFile {
66+
break;
5767
}
68+
self.statement(token)?;
5869
}
70+
return Ok(());
5971
}
6072
}
6173

0 commit comments

Comments
 (0)