Skip to content

Commit

Permalink
Merge pull request #75 from iboB/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
iboB authored Apr 6, 2023
2 parents 0136b71 + f98086c commit f332f90
Show file tree
Hide file tree
Showing 32 changed files with 796 additions and 407 deletions.
49 changes: 18 additions & 31 deletions code/dnmx/type_mutation.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,24 @@ DYNAMIX_API dnmx_type_mutation_handle dnmx_create_type_mutation_from_type(dnmx_t
DYNAMIX_API void dnmx_destroy_unused_type_mutation(dnmx_type_mutation_handle hmut);

DYNAMIX_API dnmx_domain_handle dnmx_type_mutation_get_domain(dnmx_type_mutation_handle hmut);
DYNAMIX_API dnmx_type_handle dnmx_type_mutation_get_base(dnmx_type_mutation_handle hmut);
DYNAMIX_API dnmx_type_template_handle dnmx_type_mutation_get_new_type(dnmx_type_mutation_handle hmut);

DYNAMIX_API void dnmx_type_mutation_reset(dnmx_type_mutation_handle hmut);
DYNAMIX_API bool dnmx_type_mutation_is_noop(dnmx_type_mutation_handle hmut);
DYNAMIX_API bool dnmx_type_mutation_is_adding(dnmx_type_mutation_handle hmut, const dnmx_mixin_info* info);
DYNAMIX_API const dnmx_mixin_info* dnmx_type_mutation_is_adding_by_name(dnmx_type_mutation_handle hmut, dnmx_sv name);
DYNAMIX_API bool dnmx_type_mutation_is_adding_mixins(dnmx_type_mutation_handle hmut);
DYNAMIX_API bool dnmx_type_mutation_is_removing(dnmx_type_mutation_handle hmut, const dnmx_mixin_info* info);
DYNAMIX_API const dnmx_mixin_info* dnmx_type_mutation_is_removing_by_name(dnmx_type_mutation_handle hmut, dnmx_sv name);
DYNAMIX_API bool dnmx_type_mutation_is_removing_mixins(dnmx_type_mutation_handle hmut);

// type template functions

DYNAMIX_API bool dnmx_type_template_has(dnmx_type_template_handle ht, const dnmx_mixin_info* info);
DYNAMIX_API const dnmx_mixin_info* dnmx_type_template_has_by_name(dnmx_type_template_handle ht, dnmx_sv name);
DYNAMIX_API bool dnmx_type_template_implements_strong(dnmx_type_template_handle ht, const dnmx_feature_info* info);
DYNAMIX_API const dnmx_feature_info* dnmx_type_template_implements_strong_by_name(dnmx_type_template_handle ht, dnmx_sv name);
DYNAMIX_API bool dnmx_type_template_implements(dnmx_type_template_handle ht, const dnmx_feature_info* info);

DYNAMIX_API bool dnmx_type_template_add(dnmx_type_template_handle ht, const dnmx_mixin_info* info);
DYNAMIX_API bool dnmx_type_template_add_if_lacking(dnmx_type_template_handle ht, const dnmx_mixin_info* info);

DYNAMIX_API bool dnmx_type_template_remove(dnmx_type_template_handle ht, const dnmx_mixin_info* info);
DYNAMIX_API const dnmx_mixin_info* dnmx_type_template_remove_by_name(dnmx_type_template_handle ht, dnmx_sv name);
DYNAMIX_API bool dnmx_type_template_to_back(dnmx_type_template_handle ht, const dnmx_mixin_info* info);
DYNAMIX_API const dnmx_mixin_info* dnmx_type_template_to_back_by_name(dnmx_type_template_handle ht, dnmx_sv name);
DYNAMIX_API void dnmx_type_template_dedup(dnmx_type_template_handle ht);

DYNAMIX_API const dnmx_mixin_info* const* dnmx_type_template_get_mixins(dnmx_type_template_handle ht, dnmx_mixin_index_t* out_num_mixins);
DYNAMIX_API bool dnmx_type_template_set_mixins(dnmx_type_template_handle ht, const dnmx_mixin_info* const* mixins, dnmx_mixin_index_t num_mixins);

DYNAMIX_API bool dnmx_type_mutation_has(dnmx_type_mutation_handle hmut, const dnmx_mixin_info* info);
DYNAMIX_API const dnmx_mixin_info* dnmx_type_mutation_has_by_name(dnmx_type_mutation_handle hmut, dnmx_sv name);
DYNAMIX_API bool dnmx_type_mutation_implements_strong(dnmx_type_mutation_handle hmut, const dnmx_feature_info* info);
DYNAMIX_API const dnmx_feature_info* dnmx_type_mutation_implements_strong_by_name(dnmx_type_mutation_handle hmut, dnmx_sv name);
DYNAMIX_API bool dnmx_type_mutation_implements(dnmx_type_mutation_handle hmut, const dnmx_feature_info* info);

DYNAMIX_API bool dnmx_type_mutation_add(dnmx_type_mutation_handle hmut, const dnmx_mixin_info* info);
DYNAMIX_API bool dnmx_type_mutation_add_if_lacking(dnmx_type_mutation_handle hmut, const dnmx_mixin_info* info);

DYNAMIX_API bool dnmx_type_mutation_remove(dnmx_type_mutation_handle hmut, const dnmx_mixin_info* info);
DYNAMIX_API const dnmx_mixin_info* dnmx_type_mutation_remove_by_name(dnmx_type_mutation_handle hmut, dnmx_sv name);
DYNAMIX_API bool dnmx_type_mutation_to_back(dnmx_type_mutation_handle hmut, const dnmx_mixin_info* info);
DYNAMIX_API const dnmx_mixin_info* dnmx_type_mutation_to_back_by_name(dnmx_type_mutation_handle hmut, dnmx_sv name);
DYNAMIX_API void dnmx_type_mutation_dedup(dnmx_type_mutation_handle hmut);

DYNAMIX_API const dnmx_mixin_info* const* dnmx_type_mutation_get_mixins(dnmx_type_mutation_handle hmut, dnmx_mixin_index_t* out_num_mixins);
DYNAMIX_API bool dnmx_type_mutation_set_mixins(dnmx_type_mutation_handle hmut, const dnmx_mixin_info* const* mixins, dnmx_mixin_index_t num_mixins);

#if defined(__cplusplus)
}
Expand Down
1 change: 0 additions & 1 deletion code/dnmx/type_mutation_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
#pragma once

