tmisc_vm.nim 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. discard """
  2. output: '''[127, 127, 0, 255]
  3. [127, 127, 0, 255]
  4. '''
  5. nimout: '''caught Exception'''
  6. """
  7. #bug #1009
  8. type
  9. TAggRgba8* = array[4, byte]
  10. template R*(self: TAggRgba8): byte = self[0]
  11. template G*(self: TAggRgba8): byte = self[1]
  12. template B*(self: TAggRgba8): byte = self[2]
  13. template A*(self: TAggRgba8): byte = self[3]
  14. template `R=`*(self: TAggRgba8, val: byte) =
  15. self[0] = val
  16. template `G=`*(self: TAggRgba8, val: byte) =
  17. self[1] = val
  18. template `B=`*(self: TAggRgba8, val: byte) =
  19. self[2] = val
  20. template `A=`*(self: TAggRgba8, val: byte) =
  21. self[3] = val
  22. proc ABGR*(val: int| int64): TAggRgba8 =
  23. var V = val
  24. result.R = byte(V and 0xFF)
  25. V = V shr 8
  26. result.G = byte(V and 0xFF)
  27. V = V shr 8
  28. result.B = byte(V and 0xFF)
  29. result.A = byte((V shr 8) and 0xFF)
  30. const
  31. c1 = ABGR(0xFF007F7F)
  32. echo ABGR(0xFF007F7F).repr, c1.repr
  33. # bug 8740
  34. static:
  35. try:
  36. raise newException(ValueError, "foo")
  37. except Exception:
  38. echo "caught Exception"
  39. except Defect:
  40. echo "caught Defect"
  41. except ValueError:
  42. echo "caught ValueError"