Skip to content

Commit

Permalink
evaluator: Added fixed_size attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Jul 9, 2024
1 parent 6da1493 commit 8909b96
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/source/pl/core/ast/ast_node_attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,18 @@ namespace pl::core::ast {
pattern->setSealed(true);
}

if (const auto &arguments = attributable->getAttributeArguments("fixed_size"); arguments.size() == 1) {
auto requestedSize = getAttributeValueAsInteger(arguments.front(), evaluator);
auto actualSize = pattern->getSize();
if (actualSize < requestedSize) {
pattern->setSize(requestedSize);
evaluator->setReadOffset(evaluator->getReadOffset() + (requestedSize - actualSize));
}
else if (actualSize > requestedSize)
err::E0004.throwError("Type size larger than expected", fmt::format("Pattern of type {} is larger than expected. Expected size {}, got {}", pattern->getTypeName(), requestedSize, actualSize), node->getLocation());

}

if (!pattern->hasOverriddenColor()) {
if (const auto &arguments = attributable->getAttributeArguments("color"); arguments.size() == 1) {
auto colorString = getAttributeValueAsString(arguments.front(), evaluator);
Expand Down

0 comments on commit 8909b96

Please sign in to comment.