Skip to content

Commit

Permalink
#94: getStringByStringPoolPos
Browse files Browse the repository at this point in the history
  • Loading branch information
levBagryansky committed Jun 12, 2024
1 parent e7de959 commit 5e53f47
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion include/ChaiVM/interpreter/code-manager/code-manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CodeManager final {
* @param reg_val Number from constant pool.
* @return String.
*/
const std::string &getCnstStringByReg(chsize_t reg_val);
const std::string &getStringByStringPoolPos(chsize_t reg_val);

Immidiate addCnstString(std::string &&str);

Expand Down
2 changes: 1 addition & 1 deletion src/ChaiVM/interpreter/code-manager/code-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const std::string &CodeManager::getCnstStringByImm(Immidiate imm) {
return stringPool_[constantPool_[imm]];
}

const std::string &CodeManager::getCnstStringByReg(chsize_t reg_val) {
const std::string &CodeManager::getStringByStringPoolPos(chsize_t reg_val) {
return stringPool_[reg_val];
}

Expand Down
10 changes: 5 additions & 5 deletions src/ChaiVM/interpreter/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,16 +364,16 @@ void Executor::set_f64in_arr(Instruction ins) {
}

void Executor::string_print(Instruction ins) {
const std::string &str = codeManager_->getCnstStringByReg(acc());
const std::string &str = codeManager_->getStringByStringPoolPos(acc());
std::cout << str << std::endl;
advancePc();
DO_NEXT_INS();
}

void Executor::string_concat(Instruction ins) {
const std::string &str1 = codeManager_->getCnstStringByReg(acc());
const std::string &str1 = codeManager_->getStringByStringPoolPos(acc());
const std::string &str2 =
codeManager_->getCnstStringByReg((*currentFrame_)[ins.r1]);
codeManager_->getStringByStringPoolPos((*currentFrame_)[ins.r1]);
std::string concated = str1 + str2;
acc() =
codeManager_->getCnst(codeManager_->addCnstString(std::move(concated)));
Expand All @@ -382,12 +382,12 @@ void Executor::string_concat(Instruction ins) {
}

void Executor::string_len(Instruction ins) {
acc() = codeManager_->getCnstStringByReg(acc()).size();
acc() = codeManager_->getStringByStringPoolPos(acc()).size();
advancePc();
DO_NEXT_INS();
}
void Executor::string_slice(Instruction ins) {
const std::string &str = codeManager_->getCnstStringByReg(acc());
const std::string &str = codeManager_->getStringByStringPoolPos(acc());
acc() = codeManager_->getCnst(codeManager_->addCnstString(
str.substr((*currentFrame_)[ins.r1],
(*currentFrame_)[ins.r2] - (*currentFrame_)[ins.r1])));
Expand Down
6 changes: 3 additions & 3 deletions test/ChaiVM/interpreter/executor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ TEST_F(ExecutorTest, StringPrint) {
load<Ret>();
update();
exec_.run();
EXPECT_EQ(codeManager_.getCnstStringByReg(exec_.acc()), "ABOBA");
EXPECT_EQ(codeManager_.getStringByStringPoolPos(exec_.acc()), "ABOBA");
EXPECT_EQ(codeManager_.getCnstStringByImm(raw), "ABOBA");
}

Expand All @@ -669,7 +669,7 @@ TEST_F(ExecutorTest, StringConcat) {
EXPECT_EQ(codeManager_.getCnstStringByImm(raw1), "ABOBA");
EXPECT_EQ(codeManager_.getCnstStringByImm(raw2), " Yeash");
exec_.run();
EXPECT_EQ(codeManager_.getCnstStringByReg(exec_.acc()), "ABOBA Yeash");
EXPECT_EQ(codeManager_.getStringByStringPoolPos(exec_.acc()), "ABOBA Yeash");
}

TEST_F(ExecutorTest, StringSize) {
Expand All @@ -696,6 +696,6 @@ TEST_F(ExecutorTest, StringSlice) {
load<Ret>();
update();
exec_.run();
EXPECT_EQ(codeManager_.getCnstStringByReg(exec_.acc()), "BOB");
EXPECT_EQ(codeManager_.getStringByStringPoolPos(exec_.acc()), "BOB");
EXPECT_EQ(codeManager_.getCnstStringByImm(raw), "ABOBA");
}
2 changes: 1 addition & 1 deletion test/ChaiVM/interpreter/simple-programs-executor-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,5 @@ TEST_F(ExecutorTest, StringDemo) {
load<Ret>();
update();
exec_.run();
EXPECT_EQ(codeManager_.getCnstStringByReg(exec_.acc()), "Hellodragons");
EXPECT_EQ(codeManager_.getStringByStringPoolPos(exec_.acc()), "Hellodragons");
}
2 changes: 1 addition & 1 deletion test/frontend/assembler/assembler-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TEST_F(AssemblerTest, strings) {
asM.assemble();
codeManager_.load(output_);
exec_.run();
EXPECT_EQ(codeManager_.getCnstStringByReg(exec_.acc()), "Hello world");
EXPECT_EQ(codeManager_.getStringByStringPoolPos(exec_.acc()), "Hello world");
}

TEST_F(AssemblerTest, simpleFunction) {
Expand Down

0 comments on commit 5e53f47

Please sign in to comment.