From e951d788ed7eb32bab829048af6a00914e4e497c Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Tue, 6 Aug 2024 10:19:10 -0700 Subject: [PATCH] fix watch window snap to cursor; begin introducing string literals into eval --- src/df/gfx/df_gfx.mdesk | 2 +- src/df/gfx/df_views.c | 7 +- src/df/gfx/generated/df_gfx.meta.c | 2 +- src/eval2/eval2.c | 106 +++++++++++++++++++++-------- src/eval2/eval2.h | 3 +- src/eval2/eval2.mdesk | 81 +++++++++++----------- src/eval2/generated/eval2.meta.c | 6 +- src/eval2/generated/eval2.meta.h | 5 +- 8 files changed, 135 insertions(+), 77 deletions(-) diff --git a/src/df/gfx/df_gfx.mdesk b/src/df/gfx/df_gfx.mdesk index 9938cef2..f68e3467 100644 --- a/src/df/gfx/df_gfx.mdesk +++ b/src/df/gfx/df_gfx.mdesk @@ -552,7 +552,7 @@ DF_SettingTable: { {HoverAnimations hover_animations "Hover Animations" 0 1 0 1 } {PressAnimations press_animations "Press Animations" 0 1 0 1 } - {FocusAnimations focus_animations "Focus Animations" 0 1 0 1 } + {FocusAnimations focus_animations "Focus Animations" 0 0 0 1 } {TooltipAnimations tooltip_animations "Tooltip Animations" 0 1 0 1 } {MenuAnimations menu_animations "Menu Animations" 0 1 0 1 } {ScrollingAnimations scrolling_animations "Scrolling Animations" 0 1 0 1 } diff --git a/src/df/gfx/df_views.c b/src/df/gfx/df_views.c index 30a7d770..a27771c8 100644 --- a/src/df/gfx/df_views.c +++ b/src/df/gfx/df_views.c @@ -1873,7 +1873,6 @@ df_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_WatchViewS if(state_dirty) { state_dirty = 0; - snap_to_cursor = 1; } ////////////////////////////// @@ -2187,6 +2186,7 @@ df_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_WatchViewS { df_entity_equip_name(0, watch, new_string); state_dirty = 1; + snap_to_cursor = 1; } else if(editing_complete && new_string.size != 0 && df_expand_key_match(pt.key, empty_row_key)) { @@ -2196,6 +2196,7 @@ df_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_WatchViewS DF_ExpandKey key = df_expand_key_from_entity(watch); df_eval_view_set_key_rule(eval_view, key, str8_zero()); state_dirty = 1; + snap_to_cursor = 1; } }break; case DF_WatchViewColumnKind_Value: @@ -2239,6 +2240,7 @@ df_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_WatchViewS df_entity_equip_name(0, view_rule, new_string); } state_dirty = 1; + snap_to_cursor = 1; }break; } } @@ -2297,6 +2299,7 @@ df_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_WatchViewS { taken = 1; state_dirty = 1; + snap_to_cursor = 1; for(S64 y = selection_tbl.min.y; y <= selection_tbl.max.y; y += 1) { DF_WatchViewPoint pt = df_watch_view_point_from_tbl(&blocks, v2s64(0, y)); @@ -2454,11 +2457,13 @@ df_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_WatchViewS if(evt->delta_2s32.y < 0 && !df_entity_is_nil(first_watch) && !df_entity_is_nil(reorder_group_prev)) { state_dirty = 1; + snap_to_cursor = 1; df_entity_change_parent(0, reorder_group_prev, reorder_group_prev->parent, reorder_group_prev->parent, last_watch); } if(evt->delta_2s32.y > 0 && !df_entity_is_nil(last_watch) && !df_entity_is_nil(reorder_group_next)) { state_dirty = 1; + snap_to_cursor = 1; df_entity_change_parent(0, reorder_group_next, reorder_group_next->parent, reorder_group_next->parent, reorder_group_prev); } } diff --git a/src/df/gfx/generated/df_gfx.meta.c b/src/df/gfx/generated/df_gfx.meta.c index a7e5fdbe..1ffd3101 100644 --- a/src/df/gfx/generated/df_gfx.meta.c +++ b/src/df/gfx/generated/df_gfx.meta.c @@ -1259,7 +1259,7 @@ DF_SettingVal df_g_setting_code_default_val_table[19] = { {1, 1}, {1, 1}, -{1, 1}, +{1, 0}, {1, 1}, {1, 1}, {1, 1}, diff --git a/src/eval2/eval2.c b/src/eval2/eval2.c index a0cc5e97..83dcb9bc 100644 --- a/src/eval2/eval2.c +++ b/src/eval2/eval2.c @@ -2899,7 +2899,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to U32 match_idx = matches[matches_count-1]; RDI_GlobalVariable *global_var = rdi_element_from_name_idx(rdi, GlobalVariables, match_idx); E_OpList oplist = {0}; - e_oplist_push(arena, &oplist, RDI_EvalOp_ModuleOff, global_var->voff); + e_oplist_push_op(arena, &oplist, RDI_EvalOp_ModuleOff, global_var->voff); loc_kind = RDI_LocationKind_AddrBytecodeStream; loc_bytecode = e_bytecode_from_oplist(arena, &oplist); U32 type_idx = global_var->type_idx; @@ -2936,7 +2936,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to U32 match_idx = matches[0]; RDI_ThreadVariable *thread_var = rdi_element_from_name_idx(rdi, ThreadVariables, match_idx); E_OpList oplist = {0}; - e_oplist_push(arena, &oplist, RDI_EvalOp_TLSOff, thread_var->tls_off); + e_oplist_push_op(arena, &oplist, RDI_EvalOp_TLSOff, thread_var->tls_off); loc_kind = RDI_LocationKind_AddrBytecodeStream; loc_bytecode = e_bytecode_from_oplist(arena, &oplist); U32 type_idx = thread_var->type_idx; @@ -2975,7 +2975,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to RDI_Scope *scope = rdi_element_from_name_idx(rdi, Scopes, procedure->root_scope_idx); U64 voff = *rdi_element_from_name_idx(rdi, ScopeVOffData, scope->voff_range_first); E_OpList oplist = {0}; - e_oplist_push(arena, &oplist, RDI_EvalOp_ModuleOff, voff); + e_oplist_push_op(arena, &oplist, RDI_EvalOp_ModuleOff, voff); loc_kind = RDI_LocationKind_ValBytecodeStream; loc_bytecode = e_bytecode_from_oplist(arena, &oplist); U32 type_idx = procedure->type_idx; @@ -3062,9 +3062,9 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to E_OpList oplist = {0}; U64 byte_size = bit_size_from_arch(e_state->ctx->arch)/8; U64 regread_param = RDI_EncodeRegReadParam(loc_reg_u16.reg_code, byte_size, 0); - e_oplist_push(arena, &oplist, RDI_EvalOp_RegRead, regread_param); - e_oplist_push(arena, &oplist, RDI_EvalOp_ConstU16, loc_reg_u16.offset); - e_oplist_push(arena, &oplist, RDI_EvalOp_Add, 0); + e_oplist_push_op(arena, &oplist, RDI_EvalOp_RegRead, regread_param); + e_oplist_push_op(arena, &oplist, RDI_EvalOp_ConstU16, loc_reg_u16.offset); + e_oplist_push_op(arena, &oplist, RDI_EvalOp_Add, 0); atom = e_push_expr(arena, E_ExprKind_LeafBytecode, token_string.str); atom->mode = E_Mode_Addr; atom->type_key = type_key; @@ -3075,10 +3075,10 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to E_OpList oplist = {0}; U64 byte_size = bit_size_from_arch(e_state->ctx->arch)/8; U64 regread_param = RDI_EncodeRegReadParam(loc_reg_u16.reg_code, byte_size, 0); - e_oplist_push(arena, &oplist, RDI_EvalOp_RegRead, regread_param); - e_oplist_push(arena, &oplist, RDI_EvalOp_ConstU16, loc_reg_u16.offset); - e_oplist_push(arena, &oplist, RDI_EvalOp_Add, 0); - e_oplist_push(arena, &oplist, RDI_EvalOp_MemRead, bit_size_from_arch(e_state->ctx->arch)/8); + e_oplist_push_op(arena, &oplist, RDI_EvalOp_RegRead, regread_param); + e_oplist_push_op(arena, &oplist, RDI_EvalOp_ConstU16, loc_reg_u16.offset); + e_oplist_push_op(arena, &oplist, RDI_EvalOp_Add, 0); + e_oplist_push_op(arena, &oplist, RDI_EvalOp_MemRead, bit_size_from_arch(e_state->ctx->arch)/8); atom = e_push_expr(arena, E_ExprKind_LeafBytecode, token_string.str); atom->mode = E_Mode_Addr; atom->type_key = type_key; @@ -3092,7 +3092,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to U64 byte_size = (U64)reg_rng.byte_size; U64 byte_pos = 0; U64 regread_param = RDI_EncodeRegReadParam(loc_reg.reg_code, byte_size, byte_pos); - e_oplist_push(arena, &oplist, RDI_EvalOp_RegRead, regread_param); + e_oplist_push_op(arena, &oplist, RDI_EvalOp_RegRead, regread_param); atom = e_push_expr(arena, E_ExprKind_LeafBytecode, token_string.str); atom->mode = E_Mode_Value; atom->type_key = type_key; @@ -3175,10 +3175,12 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to } }break; - // rjf: string => invalid + // rjf: string => leaf string literal case E_TokenKind_StringLiteral: { - e_msgf(arena, &result.msgs, E_MsgKind_MalformedInput, token_string.str, "String literals are not supported."); + String8 string_value_escaped = str8_chop(str8_skip(token_string, 1), 1); + atom = e_push_expr(arena, E_ExprKind_LeafStringLiteral, token_string.str); + atom->string = string_value_escaped; it += 1; }break; @@ -3457,7 +3459,7 @@ e_parse_expr_from_text_tokens(Arena *arena, String8 text, E_TokenArray *tokens) //- rjf: op list functions internal void -e_oplist_push(Arena *arena, E_OpList *list, RDI_EvalOp opcode, U64 p) +e_oplist_push_op(Arena *arena, E_OpList *list, RDI_EvalOp opcode, U64 p) { U8 ctrlbits = rdi_eval_op_ctrlbits_table[opcode]; U32 p_size = RDI_DECODEN_FROM_CTRLBITS(ctrlbits); @@ -3473,10 +3475,10 @@ internal void e_oplist_push_uconst(Arena *arena, E_OpList *list, U64 x) { if(0){} - else if(x <= 0xFF) { e_oplist_push(arena, list, RDI_EvalOp_ConstU8, x); } - else if(x <= 0xFFFF) { e_oplist_push(arena, list, RDI_EvalOp_ConstU16, x); } - else if(x <= 0xFFFFFFFF) { e_oplist_push(arena, list, RDI_EvalOp_ConstU32, x); } - else { e_oplist_push(arena, list, RDI_EvalOp_ConstU64, x); } + else if(x <= 0xFF) { e_oplist_push_op(arena, list, RDI_EvalOp_ConstU8, x); } + else if(x <= 0xFFFF) { e_oplist_push_op(arena, list, RDI_EvalOp_ConstU16, x); } + else if(x <= 0xFFFFFFFF) { e_oplist_push_op(arena, list, RDI_EvalOp_ConstU32, x); } + else { e_oplist_push_op(arena, list, RDI_EvalOp_ConstU64, x); } } internal void @@ -3484,22 +3486,22 @@ e_oplist_push_sconst(Arena *arena, E_OpList *list, S64 x) { if(-0x80 <= x && x <= 0x7F) { - e_oplist_push(arena, list, RDI_EvalOp_ConstU8, (U64)x); - e_oplist_push(arena, list, RDI_EvalOp_TruncSigned, 8); + e_oplist_push_op(arena, list, RDI_EvalOp_ConstU8, (U64)x); + e_oplist_push_op(arena, list, RDI_EvalOp_TruncSigned, 8); } else if(-0x8000 <= x && x <= 0x7FFF) { - e_oplist_push(arena, list, RDI_EvalOp_ConstU16, (U64)x); - e_oplist_push(arena, list, RDI_EvalOp_TruncSigned, 16); + e_oplist_push_op(arena, list, RDI_EvalOp_ConstU16, (U64)x); + e_oplist_push_op(arena, list, RDI_EvalOp_TruncSigned, 16); } else if(-0x80000000ll <= x && x <= 0x7FFFFFFFll) { - e_oplist_push(arena, list, RDI_EvalOp_ConstU32, (U64)x); - e_oplist_push(arena, list, RDI_EvalOp_TruncSigned, 32); + e_oplist_push_op(arena, list, RDI_EvalOp_ConstU32, (U64)x); + e_oplist_push_op(arena, list, RDI_EvalOp_TruncSigned, 32); } else { - e_oplist_push(arena, list, RDI_EvalOp_ConstU64, (U64)x); + e_oplist_push_op(arena, list, RDI_EvalOp_ConstU64, (U64)x); } } @@ -3609,6 +3611,41 @@ e_irtree_bytecode_no_copy(Arena *arena, String8 bytecode) return n; } +internal E_IRNode * +e_irtree_string_literal(Arena *arena, String8 string) +{ + E_IRNode *root = &e_irnode_nil; + for(U64 idx = 0, advance = 0; idx < string.size; idx += advance) + { + U64 bytes_left = string.size-idx; + U64 bytes_to_encode = 0; + RDI_EvalOp opcode = 0; + switch(bytes_left%8) + { + default: + case 1:{opcode = RDI_EvalOp_ConstU8; bytes_to_encode = 1;}break; + case 2:{opcode = RDI_EvalOp_ConstU16; bytes_to_encode = 2;}break; + case 3: + case 4:{opcode = RDI_EvalOp_ConstU32; bytes_to_encode = 4;}break; + case 5: + case 6: + case 7: + case 8:{opcode = RDI_EvalOp_ConstU64; bytes_to_encode = 8;}break; + } + U64 value = 0; + MemoryCopy(&value, string.str+idx, bytes_to_encode); + E_IRNode *old_root = root; + root = e_push_irnode(arena, opcode); + root->u64 = value; + if(old_root != &e_irnode_nil) + { + e_irnode_push_child(root, old_root); + } + advance = bytes_to_encode; + } + return root; +} + internal E_IRNode * e_irtree_mem_read_type(Arena *arena, E_IRNode *c, E_TypeKey type_key) { @@ -3724,7 +3761,6 @@ e_irtree_and_type_from_expr(Arena *arena, E_Expr *expr) { default: { - e_msgf(arena, &result.msgs, E_MsgKind_MalformedInput, expr->location, "(internal) Undefined expression kind (%u).", kind); }break; //- rjf: array indices @@ -4403,6 +4439,17 @@ e_irtree_and_type_from_expr(Arena *arena, E_Expr *expr) e_msgf(arena, &result.msgs, E_MsgKind_MalformedInput, expr->location, "(internal) Leaf member not expected here."); }break; + //- rjf: leaf string literal + case E_ExprKind_LeafStringLiteral: + { + String8 string = expr->string; + E_TypeKey type_key = e_type_key_cons(E_TypeKind_Array, e_type_key_basic(E_TypeKind_UChar8), string.size); + E_IRNode *new_tree = e_irtree_string_literal(arena, string); + result.root = new_tree; + result.type_key = type_key; + result.mode = E_Mode_Value; + }break; + //- rjf: leaf U64s case E_ExprKind_LeafU64: { @@ -4481,6 +4528,7 @@ e_irtree_and_type_from_expr(Arena *arena, E_Expr *expr) e_string2expr_map_dec_poison(e_state->ctx->macro_map, expr->string); } }break; + } return result; @@ -4518,11 +4566,11 @@ e_append_oplist_from_irtree(Arena *arena, E_IRNode *root, E_OpList *out) // 3. // rjf: modify prt_right in place to create step 2 - e_oplist_push(arena, &prt_right, RDI_EvalOp_Skip, prt_left.encoded_size); + e_oplist_push_op(arena, &prt_right, RDI_EvalOp_Skip, prt_left.encoded_size); // rjf: merge 1 into out e_oplist_concat_in_place(out, &prt_cond); - e_oplist_push(arena, out, RDI_EvalOp_Cond, prt_right.encoded_size); + e_oplist_push_op(arena, out, RDI_EvalOp_Cond, prt_right.encoded_size); // rjf: merge 2 into out e_oplist_concat_in_place(out, &prt_right); @@ -4551,7 +4599,7 @@ e_append_oplist_from_irtree(Arena *arena, E_IRNode *root, E_OpList *out) } // rjf: emit op to compute this node - e_oplist_push(arena, out, (RDI_EvalOp)root->op, root->u64); + e_oplist_push_op(arena, out, (RDI_EvalOp)root->op, root->u64); } }break; } diff --git a/src/eval2/eval2.h b/src/eval2/eval2.h index 51cd0925..1c656b44 100644 --- a/src/eval2/eval2.h +++ b/src/eval2/eval2.h @@ -613,7 +613,7 @@ internal E_Parse e_parse_expr_from_text_tokens(Arena *arena, String8 text, E_Tok //~ rjf: IR-ization Functions //- rjf: op list functions -internal void e_oplist_push(Arena *arena, E_OpList *list, RDI_EvalOp opcode, U64 p); +internal void e_oplist_push_op(Arena *arena, E_OpList *list, RDI_EvalOp opcode, U64 p); internal void e_oplist_push_uconst(Arena *arena, E_OpList *list, U64 x); internal void e_oplist_push_sconst(Arena *arena, E_OpList *list, S64 x); internal void e_oplist_push_bytecode(Arena *arena, E_OpList *list, String8 bytecode); @@ -630,6 +630,7 @@ internal E_IRNode *e_irtree_binary_op(Arena *arena, RDI_EvalOp op, RDI_EvalTypeG internal E_IRNode *e_irtree_binary_op_u(Arena *arena, RDI_EvalOp op, E_IRNode *l, E_IRNode *r); internal E_IRNode *e_irtree_conditional(Arena *arena, E_IRNode *c, E_IRNode *l, E_IRNode *r); internal E_IRNode *e_irtree_bytecode_no_copy(Arena *arena, String8 bytecode); +internal E_IRNode *e_irtree_string_literal(Arena *arena, String8 string); internal E_IRNode *e_irtree_mem_read_type(Arena *arena, E_IRNode *c, E_TypeKey type_key); internal E_IRNode *e_irtree_convert_lo(Arena *arena, E_IRNode *c, RDI_EvalTypeGroup out, RDI_EvalTypeGroup in); internal E_IRNode *e_irtree_trunc(Arena *arena, E_IRNode *c, E_TypeKey type_key); diff --git a/src/eval2/eval2.mdesk b/src/eval2/eval2.mdesk index 64605d3d..d451f065 100644 --- a/src/eval2/eval2.mdesk +++ b/src/eval2/eval2.mdesk @@ -64,54 +64,55 @@ E_TypeKindTable: @table(name op_string) E_ExprKindTable: { - { Nil "" } + { Nil "" } - { ArrayIndex "[]" } - { MemberAccess "." } - { Deref "*" } - { Address "&" } + { ArrayIndex "[]" } + { MemberAccess "." } + { Deref "*" } + { Address "&" } - { Cast "cast" } - { Sizeof "sizeof" } + { Cast "cast" } + { Sizeof "sizeof" } - { Neg "-" } - { LogNot "!" } - { BitNot "~" } - { Mul "*" } - { Div "/" } - { Mod "%" } - { Add "+" } - { Sub "-" } - { LShift "<<" } - { RShift ">>" } - { Less "<" } - { LsEq "<=" } - { Grtr ">" } - { GrEq ">=" } - { EqEq "==" } - { NtEq "!=" } + { Neg "-" } + { LogNot "!" } + { BitNot "~" } + { Mul "*" } + { Div "/" } + { Mod "%" } + { Add "+" } + { Sub "-" } + { LShift "<<" } + { RShift ">>" } + { Less "<" } + { LsEq "<=" } + { Grtr ">" } + { GrEq ">=" } + { EqEq "==" } + { NtEq "!=" } - { BitAnd "&" } - { BitXor "^" } - { BitOr "|" } - { LogAnd "&&" } - { LogOr "||" } + { BitAnd "&" } + { BitXor "^" } + { BitOr "|" } + { LogAnd "&&" } + { LogOr "||" } - { Ternary "? " } + { Ternary "? " } - { LeafBytecode "bytecode" } - { LeafMember "member" } - { LeafU64 "U64" } - { LeafF64 "F64" } - { LeafF32 "F32" } + { LeafBytecode "bytecode" } + { LeafMember "member" } + { LeafStringLiteral "string_literal" } + { LeafU64 "U64" } + { LeafF64 "F64" } + { LeafF32 "F32" } - { TypeIdent "type_ident" } - { Ptr "ptr" } - { Array "array" } - { Func "function" } + { TypeIdent "type_ident" } + { Ptr "ptr" } + { Array "array" } + { Func "function" } - { Define "=" } - { LeafIdent "leaf_ident" } + { Define "=" } + { LeafIdent "leaf_ident" } } @table(name display_string) diff --git a/src/eval2/generated/eval2.meta.c b/src/eval2/generated/eval2.meta.c index f665bfb6..d80be985 100644 --- a/src/eval2/generated/eval2.meta.c +++ b/src/eval2/generated/eval2.meta.c @@ -4,7 +4,7 @@ //- GENERATED CODE C_LINKAGE_BEGIN -String8 e_expr_kind_strings[40] = +String8 e_expr_kind_strings[41] = { str8_lit_comp("Nil"), str8_lit_comp("ArrayIndex"), @@ -37,6 +37,7 @@ str8_lit_comp("LogOr"), str8_lit_comp("Ternary"), str8_lit_comp("LeafBytecode"), str8_lit_comp("LeafMember"), +str8_lit_comp("LeafStringLiteral"), str8_lit_comp("LeafU64"), str8_lit_comp("LeafF64"), str8_lit_comp("LeafF32"), @@ -63,7 +64,7 @@ str8_lit_comp("Insufficient evaluation machine stack space."), str8_lit_comp("Malformed bytecode."), }; -String8 e_expr_op_strings[40] = +String8 e_expr_op_strings[41] = { str8_lit_comp(""), str8_lit_comp("[]"), @@ -96,6 +97,7 @@ str8_lit_comp("||"), str8_lit_comp("? "), str8_lit_comp("bytecode"), str8_lit_comp("member"), +str8_lit_comp("string_literal"), str8_lit_comp("U64"), str8_lit_comp("F64"), str8_lit_comp("F32"), diff --git a/src/eval2/generated/eval2.meta.h b/src/eval2/generated/eval2.meta.h index 5e2889b2..161936bb 100644 --- a/src/eval2/generated/eval2.meta.h +++ b/src/eval2/generated/eval2.meta.h @@ -109,6 +109,7 @@ E_ExprKind_LogOr, E_ExprKind_Ternary, E_ExprKind_LeafBytecode, E_ExprKind_LeafMember, +E_ExprKind_LeafStringLiteral, E_ExprKind_LeafU64, E_ExprKind_LeafF64, E_ExprKind_LeafF32, @@ -138,9 +139,9 @@ E_InterpretationCode_COUNT, } E_InterpretationCode; C_LINKAGE_BEGIN -extern String8 e_expr_kind_strings[40]; +extern String8 e_expr_kind_strings[41]; extern String8 e_interpretation_code_display_strings[11]; -extern String8 e_expr_op_strings[40]; +extern String8 e_expr_op_strings[41]; extern U8 e_kind_basic_byte_size_table[54]; extern String8 e_kind_basic_string_table[54];