Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed Nov 7, 2024
1 parent 9c67a6a commit f4417f3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
16 changes: 16 additions & 0 deletions std/reflection.pr
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export type EnumT = &struct {
}

export type Function = struct {
short_name: StringSlice
name: StringSlice
exported: bool
module: StringSlice
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions std/std.pr
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit f4417f3

Please sign in to comment.