Skip to content

Commit 9c5e446

Browse files
committed
Merge branch 'slides-main'
2 parents fba65ee + 312dcae commit 9c5e446

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

docs/slides/YOMM2.pdf

19.6 KB
Binary file not shown.

docs/slides/deck/03-ast.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ struct RPNVisitor : Node::Visitor {
169169
string result;
170170
};
171171
172-
string to_rpn(Node& node) {
172+
string to_rpn(const Node& node) {
173173
RPNVisitor viz;
174174
node.visit(viz);
175175
return viz.result;

docs/slides/deck/04-open-methods.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616

1717

18-
## Open Methods
18+
## YOMM2 Open Methods
1919

2020
```c++
2121
struct Node {
22-
virtual string to_rpn(/*const Node* this*/) const = 0;
22+
virtual string to_rpn(/* const Node* */) const = 0;
2323
};
2424
```
2525
@@ -33,7 +33,7 @@ declare_method(string, to_rpn, (virtual_<const Node&>));
3333

3434
```c++
3535
struct Plus : Node {
36-
string to_rpn(/*const Node* this*/) const override {
36+
string to_rpn(/* const Node* this */) const override {
3737
return left.to_rpn() + " " + right.to_rpn() + " +";
3838
}
3939
};
@@ -54,8 +54,6 @@ define_method(string, to_rpn, (const Plus& expr)) {
5454
```C++
5555
#include <yorel/yomm2/keywords.hpp>
5656

57-
register_classes(Node, Number, Plus, Times);
58-
5957
declare_method(string, to_rpn, (virtual_<const Node&>));
6058

6159
define_method(string, to_rpn, (const Number& expr)) {
@@ -70,6 +68,8 @@ define_method(string, to_rpn, (const Times& expr)) {
7068
return to_rpn(expr.left) + " " + to_rpn(expr.right) + " *";
7169
}
7270

71+
register_classes(Node, Number, Plus, Times);
72+
7373
int main() {
7474
yorel::yomm2::update();
7575
cout << to_rpn(expr) << " = " << expr.value() << "\n";
@@ -102,12 +102,6 @@ define_method(int, value, (Plus& expr)) {
102102

103103
## Performance
104104

105-
* 15-30% slower than equivalent native virtual function call (but see `virtual_ptr`)
106-
107-
* [Optimizing Away C++ Virtual Functions May Be
108-
Pointless](https://www.youtube.com/watch?v=i5MAXAxp_Tw) - Shachar Shemesh -
109-
CppCon 2023
110-
111105
```asm
112106
mov rax, qword ptr [rdi]
113107
mov rdx, qword ptr [rip+fast_perfect_hash<release>::mult]
@@ -124,6 +118,13 @@ define_method(int, value, (Plus& expr)) {
124118
jmp qword ptr [rax+8*rcx]
125119
```
126120

121+
* 15-30% slower than equivalent native virtual function call (using perfect
122+
integer hash; but see `virtual_ptr`)
123+
124+
* [Optimizing Away C++ Virtual Functions May Be
125+
Pointless](https://www.youtube.com/watch?v=i5MAXAxp_Tw) - Shachar Shemesh -
126+
CppCon 2023
127+
127128

128129

129130
## Multiple Dispatch

docs/slides/deck/06-evolution.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<ul>
1313
<li class="fragment">goals:
1414
<ul>
15-
<li class="fragment">help promote adoption in the standard
15+
<li class="fragment">help promote adoption in the language
1616
<ul>
1717
<li class="fragment">submit to Boost</li>
1818
<li class="fragment">talk about it (CppCon 2018...)</li>
@@ -49,12 +49,6 @@
4949

5050
<br/>
5151

52-
```c++
53-
declare_method(int, value, (virtual_ptr<Node>));
54-
```
55-
56-
<br/>
57-
5852
```c++
5953
int call_via_vptr(virtual_ptr<const Node> node) {
6054
return value(node);
@@ -67,6 +61,12 @@ mov rax, qword ptr [rsi + 8*rax]
6761
jmp rax
6862
```
6963

64+
<br/>
65+
66+
```c++
67+
declare_method(int, value, (virtual_ptr<Node>));
68+
```
69+
7070
7171
7272
@@ -124,13 +124,15 @@ ret
124124
## Core API
125125

126126
```c++
127-
use_classes<Node, Number, Plus, Times> use_ast_classes;
128-
129127
struct value_id;
130128
using value = method<value_id, int(virtual_<const Node&>)>;
129+
```
131130

131+
```c++
132132
auto result = value::fn(expr);
133+
```
133134

135+
```c++
134136
int number_value(const Number& node) {
135137
return node.val;
136138
}
@@ -145,6 +147,8 @@ struct binary_value {
145147

146148
YOMM2_STATIC(value::add_definition<binary_value<Plus, std::plus<int>>>);
147149
YOMM2_STATIC(value::add_definition<binary_value<Times, std::multiplies<int>>>);
150+
151+
YOMM2_STATIC(use_classes<Node, Number, Plus, Times>);
148152
```
149153
150154
@@ -157,10 +161,10 @@ YOMM2_STATIC(value::add_definition<binary_value<Times, std::multiplies<int>>>);
157161
<li>virtual_ptr</li>
158162
<li>core API</li>
159163
<li class="fragment">template interop toolkit</li>
160-
<li class="fragment">header only (+ Compiler Explorer)</li>
164+
<li class="fragment">header only (Compiler Explorer)</li>
161165
<li class="fragment">friendship</li>
162166
<li class="fragment">member methods</li>
163-
<li class="fragment">policies and facets
167+
<li class="fragment">policies and facets (latest release)
164168
<ul>
165169
<li class="fragment">custom RTTI</li>
166170
<li class="fragment">custom error handling, trace, vptr placement...</li>
@@ -177,9 +181,11 @@ YOMM2_STATIC(value::add_definition<binary_value<Times, std::multiplies<int>>>);
177181
<ul>
178182
<li class="fragment">goals:
179183
<ul>
180-
<li class="fragment">beat virtual function speed</li>
184+
<li class="fragment">match (beat?) virtual function speed</li>
181185
<li class="fragment">pre-calculate dispatch tables</li>
182186
<li class="fragment">malloc-free operation</li>
187+
<li class="fragment">dispatch on std::any</li>
188+
<li class="fragment">(feature complete)</li>
183189
<li class="fragment">C++20</li>
184190
</ul>
185191
</li>

0 commit comments

Comments
 (0)