@@ -61,13 +61,26 @@ e_expr_kind_is_comparison(E_ExprKind kind)
6161internal E_IRCtx *
6262e_selected_ir_ctx (void )
6363{
64- return e_ir_ctx ;
64+ return e_ir_state -> ctx ;
6565}
6666
6767internal void
6868e_select_ir_ctx (E_IRCtx * ctx )
6969{
70- e_ir_ctx = ctx ;
70+ if (e_ir_state == 0 )
71+ {
72+ Arena * arena = arena_alloc ();
73+ e_ir_state = push_array (arena , E_IRState , 1 );
74+ e_ir_state -> arena = arena ;
75+ e_ir_state -> arena_eval_start_pos = arena_pos (arena );
76+ }
77+ e_ir_state -> ctx = ctx ;
78+ e_ir_state -> used_tag_map = push_array (e_ir_state -> arena , E_UsedTagMap , 1 );
79+ e_ir_state -> used_tag_map -> slots_count = 64 ;
80+ e_ir_state -> used_tag_map -> slots = push_array (e_ir_state -> arena , E_UsedTagSlot , e_ir_state -> used_tag_map -> slots_count );
81+ e_ir_state -> type_auto_hook_cache_map = push_array (e_ir_state -> arena , E_TypeAutoHookCacheMap , 1 );
82+ e_ir_state -> type_auto_hook_cache_map -> slots_count = 256 ;
83+ e_ir_state -> type_auto_hook_cache_map -> slots = push_array (e_ir_state -> arena , E_TypeAutoHookCacheSlot , e_ir_state -> type_auto_hook_cache_map -> slots_count );
7184}
7285
7386////////////////////////////////
@@ -102,11 +115,11 @@ internal E_LookupRule *
102115e_lookup_rule_from_string (String8 string )
103116{
104117 E_LookupRule * result = & e_lookup_rule__nil ;
105- if (e_ir_ctx -> lookup_rule_map != 0 && e_ir_ctx -> lookup_rule_map -> slots_count != 0 )
118+ if (e_ir_state -> ctx -> lookup_rule_map != 0 && e_ir_state -> ctx -> lookup_rule_map -> slots_count != 0 )
106119 {
107120 U64 hash = e_hash_from_string (5381 , string );
108- U64 slot_idx = hash %e_ir_ctx -> lookup_rule_map -> slots_count ;
109- for (E_LookupRuleNode * n = e_ir_ctx -> lookup_rule_map -> slots [slot_idx ].first ;
121+ U64 slot_idx = hash %e_ir_state -> ctx -> lookup_rule_map -> slots_count ;
122+ for (E_LookupRuleNode * n = e_ir_state -> ctx -> lookup_rule_map -> slots [slot_idx ].first ;
110123 n != 0 ;
111124 n = n -> next )
112125 {
@@ -664,9 +677,9 @@ internal E_IRGenRule *
664677e_irgen_rule_from_string (String8 string )
665678{
666679 E_IRGenRule * rule = & e_irgen_rule__default ;
667- if (e_ir_ctx != 0 && e_ir_ctx -> irgen_rule_map != 0 && e_ir_ctx -> irgen_rule_map -> slots_count != 0 )
680+ if (e_ir_state != 0 && e_ir_state -> ctx != 0 && e_ir_state -> ctx -> irgen_rule_map != 0 && e_ir_state -> ctx -> irgen_rule_map -> slots_count != 0 )
668681 {
669- E_IRGenRuleMap * map = e_ir_ctx -> irgen_rule_map ;
682+ E_IRGenRuleMap * map = e_ir_state -> ctx -> irgen_rule_map ;
670683 U64 hash = e_hash_from_string (5381 , string );
671684 U64 slot_idx = hash %map -> slots_count ;
672685 for (E_IRGenRuleNode * n = map -> slots [slot_idx ].first ; n != 0 ; n = n -> next )
@@ -724,10 +737,10 @@ e_auto_hook_tag_exprs_from_type_key(Arena *arena, E_TypeKey type_key)
724737{
725738 ProfBeginFunction ();
726739 E_ExprList exprs = {0 };
727- if (e_ir_ctx != 0 )
740+ if (e_ir_state != 0 && e_ir_state -> ctx != 0 )
728741 {
729742 Temp scratch = scratch_begin (& arena , 1 );
730- E_AutoHookMap * map = e_ir_ctx -> auto_hook_map ;
743+ E_AutoHookMap * map = e_ir_state -> ctx -> auto_hook_map ;
731744
732745 //- rjf: gather exact-type-key-matches from the map
733746 if (map != 0 && map -> slots_count != 0 )
@@ -782,12 +795,12 @@ internal E_ExprList
782795e_auto_hook_tag_exprs_from_type_key__cached (E_TypeKey type_key )
783796{
784797 E_ExprList exprs = {0 };
785- if (e_ir_ctx != 0 && e_ir_ctx -> type_auto_hook_cache_map != 0 && e_ir_ctx -> type_auto_hook_cache_map -> slots_count != 0 )
798+ if (e_ir_state != 0 && e_ir_state -> ctx != 0 && e_ir_state -> type_auto_hook_cache_map != 0 && e_ir_state -> type_auto_hook_cache_map -> slots_count != 0 )
786799 {
787800 U64 hash = e_hash_from_string (5381 , str8_struct (& type_key ));
788- U64 slot_idx = hash %e_ir_ctx -> type_auto_hook_cache_map -> slots_count ;
801+ U64 slot_idx = hash %e_ir_state -> type_auto_hook_cache_map -> slots_count ;
789802 E_TypeAutoHookCacheNode * node = 0 ;
790- for (E_TypeAutoHookCacheNode * n = e_ir_ctx -> type_auto_hook_cache_map -> slots [slot_idx ].first ;
803+ for (E_TypeAutoHookCacheNode * n = e_ir_state -> type_auto_hook_cache_map -> slots [slot_idx ].first ;
791804 n != 0 ;
792805 n = n -> next )
793806 {
@@ -798,9 +811,8 @@ e_auto_hook_tag_exprs_from_type_key__cached(E_TypeKey type_key)
798811 }
799812 if (node == 0 )
800813 {
801- // TODO(rjf): @cfg hack!!! should not be using this arena...
802- node = push_array (e_type_state -> arena , E_TypeAutoHookCacheNode , 1 );
803- SLLQueuePush (e_ir_ctx -> type_auto_hook_cache_map -> slots [slot_idx ].first , e_ir_ctx -> type_auto_hook_cache_map -> slots [slot_idx ].last , node );
814+ node = push_array (e_ir_state -> arena , E_TypeAutoHookCacheNode , 1 );
815+ SLLQueuePush (e_ir_state -> type_auto_hook_cache_map -> slots [slot_idx ].first , e_ir_state -> type_auto_hook_cache_map -> slots [slot_idx ].last , node );
804816 node -> key = type_key ;
805817 node -> exprs = e_auto_hook_tag_exprs_from_type_key (e_type_state -> arena , type_key );
806818 }
@@ -1807,16 +1819,16 @@ E_IRGEN_FUNCTION_DEF(default)
18071819 //- rjf: leaf identifiers
18081820 case E_ExprKind_LeafIdent :
18091821 {
1810- E_Expr * macro_expr = e_string2expr_lookup (e_ir_ctx -> macro_map , expr -> string );
1822+ E_Expr * macro_expr = e_string2expr_lookup (e_ir_state -> ctx -> macro_map , expr -> string );
18111823 if (macro_expr == & e_expr_nil )
18121824 {
18131825 e_msgf (arena , & result .msgs , E_MsgKind_ResolutionFailure , expr -> location , "`%S` could not be found." , expr -> string );
18141826 }
18151827 else
18161828 {
1817- e_string2expr_map_inc_poison (e_ir_ctx -> macro_map , expr -> string );
1829+ e_string2expr_map_inc_poison (e_ir_state -> ctx -> macro_map , expr -> string );
18181830 result = e_irtree_and_type_from_expr (arena , macro_expr );
1819- e_string2expr_map_dec_poison (e_ir_ctx -> macro_map , expr -> string );
1831+ e_string2expr_map_dec_poison (e_ir_state -> ctx -> macro_map , expr -> string );
18201832 }
18211833 }break ;
18221834
@@ -1946,8 +1958,8 @@ e_irtree_and_type_from_expr(Arena *arena, E_Expr *expr)
19461958 {
19471959 B32 tag_is_poisoned = 0 ;
19481960 U64 hash = e_hash_from_string (5381 , str8_struct (& tag ));
1949- U64 slot_idx = hash %e_ir_ctx -> used_tag_map -> slots_count ;
1950- for (E_UsedTagNode * n = e_ir_ctx -> used_tag_map -> slots [slot_idx ].first ; n != 0 ; n = n -> next )
1961+ U64 slot_idx = hash %e_ir_state -> used_tag_map -> slots_count ;
1962+ for (E_UsedTagNode * n = e_ir_state -> used_tag_map -> slots [slot_idx ].first ; n != 0 ; n = n -> next )
19511963 {
19521964 if (n -> tag == tag )
19531965 {
@@ -1981,10 +1993,10 @@ e_irtree_and_type_from_expr(Arena *arena, E_Expr *expr)
19811993 if (t -> tag != & e_expr_nil )
19821994 {
19831995 U64 hash = e_hash_from_string (5381 , str8_struct (& t -> tag ));
1984- U64 slot_idx = hash %e_ir_ctx -> used_tag_map -> slots_count ;
1996+ U64 slot_idx = hash %e_ir_state -> used_tag_map -> slots_count ;
19851997 E_UsedTagNode * n = push_array (arena , E_UsedTagNode , 1 );
19861998 n -> tag = t -> tag ;
1987- DLLPushBack (e_ir_ctx -> used_tag_map -> slots [slot_idx ].first , e_ir_ctx -> used_tag_map -> slots [slot_idx ].last , n );
1999+ DLLPushBack (e_ir_state -> used_tag_map -> slots [slot_idx ].first , e_ir_state -> used_tag_map -> slots [slot_idx ].last , n );
19882000 }
19892001
19902002 // rjf: do this rule's generation
@@ -2002,8 +2014,8 @@ e_irtree_and_type_from_expr(Arena *arena, E_Expr *expr)
20022014 {
20032015 B32 tag_is_poisoned = 0 ;
20042016 U64 hash = e_hash_from_string (5381 , str8_struct (& tag ));
2005- U64 slot_idx = hash %e_ir_ctx -> used_tag_map -> slots_count ;
2006- for (E_UsedTagNode * n = e_ir_ctx -> used_tag_map -> slots [slot_idx ].first ; n != 0 ; n = n -> next )
2017+ U64 slot_idx = hash %e_ir_state -> used_tag_map -> slots_count ;
2018+ for (E_UsedTagNode * n = e_ir_state -> used_tag_map -> slots [slot_idx ].first ; n != 0 ; n = n -> next )
20072019 {
20082020 if (n -> tag == tag )
20092021 {
@@ -2034,12 +2046,12 @@ e_irtree_and_type_from_expr(Arena *arena, E_Expr *expr)
20342046 if (t -> tag != & e_expr_nil )
20352047 {
20362048 U64 hash = e_hash_from_string (5381 , str8_struct (& t -> tag ));
2037- U64 slot_idx = hash %e_ir_ctx -> used_tag_map -> slots_count ;
2038- for (E_UsedTagNode * n = e_ir_ctx -> used_tag_map -> slots [slot_idx ].first ; n != 0 ; n = n -> next )
2049+ U64 slot_idx = hash %e_ir_state -> used_tag_map -> slots_count ;
2050+ for (E_UsedTagNode * n = e_ir_state -> used_tag_map -> slots [slot_idx ].first ; n != 0 ; n = n -> next )
20392051 {
20402052 if (n -> tag == t -> tag )
20412053 {
2042- DLLRemove (e_ir_ctx -> used_tag_map -> slots [slot_idx ].first , e_ir_ctx -> used_tag_map -> slots [slot_idx ].last , n );
2054+ DLLRemove (e_ir_state -> used_tag_map -> slots [slot_idx ].first , e_ir_state -> used_tag_map -> slots [slot_idx ].last , n );
20432055 break ;
20442056 }
20452057 }
0 commit comments