Skip to content

Commit

Permalink
more cleanup, rename definition to overrider
Browse files Browse the repository at this point in the history
  • Loading branch information
jll63 committed Sep 18, 2024
1 parent 66492b9 commit d7fbcee
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 40 deletions.
24 changes: 24 additions & 0 deletions dev/header-check
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/env python3

import contextlib
from pathlib import Path
import os
import sys

import mdgen

out_path = Path(sys.argv[2]).absolute()

source = os.path.abspath(sys.argv[1]).replace(os.path.abspath(mdgen.repository), "")

with open(sys.argv[1]) as rh:
text = rh.read()

with contextlib.suppress(FileNotFoundError):
out_path.chmod(0o600)

with open(out_path, "w") as wh:
text = mdgen.replace_md(text, source=source)
print(text, file=wh, end="")

out_path.chmod(0o400)
2 changes: 1 addition & 1 deletion include/yorel/yomm2/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ method<Name, Return(Parameters...), Options...>::override_fn_impl<
p_next = &next<Function>;
}

static detail::definition_info info;
static detail::overrider_info info;

if (info.method) {
BOOST_ASSERT(info.method == &fn);
Expand Down
68 changes: 34 additions & 34 deletions include/yorel/yomm2/detail/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ struct generic_compiler {
}
};

