Skip to content

Commit

Permalink
policies and facets
Browse files Browse the repository at this point in the history
  • Loading branch information
jll63 committed Apr 8, 2024
1 parent d9a9195 commit 39c30e8
Show file tree
Hide file tree
Showing 191 changed files with 9,142 additions and 4,522 deletions.
7 changes: 3 additions & 4 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ BraceWrapping:
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyFunction: false
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
Expand Down Expand Up @@ -81,7 +81,7 @@ IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: false
IndentGotoLabels: true
IndentPPDirectives: BeforeHash
#IndentPPDirectives: true
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
Expand All @@ -104,7 +104,7 @@ PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
ReflowComments: false
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
Expand Down Expand Up @@ -134,4 +134,3 @@ TabWidth: 8
UseCRLF: false
UseTab: Never
...

4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
run: |
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DYOMM2_SHARED=1 -DYOMM2_CHECK_ABI_COMPATIBILITY=${{ matrix.check_abi_compatibility }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=17 -DYOMM2_ENABLE_TESTS=1 -DYOMM2_ENABLE_BENCHMARKS=1
cmake .. -DCMAKE_BUILD_TYPE=Release -DYOMM2_SHARED=1 -DYOMM2_CHECK_ABI_COMPATIBILITY=${{ matrix.check_abi_compatibility }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=17 -DYOMM2_ENABLE_TESTS=1
- name: Build
run: VERBOSE=1 cmake --build build
- name: Unit Tests
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
run: |
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DYOMM2_SHARED=1 -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=17 -DYOMM2_ENABLE_TESTS=1 -DYOMM2_ENABLE_BENCHMARKS=1
cmake .. -DCMAKE_BUILD_TYPE=Release -DYOMM2_SHARED=1 -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=17 -DYOMM2_ENABLE_TESTS=1
- name: Build
run: VERBOSE=1 cmake --build build
- name: Unit Tests
Expand Down
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright (c) 2018-2022 Jean-Louis Leroy
# Copyright (c) 2018-2024 Jean-Louis Leroy
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt
# or copy at http://www.boost.org/LICENSE_1_0.txt)

cmake_minimum_required(VERSION 3.20)
cmake_policy(SET CMP0057 NEW)
project(YOMM2 VERSION 1.4.0)
project(YOMM2 VERSION 1.5.0)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
Expand All @@ -18,7 +18,7 @@ include(cmake/find_or_download_package.cmake)
find_or_download_package(Boost INSTALL_WITH_YOMM)
message(STATUS "Using Boost libraries from ${Boost_INCLUDE_DIRS}")

if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if(NOT ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") AND (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"))
add_compile_options(-save-temps -fverbose-asm -masm=intel)
endif()

Expand Down Expand Up @@ -63,7 +63,7 @@ option(YOMM2_ENABLE_DOC "Set to ON to generate tutorials and reference" OFF)
option(YOMM2_ENABLE_BENCHMARKS "Set to ON to enable benchmarks" OFF)

set(readme_md "${CMAKE_SOURCE_DIR}/README.md")
set(readme_cpp "${CMAKE_SOURCE_DIR}/tutorials/readme.cpp")
set(readme_cpp "${CMAKE_SOURCE_DIR}/examples/README.cpp")

if(${YOMM2_ENABLE_DOC})
message(STATUS "Documentation generation enabled")
Expand All @@ -74,8 +74,8 @@ if(${YOMM2_ENABLE_DOC})
DEPENDS "${readme_cpp}")
endif()

add_subdirectory(reference.in)
add_subdirectory(tutorials)

add_subdirectory(docs.in)

## Install instruction
# Create version file for cmake package
Expand Down
42 changes: 26 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#


