added frame userdata key

lib
Avril 3 years ago
parent 69ce31afb1
commit bc2857fc86
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -3,11 +3,15 @@
#include "box.h" #include "box.h"
#include <cstdint> #include <cstdint>
#define _SM_STACK_SIZE 256 #define _SM_STACK_SIZE 15
#define _SM_KEY_SIZE (UINT64_MAX >> 2)
struct _sm_user { struct _sm_user {
bool set ;//: 1; No need for these to be bitfield packed, there's an alignment hole here anyway. uint64_t set : 1;
bool free ;//: 1; uint64_t free : 1;
uint64_t key : 62;
union { union {
uint8_t _8; uint8_t _8;

@ -4,23 +4,51 @@
typedef void* (*sm_yield)(sm_state* state); //NOTE: This `void*` is a stand-in for this function returning itself. typedef void* (*sm_yield)(sm_state* state); //NOTE: This `void*` is a stand-in for this function returning itself.
inline uint64_t _sm_confine_key(uint64_t ui)
{
return ui & _SM_KEY_SIZE;
}
inline uint64_t _sm_compute_key(uint64_t name)
{
return _sm_confine_key(name);
}
template<typename T, typename U> template<typename T, typename U>
inline T* _sm_var(sm_state* state, U name, T init) inline T* _sm_var(_sm_user_page* user, U name, T init)
{ {
auto val = &state->current->user.data[name]; auto skey = name % _SM_STACK_SIZE;
bool set = val->set;
val->set = true; auto val = &user->data[skey];
return ( ! set ) ? auto key = _sm_compute_key( (uint64_t)name );
(val->free = false, _sm_init<T>(val, init)) :
_sm_get<T>(val); bool set = val->set;
if(!set) {
val->set = true;
val->free = false;
val->key = key;
return _sm_init<T>(val, init);
}
else if(key == val->key) {
//TODO: Check equality of value somehow
return _sm_get<T>(val);
} else {
// Move to next page
if(!user->next) user->next = box<_sm_user_page, true>();
return _sm_var<T, U>(user->next, name, init);
}
}
template<typename T, typename U>
inline T* _sm_var(sm_state* state, U name, T init)
{
return _sm_var<T,U>(&state->current->user, name, init);
} }
template<uint64_t name, typename T> template<uint64_t name, typename T>
inline T* _sm_var(sm_state* state, T init) inline T* _sm_var(sm_state* state, T init)
{ {
static_assert(name < _SM_STACK_SIZE, "Line pseudo-hashmap not yet implemented"); //static_assert(name < _SM_STACK_SIZE, "Line pseudo-hashmap not yet implemented");
return _sm_var(state, name, init); return _sm_var(state, name, init);
} }

Loading…
Cancel
Save