Unified · Split
| @@ -24,9 +24,11 @@ using disvm::vm_t; · 23 unmodified lines | ||
| 24 | 24 | using disvm::debug::component_trace_t; |
| 25 | 25 | using disvm::debug::log_level_t; |
| 26 | 26 | |
| 27 | +using disvm::runtime::byte_t; | |
| 27 | 28 | using disvm::runtime::dereference_nil; |
| 28 | 29 | using disvm::runtime::intrinsic_type_desc; |
| 29 | 30 | using disvm::runtime::out_of_range_memory; |
| 31 | +using disvm::runtime::pointer_t; | |
| 30 | 32 | using disvm::runtime::type_descriptor_t; |
| 31 | 33 | using disvm::runtime::vm_alloc_t; |
| 32 | 34 | using disvm::runtime::vm_array_t; |
| @@ -171,9 +173,9 @@ namespace · 138 unmodified lines | ||
| 171 | 173 | word_t printf_to_fd( |
| 172 | 174 | disvm::vm_t &vm, |
| 173 | 175 | vm_fd_t &fd, |
| 174 | − const disvm::runtime::vm_string_t &msg_fmt, | |
| 175 | − disvm::runtime::byte_t *msg_args, | |
| 176 | − disvm::runtime::pointer_t base) | |
| 176 | + const vm_string_t &msg_fmt, | |
| 177 | + byte_t *msg_args, | |
| 178 | + pointer_t base) | |
| 177 | 179 | { |
| 178 | 180 | auto static_buffer = std::array<char, 1024>{}; |
| 179 | 181 | auto written = disvm::runtime::sys::printf_to_buffer(vm, msg_fmt, msg_args, base, static_buffer.size(), static_buffer.data()); |
| @@ -265,17 +267,28 @@ void · 85 unmodified lines | ||
| 265 | 267 | Sys_announce(vm_registers_t &r, vm_t &vm) |
| 266 | 268 | { |
| 267 | 269 | auto &fp = r.stack.peek_frame()->base<F_Sys_announce>(); |
| 270 | + | |
| 271 | + // [PAL] Consume platform API | |
| 268 | 272 | throw vm_system_exception{ "Function not implemented" }; |
| 269 | 273 | } |
| 270 | 274 | |
| 271 | 275 | void |
| 272 | 276 | Sys_aprint(vm_registers_t &r, vm_t &vm) |
| 273 | 277 | { |
| 278 | + auto fp_base = r.stack.peek_frame()->base(); | |
| 274 | 279 | auto &fp = r.stack.peek_frame()->base<F_Sys_aprint>(); |
| 280 | + auto str = vm_alloc_t::from_allocation<vm_string_t>(fp.s); | |
| 281 | + if (str == nullptr) | |
| 282 | + throw dereference_nil{ "Print string to array" }; | |
| 275 | 283 | |
| 276 | − //disvm::runtime::dec_ref_count_and_free(vm_alloc_t::from_allocation(*fp.ret)); | |
| 277 | − //*fp.ret = nullptr; | |
| 278 | − throw vm_system_exception{ "Function not implemented" }; | |
| 284 | + auto buffer = std::vector<char>(128); | |
| 285 | + auto msg_args = &fp.vargs; | |
| 286 | + auto written = disvm::runtime::sys::printf_to_dynamic_buffer(vm, *str, msg_args, fp_base, buffer); | |
| 287 | + auto new_array = new vm_array_t{ intrinsic_type_desc::type<byte_t>(), written }; | |
| 288 | + std::memcpy(new_array->at(0), buffer.data(), written); | |
| 289 | + | |
| 290 | + disvm::runtime::dec_ref_count_and_free(vm_alloc_t::from_allocation(*fp.ret)); | |
| 291 | + *fp.ret = new_array->get_allocation(); | |
| 279 | 292 | } |
| 280 | 293 | |
| 281 | 294 | void |
| @@ -366,6 +379,8 @@ void · 84 unmodified lines | ||
| 366 | 379 | Sys_chdir(vm_registers_t &r, vm_t &vm) |
| 367 | 380 | { |
| 368 | 381 | auto &fp = r.stack.peek_frame()->base<F_Sys_chdir>(); |
| 382 | + | |
| 383 | + // [PAL] Consume platform API | |
| 369 | 384 | throw vm_system_exception{ "Function not implemented" }; |
| 370 | 385 | } |
| 371 | 386 | |
| @@ -408,6 +423,8 @@ void · 36 unmodified lines | ||
| 408 | 423 | Sys_dial(vm_registers_t &r, vm_t &vm) |
| 409 | 424 | { |
| 410 | 425 | auto &fp = r.stack.peek_frame()->base<F_Sys_dial>(); |
| 426 | + | |
| 427 | + // [PAL] Consume platform API | |
| 411 | 428 | throw vm_system_exception{ "Function not implemented" }; |
| 412 | 429 | } |
| 413 | 430 | |
| @@ -415,6 +432,8 @@ void · 1 unmodified line | ||
| 415 | 432 | Sys_dirread(vm_registers_t &r, vm_t &vm) |
| 416 | 433 | { |
| 417 | 434 | auto &fp = r.stack.peek_frame()->base<F_Sys_dirread>(); |
| 435 | + | |
| 436 | + // [PAL] Consume platform API | |
| 418 | 437 | throw vm_system_exception{ "Function not implemented" }; |
| 419 | 438 | } |
| 420 | 439 | |
| @@ -523,6 +542,8 @@ void · 102 unmodified lines | ||
| 523 | 542 | Sys_fstat(vm_registers_t &r, vm_t &vm) |
| 524 | 543 | { |
| 525 | 544 | auto &fp = r.stack.peek_frame()->base<F_Sys_fstat>(); |
| 545 | + | |
| 546 | + // [PAL] Consume platform API | |
| 526 | 547 | throw vm_system_exception{ "Function not implemented" }; |
| 527 | 548 | } |
| 528 | 549 | |
| @@ -537,6 +558,8 @@ void · 8 unmodified lines | ||
| 537 | 558 | Sys_fwstat(vm_registers_t &r, vm_t &vm) |
| 538 | 559 | { |
| 539 | 560 | auto &fp = r.stack.peek_frame()->base<F_Sys_fwstat>(); |
| 561 | + | |
| 562 | + // [PAL] Consume platform API | |
| 540 | 563 | throw vm_system_exception{ "Function not implemented" }; |
| 541 | 564 | } |
| 542 | 565 | |
| @@ -551,6 +574,8 @@ void · 8 unmodified lines | ||
| 551 | 574 | Sys_listen(vm_registers_t &r, vm_t &vm) |
| 552 | 575 | { |
| 553 | 576 | auto &fp = r.stack.peek_frame()->base<F_Sys_listen>(); |
| 577 | + | |
| 578 | + // [PAL] Consume platform API | |
| 554 | 579 | throw vm_system_exception{ "Function not implemented" }; |
| 555 | 580 | } |
| 556 | 581 | |
| @@ -609,6 +634,8 @@ void · 52 unmodified lines | ||
| 609 | 634 | Sys_pctl(vm_registers_t &r, vm_t &vm) |
| 610 | 635 | { |
| 611 | 636 | auto &fp = r.stack.peek_frame()->base<F_Sys_pctl>(); |
| 637 | + | |
| 638 | + // [PAL] Consume platform API | |
| 612 | 639 | throw vm_system_exception{ "Function not implemented" }; |
| 613 | 640 | } |
| 614 | 641 | |
| @@ -616,6 +643,8 @@ void · 1 unmodified line | ||
| 616 | 643 | Sys_pipe(vm_registers_t &r, vm_t &vm) |
| 617 | 644 | { |
| 618 | 645 | auto &fp = r.stack.peek_frame()->base<F_Sys_pipe>(); |
| 646 | + | |
| 647 | + // [PAL] Consume platform API | |
| 619 | 648 | throw vm_system_exception{ "Function not implemented" }; |
| 620 | 649 | } |
| 621 | 650 | |
| @@ -753,6 +782,7 @@ Sys_sprint(vm_registers_t &r, vm_t &vm) · 131 unmodified lines | ||
| 753 | 782 | new_string = new vm_string_t{ static_cast<std::size_t>(written), reinterpret_cast<uint8_t *>(dynamic_buffer.data()) }; |
| 754 | 783 | } |
| 755 | 784 | |
| 785 | + disvm::runtime::dec_ref_count_and_free(vm_alloc_t::from_allocation(*fp.ret)); | |
| 756 | 786 | *fp.ret = new_string->get_allocation(); |
| 757 | 787 | } |
| 758 | 788 | |
| @@ -760,6 +790,8 @@ void · 1 unmodified line | ||
| 760 | 790 | Sys_stat(vm_registers_t &r, vm_t &vm) |
| 761 | 791 | { |
| 762 | 792 | auto &fp = r.stack.peek_frame()->base<F_Sys_stat>(); |
| 793 | + | |
| 794 | + // [PAL] Consume platform API | |
| 763 | 795 | throw vm_system_exception{ "Function not implemented" }; |
| 764 | 796 | } |
| 765 | 797 | |
| @@ -767,7 +799,36 @@ void · 1 unmodified line | ||
| 767 | 799 | Sys_stream(vm_registers_t &r, vm_t &vm) |
| 768 | 800 | { |
| 769 | 801 | auto &fp = r.stack.peek_frame()->base<F_Sys_stream>(); |
| 770 | − throw vm_system_exception{ "Function not implemented" }; | |
| 802 | + | |
| 803 | + auto alloc_s = vm_alloc_t::from_allocation(fp.src); | |
| 804 | + if (alloc_s == nullptr) | |
| 805 | + throw dereference_nil{ "Source in stream" }; | |
| 806 | + | |
| 807 | + auto alloc_d = vm_alloc_t::from_allocation(fp.dst); | |
| 808 | + if (alloc_d == nullptr) | |
| 809 | + throw dereference_nil{ "Destination in stream" }; | |
| 810 | + | |
| 811 | + assert(alloc_s->alloc_type->is_equal(T_FD.get()) && alloc_d->alloc_type->is_equal(T_FD.get())); | |
| 812 | + auto src = alloc_s->get_allocation<Sys_FD_Impl>()->impl; | |
| 813 | + auto dst = alloc_d->get_allocation<Sys_FD_Impl>()->impl; | |
| 814 | + | |
| 815 | + const auto buffer_size = fp.bufsiz; | |
| 816 | + if (buffer_size <= 0) | |
| 817 | + throw out_of_range_memory{}; | |
| 818 | + | |
| 819 | + std::unique_ptr<void, decltype(&disvm::runtime::free_memory)> buffer{ disvm::runtime::alloc_memory(buffer_size), disvm::runtime::free_memory }; | |
| 820 | + auto written = word_t{}; | |
| 821 | + for (;;) | |
| 822 | + { | |
| 823 | + auto bytes_read = src->read(vm, buffer_size, buffer.get()); | |
| 824 | + if (bytes_read == 0) | |
| 825 | + break; | |
| 826 | + | |
| 827 | + dst->write(vm, bytes_read, buffer.get()); | |
| 828 | + written += bytes_read; | |
| 829 | + } | |
| 830 | + | |
| 831 | + *fp.ret = written; | |
| 771 | 832 | } |
| 772 | 833 | |
| 773 | 834 | namespace |
| @@ -971,5 +1032,7 @@ void · 197 unmodified lines | ||
| 971 | 1032 | Sys_wstat(vm_registers_t &r, vm_t &vm) |
| 972 | 1033 | { |
| 973 | 1034 | auto &fp = r.stack.peek_frame()->base<F_Sys_wstat>(); |
| 1035 | + | |
| 1036 | + // [PAL] Consume platform API | |
| 974 | 1037 | throw vm_system_exception{ "Function not implemented" }; |
| 975 | 1038 | } |