Skip to content

Commit

Permalink
Complete merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed May 6, 2024
1 parent 5af28c1 commit 60ae1ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
18 changes: 15 additions & 3 deletions src/compiler.pr
Original file line number Diff line number Diff line change
Expand Up @@ -8308,8 +8308,20 @@ def create_destructor(tpe: &typechecking::Type, value: Value, state: &State) {
if typechecking::is_ref(tpe.tpe) and tpe.tpe.tpe and not is_interface(tpe.tpe.tpe) {
// Decrease ref count
_ref = state.load(tpe.tpe, value)
ref_count = state.extract_value(pointer(ref_meta), ref, [0])
let ref_count_ptr = state.gep(pointer(builtins::int64_), ref_meta, ref_count, [make_int_value(0), make_int_value(0)])
ref_count = state.extract_value(pointer(ref_meta()), _ref, [0])
let ref_count_value1 = state.ptr_to_int(ref_count)

let isnull = state.icmp(CompareInt::eq, ref_count_value1,
[ kind = ValueKind::INT, tpe = builtins::int64_, i = 0 ] !Value)

br1 = make_insn(InsnKind::BR)
br1.value.br = [ cond = isnull ] !InsnBr
push_insn(br1, state)
let nonnull = make_label(state)
push_label(nonnull, state)
br1.value.br.if_false = nonnull

let ref_count_ptr = state.gep(pointer(builtins::int64_), ref_meta(), ref_count, [make_int_value(0), make_int_value(0)])
let ref_count_value = state.ptr_to_int(ref_count_ptr)
let null_cond = state.icmp(CompareInt::eq, ref_count_value, [ kind = ValueKind::INT, tpe = builtins::int64_, i = 0 ] !Value)
null_br = make_insn(InsnKind::BR)
Expand Down Expand Up @@ -8401,7 +8413,7 @@ def create_destructor(tpe: &typechecking::Type, value: Value, state: &State) {
let _ref = state.load(tpe.tpe, value)

// Extract type
let ref_count = state.extract_value(pointer(builtins::int64_), ref, [0])
let ref_count = state.extract_value(pointer(builtins::int64_), _ref, [0])
let ref_count_value = state.ptr_to_int(ref_count)
let cond = state.icmp(CompareInt::eq, ref_count_value, [ kind = ValueKind::INT, tpe = builtins::int64_, i = 0 ] !Value)
null_br2 = make_insn(InsnKind::BR)
Expand Down
6 changes: 3 additions & 3 deletions src/consteval.pr
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,10 @@ export def walk_Def(node: &parser::Node, state: &typechecking::State) {
let type_constructor = typechecking::get_type_constructor(first_param.tpe)
if type_constructor and type_constructor.cache {
let type_name = debug::type_to_str(first_param.tpe, full_name = true)
let ref = [module = state.get_context(), name = type_name] !typechecking::TypeRef
if not map::contains(type_constructor.cache, ref) {
let _ref = [module = state.get_context(), name = type_name] !typechecking::TypeRef
if not map::contains(type_constructor.cache, _ref) {
typechecking::generate_concrete_functions(type_constructor, first_param.tpe, state)
type_constructor.cache(ref) = first_param.tpe
type_constructor.cache(_ref) = first_param.tpe
}
}
}
Expand Down

0 comments on commit 60ae1ce

Please sign in to comment.