Skip to content

Commit acbc840

Browse files
committed
evaluator: Fixed placing imported types into sections
1 parent a81154b commit acbc840

File tree

8 files changed

+26
-18
lines changed

8 files changed

+26
-18
lines changed

lib/include/pl/core/evaluator.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,10 @@ namespace pl::core {
427427
return *m_patternLanguage;
428428
}
429429

430+
const PatternLanguage& getRuntime() const {
431+
return *m_patternLanguage;
432+
}
433+
430434
void setPatternColorPalette(std::span<const u32> palette) {
431435
m_patternColorPalette.clear();
432436
m_patternColorPalette.reserve(palette.size());
@@ -492,8 +496,6 @@ namespace pl::core {
492496

493497
std::atomic<bool> m_aborted;
494498

495-
std::vector<u64> m_sectionIdStack;
496-
497499
std::vector<std::vector<u8>> m_heap;
498500
std::map<u32, PatternLocalData> m_patternLocalStorage;
499501

lib/include/pl/pattern_language.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ namespace pl {
424424
struct SectionData {
425425
std::map<u64, api::Section> sections;
426426
u64 nextSectionId = 0;
427+
std::vector<u64> sectionIdStack;
427428
};
428429

429430
private:

lib/source/pl/core/ast/ast_node_array_variable_decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ namespace pl::core::ast {
101101
evaluator->setBitwiseReadOffset(startOffset);
102102
}
103103

104-
if (this->m_placementSection != nullptr && !evaluator->isGlobalScope()) {
104+
if (evaluator->getSectionId() != ptrn::Pattern::MainSectionId && !evaluator->isGlobalScope()) {
105105
evaluator->addPattern(std::move(pattern));
106106
resultPatterns.pop_back();
107107
}

lib/source/pl/core/ast/ast_node_pointer_variable_decl.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ namespace pl::core::ast {
100100
err::E0005.throwError("'auto' can only be used with parameters.", { }, this->getLocation());
101101
}
102102

103-
if (this->m_placementSection != nullptr)
104-
pattern->setSection(evaluator->getSectionId());
103+
pattern->setSection(evaluator->getSectionId());
105104

106105
if (this->m_placementOffset != nullptr && !evaluator->isGlobalScope()) {
107106
evaluator->setBitwiseReadOffset(startOffset);
@@ -114,7 +113,7 @@ namespace pl::core::ast {
114113
this->execute(evaluator);
115114
resultPatterns.clear();
116115
} else {
117-
if (this->m_placementSection != nullptr && !evaluator->isGlobalScope()) {
116+
if (evaluator->getSectionId() != ptrn::Pattern::MainSectionId && !evaluator->isGlobalScope()) {
118117
evaluator->addPattern(std::move(pattern));
119118
resultPatterns.clear();
120119
}

lib/source/pl/core/ast/ast_node_type_operator.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ namespace pl::core::ast {
2626
if (this->m_providerOperation) {
2727
switch (this->getOperator()) {
2828
case Token::Operator::AddressOf:
29-
result = u128(evaluator->getDataBaseAddress());
29+
if (evaluator->getSectionId() != ptrn::Pattern::MainSectionId)
30+
result = u128(0x00);
31+
else
32+
result = u128(evaluator->getDataBaseAddress());
3033
break;
3134
case Token::Operator::SizeOf:
32-
result = u128(evaluator->getDataSize());
35+
result = u128(evaluator->getRuntime().getSectionSize(evaluator->getSectionId()));
3336
break;
3437
default:
3538
err::E0001.throwError("Invalid type operation.", {}, this->getLocation());

lib/source/pl/core/ast/ast_node_variable_decl.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,15 @@ namespace pl::core::ast {
7474

7575
pattern->setVariableName(this->m_name);
7676

77-
if (this->m_placementSection != nullptr)
78-
pattern->setSection(evaluator->getSectionId());
77+
pattern->setSection(evaluator->getSectionId());
7978

8079
applyVariableAttributes(evaluator, this, pattern);
8180

8281
if (this->m_placementOffset != nullptr && !evaluator->isGlobalScope()) {
8382
evaluator->setBitwiseReadOffset(startOffset);
8483
}
8584

86-
if (this->m_placementSection != nullptr && !evaluator->isGlobalScope()) {
85+
if (evaluator->getSectionId() != ptrn::Pattern::MainSectionId && !evaluator->isGlobalScope()) {
8786
evaluator->addPattern(std::move(pattern));
8887
} else {
8988
resultPatterns = hlp::moveToVector<std::shared_ptr<ptrn::Pattern>>(std::move(pattern));

lib/source/pl/core/evaluator.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -929,25 +929,27 @@ namespace pl::core {
929929
}
930930

931931
void Evaluator::pushSectionId(u64 id) {
932-
this->m_sectionIdStack.push_back(id);
932+
this->getRuntime().m_sectionData->sectionIdStack.push_back(id);
933933
}
934934

935935
void Evaluator::popSectionId() {
936-
this->m_sectionIdStack.pop_back();
936+
this->getRuntime().m_sectionData->sectionIdStack.pop_back();
937937
}
938938

939939
[[nodiscard]] u64 Evaluator::getSectionId() const {
940-
if (this->m_sectionIdStack.empty())
940+
const auto &sectionIdStack = this->getRuntime().m_sectionData->sectionIdStack;
941+
if (sectionIdStack.empty())
941942
return 0;
942943

943-
return this->m_sectionIdStack.back();
944+
return sectionIdStack.back();
944945
}
945946

946947
u64 Evaluator::getUserSectionId() const {
947-
if (this->m_sectionIdStack.empty())
948+
const auto &sectionIdStack = this->getRuntime().m_sectionData->sectionIdStack;
949+
if (sectionIdStack.empty())
948950
return 0;
949951

950-
for (auto it = this->m_sectionIdStack.rbegin(); it != this->m_sectionIdStack.rend(); ++it) {
952+
for (auto it = sectionIdStack.rbegin(); it != sectionIdStack.rend(); ++it) {
951953
if (*it != ptrn::Pattern::MainSectionId && *it != ptrn::Pattern::HeapSectionId && *it != ptrn::Pattern::PatternLocalSectionId && *it != ptrn::Pattern::InstantiationSectionId)
952954
return *it;
953955
}
@@ -959,7 +961,6 @@ namespace pl::core {
959961
this->m_readOrderReversed = false;
960962
this->m_currBitOffset = 0;
961963

962-
this->m_sectionIdStack.clear();
963964
this->m_outVariables.clear();
964965
this->m_outVariableValues.clear();
965966

@@ -978,6 +979,8 @@ namespace pl::core {
978979
this->m_evaluated = false;
979980
this->m_attributedPatterns.clear();
980981

982+
this->m_subRuntimes.clear();
983+
981984
this->setPatternColorPalette(DefaultPatternColorPalette);
982985

983986
if (this->m_allowDangerousFunctions == DangerousFunctionPermission::Deny)

lib/source/pl/pattern_language.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ namespace pl {
555555
if (!this->m_subRuntime) {
556556
this->m_sectionData->nextSectionId = 1;
557557
this->m_sectionData->sections.clear();
558+
this->m_sectionData->sectionIdStack.clear();
558559
}
559560

560561
this->m_resolvers.setDefaultResolver([this](const std::string& path) {

0 commit comments

Comments
 (0)