Skip to content

Commit 92e6870

Browse files
committed
eval: lookup rule map building; eval: use general 'set' type-kind to specify custom lookup rule; watch: new table <-> stable-point mappings
1 parent 394d352 commit 92e6870

File tree

6 files changed

+96
-17
lines changed

6 files changed

+96
-17
lines changed

src/eval/eval_core.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
////////////////////////////////
1010
//~ rjf: Basic Helper Functions
1111

12+
#if !defined(XXH_IMPLEMENTATION)
13+
# define XXH_IMPLEMENTATION
14+
# define XXH_STATIC_LINKING_ONLY
15+
# include "third_party/xxHash/xxhash.h"
16+
#endif
17+
1218
internal U64
1319
e_hash_from_string(U64 seed, String8 string)
1420
{
15-
U64 result = seed;
16-
for(U64 i = 0; i < string.size; i += 1)
17-
{
18-
result = ((result << 5) + result) + string.str[i];
19-
}
21+
U64 result = XXH3_64bits_withSeed(string.str, string.size, seed);
2022
return result;
2123
}
2224

src/eval/eval_ir.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,26 @@ e_select_ir_ctx(E_IRCtx *ctx)
7373
////////////////////////////////
7474
//~ rjf: Lookups
7575

76+
internal E_LookupRuleMap
77+
e_lookup_rule_map_make(Arena *arena, U64 slots_count)
78+
{
79+
E_LookupRuleMap map = {0};
80+
map.slots_count = slots_count;
81+
map.slots = push_array(arena, E_LookupRuleSlot, map.slots_count);
82+
return map;
83+
}
84+
85+
internal void
86+
e_lookup_rule_map_insert(Arena *arena, E_LookupRuleMap *map, E_LookupRule *rule)
87+
{
88+
U64 hash = e_hash_from_string(5381, rule->name);
89+
U64 slot_idx = hash%map->slots_count;
90+
E_LookupRuleNode *n = push_array(arena, E_LookupRuleNode, 1);
91+
SLLQueuePush(map->slots[slot_idx].first, map->slots[slot_idx].last, n);
92+
MemoryCopyStruct(&n->v, rule);
93+
n->v.name = push_str8_copy(arena, n->v.name);
94+
}
95+
7696
internal E_LookupRule *
7797
e_lookup_rule_from_string(String8 string)
7898
{
@@ -703,12 +723,21 @@ e_irtree_and_type_from_expr__space(Arena *arena, E_Space *current_space, E_Expr
703723
case E_ExprKind_MemberAccess:
704724
case E_ExprKind_ArrayIndex:
705725
{
726+
Temp scratch = scratch_begin(&arena, 1);
706727
E_Expr *lhs = expr->first;
728+
E_IRTreeAndType lhs_irtree = e_irtree_and_type_from_expr(scratch.arena, lhs);
729+
E_Type *lhs_type = e_type_from_key(scratch.arena, lhs_irtree.type_key);
730+
String8 lookup_rule_name = expr->string;
731+
if(lhs_type->kind == E_TypeKind_Set)
732+
{
733+
lookup_rule_name = lhs_type->name;
734+
}
707735
E_Expr *rhs = lhs->next;
708-
E_LookupRule *lookup_rule = e_lookup_rule_from_string(expr->string);
736+
E_LookupRule *lookup_rule = e_lookup_rule_from_string(lookup_rule_name);
709737
E_LookupInfo lookup_info = lookup_rule->lookup_info(arena, lhs);
710738
E_Lookup lookup = lookup_rule->lookup(arena, expr->kind, lhs, rhs, lookup_info.user_data);
711739
result = lookup.irtree_and_type;
740+
scratch_end(scratch);
712741
}break;
713742

714743
//- rjf: dereference

src/eval/eval_ir.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ internal void e_select_ir_ctx(E_IRCtx *ctx);
152152
////////////////////////////////
153153
//~ rjf: Lookups
154154

155+
internal E_LookupRuleMap e_lookup_rule_map_make(Arena *arena, U64 slots_count);
156+
internal void e_lookup_rule_map_insert(Arena *arena, E_LookupRuleMap *map, E_LookupRule *rule);
157+
#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_)})
158+
155159
internal E_LookupRule *e_lookup_rule_from_string(String8 string);
156160
E_LOOKUP_INFO_FUNCTION_DEF(default);
157161
E_LOOKUP_FUNCTION_DEF(default);

src/raddbg/raddbg_core.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13086,6 +13086,8 @@ rd_frame(void)
1308613086
E_IRCtx *ctx = ir_ctx;
1308713087
ctx->macro_map = push_array(scratch.arena, E_String2ExprMap, 1);
1308813088
ctx->macro_map[0] = e_string2expr_map_make(scratch.arena, 512);
13089+
ctx->lookup_rule_map = push_array(scratch.arena, E_LookupRuleMap, 1);
13090+
ctx->lookup_rule_map[0] = e_lookup_rule_map_make(scratch.arena, 512);
1308913091

1309013092
//- rjf: add macros for collections
1309113093
{
@@ -13228,6 +13230,7 @@ rd_frame(void)
1322813230
e_string2expr_map_insert(scratch.arena, ctx->macro_map, push_str8f(scratch.arena, "$%I64x%I64x", (U64)cfg, cfg->gen), expr);
1322913231
}
1323013232
}
13233+
1323113234
//- rjf: add macros for all evallable control entities
1323213235
{
1323313236
CTRL_EntityKind evallable_kinds[] =
@@ -13282,19 +13285,15 @@ rd_frame(void)
1328213285
{
1328313286
String8 cfg_name = evallable_cfg_names[cfg_name_idx];
1328413287
String8 collection_name = rd_plural_from_code_name(cfg_name);
13285-
E_TypeKey collection_type_key = {0};
13286-
{
13287-
E_TypeKey element_type_key = evallable_cfg_types[cfg_name_idx];
13288-
RD_CfgList cfgs = rd_cfg_top_level_list_from_string(scratch.arena, cfg_name);
13289-
collection_type_key = e_type_key_cons_array(e_type_key_cons_space_ptr(element_type_key), cfgs.count);
13290-
}
13288+
E_TypeKey collection_type_key = e_type_key_cons(.kind = E_TypeKind_Set, .name = collection_name);
1329113289
E_Expr *expr = e_push_expr(scratch.arena, E_ExprKind_LeafOffset, 0);
1329213290
E_Space space = e_space_make(RD_EvalSpaceKind_MetaCollection);
1329313291
space.u64s[0] = cfg_name_idx;
1329413292
expr->space = space;
1329513293
expr->mode = E_Mode_Offset;
1329613294
expr->type_key = collection_type_key;
1329713295
e_string2expr_map_insert(scratch.arena, ctx->macro_map, collection_name, expr);
13296+
// TODO(rjf): e_lookup_rule_map_insert_new(scratch.arena, ctx->lookup_rule_map, collection_name, );
1329813297
}
1329913298

1330013299
//- rjf: add macro for output log

src/raddbg/raddbg_views.c

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,15 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla
796796

797797
//- rjf: cell list building
798798

799+
internal U64
800+
rd_id_from_watch_cell(RD_WatchCell *cell)
801+
{
802+
U64 result = 5381;
803+
result = e_hash_from_string(result, str8_struct(&cell->kind));
804+
result = e_hash_from_string(result, cell->member);
805+
return result;
806+
}
807+
799808
internal RD_WatchCell *
800809
rd_watch_cell_list_push(Arena *arena, RD_WatchCellList *list)
801810
{
@@ -846,18 +855,53 @@ internal RD_WatchPt
846855
rd_watch_pt_from_tbl(EV_BlockRangeList *block_ranges, Vec2S64 tbl)
847856
{
848857
RD_WatchPt pt = zero_struct;
849-
pt.cell_id = (U64)tbl.x;
850-
pt.key = ev_key_from_num(block_ranges, (U64)tbl.y);
851-
pt.parent_key = ev_block_range_from_num(block_ranges, (U64)tbl.y).block->key;
858+
{
859+
Temp scratch = scratch_begin(0, 0);
860+
EV_Row *row = ev_row_from_num(scratch.arena, rd_view_eval_view(), rd_view_filter(), block_ranges, (U64)tbl.y);
861+
RD_WatchRowInfo row_info = rd_watch_row_info_from_row(scratch.arena, row);
862+
{
863+
S64 x = 0;
864+
for(RD_WatchCell *cell = row_info.cells.first; cell != 0; cell = cell->next, x += 1)
865+
{
866+
if(x == tbl.x)
867+
{
868+
pt.cell_id = rd_id_from_watch_cell(cell);
869+
break;
870+
}
871+
}
872+
}
873+
pt.key = row->key;
874+
pt.parent_key = row->block->key;
875+
scratch_end(scratch);
876+
}
852877
return pt;
853878
}
854879

855880
internal Vec2S64
856881
rd_tbl_from_watch_pt(EV_BlockRangeList *block_ranges, RD_WatchPt pt)
857882
{
858883
Vec2S64 tbl = {0};
859-
tbl.x = (S64)pt.cell_id;
860-
tbl.y = (S64)ev_num_from_key(block_ranges, pt.key);
884+
{
885+
Temp scratch = scratch_begin(0, 0);
886+
U64 num = ev_num_from_key(block_ranges, pt.key);
887+
EV_Row *row = ev_row_from_num(scratch.arena, rd_view_eval_view(), rd_view_filter(), block_ranges, num);
888+
RD_WatchRowInfo row_info = rd_watch_row_info_from_row(scratch.arena, row);
889+
tbl.x = 0;
890+
{
891+
S64 x = 0;
892+
for(RD_WatchCell *cell = row_info.cells.first; cell != 0; cell = cell->next, x += 1)
893+
{
894+
U64 cell_id = rd_id_from_watch_cell(cell);
895+
if(cell_id == pt.cell_id)
896+
{
897+
tbl.x = x;
898+
break;
899+
}
900+
}
901+
}
902+
tbl.y = (S64)num;
903+
scratch_end(scratch);
904+
}
861905
return tbl;
862906
}
863907

src/raddbg/raddbg_views.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ internal RD_CodeViewBuildResult rd_code_view_build(Arena *arena, RD_CodeViewStat
223223
//~ rjf: Watch View Functions
224224

225225
//- rjf: cell list building
226+
internal U64 rd_id_from_watch_cell(RD_WatchCell *cell);
226227
internal RD_WatchCell *rd_watch_cell_list_push(Arena *arena, RD_WatchCellList *list);
227228
internal RD_WatchCell *rd_watch_cell_list_push_new_(Arena *arena, RD_WatchCellList *list, RD_WatchCell *params);
228229
#define rd_watch_cell_list_push_new(arena, list, kind_, ...) rd_watch_cell_list_push_new_((arena), (list), &(RD_WatchCell){.kind = (kind_), __VA_ARGS__})

0 commit comments

Comments
 (0)