import strformat

var
  swizzles = @["xyzw", "rgba", "stpq"]
  code = ""

code.add "# Generated by tools/gensswizzle - don't edit manually.\n"

for swizzle in swizzles[1 .. ^1]:
  code.add "\n# 1 x " & swizzle & "\n"
  for i1, s1 in swizzle:
    code.add &"proc {s1}*[T](a: GVec234[T]): T = a[{i1}]\n"
  for i1, s1 in swizzle:
    code.add &"proc `{s1}=`*[T](a: var GVec234[T], b: T) = a[{i1}] = b\n"

for swizzle in swizzles:
  code.add "\n# 2 x " & swizzle & "\n"
  for i1, s1 in swizzle:
    for i2, s2 in swizzle:
      code.add &"proc {s1}{s2}*[T](a: GVec234[T]): GVec2[T] = gvec2(a[{i1}], a[{i2}])\n"
  for i1, s1 in swizzle:
    for i2, s2 in swizzle:
      code.add &"proc `{s1}{s2}=`*[T](a: var GVec234[T], b: GVec2[T]) = (let b = b; a[{i1}] = b.x; a[{i2}] = b.y)\n"

for swizzle in swizzles:
  code.add "\n# 3 x " & swizzle & "\n"
  for i1, s1 in swizzle:
    for i2, s2 in swizzle:
      for i3, s3 in swizzle:
        code.add &"proc {s1}{s2}{s3}*[T](a: GVec234[T]): GVec3[T] = gvec3(a[{i1}], a[{i2}], a[{i3}])\n"
  for i1, s1 in swizzle:
    for i2, s2 in swizzle:
      for i3, s3 in swizzle:
        code.add &"proc `{s1}{s2}{s3}=`*[T](a: var GVec234[T], b: GVec3[T]) = (let b = b; a[{i1}] = b.x; a[{i2}] = b.y; a[{i3}] = b.z)\n"

for swizzle in swizzles:
  code.add "\n# 4 x " & swizzle & "\n"
  for i1, s1 in swizzle:
    for i2, s2 in swizzle:
      for i3, s3 in swizzle:
        for i4, s4 in swizzle:
          code.add &"proc {s1}{s2}{s3}{s4}*[T](a: GVec234[T]): GVec4[T] = gvec4(a[{i1}], a[{i2}], a[{i3}], a[{i4}])\n"
  for i1, s1 in swizzle:
    for i2, s2 in swizzle:
      for i3, s3 in swizzle:
        for i4, s4 in swizzle:
          code.add &"proc `{s1}{s2}{s3}{s4}=`*[T](a: var GVec234[T], b: GVec4[T]) = (let b = b; a[{i1}] = b.x; a[{i2}] = b.y; a[{i3}] = b.z; a[{i4}] = b.w)\n"

writeFile("src/vmath/swizzle.nim", code)
