Showing the changes to src/vm/vm_memory.cpp (1 of 11 files). Show all
Unified · Split
| @@ -323,92 +323,76 @@ namespace · 322 unmodified lines | |||
| 323 | { | 323 | { |
| 324 | namespace hidden_type_desc | 324 | namespace hidden_type_desc |
| 325 | { | 325 | { |
| 326 | std::shared_ptr<const type_descriptor_t> byte; | 326 | const type_descriptor_t byte{ sizeof(byte_t), 0, nullptr, type_descriptor_t::no_finalizer }; |
| 327 | std::shared_ptr<const type_descriptor_t> short_word; | 327 | const type_descriptor_t short_word{ sizeof(short_word_t), 0, nullptr, type_descriptor_t::no_finalizer }; |
| 328 | std::shared_ptr<const type_descriptor_t> word; | 328 | const type_descriptor_t word{ sizeof(word_t), 0, nullptr, type_descriptor_t::no_finalizer }; |
| 329 | std::shared_ptr<const type_descriptor_t> short_real; | 329 | const type_descriptor_t short_real{ sizeof(short_real_t), 0, nullptr, type_descriptor_t::no_finalizer }; |
| 330 | std::shared_ptr<const type_descriptor_t> real; | 330 | const type_descriptor_t real{ sizeof(real_t), 0, nullptr, type_descriptor_t::no_finalizer }; |
| 331 | std::shared_ptr<const type_descriptor_t> big; | 331 | const type_descriptor_t big{ sizeof(big_t), 0, nullptr, type_descriptor_t::no_finalizer }; |
| 332 | std::shared_ptr<const type_descriptor_t> pointer; | 332 | |
| 333 | 333 | const byte_t pointer_map[] = { 0x80 }; | |
| 334 | std::shared_ptr<const type_descriptor_t> vm_array; | 334 | const type_descriptor_t pointer{ sizeof(pointer_t), (sizeof(pointer_map) / sizeof(pointer_map[0])), pointer_map, type_descriptor_t::no_finalizer }; |
| 335 | std::shared_ptr<const type_descriptor_t> vm_list; | 335 | |
| 336 | std::shared_ptr<const type_descriptor_t> vm_channel; | 336 | const type_descriptor_t vm_array{ 0, 0, nullptr, type_descriptor_t::no_finalizer }; |
| 337 | std::shared_ptr<const type_descriptor_t> vm_string; | 337 | const type_descriptor_t vm_list{ 0, 0, nullptr, type_descriptor_t::no_finalizer }; |
| 338 | 338 | const type_descriptor_t vm_channel{ 0, 0, nullptr, type_descriptor_t::no_finalizer }; | |
| 339 | std::shared_ptr<const type_descriptor_t> vm_module_ref; | 339 | const type_descriptor_t vm_string{ 0, 0, nullptr, type_descriptor_t::no_finalizer }; |
| 340 | std::shared_ptr<const type_descriptor_t> vm_stack; | 340 | |
| 341 | std::shared_ptr<const type_descriptor_t> vm_thread; | 341 | const type_descriptor_t vm_module_ref{ 0, 0, nullptr, type_descriptor_t::no_finalizer }; |
| 342 | const type_descriptor_t vm_stack{ 0, 0, nullptr, type_descriptor_t::no_finalizer }; | ||
| 343 | const type_descriptor_t vm_thread{ 0, 0, nullptr, type_descriptor_t::no_finalizer }; | ||
| 344 | |||
| 345 | struct | ||
| 346 | { | ||
| 347 | void operator()(const type_descriptor_t *) | ||
| 348 | { | ||
| 349 | // Not allocated on heap | ||
| 350 | } | ||
| 351 | } deleter; | ||
| 342 | } | 352 | } |
| 343 | } | 353 | } |
| 344 | 354 | ||
| 345 | std::atomic_bool intrinsic_type_desc::is_initialized{ false }; | ||
| 346 | |||
| 347 | void intrinsic_type_desc::initialize() | ||
| 348 | { | ||
| 349 | auto is_false = bool{ false }; | ||
| 350 | if (!intrinsic_type_desc::is_initialized.compare_exchange_strong(is_false, true)) | ||
| 351 | return; | ||
| 352 | |||
| 353 | hidden_type_desc::byte = type_descriptor_t::create(sizeof(byte_t)); | ||
| 354 | hidden_type_desc::short_word = type_descriptor_t::create(sizeof(short_word_t)); | ||
| 355 | hidden_type_desc::word = type_descriptor_t::create(sizeof(word_t)); | ||
| 356 | hidden_type_desc::short_real = type_descriptor_t::create(sizeof(short_real_t)); | ||
| 357 | hidden_type_desc::real = type_descriptor_t::create(sizeof(real_t)); | ||
| 358 | hidden_type_desc::big = type_descriptor_t::create(sizeof(big_t)); | ||
| 359 | hidden_type_desc::pointer = type_descriptor_t::create(sizeof(pointer_t), std::vector<byte_t>{0x80}); | ||
| 360 | |||
| 361 | hidden_type_desc::vm_array = type_descriptor_t::create(0); | ||
| 362 | hidden_type_desc::vm_list = type_descriptor_t::create(0); | ||
| 363 | hidden_type_desc::vm_channel = type_descriptor_t::create(0); | ||
| 364 | hidden_type_desc::vm_string = type_descriptor_t::create(0); | ||
| 365 | |||
| 366 | hidden_type_desc::vm_module_ref = type_descriptor_t::create(0); | ||
| 367 | hidden_type_desc::vm_stack = type_descriptor_t::create(0); | ||
| 368 | hidden_type_desc::vm_thread = type_descriptor_t::create(0); | ||
| 369 | } | ||
| 370 | |||
| 371 | template<> | 355 | template<> |
| 372 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<byte_t>() { return hidden_type_desc::byte; } | 356 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<byte_t>() { return{ &hidden_type_desc::byte, hidden_type_desc::deleter }; } |
| 373 | 357 | ||
| 374 | template<> | 358 | template<> |
| 375 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<short_word_t>() { return hidden_type_desc::short_word; } | 359 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<short_word_t>() { return{ &hidden_type_desc::short_word, hidden_type_desc::deleter }; } |
| 376 | 360 | ||
| 377 | template<> | 361 | template<> |
| 378 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<word_t>() { return hidden_type_desc::word; } | 362 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<word_t>() { return{ &hidden_type_desc::word, hidden_type_desc::deleter }; } |
| 379 | 363 | ||
| 380 | template<> | 364 | template<> |
| 381 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<short_real_t>() { return hidden_type_desc::short_real; } | 365 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<short_real_t>() { return{ &hidden_type_desc::short_real, hidden_type_desc::deleter }; } |
| 382 | 366 | ||
| 383 | template<> | 367 | template<> |
| 384 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<real_t>() { return hidden_type_desc::real; } | 368 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<real_t>() { return{ &hidden_type_desc::real, hidden_type_desc::deleter }; } |
| 385 | 369 | ||
| 386 | template<> | 370 | template<> |
| 387 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<big_t>() { return hidden_type_desc::big; } | 371 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<big_t>() { return{ &hidden_type_desc::big, hidden_type_desc::deleter }; } |
| 388 | 372 | ||
| 389 | template<> | 373 | template<> |
| 390 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<pointer_t>() { return hidden_type_desc::pointer; } | 374 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<pointer_t>() { return{ &hidden_type_desc::pointer, hidden_type_desc::deleter }; } |
| 391 | 375 | ||
| 392 | template<> | 376 | template<> |
| 393 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<vm_array_t>() { return hidden_type_desc::vm_array; } | 377 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<vm_array_t>() { return{ &hidden_type_desc::vm_array, hidden_type_desc::deleter }; } |
| 394 | 378 | ||
| 395 | template<> | 379 | template<> |
| 396 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<vm_list_t>() { return hidden_type_desc::vm_list; } | 380 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<vm_list_t>() { return{ &hidden_type_desc::vm_list, hidden_type_desc::deleter }; } |
| 397 | 381 | ||
| 398 | template<> | 382 | template<> |
| 399 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<vm_channel_t>() { return hidden_type_desc::vm_channel; } | 383 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<vm_channel_t>() { return{ &hidden_type_desc::vm_channel, hidden_type_desc::deleter }; } |
| 400 | 384 | ||
| 401 | template<> | 385 | template<> |
| 402 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<vm_string_t>() { return hidden_type_desc::vm_string; } | 386 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<vm_string_t>() { return{ &hidden_type_desc::vm_string, hidden_type_desc::deleter }; } |
| 403 | 387 | ||
| 404 | template<> | 388 | template<> |
| 405 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<vm_module_ref_t>() { return hidden_type_desc::vm_module_ref; } | 389 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<vm_module_ref_t>() { return{ &hidden_type_desc::vm_module_ref, hidden_type_desc::deleter }; } |
| 406 | 390 | ||
| 407 | template<> | 391 | template<> |
| 408 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<vm_stack_t>() { return hidden_type_desc::vm_stack; } | 392 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<vm_stack_t>() { return{ &hidden_type_desc::vm_stack, hidden_type_desc::deleter }; } |
| 409 | 393 | ||
| 410 | template<> | 394 | template<> |
| 411 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<vm_thread_t>() { return hidden_type_desc::vm_thread; } | 395 | static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<vm_thread_t>() { return{ &hidden_type_desc::vm_thread, hidden_type_desc::deleter }; } |
| 412 | 396 | ||
| 413 | vm_alloc_instance_finalizer_t type_descriptor_t::no_finalizer = nullptr; | 397 | vm_alloc_instance_finalizer_t type_descriptor_t::no_finalizer = nullptr; |
| 414 | 398 | ||