meta-expr type operators, for meta-evaluations, to annotate source expression strings of evaluations

This commit is contained in:
Ryan Fleury
2025-04-14 15:21:46 -07:00
parent 8e13f8162a
commit db381db85d
8 changed files with 85 additions and 8 deletions
+1
View File
@@ -74,6 +74,7 @@ E_TypeKindTable:
{Set "set" 0 }
{Lens "lens" 0 }
{LensSpec "lens_spec" 0 }
{MetaExpr "meta_expr" 0 }
}
@table(name op_kind precedence op_pre op_sep op_pos op_chain)
+21 -1
View File
@@ -1338,7 +1338,8 @@ e_type_unwrap(E_TypeKey key)
if((E_TypeKind_FirstIncomplete <= kind && kind <= E_TypeKind_LastIncomplete) ||
kind == E_TypeKind_Modifier ||
kind == E_TypeKind_Alias ||
kind == E_TypeKind_Lens)
kind == E_TypeKind_Lens ||
kind == E_TypeKind_MetaExpr)
{
result = e_type_direct_from_key(result);
}
@@ -1800,6 +1801,12 @@ e_type_lhs_string_from_key(Arena *arena, E_TypeKey key, String8List *out, U32 pr
}
str8_list_push(arena, out, str8_lit("::*"));
}break;
case E_TypeKind_MetaExpr:
{
E_TypeKey direct = e_type_direct_from_key(key);
e_type_lhs_string_from_key(arena, direct, out, prec, skip_return);
}break;
}
}
@@ -1874,6 +1881,12 @@ e_type_rhs_string_from_key(Arena *arena, E_TypeKey key, String8List *out, U32 pr
E_TypeKey direct = e_type_direct_from_key(key);
e_type_rhs_string_from_key(arena, direct, out, 2);
}break;
case E_TypeKind_MetaExpr:
{
E_TypeKey direct = e_type_direct_from_key(key);
e_type_rhs_string_from_key(arena, direct, out, prec);
}break;
}
}
@@ -1947,6 +1960,13 @@ e_default_expansion_type_from_key(E_TypeKey root_key)
done = 0;
}
//- rjf: if we have meta-expression tags in the type chain, defer
// to the next type in the chain.
else if(kind == E_TypeKind_MetaExpr)
{
done = 0;
}
//- rjf: if we've reached a struct-like, then we can use that for
// struct-like expansion.
else if(kind == E_TypeKind_Struct ||
+4 -2
View File
@@ -14,7 +14,7 @@ str8_lit_comp("CharLiteral"),
str8_lit_comp("Symbol"),
};
String8 e_type_kind_basic_string_table[58] =
String8 e_type_kind_basic_string_table[59] =
{
str8_lit_comp(""),
str8_lit_comp("void"),
@@ -74,9 +74,10 @@ str8_lit_comp("variadic"),
str8_lit_comp("set"),
str8_lit_comp("lens"),
str8_lit_comp("lens_spec"),
str8_lit_comp("meta_expr"),
};
U8 e_type_kind_basic_byte_size_table[58] =
U8 e_type_kind_basic_byte_size_table[59] =
{
0,
0,
@@ -136,6 +137,7 @@ U8 e_type_kind_basic_byte_size_table[58] =
0,
0,
0,
0,
};
String8 e_expr_kind_strings[48] =
+3 -2
View File
@@ -77,6 +77,7 @@ E_TypeKind_Variadic,
E_TypeKind_Set,
E_TypeKind_Lens,
E_TypeKind_LensSpec,
E_TypeKind_MetaExpr,
E_TypeKind_COUNT,
E_TypeKind_FirstBasic = E_TypeKind_Void,
E_TypeKind_LastBasic = E_TypeKind_ComplexF128,
@@ -162,8 +163,8 @@ E_InterpretationCode_COUNT,
C_LINKAGE_BEGIN
extern String8 e_token_kind_strings[6];
extern String8 e_type_kind_basic_string_table[58];
extern U8 e_type_kind_basic_byte_size_table[58];
extern String8 e_type_kind_basic_string_table[59];
extern U8 e_type_kind_basic_byte_size_table[59];
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];
@@ -1657,6 +1657,38 @@ ev_string_iter_next(Arena *arena, EV_StringIter *it, String8 *out_string)
}
}break;
//////////////////////////
//- rjf: meta-expression tags
//
case E_TypeKind_MetaExpr:
{
if(params->flags & EV_StringFlag_ReadOnlyDisplayRules)
{
switch(task_idx)
{
default:{}break;
case 0:
{
need_pop = 0;
need_new_task = 1;
new_task.params = *params;
new_task.eval = eval;
new_task.eval.irtree.type_key = e_type_direct_from_key(eval.irtree.type_key);
}break;
case 1:
{
E_Type *type = e_type_from_key__cached(type_key);
*out_string = push_str8f(arena, " (%S)", type->name);
}break;
}
}
else
{
E_Type *type = e_type_from_key__cached(type_key);
*out_string = type->name;
}
}break;
//////////////////////////
//- rjf: modifiers
//
+1 -1
View File
@@ -328,7 +328,7 @@ RD_NameSchemaInfo rd_name_schema_info_table[17] =
{str8_lit_comp("settings"), str8_lit_comp("x:\n{\n @default(1) 'hover_animations': bool,\n @default(1) 'press_animations': bool,\n @default(0) 'focus_animations': bool,\n @default(1) 'tooltip_animations': bool,\n @default(1) 'menu_animations': bool,\n @default(1) 'scrolling_animations': bool,\n @default(1) 'background_blur': bool,\n @default(1) 'thread_lines': bool,\n @default(1) 'breakpoint_lines': bool,\n @default(1) 'thread_glow': bool,\n @default(1) 'breakpoint_glow': bool,\n @default(0) 'opaque_backgrounds': bool,\n @default(1) 'smooth_main_text': bool,\n @default(0) 'smooth_code_text': bool,\n @default(1) 'hint_main_text': bool,\n @default(1) 'hint_code_text': bool,\n @default(2) 'tab_width': @range[1, 32] u64,\n @can_be_per_window 'main_font_size': @range[6, 72] u64,\n @can_be_per_window 'code_font_size': @range[1, 32] u64,\n}\n")},
{str8_lit_comp("text"), str8_lit_comp("x:\n{\n 'lang':lang,\n 'size':code_string,\n @default(1) 'show_line_numbers':bool,\n}\n")},
{str8_lit_comp("disasm"), str8_lit_comp("x:\n{\n 'arch': arch,\n 'syntax': dasm_syntax,\n 'size': code_string,\n @default(1) 'show_addresses': bool,\n @default(0) 'show_code_bytes': bool,\n @default(1) 'show_source_lines': bool,\n @default(1) 'show_symbol_names': bool,\n @default(1) 'show_line_numbers': bool,\n}\n")},
{str8_lit_comp("memory"), str8_lit_comp("x:\n{\n 'size': code_string,\n @default(16) 'num_columns': @range[1, 256] u64,\n @default(1) 'bytes_per_cell': @range[1, 16] u64,\n}\n")},
{str8_lit_comp("memory"), str8_lit_comp("x:\n{\n 'size': code_string,\n @default(16) 'num_columns': @range[1, 64] u64,\n @default(1) 'bytes_per_cell': @range[1, 8] u64,\n}\n")},
{str8_lit_comp("bitmap"), str8_lit_comp("x:\n{\n @order(0) 'w': u64,\n @order(1) 'h': u64,\n 'fmt': tex2dformat,\n}\n")},
{str8_lit_comp("geo3d"), str8_lit_comp("x:\n{\n 'count': code_string,\n 'vtx': code_string,\n 'vtx_size': code_string,\n 'yaw': @range[0, 1] f32,\n 'pitch': @range[-0.5, 0] f32,\n 'zoom': @range[0, 100] f32,\n}\n")},
{str8_lit_comp("target"), str8_lit_comp("@commands(enable_cfg, launch_and_run, launch_and_step_into, remove_cfg)\n@collection_commands(add_target)\nx:\n{\n 'label': code_string,\n 'executable': path,\n 'arguments': string,\n 'working_directory': path,\n 'entry_point': code_string,\n 'stdout_path': path,\n 'stderr_path': path,\n 'stdin_path': path,\n 'environment': query,\n 'debug_subprocesses': bool,\n @no_expand @default(0) 'enabled': bool,\n}\n")},
+2 -2
View File
@@ -205,8 +205,8 @@ RD_VocabTable:
x:
{
'size': code_string,
@default(16) 'num_columns': @range[1, 256] u64,
@default(1) 'bytes_per_cell': @range[1, 16] u64,
@default(16) 'num_columns': @range[1, 64] u64,
@default(1) 'bytes_per_cell': @range[1, 8] u64,
}
```
}
+21
View File
@@ -367,15 +367,36 @@ E_TYPE_ACCESS_FUNCTION_DEF(schema)
//- rjf: catchall cases
else if(str8_match(child_schema->first->string, str8_lit("u64"), 0))
{
Temp scratch = scratch_begin(&arena, 1);
child_type_key = e_type_key_basic(E_TypeKind_U64);
E_Expr *expr = e_parse_expr_from_text(scratch.arena, child->first->string).exprs.first;
if(expr->kind != E_ExprKind_LeafU64)
{
child_type_key = e_type_key_cons(.kind = E_TypeKind_MetaExpr, .name = child->first->string, .direct_key = child_type_key);
}
scratch_end(scratch);
}
else if(str8_match(child_schema->first->string, str8_lit("f32"), 0))
{
Temp scratch = scratch_begin(&arena, 1);
child_type_key = e_type_key_basic(E_TypeKind_F32);
E_Expr *expr = e_parse_expr_from_text(scratch.arena, child->first->string).exprs.first;
if(expr->kind != E_ExprKind_LeafF32 && expr->kind != E_ExprKind_LeafF64)
{
child_type_key = e_type_key_cons(.kind = E_TypeKind_MetaExpr, .name = child->first->string, .direct_key = child_type_key);
}
scratch_end(scratch);
}
else if(str8_match(child_schema->first->string, str8_lit("bool"), 0))
{
Temp scratch = scratch_begin(&arena, 1);
child_type_key = e_type_key_basic(E_TypeKind_Bool);
E_Expr *expr = e_parse_expr_from_text(scratch.arena, child->first->string).exprs.first;
if(expr->kind != E_ExprKind_LeafU64)
{
child_type_key = e_type_key_cons(.kind = E_TypeKind_MetaExpr, .name = child->first->string, .direct_key = child_type_key);
}
scratch_end(scratch);
}
else if(str8_match(child_schema->first->string, str8_lit("vaddr_range"), 0))
{