Skip to content

Commit aac93b5

Browse files
committed
move over all expansion view rules to new eval-system lookup hooks; eliminate most of old hooks
1 parent b1829af commit aac93b5

File tree

16 files changed

+859
-801
lines changed

16 files changed

+859
-801
lines changed

src/ctrl/ctrl.mdesk

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
////////////////////////////////
55
//~ rjf: Entity Kinds
66

7-
@table(name display_string)
7+
@table(name code_name display_string)
88
CTRL_EntityKindTable:
99
{
10-
{Root "Root" }
11-
{Machine "Machine" }
12-
{Process "Process" }
13-
{Thread "Thread" }
14-
{Module "Module" }
15-
{EntryPoint "Entry Point" }
16-
{DebugInfoPath "Debug Info Path" }
17-
{PendingThreadName "Pending Thread Name" }
10+
{Root root "Root" }
11+
{Machine machine "Machine" }
12+
{Process process "Process" }
13+
{Thread thread "Thread" }
14+
{Module module "Module" }
15+
{EntryPoint entry_point "Entry Point" }
16+
{DebugInfoPath debug_info_path "Debug Info Path" }
17+
{PendingThreadName pending_thread_name "Pending Thread Name" }
1818
}
1919

2020
@enum CTRL_EntityKind:
@@ -24,6 +24,12 @@ CTRL_EntityKindTable:
2424
COUNT,
2525
}
2626

27+
@data(String8) ctrl_entity_kind_code_name_table:
28+
{
29+
`{0}`,
30+
@expand(CTRL_EntityKindTable a) `str8_lit_comp("$(a.code_name)")`
31+
}
32+
2733
@data(String8) ctrl_entity_kind_display_string_table:
2834
{
2935
`{0}`,

src/ctrl/ctrl_core.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ ctrl_string_from_msg_kind(CTRL_MsgKind kind)
9191
return result;
9292
}
9393

94+
internal CTRL_EntityKind
95+
ctrl_entity_kind_from_string(String8 string)
96+
{
97+
CTRL_EntityKind result = CTRL_EntityKind_Null;
98+
for EachNonZeroEnumVal(CTRL_EntityKind, k)
99+
{
100+
if(str8_match(ctrl_entity_kind_code_name_table[k], string, 0))
101+
{
102+
result = k;
103+
break;
104+
}
105+
}
106+
return result;
107+
}
108+
94109
////////////////////////////////
95110
//~ rjf: Machine/Handle Pair Type Functions
96111

src/ctrl/ctrl_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,7 @@ internal U64 ctrl_hash_from_handle(CTRL_Handle handle);
951951
internal CTRL_EventCause ctrl_event_cause_from_dmn_event_kind(DMN_EventKind event_kind);
952952
internal String8 ctrl_string_from_event_kind(CTRL_EventKind kind);
953953
internal String8 ctrl_string_from_msg_kind(CTRL_MsgKind kind);
954+
internal CTRL_EntityKind ctrl_entity_kind_from_string(String8 string);
954955

955956
////////////////////////////////
956957
//~ rjf: Handle Type Functions

src/ctrl/generated/ctrl.meta.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
//- GENERATED CODE
55

66
C_LINKAGE_BEGIN
7+
String8 ctrl_entity_kind_code_name_table[9] =
8+
{
9+
{0},
10+
str8_lit_comp("root"),
11+
str8_lit_comp("machine"),
12+
str8_lit_comp("process"),
13+
str8_lit_comp("thread"),
14+
str8_lit_comp("module"),
15+
str8_lit_comp("entry_point"),
16+
str8_lit_comp("debug_info_path"),
17+
str8_lit_comp("pending_thread_name"),
18+
};
19+
720
String8 ctrl_entity_kind_display_string_table[9] =
821
{
922
{0},

src/ctrl/generated/ctrl.meta.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ CTRL_ExceptionCodeKind_COUNT,
6464
} CTRL_ExceptionCodeKind;
6565

