Skip to content

Commit

Permalink
mirtypes: make field/param count query clearer
Browse files Browse the repository at this point in the history
Use a template to make clear what `a.b - a.b` is supposed to mean.
  • Loading branch information
zerbina committed Jul 24, 2024
1 parent 804c307 commit b56dd21
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions compiler/mir/mirtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ func isEqual(env: TypeEnv, a, b: TypeHeader): bool =
return false
result = true

template fieldCount(t: TypeHeader): uint32 =
t.b - t.a # also valid for procedure types

case a.kind
of tkVoid, tkBool, tkChar, tkPointer, tkString, tkCstring:
true
Expand All @@ -229,13 +232,13 @@ func isEqual(env: TypeEnv, a, b: TypeHeader): bool =
of tkArray:
a.a == b.a and a.b == b.b
of tkRecord, tkUnion, tkTaggedUnion:
if a.b - a.a == b.b - b.a: # same number of fields?
isEqual(env.fields, a.a, b.a, a.b - a.a)
if fieldCount(a) == fieldCount(b): # same number of fields?
isEqual(env.fields, a.a, b.a, fieldCount(a))
else:
false
of tkProc, tkClosure:
if a.b - a.a == b.b - b.a: # same number of params?
isEqual(env.params, a.a, b.a, a.b - a.a)
if fieldCount(a) == fieldCount(b): # same number of params?
isEqual(env.params, a.a, b.a, fieldCount(a))
else:
false

Expand Down

0 comments on commit b56dd21

Please sign in to comment.