example.idl 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. -- There is no way to extend (subtype) an existing structure, or compose
  41. -- structures within structures. However, names may be repeated.
  42. (def-struct timed_coord_t
  43. (lat lat_t)
  44. (lon lon_t)
  45. (alt meters_t)
  46. (time time_micros_t))
  47. -------------------------------------------------------------------------------
  48. -- Interface language
  49. -------------------------------------------------------------------------------
  50. -- Here is an interface which defines a single stream named heartbeat.
  51. (def-interface vehicle_i ()
  52. (heartbeat (stream heartbeat_t)))
  53. -- Type definitions may be interspersed with interface definitions
  54. (def-enum light_mode_t
  55. (off 0)
  56. (blink_slow 1)
  57. (blink_fast 2)
  58. (on 3))
  59. -- Here is an interface which defines a single attribute. Attributes
  60. -- may be given read, write, or readwrite access.
  61. (def-interface light_i ()
  62. (light_mode (attr readwrite light_mode_t)))
  63. -- Interfaces may be extended (subtyped). No shadowing of method
  64. -- names permitted.
  65. -- This interface extends the vehicle_i and light_i interfaces,
  66. -- and defines two additional attributes.
  67. (def-interface controllable_vehicle_i (vehicle_i light_i)
  68. (current_waypoint (attr read coordinate_t))
  69. (next_waypoint (attr readwrite timed_coord_t)))