6666
C_LINKAGE_BEGIN
67+
extern String8 ctrl_entity_kind_code_name_table[9];
6768
extern String8 ctrl_entity_kind_display_string_table[9];
6869
extern U32 ctrl_exception_code_kind_code_table[38];
6970
extern String8 ctrl_exception_code_kind_display_string_table[38];

src/eval/eval_ir.c

Lines changed: 88 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/eval/eval_ir.h

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,31 +66,60 @@ struct E_LookupInfo
6666
U64 idxed_expr_count;
6767
};
6868

69-
typedef struct E_Lookup E_Lookup;
70-
struct E_Lookup
69+
typedef struct E_LookupAccess E_LookupAccess;
70+
struct E_LookupAccess
7171
{
7272
E_IRTreeAndType irtree_and_type;
7373
};
7474

75-
#define E_LOOKUP_INFO_FUNCTION_SIG(name) E_LookupInfo name(Arena *arena, E_Expr *lhs)
75+
typedef struct E_LookupRange E_LookupRange;
76+
struct E_LookupRange
77+
{
78+
U64 exprs_count;
79+
E_Expr **exprs;
80+
String8 *exprs_strings;
81+
};
82+
83+
#define E_LOOKUP_INFO_FUNCTION_SIG(name) E_LookupInfo name(Arena *arena, E_Expr *lhs, String8 filter)
7684
#define E_LOOKUP_INFO_FUNCTION_NAME(name) e_lookup_info_##name
7785
#define E_LOOKUP_INFO_FUNCTION_DEF(name) internal E_LOOKUP_INFO_FUNCTION_SIG(E_LOOKUP_INFO_FUNCTION_NAME(name))
7886
typedef E_LOOKUP_INFO_FUNCTION_SIG(E_LookupInfoFunctionType);
7987

80-
#define E_LOOKUP_FUNCTION_SIG(name) E_Lookup name(Arena *arena, E_ExprKind kind, E_Expr *lhs, E_Expr *rhs, void *user_data)
81-
#define E_LOOKUP_FUNCTION_NAME(name) e_lookup_##name
82-
#define E_LOOKUP_FUNCTION_DEF(name) internal E_LOOKUP_FUNCTION_SIG(E_LOOKUP_FUNCTION_NAME(name))
83-
typedef E_LOOKUP_FUNCTION_SIG(E_LookupFunctionType);
88+
#define E_LOOKUP_ACCESS_FUNCTION_SIG(name) E_LookupAccess name(Arena *arena, E_ExprKind kind, E_Expr *lhs, E_Expr *rhs, void *user_data)
89+
#define E_LOOKUP_ACCESS_FUNCTION_NAME(name) e_lookup_access_##name
90+
#define E_LOOKUP_ACCESS_FUNCTION_DEF(name) internal E_LOOKUP_ACCESS_FUNCTION_SIG(E_LOOKUP_ACCESS_FUNCTION_NAME(name))
91+
typedef E_LOOKUP_ACCESS_FUNCTION_SIG(E_LookupAccessFunctionType);
92+
93+
#define E_LOOKUP_RANGE_FUNCTION_SIG(name) E_LookupRange name(Arena *arena, E_Expr *lhs, Rng1U64 idx_range, void *user_data)
94+
#define E_LOOKUP_RANGE_FUNCTION_NAME(name) e_lookup_range_##name
95+
#define E_LOOKUP_RANGE_FUNCTION_DEF(name) internal E_LOOKUP_RANGE_FUNCTION_SIG(E_LOOKUP_RANGE_FUNCTION_NAME(name))
96+
typedef E_LOOKUP_RANGE_FUNCTION_SIG(E_LookupRangeFunctionType);
97+
98+
#define E_LOOKUP_ID_FROM_NUM_FUNCTION_SIG(name) U64 name(U64 num, void *user_data)
99+
#define E_LOOKUP_ID_FROM_NUM_FUNCTION_NAME(name) e_lookup_id_from_num_##name
100+
#define E_LOOKUP_ID_FROM_NUM_FUNCTION_DEF(name) internal E_LOOKUP_ID_FROM_NUM_FUNCTION_SIG(E_LOOKUP_ID_FROM_NUM_FUNCTION_NAME(name))
101+
typedef E_LOOKUP_ID_FROM_NUM_FUNCTION_SIG(E_LookupIDFromNumFunctionType);
102+
103+
#define E_LOOKUP_NUM_FROM_ID_FUNCTION_SIG(name) U64 name(U64 id, void *user_data)
104+
#define E_LOOKUP_NUM_FROM_ID_FUNCTION_NAME(name) e_lookup_num_from_id_##name
105+
#define E_LOOKUP_NUM_FROM_ID_FUNCTION_DEF(name) internal E_LOOKUP_NUM_FROM_ID_FUNCTION_SIG(E_LOOKUP_NUM_FROM_ID_FUNCTION_NAME(name))
106+
typedef E_LOOKUP_NUM_FROM_ID_FUNCTION_SIG(E_LookupNumFromIDFunctionType);
84107

