Skip to content

Commit 05da61f

Browse files
committed
evaluator: More imported type fixes
1 parent 2befd6a commit 05da61f

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

lib/include/pl/core/evaluator.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ namespace pl::core {
453453
}
454454
}
455455

456+
u64 getDefaultSection() const { return m_defaultSection; }
457+
456458
private:
457459
void patternCreated(ptrn::Pattern *pattern);
458460
void patternDestroyed(ptrn::Pattern *pattern);
@@ -482,6 +484,7 @@ namespace pl::core {
482484
i8 m_currBitOffset = 0;
483485
bool m_readOrderReversed = false;
484486
u64 m_startAddress = 0x00;
487+
u64 m_defaultSection = 0;
485488

486489
bool m_evaluated = false;
487490
bool m_debugMode = false;

lib/include/pl/patterns/pattern.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ namespace pl::ptrn {
376376
if (this->m_section == id)
377377
return;
378378

379+
if (this->m_section.has_value())
380+
return;
381+
379382
if (this->m_section != PatternLocalSectionId && this->m_section != HeapSectionId) {
380383
if (this->m_evaluator != nullptr)
381384
this->m_evaluator->patternDestroyed(this);
@@ -386,7 +389,7 @@ namespace pl::ptrn {
386389
}
387390

388391
[[nodiscard]] u64 getSection() const {
389-
return this->m_section;
392+
return this->m_section.value_or(m_evaluator->getDefaultSection());
390393
}
391394

392395
virtual void sort(const std::function<bool(const Pattern *left, const Pattern *right)> &comparator) {
@@ -638,7 +641,7 @@ namespace pl::ptrn {
638641

639642
u64 m_offset = 0x00;
640643
size_t m_size = 0x00;
641-
u64 m_section = 0x00;
644+
std::optional<u64> m_section;
642645

643646
u32 m_color = 0x00;
644647

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace pl::core::ast {
2020

2121
const auto startAddress = evaluator->getReadOffset();
2222
runtime.setStartAddress(evaluator->getStartAddress() + startAddress);
23+
runtime.setDataSize(evaluator->getDataSize() - (evaluator->getStartAddress() + startAddress));
2324
if (!runtime.executeString(source->content, source->source)) {
2425
err::E0005.throwError(fmt::format("Error while processing imported type '{}'.", m_importedTypeName), "Check the imported pattern for errors.", getLocation());
2526
}

lib/source/pl/core/evaluator.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,9 @@ namespace pl::core {
678678
if (pattern->getSize() > 0xFFFF'FFFF)
679679
err::E0003.throwError(fmt::format("Value is too large to place into local variable '{}'.", pattern->getVariableName()));
680680

681+
if (pattern->isReference() && pattern->getSection() == this->getDefaultSection())
682+
return;
683+
681684
// Cast values to type given by pattern
682685
Token::Literal castedValue = castLiteral(pattern.get(), variableValue);
683686

@@ -989,6 +992,11 @@ namespace pl::core {
989992

990993
this->m_subRuntimes.clear();
991994

995+
if (auto &sectionIds = this->getRuntime().m_sectionData->sectionIdStack; !sectionIds.empty())
996+
this->m_defaultSection = sectionIds.back();
997+
else
998+
this->m_defaultSection = ptrn::Pattern::MainSectionId;
999+
9921000
this->setPatternColorPalette(DefaultPatternColorPalette);
9931001

9941002
if (this->m_allowDangerousFunctions == DangerousFunctionPermission::Deny)
@@ -1143,6 +1151,9 @@ namespace pl::core {
11431151

11441152
stop_evaluation:
11451153

1154+
for (auto &pattern : this->m_patterns)
1155+
pattern->setSection(this->getDefaultSection());
1156+
11461157
if (!this->m_mainResult.has_value() && this->m_customFunctions.contains("main")) {
11471158
auto mainFunction = this->m_customFunctions["main"];
11481159

lib/source/pl/pattern_language.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,8 @@ namespace pl {
655655
auto visibility = pattern->getVisibility();
656656
if (visibility == pl::ptrn::Visibility::Hidden || visibility == pl::ptrn::Visibility::HighlightHidden)
657657
continue;
658+
if (pattern->getSection() != ptrn::Pattern::MainSectionId)
659+
continue;
658660

659661
results.push_back(pattern->getColor());
660662
}

0 commit comments

Comments
 (0)