@@ -90,6 +90,11 @@ e_lookup_rule_map_insert(Arena *arena, E_LookupRuleMap *map, E_LookupRule *rule)
9090 E_LookupRuleNode * n = push_array (arena , E_LookupRuleNode , 1 );
9191 SLLQueuePush (map -> slots [slot_idx ].first , map -> slots [slot_idx ].last , n );
9292 MemoryCopyStruct (& n -> v , rule );
93+ if (n -> v .info == 0 ) { n -> v .info = E_LOOKUP_INFO_FUNCTION_NAME (default ); }
94+ if (n -> v .access == 0 ) { n -> v .access = E_LOOKUP_ACCESS_FUNCTION_NAME (default ); }
95+ if (n -> v .range == 0 ) { n -> v .range = E_LOOKUP_RANGE_FUNCTION_NAME (default ); }
96+ if (n -> v .id_from_num == 0 ){ n -> v .id_from_num = E_LOOKUP_ID_FROM_NUM_FUNCTION_NAME (default ); }
97+ if (n -> v .num_from_id == 0 ){ n -> v .num_from_id = E_LOOKUP_NUM_FROM_ID_FUNCTION_NAME (default ); }
9398 n -> v .name = push_str8_copy (arena , n -> v .name );
9499}
95100
@@ -155,9 +160,18 @@ E_LOOKUP_INFO_FUNCTION_DEF(default)
155160 return lookup_info ;
156161}
157162
158- E_LOOKUP_FUNCTION_DEF (default )
163+ E_LOOKUP_ACCESS_FUNCTION_DEF (default )
159164{
160- E_Lookup lookup = {{& e_irnode_nil }};
165+ //
166+ // TODO(rjf): need to define what it means to access a set expression
167+ // whose type *does not* define its IR generation rules, BUT it does
168+ // define specific child expressions. so e.g. `watches`, does not
169+ // define `watches[0]`, because it has defined that `watches[0]`
170+ // maps to another expression, which is whatever the first watch
171+ // expression is (e.g. `basics`). so, in that case, we can just use
172+ // the lookup-range rule, grab the Nth expression, and IR-ify *that*.
173+ //
174+ E_LookupAccess result = {{& e_irnode_nil }};
161175 switch (kind )
162176 {
163177 default :{}break ;
@@ -180,7 +194,7 @@ E_LOOKUP_FUNCTION_DEF(default)
180194 check_type_key = e_type_unwrap (e_type_direct_from_key (e_type_unwrap (l_restype )));
181195 check_type_kind = e_type_kind_from_key (check_type_key );
182196 }
183- e_msg_list_concat_in_place (& lookup .irtree_and_type .msgs , & l .msgs );
197+ e_msg_list_concat_in_place (& result .irtree_and_type .msgs , & l .msgs );
184198
185199 // rjf: look up member
186200 B32 r_found = 0 ;
@@ -234,20 +248,20 @@ E_LOOKUP_FUNCTION_DEF(default)
234248 }
235249 else if (exprr -> kind != E_ExprKind_LeafMember )
236250 {
237- e_msgf (arena , & lookup .irtree_and_type .msgs , E_MsgKind_MalformedInput , exprl -> location , "Expected member name." );
251+ e_msgf (arena , & result .irtree_and_type .msgs , E_MsgKind_MalformedInput , exprl -> location , "Expected member name." );
238252 break ;
239253 }
240254 else if (!r_found )
241255 {
242- e_msgf (arena , & lookup .irtree_and_type .msgs , E_MsgKind_MalformedInput , exprr -> location , "Could not find a member named `%S`." , exprr -> string );
256+ e_msgf (arena , & result .irtree_and_type .msgs , E_MsgKind_MalformedInput , exprr -> location , "Could not find a member named `%S`." , exprr -> string );
243257 break ;
244258 }
245259 else if (check_type_kind != E_TypeKind_Struct &&
246260 check_type_kind != E_TypeKind_Class &&
247261 check_type_kind != E_TypeKind_Union &&
248262 check_type_kind != E_TypeKind_Enum )
249263 {
250- e_msgf (arena , & lookup .irtree_and_type .msgs , E_MsgKind_MalformedInput , exprl -> location , "Cannot perform member access on this type." );
264+ e_msgf (arena , & result .irtree_and_type .msgs , E_MsgKind_MalformedInput , exprl -> location , "Cannot perform member access on this type." );
251265 break ;
252266 }
253267
@@ -275,9 +289,9 @@ E_LOOKUP_FUNCTION_DEF(default)
275289 }
276290
277291 // rjf: fill
278- lookup .irtree_and_type .root = new_tree ;
279- lookup .irtree_and_type .type_key = r_type ;
280- lookup .irtree_and_type .mode = mode ;
292+ result .irtree_and_type .root = new_tree ;
293+ result .irtree_and_type .type_key = r_type ;
294+ result .irtree_and_type .mode = mode ;
281295 }
282296 }break ;
283297
@@ -302,8 +316,8 @@ E_LOOKUP_FUNCTION_DEF(default)
302316 direct_type = e_type_direct_from_key (direct_type );
303317 direct_type = e_type_unwrap (direct_type );
304318 U64 direct_type_size = e_type_byte_size_from_key (direct_type );
305- e_msg_list_concat_in_place (& lookup .irtree_and_type .msgs , & l .msgs );
306- e_msg_list_concat_in_place (& lookup .irtree_and_type .msgs , & r .msgs );
319+ e_msg_list_concat_in_place (& result .irtree_and_type .msgs , & l .msgs );
320+ e_msg_list_concat_in_place (& result .irtree_and_type .msgs , & r .msgs );
307321
308322 // rjf: bad conditions? -> error if applicable, exit
309323 if (r .root -> op == 0 )
@@ -312,22 +326,22 @@ E_LOOKUP_FUNCTION_DEF(default)
312326 }
313327 else if (l_restype_kind != E_TypeKind_Ptr && l_restype_kind != E_TypeKind_Array )
314328 {
315- e_msgf (arena , & lookup .irtree_and_type .msgs , E_MsgKind_MalformedInput , exprl -> location , "Cannot index into this type." );
329+ e_msgf (arena , & result .irtree_and_type .msgs , E_MsgKind_MalformedInput , exprl -> location , "Cannot index into this type." );
316330 break ;
317331 }
318332 else if (!e_type_kind_is_integer (r_restype_kind ))
319333 {
320- e_msgf (arena , & lookup .irtree_and_type .msgs , E_MsgKind_MalformedInput , exprr -> location , "Cannot index with this type." );
334+ e_msgf (arena , & result .irtree_and_type .msgs , E_MsgKind_MalformedInput , exprr -> location , "Cannot index with this type." );
321335 break ;
322336 }
323337 else if (l_restype_kind == E_TypeKind_Ptr && direct_type_size == 0 )
324338 {
325- e_msgf (arena , & lookup .irtree_and_type .msgs , E_MsgKind_MalformedInput , exprr -> location , "Cannot index into pointers of zero-sized types." );
339+ e_msgf (arena , & result .irtree_and_type .msgs , E_MsgKind_MalformedInput , exprr -> location , "Cannot index into pointers of zero-sized types." );
326340 break ;
327341 }
328342 else if (l_restype_kind == E_TypeKind_Array && direct_type_size == 0 )
329343 {
330- e_msgf (arena , & lookup .irtree_and_type .msgs , E_MsgKind_MalformedInput , exprr -> location , "Cannot index into arrays of zero-sized types." );
344+ e_msgf (arena , & result .irtree_and_type .msgs , E_MsgKind_MalformedInput , exprr -> location , "Cannot index into arrays of zero-sized types." );
331345 break ;
332346 }
333347
@@ -381,12 +395,64 @@ E_LOOKUP_FUNCTION_DEF(default)
381395 }
382396
383397 // rjf: fill
384- lookup .irtree_and_type .root = new_tree ;
385- lookup .irtree_and_type .type_key = direct_type ;
386- lookup .irtree_and_type .mode = l .mode ;
398+ result .irtree_and_type .root = new_tree ;
399+ result .irtree_and_type .type_key = direct_type ;
400+ result .irtree_and_type .mode = l .mode ;
387401 }break ;
388402 }
389- return lookup ;
403+ return result ;
404+ }
405+
406+ E_LOOKUP_RANGE_FUNCTION_DEF (default )
407+ {
408+ E_LookupRange result = {0 };
409+ Temp scratch = scratch_begin (& arena , 1 );
410+ {
411+ E_IRTreeAndType lhs_irtree = e_irtree_and_type_from_expr (scratch .arena , lhs );
412+ E_TypeKey lhs_type_key = lhs_irtree .type_key ;
413+ E_TypeKind lhs_type_kind = e_type_kind_from_key (lhs_type_key );
414+ if (lhs_type_kind == E_TypeKind_Struct ||
415+ lhs_type_kind == E_TypeKind_Union ||
416+ lhs_type_kind == E_TypeKind_Class ||
417+ lhs_type_kind == E_TypeKind_Enum )
418+ {
419+ E_Type * lhs_type = e_type_from_key (scratch .arena , lhs_type_key );
420+ Rng1U64 legal_idx_range = r1u64 (0 , lhs_type -> count );
421+ Rng1U64 read_range = intersect_1u64 (legal_idx_range , idx_range );
422+ U64 read_range_count = dim_1u64 (read_range );
423+ result .exprs_count = read_range_count ;
424+ result .exprs = push_array (arena , E_Expr * , result .exprs_count );
425+ for (U64 idx = 0 ; idx < result .exprs_count ; idx += 1 )
426+ {
427+ U64 member_idx = idx + read_range .min ;
428+ String8 member_name = (lhs_type -> members ? lhs_type -> members [member_idx ].name :
429+ lhs_type -> enum_vals ? lhs_type -> enum_vals [member_idx ].name : str8_lit ("" ));
430+ result .exprs [idx ] = e_expr_ref_member_access (arena , lhs , member_name );
431+ }
432+ }
433+ else if (lhs_type_kind == E_TypeKind_Set )
434+ {
435+ result .exprs_count = dim_1u64 (idx_range );
436+ result .exprs = push_array (arena , E_Expr * , result .exprs_count );
437+ result .exprs_strings = push_array (arena , String8 , result .exprs_count );
438+ for (U64 idx = 0 ; idx < result .exprs_count ; idx += 1 )
439+ {
440+ result .exprs [idx ] = e_expr_ref_array_index (arena , lhs , idx_range .min + idx );
441+ }
442+ }
443+ }
444+ scratch_end (scratch );
445+ return result ;
446+ }
447+
448+ E_LOOKUP_ID_FROM_NUM_FUNCTION_DEF (default )
449+ {
450+ return num ;
451+ }
452+
453+ E_LOOKUP_NUM_FROM_ID_FUNCTION_DEF (default )
454+ {
455+ return id ;
390456}
391457
392458////////////////////////////////
@@ -716,9 +782,9 @@ e_irtree_and_type_from_expr__space(Arena *arena, E_Space *current_space, E_Expr
716782 }
717783 E_Expr * rhs = lhs -> next ;
718784 E_LookupRule * lookup_rule = e_lookup_rule_from_string (lookup_rule_name );
719- E_LookupInfo lookup_info = lookup_rule -> lookup_info (arena , lhs );
720- E_Lookup lookup = lookup_rule -> lookup (arena , expr -> kind , lhs , rhs , lookup_info .user_data );
721- result = lookup .irtree_and_type ;
785+ E_LookupInfo lookup_info = lookup_rule -> info (arena , lhs , str8_zero () );
786+ E_LookupAccess lookup_access = lookup_rule -> access (arena , expr -> kind , lhs , rhs , lookup_info .user_data );
787+ result = lookup_access .irtree_and_type ;
722788 scratch_end (scratch );
723789 }break ;
724790
0 commit comments