interval lens, to generate an expansion of N things, to use w/ tables

This commit is contained in:
Ryan Fleury
2025-04-17 13:46:06 -07:00
parent a2047619c4
commit 751f3708e7
4 changed files with 64 additions and 10 deletions
+31
View File
@@ -2281,6 +2281,37 @@ E_TYPE_EXPAND_NUM_FROM_ID_FUNCTION_DEF(identity)
return id;
}
////////////////////////////////
//~ rjf: (Built-In Type Hooks) `sequence` lens
E_TYPE_EXPAND_INFO_FUNCTION_DEF(sequence)
{
E_Type *type = e_type_from_key__cached(irtree->type_key);
U64 count = 0;
{
Temp scratch = scratch_begin(&arena, 1);
E_OpList count_oplist = e_oplist_from_irtree(scratch.arena, irtree->root);
String8 count_bytecode = e_bytecode_from_oplist(scratch.arena, &count_oplist);
E_Interpretation count_interpret = e_interpret(count_bytecode);
E_Value count_value = count_interpret.value;
count = count_value.u64;
scratch_end(scratch);
}
E_TypeExpandInfo info = {0, count};
return info;
}
E_TYPE_EXPAND_RANGE_FUNCTION_DEF(sequence)
{
U64 read_range_count = dim_1u64(idx_range);
for(U64 idx = 0; idx < read_range_count; idx += 1)
{
E_Expr *expr = e_push_expr(arena, E_ExprKind_LeafU64, 0);
expr->value.u64 = idx_range.min + idx;
exprs_out[idx] = expr;
}
}
////////////////////////////////
//~ rjf: (Built-In Type Hooks) `array` lens
+6
View File
@@ -309,6 +309,12 @@ E_TYPE_EXPAND_RANGE_FUNCTION_DEF(default);
E_TYPE_EXPAND_ID_FROM_NUM_FUNCTION_DEF(identity);
E_TYPE_EXPAND_NUM_FROM_ID_FUNCTION_DEF(identity);
////////////////////////////////
//~ rjf: (Built-In Type Hooks) `sequence` lens
E_TYPE_EXPAND_INFO_FUNCTION_DEF(sequence);
E_TYPE_EXPAND_RANGE_FUNCTION_DEF(sequence);
////////////////////////////////
//~ rjf: (Built-In Type Hooks) `array` lens