example.gidl 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. -- An example gidl IDL.
  2. -- Line comments are haskell style.
  3. {- Block comments are haskell style, as well. -}
  4. -------------------------------------------------------------------------------
  5. -- Type language
  6. -------------------------------------------------------------------------------
  7. -- All types end with a _t suffix in gidl syntax. Code generators may elect to
  8. -- drop the _t suffix when generating type definitions.
  9. -- Newtype definitions create a distinct type by wrapping an existing atomic,
  10. -- enum, or newtype.
  11. (def-newtype time_micros_t sint64_t)
  12. -- Enums are pairs of names and integer values. Must be a one-to-one
  13. -- mapping: names are not repeated, values are not repeated.
  14. -- Enums default to 8 bit width if you don't really care.
  15. -- N.B. we should probably change it to default to the smallest
  16. -- width that fits the values the user declared.
  17. (def-enum mode_t
  18. (stabilize 0)
  19. (auto 1))
  20. -- The user can specify a bit width for enums with the
  21. -- following syntax. 8, 16, 32, 64 bit widths are valid.
  22. -- Integer literals can use any haskell integer literal format
  23. (def-enum (armed_t 32)
  24. (disarmed 0)
  25. (armed 0x80000000))
  26. -- Structures are a set of pairs of names and types. All
  27. -- names must be distinct. All types must be atomic, enum,
  28. -- or newtypes.
  29. (def-struct heartbeat_t
  30. (time time_micros_t)
  31. (armed armed_t)
  32. (err bool_t))
  33. -- Definitions may be out of order. Circular definitions
  34. -- are not permitted.
  35. (def-struct coordinate_t
  36. (lat lat_t)
  37. (lon lon_t)
  38. (alt meters_t))
  39. (def-newtype lat_t sint32_t)
  40. (def-newtype lon_t sint32_t)
  41. (def-newtype meters_t float_t)
  42. -- Structures may contain structures.
  43. (def-struct timed_coord_t
  44. (coord coordinate_t)
  45. (time time_micros_t))
  46. -------------------------------------------------------------------------------
  47. -- Interface language
  48. -------------------------------------------------------------------------------
  49. -- Here is an interface which defines a single stream named heartbeat.
  50. (def-interface vehicle_i ()
  51. (heartbeat (stream heartbeat_t)))
  52. -- Type definitions may be interspersed with interface definitions
  53. (def-enum light_mode_t
  54. (off 0)
  55. (blink_slow 1)
  56. (blink_fast 2)
  57. (on 3))
  58. -- Here is an interface which defines a single attribute. Attributes
  59. -- may be given read, write, or readwrite access.
  60. (def-interface light_i ()
  61. (light_mode (attr readwrite light_mode_t)))
  62. -- Interfaces may be extended (subtyped). No shadowing of method
  63. -- names permitted.
  64. -- This interface extends the vehicle_i and light_i interfaces,
  65. -- and defines two additional attributes.
  66. (def-interface controllable_vehicle_i (vehicle_i light_i)
  67. (current_waypoint (attr read coordinate_t))
  68. (next_waypoint (attr readwrite timed_coord_t)))