testtypes.sexpr 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. (def-newtype time_micros_t sint64_t)
  2. -- comments should be haskell style, because we're suing parsec's haskell lexer
  3. (def-enum armed_t
  4. ((disarmed 0)
  5. (armed 1)))
  6. (def-struct heartbeat_t
  7. ((time time_micros_t)
  8. (armed armed_t)))
  9. (def-newtype lat_t sint32_t)
  10. (def-newtype lon_t sint32_t)
  11. -- Todo: allow attaching unit annotations to newtypes. The code generator will
  12. -- provide the units as a human readable comment, and/or in some type/unit
  13. -- system supported by the host language.
  14. -- Todo: allow attaching predicates to newtypes. e.g., lon_t might have some
  15. -- type (degrees * 10e-6), some predicate
  16. -- (lambda (v) (and (gt v -180000000) (lte v 180000000)))
  17. (def-newtype meters_t float_t)
  18. (def-struct coordinate_t
  19. ((lat lat_t)
  20. (lon lon_t)
  21. (alt meters_t)))
  22. (def-newtype waypoint_t coordinate_t)
  23. -- Todo: the following interface syntax and semantics are a strawman.
  24. -- Interfaces have methods that are either streams or attrs.
  25. -- attrs take a parameter for access control.
  26. -- streams take a parameter for their default period in hz (none should default
  27. -- to zero). they also implicitly define an attr $(steamname)-stream-rate,
  28. -- which permits changing the stream rate at runtime.
  29. (def-interface vehicle
  30. ((heartbeat (stream 10 heartbeat_t))))
  31. -- Interfaces implement java-style inheritance. No shadowing of inherited method
  32. -- names permitted.
  33. (def-interface controllable-vehicle
  34. ((current_waypoint (attr read waypoint_t))
  35. (next_waypoint (attr readwrite waypoint_t)))
  36. (vehicle)) -- Inherits from interface vehicle
  37. -- The idea here is that, when negotiating a gidl connection, the client can
  38. -- specify or negotiate what interface is supported.
  39. -- this may be communicated by just sending the string name, or potentially by
  40. -- sending the entire serialized schema. At very least, the client and server
  41. -- should check agreement of their type schemas, probably by having the client
  42. -- send a sha1-hash of the serialized type schema.
  43. -- This allows us to specify various kinds of vehicles might exist without
  44. -- repeating ourselves, and provides a way to
  45. -- manage new functionality without breaking legacy code.