Skip to content

Commit 7891157

Browse files
committed
Print field / argument info more compactly
1 parent 4993dea commit 7891157

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

contrib/juliac/abi_export.jl

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,12 @@ end
8282
function emit_field_info!(ctx::TypeEmitter, @nospecialize(dt::DataType), field::Int; indent::Int = 0)
8383
desc = Base.DataTypeFieldDesc(dt)[field]
8484
type_id = ctx.type_ids[fieldtype(dt, field)]
85-
let indented_println(args...) = println(ctx.io, " " ^ indent, args...)
86-
indented_println("{")
87-
indented_println(" \"name\": ", field_name_json(dt, field), ",")
88-
indented_println(" \"offset\": ", desc.offset, ",")
89-
indented_println(" \"type\": ", type_id)
90-
print(ctx.io, " " ^ indent, "}")
91-
end
85+
print(ctx.io, " " ^ indent)
86+
print(ctx.io, "{")
87+
print(ctx.io, " \"name\": ", field_name_json(dt, field), ",")
88+
print(ctx.io, " \"type\": ", type_id, ",")
89+
print(ctx.io, " \"offset\": ", desc.offset)
90+
print(ctx.io, " }")
9291
end
9392

9493
function emit_struct_info!(ctx::TypeEmitter, @nospecialize(dt::DataType); indent::Int = 0)
@@ -157,15 +156,14 @@ function emit_method_info!(ctx::TypeEmitter, method::Core.Method; indent::Int =
157156
indented_println(" \"name\": ", escape_string_json(name), ",")
158157
indented_println(" \"arguments\": [")
159158
for i in 2:length(sig.parameters)
160-
indented_println(" {")
161-
indented_println(" \"name\": ", escape_string_json(argnames[i]), ",")
162-
indented_println(" \"type\": ", ctx.type_ids[sig.parameters[i]])
163-
indented_println(" }", i == length(sig.parameters) ? "" : ",")
159+
print(ctx.io, " " ^ (indent + 4))
160+
print(ctx.io, "{")
161+
print(ctx.io, " \"name\": ", escape_string_json(argnames[i]), ",")
162+
print(ctx.io, " \"type\": ", ctx.type_ids[sig.parameters[i]])
163+
println(ctx.io, i == length(sig.parameters) ? " }" : " },")
164164
end
165165
indented_println(" ],")
166-
indented_println(" \"returns\": {")
167-
indented_println(" \"type\": ", ctx.type_ids[rt])
168-
indented_println(" }")
166+
indented_println(" \"returns\": { \"type\": ", ctx.type_ids[rt], " }")
169167
print(ctx.io, " " ^ indent, "}")
170168
end
171169
end

0 commit comments

Comments
 (0)