libriscv / rvscript

Fast RISC-V-based scripting backend for game engines
MIT License
239 stars 7 forks source link

Game::setting does not work in debug mode #9

Open fwsGonzo opened 5 months ago

fwsGonzo commented 5 months ago
inline std::optional<intptr_t> Game::setting(std::string_view setting)
{
    register const char* name_ptr  asm("a0") = setting.begin();
    register unsigned    name_len  asm("a1") = setting.size();
    register long        sysno     asm("a7") = ECALL_GAME_SETTING;
    register bool        has_value asm("a0");
    register intptr_t    result    asm("a1");

    asm("ecall"
        : "=r"(has_value), "=r"(result)
        : "m"(*(const char(*)[name_len])name_ptr),
          "r"(name_ptr), "r"(name_len), "r"(sysno));

    if (has_value) return int64_t(result);
    return std::nullopt;
}

Looking at this, I cannot see what's wrong. It just doesn't work. Can you see what's wrong?