eval stability tests in tester; tear out last pass' view rule extensions

This commit is contained in:
Ryan Fleury
2025-04-07 12:01:41 -07:00
parent 710828c67d
commit ecb3992b93
16 changed files with 324 additions and 241 deletions
+2 -1
View File
@@ -71,7 +71,8 @@ E_TypeKindTable:
{IncompleteEnum "enum" 0 }
{Bitfield "bitfield" 0 }
{Variadic "variadic" 0 }
{Stub "stub" 0 }
{Set "set" 0 }
{Lens "lens" 0 }
}
@table(name op_kind precedence op_pre op_sep op_pos)
+131 -3
View File
@@ -17,7 +17,6 @@ e_eval_from_exprs(Arena *arena, E_ExprChain exprs)
{
ProfBeginFunction();
E_IRTreeAndType irtree = e_irtree_and_type_from_expr(arena, exprs.last);
E_LookupRuleTagPair lookup = e_lookup_rule_tag_pair_from_expr_irtree(exprs.last, &irtree);
E_OpList oplist = e_oplist_from_irtree(arena, irtree.root);
String8 bytecode = e_bytecode_from_oplist(arena, &oplist);
E_Interpretation interp = e_interpret(bytecode);
@@ -28,7 +27,6 @@ e_eval_from_exprs(Arena *arena, E_ExprChain exprs)
.exprs = exprs,
.irtree = irtree,
.bytecode = bytecode,
.lookup_rule_tag = lookup,
.code = interp.code,
};
e_msg_list_concat_in_place(&eval.msgs, &irtree.msgs);
@@ -254,4 +252,134 @@ e_value_from_expr(E_Expr *expr)
E_Value result = value_eval.value;
scratch_end(scratch);
return result;
}
}
////////////////////////////////
//~ rjf: Debug Logging Functions
internal String8
e_debug_log_from_expr_string(Arena *arena, String8 string)
{
Temp scratch = scratch_begin(&arena, 1);
char *indent_spaces = " ";
String8List strings = {0};
//- rjf: begin expression
String8 expr_text = string;
str8_list_pushf(scratch.arena, &strings, "`%S`\n", expr_text);
//- rjf: tokenize
E_TokenArray tokens = e_token_array_from_text(scratch.arena, expr_text);
str8_list_pushf(scratch.arena, &strings, " tokens:\n");
for EachIndex(idx, tokens.count)
{
E_Token token = tokens.v[idx];
String8 token_string = str8_substr(expr_text, token.range);
str8_list_pushf(scratch.arena, &strings, " %S: `%S`\n", e_token_kind_strings[token.kind], token_string);
}
//- rjf: parse
E_Parse parse = e_parse_expr_from_text_tokens(scratch.arena, expr_text, tokens);
{
typedef struct Task Task;
struct Task
{
Task *next;
E_Expr *expr;
S32 indent;
};
str8_list_pushf(scratch.arena, &strings, " expr:\n");
Task start_task = {0, parse.exprs.first, 2};
Task *first_task = &start_task;
for(Task *t = first_task; t != 0; t = t->next)
{
E_Expr *expr = t->expr;
str8_list_pushf(scratch.arena, &strings, "%.*s%S", (int)t->indent*4, indent_spaces, e_expr_kind_strings[expr->kind]);
switch(expr->kind)
{
default:{}break;
case E_ExprKind_LeafU64:
{
str8_list_pushf(scratch.arena, &strings, " (%I64u)", expr->value.u64);
}break;
case E_ExprKind_LeafIdentifier:
{
str8_list_pushf(scratch.arena, &strings, " (`%S`)", expr->string);
}break;
}
str8_list_pushf(scratch.arena, &strings, "\n");
Task *last_task = t;
for(E_Expr *child = expr->first; child != &e_expr_nil; child = child->next)
{
Task *task = push_array(scratch.arena, Task, 1);
task->next = last_task->next;
last_task->next = task;
task->expr = child;
task->indent = t->indent+1;
last_task = task;
}
}
}
//- rjf: type
E_IRTreeAndType irtree = e_irtree_and_type_from_expr(scratch.arena, parse.exprs.first);
{
str8_list_pushf(scratch.arena, &strings, " type:\n");
S32 indent = 2;
for(E_TypeKey type_key = irtree.type_key;
!e_type_key_match(e_type_key_zero(), type_key);
type_key = e_type_direct_from_key(type_key),
indent += 1)
{
E_Type *type = e_type_from_key(scratch.arena, type_key);
str8_list_pushf(scratch.arena, &strings, "%.*s%S\n", (int)indent*4, indent_spaces, e_type_kind_basic_string_table[type->kind]);
}
}
//- rjf: irtree
{
typedef struct Task Task;
struct Task
{
Task *next;
E_IRNode *irnode;
S32 indent;
};
str8_list_pushf(scratch.arena, &strings, " ir_tree:\n");
Task start_task = {0, irtree.root, 2};
Task *first_task = &start_task;
for(Task *t = first_task; t != 0; t = t->next)
{
E_IRNode *irnode = t->irnode;
str8_list_pushf(scratch.arena, &strings, "%.*s", (int)t->indent*4, indent_spaces);
switch(irnode->op)
{
default:{}break;
#define X(name) case RDI_EvalOp_##name:{str8_list_pushf(scratch.arena, &strings, #name);}break;
RDI_EvalOp_XList
#undef X
}
if(irnode->value.u64 != 0)
{
str8_list_pushf(scratch.arena, &strings, " (%I64u)", irnode->value.u64);
}
str8_list_pushf(scratch.arena, &strings, "\n");
Task *last_task = t;
for(E_IRNode *child = irnode->first; child != &e_irnode_nil; child = child->next)
{
Task *task = push_array(scratch.arena, Task, 1);
task->next = last_task->next;
last_task->next = task;
task->irnode = child;
task->indent = t->indent+1;
last_task = task;
}
}
}
str8_list_pushf(scratch.arena, &strings, "\n");
String8 result = str8_list_join(arena, &strings, 0);
scratch_end(scratch);
return result;
}
+5 -1
View File
@@ -15,7 +15,6 @@ struct E_Eval
E_ExprChain exprs;
E_IRTreeAndType irtree;
String8 bytecode;
E_LookupRuleTagPair lookup_rule_tag;
E_InterpretationCode code;
E_MsgList msgs;
};
@@ -34,4 +33,9 @@ internal E_Value e_value_from_string(String8 string);
internal E_Value e_value_from_stringf(char *fmt, ...);
internal E_Value e_value_from_expr(E_Expr *expr);
////////////////////////////////
//~ rjf: Debug Logging Functions
internal String8 e_debug_log_from_expr_string(Arena *arena, String8 string);
#endif // EVAL_BUNDLES_H
+16 -45
View File
@@ -69,6 +69,7 @@ e_select_ir_ctx(E_IRCtx *ctx)
e_ir_state->arena_eval_start_pos = arena_pos(arena);
}
arena_pop_to(e_ir_state->arena, e_ir_state->arena_eval_start_pos);
if(ctx->modules == 0) { ctx->modules = &e_module_nil; }
if(ctx->primary_module == 0) { ctx->primary_module = &e_module_nil; }
if(ctx->regs_map == 0) { ctx->regs_map = &e_string2num_map_nil; }
if(ctx->reg_alias_map == 0) { ctx->reg_alias_map = &e_string2num_map_nil; }
@@ -97,8 +98,7 @@ e_select_ir_ctx(E_IRCtx *ctx)
for EachElement(idx, builtin_view_rule_names)
{
E_Expr *expr = e_push_expr(e_ir_state->arena, E_ExprKind_LeafOffset, 0);
expr->type_key = e_type_key_cons(.kind = E_TypeKind_Stub, .name = str8_lit("view_rule"));
expr->value.u64 = e_id_from_string(builtin_view_rule_names[idx]);
expr->type_key = e_type_key_cons(.kind = E_TypeKind_Lens, .name = builtin_view_rule_names[idx]);
e_string2expr_map_insert(e_ir_state->arena, ctx->macro_map, builtin_view_rule_names[idx], expr);
}
}
@@ -192,7 +192,7 @@ E_LOOKUP_RANGE_FUNCTION_DEF(folder)
String8 folder_name = accel->folders.v[idx - 0];
String8 folder_path = push_str8f(scratch.arena, "%S%s%S", accel->folder_path, accel->folder_path.size != 0 ? "/" : "", folder_name);
expr = e_push_expr(arena, E_ExprKind_LeafValue, 0);
expr->type_key = e_type_key_cons(.kind = E_TypeKind_Stub, .name = str8_lit("folder"));
expr->type_key = e_type_key_cons(.kind = E_TypeKind_Set, .name = str8_lit("folder"));
expr->space = e_space_make(E_SpaceKind_FileSystem);
expr->value.u64 = e_id_from_string(folder_path);
expr_string = push_str8f(arena, "\"%S\"", escaped_from_raw_str8(scratch.arena, folder_name));
@@ -202,7 +202,7 @@ E_LOOKUP_RANGE_FUNCTION_DEF(folder)
String8 file_name = accel->files.v[idx - accel->folders.count];
String8 file_path = push_str8f(scratch.arena, "%S%s%S", accel->folder_path, accel->folder_path.size != 0 ? "/" : "", file_name);
expr = e_push_expr(arena, E_ExprKind_LeafValue, 0);
expr->type_key = e_type_key_cons(.kind = E_TypeKind_Stub, .name = str8_lit("file"));
expr->type_key = e_type_key_cons(.kind = E_TypeKind_Set, .name = str8_lit("file"));
expr->space = e_space_make(E_SpaceKind_FileSystem);
expr->value.u64 = e_id_from_string(file_path);
expr_string = push_str8f(arena, "\"%S\"", escaped_from_raw_str8(scratch.arena, file_name));
@@ -879,7 +879,7 @@ E_LOOKUP_RANGE_FUNCTION_DEF(default)
enum_type_key = lhs_type_key;
do_enum_range = 1;
}
else if(lhs_type_kind == E_TypeKind_Stub)
else if(lhs_type_kind == E_TypeKind_Set)
{
do_index_range = 1;
}
@@ -1818,14 +1818,12 @@ E_IRGEN_FUNCTION_DEF(default)
E_Expr *lhs = expr->first;
E_Expr *rhs = lhs->next;
E_IRTreeAndType lhs_irtree = e_irtree_and_type_from_expr(scratch.arena, lhs);
E_LookupRule *lookup_rule = e_lookup_rule_from_irtree(&lhs_irtree);
ProfScope("lookup via rule '%.*s'", str8_varg(lhs_lookup_rule->name))
E_LookupRule *lookup_rule = &e_lookup_rule__default;
ProfScope("lookup via rule '%.*s'", str8_varg(lookup_rule->name))
{
e_expr_poison(lhs_lookup_rule_and_tag.tag);
E_LookupInfo lookup_info = lhs_lookup_rule_and_tag.rule->info(arena, &lhs_irtree, lhs_lookup_rule_and_tag.tag, str8_zero());
E_LookupAccess lookup_access = lhs_lookup_rule_and_tag.rule->access(arena, expr->kind, lhs, rhs, lhs_lookup_rule_and_tag.tag, lookup_info.user_data);
E_LookupInfo lookup_info = lookup_rule->info(arena, &lhs_irtree, &e_expr_nil, str8_zero());
E_LookupAccess lookup_access = lookup_rule->access(arena, expr->kind, lhs, rhs, &e_expr_nil, lookup_info.user_data);
result = lookup_access.irtree_and_type;
e_expr_unpoison(lhs_lookup_rule_and_tag.tag);
}
scratch_end(scratch);
}break;
@@ -2429,18 +2427,13 @@ E_IRGEN_FUNCTION_DEF(default)
// rjf: map callee -> ir-generation rule
E_IRGenRule *irgen_rule = &e_irgen_rule__default;
{
Temp scratch = scratch_begin(&arena, 1);
E_TypeKey type_key = lhs_irtree.type_key;
E_Type *type = e_type_from_key__cached(type_key);
if(type->kind == E_TypeKind_Stub)
if(type->kind == E_TypeKind_Lens)
{
E_OpList oplist = e_oplist_from_irtree(scratch.arena, lhs_irtree.root);
String8 bytecode = e_bytecode_from_oplist(scratch.arena, &oplist);
E_Interpretation interp = e_interpret(bytecode);
String8 name = e_string_from_id(interp.value.u64);
String8 name = type->name;
irgen_rule = e_irgen_rule_from_string(name);
}
scratch_end(scratch);
}
// rjf: if we have a non-default ir-generation rule, then we can use that
@@ -2451,7 +2444,7 @@ E_IRGEN_FUNCTION_DEF(default)
}
else
{
e_msgf(arena, &result.msgs, E_MsgKind_InterpretationError, expr->location, "Calling this type is not currently supported.");
e_msgf(arena, &result.msgs, E_MsgKind_InterpretationError, expr->location, "Calling this type is not supported.");
}
}break;
@@ -2967,7 +2960,7 @@ E_IRGEN_FUNCTION_DEF(default)
{
E_Space space = e_space_make(E_SpaceKind_FileSystem);
result.root = e_irtree_set_space(arena, space, e_irtree_const_u(arena, e_id_from_string(file_path)));
result.type_key = e_type_key_cons(.kind = E_TypeKind_Stub, .name = str8_lit("file"));
result.type_key = e_type_key_cons(.kind = E_TypeKind_Set, .name = str8_lit("file"));
result.mode = E_Mode_Value;
}
else
@@ -2978,7 +2971,7 @@ E_IRGEN_FUNCTION_DEF(default)
{
E_Space space = e_space_make(E_SpaceKind_FileSystem);
result.root = e_irtree_set_space(arena, space, e_irtree_const_u(arena, e_id_from_string(folder_path)));
result.type_key = e_type_key_cons(.kind = E_TypeKind_Stub, .name = str8_lit("folder"));
result.type_key = e_type_key_cons(.kind = E_TypeKind_Set, .name = str8_lit("folder"));
result.mode = E_Mode_Value;
}
}
@@ -3346,30 +3339,7 @@ e_expr_irext_cast(Arena *arena, E_Expr *rhs, E_IRTreeAndType *rhs_irtree, E_Type
////////////////////////////////
//~ rjf: Expression & IR-Tree => Rules
internal E_LookupRule *
e_lookup_rule_from_irtree(E_IRTreeAndType *irtree)
{
E_LookupRule *rule = &e_lookup_rule__default;
E_TypeKey type_key = irtree->type_key;
E_Type *type = e_type_from_key__cached(type_key);
// rjf: first try implicit stub name -> rule mapping
if(rule == &e_lookup_rule__default && type->kind == E_TypeKind_Stub)
{
String8 name = type->name;
rule = e_lookup_rule_from_string(name);
}
// rjf: try auto hook map
if(rule == &e_lookup_rule__default)
{
E_ExprList tags = e_auto_hook_exprs_from_type_key__cached(irtree->type_key);
}
return rule;
}
#if 0 // TODO(rjf): @eval
internal E_LookupRuleTagPair
e_lookup_rule_tag_pair_from_expr_irtree(E_Expr *expr, E_IRTreeAndType *irtree)
{
@@ -3432,3 +3402,4 @@ e_lookup_rule_tag_pair_from_expr_irtree(E_Expr *expr, E_IRTreeAndType *irtree)
}
return result;
}
#endif
+2 -1
View File
@@ -288,7 +288,8 @@ internal E_Expr *e_expr_irext_cast(Arena *arena, E_Expr *rhs, E_IRTreeAndType *r
////////////////////////////////
//~ rjf: Expression & IR-Tree => Rules
internal E_LookupRule *e_lookup_rule_from_irtree(E_IRTreeAndType *irtree);
#if 0 // TODO(rjf): @eval
internal E_LookupRuleTagPair e_lookup_rule_tag_pair_from_expr_irtree(E_Expr *expr, E_IRTreeAndType *irtree);
#endif
#endif // EVAL_IR_H
+2 -22
View File
@@ -315,7 +315,8 @@ e_select_parse_ctx(E_ParseCtx *ctx)
e_parse_state->arena_eval_start_pos = arena_pos(arena);
}
arena_pop_to(e_parse_state->arena, e_parse_state->arena_eval_start_pos);
if(ctx->primary_module == 0){ ctx->primary_module = &e_module_nil; }
if(ctx->modules == 0) { ctx->modules = &e_module_nil; }
if(ctx->primary_module == 0) { ctx->primary_module = &e_module_nil; }
e_parse_state->ctx = ctx;
}
@@ -408,7 +409,6 @@ e_expr_copy(Arena *arena, E_Expr *src)
E_Expr *dst_parent;
E_Expr *src;
B32 is_ref;
B32 is_tag;
};
Task start_task = {0, &e_expr_nil, src};
Task *first_task = &start_task;
@@ -431,10 +431,6 @@ e_expr_copy(Arena *arena, E_Expr *src)
{
t->dst_parent->ref = dst;
}
else if(t->is_tag)
{
e_expr_push_tag(t->dst_parent, dst);
}
else
{
e_expr_push_child(t->dst_parent, dst);
@@ -1484,22 +1480,6 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray tok
}
}
//- rjf: parse tags
{
if(token.kind == E_TokenKind_Symbol && str8_match(token_string, str8_lit("=>"), 0))
{
it += 1;
E_Parse tags_parse = e_parse_expr_from_text_tokens__prec(arena, text, e_token_array_make_first_opl(it, it_opl), e_max_precedence, max_U64);
e_msg_list_concat_in_place(&result.msgs, &tags_parse.msgs);
it = tags_parse.last_token;
for(E_Expr *tag = tags_parse.exprs.first, *next = &e_expr_nil; tag != &e_expr_nil; tag = next)
{
next = tag->next;
e_expr_push_tag(atom, tag);
}
}
}
// rjf: if we parsed nothing successfully, we're done
if(it == start_it)
{
+2 -1
View File
@@ -235,7 +235,8 @@ e_select_type_ctx(E_TypeCtx *ctx)
e_type_state->arena = arena;
e_type_state->arena_eval_start_pos = arena_pos(e_type_state->arena);
}
if(ctx->primary_module == 0) {ctx->primary_module = &e_module_nil;}
if(ctx->modules == 0) { ctx->modules = &e_module_nil; }
if(ctx->primary_module == 0) { ctx->primary_module = &e_module_nil; }
arena_pop_to(e_type_state->arena, e_type_state->arena_eval_start_pos);
e_type_state->ctx = ctx;
e_type_state->cons_id_gen = 0;
+5 -3
View File
@@ -14,7 +14,7 @@ str8_lit_comp("CharLiteral"),
str8_lit_comp("Symbol"),
};
String8 e_type_kind_basic_string_table[56] =
String8 e_type_kind_basic_string_table[57] =
{
str8_lit_comp(""),
str8_lit_comp("void"),
@@ -71,10 +71,11 @@ str8_lit_comp("class"),
str8_lit_comp("enum"),
str8_lit_comp("bitfield"),
str8_lit_comp("variadic"),
str8_lit_comp("stub"),
str8_lit_comp("set"),
str8_lit_comp("lens"),
};
U8 e_type_kind_basic_byte_size_table[56] =
U8 e_type_kind_basic_byte_size_table[57] =
{
0,
0,
@@ -132,6 +133,7 @@ U8 e_type_kind_basic_byte_size_table[56] =
0,
0,
0,
0,
};
String8 e_expr_kind_strings[48] =
+4 -3
View File
@@ -74,7 +74,8 @@ E_TypeKind_IncompleteClass,
E_TypeKind_IncompleteEnum,
E_TypeKind_Bitfield,
E_TypeKind_Variadic,
E_TypeKind_Stub,
E_TypeKind_Set,
E_TypeKind_Lens,
E_TypeKind_COUNT,
E_TypeKind_FirstBasic = E_TypeKind_Void,
E_TypeKind_LastBasic = E_TypeKind_ComplexF128,
@@ -160,8 +161,8 @@ E_InterpretationCode_COUNT,
C_LINKAGE_BEGIN
extern String8 e_token_kind_strings[6];
extern String8 e_type_kind_basic_string_table[56];
extern U8 e_type_kind_basic_byte_size_table[56];
extern String8 e_type_kind_basic_string_table[57];
extern U8 e_type_kind_basic_byte_size_table[57];
extern String8 e_expr_kind_strings[48];
extern E_OpInfo e_expr_kind_op_info_table[48];
extern String8 e_interpretation_code_display_strings[11];