Small code improvements
60ca87f0184444e84bd693dcdcc18e8ef65b2020f5b190622f8ce3a4b3948242
1 parent
f5bdf05c
lib/std/lang/resolver.rad
+18 -10
| 779 | 779 | return &node.ty; |
|
| 780 | 780 | } |
|
| 781 | 781 | cursor = node.next; |
|
| 782 | 782 | } |
|
| 783 | 783 | // Allocate a new type node from the arena. |
|
| 784 | - | let p = try! alloc::alloc(&mut self.arena, @sizeOf(TypeNode), @alignOf(TypeNode)); |
|
| 785 | - | let node = p as *mut TypeNode; |
|
| 784 | + | let node = try! alloc::alloc( |
|
| 785 | + | &mut self.arena, @sizeOf(TypeNode), @alignOf(TypeNode) |
|
| 786 | + | ) as *mut TypeNode; |
|
| 786 | 787 | ||
| 787 | 788 | *node = TypeNode { ty, next: self.types }; |
|
| 788 | 789 | self.types = node; |
|
| 789 | 790 | ||
| 790 | 791 | return &node.ty; |
| 793 | 794 | /// Allocate a nominal type descriptor and return a pointer to it. |
|
| 794 | 795 | fn allocNominalType(self: *mut Resolver, info: NominalType) -> *mut NominalType { |
|
| 795 | 796 | // Nb. We don't attempt to de-duplicate nominal type entries, |
|
| 796 | 797 | // since they don't carry node information and we create |
|
| 797 | 798 | // placeholder entries when binding symbols. |
|
| 798 | - | let p = try! alloc::alloc(&mut self.arena, @sizeOf(NominalType), @alignOf(NominalType)); |
|
| 799 | - | let entry = p as *mut NominalType; |
|
| 799 | + | let entry = try! alloc::alloc( |
|
| 800 | + | &mut self.arena, @sizeOf(NominalType), @alignOf(NominalType) |
|
| 801 | + | ) as *mut NominalType; |
|
| 802 | + | ||
| 800 | 803 | *entry = info; |
|
| 801 | 804 | ||
| 802 | 805 | return entry; |
|
| 803 | 806 | } |
|
| 804 | 807 | ||
| 805 | 808 | /// Allocate a function type descriptor and return a pointer to it. |
|
| 806 | 809 | fn allocFnType(self: *mut Resolver, info: FnType) -> *FnType { |
|
| 807 | - | let p = try! alloc::alloc(&mut self.arena, @sizeOf(FnType), @alignOf(FnType)); |
|
| 808 | - | let entry = p as *mut FnType; |
|
| 810 | + | let entry = try! alloc::alloc( |
|
| 811 | + | &mut self.arena, @sizeOf(FnType), @alignOf(FnType) |
|
| 812 | + | ) as *mut FnType; |
|
| 813 | + | ||
| 809 | 814 | *entry = info; |
|
| 810 | 815 | ||
| 811 | 816 | return entry; |
|
| 812 | 817 | } |
|
| 813 | 818 |
| 846 | 851 | pub fn resolver( |
|
| 847 | 852 | storage: ResolverStorage, |
|
| 848 | 853 | config: Config |
|
| 849 | 854 | ) -> Resolver { |
|
| 850 | 855 | let mut arena = storage.arena; |
|
| 851 | - | let ptr = try! alloc::allocSlice(&mut arena, @sizeOf(*mut Symbol), @alignOf(*mut Symbol), MAX_MODULE_SYMBOLS); |
|
| 852 | - | let symbols = ptr as *mut [*mut Symbol]; |
|
| 856 | + | let symbols = try! alloc::allocSlice( |
|
| 857 | + | &mut arena, @sizeOf(*mut Symbol), @alignOf(*mut Symbol), MAX_MODULE_SYMBOLS |
|
| 858 | + | ) as *mut [*mut Symbol]; |
|
| 853 | 859 | ||
| 854 | 860 | // Initialize the root scope. |
|
| 855 | 861 | // TODO: Set this up when declaring `PKG_SCOPE`, not here. |
|
| 856 | 862 | *storage.pkgScope = Scope { |
|
| 857 | 863 | owner: nil, |
| 944 | 950 | assert owner.id < self.nodeData.entries.len, "allocScope: node ID out of bounds"; |
|
| 945 | 951 | let p = try! alloc::alloc(&mut self.arena, @sizeOf(Scope), @alignOf(Scope)); |
|
| 946 | 952 | let entry = p as *mut Scope; |
|
| 947 | 953 | ||
| 948 | 954 | // Allocate symbols from the arena. |
|
| 949 | - | let ptr = try! alloc::allocSlice(&mut self.arena, @sizeOf(*mut Symbol), @alignOf(*mut Symbol), capacity); |
|
| 950 | - | let symbols = ptr as *mut [*mut Symbol]; |
|
| 955 | + | let symbols = try! alloc::allocSlice( |
|
| 956 | + | &mut self.arena, @sizeOf(*mut Symbol), @alignOf(*mut Symbol), capacity |
|
| 957 | + | ) as *mut [*mut Symbol]; |
|
| 951 | 958 | ||
| 952 | 959 | *entry = Scope { owner, parent: nil, moduleId: nil, symbols, symbolsLen: 0 }; |
|
| 953 | 960 | self.nodeData.entries[owner.id].scope = entry; |
|
| 954 | 961 | ||
| 955 | 962 | return entry; |
| 972 | 979 | let scope = allocScope(self, owner, MAX_MODULE_SYMBOLS); |
|
| 973 | 980 | ||
| 974 | 981 | self.scope = scope; |
|
| 975 | 982 | self.scope.moduleId = module.id; |
|
| 976 | 983 | self.currentMod = module.id; |
|
| 984 | + | // TODO: Allow any unsigned integer to index an array. |
|
| 977 | 985 | self.moduleScopes[module.id as u32] = scope; |
|
| 978 | 986 | ||
| 979 | 987 | return ModuleScope { root: owner, entry: module, newScope: scope, prevScope, prevMod }; |
|
| 980 | 988 | } |
|
| 981 | 989 |