mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-10 15:58:09 +00:00
eval2: function pointer type parsing/compiling
This commit is contained in:
@@ -269,6 +269,13 @@ e2_cons_type_node_from_params(E2_ConsTypeParams *params)
|
||||
hash = u64_hash_from_seed_str8(hash, str8_struct(¶ms->direct));
|
||||
hash = u64_hash_from_seed_str8(hash, str8_struct(¶ms->count));
|
||||
hash = u64_hash_from_seed_str8(hash, str8_struct(¶ms->depth));
|
||||
if(params->param_types != 0)
|
||||
{
|
||||
for EachIndex(idx, params->count)
|
||||
{
|
||||
hash = u64_hash_from_seed_str8(hash, str8_struct(¶ms->param_types[idx]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// rjf: hash -> content slot
|
||||
@@ -299,6 +306,11 @@ e2_cons_type_node_from_params(E2_ConsTypeParams *params)
|
||||
node->id = id;
|
||||
MemoryCopyStruct(&node->params, params);
|
||||
node->params.name = str8_copy(map->arena, node->params.name);
|
||||
if(node->params.param_types != 0)
|
||||
{
|
||||
node->params.param_types = push_array(map->arena, E2_TypeKey, node->params.count);
|
||||
MemoryCopy(node->params.param_types, params->param_types, sizeof(params->param_types[0])*params->count);
|
||||
}
|
||||
// TODO(rjf): double check once we're doing type expression
|
||||
// arguments that we don't need a deep copy of the args here.
|
||||
switch(node->params.kind)
|
||||
@@ -1914,6 +1926,7 @@ e2_parse_from_string(Arena *arena, E2_ParseState *state, B32 identifier_is_type,
|
||||
{
|
||||
E2_ExprKindParseInfo *op_info = &lang_info->expr_kind_parse_infos[idx];
|
||||
if(e2_expr_kind_is_type_expr_table[op_info->expr_kind] &&
|
||||
op_info->sep.size == 0 &&
|
||||
str8_match(op_info->post, token_string, 0))
|
||||
{
|
||||
expr_kind = op_info->expr_kind;
|
||||
@@ -2451,6 +2464,28 @@ e2_compile_from_expr(Arena *arena, E2_CompileState *state, E2_IRNode *resolve_re
|
||||
}
|
||||
}break;
|
||||
|
||||
//- rjf: function type operator
|
||||
case E2_ExprKind_Function:
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
U64 params_count = 0;
|
||||
E2_TypeKey *param_types = 0;
|
||||
if(task->irtree_child_count != 0)
|
||||
{
|
||||
params_count = task->irtree_child_count-1;
|
||||
param_types = push_array(scratch.arena, E2_TypeKey, params_count);
|
||||
U64 idx = 0;
|
||||
for(E2_IRNodePtrNode *n = task->first_irtree_child->next; n != 0; n = n->next, idx += 1)
|
||||
{
|
||||
param_types[idx] = n->v->type_key;
|
||||
}
|
||||
}
|
||||
E2_TypeKey fn_type_key = e2_type_key_cons(E2_TypeKind_Function, .direct = lhs->type_key, .count = params_count, .param_types = param_types);
|
||||
finished_root = e2_irnode(arena);
|
||||
finished_root->type_key = fn_type_key;
|
||||
scratch_end(scratch);
|
||||
}break;
|
||||
|
||||
//- rjf: leaf numerics
|
||||
case E2_ExprKind_Numeric:
|
||||
{
|
||||
|
||||
@@ -156,6 +156,7 @@ struct E2_ConsTypeParams
|
||||
E2_TypeKey direct;
|
||||
U64 count;
|
||||
U64 depth;
|
||||
E2_TypeKey *param_types;
|
||||
struct E2_Expr **args;
|
||||
};
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ E2_ExprKindTable:
|
||||
{Neg 1 0 0 1 }
|
||||
{LogNot 1 0 0 1 }
|
||||
{BitNot 1 0 0 1 }
|
||||
{Mul 1 0 0 2 }
|
||||
{Mul 0 0 0 2 }
|
||||
{Div 1 0 0 2 }
|
||||
{Mod 1 0 0 2 }
|
||||
{Add 1 0 0 2 }
|
||||
@@ -120,6 +120,7 @@ E2_ExprKindParseInfoTable_CLike:
|
||||
{Dot Postfix 1 "" "." "" "" 0}
|
||||
{Index Postfix 1 "" "[" "]" "" 0}
|
||||
{Call Postfix 1 "" "(" ")" "," 0}
|
||||
{Function Postfix 1 "" "(" ")" "," 0}
|
||||
{DerefAsm Prefix 1 "[" "" "]" "" 0}
|
||||
{SizeOf Prefix 1 "sizeof " "" "" "" 0}
|
||||
{TypeOf Prefix 1 "typeof " "" "" "" 0}
|
||||
|
||||
@@ -29,7 +29,7 @@ B8 e2_expr_kind_allow_type_operands_table[44] =
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
@@ -201,11 +201,12 @@ E2_LangInfo e2_lang_kind_info_table[1] =
|
||||
{ArrayCount(e2_expr_kind_parse_info_table__clike), (e2_expr_kind_parse_info_table__clike)},
|
||||
};
|
||||
|
||||
E2_ExprKindParseInfo e2_expr_kind_parse_info_table__clike[38] =
|
||||
E2_ExprKindParseInfo e2_expr_kind_parse_info_table__clike[39] =
|
||||
{
|
||||
{E2_ExprKind_Dot, E2_ExprParseKind_Postfix, 1, 0, str8_lit_comp(""), str8_lit_comp("."), str8_lit_comp(""), str8_lit_comp("")},
|
||||
{E2_ExprKind_Index, E2_ExprParseKind_Postfix, 1, 0, str8_lit_comp(""), str8_lit_comp("["), str8_lit_comp("]"), str8_lit_comp("")},
|
||||
{E2_ExprKind_Call, E2_ExprParseKind_Postfix, 1, 0, str8_lit_comp(""), str8_lit_comp("("), str8_lit_comp(")"), str8_lit_comp(",")},
|
||||
{E2_ExprKind_Function, E2_ExprParseKind_Postfix, 1, 0, str8_lit_comp(""), str8_lit_comp("("), str8_lit_comp(")"), str8_lit_comp(",")},
|
||||
{E2_ExprKind_DerefAsm, E2_ExprParseKind_Prefix, 1, 0, str8_lit_comp("["), str8_lit_comp(""), str8_lit_comp("]"), str8_lit_comp("")},
|
||||
{E2_ExprKind_SizeOf, E2_ExprParseKind_Prefix, 1, 0, str8_lit_comp("sizeof "), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
|
||||
{E2_ExprKind_TypeOf, E2_ExprParseKind_Prefix, 1, 0, str8_lit_comp("typeof "), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
|
||||
|
||||
@@ -164,7 +164,7 @@ extern B8 e2_expr_kind_is_type_expr_table[44];
|
||||
extern B8 e2_expr_kind_is_first_operand_type_maybe_table[44];
|
||||
extern U64 e2_expr_kind_target_operand_count_table[44];
|
||||
extern E2_LangInfo e2_lang_kind_info_table[1];
|
||||
extern E2_ExprKindParseInfo e2_expr_kind_parse_info_table__clike[38];
|
||||
extern E2_ExprKindParseInfo e2_expr_kind_parse_info_table__clike[39];
|
||||
extern U8 e2_type_kind_basic_byte_size_table[61];
|
||||
extern String8 e2_type_kind_basic_string_table[61];
|
||||
|
||||
|
||||
@@ -43,11 +43,15 @@ entry_point(CmdLine *cmdline)
|
||||
// (A)
|
||||
// int & B
|
||||
// (1 + (int)&B)
|
||||
s("int32 *"),
|
||||
s("int32[100]"),
|
||||
s("int32(*)(int32, int32)"),
|
||||
#if 0
|
||||
s("123(1, 2, 3)"),
|
||||
s("int32 (*) [100]"),
|
||||
s("3 * 4 + 2"),
|
||||
s("(3 * 4) + 2"),
|
||||
s("cast (float32) 123"),
|
||||
s("int32 *"),
|
||||
s("3 * 4 + 2"),
|
||||
s("int32[100]"),
|
||||
s("3 * 4"),
|
||||
s("foo"),
|
||||
s("foo.bar"),
|
||||
@@ -59,7 +63,6 @@ entry_point(CmdLine *cmdline)
|
||||
s("222.f"),
|
||||
s("123 as float32"),
|
||||
s("cast float32 123"),
|
||||
s("cast (float32) 123"),
|
||||
s("(int32 *)123"),
|
||||
s("bar(a, b) = a + b"),
|
||||
s("foo = 123"),
|
||||
@@ -82,8 +85,7 @@ entry_point(CmdLine *cmdline)
|
||||
s("123 + "),
|
||||
s("-123"),
|
||||
s("sizeof 123"),
|
||||
s("123(1, 2, 3)"),
|
||||
#if 0
|
||||
// TODO(rjf): these are ambiguous with regular C type expressions with a naive parse:
|
||||
// s("float32(111)"),
|
||||
// s("float64(111)"),
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user