Skip to content

Commit 66a3807

Browse files
authored
Enable idiomatic record.pt syntax (#113)
* Enable idiomatic record.pt syntax * more getfield(layout, :array)
1 parent 1af9378 commit 66a3807

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

src/all_implementations.jl

+33-30
Original file line numberDiff line numberDiff line change
@@ -2090,14 +2090,16 @@ slot(
20902090

20912091
"""
20922092
Base.getindex(
2093-
layout::Record{FIELDS,CONTENTS},
2094-
f::Symbol,
2095-
) where {FIELDS,CONTENTS<:Base.Tuple{Vararg{Content}}}
2093+
layout::AwkwardArray.Record,
2094+
f::Symbol,
2095+
)
20962096
"""
20972097
Base.getindex(
2098-
layout::Record{FIELDS,CONTENTS},
2099-
f::Symbol,
2100-
) where {FIELDS,CONTENTS<:Base.Tuple{Vararg{Content}}} = layout.array.contents[f][layout.at]
2098+
layout::AwkwardArray.Record,
2099+
f::Symbol,
2100+
) = getfield(layout, :array).contents[f][getfield(layout, :at)]
2101+
2102+
Base.getproperty(layout::Record, f::Symbol) = layout[f]
21012103

21022104
"""
21032105
Base.:(==)(
@@ -2388,15 +2390,16 @@ end
23882390

23892391
"""
23902392
Base.getindex(
2391-
layout::SlotRecord{CONTENTS},
2393+
layout::SlotRecord,
23922394
f::Int64,
2393-
) where {CONTENTS<:Base.Tuple{Vararg{Content}}}
2395+
)
23942396
"""
23952397
Base.getindex(
2396-
layout::SlotRecord{CONTENTS},
2398+
layout::SlotRecord,
23972399
f::Int64,
2398-
) where {CONTENTS<:Base.Tuple{Vararg{Content}}} =
2399-
layout.array.contents[f][layout.at]
2400+
) = getfield(layout, :array).contents[f][getfield(layout, :at)]
2401+
2402+
Base.getproperty(layout::SlotRecord, f::Symbol) = layout[f]
24002403

24012404
"""
24022405
Base.:(==)(
@@ -2445,7 +2448,7 @@ function Base.:(==)(
24452448
CONTENTS1<:Base.Tuple{Vararg{Content,N}},
24462449
CONTENTS2<:Base.Tuple{Vararg{Content,N}},
24472450
}
2448-
for i in eachindex(layout1.array.contents) # same number of indexes by type constraint
2451+
for i in eachindex(getfield(layout1, :array).contents) # same number of indexes by type constraint
24492452
if layout1[i] != layout2[i] # compare tuple items
24502453
return false
24512454
end
@@ -4002,8 +4005,8 @@ Base.getindex(layout::UnionArray, f::Symbol) =
40024005
function Base.push!(special::Specialization, input)
40034006
tmp = length(special.tagged)
40044007
push!(special.tagged, input)
4005-
push!(special.array.tags, special.tag - firstindex(special.array.contents))
4006-
push!(special.array.index, tmp)
4008+
push!(getfield(special, :array).tags, special.tag - firstindex(getfield(special, :array).contents))
4009+
push!(getfield(special, :array).index, tmp)
40074010
special
40084011
end
40094012

@@ -4023,8 +4026,8 @@ end
40234026
function end_list!(special::Specialization)
40244027
tmp = length(special.tagged)
40254028
end_list!(special.tagged)
4026-
push!(special.array.tags, special.tag - firstindex(special.array.contents))
4027-
push!(special.array.index, tmp)
4029+
push!(getfield(special, :array).tags, special.tag - firstindex(getfield(special, :array).contents))
4030+
push!(getfield(special, :array).index, tmp)
40284031
special
40294032
end
40304033

@@ -4034,8 +4037,8 @@ end
40344037
function end_record!(special::Specialization)
40354038
tmp = length(special.tagged)
40364039
end_record!(special.tagged)
4037-
push!(special.array.tags, special.tag - firstindex(special.array.contents))
4038-
push!(special.array.index, tmp)
4040+
push!(getfield(special, :array).tags, special.tag - firstindex(getfield(special, :array).contents))
4041+
push!(getfield(special, :array).index, tmp)
40394042
special
40404043
end
40414044

@@ -4045,8 +4048,8 @@ end
40454048
function end_tuple!(special::Specialization)
40464049
tmp = length(special.tagged)
40474050
end_tuple!(special.tagged)
4048-
push!(special.array.tags, special.tag - firstindex(special.array.contents))
4049-
push!(special.array.index, tmp)
4051+
push!(getfield(special, :array).tags, special.tag - firstindex(getfield(special, :array).contents))
4052+
push!(getfield(special, :array).index, tmp)
40504053
special
40514054
end
40524055

@@ -4060,8 +4063,8 @@ function push_null!(
40604063
) where {ARRAY<:UnionArray,TAGGED<:OptionType}
40614064
tmp = length(special.tagged)
40624065
push_null!(special.tagged)
4063-
push!(special.array.tags, special.tag - firstindex(special.array.contents))
4064-
push!(special.array.index, tmp)
4066+
push!(getfield(special, :array).tags, special.tag - firstindex(getfield(special, :array).contents))
4067+
push!(getfield(special, :array).index, tmp)
40654068
special
40664069
end
40674070

@@ -4071,8 +4074,8 @@ end
40714074
function push_dummy!(special::Specialization)
40724075
tmp = length(special.tagged)
40734076
push_dummy!(special.tagged)
4074-
push!(special.array.tags, special.tag - firstindex(special.array.contents))
4075-
push!(special.array.index, tmp)
4077+
push!(getfield(special, :array).tags, special.tag - firstindex(getfield(special, :array).contents))
4078+
push!(getfield(special, :array).index, tmp)
40764079
special
40774080
end
40784081

@@ -4236,7 +4239,7 @@ to_vector(
42364239
view::Bool = false,
42374240
na::Union{Missing,Nothing} = missing,
42384241
) where {FIELDS,CONTENTS<:Base.Tuple{Vararg{Content}}} = NamedTuple{FIELDS}(
4239-
to_vector_or_scalar(record.array.contents[f][record.at], view = view, na = na) for
4242+
to_vector_or_scalar(getfield(record, :array).contents[f][record.at], view = view, na = na) for
42404243
f in FIELDS
42414244
)
42424245

@@ -4253,7 +4256,7 @@ to_vector(
42534256
na::Union{Missing,Nothing} = missing,
42544257
) where {CONTENTS<:Base.Tuple{Vararg{Content}}} = Base.Tuple(
42554258
to_vector_or_scalar(content[record.at], view = view, na = na) for
4256-
content in tuple.array.contents
4259+
content in getfield(tuple, :array).contents
42574260
)
42584261

42594262
"""
@@ -4731,7 +4734,7 @@ function _horizontal(data::Any, limit_cols::Int)
47314734
limit_cols -= 5 # anticipate the ", ..."
47324735

47334736
which = 0
4734-
fields = keys(data.array.contents)
4737+
fields = keys(getfield(data, :array).contents)
47354738
for field in fields
47364739
key = Base.string(field)
47374740

@@ -4798,7 +4801,7 @@ function _horizontal(data::Any, limit_cols::Int)
47984801
limit_cols -= 5 # anticipate the ", ..."
47994802

48004803
which = 0
4801-
fields = eachindex(data.array.contents)
4804+
fields = eachindex(getfield(data, :array).contents)
48024805
for field in fields
48034806
if which == 0
48044807
for_comma = 0
@@ -4916,7 +4919,7 @@ function _vertical(data::Union{Content,Record,Tuple}, limit_rows::Int, limit_col
49164919
front = Vector{String}([]) # 1-indexed
49174920

49184921
which = 0
4919-
fields = keys(data.array.contents)
4922+
fields = keys(getfield(data, :array).contents)
49204923
for field in fields
49214924
key = Base.string(field)
49224925
if occursin(r"^[A-Za-z_][A-Za-z_0-9]*$", key)
@@ -4957,7 +4960,7 @@ function _vertical(data::Union{Content,Record,Tuple}, limit_rows::Int, limit_col
49574960
front = Vector{String}([]) # 1-indexed
49584961

49594962
which = 0
4960-
fields = eachindex(data.array.contents)
4963+
fields = eachindex(getfield(data, :array).contents)
49614964
for field in fields
49624965
(_, strs) = _horizontal(data[field], limit_cols - 2)
49634966
push!(front, join(strs, ""))

0 commit comments

Comments
 (0)