eval: lookup rule map building; eval: use general 'set' type-kind to specify custom lookup rule; watch: new table <-> stable-point mappings

This commit is contained in:
Ryan Fleury
2025-01-30 10:57:29 -08:00
parent 394d35287a
commit 92e68701d0
6 changed files with 96 additions and 17 deletions
+7 -5
View File
@@ -9,14 +9,16 @@
////////////////////////////////
//~ rjf: Basic Helper Functions
#if !defined(XXH_IMPLEMENTATION)
# define XXH_IMPLEMENTATION
# define XXH_STATIC_LINKING_ONLY
# include "third_party/xxHash/xxhash.h"
#endif
internal U64
e_hash_from_string(U64 seed, String8 string)
{
U64 result = seed;
for(U64 i = 0; i < string.size; i += 1)
{
result = ((result << 5) + result) + string.str[i];
}
U64 result = XXH3_64bits_withSeed(string.str, string.size, seed);
return result;
}
+30 -1
View File
@@ -73,6 +73,26 @@ e_select_ir_ctx(E_IRCtx *ctx)
////////////////////////////////
//~ rjf: Lookups
internal E_LookupRuleMap
e_lookup_rule_map_make(Arena *arena, U64 slots_count)
{
E_LookupRuleMap map = {0};
map.slots_count = slots_count;
map.slots = push_array(arena, E_LookupRuleSlot, map.slots_count);
return map;
}
internal void
e_lookup_rule_map_insert(Arena *arena, E_LookupRuleMap *map, E_LookupRule *rule)
{
U64 hash = e_hash_from_string(5381, rule->name);
U64 slot_idx = hash%map->slots_count;
E_LookupRuleNode *n = push_array(arena, E_LookupRuleNode, 1);
SLLQueuePush(map->slots[slot_idx].first, map->slots[slot_idx].last, n);
MemoryCopyStruct(&n->v, rule);
n->v.name = push_str8_copy(arena, n->v.name);
}
internal E_LookupRule *
e_lookup_rule_from_string(String8 string)
{
@@ -703,12 +723,21 @@ e_irtree_and_type_from_expr__space(Arena *arena, E_Space *current_space, E_Expr
case E_ExprKind_MemberAccess:
case E_ExprKind_ArrayIndex:
{
Temp scratch = scratch_begin(&arena, 1);
E_Expr *lhs = expr->first;
E_IRTreeAndType lhs_irtree = e_irtree_and_type_from_expr(scratch.arena, lhs);
E_Type *lhs_type = e_type_from_key(scratch.arena, lhs_irtree.type_key);
String8 lookup_rule_name = expr->string;
if(lhs_type->kind == E_TypeKind_Set)
{
lookup_rule_name = lhs_type->name;
}
E_Expr *rhs = lhs->next;
E_LookupRule *lookup_rule = e_lookup_rule_from_string(expr->string);
E_LookupRule *lookup_rule = e_lookup_rule_from_string(lookup_rule_name);
E_LookupInfo lookup_info = lookup_rule->lookup_info(arena, lhs);
E_Lookup lookup = lookup_rule->lookup(arena, expr->kind, lhs, rhs, lookup_info.user_data);
result = lookup.irtree_and_type;
scratch_end(scratch);
}break;
//- rjf: dereference
+4
View File
@@ -152,6 +152,10 @@ internal void e_select_ir_ctx(E_IRCtx *ctx);
////////////////////////////////
//~ rjf: Lookups
internal E_LookupRuleMap e_lookup_rule_map_make(Arena *arena, U64 slots_count);
internal void e_lookup_rule_map_insert(Arena *arena, E_LookupRuleMap *map, E_LookupRule *rule);
#define e_lookup_rule_map_insert_new(arena, map, name_, lookup_info_, lookup_) e_lookup_rule_map_insert((arena), (map), &(E_LookupRule){.name = (name_), .lookup_info = (lookup_info_), .lookup = (lookup_)})
internal E_LookupRule *e_lookup_rule_from_string(String8 string);
E_LOOKUP_INFO_FUNCTION_DEF(default);
E_LOOKUP_FUNCTION_DEF(default);
+5 -6
View File
@@ -13086,6 +13086,8 @@ rd_frame(void)
E_IRCtx *ctx = ir_ctx;
ctx->macro_map = push_array(scratch.arena, E_String2ExprMap, 1);
ctx->macro_map[0] = e_string2expr_map_make(scratch.arena, 512);
ctx->lookup_rule_map = push_array(scratch.arena, E_LookupRuleMap, 1);
ctx->lookup_rule_map[0] = e_lookup_rule_map_make(scratch.arena, 512);
//- rjf: add macros for collections
{
@@ -13228,6 +13230,7 @@ rd_frame(void)
e_string2expr_map_insert(scratch.arena, ctx->macro_map, push_str8f(scratch.arena, "$%I64x%I64x", (U64)cfg, cfg->gen), expr);
}
}
//- rjf: add macros for all evallable control entities
{
CTRL_EntityKind evallable_kinds[] =
@@ -13282,12 +13285,7 @@ rd_frame(void)
{
String8 cfg_name = evallable_cfg_names[cfg_name_idx];
String8 collection_name = rd_plural_from_code_name(cfg_name);
E_TypeKey collection_type_key = {0};
{
E_TypeKey element_type_key = evallable_cfg_types[cfg_name_idx];
RD_CfgList cfgs = rd_cfg_top_level_list_from_string(scratch.arena, cfg_name);
collection_type_key = e_type_key_cons_array(e_type_key_cons_space_ptr(element_type_key), cfgs.count);
}
E_TypeKey collection_type_key = e_type_key_cons(.kind = E_TypeKind_Set, .name = collection_name);
E_Expr *expr = e_push_expr(scratch.arena, E_ExprKind_LeafOffset, 0);
E_Space space = e_space_make(RD_EvalSpaceKind_MetaCollection);
space.u64s[0] = cfg_name_idx;
@@ -13295,6 +13293,7 @@ rd_frame(void)
expr->mode = E_Mode_Offset;
expr->type_key = collection_type_key;
e_string2expr_map_insert(scratch.arena, ctx->macro_map, collection_name, expr);
// TODO(rjf): e_lookup_rule_map_insert_new(scratch.arena, ctx->lookup_rule_map, collection_name, );
}
//- rjf: add macro for output log
+49 -5
View File
@@ -796,6 +796,15 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla
//- rjf: cell list building
internal U64
rd_id_from_watch_cell(RD_WatchCell *cell)
{
U64 result = 5381;
result = e_hash_from_string(result, str8_struct(&cell->kind));
result = e_hash_from_string(result, cell->member);
return result;
}
internal RD_WatchCell *
rd_watch_cell_list_push(Arena *arena, RD_WatchCellList *list)
{
@@ -846,9 +855,25 @@ internal RD_WatchPt
rd_watch_pt_from_tbl(EV_BlockRangeList *block_ranges, Vec2S64 tbl)
{
RD_WatchPt pt = zero_struct;
pt.cell_id = (U64)tbl.x;
pt.key = ev_key_from_num(block_ranges, (U64)tbl.y);
pt.parent_key = ev_block_range_from_num(block_ranges, (U64)tbl.y).block->key;
{
Temp scratch = scratch_begin(0, 0);
EV_Row *row = ev_row_from_num(scratch.arena, rd_view_eval_view(), rd_view_filter(), block_ranges, (U64)tbl.y);
RD_WatchRowInfo row_info = rd_watch_row_info_from_row(scratch.arena, row);
{
S64 x = 0;
for(RD_WatchCell *cell = row_info.cells.first; cell != 0; cell = cell->next, x += 1)
{
if(x == tbl.x)
{
pt.cell_id = rd_id_from_watch_cell(cell);
break;
}
}
}
pt.key = row->key;
pt.parent_key = row->block->key;
scratch_end(scratch);
}
return pt;
}
@@ -856,8 +881,27 @@ internal Vec2S64
rd_tbl_from_watch_pt(EV_BlockRangeList *block_ranges, RD_WatchPt pt)
{
Vec2S64 tbl = {0};
tbl.x = (S64)pt.cell_id;
tbl.y = (S64)ev_num_from_key(block_ranges, pt.key);
{
Temp scratch = scratch_begin(0, 0);
U64 num = ev_num_from_key(block_ranges, pt.key);
EV_Row *row = ev_row_from_num(scratch.arena, rd_view_eval_view(), rd_view_filter(), block_ranges, num);
RD_WatchRowInfo row_info = rd_watch_row_info_from_row(scratch.arena, row);
tbl.x = 0;
{
S64 x = 0;
for(RD_WatchCell *cell = row_info.cells.first; cell != 0; cell = cell->next, x += 1)
{
U64 cell_id = rd_id_from_watch_cell(cell);
if(cell_id == pt.cell_id)
{
tbl.x = x;
break;
}
}
}
tbl.y = (S64)num;
scratch_end(scratch);
}
return tbl;
}
+1
View File
@@ -223,6 +223,7 @@ internal RD_CodeViewBuildResult rd_code_view_build(Arena *arena, RD_CodeViewStat
//~ rjf: Watch View Functions
//- rjf: cell list building
internal U64 rd_id_from_watch_cell(RD_WatchCell *cell);
internal RD_WatchCell *rd_watch_cell_list_push(Arena *arena, RD_WatchCellList *list);
internal RD_WatchCell *rd_watch_cell_list_push_new_(Arena *arena, RD_WatchCellList *list, RD_WatchCell *params);
#define rd_watch_cell_list_push_new(arena, list, kind_, ...) rd_watch_cell_list_push_new_((arena), (list), &(RD_WatchCell){.kind = (kind_), __VA_ARGS__})