checkpoint - extend constructed types w/ expression arguments, new 'lens' type operator, which can wrap evaluations of other types, + provide a name/args. e.g., bitmap(256, 256) <- (uint8 *), as a well-formed type. this also is the first step to collapsing all 'expression introspection' paths, and making sure they all compose properly.

This commit is contained in:
Ryan Fleury
2025-04-07 14:57:56 -07:00
parent 97a1003d85
commit b1f17b217c
5 changed files with 157 additions and 112 deletions
+91 -90
View File
@@ -158,6 +158,96 @@ struct E_TypeKeyList
#include "generated/eval.meta.h"
////////////////////////////////
//~ rjf: Token Types
typedef struct E_Token E_Token;
struct E_Token
{
E_TokenKind kind;
Rng1U64 range;
};
typedef struct E_TokenChunkNode E_TokenChunkNode;
struct E_TokenChunkNode
{
E_TokenChunkNode *next;
E_Token *v;
U64 count;
U64 cap;
};
typedef struct E_TokenChunkList E_TokenChunkList;
struct E_TokenChunkList
{
E_TokenChunkNode *first;
E_TokenChunkNode *last;
U64 node_count;
U64 total_count;
};
typedef struct E_TokenArray E_TokenArray;
struct E_TokenArray
{
E_Token *v;
U64 count;
};
////////////////////////////////
//~ rjf: Evaluation Modes
typedef enum E_Mode
{
E_Mode_Null,
E_Mode_Value,
E_Mode_Offset,
}
E_Mode;
////////////////////////////////
//~ rjf: Expression Tree Types
typedef struct E_Expr E_Expr;
struct E_Expr
{
E_Expr *first;
E_Expr *last;
E_Expr *next;
E_Expr *prev;
E_Expr *ref;
void *location;
E_ExprKind kind;
E_Mode mode;
E_Space space;
E_TypeKey type_key;
E_Value value;
String8 string;
String8 qualifier;
String8 bytecode;
};
typedef struct E_ExprChain E_ExprChain;
struct E_ExprChain
{
E_Expr *first;
E_Expr *last;
};
typedef struct E_ExprNode E_ExprNode;
struct E_ExprNode
{
E_ExprNode *next;
E_Expr *v;
};
typedef struct E_ExprList E_ExprList;
struct E_ExprList
{
E_ExprNode *first;
E_ExprNode *last;
U64 count;
};
////////////////////////////////
//~ rjf: Full Extracted Type Information Types
@@ -253,19 +343,9 @@ struct E_Type
E_TypeKey *param_type_keys;
E_Member *members;
E_EnumVal *enum_vals;
E_Expr **args;
};
////////////////////////////////
//~ rjf: Evaluation Modes
typedef enum E_Mode
{
E_Mode_Null,
E_Mode_Value,
E_Mode_Offset,
}
E_Mode;
////////////////////////////////
//~ rjf: Modules
@@ -278,85 +358,6 @@ struct E_Module
E_Space space;
};
////////////////////////////////
//~ rjf: Token Types
typedef struct E_Token E_Token;
struct E_Token
{
E_TokenKind kind;
Rng1U64 range;
};
typedef struct E_TokenChunkNode E_TokenChunkNode;
struct E_TokenChunkNode
{
E_TokenChunkNode *next;
E_Token *v;
U64 count;
U64 cap;
};
typedef struct E_TokenChunkList E_TokenChunkList;
struct E_TokenChunkList
{
E_TokenChunkNode *first;
E_TokenChunkNode *last;
U64 node_count;
U64 total_count;
};
typedef struct E_TokenArray E_TokenArray;
struct E_TokenArray
{
E_Token *v;
U64 count;
};
////////////////////////////////
//~ rjf: Expression Tree Types
typedef struct E_Expr E_Expr;
struct E_Expr
{
E_Expr *first;
E_Expr *last;
E_Expr *next;
E_Expr *prev;
E_Expr *ref;
void *location;
E_ExprKind kind;
E_Mode mode;
E_Space space;
E_TypeKey type_key;
E_Value value;
String8 string;
String8 qualifier;
String8 bytecode;
};
typedef struct E_ExprChain E_ExprChain;
struct E_ExprChain
{
E_Expr *first;
E_Expr *last;
};
typedef struct E_ExprNode E_ExprNode;
struct E_ExprNode
{
E_ExprNode *next;
E_Expr *v;
};
typedef struct E_ExprList E_ExprList;
struct E_ExprList
{
E_ExprNode *first;
E_ExprNode *last;
U64 count;
};
////////////////////////////////
//~ rjf: IR Tree Types
+29 -21
View File
@@ -1210,13 +1210,6 @@ E_IRGEN_FUNCTION_DEF(array)
return result;
}
E_IRGEN_FUNCTION_DEF(view_rule_noop)
{
E_Expr *expr_arg = expr->first->next;
E_IRTreeAndType result = e_irtree_and_type_from_expr(arena, expr_arg);
return result;
}
internal E_IRGenRuleMap
e_irgen_rule_map_make(Arena *arena, U64 slots_count)
{
@@ -2423,24 +2416,39 @@ E_IRGEN_FUNCTION_DEF(default)
{
E_Expr *lhs = expr->first;
E_IRTreeAndType lhs_irtree = e_irtree_and_type_from_expr(arena, lhs);
E_TypeKey lhs_type_key = lhs_irtree.type_key;
E_Type *lhs_type = e_type_from_key__cached(lhs_type_key);
// rjf: map callee -> ir-generation rule
E_IRGenRule *irgen_rule = &e_irgen_rule__default;
// rjf: calling a lens? -> generate IR for the first argument; wrap the type in
// a lens type, which preserves the name & arguments of the lens call expression
if(lhs_type->kind == E_TypeKind_Lens)
{
E_TypeKey type_key = lhs_irtree.type_key;
E_Type *type = e_type_from_key__cached(type_key);
if(type->kind == E_TypeKind_Lens)
Temp scratch = scratch_begin(&arena, 1);
// rjf: generate result via first argument to lens
result = e_irtree_and_type_from_expr(arena, lhs->next);
// rjf: count extra arguments
U64 arg_count = 0;
for(E_Expr *arg = lhs->next->next; arg != &e_expr_nil; arg = arg->next)
{
String8 name = type->name;
irgen_rule = e_irgen_rule_from_string(name);
arg_count += 1;
}
}
// rjf: if we have a non-default ir-generation rule, then we can use that
// to generate the resultant IR tree
if(irgen_rule != &e_irgen_rule__default)
{
result = irgen_rule->irgen(arena, expr);
// rjf: flatten extra arguments
E_Expr **args = push_array(scratch.arena, E_Expr *, arg_count);
{
U64 idx = 0;
for(E_Expr *arg = lhs->next->next; arg != &e_expr_nil; arg = arg->next, idx += 1)
{
args[idx] = arg;
}
}
// rjf: patch resultant type with a lens w/ args, pointing to the original type
result.type_key = e_type_key_cons(.kind = E_TypeKind_Lens, .count = arg_count, .args = args, .direct_key = result.type_key, .name = lhs_type->name);
scratch_end(scratch);
}
else
{
+36
View File
@@ -418,6 +418,14 @@ e_type_key_cons_(E_ConsTypeParams *params)
}
node->byte_size = e_type_byte_size_from_key(node->params.direct_key);
}
else if(params->args != 0)
{
node->params.args = push_array(e_type_state->arena, E_Expr *, params->count);
for EachIndex(idx, params->count)
{
node->params.args[idx] = e_expr_copy(e_type_state->arena, params->args[idx]);
}
}
else switch(params->kind)
{
default:
@@ -629,6 +637,15 @@ e_type_from_key(Arena *arena, E_TypeKey key)
switch(type->kind)
{
default:{}break;
case E_TypeKind_Lens:
{
type->args = push_array(arena, E_Expr *, type->count);
MemoryCopy(type->args, node->params.args, sizeof(E_Expr *)*type->count);
for EachIndex(idx, type->count)
{
type->args[idx] = e_expr_copy(arena, type->args[idx]);
}
}break;
case E_TypeKind_Struct:
case E_TypeKind_Union:
case E_TypeKind_Class:
@@ -1686,6 +1703,25 @@ e_type_lhs_string_from_key(Arena *arena, E_TypeKey key, String8List *out, U32 pr
}
}break;
case E_TypeKind_Lens:
{
E_Type *type = e_type_from_key__cached(key);
str8_list_pushf(arena, out, "%S(", type->name);
for EachIndex(idx, type->count)
{
String8 string = e_string_from_expr(arena, type->args[idx]);
str8_list_push(arena, out, string);
if(idx+1 < type->count)
{
str8_list_pushf(arena, out, ", ");
}
}
str8_list_pushf(arena, out, ") <- (");
E_TypeKey direct = e_type_direct_from_key(key);
e_type_lhs_string_from_key(arena, direct, out, 1, skip_return);
str8_list_pushf(arena, out, ")");
}break;
case E_TypeKind_Ptr:
{
E_TypeKey direct = e_type_direct_from_key(key);
+1
View File
@@ -46,6 +46,7 @@ struct E_ConsTypeParams
U64 depth;
E_Member *members;
E_EnumVal *enum_vals;
E_Expr **args;
};
typedef struct E_ConsTypeNode E_ConsTypeNode;
-1
View File
@@ -13912,7 +13912,6 @@ rd_frame(void)
{
for EachElement(idx, view_ui_rule_table)
{
e_irgen_rule_map_insert_new(scratch.arena, e_ir_state->ctx->irgen_rule_map, view_ui_rule_table[idx].name, E_IRGEN_FUNCTION_NAME(view_rule_noop));
rd_view_ui_rule_map_insert(scratch.arena, rd_state->view_ui_rule_map, view_ui_rule_table[idx].name, view_ui_rule_table[idx].ui);
if(view_ui_rule_table[idx].expand != 0)
{