From f4417f3426ce57fb51bace0a07aa218a2a85afd3 Mon Sep 17 00:00:00 2001 From: Vic Nightfall Date: Wed, 23 Oct 2024 11:27:52 +0200 Subject: [PATCH] Some fixes --- std/reflection.pr | 16 ++++++++++++++++ std/std.pr | 11 ++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/std/reflection.pr b/std/reflection.pr index 1f50902..f062dc5 100644 --- a/std/reflection.pr +++ b/std/reflection.pr @@ -149,6 +149,7 @@ export type EnumT = &struct { } export type Function = struct { + short_name: StringSlice name: StringSlice exported: bool module: StringSlice @@ -207,6 +208,19 @@ var types: &Map(uint64, Type) load_types(__reflection_data, @__reflection_data_size, @__reflection_num_types, __reflection_strings) +import runtime + +for var id in @types.keys() { + + var r: runtime::Ref + if true { + let tpe = types(id) + printf("%s: ".value, tpe.name.data ++ tpe.name.offset) + r = tpe !runtime::Ref + } + printf("%zu %zu\n".value, r.ref_count.strong_cnt, r.ref_count.weak_cnt) +} + // Type registry functions def load_types(input: *uint8, size: size_t, num: size_t, strings: *char) { var data: [uint8] @@ -341,12 +355,14 @@ def load_types(input: *uint8, size: size_t, num: size_t, strings: *char) { base.type_members = allocate_ref(type Function, nmembers) for var i in 0..nmembers { let name = make_slice(strings, fp.read(int)) + let short_name = make_slice(strings, fp.read(int)) let exported = fp.read(bool) let module = make_slice(strings, fp.read(int)) printf("\t%s %d %s\n".value, name.data ++ name.offset, exported, module.data ++ module.offset) let member = [ + short_name = short_name, name = name, exported = exported, module = module diff --git a/std/std.pr b/std/std.pr index adb80d1..8c91716 100644 --- a/std/std.pr +++ b/std/std.pr @@ -356,8 +356,9 @@ def print_val(file: File, value: *, tpe: reflection::Type) -> int { } else if tpe.type == reflection::PointerT { return cstd::fprintf(file, "%p".value, value) } else if tpe.type == reflection::ReferenceT { - let ptr = value !& !* - return cstd::fprintf(file, "%p".value, ptr) + let ref_tpe = tpe !reflection::ReferenceT + let ptr = @(value !*&) + return print_val(file, ptr !*, ref_tpe.tpe) } else if tpe.type == reflection::ArrayT { let arr_t = tpe !reflection::ArrayT let arr = @(value !*[int8]) @@ -426,10 +427,10 @@ def print_val(file: File, value: *, tpe: reflection::Type) -> int { export def fprint(file: File, args: &...) -> int { var sum = 0 for var i in 0..args.size { - let arg = args(i) - let ref_tpe = arg.type !ReferenceT + let arg = *args(i) + let ref_tpe = args(i).type !ReferenceT if ref_tpe { - sum += print_val(file, arg !*, ref_tpe.tpe) + sum += print_val(file, arg !*, ref_tpe) } else { sum += cstd::fprintf(file, "null".value) }