fix printing issue

shared
Brett 2024-08-19 22:05:42 -04:00
parent 3ac18cd1a4
commit 52732bc1a1
3 changed files with 12 additions and 10 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25) cmake_minimum_required(VERSION 3.25)
project(blt-gp VERSION 0.1.12) project(blt-gp VERSION 0.1.13)
include(CTest) include(CTest)

View File

@ -130,7 +130,7 @@ namespace blt::gp
if (stack.empty()) if (stack.empty())
return; return;
if (size_ < stack.bytes_stored + bytes_stored) if (size_ < stack.bytes_stored + bytes_stored)
expand(stack.bytes_stored + bytes_stored); expand(stack.bytes_stored + size_);
std::memcpy(data_ + bytes_stored, stack.data_, stack.bytes_stored); std::memcpy(data_ + bytes_stored, stack.data_, stack.bytes_stored);
bytes_stored += stack.bytes_stored; bytes_stored += stack.bytes_stored;
} }
@ -140,7 +140,7 @@ namespace blt::gp
if (bytes == 0) if (bytes == 0)
return; return;
if (size_ < bytes + bytes_stored) if (size_ < bytes + bytes_stored)
expand(bytes + bytes_stored); expand(bytes + size_);
std::memcpy(data_ + bytes_stored, stack.data_ + (stack.bytes_stored - bytes), bytes); std::memcpy(data_ + bytes_stored, stack.data_ + (stack.bytes_stored - bytes), bytes);
bytes_stored += bytes; bytes_stored += bytes;
} }
@ -150,7 +150,7 @@ namespace blt::gp
if (bytes == 0 || data == nullptr) if (bytes == 0 || data == nullptr)
return; return;
if (size_ < bytes + bytes_stored) if (size_ < bytes + bytes_stored)
expand(bytes + bytes_stored); expand(bytes + size_);
std::memcpy(data_ + bytes_stored, data, bytes); std::memcpy(data_ + bytes_stored, data, bytes);
bytes_stored += bytes; bytes_stored += bytes;
} }
@ -196,7 +196,7 @@ namespace blt::gp
BLT_ABORT(("Not enough bytes in stack to reference " + std::to_string(size) + " bytes requested but " + std::to_string(bytes) + BLT_ABORT(("Not enough bytes in stack to reference " + std::to_string(size) + " bytes requested but " + std::to_string(bytes) +
" bytes stored!").c_str()); " bytes stored!").c_str());
#endif #endif
return *reinterpret_cast<NO_REF*>(data_ + bytes_stored - size); return *reinterpret_cast<NO_REF*>(data_ + (bytes_stored - size));
} }
void pop_bytes(blt::size_t bytes) void pop_bytes(blt::size_t bytes)
@ -298,15 +298,15 @@ namespace blt::gp
void* allocate_bytes_for_size(blt::size_t bytes) void* allocate_bytes_for_size(blt::size_t bytes)
{ {
auto aligned_ptr = get_aligned_pointer(bytes); auto used_bytes = aligned_size(bytes);
auto aligned_ptr = get_aligned_pointer(used_bytes);
if (aligned_ptr == nullptr) if (aligned_ptr == nullptr)
{ {
expand(size_ + bytes); expand(size_ + used_bytes);
aligned_ptr = get_aligned_pointer(bytes); aligned_ptr = get_aligned_pointer(used_bytes);
} }
if (aligned_ptr == nullptr) if (aligned_ptr == nullptr)
throw std::bad_alloc(); throw std::bad_alloc();
auto used_bytes = aligned_size(bytes);
bytes_stored += used_bytes; bytes_stored += used_bytes;
return aligned_ptr; return aligned_ptr;
} }

View File

@ -135,8 +135,10 @@ namespace blt::gp
{ {
create_indent(out, indent, pretty_print); create_indent(out, indent, pretty_print);
if (program.is_static(v.id)) if (program.is_static(v.id))
{
program.get_print_func(v.id)(out, reversed); program.get_print_func(v.id)(out, reversed);
else reversed.pop_bytes(stack_allocator::aligned_size(v.type_size));
} else
out << name; out << name;
out << return_type << end_indent(pretty_print); out << return_type << end_indent(pretty_print);
} else } else