Skip to content

Commit

Permalink
more macro work
Browse files Browse the repository at this point in the history
  • Loading branch information
jll63 committed Sep 22, 2024
1 parent afffbf0 commit 0e32aee
Show file tree
Hide file tree
Showing 21 changed files with 158 additions and 237 deletions.
16 changes: 0 additions & 16 deletions docs.in/reference/YOMM2_GENSYM.md

This file was deleted.

17 changes: 0 additions & 17 deletions docs.in/reference/YOMM2_STATIC.md

This file was deleted.

31 changes: 0 additions & 31 deletions docs.in/reference/YOMM2_SYMBOL.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion docs.in/reference/declare_static_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

macro: declare_static_method
headers: yorel/yomm2/cute.hpp, yorel/yomm2.hpp
hrefs: YOMM2_STATIC_DECLARE
hrefs: YOMM2_STATIC_METHOD

```c++
#define declare_static_method(name, (types), return -type) /*unspecified*/
Expand Down
2 changes: 1 addition & 1 deletion docs.in/reference/define_method.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef YOMM2_MD

hrefs: YOMM2_DEFINE
hrefs: YOMM2_OVERRIDE

macro: define_method
headers: yorel/yomm2/cute.hpp, yorel/yomm2.hpp></sub
Expand Down
14 changes: 7 additions & 7 deletions docs.in/reference/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ make sense, see the example below.

#include <yorel/yomm2/core.hpp>
#include <yorel/yomm2/compiler.hpp>
#include <yorel/yomm2/symbols.hpp> // for YOMM2_GENSYM
#include <yorel/yomm2/macros.hpp>

#include <memory>
#include <string>
Expand All @@ -189,30 +189,30 @@ struct Bulldog : Dog {};
namespace yomm2 = yorel::yomm2; // for brevity
using yomm2::virtual_;

YOMM2_STATIC(yomm2::use_classes<Animal, Cat, Dog, Bulldog>);
YOMM2_REGISTER(yomm2::use_classes<Animal, Cat, Dog, Bulldog>);

struct kick_methods;
using kick = yomm2::method<kick_methods(virtual_<Animal&>), std::string>;

std::string kick_cat(Cat& dog) { return "hiss"; }
YOMM2_STATIC(kick::override_fn<kick_cat>);
YOMM2_REGISTER(kick::override_fn<kick_cat>);

std::string kick_dog(Dog& dog) { return "bark"; }
YOMM2_STATIC(kick::override_fn<kick_dog>);
YOMM2_REGISTER(kick::override_fn<kick_dog>);

struct kick_bulldog : kick::with_next<kick_bulldog> {
static std::string fn(Bulldog& dog) { return next(dog) + " and bite"; }
};
YOMM2_STATIC(kick::override<kick_bulldog>);
YOMM2_REGISTER(kick::override<kick_bulldog>);

struct YOMM2_METHOD_NAME(pet); // use obfuscated name
using pet = yomm2::method<YOMM2_METHOD_NAME(pet)(virtual_<Animal&>), std::string>;

std::string pet_cat(Cat& dog) { return "purr"; }
YOMM2_STATIC(pet::override_fn<pet_cat>);
YOMM2_REGISTER(pet::override_fn<pet_cat>);

std::string pet_dog(Dog& dog) { return "wag tail"; }
YOMM2_STATIC(pet::override_fn<pet_dog>);
YOMM2_REGISTER(pet::override_fn<pet_dog>);

BOOST_AUTO_TEST_CASE(ref_method_example) {
yomm2::initialize();
Expand Down
12 changes: 6 additions & 6 deletions docs.in/reference/use_classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ Classes can also be registered incrementally:

#ifdef YOMM2_CODE

YOMM2_STATIC(use_classes<Animal, Herbivore, Carnivore>);
YOMM2_STATIC(use_classes<Omnivore, Human, Wolf>);
YOMM2_STATIC(use_classes<Sheep, Herbivore>);
YOMM2_REGISTER(use_classes<Animal, Herbivore, Carnivore>);
YOMM2_REGISTER(use_classes<Omnivore, Human, Wolf>);
YOMM2_REGISTER(use_classes<Sheep, Herbivore>);

#endif

Expand All @@ -130,9 +130,9 @@ and `Wolf` derive from `Omnivore`.

#ifdef YOMM2_CODE

YOMM2_STATIC(use_classes<Animal, Herbivore, Carnivore, Omnivore>);
YOMM2_STATIC(use_classes<Human, Wolf>); // wrong!
YOMM2_STATIC(use_classes<Sheep, Herbivore>); // ok
YOMM2_REGISTER(use_classes<Animal, Herbivore, Carnivore, Omnivore>);
YOMM2_REGISTER(use_classes<Human, Wolf>); // wrong!
YOMM2_REGISTER(use_classes<Sheep, Herbivore>); // ok

#endif

Expand Down
8 changes: 4 additions & 4 deletions docs.in/reference/use_definitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct sparse_matrix : abstract_matrix {};

#include <yorel/yomm2/core.hpp>
#include <yorel/yomm2/compiler.hpp>
#include <yorel/yomm2/symbols.hpp>
#include <yorel/yomm2/macros/register.hpp>
#include <yorel/yomm2/templates.hpp>

using namespace yorel::yomm2; // for brevity
Expand All @@ -43,15 +43,15 @@ using boost::mp11::mp_list;
use_classes<abstract_matrix, ordinary_matrix, square_matrix, sparse_matrix>
YOMM2_GENSYM;

struct YOMM2_METHOD_NAME(same_type);
using same_type = method<YOMM2_METHOD_NAME(same_type)(
struct same_type_;
using same_type = method<same_type_(
virtual_<const abstract_matrix&>, virtual_<const abstract_matrix&>), bool>;

// 1 - see notes below
bool same_type_catch_all(const abstract_matrix&, const abstract_matrix&) {
return false;
}
YOMM2_STATIC(same_type::override_fn<same_type_catch_all>);
YOMM2_REGISTER(same_type::override_fn<same_type_catch_all>);

// 2
template<class Method, typename...>
Expand Down
16 changes: 8 additions & 8 deletions docs.in/tutorials/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ BOOST_AUTO_TEST_CASE(test_synopsis_functions_no_macros) {
// ## A peek inside the two main YOMM2 macros

// The code in the example above is essentially what
// `YOMM2_DECLARE`/`declare_method` and `YOMM2_DEFINE`/`define_method` generate.
// `YOMM2_METHOD`/`declare_method` and `YOMM2_OVERRIDE`/`define_method` generate.

// In addition, `declare_method` generates an ordinary inline function that
// forwards to the `fn` object nested inside the method. Importantly, ordinary
Expand All @@ -187,7 +187,7 @@ BOOST_AUTO_TEST_CASE(test_synopsis_functions_no_macros) {
// - `YOMM2_GENSYM` expands to a new symbol each time it is called. It is used
// for the static "registrar" objects.

// - `YOMM2_STATIC(...)` expands to `static __VA_ARGS__ YOMM2_GENSYM`, i.e. it
// - `YOMM2_REGISTER(...)` expands to `static __VA_ARGS__ YOMM2_GENSYM`, i.e. it
// creates a static object of the type specified as macro parameters.

// - `YOMM2_METHOD_NAME(name)` expands to an obfuscated version of `name`. It is used
Expand Down Expand Up @@ -235,15 +235,15 @@ class Bulldog : public Dog {};
// code<
#include <yorel/yomm2/core.hpp>
#include <yorel/yomm2/compiler.hpp>
#include <yorel/yomm2/symbols.hpp>
#include <yorel/yomm2/macros/register.hpp>

using namespace yorel::yomm2;

YOMM2_STATIC(use_classes<Animal, Dog, Bulldog>);
YOMM2_REGISTER(use_classes<Animal, Dog, Bulldog>);

struct YOMM2_METHOD_NAME(kick);
struct kick_;

using kick = method<YOMM2_METHOD_NAME(kick)(virtual_<Animal&>), std::string>;
using kick = method<kick_(virtual_<Animal&>), std::string>;

// >

Expand All @@ -266,7 +266,7 @@ struct kick_dog {
}
};

YOMM2_STATIC(kick::override<kick_dog>);
YOMM2_REGISTER(kick::override<kick_dog>);
// >

// md<
Expand All @@ -287,7 +287,7 @@ struct kick_bulldog : kick::with_next<kick_bulldog> {
}
};

YOMM2_STATIC(kick::override<kick_bulldog>);
YOMM2_REGISTER(kick::override<kick_bulldog>);
// >

// md<
Expand Down
47 changes: 22 additions & 25 deletions docs.in/tutorials/templates_tutorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ std::ostream &operator<<(std::ostream &os, const std::type_info &ti) {

#include <yorel/yomm2/compiler.hpp>
#include <yorel/yomm2/core.hpp>
#include <yorel/yomm2/symbols.hpp>
#include <yorel/yomm2/macros/register.hpp>
#include <yorel/yomm2/templates.hpp>

using namespace yorel::yomm2;
Expand Down Expand Up @@ -232,26 +232,26 @@ vector reals(new concrete_vector<double>{4., 5., 6.});

using namespace yorel::yomm2;

struct YOMM2_METHOD_NAME(addition);
struct addition_;

using addition = method<
YOMM2_METHOD_NAME(addition)(
addition_(
virtual_<abstract_vector&>,
virtual_<abstract_vector&>),
vector>;

struct YOMM2_METHOD_NAME(subtraction);
struct subtraction_;

using subtraction = method<
YOMM2_METHOD_NAME(subtraction)(
subtraction_(
virtual_<abstract_vector&>,
virtual_<abstract_vector&>),
vector>;

struct YOMM2_METHOD_NAME(comparison);
struct comparision_;

using comparison = method<
YOMM2_METHOD_NAME(comparison)(
comparision_(
virtual_<abstract_vector&>,
virtual_<abstract_vector&>),
bool>;
Expand Down Expand Up @@ -447,18 +447,18 @@ static_assert(

// code<

use_classes<
YOMM2_REGISTER(use_classes<
abstract_vector, concrete_vector<int>, concrete_vector<double>
> YOMM2_GENSYM;
>);

use_definitions<
YOMM2_REGISTER(use_definitions<
definition,
product<
types<addition, subtraction, comparison>,
types<int, double>,
types<int, double>
>
> YOMM2_GENSYM;
>);

// >

Expand Down Expand Up @@ -882,11 +882,10 @@ BOOST_AUTO_TEST_CASE(test_static_operations) {

// code<

struct YOMM2_METHOD_NAME(transpose);
struct transpose_;

template<typename Matrix>
using transpose =
method<YOMM2_METHOD_NAME(transpose)(virtual_<Matrix&>), handle<Matrix>>;
using transpose = method<transpose_(virtual_<Matrix&>), handle<Matrix>>;

template<
template<typename> typename Matrix, typename T,
Expand Down Expand Up @@ -1026,12 +1025,11 @@ using matrix_templates = boost::mp11::mp_append<
// >

// code<
use_definitions<
YOMM2_REGISTER(use_definitions<
unary_definition,
product<
templates<transpose>, abstract_matrix_templates,
concrete_matrix_templates, types<double, int>>>
YOMM2_GENSYM;
concrete_matrix_templates, types<double, int>>>);
// >

// md<
Expand All @@ -1050,7 +1048,8 @@ use_definitions<
// >

// code<
YOMM2_STATIC(use_classes<apply_product<matrix_templates, types<double, int>>>);
YOMM2_REGISTER(
use_classes<apply_product<matrix_templates, types<double, int>>>);
// >

#endif
Expand Down Expand Up @@ -1134,12 +1133,11 @@ static_assert(

// code<

struct YOMM2_METHOD_NAME(add);
struct add_;

template<typename M1, typename M2>
using add = method<
YOMM2_METHOD_NAME(add)(virtual_<M1&>, virtual_<M2&>),
handle<binary_result_type<M1, M2>>>;
add_(virtual_<M1&>, virtual_<M2&>), handle<binary_result_type<M1, M2>>>;

template<
typename M1, typename M2,
Expand Down Expand Up @@ -1281,13 +1279,12 @@ static_assert(

// code<

use_definitions<
YOMM2_REGISTER(use_definitions<
binary_definition,
product<
templates<add>, abstract_matrix_templates, concrete_matrix_templates,
types<double, int>, abstract_matrix_templates,
concrete_matrix_templates, types<double, int>>>
YOMM2_GENSYM;
concrete_matrix_templates, types<double, int>>>);
// >

// code<
Expand Down Expand Up @@ -1450,7 +1447,7 @@ struct use_polymorphic_matrices<>
: use_polymorphic_matrices<ordinary, square, symmetric> {};
// >

YOMM2_STATIC(use_polymorphic_matrices<>::of<int, double>);
YOMM2_REGISTER(use_polymorphic_matrices<>::of<int, double>);

#endif

Expand Down
4 changes: 2 additions & 2 deletions examples/slides.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ struct binary_value {
}
};

YOMM2_STATIC(value::override<binary_value<Plus, std::plus<int>>>);
YOMM2_STATIC(value::override<binary_value<Times, std::multiplies<int>>>);
YOMM2_REGISTER(value::override<binary_value<Plus, std::plus<int>>>);
YOMM2_REGISTER(value::override<binary_value<Times, std::multiplies<int>>>);

}

Expand Down
Loading

0 comments on commit 0e32aee

Please sign in to comment.