typedef struct dnmx_tag_type_mutation* dnmx_type_mutation_handle;
typedef struct dnmx_tag_type_template* dnmx_type_template_handle;
2 changes: 1 addition & 1 deletion code/dynamix/common_mutation_rules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace impl {
template <typename Primary, typename Dependent>
error_return_t _apply_basic_mixin_dep(dnmx_type_mutation_handle mutation, uintptr_t) {
auto mut = type_mutation::from_c_handle(mutation);
if (mut->new_type().has<Primary>()) {
if (mut->has<Primary>()) {
mut->add_if_lacking<Dependent>();
}
return result_success;
Expand Down
14 changes: 7 additions & 7 deletions code/dynamix/domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace dynamix {

namespace {
error_return_t sort_by_canonical_order(dnmx_type_mutation_handle mutation, uintptr_t) {
auto& mixins = type_mutation::from_c_handle(mutation)->mod_new_type().mixins;
auto& mixins = type_mutation::from_c_handle(mutation)->mixins;
std::sort(mixins.begin(), mixins.end(), canonical_mixin_order{});
return result_success;
}
Expand Down Expand Up @@ -401,7 +401,7 @@ class domain::impl {
type_query original_query(m_allocator); // store original query here to return
type_query last_result(m_allocator); // store last rule application result here

auto& nt_mixins = mutation.mod_new_type().mixins;
auto& nt_mixins = mutation.mixins;
last_result = nt_mixins;

// first erase all deps from mixins
Expand All @@ -425,7 +425,7 @@ class domain::impl {
throw domain_error("rule interdependency too deep or cyclic");
}
if (i == 0) {
// first time running the loop and rules made changes, store original querty to return
// first time running the loop and rules made changes, store original query to return
original_query.swap(last_result);
}
last_result = nt_mixins;
Expand All @@ -439,15 +439,15 @@ class domain::impl {
{
// search for stored query for this combo
auto reg = m_registry.shared_lock();
auto f = reg->type_queries.find(mutation.new_type().mixins);
auto f = reg->type_queries.find(mutation.mixins);
if (f != reg->type_queries.end()) return *f->second;

// query is not available, so we need to apply mutation rules
// we can do it while holding the shared lock
original_query = apply_mutation_rules_l(mutation, reg->mutation_rules);

// now look for exact type
found = find_exact_type_l(mutation.new_type().mixins, reg->types);
found = find_exact_type_l(mutation.mixins, reg->types);
}

if (found) {
Expand Down Expand Up @@ -478,7 +478,7 @@ class domain::impl {
// creating a mutation will run more or less the exact same as above again
// TODO: optimize
type_mutation mut(m_empty_type, m_allocator);
mut.mod_new_type().mixins.assign(mixins.begin(), mixins.end());
mut.mixins.assign(mixins.begin(), mixins.end());
return get_type(mut);
}

Expand Down Expand Up @@ -623,7 +623,7 @@ class domain::impl {

// create type for a given mutation requested by a given query
const type& create_type(type_mutation& mutation, type_query&& query) {
itlib::span mixins(mutation.new_type().mixins);
mixin_info_span mixins(mutation.mixins);

// first check validity
for (size_t i = 0; i < mixins.size(); ++i) {
Expand Down
1 change: 1 addition & 0 deletions code/dynamix/mutate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once
#include "mutate_ops.hpp"
#include "mutate_to.hpp"
#include "domain.hpp"

namespace dynamix {
// regular mutate with ops as arguments
Expand Down
1 change: 1 addition & 0 deletions code/dynamix/mutate_to_ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "object_mutate_ops.hpp"
#include "mixin_info.hpp"
#include "object.hpp"
#include "domain.hpp"

#include <string_view>

Expand Down
68 changes: 17 additions & 51 deletions code/dynamix/type_mutation-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dnmx_type_mutation_handle dnmx_create_type_mutation_empty(dnmx_domain_handle hd)
return nullptr;
}
}

dnmx_type_mutation_handle dnmx_create_type_mutation_from_type(dnmx_type_handle ht) {
try {
auto mut = new type_mutation(*type::from_c_handle(ht));
Expand All @@ -30,67 +31,32 @@ dnmx_type_mutation_handle dnmx_create_type_mutation_from_type(dnmx_type_handle h
return nullptr;
}
}

void dnmx_destroy_unused_type_mutation(dnmx_type_mutation_handle hmut) {
delete self;
}

dnmx_domain_handle dnmx_type_mutation_get_domain(dnmx_type_mutation_handle hmut) {
return self->get_domain().to_c_hanlde();
}
dnmx_type_handle dnmx_type_mutation_get_base(dnmx_type_mutation_handle hmut) {
return &self->base();
}
dnmx_type_template_handle dnmx_type_mutation_get_new_type(dnmx_type_mutation_handle hmut) {
return self->mod_new_type().to_c_hanlde();
}

void dnmx_type_mutation_reset(dnmx_type_mutation_handle hmut) {
self->reset();
}
bool dnmx_type_mutation_is_noop(dnmx_type_mutation_handle hmut) {
return self->noop();
}
bool dnmx_type_mutation_is_adding(dnmx_type_mutation_handle hmut, const dnmx_mixin_info* info) {
return self->adding(*info);
return self->dom.to_c_hanlde();
}
const dnmx_mixin_info* dnmx_type_mutation_is_adding_by_name(dnmx_type_mutation_handle hmut, dnmx_sv name) {
return self->adding(name.to_std());
}
bool dnmx_type_mutation_is_adding_mixins(dnmx_type_mutation_handle hmut) {
return self->adding_mixins();
}
bool dnmx_type_mutation_is_removing(dnmx_type_mutation_handle hmut, const dnmx_mixin_info* info) {
return self->removing(*info);
}
const dnmx_mixin_info* dnmx_type_mutation_is_removing_by_name(dnmx_type_mutation_handle hmut, dnmx_sv name) {
return self->removing(name.to_std());
}
bool dnmx_type_mutation_is_removing_mixins(dnmx_type_mutation_handle hmut) {
return self->removing_mixins();
}

#undef self
#define self type_mutation::type_template::from_c_handle(ht)

// type template functions

bool dnmx_type_template_has(dnmx_type_template_handle ht, const dnmx_mixin_info* info) {
bool dnmx_type_mutation_has(dnmx_type_mutation_handle hmut, const dnmx_mixin_info* info) {
return self->has(*info);
}
const dnmx_mixin_info* dnmx_type_template_has_by_name(dnmx_type_template_handle ht, dnmx_sv name) {
const dnmx_mixin_info* dnmx_type_mutation_has_by_name(dnmx_type_mutation_handle hmut, dnmx_sv name) {
return self->has(name.to_std());
}
bool dnmx_type_template_implements_strong(dnmx_type_template_handle ht, const dnmx_feature_info* info) {
bool dnmx_type_mutation_implements_strong(dnmx_type_mutation_handle hmut, const dnmx_feature_info* info) {
return self->implements_strong(*info);
}
const dnmx_feature_info* dnmx_type_template_implements_strong_by_name(dnmx_type_template_handle ht, dnmx_sv name) {
const dnmx_feature_info* dnmx_type_mutation_implements_strong_by_name(dnmx_type_mutation_handle hmut, dnmx_sv name) {
return self->implements_strong(name.to_std());
}
bool dnmx_type_template_implements(dnmx_type_template_handle ht, const dnmx_feature_info* info) {
bool dnmx_type_mutation_implements(dnmx_type_mutation_handle hmut, const dnmx_feature_info* info) {
return self->implements(*info);
}

bool dnmx_type_template_add(dnmx_type_template_handle ht, const dnmx_mixin_info* info) {
bool dnmx_type_mutation_add(dnmx_type_mutation_handle hmut, const dnmx_mixin_info* info) {
try {
self->add(*info);
return true;
Expand All @@ -99,21 +65,21 @@ bool dnmx_type_template_add(dnmx_type_template_handle ht, const dnmx_mixin_info*
return false;
}
}
bool dnmx_type_template_add_if_lacking(dnmx_type_template_handle ht, const dnmx_mixin_info* info) {
bool dnmx_type_mutation_add_if_lacking(dnmx_type_mutation_handle hmut, const dnmx_mixin_info* info) {
try {
return self->add_if_lacking(*info);
}
catch (std::exception&) {
return false;
}
}
bool dnmx_type_template_remove(dnmx_type_template_handle ht, const dnmx_mixin_info* info) {
bool dnmx_type_mutation_remove(dnmx_type_mutation_handle hmut, const dnmx_mixin_info* info) {
return self->remove(*info);
}
const dnmx_mixin_info* dnmx_type_template_remove_by_name(dnmx_type_template_handle ht, dnmx_sv name) {
const dnmx_mixin_info* dnmx_type_mutation_remove_by_name(dnmx_type_mutation_handle hmut, dnmx_sv name) {
return self->remove(name.to_std());
}
bool dnmx_type_template_to_back(dnmx_type_template_handle ht, const dnmx_mixin_info* info) {
bool dnmx_type_mutation_to_back(dnmx_type_mutation_handle hmut, const dnmx_mixin_info* info) {
try {
self->to_back(*info);
return true;
Expand All @@ -122,25 +88,25 @@ bool dnmx_type_template_to_back(dnmx_type_template_handle ht, const dnmx_mixin_i
return false;
}
}
const dnmx_mixin_info* dnmx_type_template_to_back_by_name(dnmx_type_template_handle ht, dnmx_sv name) {
const dnmx_mixin_info* dnmx_type_mutation_to_back_by_name(dnmx_type_mutation_handle hmut, dnmx_sv name) {
try {
return &self->to_back(name.to_std());
}
catch (std::exception&) {
return nullptr;
}
}
void dnmx_type_template_dedup(dnmx_type_template_handle ht) {
void dnmx_type_mutation_dedup(dnmx_type_mutation_handle hmut) {
self->dedup();
}

const dnmx_mixin_info* const* dnmx_type_template_get_mixins(dnmx_type_template_handle ht, dnmx_mixin_index_t* out_num_mixins) {
const dnmx_mixin_info* const* dnmx_type_mutation_get_mixins(dnmx_type_mutation_handle hmut, dnmx_mixin_index_t* out_num_mixins) {
const auto& vec = self->mixins;
*out_num_mixins = dnmx_mixin_index_t(vec.size());
return vec.data();
}

bool dnmx_type_template_set_mixins(dnmx_type_template_handle ht, const dnmx_mixin_info* const* mixins, dnmx_mixin_index_t num_mixins) {
bool dnmx_type_mutation_set_mixins(dnmx_type_mutation_handle hmut, const dnmx_mixin_info* const* mixins, dnmx_mixin_index_t num_mixins) {
try {
self->mixins.assign(mixins, mixins + num_mixins);
return true;
Expand Down
Loading

0 comments on commit f332f90

Please sign in to comment.