85108
E_LOOKUP_INFO_FUNCTION_DEF(default);
86-
E_LOOKUP_FUNCTION_DEF(default);
109+
E_LOOKUP_ACCESS_FUNCTION_DEF(default);
110+
E_LOOKUP_RANGE_FUNCTION_DEF(default);
111+
E_LOOKUP_ID_FROM_NUM_FUNCTION_DEF(default);
112+
E_LOOKUP_NUM_FROM_ID_FUNCTION_DEF(default);
87113

88114
typedef struct E_LookupRule E_LookupRule;
89115
struct E_LookupRule
90116
{
91117
String8 name;
92-
E_LookupInfoFunctionType *lookup_info;
93-
E_LookupFunctionType *lookup;
118+
E_LookupInfoFunctionType *info;
119+
E_LookupAccessFunctionType *access;
120+
E_LookupRangeFunctionType *range;
121+
E_LookupIDFromNumFunctionType *id_from_num;
122+
E_LookupNumFromIDFunctionType *num_from_id;
94123
};
95124

96125
typedef struct E_LookupRuleNode E_LookupRuleNode;
@@ -131,7 +160,10 @@ local_persist read_only E_LookupRule e_lookup_rule__default =
131160
{
132161
str8_lit_comp("default"),
133162
E_LOOKUP_INFO_FUNCTION_NAME(default),
134-
E_LOOKUP_FUNCTION_NAME(default),
163+
E_LOOKUP_ACCESS_FUNCTION_NAME(default),
164+
E_LOOKUP_RANGE_FUNCTION_NAME(default),
165+
E_LOOKUP_ID_FROM_NUM_FUNCTION_NAME(default),
166+
E_LOOKUP_NUM_FROM_ID_FUNCTION_NAME(default),
135167
};
136168
global read_only E_IRNode e_irnode_nil = {&e_irnode_nil, &e_irnode_nil, &e_irnode_nil};
137169
thread_static E_IRCtx *e_ir_ctx = 0;
@@ -153,11 +185,9 @@ internal void e_select_ir_ctx(E_IRCtx *ctx);
153185

154186
internal E_LookupRuleMap e_lookup_rule_map_make(Arena *arena, U64 slots_count);
155187
internal void e_lookup_rule_map_insert(Arena *arena, E_LookupRuleMap *map, E_LookupRule *rule);
156-
#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_)})
188+
#define e_lookup_rule_map_insert_new(arena, map, name_, ...) e_lookup_rule_map_insert((arena), (map), &(E_LookupRule){.name = (name_), __VA_ARGS__})
157189

158190
internal E_LookupRule *e_lookup_rule_from_string(String8 string);
159-
E_LOOKUP_INFO_FUNCTION_DEF(default);
160-
E_LOOKUP_FUNCTION_DEF(default);
161191

162192
////////////////////////////////
163193
//~ rjf: IR-ization Functions

0 commit comments

Comments
 (0)