Showing the changes to src/include (7 of 14 files). Show all
Unified · Split
| @@ -20,12 +20,9 @@ namespace disvm · 19 unmodified lines | ||
| 20 | 20 | { |
| 21 | 21 | class buffered_reader_t |
| 22 | 22 | { |
| 23 | − private: // static | |
| 24 | − static const std::size_t buffer_size = 64 * 1024; // 64k is an optimization for the Windows filesystem manager | |
| 25 | − | |
| 26 | 23 | public: |
| 27 | 24 | buffered_reader_t(std::istream &stream) |
| 28 | − : _buffer(buffered_reader_t::buffer_size) | |
| 25 | + : _buffer(64 * 1024) // 64k is an optimization for the Windows filesystem manager | |
| 29 | 26 | , _current_index{ 0 } |
| 30 | 27 | , _current_size{ 0 } |
| 31 | 28 | , _stream{ stream } |
| @@ -141,10 +138,10 @@ namespace disvm · 109 unmodified lines | ||
| 141 | 138 | if (_stream.fail()) |
| 142 | 139 | return 0; |
| 143 | 140 | |
| 144 | − _stream.read(_buffer.data(), buffered_reader_t::buffer_size); | |
| 141 | + _stream.read(_buffer.data(), _buffer.size()); | |
| 145 | 142 | |
| 146 | 143 | // If the stream has failed, set the current size, otherwise the buffer size |
| 147 | − _current_size = _stream.fail() ? static_cast<std::size_t>(_stream.gcount()) : buffered_reader_t::buffer_size; | |
| 144 | + _current_size = _stream.fail() ? static_cast<std::size_t>(_stream.gcount()) : _buffer.size(); | |
| 148 | 145 | } |
| 149 | 146 | |
| 150 | 147 | return _current_size - _current_index; |
| @@ -61,23 +61,23 @@ namespace disvm · 60 unmodified lines | ||
| 61 | 61 | |
| 62 | 62 | struct vm_frame_constants |
| 63 | 63 | { |
| 64 | − static const auto register_size_in_bytes = sizeof(word_t); | |
| 64 | + static constexpr auto register_size_in_bytes() { return sizeof(word_t); } | |
| 65 | 65 | |
| 66 | 66 | // Includes registers on base frame plus the implied return register |
| 67 | − static const auto default_register_count = (sizeof(vm_frame_base_alloc_t) / register_size_in_bytes) + 1; | |
| 67 | + static constexpr auto default_register_count() { return (sizeof(vm_frame_base_alloc_t) / register_size_in_bytes()) + 1; } | |
| 68 | 68 | |
| 69 | 69 | // [SPEC] The fixed point registers are defined by their usage in the |
| 70 | 70 | // Inferno implementation. They rely on the 'temp' registers defined below. |
| 71 | 71 | // See fixed point opcodes in Inferno (libinterp/xec.c). |
| 72 | − static const auto fixed_point_register_1_offset = default_register_count * register_size_in_bytes; | |
| 73 | − static const auto fixed_point_register_2_offset = fixed_point_register_1_offset + (2 * register_size_in_bytes); | |
| 72 | + static constexpr auto fixed_point_register_1_offset() { return default_register_count() * register_size_in_bytes(); } | |
| 73 | + static constexpr auto fixed_point_register_2_offset() { return fixed_point_register_1_offset() + (2 * register_size_in_bytes()); } | |
| 74 | 74 | |
| 75 | 75 | // [SPEC] The official Limbo compiler allocates additional 'temp' registers on all call frames. |
| 76 | 76 | // See 'STemp', 'RTemp', and 'DTemp' in Inferno (limbo/limbo.h) |
| 77 | − static const auto limbo_temp_register_count = 3; | |
| 77 | + static constexpr auto limbo_temp_register_count() { return 3; } | |
| 78 | 78 | |
| 79 | 79 | // Define the first argument offset in a Limbo compiler generated call frame. |
| 80 | − static const auto limbo_first_arg_register_offset = (default_register_count + limbo_temp_register_count) * register_size_in_bytes; | |
| 80 | + static constexpr auto limbo_first_arg_register_offset() { return (default_register_count() + limbo_temp_register_count()) * register_size_in_bytes(); } | |
| 81 | 81 | }; |
| 82 | 82 | |
| 83 | 83 | // |
| @@ -55,12 +55,9 @@ namespace disvm · 54 unmodified lines | ||
| 55 | 55 | class vm_t final |
| 56 | 56 | { |
| 57 | 57 | public: // static |
| 58 | − static const uint32_t root_vm_thread_id = 0; | |
| 59 | − | |
| 60 | − static const uint32_t default_system_thread_count = 1; | |
| 61 | − | |
| 62 | − // The Inferno implementation defined the thread quanta as 2048 (include/interp.h) | |
| 63 | − static const uint32_t default_thread_quanta = 2048; | |
| 58 | + static const uint32_t root_vm_thread_id; | |
| 59 | + static const uint32_t default_system_thread_count; | |
| 60 | + static const uint32_t default_thread_quanta; | |
| 64 | 61 | |
| 65 | 62 | public: |
| 66 | 63 | explicit vm_t( |
| @@ -18,10 +18,10 @@ namespace disvm · 17 unmodified lines | ||
| 18 | 18 | static_assert(sizeof(operand_t) == sizeof(runtime::word_t), "Operand and word should be the same size"); |
| 19 | 19 | static_assert(sizeof(operand_t) == sizeof(runtime::vm_pc_t), "Operand and VM program counter type should be the same size"); |
| 20 | 20 | |
| 21 | − struct magic_number_constants final | |
| 21 | + namespace magic_number_constants | |
| 22 | 22 | { |
| 23 | − static const auto xmagic = operand_t{ 819248 }; // Normal module (0xC8030) | |
| 24 | − static const auto smagic = operand_t{ 923426 }; // Signed module (0xE1722) | |
| 23 | + const auto xmagic = operand_t{ 819248 }; // Normal module (0xC8030) | |
| 24 | + const auto smagic = operand_t{ 923426 }; // Signed module (0xE1722) | |
| 25 | 25 | }; |
| 26 | 26 | } |
| 27 | 27 | } |
| @@ -364,11 +364,11 @@ namespace disvm · 363 unmodified lines | ||
| 364 | 364 | }; |
| 365 | 365 | |
| 366 | 366 | // Runtime constants |
| 367 | − struct runtime_constants | |
| 367 | + namespace runtime_constants | |
| 368 | 368 | { |
| 369 | − static const auto nil = std::size_t{ 0 }; | |
| 369 | + const auto nil = std::size_t{ 0 }; | |
| 370 | 370 | |
| 371 | − static const auto invalid_program_counter = vm_pc_t{ ~0 }; | |
| 371 | + const auto invalid_program_counter = vm_pc_t{ ~0 }; | |
| 372 | 372 | }; |
| 373 | 373 | |
| 374 | 374 | // Addressing mode for middle instruction data |
| @@ -17,16 +17,16 @@ namespace disvm · 16 unmodified lines | ||
| 17 | 17 | namespace utf8 |
| 18 | 18 | { |
| 19 | 19 | // As defined in http://tools.ietf.org/html/rfc3629 |
| 20 | − struct constants | |
| 20 | + namespace constants | |
| 21 | 21 | { |
| 22 | − static const rune_t multi_byte_value_mask = 0x3f; | |
| 22 | + const disvm::runtime::rune_t multi_byte_value_mask = 0x3f; | |
| 23 | 23 | |
| 24 | − static const rune_t max_codepoint_ascii = 0x7f; | |
| 25 | − static const rune_t max_codepoint_2_byte = 0x7ff; | |
| 26 | − static const rune_t max_codepoint_3_byte = 0xffff; | |
| 27 | − static const rune_t max_codepoint_4_byte = 0x10ffff; | |
| 24 | + const disvm::runtime::rune_t max_codepoint_ascii = 0x7f; | |
| 25 | + const disvm::runtime::rune_t max_codepoint_2_byte = 0x7ff; | |
| 26 | + const disvm::runtime::rune_t max_codepoint_3_byte = 0xffff; | |
| 27 | + const disvm::runtime::rune_t max_codepoint_4_byte = 0x10ffff; | |
| 28 | 28 | |
| 29 | − static const rune_t max_supported_codepoint = max_codepoint_4_byte; | |
| 29 | + const disvm::runtime::rune_t max_supported_codepoint = max_codepoint_4_byte; | |
| 30 | 30 | }; |
| 31 | 31 | |
| 32 | 32 | // Compute the number of code points in the supplied string |
| @@ -46,7 +46,7 @@ namespace disvm · 45 unmodified lines | ||
| 46 | 46 | static uint32_t compute_signature_hash(const char *); |
| 47 | 47 | |
| 48 | 48 | // Type delimiter |
| 49 | − static const char delim = ','; | |
| 49 | + static const char delim; | |
| 50 | 50 | |
| 51 | 51 | public: |
| 52 | 52 | std::string get_signature() const; |
| @@ -100,7 +100,7 @@ namespace disvm · 47 unmodified lines | ||
| 100 | 100 | template<type_id_t T> |
| 101 | 101 | struct Tbasic_type |
| 102 | 102 | { |
| 103 | − static const type_id_t id = T; | |
| 103 | + static const type_id_t id; | |
| 104 | 104 | |
| 105 | 105 | constexpr operator type_id_t() const |
| 106 | 106 | { |
| @@ -108,6 +108,9 @@ namespace disvm · 1 unmodified line | ||
| 108 | 108 | } |
| 109 | 109 | }; |
| 110 | 110 | |
| 111 | + template<type_id_t T> | |
| 112 | + const type_id_t Tbasic_type<T>::id = T; | |
| 113 | + | |
| 111 | 114 | using Tnone = Tbasic_type<type_id_t::none>; |
| 112 | 115 | using Tbyte = Tbasic_type<type_id_t::byte>; |
| 113 | 116 | using Tinteger = Tbasic_type<type_id_t::integer>; |
| @@ -164,7 +167,7 @@ namespace disvm · 50 unmodified lines | ||
| 164 | 167 | class Ttype_ref final |
| 165 | 168 | { |
| 166 | 169 | public: // static |
| 167 | − static const char id = '@'; | |
| 170 | + static const char id; | |
| 168 | 171 | |
| 169 | 172 | public: |
| 170 | 173 | Ttype_ref(uint32_t num); |
| @@ -218,7 +221,7 @@ namespace disvm · 47 unmodified lines | ||
| 218 | 221 | template <type_id_t ID> |
| 219 | 222 | class Tnested_aggregate_type : public Tbasic_type<ID> |
| 220 | 223 | { |
| 221 | − public: // static | |
| 224 | + public: // static | |
| 222 | 225 | static const char begin; |
| 223 | 226 | static const char end; |
| 224 | 227 | |
| @@ -258,8 +261,8 @@ namespace disvm · 33 unmodified lines | ||
| 258 | 261 | { |
| 259 | 262 | public: // static |
| 260 | 263 | static const char *tag_delim; |
| 261 | − static const char begin = '('; | |
| 262 | − static const char end = ')'; | |
| 264 | + static const char begin; | |
| 265 | + static const char end; | |
| 263 | 266 | |
| 264 | 267 | static Tadt_pick_tag create(const char *pick_tag, uint32_t adt_ref, std::initializer_list<const Tm> tms); |
| 265 | 268 | |
| @@ -325,8 +328,8 @@ namespace disvm · 59 unmodified lines | ||
| 325 | 328 | class Tfunction_base_type final : public Tbasic_type<T> |
| 326 | 329 | { |
| 327 | 330 | public: // static |
| 328 | − static const char begin = '('; | |
| 329 | − static const char end = ')'; | |
| 331 | + static const char begin; | |
| 332 | + static const char end; | |
| 330 | 333 | |
| 331 | 334 | template<typename ...AT> |
| 332 | 335 | static Tfunction_base_type create(AT... argTypes) |
| @@ -360,6 +363,12 @@ namespace disvm · 27 unmodified lines | ||
| 360 | 363 | Tfunction_base_type() : _fully_defined{ false } { } |
| 361 | 364 | }; |
| 362 | 365 | |
| 366 | + template<type_id_t T> | |
| 367 | + const char Tfunction_base_type<T>::begin = '('; | |
| 368 | + | |
| 369 | + template<type_id_t T> | |
| 370 | + const char Tfunction_base_type<T>::end = ')'; | |
| 371 | + | |
| 363 | 372 | using Tfunction = Tfunction_base_type<type_id_t::function>; |
| 364 | 373 | using Tfunction_varargs = Tfunction_base_type<type_id_t::function_varargs>; |
| 365 | 374 | |