example.idl 2.6 KB

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