Skip to content

Commit

Permalink
unordered_map works in both backends now
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaztahir committed Feb 9, 2025
1 parent 68d87ab commit 59770a2
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ast/base/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ bool Value::requires_memcpy_ref_struct(BaseType* known_type) {
const auto chain = as_access_chain_unsafe();
const auto id = as_identifier_unsafe();
if(kind == ValueKind::Identifier || (kind == ValueKind::AccessChain && chain->values.back()->as_func_call() == nullptr)) {
auto linked = known_type->get_direct_linked_node();
auto linked = known_type->get_ref_or_linked_node(known_type->kind());
if (linked) {
auto k = linked->kind();
if(k == ASTNodeKind::UnnamedStruct || k == ASTNodeKind::UnnamedUnion) {
Expand Down
2 changes: 1 addition & 1 deletion ast/statements/VarInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void VarInitStatement::code_gen(Codegen &gen) {
if(!dyn_obj_impl) {
auto llvmType = llvm_type(gen);
// is referencing another struct, that is non movable and must be mem copied into the pointer
llvm_ptr = gen.memcpy_ref_struct(known_type(), value, nullptr, llvmType);
llvm_ptr = gen.memcpy_ref_struct(create_value_type(gen.allocator), value, nullptr, llvmType);
if (llvm_ptr) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/backend/LLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ bool Codegen::requires_memcpy_ref_struct(BaseType* known_type, Value* value) {

llvm::Value* Codegen::memcpy_ref_struct(BaseType* known_type, Value* value, llvm::Value* llvm_ptr, llvm::Type* type) {
// const auto pure = known_type->pure_type();
if(requires_memcpy_ref_struct(known_type, value)) {
if(requires_memcpy_ref_struct(known_type->pure_type(allocator), value)) {
if(!llvm_ptr) {
llvm_ptr = builder->CreateAlloca(type, nullptr);
}
Expand Down
2 changes: 1 addition & 1 deletion lang/libs/std/unordered_map.ch
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct unordered_map<Key, Value> {
}

// Insert the new node at the front of the chain
var newNode = malloc(sizeof(unordered_map_node<Key, Value>)) as *mut unordered_map_node<Key, Value>;
const newNode = malloc(sizeof(unordered_map_node<Key, Value>)) as *mut unordered_map_node<Key, Value>;
newNode.key = key;
newNode.value = value;
newNode.next = table[index];
Expand Down

0 comments on commit 59770a2

Please sign in to comment.