Advertisement
tinyevil

Untitled

Feb 18th, 2019
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. // Motivation #1
  2. // Hiding some stuff from accidental access
  3. public region debug;
  4. public region deprecated;
  5.  
  6. struct IRBuilder {
  7. ...
  8.  
  9. // this variable is only relevant for debugging
  10. // so it is either must be used by a function within the debug region,
  11. // or the user must explicitly opt-in with the debug:: prefix
  12. // (or 'use region debug')
  13. var debug::instr_count: i32 = 0;
  14. }
  15.  
  16. implementation IRBuilder {
  17.  
  18. method create_phi(self: IRBuilder, bracnhes: i32): PHINode {
  19. ...
  20. }
  21.  
  22. // you cannot use a deprecated function unless you are deprecated yourself,
  23. // or opt in
  24. method deprecated::create_phi(self: IRBuilder): PHINode {
  25. ...
  26. }
  27.  
  28. method debug::print_next_name(self: IRBuilder) {
  29. ...
  30. }
  31.  
  32. method debug::print_instr_count(self: IRBuilder) {
  33. ...
  34. }
  35.  
  36. }
  37.  
  38.  
  39. // Motivation #2
  40. // API versioning
  41.  
  42. public region v1;
  43. public region v2 (v1);
  44. public region v3 (v2);
  45. public region v4 (v3);
  46.  
  47. // we can use the version tag for function selection:
  48. function v4::connect();
  49. function v3::connect();
  50. function v1::connect();
  51.  
  52. function client() {
  53. use region v3;
  54. connect(); // selects v3::connect, even when v4 or v5 arrives
  55. }
  56.  
  57. // cannot accidently use a newer version if didn't opted in for it:
  58. function v4::new_stuff_added_in_4();
  59.  
  60. function i_use_old_one() {
  61. use region v2;
  62. new_stuff_added_in_4(); // fail
  63. }
  64.  
  65.  
  66. // other useful semantical tagging (unsafe, throws, blocking...)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement