22
33use std:: collections:: { HashMap , HashSet } ;
44
5+ use compiler_global_scope:: key:: EntryKey ;
56use compiler_typing:: tree:: Type ;
6- use compiler_utils:: { hash:: SelfHash , utils :: indexed :: IndexStorage } ;
7+ use compiler_utils:: hash:: SelfHash ;
78use diagnostics:: {
89 DiagnosticResult , DiagnosticSpanOrigin ,
9- builders:: { make_cannot_find_func , make_cannot_find_var, make_doesnt_exist_in_era} ,
10+ builders:: { make_cannot_find_var, make_doesnt_exist_in_era} ,
1011} ;
1112
12- use crate :: { nodes:: HIRNode , scope:: HIRGlobalScopeStorage , structs :: HIRStructContainer } ;
13+ use crate :: { nodes:: HIRNode , scope:: HIRGlobalScopeStorage } ;
1314
1415pub type HIRFunction = ( Option < Type > , Vec < ( u64 , Type ) > , String ) ;
1516pub type HIRFunctionImpl = ( HIRBranchedContext , Box < HIRNode > ) ;
@@ -274,11 +275,6 @@ pub struct HIRBranchedVariable {
274275
275276#[ derive( Debug ) ]
276277pub struct HIRContext {
277- pub functions : IndexStorage < HIRFunction > ,
278- pub function_declarations : Vec < Option < Box < HIRNode > > > ,
279- pub function_contexts : Vec < Option < HIRBranchedContext > > ,
280- pub static_variables : IndexStorage < Type > ,
281- pub struct_func_impls : HashMap < usize , HIRStructContainer > ,
282278 pub global_scope : HIRGlobalScopeStorage ,
283279}
284280
@@ -291,25 +287,9 @@ pub enum VariableKind {
291287impl HIRContext {
292288 pub fn new ( ) -> Self {
293289 return HIRContext {
294- functions : IndexStorage :: new ( ) ,
295- static_variables : IndexStorage :: new ( ) ,
296- function_contexts : vec ! [ ] ,
297- function_declarations : vec ! [ ] ,
298- struct_func_impls : HashMap :: new ( ) ,
299290 global_scope : HIRGlobalScopeStorage :: new ( ) ,
300291 } ;
301292 }
302-
303- pub fn translate_function < K : DiagnosticSpanOrigin > (
304- & self ,
305- func_hash : u64 ,
306- origin : & K ,
307- ) -> DiagnosticResult < usize > {
308- return match self . functions . get_index ( func_hash) {
309- Some ( v) => Ok ( v) ,
310- None => return Err ( make_cannot_find_func ( origin, & func_hash) . into ( ) ) ,
311- } ;
312- }
313293}
314294
315295pub fn get_variable < K : DiagnosticSpanOrigin > (
@@ -328,15 +308,12 @@ pub fn get_variable<K: DiagnosticSpanOrigin>(
328308 ) ) ;
329309 }
330310
331- match context. static_variables . get_index ( hash) {
332- Some ( v) => {
333- return Ok ( (
334- VariableKind :: STATIC ,
335- context. static_variables . vals [ v] . clone ( ) ,
336- v,
337- ) ) ;
338- }
311+ let name = EntryKey { name_hash : hash } ;
312+
313+ let ind = context. global_scope . scope . value_to_ind
314+ [ & context. global_scope . get_base ( name. clone ( ) , origin) ?] ;
315+
316+ let t = context. global_scope . get_static_variable ( name, origin) ?;
339317
340- None => return Err ( make_cannot_find_var ( origin, & hash) . into ( ) ) ,
341- } ;
318+ Ok ( ( VariableKind :: STATIC , t, ind) )
342319}
0 commit comments