example.idl 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 32 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. (def-enum (armed_t 8)
  23. (disarmed 0)
  24. (armed 1))
  25. -- Structures are a set of pairs of names and types. All
  26. -- names must be distinct. All types must be atomic, enum,
  27. -- or newtypes.
  28. (def-struct heartbeat_t
  29. (time time_micros_t)
  30. (armed armed_t))
  31. -- Definitions may be out of order. Circular definitions
  32. -- are not permitted.
  33. (def-struct coordinate_t
  34. (lat lat_t)
  35. (lon lon_t)
  36. (alt meters_t))
  37. (def-newtype lat_t sint32_t)
  38. (def-newtype lon_t sint32_t)
  39. (def-newtype meters_t float_t)
  40. -- Structures may contain structures.
  41. (def-struct timed_coord_t
  42. (coord coordinate_t)
  43. (time time_micros_t))
  44. -------------------------------------------------------------------------------
  45. -- Interface language
  46. -------------------------------------------------------------------------------
  47. -- Here is an interface which defines a single stream named heartbeat.
  48. (def-interface vehicle_i ()
  49. (heartbeat (stream heartbeat_t)))
  50. -- Type definitions may be interspersed with interface definitions
  51. (def-enum light_mode_t
  52. (off 0)
  53. (blink_slow 1)
  54. (blink_fast 2)
  55. (on 3))
  56. -- Here is an interface which defines a single attribute. Attributes
  57. -- may be given read, write, or readwrite access.
  58. (def-interface light_i ()
  59. (light_mode (attr readwrite light_mode_t)))
  60. -- Interfaces may be extended (subtyped). No shadowing of method
  61. -- names permitted.
  62. -- This interface extends the vehicle_i and light_i interfaces,
  63. -- and defines two additional attributes.
  64. (def-interface controllable_vehicle_i (vehicle_i light_i)
  65. (current_waypoint (attr read coordinate_t))
  66. (next_waypoint (attr readwrite timed_coord_t)))