# YOMM2
Expand All @@ -21,7 +22,7 @@ Stroustrup.
If you are familiar with the concept of open multi-methods, or if you prefer
to learn by reading code, go directly to [the
synopsis](examples/synopsis.cpp). The [reference is
here](reference/README.md)
here](https://jll63.github.io/yomm2/reference)

## Open Methods in a Nutshell

Expand Down Expand Up @@ -74,12 +75,15 @@ Let's look at an example.
// library code

struct matrix {
virtual ~matrix() {}
virtual ~matrix() {
}
// ...
};

struct dense_matrix : matrix { /* ... */ };
struct diagonal_matrix : matrix { /* ... */ };
struct dense_matrix : matrix { /* ... */
};
struct diagonal_matrix : matrix { /* ... */
};

// -----------------------------------------------------------------------------
// application code
Expand Down Expand Up @@ -110,14 +114,15 @@ int main() {
return 0;
}
```
#
`<yorel/yomm2/keywords.hpp>` is the library's main entry point. It declares a
set of macros, and injects a single name, [`virtual_`](virtual_.md), in the global
set of macros, and injects a single name, [`virtual_`](/yomm2/reference/virtual_.html), in the global
namespace. The purpose of the header is to make it look as if open methods
are part of the language.
[`register_classes`](use_classes.md) informs the library of the existence of the classes, and
[`register_classes`](/yomm2/reference/use_classes.html) informs the library of the existence of the classes, and
their inheritance relationships. Any class that can appear in a method call
needs to be registered, even if it is not directly referenced by a method.
Expand All @@ -139,7 +144,7 @@ shared libraries.
The example can be compiled (from the root of the repository) with:
```shell
clang++-14 -I include -std=c++17 tutorials/readme.cpp -o example
clang++- -I include -std=c++17 tutorials/README.cpp -o example
```

### Multiple Dispatch
Expand Down Expand Up @@ -187,9 +192,9 @@ the body of the method does any amount of work, the difference is
unnoticeable. See the implementation notes for benchmarks and assembly
listings.
[`virtual_ptr`](reference/virtual_ptr.md), a fat pointer class, can be used
to make method dispatch even faster - three instructions and two memory
reads -, without sacrificing orthogonality.
[`virtual_ptr`](https://jll63.github.io/yomm2/reference/virtual_ptr.md), a fat
pointer class, can be used to make method dispatch even faster - three
instructions and two memory reads -, without sacrificing orthogonality.
## Building and Installing
Expand Down Expand Up @@ -277,7 +282,8 @@ The runtime can also be built and installed as a shared library, by adding
A CMake package configuration is also installed. If the install location is
in `CMAKE_PREFIX_PATH`, you can use `find_package(YOMM2)` to locate YOMM2,
then `target_link_libraries(<your_target> YOMM2::yomm2)` to add the necessary
include paths and the library. See [this example](examples/cmakeyomm2).
include paths and the library. See [this
example](examples/cmakeyomm2).
Make sure to add the install location to `CMAKE_PREFIX_PATH` so that you can
use `find_package(YOMM2)` from your including project. For linking, the use
Expand All @@ -287,7 +293,7 @@ to link to yomm2.
## Going Further
The Reference is [here](reference/README.md). Since version 1.3.0, some of
The Reference is [here](https://jll63.github.io/yomm2/reference). Since version 1.3.0, some of
the internals are documented, which make it possible to use the library
without using macros - see [the API tutorial](tutorials/api.md).
Expand All @@ -296,13 +302,17 @@ definitions - see [the templates tutorial](tutorials/templates_tutorial.md).
The library comes with a series of examples:
* [The complete `matrix` example](examples/matrix.cpp)
* [The complete `matrix`
example](examples/matrix.cpp)
* [The Asteroids example used in Wikipedia's article on Multiple Dispatch](examples/asteroids.cpp)
* [The Asteroids example used in Wikipedia's article on Multiple
Dispatch](examples/asteroids.cpp)
* [Process an AST sans clumsy Visitor](examples/accept_no_visitors.cpp)
* [Process an AST sans clumsy
Visitor](examples/accept_no_visitors.cpp)
* [Adventure: a 3-method example](examples/adventure.cpp)
* [Adventure: a 3-method
example](examples/adventure.cpp)
* [friendship: an example with namespaces, method containers and friend
declarations](examples/containers)
Expand Down
2 changes: 1 addition & 1 deletion ce/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018-2022 Jean-Louis Leroy
# Copyright (c) 2018-2024 Jean-Louis Leroy
# Distributed uce_nder the Boost Software License, Version 1.0.
# See accompanying filce_e LICENSE_1_0.txt
# or copy at hce_ttp://www.boost.oce_rg/LICENSE_1_0.txt)
Expand Down
4 changes: 2 additions & 2 deletions dev/bm2md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python3
#!/bin/env python3

import argparse
from typing import Iterable
Expand Down Expand Up @@ -123,7 +123,7 @@ for other_tags in product(*other_axes.values()):
"{:5.2f}".format(
1
if ref.base is None
else (result.mean / result.base.mean) / (ref.mean / ref.base.mean)
else result.mean / ref.mean
)
)
table.extend(row)
Expand Down
1 change: 1 addition & 0 deletions dev/bmutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
dispatch=(
"virtual_function",
"basic_policy",
"compact_map_policy",
"direct_intrusive",
"indirect_intrusive",
"direct_virtual_ptr",
Expand Down
94 changes: 65 additions & 29 deletions dev/code2md
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,81 @@

import contextlib
from pathlib import Path
import os
import re
import sys

import mdgen

with open(sys.argv[1]) as fh:
code = fh.read()
source = os.path.abspath(sys.argv[1]).replace(os.path.abspath(mdgen.repository), "")

def generate_code(text, out):
print("```c++", file=out)
text = text.replace("elided", "...")
text = text.strip()
print(text, file=out)
print("```", file=out)


def generate_md(text, out):
text = re.sub(r"^// ?", "", text, flags=re.MULTILINE)
text = mdgen.replace_md(text, source=source)
print(text, file=out)


action = {"MD": generate_md, "md": generate_md, "/***": generate_md, "CODE": generate_code, "code": generate_code, "//***": generate_code}

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

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

with open(out_path, "w") as out:
# print(f"{out_path}...")
fragments = re.findall(
r"// (md|code)<(.*?)// > *",
re.sub(r"// etc<.*?// >.*?$", r"// etc", code, flags=re.MULTILINE | re.DOTALL),
flags=re.MULTILINE | re.DOTALL,
) + re.findall(
r"# *ifdef YOMM2_(MD|CODE)(.*?)# *endif",
re.sub(r"// etc<.*?// >.*?$", r"// etc", code, flags=re.MULTILINE | re.DOTALL),
flags=re.MULTILINE | re.DOTALL,
)

def code(text):
print("```c++", file=out)
text = text.replace("elided", "...")
text = text.strip()
print(text, file=out)
print("```", file=out)

def md(text):
text = re.sub(r"^// ?", "", text, flags=re.MULTILINE)
text = mdgen.replace_md(text)
print(text, file=out)

for fragment in fragments:
action, content = fragment
globals()[action.lower()](content)

def generate():
with open(sys.argv[1]) as fh:
input = fh.read()

with open(out_path, "w") as out:
fragments = re.findall(
r"(/\*{3}(.*?)\*{3}/)|(//\*{3}(.*?)//\*{3})",
re.sub(
r"// etc<.*?// >.*?$", r"// etc", input, flags=re.MULTILINE | re.DOTALL
),
flags=re.MULTILINE | re.DOTALL,
)

for i, fragment in enumerate(fragments):
if fragment[1] != "":
text = re.sub(r"^// ?", "", fragment[1], flags=re.MULTILINE)
if i > 0:
text = mdgen.replace_links(text, source=source)
else:
text = mdgen.replace_md(text, source=source)
print(text, file=out)
else:
generate_code(fragment[3], out)

if len(fragments) > 0:
return

fragments = re.findall(
r"// (md|code)<(.*?)// > *",
re.sub(
r"// etc<.*?// >.*?$", r"// etc", input, flags=re.MULTILINE | re.DOTALL
),
flags=re.MULTILINE | re.DOTALL,
) + re.findall(
r"# *ifdef YOMM2_(MD|CODE)(.*?)# *endif",
re.sub(
r"// etc<.*?// >.*?$", r"// etc", input, flags=re.MULTILINE | re.DOTALL
),
flags=re.MULTILINE | re.DOTALL,
)

for fragment in fragments:
prefix, content = fragment
action[prefix](content, out)


generate()
out_path.chmod(0o400)
15 changes: 9 additions & 6 deletions dev/md2md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@

import contextlib
from pathlib import Path
import re
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(sys.argv[1]) as rh, open(out_path, "w") as wh:
for text in rh.readlines():
text = mdgen.replace_md(text)
print(text, file=wh, end="")
with open(out_path, "w") as wh:
text = mdgen.replace_md(text, source=source)
print(text, file=wh, end="")

out_path.chmod(0o400)
Loading

0 comments on commit 39c30e8

Please sign in to comment.