Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed Nov 9, 2024
1 parent 9c67a6a commit 633ca38
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
18 changes: 17 additions & 1 deletion 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 @@ -247,7 +261,7 @@ def load_types(input: *uint8, size: size_t, num: size_t, strings: *char) {
case TypeKind::STRUCT, TypeKind::UNION
let size = fp.read(int)
let align = fp.read(int)
let fields = zero_allocate(Field, fp.read(int))
let fields = allocate_ref(Field, fp.read(int))

printf("\tsize: %zu align: %zu fields: %zu\n".value, size, align, fields.size)

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 633ca38

Please sign in to comment.