Showing the changes to src/include (1 of 2 files). Show all
Unified · Split
| @@ -11,7 +11,6 @@ · 10 unmodified lines | ||
| 11 | 11 | #include <sstream> |
| 12 | 12 | #include <cassert> |
| 13 | 13 | #include <cstdint> |
| 14 | −#include "opcodes.h" | |
| 15 | 14 | #include "runtime.h" |
| 16 | 15 | |
| 17 | 16 | namespace disvm |
| @@ -29,7 +28,7 @@ namespace disvm · 11 unmodified lines | ||
| 29 | 28 | static uint32_t compute_signature_hash(const char *); |
| 30 | 29 | |
| 31 | 30 | // Type delimiter |
| 32 | − static const char delim; | |
| 31 | + static constexpr char delim(); | |
| 33 | 32 | |
| 34 | 33 | public: |
| 35 | 34 | std::string get_signature() const; |
| @@ -45,6 +44,8 @@ namespace disvm · 9 unmodified lines | ||
| 45 | 44 | mutable std::stringstream _ss; |
| 46 | 45 | }; |
| 47 | 46 | |
| 47 | + constexpr char sig_stream_t::delim() { return ','; } | |
| 48 | + | |
| 48 | 49 | // Type context modifiers |
| 49 | 50 | enum class modifier_id_t : uint8_t |
| 50 | 51 | { |
| @@ -196,7 +197,7 @@ namespace disvm · 145 unmodified lines | ||
| 196 | 197 | template<typename T1, typename T2, typename ...S> |
| 197 | 198 | void nested_type(sig_stream_t &ss, const T1 &t1, const T2 &t2, const S&...s) |
| 198 | 199 | { |
| 199 | − ss << t1 << sig_stream_t::delim; | |
| 200 | + ss << t1 << sig_stream_t::delim(); | |
| 200 | 201 | nested_type(ss, t2, s...); |
| 201 | 202 | } |
| 202 | 203 | |
| @@ -205,18 +206,18 @@ namespace disvm · 2 unmodified lines | ||
| 205 | 206 | class Tnested_aggregate_type : public Tbasic_type<ID> |
| 206 | 207 | { |
| 207 | 208 | public: // static |
| 208 | − static const char begin; | |
| 209 | − static const char end; | |
| 209 | + static constexpr char begin(); | |
| 210 | + static constexpr char end(); | |
| 210 | 211 | |
| 211 | 212 | template<typename ...NT> |
| 212 | 213 | static Tnested_aggregate_type create(const NT&... nestedTypes) |
| 213 | 214 | { |
| 214 | 215 | sig_stream_t ss; |
| 215 | − ss << Tbasic_type<ID>::id << Tnested_aggregate_type::begin; | |
| 216 | + ss << Tbasic_type<ID>::id << Tnested_aggregate_type::begin(); | |
| 216 | 217 | |
| 217 | 218 | nested_type(ss, nestedTypes...); |
| 218 | 219 | |
| 219 | − ss << Tnested_aggregate_type::end; | |
| 220 | + ss << Tnested_aggregate_type::end(); | |
| 220 | 221 | |
| 221 | 222 | return Tnested_aggregate_type{ ss }; |
| 222 | 223 | } |
| @@ -234,6 +235,16 @@ namespace disvm · 11 unmodified lines | ||
| 234 | 235 | |
| 235 | 236 | using Ttuple = Tnested_aggregate_type<type_id_t::tuple>; |
| 236 | 237 | using Tmodule = Tnested_aggregate_type<type_id_t::module>; |
| 238 | + using _Tadt = Tnested_aggregate_type<type_id_t::adt>; | |
| 239 | + | |
| 240 | + template<> constexpr char Ttuple::begin() { return '('; } | |
| 241 | + template<> constexpr char Ttuple::end() { return ')'; } | |
| 242 | + | |
| 243 | + template<> constexpr char Tmodule::begin() { return '{'; } | |
| 244 | + template<> constexpr char Tmodule::end() { return '}'; } | |
| 245 | + | |
| 246 | + template<> constexpr char _Tadt::begin() { return '('; } | |
| 247 | + template<> constexpr char _Tadt::end() { return ')'; } | |
| 237 | 248 | |
| 238 | 249 | sig_stream_t &operator<<(sig_stream_t &, const disvm::assembly::sigkind::Ttuple &); |
| 239 | 250 | sig_stream_t &operator<<(sig_stream_t &, const disvm::assembly::sigkind::Tmodule &); |
| @@ -243,9 +254,9 @@ namespace disvm · 3 unmodified lines | ||
| 243 | 254 | class Tadt_pick_tag final : public Tbasic_type<type_id_t::adt_pick_tag> |
| 244 | 255 | { |
| 245 | 256 | public: // static |
| 246 | − static const char *tag_delim; | |
| 247 | − static const char begin; | |
| 248 | − static const char end; | |
| 257 | + static constexpr char *tag_delim(); | |
| 258 | + static constexpr char begin(); | |
| 259 | + static constexpr char end(); | |
| 249 | 260 | |
| 250 | 261 | static Tadt_pick_tag create(const char *pick_tag, uint32_t adt_ref, std::initializer_list<const Tm> tms); |
| 251 | 262 | |
| @@ -256,24 +267,28 @@ namespace disvm · 4 unmodified lines | ||
| 256 | 267 | Tadt_pick_tag(sig_stream_t &s) : _s{ std::move(s) } { } |
| 257 | 268 | }; |
| 258 | 269 | |
| 270 | + constexpr char *Tadt_pick_tag::tag_delim() { return "=>"; } | |
| 271 | + constexpr char Tadt_pick_tag::begin() { return '('; } | |
| 272 | + constexpr char Tadt_pick_tag::end() { return ')'; } | |
| 273 | + | |
| 259 | 274 | sig_stream_t &operator<<(sig_stream_t &, const disvm::assembly::sigkind::Tadt_pick_tag &); |
| 260 | 275 | |
| 261 | 276 | // Abstract data type (ADT) |
| 262 | − class Tadt final : public Tnested_aggregate_type<type_id_t::adt> | |
| 277 | + class Tadt final : public _Tadt | |
| 263 | 278 | { |
| 264 | 279 | public: // static |
| 265 | 280 | // Unhide base class version of function |
| 266 | − using Tnested_aggregate_type::create; | |
| 281 | + using _Tadt::create; | |
| 267 | 282 | |
| 268 | 283 | // Create an ADT with a single pick tag |
| 269 | 284 | static Tadt create(const Tadt_pick_tag &p) |
| 270 | 285 | { |
| 271 | 286 | sig_stream_t ss; |
| 272 | 287 | ss << Tbasic_type::id |
| 273 | − << Tadt::begin | |
| 274 | − << sig_stream_t::delim | |
| 288 | + << Tadt::begin() | |
| 289 | + << sig_stream_t::delim() | |
| 275 | 290 | << p |
| 276 | − << Tadt::end; | |
| 291 | + << Tadt::end(); | |
| 277 | 292 | |
| 278 | 293 | return Tadt{ ss }; |
| 279 | 294 | } |
| @@ -288,20 +303,20 @@ namespace disvm · 8 unmodified lines | ||
| 288 | 303 | // single pick tag for an ADT must also be handled (above). |
| 289 | 304 | sig_stream_t ss; |
| 290 | 305 | ss << Tbasic_type::id |
| 291 | − << Tadt::begin | |
| 292 | − << sig_stream_t::delim | |
| 306 | + << Tadt::begin() | |
| 307 | + << sig_stream_t::delim() | |
| 293 | 308 | << p |
| 294 | − << sig_stream_t::delim; | |
| 309 | + << sig_stream_t::delim(); | |
| 295 | 310 | |
| 296 | 311 | nested_type(ss, t, nestedTypes...); |
| 297 | 312 | |
| 298 | − ss << Tadt::end; | |
| 313 | + ss << Tadt::end(); | |
| 299 | 314 | |
| 300 | 315 | return Tadt{ ss }; |
| 301 | 316 | } |
| 302 | 317 | |
| 303 | 318 | private: |
| 304 | − Tadt(sig_stream_t &s) : Tnested_aggregate_type{ s } { } | |
| 319 | + Tadt(sig_stream_t &s) : _Tadt{ s } { } | |
| 305 | 320 | }; |
| 306 | 321 | |
| 307 | 322 | sig_stream_t &operator<<(sig_stream_t &, const disvm::assembly::sigkind::Tnested_aggregate_type<type_id_t::adt> &); |
| @@ -311,18 +326,18 @@ namespace disvm · 3 unmodified lines | ||
| 311 | 326 | class Tfunction_base_type final : public Tbasic_type<T> |
| 312 | 327 | { |
| 313 | 328 | public: // static |
| 314 | − static const char begin; | |
| 315 | − static const char end; | |
| 329 | + static constexpr char begin(); | |
| 330 | + static constexpr char end(); | |
| 316 | 331 | |
| 317 | 332 | template<typename ...AT> |
| 318 | 333 | static Tfunction_base_type create(AT... argTypes) |
| 319 | 334 | { |
| 320 | 335 | Tfunction_base_type a; |
| 321 | − a._s << Tfunction_base_type::id << Tfunction_base_type::begin; | |
| 336 | + a._s << Tfunction_base_type::id << Tfunction_base_type::begin(); | |
| 322 | 337 | |
| 323 | 338 | nested_type(a._s, argTypes...); |
| 324 | 339 | |
| 325 | − a._s << Tfunction_base_type::end; | |
| 340 | + a._s << Tfunction_base_type::end(); | |
| 326 | 341 | return a; |
| 327 | 342 | } |
| 328 | 343 | |
| @@ -347,10 +362,10 @@ namespace disvm · 18 unmodified lines | ||
| 347 | 362 | }; |
| 348 | 363 | |
| 349 | 364 | template<type_id_t T> |
| 350 | − const char Tfunction_base_type<T>::begin = '('; | |
| 365 | + constexpr char Tfunction_base_type<T>::begin() { return '('; } | |
| 351 | 366 | |
| 352 | 367 | template<type_id_t T> |
| 353 | − const char Tfunction_base_type<T>::end = ')'; | |
| 368 | + constexpr char Tfunction_base_type<T>::end() { return ')'; } | |
| 354 | 369 | |
| 355 | 370 | using Tfunction = Tfunction_base_type<type_id_t::function>; |
| 356 | 371 | using Tfunction_varargs = Tfunction_base_type<type_id_t::function_varargs>; |