Skip to content

Commit c77f2de

Browse files
committed
more work on file evaluation; move eval_string <-> eval <-> file_path to formal filesystem/file spaces, rather than inferring from the expression tree; imply '.data' when generating file contents visualizer tabs
1 parent 5e98e40 commit c77f2de

File tree

6 files changed

+132
-48
lines changed

6 files changed

+132
-48
lines changed

src/eval/eval_core.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ typedef U64 E_SpaceKind;
9393
enum
9494
{
9595
E_SpaceKind_Null,
96-
E_SpaceKind_HashStoreKey,
96+
E_SpaceKind_File,
9797
E_SpaceKind_FileSystem,
98+
E_SpaceKind_HashStoreKey,
9899
E_SpaceKind_FirstUserDefined,
99100
};
100101

src/eval/eval_ir.c

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,43 @@ E_LOOKUP_INFO_FUNCTION_DEF(file)
234234
return info;
235235
}
236236

237+
E_LOOKUP_ACCESS_FUNCTION_DEF(file)
238+
{
239+
E_LookupAccess result = {{&e_irnode_nil}};
240+
if(kind == E_ExprKind_MemberAccess)
241+
{
242+
E_FileAccel *accel = (E_FileAccel *)user_data;
243+
String8 member_name = rhs->string;
244+
if(str8_match(member_name, str8_lit("size"), 0))
245+
{
246+
result.irtree_and_type.root = e_irtree_const_u(arena, accel->props.size);
247+
result.irtree_and_type.type_key = e_type_key_basic(E_TypeKind_U64);
248+
result.irtree_and_type.mode = E_Mode_Value;
249+
}
250+
else if(str8_match(member_name, str8_lit("last_modified_time"), 0))
251+
{
252+
result.irtree_and_type.root = e_irtree_const_u(arena, accel->props.modified);
253+
result.irtree_and_type.type_key = e_type_key_basic(E_TypeKind_U64);
254+
result.irtree_and_type.mode = E_Mode_Value;
255+
}
256+
else if(str8_match(member_name, str8_lit("creation_time"), 0))
257+
{
258+
result.irtree_and_type.root = e_irtree_const_u(arena, accel->props.created);
259+
result.irtree_and_type.type_key = e_type_key_basic(E_TypeKind_U64);
260+
result.irtree_and_type.mode = E_Mode_Value;
261+
}
262+
else if(str8_match(member_name, str8_lit("data"), 0))
263+
{
264+
E_Space space = e_space_make(E_SpaceKind_File);
265+
space.u64_0 = e_id_from_string(accel->file_path);
266+
result.irtree_and_type.root = e_irtree_set_space(arena, space, e_irtree_const_u(arena, 0));
267+
result.irtree_and_type.type_key = e_type_key_cons_array(e_type_key_basic(E_TypeKind_U8), accel->props.size);
268+
result.irtree_and_type.mode = E_Mode_Offset;
269+
}
270+
}
271+
return result;
272+
}
273+
237274
E_LOOKUP_RANGE_FUNCTION_DEF(file)
238275
{
239276
E_FileAccel *accel = (E_FileAccel *)user_data;
@@ -245,29 +282,11 @@ E_LOOKUP_RANGE_FUNCTION_DEF(file)
245282
if(0 <= idx && idx < accel->fields.count)
246283
{
247284
String8 name = accel->fields.v[idx];
248-
if(str8_match(name, str8_lit("size"), 0))
249-
{
250-
expr = e_push_expr(arena, E_ExprKind_LeafU64, 0);
251-
expr->value.u64 = accel->props.size;
252-
}
253-
else if(str8_match(name, str8_lit("last_modified_time"), 0))
254-
{
255-
expr = e_push_expr(arena, E_ExprKind_LeafU64, 0);
256-
expr->value.u64 = accel->props.modified;
257-
}
258-
else if(str8_match(name, str8_lit("creation_time"), 0))
259-
{
260-
expr = e_push_expr(arena, E_ExprKind_LeafU64, 0);
261-
expr->value.u64 = accel->props.created;
262-
}
263-
else if(str8_match(name, str8_lit("data"), 0))
264-
{
265-
expr = e_push_expr(arena, E_ExprKind_LeafOffset, 0);
266-
expr->space = e_space_make(E_SpaceKind_HashStoreKey);
267-
expr->space.u128 = fs_key_from_path_range(accel->file_path, r1u64(0, max_U64));
268-
expr->type_key = e_type_key_cons_array(e_type_key_basic(E_TypeKind_U8), accel->props.size);
269-
}
270-
string = push_str8f(arena, ".%S", name);
285+
expr = e_push_expr(arena, E_ExprKind_MemberAccess, 0);
286+
E_Expr *rhs = e_push_expr(arena, E_ExprKind_LeafMember, 0);
287+
rhs->string = push_str8_copy(arena, name);
288+
e_expr_push_child(expr, e_expr_ref(arena, lhs));
289+
e_expr_push_child(expr, rhs);
271290
}
272291
exprs[out_idx] = expr;
273292
exprs_strings[out_idx] = string;
@@ -401,6 +420,7 @@ e_lookup_rule_map_make(Arena *arena, U64 slots_count)
401420
.range = E_LOOKUP_RANGE_FUNCTION_NAME(folder));
402421
e_lookup_rule_map_insert_new(arena, &map, str8_lit("file"),
403422
.info = E_LOOKUP_INFO_FUNCTION_NAME(file),
423+
.access = E_LOOKUP_ACCESS_FUNCTION_NAME(file),
404424
.range = E_LOOKUP_RANGE_FUNCTION_NAME(file));
405425
e_lookup_rule_map_insert_new(arena, &map, str8_lit("slice"),
406426
.info = E_LOOKUP_INFO_FUNCTION_NAME(slice),
@@ -2203,7 +2223,7 @@ E_IRGEN_FUNCTION_DEF(default)
22032223
//- rjf: leaf file paths
22042224
case E_ExprKind_LeafFilePath:
22052225
{
2206-
FileProperties props = fs_properties_from_path(expr->string);
2226+
FileProperties props = os_properties_from_file_path(expr->string);
22072227
if(props.flags & FilePropertyFlag_IsFolder)
22082228
{
22092229
E_Space space = e_space_make(E_SpaceKind_FileSystem);
@@ -2213,6 +2233,11 @@ E_IRGEN_FUNCTION_DEF(default)
22132233
}
22142234
else
22152235
{
2236+
E_Space space = e_space_make(E_SpaceKind_FileSystem);
2237+
result.root = e_irtree_set_space(arena, space, e_irtree_const_u(arena, e_id_from_string(expr->string)));
2238+
result.type_key = e_type_key_cons(.kind = E_TypeKind_Set, .name = str8_lit("file"));
2239+
result.mode = E_Mode_Value;
2240+
#if 0
22162241
U128 key = fs_key_from_path_range(expr->string, r1u64(0, max_U64));
22172242
E_Space space = {E_SpaceKind_HashStoreKey, .u128 = key};
22182243
U64 size = props.size;
@@ -2222,6 +2247,7 @@ E_IRGEN_FUNCTION_DEF(default)
22222247
result.root->string = push_str8_copy(arena, expr->string);
22232248
result.type_key = e_type_key_cons_array(e_type_key_basic(E_TypeKind_U8), size);
22242249
result.mode = E_Mode_Offset;
2250+
#endif
22252251
}
22262252
}break;
22272253

src/eval_visualization/eval_visualization_core.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,14 @@ ev_block_tree_from_exprs(Arena *arena, EV_View *view, String8 filter, E_ExprChai
584584
expansion_row_count = expand_info.row_count;
585585
}
586586

587+
// rjf: determine if this expansion supports child expansions
588+
B32 allow_child_expansions = 1;
589+
if(expand_info.single_item)
590+
{
591+
// NOTE(rjf): for now, just plugging in the heuristic of "is this a single row (a.k.a. visualizer)?"
592+
allow_child_expansions = 0;
593+
}
594+
587595
// rjf: generate block for expansion
588596
EV_Block *expansion_block = &ev_nil_block;
589597
if(expansion_row_count != 0)
@@ -612,7 +620,7 @@ ev_block_tree_from_exprs(Arena *arena, EV_View *view, String8 filter, E_ExprChai
612620
U64 child_count = 0;
613621
EV_Key *child_keys = 0;
614622
U64 *child_nums = 0;
615-
if(!child_count && !expand_info.rows_default_expanded && expand_node != 0 && expansion_row_count != 0)
623+
if(allow_child_expansions && !child_count && !expand_info.rows_default_expanded && expand_node != 0 && expansion_row_count != 0)
616624
{
617625
// rjf: count children
618626
for(EV_ExpandNode *child = expand_node->first; child != 0; child = child->next, child_count += 1){}
@@ -659,7 +667,7 @@ ev_block_tree_from_exprs(Arena *arena, EV_View *view, String8 filter, E_ExprChai
659667
}
660668

661669
// rjf: gather children expansions from inverse of expansion state
662-
if(!child_count && (expand_info.rows_default_expanded || (expand_node == 0 && !expand_info.rows_default_expanded)))
670+
if(allow_child_expansions && !child_count && (expand_info.rows_default_expanded || (expand_node == 0 && !expand_info.rows_default_expanded)))
663671
{
664672
child_count = expand_info.row_count;
665673
child_keys = push_array(scratch.arena, EV_Key, child_count);

src/raddbg/raddbg_core.c

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3010,7 +3010,7 @@ rd_eval_space_read(void *u, E_Space space, void *out, Rng1U64 range)
30103010
B32 result = 0;
30113011
switch(space.kind)
30123012
{
3013-
//- rjf: filesystem reads
3013+
//- rjf: reads from hash store key
30143014
case E_SpaceKind_HashStoreKey:
30153015
{
30163016
U128 key = space.u128;
@@ -3029,6 +3029,27 @@ rd_eval_space_read(void *u, E_Space space, void *out, Rng1U64 range)
30293029
hs_scope_close(scope);
30303030
}break;
30313031

3032+
//- rjf: file reads
3033+
case E_SpaceKind_File:
3034+
{
3035+
U64 file_path_string_id = space.u64_0;
3036+
String8 file_path = e_string_from_id(file_path_string_id);
3037+
U128 key = fs_key_from_path_range(file_path, range);
3038+
U128 hash = hs_hash_from_key(key, 0);
3039+
HS_Scope *scope = hs_scope_open();
3040+
{
3041+
String8 data = hs_data_from_hash(scope, hash);
3042+
Rng1U64 legal_range = r1u64(0, data.size);
3043+
Rng1U64 read_range = intersect_1u64(range, legal_range);
3044+
if(read_range.min < read_range.max)
3045+
{
3046+
result = 1;
3047+
MemoryCopy(out, data.str + read_range.min, dim_1u64(read_range));
3048+
}
3049+
}
3050+
hs_scope_close(scope);
3051+
}break;
3052+
30323053
//- rjf: interior control entity reads (inside process address space or thread register block)
30333054
case RD_EvalSpaceKind_CtrlEntity:
30343055
{
@@ -3301,6 +3322,12 @@ rd_key_from_eval_space_range(E_Space space, Rng1U64 range, B32 zero_terminated)
33013322
{
33023323
result = space.u128;
33033324
}break;
3325+
case E_SpaceKind_File:
3326+
{
3327+
U64 file_path_string_id = space.u64_0;
3328+
String8 file_path = e_string_from_id(file_path_string_id);
3329+
result = fs_key_from_path_range(file_path, range);
3330+
}break;
33043331
case RD_EvalSpaceKind_CtrlEntity:
33053332
{
33063333
CTRL_Entity *entity = rd_ctrl_entity_from_eval_space(space);
@@ -3323,19 +3350,21 @@ rd_whole_range_from_eval_space(E_Space space)
33233350
{
33243351
case E_SpaceKind_HashStoreKey:
33253352
{
3326-
HS_Scope *scope = hs_scope_open();
3327-
U128 hash = {0};
3328-
for(U64 idx = 0; idx < 2; idx += 1)
3353+
U128 key = space.u128;
3354+
U128 hash = hs_hash_from_key(key, 0);
3355+
HS_Scope *hs_scope = hs_scope_open();
33293356
{
3330-
hash = hs_hash_from_key(space.u128, idx);
3331-
if(!u128_match(hash, u128_zero()))
3332-
{
3333-
break;
3334-
}
3357+
String8 data = hs_data_from_hash(hs_scope, hash);
3358+
result = r1u64(0, data.size);
33353359
}
3336-
String8 data = hs_data_from_hash(scope, hash);
3337-
result = r1u64(0, data.size);
3338-
hs_scope_close(scope);
3360+
hs_scope_close(hs_scope);
3361+
}break;
3362+
case E_SpaceKind_File:
3363+
{
3364+
U64 file_path_string_id = space.u64_0;
3365+
String8 file_path = e_string_from_id(file_path_string_id);
3366+
FileProperties props = os_properties_from_file_path(file_path);
3367+
result = r1u64(0, props.size);
33393368
}break;
33403369
case RD_EvalSpaceKind_CtrlEntity:
33413370
{
@@ -3463,17 +3492,33 @@ rd_commit_eval_value_string(E_Eval dst_eval, String8 string, B32 string_needs_un
34633492

34643493
//- rjf: eval <-> file path
34653494

3495+
internal String8
3496+
rd_file_path_from_eval(Arena *arena, E_Eval eval)
3497+
{
3498+
String8 result = {0};
3499+
switch(eval.space.kind)
3500+
{
3501+
default:{}break;
3502+
case E_SpaceKind_File:
3503+
{
3504+
result = push_str8_copy(arena, e_string_from_id(eval.space.u64_0));
3505+
}break;
3506+
case E_SpaceKind_FileSystem:
3507+
{
3508+
result = push_str8_copy(arena, e_string_from_id(eval.value.u64));
3509+
}break;
3510+
}
3511+
return result;
3512+
}
3513+
34663514
internal String8
34673515
rd_file_path_from_eval_string(Arena *arena, String8 string)
34683516
{
34693517
String8 result = {0};
34703518
{
34713519
Temp scratch = scratch_begin(&arena, 1);
3472-
E_Expr *expr = e_parse_expr_from_text(scratch.arena, string).exprs.last;
3473-
if(expr->kind == E_ExprKind_LeafFilePath)
3474-
{
3475-
result = raw_from_escaped_str8(arena, expr->string);
3476-
}
3520+
E_Eval eval = e_eval_from_string(scratch.arena, string);
3521+
result = rd_file_path_from_eval(arena, eval);
34773522
scratch_end(scratch);
34783523
}
34793524
return result;
@@ -3484,7 +3529,7 @@ rd_eval_string_from_file_path(Arena *arena, String8 string)
34843529
{
34853530
Temp scratch = scratch_begin(&arena, 1);
34863531
String8 string_escaped = escaped_from_raw_str8(scratch.arena, string);
3487-
String8 result = push_str8f(arena, "file:\"%S\"", string_escaped);
3532+
String8 result = push_str8f(arena, "file:\"%S\".data", string_escaped);
34883533
scratch_end(scratch);
34893534
return result;
34903535
}
@@ -3933,9 +3978,11 @@ internal TXT_LangKind
39333978
rd_lang_kind_from_eval_tag(E_Eval eval, E_Expr *tag)
39343979
{
39353980
TXT_LangKind lang_kind = TXT_LangKind_Null;
3936-
if(eval.exprs.last->kind == E_ExprKind_LeafFilePath)
3981+
Temp scratch = scratch_begin(0, 0);
3982+
String8 file_path = rd_file_path_from_eval(scratch.arena, eval);
3983+
if(file_path.size != 0)
39373984
{
3938-
lang_kind = txt_lang_kind_from_extension(str8_skip_last_dot(eval.exprs.last->string));
3985+
lang_kind = txt_lang_kind_from_extension(str8_skip_last_dot(file_path));
39393986
}
39403987
else for(E_Expr *param = tag->first->next; param != &e_expr_nil; param = param->next)
39413988
{
@@ -3945,6 +3992,7 @@ rd_lang_kind_from_eval_tag(E_Eval eval, E_Expr *tag)
39453992
break;
39463993
}
39473994
}
3995+
scratch_end(scratch);
39483996
return lang_kind;
39493997
}
39503998

src/raddbg/raddbg_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,7 @@ internal Rng1U64 rd_whole_range_from_eval_space(E_Space space);
10371037
internal B32 rd_commit_eval_value_string(E_Eval dst_eval, String8 string, B32 string_needs_unescaping);
10381038

10391039
//- rjf: eval <-> file path
1040+
internal String8 rd_file_path_from_eval(Arena *arena, E_Eval eval);
10401041
internal String8 rd_file_path_from_eval_string(Arena *arena, String8 string);
10411042
internal String8 rd_eval_string_from_file_path(Arena *arena, String8 string);
10421043

src/raddbg/raddbg_views.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2878,7 +2878,7 @@ RD_VIEW_UI_FUNCTION_DEF(watch)
28782878
RD_Cfg *expr = rd_cfg_child_from_string_or_alloc(view, str8_lit("expression"));
28792879
rd_cfg_new(expr, e_string_from_expr(scratch.arena, cell_info.eval.exprs.last));
28802880
rd_cfg_new(view, str8_lit("selected"));
2881-
RD_RegsScope(.view = view->id)
2881+
RD_RegsScope(.view = view->id, .file_path = rd_file_path_from_eval(scratch.arena, cell_info.eval))
28822882
UI_PermissionFlags(UI_PermissionFlag_Clicks|UI_PermissionFlag_ScrollX)
28832883
UI_Flags(0)
28842884
{

0 commit comments

Comments
 (0)