about summary refs log blame commit diff stats
path: root/src/js/typeptr.nim
blob: 55fd89c784365707bf6a15bec087ff18c8717055 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12











                                                                      
             




                                    
# Get a unique pointer for each type.
proc getTypePtr*[T](x: T): pointer =
  when T is RootRef:
    # I'm so sorry.
    # (This dereferences the object's first member, m_type. Probably.)
    return cast[ptr pointer](x)[]
  elif T is RootObj:
    return cast[pointer](x)
  else:
    return getTypeInfo(x)

func getTypePtr*(t: typedesc[ref object]): pointer =
  var x = t()
  return getTypePtr(x)

func getTypePtr*(t: type): pointer =
  var x: t
  return getTypePtr(x)