Skip to content

Commit c2e4a67

Browse files
committed
lib: Allow std::mem::size and std::mem::base_address to work in sections
1 parent 8377276 commit c2e4a67

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/source/pl/lib/std/mem.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,24 @@ namespace pl::lib::libstd::mem {
5959
{
6060

6161
/* base_address() */
62-
runtime.addFunction(nsStdMem, "base_address", FunctionParameterCount::none(), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
63-
wolv::util::unused(params);
62+
runtime.addFunction(nsStdMem, "base_address", FunctionParameterCount::between(0, 1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
63+
auto section = params.size() == 1 ? params[0].toUnsigned() : ptrn::Pattern::MainSectionId;
64+
if (section == 0xFFFF'FFFF'FFFF'FFFF)
65+
section = ctx->getUserSectionId();
66+
67+
if (section != ptrn::Pattern::MainSectionId)
68+
return 0;
6469

6570
return u128(ctx->getDataBaseAddress());
6671
});
6772

6873
/* size() */
69-
runtime.addFunction(nsStdMem, "size", FunctionParameterCount::none(), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
70-
wolv::util::unused(params);
74+
runtime.addFunction(nsStdMem, "size", FunctionParameterCount::between(0, 1), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
75+
auto section = params.size() == 1 ? params[0].toUnsigned() : ptrn::Pattern::MainSectionId;
76+
if (section == 0xFFFF'FFFF'FFFF'FFFF)
77+
section = ctx->getUserSectionId();
7178

72-
return u128(ctx->getDataSize());
79+
return u128(ctx->getSectionSize(section));
7380
});
7481

7582
/* find_sequence_in_range(occurrence_index, start_offset, end_offset, bytes...) */

0 commit comments

Comments
 (0)