From f1f654ecfd97541f513c717db4b44d138271b599 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Fri, 26 Jun 2026 13:20:38 -0700 Subject: [PATCH] eval2: simplify expression parsing info, allow child reversal (for parsing non-canonical expression orders into canonical shapes, e.g. Rust-style casts like 123 as float32 -> cast(float32, 123); ptr/array type operators, etc./ --- project.4coder | 2 +- project.raddbg | 2 +- src/eval2/eval2.c | 353 +++++++++++-------------------- src/eval2/eval2.h | 21 +- src/eval2/eval2.mdesk | 179 +++++++++------- src/eval2/generated/eval2.meta.c | 214 ++++++++++++++++--- src/eval2/generated/eval2.meta.h | 11 +- src/scratch/ryan_scratch.c | 5 + 8 files changed, 421 insertions(+), 366 deletions(-) diff --git a/project.4coder b/project.4coder index 0dfc2fee..6d11dd66 100644 --- a/project.4coder +++ b/project.4coder @@ -49,7 +49,7 @@ commands = // .f1 = { .win = "raddbg_stable --ipc kill_all && build raddbg", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, // .f1 = { .win = "raddbg_stable --ipc kill_all && build raddbg debug telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, // .f1 = { .win = "raddbg_stable --ipc kill_all && build radbin", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, - .f1 = { .win = "raddbg_stable --ipc kill_all && build ryan_scratch no_meta && pushd build && ryan_scratch && popd", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, + .f1 = { .win = "raddbg_stable --ipc kill_all && build ryan_scratch && pushd build && ryan_scratch && popd", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, //- rjf: [raddbg wsl] // .f1 = { .win = "wsl ./build.sh raddbg", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, diff --git a/project.raddbg b/project.raddbg index 4adbb44b..8c9b43d1 100644 --- a/project.raddbg +++ b/project.raddbg @@ -7,7 +7,6 @@ target: working_directory: "../raddebugger" arguments: "--user:C:/devel/raddebugger/build/raddbg_test.user" debug_subprocesses: 0 - enabled: 1 } target: { @@ -67,4 +66,5 @@ target: { executable: "build/ryan_scratch.exe" working_directory: build + enabled: 1 } diff --git a/src/eval2/eval2.c b/src/eval2/eval2.c index 5b528e45..e1aecb5a 100644 --- a/src/eval2/eval2.c +++ b/src/eval2/eval2.c @@ -1069,211 +1069,6 @@ e2_expr_push_child(Arena *arena, E2_Expr *parent, E2_Expr *expr) n->v = expr; e2_expr_push_child_node(parent, n); } -#if 0 - -internal E2_Expr * -e2_expr_const_u64_or_smaller(Arena *arena, U64 u) -{ - E2_Expr *e = e2_expr(arena); - { - e->mode = E2_Mode_Value; - e->val.u64 = u; - if(u <= 0x7fffffff) - { - e->op = RDI_EvalOp_ConstU32; - e->type_key = e2_type_key_basic(E2_TypeKind_S32); - } - else if(u <= 0xffffffff) - { - e->op = RDI_EvalOp_ConstU32; - e->type_key = e2_type_key_basic(E2_TypeKind_U32); - } - else if(u <= 0x7fffffffffffffffull) - { - e->op = RDI_EvalOp_ConstU64; - e->type_key = e2_type_key_basic(E2_TypeKind_S64); - } - else if(u <= 0xffffffffffffffffull) - { - e->op = RDI_EvalOp_ConstU64; - e->type_key = e2_type_key_basic(E2_TypeKind_U64); - } - } - return e; -} - -internal E2_Expr * -e2_expr_const_f32(Arena *arena, F32 f32) -{ - E2_Expr *e = e2_expr(arena); - e->mode = E2_Mode_Value; - e->val.f32 = f32; - e->op = RDI_EvalOp_ConstU32; - e->type_key = e2_type_key_basic(E2_TypeKind_F32); - return e; -} - -internal E2_Expr * -e2_expr_const_f64(Arena *arena, F64 f64) -{ - E2_Expr *e = e2_expr(arena); - e->mode = E2_Mode_Value; - e->val.f64 = f64; - e->op = RDI_EvalOp_ConstU64; - e->type_key = e2_type_key_basic(E2_TypeKind_F64); - return e; -} - -internal E2_Expr * -e2_expr_unary_op(Arena *arena, E2_TypeKey type_key, RDI_EvalOp op, E2_Expr *operand) -{ - E2_Expr *e = e2_expr(arena); - e->type_key = type_key; - e->op = op; - e->mode = E2_Mode_Value; - e->val.u512.u8[0] = e2_type_group_from_kind(e2_type_kind_from_key(type_key)); - e->val.u512.u8[1] = 8*e2_byte_size_from_type_key(type_key); - e2_expr_push_child(arena, e, operand); - return e; -} - -internal E2_Expr * -e2_expr_binary_op(Arena *arena, E2_TypeKey type_key, RDI_EvalOp op, E2_Expr *lhs, E2_Expr *rhs) -{ - E2_Expr *e = e2_expr(arena); - E2_TypeKey arith_type_key = type_key; - if(RDI_EvalOp_FirstLogical <= op && op <= RDI_EvalOp_LastLogical) - { - arith_type_key = lhs->type_key; - } - e->type_key = type_key; - e->op = op; - e->mode = E2_Mode_Value; - e->val.u512.u8[0] = e2_type_group_from_kind(e2_type_kind_from_key(arith_type_key)); - e->val.u512.u8[1] = 8*e2_byte_size_from_type_key(arith_type_key); - e2_expr_push_child(arena, e, lhs); - e2_expr_push_child(arena, e, rhs); - return e; -} - -internal E2_Expr * -e2_expr_resolve_to_value(Arena *arena, E2_Expr *expr) -{ - E2_Expr *result = expr; - - // rjf: address evaluations of arrays -> create value of pointer to first element - if(expr->mode == E2_Mode_Address && e2_type_kind_from_key(e2_type_key_undecorate(expr->type_key)) == E2_TypeKind_Array) - { - result = e2_expr(arena); - result->type_key = e2_type_key_direct(e2_type_key_undecorate(expr->type_key)); - result->mode = E2_Mode_Value; - e2_expr_push_child(arena, result, expr); - } - - // rjf: address evaluations -> read value from space - else if(expr->mode == E2_Mode_Address) - { - U64 memread_byte_size = e2_byte_size_from_type_key(expr->type_key); - memread_byte_size = Min(64, memread_byte_size); - E2_Expr *memread_expr = e2_expr(arena); - memread_expr->op = RDI_EvalOp_MemRead; - memread_expr->mode = E2_Mode_Value; - memread_expr->type_key = expr->type_key; - memread_expr->val.u64 = memread_byte_size; - e2_expr_push_child(arena, memread_expr, expr); - result = memread_expr; - } - - // rjf: bitfields -> shift & mask - E2_TypeKey core_type_key = e2_type_key_undecorate(expr->type_key); - if(e2_type_kind_from_key(core_type_key) == E2_TypeKind_Bitfield) - { - // rjf: unpack bitfield params - U64 shift = e2_shift_from_type_key(result->type_key); - U64 mask_count = e2_mask_count_from_type_key(result->type_key); - U64 valid_bits_mask = 0; - for EachIndex(idx, mask_count) - { - valid_bits_mask |= (1ull<type_key = dst_type_key; - result->op = dst_type_is_signed ? RDI_EvalOp_TruncSigned : RDI_EvalOp_Trunc; - result->val.u64 = dst_type_byte_size*8; - e2_expr_push_child(arena, result, expr); - } - return result; -} - -internal E2_Expr * -e2_expr_convert_if_possible(Arena *arena, E2_Expr *expr, E2_TypeKey dst_type_key) -{ - E2_Expr *result = expr; - { - // rjf: unpack src / dst types - E2_TypeKey src_type_key = expr->type_key; - E2_TypeKind src_type_kind = e2_type_kind_from_key(src_type_key); - E2_TypeKind dst_type_kind = e2_type_kind_from_key(dst_type_key); - RDI_EvalTypeGroup src_type_group = e2_type_group_from_kind(src_type_kind); - RDI_EvalTypeGroup dst_type_group = e2_type_group_from_kind(dst_type_kind); - U64 src_byte_size = e2_byte_size_from_type_key(src_type_key); - U64 dst_byte_size = e2_byte_size_from_type_key(dst_type_key); - - // rjf: convert from src -> dst - RDI_EvalConversionKind conversion_kind = rdi_eval_conversion_kind_from_typegroups(src_type_group, dst_type_group); - if(conversion_kind == RDI_EvalConversionKind_Legal) - { - result = e2_expr(arena); - result->mode = E2_Mode_Value; - result->type_key = dst_type_key; - result->op = RDI_EvalOp_Convert; - result->val.u64 = src_type_group | (dst_type_group << 8); - e2_expr_push_child(arena, result, expr); - } - - // rjf: no-op from src -> dst - if(conversion_kind == RDI_EvalConversionKind_Noop) - { - result->type_key = dst_type_key; - } - - // rjf: if shrinking integer sizes, truncate - if(dst_byte_size < src_byte_size && e2_type_kind_is_integer(dst_type_kind)) - { - result = e2_expr_truncate(arena, expr, dst_type_key); - } - } - return result; -} - -internal E2_Expr * -e2_expr_type(Arena *arena, E2_TypeKey type_key) -{ - E2_Expr *expr = e2_expr(arena); - expr->type_key = type_key; - expr->mode = E2_Mode_Type; - return expr; -} -#endif //////////////////////////////// //~ rjf: Expression Constructors @@ -1801,7 +1596,7 @@ e2_parse_from_string(Arena *arena, E2_ParseState *state, B32 identifier_is_type, String8 token_string = str8_substr(string, token.range); for EachIndex(idx, lang_info->expr_kind_parse_infos_count) { - if(lang_info->expr_kind_parse_infos[idx].parse_kind == E2_ExprParseKind_UnaryPrefix && + if(lang_info->expr_kind_parse_infos[idx].parse_kind == E2_ExprParseKind_Prefix && lang_info->expr_kind_parse_infos[idx].precedence <= max_precedence && str8_match(token_string, lang_info->expr_kind_parse_infos[idx].pre, 0)) { @@ -1826,11 +1621,11 @@ e2_parse_from_string(Arena *arena, E2_ParseState *state, B32 identifier_is_type, task = push_array_no_zero(arena, E2_ParseTask, 1); } MemoryZeroStruct(task); - task->src_range = token.range; - task->child_count_target = 1; - task->expr_kind = expr_kind; - task->max_precedence = precedence; - task->expected_closer = closer; + task->src_range = token.range; + task->child_count_target = e2_expr_kind_target_operand_count_table[expr_kind]; + task->expr_kind = expr_kind; + task->max_precedence = precedence; + task->expected_closer = closer; SLLStackPush(state->top_task, task); } @@ -1878,7 +1673,7 @@ e2_parse_from_string(Arena *arena, E2_ParseState *state, B32 identifier_is_type, } MemoryZeroStruct(task); task->src_range = token.range; - task->child_count_target = 1; + task->child_count_target = e2_expr_kind_target_operand_count_table[E2_ExprKind_Define]; task->expr_kind = E2_ExprKind_Define; task->max_precedence = max_S64; task->identifier = identifier; @@ -1923,7 +1718,7 @@ e2_parse_from_string(Arena *arena, E2_ParseState *state, B32 identifier_is_type, } MemoryZeroStruct(task); task->src_range = token.range; - task->child_count_target = 1; + task->child_count_target = e2_expr_kind_target_operand_count_table[E2_ExprKind_Macro]; task->expr_kind = E2_ExprKind_Macro; task->max_precedence = max_S64; task->identifier = identifier; @@ -1963,7 +1758,7 @@ e2_parse_from_string(Arena *arena, E2_ParseState *state, B32 identifier_is_type, String8 token_string = str8_substr(string, token.range); for EachIndex(idx, lang_info->expr_kind_parse_infos_count) { - if(lang_info->expr_kind_parse_infos[idx].parse_kind == E2_ExprParseKind_UnaryPrefix && + if(lang_info->expr_kind_parse_infos[idx].parse_kind == E2_ExprParseKind_Prefix && lang_info->expr_kind_parse_infos[idx].precedence <= max_precedence && str8_match(token_string, str8_skip_chop_whitespace(lang_info->expr_kind_parse_infos[idx].pre), 0)) { @@ -1989,7 +1784,7 @@ e2_parse_from_string(Arena *arena, E2_ParseState *state, B32 identifier_is_type, } MemoryZeroStruct(task); task->src_range = token.range; - task->child_count_target = 1; + task->child_count_target = e2_expr_kind_target_operand_count_table[expr_kind]; task->expr_kind = expr_kind; task->max_precedence = precedence; SLLStackPush(state->top_task, task); @@ -2067,12 +1862,55 @@ e2_parse_from_string(Arena *arena, E2_ParseState *state, B32 identifier_is_type, expr->string = raw_string; } - //- rjf: extend parsed expression tree with trailing operators + //- rjf: extend parsed expression tree with completed trailing type operators (right-to-left) if(!state->caller_info_completes_task && expr != &e2_expr_nil) { U64 trailing_symbol_off = off; if(e2_try_token(lang, string, E2_TokenKind_Symbol, s(""), &trailing_symbol_off, &token)) { + B32 is_expr_type = (expr->kind == E2_ExprKind_TypeIdentifier || + expr->kind == E2_ExprKind_Ptr || + (state->top_task != 0 && state->top_task->expr_kind == E2_ExprKind_Cast)); + if(is_expr_type) + { + // rjf: token string -> operator kind + E2_ExprKind expr_kind = E2_ExprKind_Null; + { + String8 token_string = str8_substr(string, token.range); + for EachIndex(idx, lang_info->expr_kind_parse_infos_count) + { + E2_ExprKindParseInfo *op_info = &lang_info->expr_kind_parse_infos[idx]; + if(e2_expr_kind_is_type_expr_table[op_info->expr_kind] && + str8_match(op_info->post, token_string, 0)) + { + expr_kind = op_info->expr_kind; + break; + } + } + } + + // rjf: got an expression kind -> build new operator node + if(expr_kind != E2_ExprKind_Null) + { + E2_Expr *op_expr = e2_expr(arena, expr_kind); + e2_expr_push_child(arena, op_expr, expr); + expr = op_expr; + off = trailing_symbol_off; + } + } + } + } + + //- rjf: extend parsed expression tree with trailing operators + if(!state->caller_info_completes_task && expr != &e2_expr_nil) + { + U64 trailing_symbol_off = off; + if(e2_try_token(lang, string, E2_TokenKind_Symbol, s(""), &trailing_symbol_off, &token) || + e2_try_token(lang, string, E2_TokenKind_Identifier, s(""), &trailing_symbol_off, &token)) + { + // rjf: determine if the expression is a type + B32 expr_is_type = e2_expr_kind_is_type_expr_table[expr->kind]; + // rjf: token string -> operator kind E2_ExprKind expr_kind = E2_ExprKind_Null; U64 child_count_target = 2; @@ -2080,24 +1918,22 @@ e2_parse_from_string(Arena *arena, E2_ParseState *state, B32 identifier_is_type, String8 closer = {0}; B32 splitter_is_required = 0; S64 precedence = 0; + B32 reverse_children = 0; { String8 token_string = str8_substr(string, token.range); for EachIndex(idx, lang_info->expr_kind_parse_infos_count) { E2_ExprKindParseInfo *expr_kind_info = &lang_info->expr_kind_parse_infos[idx]; - if(expr_kind_info->precedence <= max_precedence && str8_match(token_string, expr_kind_info->sep, 0)) + if(expr_kind_info->precedence <= max_precedence && + str8_match(token_string, expr_kind_info->sep, 0) && + (!!expr_is_type == !!e2_expr_kind_is_type_expr_table[expr_kind_info->expr_kind])) { - switch(expr_kind_info->parse_kind) - { - default:{}break; - case E2_ExprParseKind_Binary: {child_count_target = 2;}break; - case E2_ExprParseKind_Ternary: {child_count_target = 3; splitter_is_required = 1;}break; - case E2_ExprParseKind_Call: {child_count_target = max_U64;}break; - } splitter = expr_kind_info->chain; closer = expr_kind_info->post; expr_kind = expr_kind_info->expr_kind; precedence = expr_kind_info->precedence; + reverse_children = expr_kind_info->reverse_children; + child_count_target = e2_expr_kind_target_operand_count_table[expr_kind]; break; } } @@ -2120,6 +1956,7 @@ e2_parse_from_string(Arena *arena, E2_ParseState *state, B32 identifier_is_type, task->child_count = 0; task->child_count_target = child_count_target; task->expr_kind = expr_kind; + task->reverse_children = reverse_children; task->max_precedence = precedence; task->expected_splitter = splitter; task->expected_closer = closer; @@ -2141,7 +1978,14 @@ e2_parse_from_string(Arena *arena, E2_ParseState *state, B32 identifier_is_type, if(!state->caller_info_completes_task) { E2_ExprNode *n = push_array(arena, E2_ExprNode, 1); - SLLQueuePush(state->top_task->first_child, state->top_task->last_child, n); + if(state->top_task->reverse_children) + { + SLLQueuePushFront(state->top_task->first_child, state->top_task->last_child, n); + } + else + { + SLLQueuePush(state->top_task->first_child, state->top_task->last_child, n); + } n->v = expr; state->top_task->child_count += 1; } @@ -2165,9 +2009,19 @@ e2_parse_from_string(Arena *arena, E2_ParseState *state, B32 identifier_is_type, closer_found = e2_try_token(lang, string, E2_TokenKind_Symbol, state->top_task->expected_closer, &off, 0); } + //- rjf: determine if the task above a parenthesized sub-expression is expecting a type + B32 parent_looking_for_type = 0; + if(state->top_task->next != 0 && + state->top_task->next->expr_kind != E2_ExprKind_Null && + state->top_task->next->child_count == 0 && + e2_expr_kind_is_first_operand_type_maybe_table[state->top_task->next->expr_kind]) + { + parent_looking_for_type = 1; + } + //- rjf: determine if first child of a parenthesized sub-expression is a type B32 parenthesized_child_is_type = 0; - if(closer_found && state->top_task->child_count == 1) + if(!parent_looking_for_type && closer_found && state->top_task->child_count == 1) { E2_Expr *expr = state->top_task->first_child->v; parenthesized_child_is_type = 1; @@ -2193,7 +2047,7 @@ e2_parse_from_string(Arena *arena, E2_ParseState *state, B32 identifier_is_type, //- rjf: closer found, completed child count == 1 & completed child is a // type evaluation - then this is cast. push a task to fill the operand B32 is_cast = parenthesized_child_is_type; - if(is_cast) + if(!parent_looking_for_type && is_cast) { // rjf: pop the sub-task for the type expression E2_Expr *type_expr = state->top_task->first_child->v; @@ -2217,8 +2071,8 @@ e2_parse_from_string(Arena *arena, E2_ParseState *state, B32 identifier_is_type, MemoryZeroStruct(task); task->src_range = type_expr->src_range; task->child_count = 1; - task->child_count_target = 2; - task->expr_kind = E2_ExprKind_CCast; + task->child_count_target = e2_expr_kind_target_operand_count_table[E2_ExprKind_Cast]; + task->expr_kind = E2_ExprKind_Cast; task->max_precedence = 1; SLLStackPush(state->top_task, task); expr = &e2_expr_nil; @@ -2319,11 +2173,12 @@ e2_parse_from_string(Arena *arena, E2_ParseState *state, B32 identifier_is_type, { if(lang_info->expr_kind_parse_infos[idx].expr_kind == t->expr_kind) { - if(lang_info->expr_kind_parse_infos[idx].parse_kind == E2_ExprParseKind_Binary) + U64 target_operand_count = e2_expr_kind_target_operand_count_table[t->expr_kind]; + if(target_operand_count == 2) { symbol = lang_info->expr_kind_parse_infos[idx].sep; } - else if(lang_info->expr_kind_parse_infos[idx].parse_kind == E2_ExprParseKind_UnaryPrefix) + else if(target_operand_count == 1) { symbol = lang_info->expr_kind_parse_infos[idx].pre; } @@ -2468,6 +2323,35 @@ e2_compile_from_expr(Arena *arena, E2_CompileState *state, E2_IRNode *resolve_re } }break; + //- rjf: pointer type operators + case E2_ExprKind_Ptr: + { + Arch arch = state->selected_ctx.arch; + E2_TypeKey ptee_type_key = lhs->type_key; + E2_TypeKey ptr_type_key = e2_type_key_cons_ptr(arch, ptee_type_key); + finished_root = e2_irnode(arena); + finished_root->type_key = ptr_type_key; + }break; + + //- rjf: array type operator + case E2_ExprKind_Array: + { + if(state->caller_request_count == 0) + { + done = 1; + compile.status = E2_CompileStatus_CompileTimeEval; + compile.irtree = rhs; + } + else + { + U64 array_count = compile_time_eval_result.u64; + E2_TypeKey element_type_key = lhs->type_key; + E2_TypeKey array_type_key = e2_type_key_cons_array(element_type_key, array_count); + finished_root = e2_irnode(arena); + finished_root->type_key = array_type_key; + } + }break; + //- rjf: leaf numerics case E2_ExprKind_Numeric: { @@ -2652,7 +2536,7 @@ e2_compile_from_expr(Arena *arena, E2_CompileState *state, E2_IRNode *resolve_re }break; //- rjf: casts - case E2_ExprKind_CCast: + case E2_ExprKind_Cast: cast:; { E2_IRNode *cast_type_ir = lhs; @@ -2661,6 +2545,11 @@ e2_compile_from_expr(Arena *arena, E2_CompileState *state, E2_IRNode *resolve_re { e2_msgf(arena, &compile.msgs, e->src_range, "Cannot cast to this type."); } + else if(e2_type_kind_is_ptr_or_ref(e2_type_kind_from_key(cast_type_key))) + { + finished_root = rhs; + rhs->mode = E2_Mode_Address; + } else { E2_IRNode *castee_ir = rhs; diff --git a/src/eval2/eval2.h b/src/eval2/eval2.h index 758a43ac..3b1aa869 100644 --- a/src/eval2/eval2.h +++ b/src/eval2/eval2.h @@ -10,11 +10,8 @@ typedef enum E2_ExprParseKind { E2_ExprParseKind_Null, - E2_ExprParseKind_UnaryPrefix, - E2_ExprParseKind_UnaryPostfix, - E2_ExprParseKind_Binary, - E2_ExprParseKind_Ternary, - E2_ExprParseKind_Call, + E2_ExprParseKind_Prefix, + E2_ExprParseKind_Postfix, } E2_ExprParseKind; @@ -67,6 +64,7 @@ typedef enum E2_CompileStatus //- rjf: caller-provided info E2_CompileStatus_MissedIdentifierResolution, E2_CompileStatus_NewIdentifierDefinition, + E2_CompileStatus_NewCtxID, E2_CompileStatus_MemberAccess, E2_CompileStatus_IndexAccess, E2_CompileStatus_Call, @@ -345,6 +343,7 @@ struct E2_ParseTask E2_ExprNode *last_child; U64 child_count; U64 child_count_target; + B32 reverse_children; S64 max_precedence; E2_ExprKind expr_kind; String8 identifier; @@ -448,6 +447,7 @@ struct E2_CompileState E2_CompileTask *top_task; E2_CompileTask *free_task; U64 caller_request_count; + E2_Ctx selected_ctx; }; typedef struct E2_Compile E2_Compile; @@ -632,17 +632,6 @@ internal E2_TypeKey e2_coerced_type_key_from_operands(E2_TypeKey lhs, E2_TypeKey internal E2_Expr *e2_expr(Arena *arena, E2_ExprKind kind); internal void e2_expr_push_child_node(E2_Expr *parent, E2_ExprNode *node); internal void e2_expr_push_child(Arena *arena, E2_Expr *parent, E2_Expr *expr); -#if 0 -internal E2_Expr *e2_expr_const_u64_or_smaller(Arena *arena, U64 u); -internal E2_Expr *e2_expr_const_f32(Arena *arena, F32 f32); -internal E2_Expr *e2_expr_const_f64(Arena *arena, F64 f64); -internal E2_Expr *e2_expr_unary_op(Arena *arena, E2_TypeKey type_key, RDI_EvalOp op, E2_Expr *operand); -internal E2_Expr *e2_expr_binary_op(Arena *arena, E2_TypeKey type_key, RDI_EvalOp op, E2_Expr *lhs, E2_Expr *rhs); -internal E2_Expr *e2_expr_resolve_to_value(Arena *arena, E2_Expr *expr); -internal E2_Expr *e2_expr_truncate(Arena *arena, E2_Expr *expr, E2_TypeKey dst_type_key); -internal E2_Expr *e2_expr_convert_if_possible(Arena *arena, E2_Expr *expr, E2_TypeKey dst_type_key); -internal E2_Expr *e2_expr_type(Arena *arena, E2_TypeKey type_key); -#endif //////////////////////////////// //~ rjf: IR Tree Constructors diff --git a/src/eval2/eval2.mdesk b/src/eval2/eval2.mdesk index 50b986a3..9392574c 100644 --- a/src/eval2/eval2.mdesk +++ b/src/eval2/eval2.mdesk @@ -1,50 +1,51 @@ // Copyright (c) Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) -@table(name) +@table(name is_type_expression is_first_operand_type_maybe target_operand_count) E2_ExprKindTable: { - {Identifier} - {MacroArg} - {TypeIdentifier} - {Numeric} - {StringLiteral} - {CharLiteral} - {Dot} - {Index} - {Call} - {DerefAsm} - {SizeOf} - {TypeOf} - {CCast} - {Deref} - {Address} - {Pos} - {Neg} - {LogNot} - {BitNot} - {Ptr} - {Mul} - {Div} - {Mod} - {Add} - {Sub} - {LShift} - {RShift} - {Less} - {LtEq} - {Grtr} - {GrEq} - {EqEq} - {NtEq} - {BitAnd} - {BitXor} - {BitOr} - {LogAnd} - {LogOr} - {Define} - {Macro} - {Cond} + {Identifier 0 0 0 } + {MacroArg 0 0 0 } + {TypeIdentifier 1 0 0 } + {Ptr 1 1 1 } + {Array 1 1 2 } + {Numeric 0 0 0 } + {StringLiteral 0 0 0 } + {CharLiteral 0 0 0 } + {Dot 0 0 1 } + {Index 0 0 2 } + {Call 0 0 0xffffffffffffffffull} + {DerefAsm 0 0 1 } + {SizeOf 0 1 1 } + {TypeOf 1 1 1 } + {Cast 0 1 2 } + {Deref 0 0 1 } + {Address 0 0 1 } + {Pos 0 0 1 } + {Neg 0 0 1 } + {LogNot 0 0 1 } + {BitNot 0 0 1 } + {Mul 0 0 2 } + {Div 0 0 2 } + {Mod 0 0 2 } + {Add 0 0 2 } + {Sub 0 0 2 } + {LShift 0 0 2 } + {RShift 0 0 2 } + {Less 0 0 2 } + {LtEq 0 0 2 } + {Grtr 0 0 2 } + {GrEq 0 0 2 } + {EqEq 0 0 2 } + {NtEq 0 0 2 } + {BitAnd 0 0 2 } + {BitXor 0 0 2 } + {BitOr 0 0 2 } + {LogAnd 0 0 2 } + {LogOr 0 0 2 } + {Define 0 0 1 } + {Macro 0 0 1 } + {Cond 0 0 3 } } @enum E2_ExprKind: @@ -54,11 +55,30 @@ E2_ExprKindTable: COUNT, } +@data(B8) e2_expr_kind_is_type_expr_table: +{ + 0, + @expand(E2_ExprKindTable a) `$(a.is_type_expression)` +} + +@data(B8) e2_expr_kind_is_first_operand_type_maybe_table: +{ + 0, + @expand(E2_ExprKindTable a) `$(a.is_first_operand_type_maybe)` +} + +@data(U64) e2_expr_kind_target_operand_count_table: +{ + 0, + @expand(E2_ExprKindTable a) `$(a.target_operand_count)` +} + @struct E2_ExprKindParseInfo: { `E2_ExprKind expr_kind`; `E2_ExprParseKind parse_kind`; `S64 precedence`; + `B8 reverse_children`; `String8 pre`; `String8 sep`; `String8 post`; @@ -87,48 +107,51 @@ E2_LangKindTable: @expand(E2_LangKindTable a) `{ArrayCount(e2_expr_kind_parse_info_table__$(a.name_lower)), (e2_expr_kind_parse_info_table__$(a.name_lower))}` } -@table(name parse_kind precedence pre sep pos chain) +@table(name parse_kind precedence pre sep pos chain reverse_children) E2_ExprKindParseInfoTable_CLike: { - {Index Binary 1 "" "[" "]" "" } - {Call Call 1 "" "(" ")" ","} - {DerefAsm UnaryPrefix 1 "[" "" "]" "" } - {SizeOf UnaryPrefix 1 "sizeof " "" "" "" } - {TypeOf UnaryPrefix 1 "typeof " "" "" "" } - {SizeOf UnaryPrefix 1 "size_of " "" "" "" } - {TypeOf UnaryPrefix 1 "type_of " "" "" "" } - {CCast UnaryPrefix 1 "" "" "" "" } - {Deref UnaryPrefix 2 "*" "" "" "" } - {Address UnaryPrefix 2 "&" "" "" "" } - {Pos UnaryPrefix 2 "+" "" "" "" } - {Neg UnaryPrefix 2 "-" "" "" "" } - {LogNot UnaryPrefix 2 "!" "" "" "" } - {BitNot UnaryPrefix 2 "~" "" "" "" } - {Ptr UnaryPostfix 1 "" "" "*" "" } - {Mul Binary 3 "" "*" "" "" } - {Div Binary 3 "" "/" "" "" } - {Mod Binary 3 "" "%" "" "" } - {Add Binary 4 "" "+" "" "" } - {Sub Binary 4 "" "-" "" "" } - {LShift Binary 5 "" "<<" "" "" } - {RShift Binary 5 "" ">>" "" "" } - {Less Binary 6 "" "<" "" "" } - {LtEq Binary 6 "" "<=" "" "" } - {Grtr Binary 6 "" ">" "" "" } - {GrEq Binary 6 "" ">=" "" "" } - {EqEq Binary 7 "" "==" "" "" } - {NtEq Binary 7 "" "!=" "" "" } - {BitAnd Binary 8 "" "&" "" "" } - {BitXor Binary 9 "" "^" "" "" } - {BitOr Binary 10 "" "|" "" "" } - {LogAnd Binary 11 "" "&&" "" "" } - {LogOr Binary 12 "" "||" "" "" } - {Cond Ternary 14 "" "?" "" ":"} + {Index Postfix 1 "" "[" "]" "" 0} + {Call Postfix 1 "" "(" ")" "," 0} + {DerefAsm Prefix 1 "[" "" "]" "" 0} + {SizeOf Prefix 1 "sizeof " "" "" "" 0} + {TypeOf Prefix 1 "typeof " "" "" "" 0} + {SizeOf Prefix 1 "size_of " "" "" "" 0} + {TypeOf Prefix 1 "type_of " "" "" "" 0} + {Cast Prefix 1 "" "" "" "" 0} + {Deref Prefix 2 "*" "" "" "" 0} + {Address Prefix 2 "&" "" "" "" 0} + {Pos Prefix 2 "+" "" "" "" 0} + {Neg Prefix 2 "-" "" "" "" 0} + {LogNot Prefix 2 "!" "" "" "" 0} + {BitNot Prefix 2 "~" "" "" "" 0} + {Cast Prefix 1 "cast " "" "" "" 0} + {Cast Postfix 1 "" "as" "" "" 1} + {Ptr Postfix 1 "" "" "*" "" 0} + {Array Postfix 1 "" "[" "]" "" 0} + {Mul Postfix 3 "" "*" "" "" 0} + {Div Postfix 3 "" "/" "" "" 0} + {Mod Postfix 3 "" "%" "" "" 0} + {Add Postfix 4 "" "+" "" "" 0} + {Sub Postfix 4 "" "-" "" "" 0} + {LShift Postfix 5 "" "<<" "" "" 0} + {RShift Postfix 5 "" ">>" "" "" 0} + {Less Postfix 6 "" "<" "" "" 0} + {LtEq Postfix 6 "" "<=" "" "" 0} + {Grtr Postfix 6 "" ">" "" "" 0} + {GrEq Postfix 6 "" ">=" "" "" 0} + {EqEq Postfix 7 "" "==" "" "" 0} + {NtEq Postfix 7 "" "!=" "" "" 0} + {BitAnd Postfix 8 "" "&" "" "" 0} + {BitXor Postfix 9 "" "^" "" "" 0} + {BitOr Postfix 10 "" "|" "" "" 0} + {LogAnd Postfix 11 "" "&&" "" "" 0} + {LogOr Postfix 12 "" "||" "" "" 0} + {Cond Postfix 14 "" "?" "" ":" 0} } @data(E2_ExprKindParseInfo) e2_expr_kind_parse_info_table__clike: { - @expand(E2_ExprKindParseInfoTable_CLike a) `{E2_ExprKind_$(a.name), E2_ExprParseKind_$(a.parse_kind), $(a.precedence), str8_lit_comp("$(a.pre)"), str8_lit_comp("$(a.sep)"), str8_lit_comp("$(a.pos)"), str8_lit_comp("$(a.chain)")}` + @expand(E2_ExprKindParseInfoTable_CLike a) `{E2_ExprKind_$(a.name), E2_ExprParseKind_$(a.parse_kind), $(a.precedence), $(a.reverse_children), str8_lit_comp("$(a.pre)"), str8_lit_comp("$(a.sep)"), str8_lit_comp("$(a.pos)"), str8_lit_comp("$(a.chain)")}` } @table(name basic_string basic_byte_size) diff --git a/src/eval2/generated/eval2.meta.c b/src/eval2/generated/eval2.meta.c index 5a9c842c..7f578104 100644 --- a/src/eval2/generated/eval2.meta.c +++ b/src/eval2/generated/eval2.meta.c @@ -4,47 +4,191 @@ //- GENERATED CODE C_LINKAGE_BEGIN +B8 e2_expr_kind_is_type_expr_table[43] = +{ +0, +0, +0, +1, +1, +1, +0, +0, +0, +0, +0, +0, +0, +0, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +}; + +B8 e2_expr_kind_is_first_operand_type_maybe_table[43] = +{ +0, +0, +0, +0, +1, +1, +0, +0, +0, +0, +0, +0, +0, +1, +1, +1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +}; + +U64 e2_expr_kind_target_operand_count_table[43] = +{ +0, +0, +0, +0, +1, +2, +0, +0, +0, +1, +2, +0xffffffffffffffffull, +1, +1, +1, +2, +1, +1, +1, +1, +1, +1, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +2, +1, +1, +3, +}; + 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[34] = +E2_ExprKindParseInfo e2_expr_kind_parse_info_table__clike[37] = { -{E2_ExprKind_Index, E2_ExprParseKind_Binary, 1, str8_lit_comp(""), str8_lit_comp("["), str8_lit_comp("]"), str8_lit_comp("")}, -{E2_ExprKind_Call, E2_ExprParseKind_Call, 1, str8_lit_comp(""), str8_lit_comp("("), str8_lit_comp(")"), str8_lit_comp(",")}, -{E2_ExprKind_DerefAsm, E2_ExprParseKind_UnaryPrefix, 1, str8_lit_comp("["), str8_lit_comp(""), str8_lit_comp("]"), str8_lit_comp("")}, -{E2_ExprKind_SizeOf, E2_ExprParseKind_UnaryPrefix, 1, str8_lit_comp("sizeof "), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_TypeOf, E2_ExprParseKind_UnaryPrefix, 1, str8_lit_comp("typeof "), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_SizeOf, E2_ExprParseKind_UnaryPrefix, 1, str8_lit_comp("size_of "), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_TypeOf, E2_ExprParseKind_UnaryPrefix, 1, str8_lit_comp("type_of "), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_CCast, E2_ExprParseKind_UnaryPrefix, 1, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_Deref, E2_ExprParseKind_UnaryPrefix, 2, str8_lit_comp("*"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_Address, E2_ExprParseKind_UnaryPrefix, 2, str8_lit_comp("&"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_Pos, E2_ExprParseKind_UnaryPrefix, 2, str8_lit_comp("+"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_Neg, E2_ExprParseKind_UnaryPrefix, 2, str8_lit_comp("-"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_LogNot, E2_ExprParseKind_UnaryPrefix, 2, str8_lit_comp("!"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_BitNot, E2_ExprParseKind_UnaryPrefix, 2, str8_lit_comp("~"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_Ptr, E2_ExprParseKind_UnaryPostfix, 1, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("*"), str8_lit_comp("")}, -{E2_ExprKind_Mul, E2_ExprParseKind_Binary, 3, str8_lit_comp(""), str8_lit_comp("*"), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_Div, E2_ExprParseKind_Binary, 3, str8_lit_comp(""), str8_lit_comp("/"), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_Mod, E2_ExprParseKind_Binary, 3, str8_lit_comp(""), str8_lit_comp("%"), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_Add, E2_ExprParseKind_Binary, 4, str8_lit_comp(""), str8_lit_comp("+"), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_Sub, E2_ExprParseKind_Binary, 4, str8_lit_comp(""), str8_lit_comp("-"), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_LShift, E2_ExprParseKind_Binary, 5, str8_lit_comp(""), str8_lit_comp("<<"), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_RShift, E2_ExprParseKind_Binary, 5, str8_lit_comp(""), str8_lit_comp(">>"), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_Less, E2_ExprParseKind_Binary, 6, str8_lit_comp(""), str8_lit_comp("<"), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_LtEq, E2_ExprParseKind_Binary, 6, str8_lit_comp(""), str8_lit_comp("<="), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_Grtr, E2_ExprParseKind_Binary, 6, str8_lit_comp(""), str8_lit_comp(">"), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_GrEq, E2_ExprParseKind_Binary, 6, str8_lit_comp(""), str8_lit_comp(">="), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_EqEq, E2_ExprParseKind_Binary, 7, str8_lit_comp(""), str8_lit_comp("=="), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_NtEq, E2_ExprParseKind_Binary, 7, str8_lit_comp(""), str8_lit_comp("!="), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_BitAnd, E2_ExprParseKind_Binary, 8, str8_lit_comp(""), str8_lit_comp("&"), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_BitXor, E2_ExprParseKind_Binary, 9, str8_lit_comp(""), str8_lit_comp("^"), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_BitOr, E2_ExprParseKind_Binary, 10, str8_lit_comp(""), str8_lit_comp("|"), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_LogAnd, E2_ExprParseKind_Binary, 11, str8_lit_comp(""), str8_lit_comp("&&"), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_LogOr, E2_ExprParseKind_Binary, 12, str8_lit_comp(""), str8_lit_comp("||"), str8_lit_comp(""), str8_lit_comp("")}, -{E2_ExprKind_Cond, E2_ExprParseKind_Ternary, 14, 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_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("")}, +{E2_ExprKind_SizeOf, E2_ExprParseKind_Prefix, 1, 0, str8_lit_comp("size_of "), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_TypeOf, E2_ExprParseKind_Prefix, 1, 0, str8_lit_comp("type_of "), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_Cast, E2_ExprParseKind_Prefix, 1, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_Deref, E2_ExprParseKind_Prefix, 2, 0, str8_lit_comp("*"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_Address, E2_ExprParseKind_Prefix, 2, 0, str8_lit_comp("&"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_Pos, E2_ExprParseKind_Prefix, 2, 0, str8_lit_comp("+"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_Neg, E2_ExprParseKind_Prefix, 2, 0, str8_lit_comp("-"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_LogNot, E2_ExprParseKind_Prefix, 2, 0, str8_lit_comp("!"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_BitNot, E2_ExprParseKind_Prefix, 2, 0, str8_lit_comp("~"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_Cast, E2_ExprParseKind_Prefix, 1, 0, str8_lit_comp("cast "), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_Cast, E2_ExprParseKind_Postfix, 1, 1, str8_lit_comp(""), str8_lit_comp("as"), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_Ptr, E2_ExprParseKind_Postfix, 1, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("*"), str8_lit_comp("")}, +{E2_ExprKind_Array, E2_ExprParseKind_Postfix, 1, 0, str8_lit_comp(""), str8_lit_comp("["), str8_lit_comp("]"), str8_lit_comp("")}, +{E2_ExprKind_Mul, E2_ExprParseKind_Postfix, 3, 0, str8_lit_comp(""), str8_lit_comp("*"), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_Div, E2_ExprParseKind_Postfix, 3, 0, str8_lit_comp(""), str8_lit_comp("/"), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_Mod, E2_ExprParseKind_Postfix, 3, 0, str8_lit_comp(""), str8_lit_comp("%"), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_Add, E2_ExprParseKind_Postfix, 4, 0, str8_lit_comp(""), str8_lit_comp("+"), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_Sub, E2_ExprParseKind_Postfix, 4, 0, str8_lit_comp(""), str8_lit_comp("-"), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_LShift, E2_ExprParseKind_Postfix, 5, 0, str8_lit_comp(""), str8_lit_comp("<<"), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_RShift, E2_ExprParseKind_Postfix, 5, 0, str8_lit_comp(""), str8_lit_comp(">>"), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_Less, E2_ExprParseKind_Postfix, 6, 0, str8_lit_comp(""), str8_lit_comp("<"), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_LtEq, E2_ExprParseKind_Postfix, 6, 0, str8_lit_comp(""), str8_lit_comp("<="), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_Grtr, E2_ExprParseKind_Postfix, 6, 0, str8_lit_comp(""), str8_lit_comp(">"), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_GrEq, E2_ExprParseKind_Postfix, 6, 0, str8_lit_comp(""), str8_lit_comp(">="), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_EqEq, E2_ExprParseKind_Postfix, 7, 0, str8_lit_comp(""), str8_lit_comp("=="), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_NtEq, E2_ExprParseKind_Postfix, 7, 0, str8_lit_comp(""), str8_lit_comp("!="), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_BitAnd, E2_ExprParseKind_Postfix, 8, 0, str8_lit_comp(""), str8_lit_comp("&"), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_BitXor, E2_ExprParseKind_Postfix, 9, 0, str8_lit_comp(""), str8_lit_comp("^"), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_BitOr, E2_ExprParseKind_Postfix, 10, 0, str8_lit_comp(""), str8_lit_comp("|"), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_LogAnd, E2_ExprParseKind_Postfix, 11, 0, str8_lit_comp(""), str8_lit_comp("&&"), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_LogOr, E2_ExprParseKind_Postfix, 12, 0, str8_lit_comp(""), str8_lit_comp("||"), str8_lit_comp(""), str8_lit_comp("")}, +{E2_ExprKind_Cond, E2_ExprParseKind_Postfix, 14, 0, str8_lit_comp(""), str8_lit_comp("?"), str8_lit_comp(""), str8_lit_comp(":")}, }; U8 e2_type_kind_basic_byte_size_table[61] = diff --git a/src/eval2/generated/eval2.meta.h b/src/eval2/generated/eval2.meta.h index bc3638b5..5995845e 100644 --- a/src/eval2/generated/eval2.meta.h +++ b/src/eval2/generated/eval2.meta.h @@ -12,6 +12,8 @@ E2_ExprKind_Null, E2_ExprKind_Identifier, E2_ExprKind_MacroArg, E2_ExprKind_TypeIdentifier, +E2_ExprKind_Ptr, +E2_ExprKind_Array, E2_ExprKind_Numeric, E2_ExprKind_StringLiteral, E2_ExprKind_CharLiteral, @@ -21,14 +23,13 @@ E2_ExprKind_Call, E2_ExprKind_DerefAsm, E2_ExprKind_SizeOf, E2_ExprKind_TypeOf, -E2_ExprKind_CCast, +E2_ExprKind_Cast, E2_ExprKind_Deref, E2_ExprKind_Address, E2_ExprKind_Pos, E2_ExprKind_Neg, E2_ExprKind_LogNot, E2_ExprKind_BitNot, -E2_ExprKind_Ptr, E2_ExprKind_Mul, E2_ExprKind_Div, E2_ExprKind_Mod, @@ -142,6 +143,7 @@ struct E2_ExprKindParseInfo E2_ExprKind expr_kind; E2_ExprParseKind parse_kind; S64 precedence; +B8 reverse_children; String8 pre; String8 sep; String8 post; @@ -156,8 +158,11 @@ E2_ExprKindParseInfo *expr_kind_parse_infos; }; C_LINKAGE_BEGIN +extern B8 e2_expr_kind_is_type_expr_table[43]; +extern B8 e2_expr_kind_is_first_operand_type_maybe_table[43]; +extern U64 e2_expr_kind_target_operand_count_table[43]; extern E2_LangInfo e2_lang_kind_info_table[1]; -extern E2_ExprKindParseInfo e2_expr_kind_parse_info_table__clike[34]; +extern E2_ExprKindParseInfo e2_expr_kind_parse_info_table__clike[37]; extern U8 e2_type_kind_basic_byte_size_table[61]; extern String8 e2_type_kind_basic_string_table[61]; diff --git a/src/scratch/ryan_scratch.c b/src/scratch/ryan_scratch.c index 3c0994de..02673e0f 100644 --- a/src/scratch/ryan_scratch.c +++ b/src/scratch/ryan_scratch.c @@ -43,6 +43,11 @@ entry_point(CmdLine *cmdline) // (A) // int & B // (1 + (int)&B) + s("int32[100]"), + s("123 as float32"), + s("cast float32 123"), + s("cast (float32) 123"), + s("(int32 *)123"), s("bar(a, b) = a + b"), s("123, 456"), s("int32 == int32"),