Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Motivation #1
- // Hiding some stuff from accidental access
- public region debug;
- public region deprecated;
- struct IRBuilder {
- ...
- // this variable is only relevant for debugging
- // so it is either must be used by a function within the debug region,
- // or the user must explicitly opt-in with the debug:: prefix
- // (or 'use region debug')
- var debug::instr_count: i32 = 0;
- }
- implementation IRBuilder {
- method create_phi(self: IRBuilder, bracnhes: i32): PHINode {
- ...
- }
- // you cannot use a deprecated function unless you are deprecated yourself,
- // or opt in
- method deprecated::create_phi(self: IRBuilder): PHINode {
- ...
- }
- method debug::print_next_name(self: IRBuilder) {
- ...
- }
- method debug::print_instr_count(self: IRBuilder) {
- ...
- }
- }
- // Motivation #2
- // API versioning
- public region v1;
- public region v2 (v1);
- public region v3 (v2);
- public region v4 (v3);
- // we can use the version tag for function selection:
- function v4::connect();
- function v3::connect();
- function v1::connect();
- function client() {
- use region v3;
- connect(); // selects v3::connect, even when v4 or v5 arrives
- }
- // cannot accidently use a newer version if didn't opted in for it:
- function v4::new_stuff_added_in_4();
- function i_use_old_one() {
- use region v2;
- new_stuff_added_in_4(); // fail
- }
- // other useful semantical tagging (unsafe, throws, blocking...)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement