King_DuckZ
eadd25b827
This commit breaks the ARM64 version, I will fix it next. Lots going on here. DynafuncMaker got updated to store strings to back the ModuleAndName objects that get hardcoded in the assembly glue function. ModuleAndName is not a typedef to a tuple anymore, because I discovered that tuples suck. They get always pushed on the stack when passed as parameter, instead the new implementation gets passed into 2 registers being it a standard layout type. dhandy::bt::string got updated so it can be used as a literal value for non-type template parameters, which allowed for a really easy to use `wren::MN<>` helper. Code now fully requires c++20.
92 lines
2.9 KiB
C++
92 lines
2.9 KiB
C++
/* Copyright 2020-2022, Michele Santullo
|
|
* This file is part of wrenpp.
|
|
*
|
|
* Wrenpp is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Wrenpp is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with wrenpp. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "wrenpp/vm_fun.hpp"
|
|
#include <cassert>
|
|
#include <iterator>
|
|
#include <utility>
|
|
|
|
namespace wren {
|
|
namespace detail {
|
|
} //namespace detail
|
|
|
|
void set (VM& vm, int slot_num, const char* beg, const char* end) {
|
|
vm.set_slot_bytes(slot_num, beg, std::distance(beg, end));
|
|
}
|
|
|
|
std::string_view slot_string_view (VM& vm, int slot_num) {
|
|
assert(SlotType::String == vm.slot_type(slot_num));
|
|
auto ptr = vm.slot_bytes(slot_num);
|
|
return {ptr.first, static_cast<std::size_t>(ptr.second)};
|
|
}
|
|
|
|
template<> const char* get<const char*> (VM& vm, int slot_num) {
|
|
return vm.slot_string(slot_num);
|
|
}
|
|
|
|
template <> double get<double> (VM& vm, int slot_num) {
|
|
return vm.slot_double(slot_num);
|
|
}
|
|
|
|
template <> bool get<bool> (VM& vm, int slot_num) {
|
|
return vm.slot_bool(slot_num);
|
|
}
|
|
|
|
template <> std::pair<const char*, int> get<std::pair<const char*,int>> (VM& vm, int slot_num) {
|
|
return vm.slot_bytes(slot_num);
|
|
}
|
|
|
|
template<> int get<int> (VM& vm, int slot_num) {
|
|
return static_cast<int>(vm.slot_double(slot_num));
|
|
}
|
|
|
|
template<> std::size_t get<std::size_t> (VM& vm, int slot_num) {
|
|
return static_cast<std::size_t>(vm.slot_double(slot_num));
|
|
}
|
|
|
|
template<> std::string get<std::string> (VM& vm, int slot_num) {
|
|
return {vm.slot_string(slot_num)};
|
|
}
|
|
|
|
template <> std::string_view get<std::string_view> (VM& vm, int slot_num) {
|
|
auto arr = get<std::pair<const char*, int>>(vm, slot_num);
|
|
return std::string_view{arr.first, static_cast<std::size_t>(arr.second)};
|
|
}
|
|
|
|
template <> std::vector<char> get<std::vector<char>> (VM& vm, int slot_num) {
|
|
auto arr = get<std::pair<const char*, int>>(vm, slot_num);
|
|
return std::vector<char>{arr.first, arr.first + arr.second};
|
|
}
|
|
|
|
void variable(VM& vm, ModuleAndName mod_and_name, int slot) {
|
|
vm.variable_or_throw(mod_and_name.module_name_char(), mod_and_name.class_name_char(), slot);
|
|
}
|
|
|
|
void variable (VM& vm, const Handle& handle, int slot) {
|
|
vm.set_slot_handle(handle, slot);
|
|
}
|
|
|
|
void variable_ensure_slot(VM& vm, ModuleAndName mod_and_name, int slot) {
|
|
vm.ensure_slots(1);
|
|
variable(vm, mod_and_name, slot);
|
|
}
|
|
|
|
void variable_ensure_slot (VM& vm, const Handle& handle, int slot) {
|
|
vm.ensure_slots(1);
|
|
variable(vm, handle, slot);
|
|
}
|
|
} //namespace wren
|