struct definition {
const detail::definition_info* info;
struct overrider {
const detail::overrider_info* info;
std::vector<class_*> vp;
std::uintptr_t pf;
std::size_t method_index, spec_index;
Expand Down Expand Up @@ -147,14 +147,14 @@ struct generic_compiler {
struct method {
detail::method_info* info;
std::vector<class_*> vp;
std::vector<definition> specs;
std::vector<overrider> specs;
std::vector<std::size_t> slots;
std::vector<std::size_t> strides;
std::vector<const definition*> dispatch_table;
std::vector<const overrider*> dispatch_table;
// following two are dummies, when converting to a function pointer, we will
// get the corresponding pointer from method_info
definition not_implemented;
definition ambiguous;
overrider not_implemented;
overrider ambiguous;
const std::uintptr_t* gv_dispatch_table{nullptr};
auto arity() const {
return vp.size();
Expand Down Expand Up @@ -199,11 +199,11 @@ trace_type<Policy>& operator<<(
struct spec_name {
spec_name(
const detail::generic_compiler::method& method,
const detail::generic_compiler::definition* def)
const detail::generic_compiler::overrider* def)
: method(method), def(def) {
}
const detail::generic_compiler::method& method;
const detail::generic_compiler::definition* def;
const detail::generic_compiler::overrider* def;
};

template<class Policy>
Expand Down Expand Up @@ -251,10 +251,10 @@ struct compiler : detail::generic_compiler {
bool concrete);
void install_gv();
void print(const update_method_report& report) const;
static std::vector<const definition*>
best(std::vector<const definition*>& candidates);
static bool is_more_specific(const definition* a, const definition* b);
static bool is_base(const definition* a, const definition* b);
static std::vector<const overrider*>
best(std::vector<const overrider*>& candidates);
static bool is_more_specific(const overrider* a, const overrider* b);
static bool is_base(const overrider* a, const overrider* b);

static type_id static_type(type_id type) {
if constexpr (std::is_base_of_v<
Expand Down Expand Up @@ -342,15 +342,15 @@ void compiler<Policy>::resolve_static_type_ids() {
}

if (!method.specs.empty())
for (auto& definition : method.specs) {
if (*definition.vp_end == 0) {
for (auto& overrider : method.specs) {
if (*overrider.vp_end == 0) {
for (auto& ti : range{
definition.vp_begin,
definition.vp_end}) {
overrider.vp_begin,
overrider.vp_end}) {
resolve(&ti);
}

*definition.vp_end = 1;
*overrider.vp_end = 1;
}
}
}
Expand Down Expand Up @@ -578,18 +578,18 @@ void compiler<Policy>::augment_methods() {
meth_iter->specs.resize(spec_size);
auto spec_iter = meth_iter->specs.begin();

for (auto& definition_info : meth_info.specs) {
for (auto& overrider_info : meth_info.specs) {
spec_iter->method_index = meth_iter - methods.begin();
spec_iter->spec_index = spec_iter - meth_iter->specs.begin();

++trace << type_name(definition_info.type) << " ("
<< definition_info.pf << ")\n";
spec_iter->info = &definition_info;
++trace << type_name(overrider_info.type) << " ("
<< overrider_info.pf << ")\n";
spec_iter->info = &overrider_info;
spec_iter->vp.reserve(meth_info.arity());
std::size_t param_index = 0;

for (auto type :
range{definition_info.vp_begin, definition_info.vp_end}) {
range{overrider_info.vp_begin, overrider_info.vp_end}) {
indent _(trace);
auto class_ = class_map[Policy::type_index(type)];
if (!class_) {
Expand Down Expand Up @@ -892,18 +892,18 @@ void compiler<Policy>::build_dispatch_tables() {
accumulate(m.report, report);
++trace << "assigning next\n";

std::vector<const definition*> specs;
std::vector<const overrider*> specs;
std::transform(
m.specs.begin(), m.specs.end(), std::back_inserter(specs),
[](const definition& spec) { return &spec; });
[](const overrider& spec) { return &spec; });

for (auto& spec : m.specs) {
indent _(trace);
++trace << type_name(spec.info->type) << ":\n";
std::vector<const definition*> candidates;
std::vector<const overrider*> candidates;
std::copy_if(
specs.begin(), specs.end(), std::back_inserter(candidates),
[&spec](const definition* other) {
[&spec](const overrider* other) {
return is_base(other, &spec);
});

Expand All @@ -922,7 +922,7 @@ void compiler<Policy>::build_dispatch_tables() {
void* next;

if (nexts.size() == 1) {
const definition_info* next_info = nexts.front()->info;
const overrider_info* next_info = nexts.front()->info;
next = next_info->pf;
++trace << "-> "
<< "#" << nexts.front()->spec_index
Expand Down Expand Up @@ -966,7 +966,7 @@ void compiler<Policy>::build_dispatch_table(
}

if (dim == 0) {
std::vector<const definition*> applicable;
std::vector<const overrider*> applicable;
std::size_t i = 0;

for (const auto& spec : m.specs) {
Expand Down Expand Up @@ -1129,12 +1129,12 @@ void compiler<Policy>::install_gv() {
}

template<class Policy>
std::vector<const detail::generic_compiler::definition*>
compiler<Policy>::best(std::vector<const definition*>& candidates) {
std::vector<const definition*> best;
std::vector<const detail::generic_compiler::overrider*>
compiler<Policy>::best(std::vector<const overrider*>& candidates) {
std::vector<const overrider*> best;

for (auto spec : candidates) {
const definition* candidate = spec;
const overrider* candidate = spec;

for (auto iter = best.begin(); iter != best.end();) {
if (is_more_specific(spec, *iter)) {
Expand All @@ -1157,7 +1157,7 @@ compiler<Policy>::best(std::vector<const definition*>& candidates) {

template<class Policy>
bool compiler<Policy>::is_more_specific(
const definition* a, const definition* b) {
const overrider* a, const overrider* b) {
bool result = false;

auto a_iter = a->vp.begin(), a_last = a->vp.end(), b_iter = b->vp.begin();
Expand All @@ -1179,7 +1179,7 @@ bool compiler<Policy>::is_more_specific(
}

template<class Policy>
bool compiler<Policy>::is_base(const definition* a, const definition* b) {
bool compiler<Policy>::is_base(const overrider* a, const overrider* b) {
bool result = false;

auto a_iter = a->vp.begin(), a_last = a->vp.end(), b_iter = b->vp.begin();
Expand Down
1 change: 1 addition & 0 deletions include/yorel/yomm2/detail/trace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define YOREL_YOMM2_DETAIL_TRACE_HPP

#include <yorel/yomm2/detail/types.hpp>
#include <yorel/yomm2/policies/core.hpp>

#include <boost/dynamic_bitset.hpp>

Expand Down
8 changes: 4 additions & 4 deletions include/yorel/yomm2/detail/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ struct class_info : static_list<class_info>::static_link {
// -----------
// method info

struct definition_info;
struct overrider_info;

struct yOMM2_API method_info : static_list<method_info>::static_link {
type_id *vp_begin, *vp_end;
static_list<definition_info> specs;
static_list<overrider_info> specs;
void* ambiguous;
void* not_implemented;
type_id method_type;
Expand All @@ -102,8 +102,8 @@ struct yOMM2_API method_info : static_list<method_info>::static_link {
}
};

struct definition_info : static_list<definition_info>::static_link {
~definition_info() {
struct overrider_info : static_list<overrider_info>::static_link {
~overrider_info() {
method->specs.remove(*this);
}

Expand Down
3 changes: 3 additions & 0 deletions include/yorel/yomm2/policies/vectored_error_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

#include <yorel/yomm2/policies/core.hpp>

#include <functional>
#include <variant>

namespace yorel {
namespace yomm2 {
namespace policies {
Expand Down
2 changes: 2 additions & 0 deletions include/yorel/yomm2/templates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#ifndef YOREL_YOMM2_TEMPLATES_HPP
#define YOREL_YOMM2_TEMPLATES_HPP

#include <yorel/yomm2/detail/types.hpp>

#include <boost/mp11/algorithm.hpp>
#include <boost/mp11/bind.hpp>
#include <boost/mp11/list.hpp>
Expand Down
2 changes: 1 addition & 1 deletion tests/test_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using namespace yorel::yomm2::detail;

using class_ = generic_compiler::class_;
using cc_method = generic_compiler::method;
using definition = generic_compiler::definition;
using overrider = generic_compiler::overrider;

std::ostream& operator<<(std::ostream& os, const class_* cls) {
return os
Expand Down

0 comments on commit d7fbcee

Please sign in to comment.