...
 
Commits (125)

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

# common configuration parts
.common: &common
before_script:
- rm -rf .git # ups
tags:
- shared-fi
.debian: &debian
image: cxx:latest
script:
- apt-get update >& apt.log
- make prerequisites >& prerequisites.log
- make toolchain >& toolchain.log
- make CMAKE_EXTRA="-DOPT_Z3=OFF" >& build.log
- make unit >& unit.log
- make functional >& functional.log
artifacts:
paths:
- "*.log"
expire_in: 1 month
when: always
# actual builds
build_clang:
<<: *common
<<: *debian
variables:
CC: "clang"
CXX: "clang++"
build_gcc:
<<: *common
<<: *debian
variables:
CC: "gcc"
CXX: "g++"
......@@ -127,6 +127,24 @@ namespace brick::bitlevel
* bits), with basic bitwise and shift operators. See the bitvec template
* below. */
template< typename T >
static constexpr T shift_left( T v, size_t bits )
{
if ( bits >= sizeof( T ) * 8 )
return T();
else
return v << bits;
}
template< typename T >
static constexpr T shift_right( T v, size_t bits )
{
if ( bits >= sizeof( T ) * 8 )
return T();
else
return v >> bits;
}
template< typename L, typename H >
struct bvpair
{
......@@ -156,8 +174,8 @@ namespace brick::bitlevel
int rem = 8 * sizeof( low ) - s;
int unshift = std::max( rem, 0 );
int shift = rem < 0 ? -rem : 0;
H carry = ( low & ~ones< L >( unshift ) ) >> unshift;
return bvpair( low << s, ( high << s ) | ( carry << shift ) );
H carry = shift_right( low & ~ones< L >( unshift ), unshift );
return bvpair( shift_left( low, s ), shift_left( high, s ) | shift_left( carry, shift ) );
}
constexpr bvpair operator>>( int s ) const
......
......@@ -936,7 +936,7 @@ struct Parser : ParserBase
auto command( Tokens (U::*extra), Args... args )
{
auto cmd = command< T >( args... );
cmd._cmds.car._extra = extra;
cmd._cmds.car()._extra = extra;
return cmd;
}
......@@ -944,7 +944,7 @@ struct Parser : ParserBase
auto command( std::string dsc, Args... args )
{
auto cmd = command< T >( args... );
cmd._cmds.car._description = dsc;
cmd._cmds.car()._description = dsc;
return cmd;
}
......@@ -1106,7 +1106,7 @@ struct TestCmd
.command< Foo >( common, uncommon )
.command< Bar >( common );
ASSERT_EQ( p._cmds.car.name(), "bar" );
ASSERT_EQ( p._cmds.car().name(), "bar" );
cmd::Tokens in = { "foo", "32" };
bool is_foo = false;
......
......@@ -248,10 +248,10 @@ namespace brq
}
namespace brq_t
namespace t_brq
{
template< template< typename > class sort_ >
struct test_array_map
struct array_map
{
using sort = sort_< brq::less_map >;
......@@ -323,6 +323,6 @@ namespace brq_t
}
};
template struct test_array_map< brq::std_sort >;
template struct test_array_map< brq::insert_sort >;
template struct array_map< brq::std_sort >;
template struct array_map< brq::insert_sort >;
}
......@@ -59,7 +59,7 @@ namespace brq
using module = module_< mod, x... >;
}
namespace brq_t
namespace t_brq
{
template< typename next >
struct m0_ : next
......
......@@ -28,22 +28,28 @@ namespace brq
struct nil
{
using co = nil;
template< template< typename > class f > using map_t = nil;
using unique_t = nil;
static constexpr bool empty = true;
static constexpr size_t size = 0;
template< typename F >
void each( const F & ) const {}
template< int idx > using type_at = void;
template< template< typename > class f > using map_t = nil;
template< typename L > using cat_t = L;
template< typename... Fs >
auto match( Fs... ) { return std::nullopt; }
template< typename F > void each( const F & ) const {}
template< typename F > nil map( F ) const { return {}; }
template< typename... Fs > auto match( Fs... ) { return std::nullopt; }
template< typename L > auto cat( const L &l ) const { return l; }
template< typename T > static constexpr bool has = false;
template< template< typename > class P >
constexpr nil filter() const { return {}; }
template< typename F >
nil map( F ) const { return {}; }
template< typename L >
auto cat( const L &l ) const { return l; }
template< typename F, typename... args_t >
auto apply( const F &f, args_t && ... args ) const
{
return f( args... );
}
};
template< typename, typename > struct cons;
......@@ -53,66 +59,98 @@ namespace brq
auto make_cons( const A &a, const B &b ) { return cons< A, B >( a, b ); }
template< typename A, typename B >
struct cons
struct cons : B
{
using car_t = A;
using cdr_t = B;
using co = ns< car_t, typename cdr_t::co >;
template< template< typename > class f >
using map_t = cons< f< car_t >, typename cdr_t::template map_t< f > >;
car_t car;
cdr_t cdr;
car_t _car;
template< typename F >
void each( const F &f )
operator car_t&() { return _car; }
operator const car_t&() const { return _car; }
car_t &car() { return _car; }
const car_t &car() const { return _car; }
cdr_t &cdr() { return *this; }
const cdr_t &cdr() const { return *this; }
template< typename F > void each( const F &f ) { f( car() ); cdr().each( f ); }
template< typename F > void each( const F &f ) const { f( car() ); cdr().each( f ); }
template< typename L > auto cat( const L &l ) const { return make_cons( car(), cdr().cat( l ) ); }
constexpr auto reverse() const { nil rev; return cons_reverse( *this, rev ); }
template< typename T > auto &get()
{
f( car );
cdr.each( f );
if constexpr ( std::is_same_v< std::remove_reference_t< T >, car_t > )
return car();
else
return cdr().template get< T >();
}
template< typename F >
void each( const F &f ) const
template< typename L >
auto view()
{
f( car );
cdr.each( f );
if constexpr ( std::is_same_v< L, nil > )
return nil();
else
{
static_assert( has< std::remove_reference_t< typename L::car_t > > );
auto tail = view< typename L::cdr_t >();
return cons< typename L::car_t, decltype( tail ) >( get< typename L::car_t >(), tail );
}
}
cons( const car_t &car, const cdr_t &cdr )
: car( car ), cdr( cdr )
{}
static constexpr bool empty = false;
static constexpr size_t size = 1 + cdr_t::size;
template< int idx >
using type_at = std::conditional_t< idx == 0, car_t,
typename cdr_t::template type_at< idx - 1 > >;
template< typename T > static constexpr bool has =
std::is_same_v< T, car_t > || cdr_t::template has< T >;
template< template< typename > class f >
using map_t = cons< f< car_t >, typename cdr_t::template map_t< f > >;
using unique_t = std::conditional_t< cdr_t::unique_t::template has< car_t >, cdr_t, cons >;
template< typename L > using cat_t = cons< car_t, typename cdr_t::template cat_t< L > >;
template< typename F, typename... args_t >
auto apply( const F &f, args_t &&... args ) const
{
return cdr().apply( f, car(), std::forward< args_t >( args ) ... );
}
constexpr auto reverse() const
template< typename F, typename... args_t >
auto apply( const F &f, args_t &&... args )
{
nil rev;
return cons_reverse( *this, rev );
return cdr().apply( f, car(), std::forward< args_t >( args ) ... );
}
template< template< typename > class P >
constexpr auto filter() const
{
if constexpr ( P< car_t >::value )
return make_cons( car, cdr.template filter< P >() );
return make_cons( car(), cdr().template filter< P >() );
else
return cdr.template filter< P >();
return cdr().template filter< P >();
}
template< typename F >
auto map( F f )
{
auto car_ = f( car );
auto cdr_ = cdr.map( f );
auto car_ = f( car() );
auto cdr_ = cdr().map( f );
return make_cons( car_, cdr_ );
}
template< typename L >
auto cat( const L &l )
{
return make_cons( car, cdr.cat( l ) );
}
cons( const car_t &car, const cdr_t &cdr )
: cdr_t( cdr ), _car( car )
{}
template< typename arg_t, typename... args_t >
cons( const arg_t &arg, const args_t&... args ) : car( arg ), cdr( args... ) {}
template< typename T, typename U, typename... Us >
cons( const T &t, const U &u, const Us &... us ) : cdr_t( u, us... ), _car( t ) {}
cons() = default;
};
......@@ -130,6 +168,14 @@ namespace brq
}
static auto cons_list() { return nil(); }
static auto cons_list_ref() { return nil(); }
template< typename T, typename... Ts >
auto cons_list_ref( T &&t, Ts &&... ts )
{
auto tail = cons_list_ref( std::forward< Ts >( ts )... );
return cons< T, decltype( tail ) >( std::forward< T >( t ), tail );
}
template< typename T, typename... Ts >
auto cons_list( const T &t, const Ts &... ts )
......@@ -139,7 +185,7 @@ namespace brq
}
template< typename... Ts >
using cons_list_t_ = decltype( cons_list( std::declval< Ts >()... ) );
using cons_list_t_ = decltype( cons_list_ref( std::declval< Ts >()... ) );
template< typename... Ts >
struct cons_list_t: cons_list_t_< Ts... >
......@@ -147,6 +193,8 @@ namespace brq
using cons_list_t_< Ts... >::cons_list_t_;
};
static_assert( std::is_same_v< cons_list_t< int, int >::unique_t, cons_list_t_< int > > );
template< typename car_t_, typename cdr_t_ >
struct ns
{
......@@ -222,7 +270,44 @@ namespace brq
}
}
};
}
namespace t_brq
{
struct cons
{
TEST( view_ref )
{
auto x = brq::cons_list( 3.0, 7, static_cast< const char * >( "bla " ) );
using v = brq::cons_list_t< int & >;
static_assert( std::is_same_v< v::car_t, int & > );
auto y = x.view< v >();
ASSERT_EQ( y.car(), 7 );
y.car() ++;
ASSERT_EQ( y.car(), 8 );
ASSERT_EQ( x.cdr().car(), 8 );
}
TEST( view_val )
{
auto x = brq::cons_list( 3.0, 7, static_cast< const char * >( "bla " ) );
using v = brq::cons_list_t< int >;
auto y = x.view< v >();
ASSERT_EQ( y.car(), 7 );
y.car() ++;
ASSERT_EQ( y.car(), 8 );
ASSERT_EQ( x.cdr().car(), 7 );
}
TEST( val_ctor )
{
int x;
auto y = brq::cons_list( x );
auto z = brq::cons_list_ref( x );
static_assert( std::is_same_v< decltype( y ), brq::cons_list_t_< int > > );
static_assert( std::is_same_v< decltype( z ), brq::cons_list_t_<