From ed4e79c3d0ac83864f8dc39539d76a171f975638 Mon Sep 17 00:00:00 2001 From: Gabriel Dos Reis Date: Fri, 12 Aug 2022 19:33:26 -0700 Subject: Use C++ concepts in lieu of SFINAE. --- src/include/open-axiom/Charset | 8 ++++---- src/include/open-axiom/string-pool | 2 +- src/include/open-axiom/token | 26 +++++++++++++------------- src/include/open-axiom/vm | 19 ++++++++----------- 4 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/include/open-axiom/Charset b/src/include/open-axiom/Charset index 58fa9ea8..4a2c6050 100644 --- a/src/include/open-axiom/Charset +++ b/src/include/open-axiom/Charset @@ -1,5 +1,5 @@ // -*- C++ -*- -// Copyright (C) 2013, Gabriel Dos Reis. +// Copyright (C) 2013-2022, Gabriel Dos Reis. // All rights reserved. // Written by Gabriel Dos Reis. // @@ -34,15 +34,15 @@ #ifndef OPENAXIOM_CHARSET_included #define OPENAXIOM_CHARSET_included -#include +#include namespace OpenAxiom { // Code point value of a UCS member. - using Codepoint = uint32_t; + using Codepoint = std::uint32_t; // Unicode character type. enum class Character : Codepoint { - NUL = Codepoint() // The NUL character + NUL = Codepoint{} // The NUL character }; } diff --git a/src/include/open-axiom/string-pool b/src/include/open-axiom/string-pool index d35c67b1..aed947e2 100644 --- a/src/include/open-axiom/string-pool +++ b/src/include/open-axiom/string-pool @@ -80,7 +80,7 @@ namespace OpenAxiom { const Byte* make_copy(const Byte*, size_t); }; - typedef const StringPool::EntryType* InternedString; + using InternedString = const StringPool::EntryType*; } #endif // OPENAXIOM_STRING_POOL_INCLUDED diff --git a/src/include/open-axiom/token b/src/include/open-axiom/token index 1d17f5de..a586fa6d 100644 --- a/src/include/open-axiom/token +++ b/src/include/open-axiom/token @@ -1,5 +1,5 @@ // -*- C++ -*- -// Copyright (C) 2013-2017, Gabriel Dos Reis. +// Copyright (C) 2013-2022, Gabriel Dos Reis. // All rights reserved. // Written by Gabriel Dos Reis. // @@ -34,7 +34,7 @@ #ifndef OPENAXIOM_TOKEN_included #define OPENAXIOM_TOKEN_included -#include +#include #include #include #include @@ -42,7 +42,7 @@ namespace OpenAxiom { // Categorization of Boot and Spad tokens. - enum class TokenCategory : uint8_t { + enum class TokenCategory : std::uint8_t { Unclassified, // token of unknown class Whitespace, // sequence of white-space characters Comment, // a description of an ignorable comment @@ -61,7 +61,7 @@ namespace OpenAxiom { std::ostream& operator<<(std::ostream&, TokenCategory); // The abstract value associated with a token. - enum class TokenValue : uint8_t { + enum class TokenValue : std::uint8_t { #undef OPENAXIOM_DEFINE_TOKEN #define OPENAXIOM_DEFINE_TOKEN(T, ...) T, #include @@ -73,14 +73,14 @@ namespace OpenAxiom { std::ostream& operator<<(std::ostream&, TokenValue); - enum class TokenIndex : uint32_t { }; + enum class TokenIndex : std::uint32_t { }; constexpr TokenValue value(TokenIndex t) { - return TokenValue((uint32_t(t) & 0xFF000000) >> 24); + return TokenValue((std::uint32_t(t) & 0xFF000000) >> 24); } - constexpr uint32_t index(TokenIndex t) { - return uint32_t(t) & 0x00FFFFFF; + constexpr std::uint32_t index(TokenIndex t) { + return std::uint32_t(t) & 0x00FFFFFF; } // Program text region, with a fragment. @@ -146,7 +146,7 @@ namespace OpenAxiom { Tok finish(Tok&, Language); }; - bool separator_or_punctuator(uint8_t); + bool separator_or_punctuator(std::uint8_t); template inline void comment_token(T& t, TokenValue v) { @@ -271,7 +271,7 @@ namespace OpenAxiom { } inline bool - identifier_head(uint8_t c) { + identifier_head(std::uint8_t c) { return isalpha(c) or c == '%' or c == '_'; } @@ -281,17 +281,17 @@ namespace OpenAxiom { } inline bool - identifier_suffix(uint8_t c) { + identifier_suffix(std::uint8_t c) { return c == '!' or c == '?'; } - inline bool internal_prefix(uint8_t c) { + inline bool internal_prefix(std::uint8_t c) { return c == '%' or c == '$'; } template inline void - skip_prefix(L& line, ColumnIndex& idx, uint8_t c) { + skip_prefix(L& line, ColumnIndex& idx, std::uint8_t c) { while (idx < line.size() and line[idx] == c) ++idx; } diff --git a/src/include/open-axiom/vm b/src/include/open-axiom/vm index 400fc3a2..f7862249 100644 --- a/src/include/open-axiom/vm +++ b/src/include/open-axiom/vm @@ -1,5 +1,5 @@ // -*- C++ -*- -// Copyright (C) 2011-2014, Gabriel Dos Reis. +// Copyright (C) 2011-2022, Gabriel Dos Reis. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -40,11 +40,12 @@ #include #include -#include +#include #include #include #include #include +#include #define internal_type struct alignas(16) #define internal_data alignas(16) @@ -157,7 +158,7 @@ namespace OpenAxiom { // -- Value -- // ----------- // All VM values fit in a universal value datatype. - using ValueBits = uintptr_t; + using ValueBits = std::uintptr_t; using ValueMask = ValueBits; enum class Value : ValueBits { nil = 0x00, // distinguished NIL value @@ -205,7 +206,7 @@ namespace OpenAxiom { // -- Arity: number of arguments or forms taken by a function // or a special operator. - enum class Arity : intptr_t { + enum class Arity : std::intptr_t { variable = -1, // Any number of arguments. zero = 0, // Exactly no argument. one = 1, // Exactly one argument. @@ -242,12 +243,8 @@ namespace OpenAxiom { return is(v) ? to_dynamic(v) : nullptr; } - template - using IfDynamic = typename - std::enable_if::value, Value>::type; - - template - inline IfDynamic to_value(const T* o) { + template T> + inline Value to_value(const T* o) { return Value(ValueBits(o) | ValueTrait::tag); } @@ -261,7 +258,7 @@ namespace OpenAxiom { // VM integers are divided into classes: small numbers, // and large numbers. A small number fits entirely in a register. // A large number is allocated and represented by its address. - using FixnumBits = intptr_t; + using FixnumBits = std::intptr_t; enum class Fixnum : FixnumBits { minimum = FixnumBits(~(~ValueBits() >> 2)), zero = FixnumBits(0), -- cgit v1.2.3