testtypes.sexpr 2.2 KB

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