From 98d2e86dca1356749db341b7c12a3654750b1932 Mon Sep 17 00:00:00 2001 From: chentianya Date: Wed, 26 Aug 2026 10:26:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B6=E6=AE=B55-1=EF=BC=9A=E4=BF=AE=20LREAL?= =?UTF-8?q?=20=E5=AD=97=E9=9D=A2=E9=87=8F=E8=A3=85=E8=BD=BD=EF=BC=88compil?= =?UTF-8?q?e=5Fexpr=20=E6=90=BA=E5=B8=A6=E7=9B=AE=E6=A0=87=20func=EF=BC=8C?= =?UTF-8?q?F64/F32=20=E4=BD=8D=E6=A8=A1=E5=BC=8F=E5=8C=BA=E5=88=86?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- compiler/src/Codegen.cpp | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/compiler/src/Codegen.cpp b/compiler/src/Codegen.cpp index f1ac473..bcc7815 100644 --- a/compiler/src/Codegen.cpp +++ b/compiler/src/Codegen.cpp @@ -347,7 +347,11 @@ namespace { const auto fit = inline_fields_->field_off.find(st.target); if (fit != inline_fields_->field_off.end()) { const uint8_t t = alloc_temp(f); - if (!compile_expr(f, *st.value, t)) { + const auto ff_ = inline_fields_->field_func.find(st.target); + if (!compile_expr(f, *st.value, t, + ff_ != inline_fields_->field_func.end() + ? ff_->second + : 0)) { return false; } const size_t so = E_slot_off(f, "STORE_OFF", t, inline_fields_->slot, @@ -366,7 +370,9 @@ namespace { if (f.is_function && it->second >= 1 && it->second <= 7) { return fail("cannot write function input '" + st.target + "'"); } - return compile_expr(f, *st.value, it->second); + const auto tf_ = f.reg_func.find(st.target); + return compile_expr(f, *st.value, it->second, + tf_ != f.reg_func.end() ? tf_->second : 0); } bool compile_fb_call(FuncCtx& f, const Stmt& st) { @@ -380,7 +386,9 @@ namespace { return fail("unknown input '" + a.name + "' for '" + st.instance + "'"); } const uint8_t t = alloc_temp(f); - if (!compile_expr(f, *a.value, t)) { + const auto ff_in = inst->field_func.find(a.name); + if (!compile_expr(f, *a.value, t, + ff_in != inst->field_func.end() ? ff_in->second : 0)) { return false; } const size_t so = E_slot_off(f, "STORE_OFF", t, inst->slot, it->second); @@ -492,14 +500,16 @@ namespace { return fail("cannot write to input '" + target + "'"); } const uint8_t tmp = alloc_temp(f); - if (!compile_expr(f, value, tmp)) { + const compiler::Symbol& sym = link_.globals[git->second]; + if (!compile_expr(f, value, tmp, func_of_name(sym.type_name))) { return false; } E_slot(f, "STORE", tmp, git->second); return true; } - bool compile_expr(FuncCtx& f, const Expr& e, uint8_t rd) { + bool compile_expr(FuncCtx& f, const Expr& e, uint8_t rd, + uint8_t dst_func = 0) { if (e.kind == ExprKind::LitBool || e.kind == ExprKind::LitInt || e.kind == ExprKind::LitTime || e.kind == ExprKind::LitReal || e.kind == ExprKind::LitDate || e.kind == ExprKind::LitTod || @@ -511,11 +521,15 @@ namespace { case ExprKind::LitInt: type_name = "INT"; break; case ExprKind::LitTime: type_name = "TIME"; break; case ExprKind::LitReal: { - // TODO(V2): 浮点字面量按目标类型装载(REAL/LREAL 位模式不同), - // 需 compile_expr 携带目标 func;当前按 REAL(float32)装载 - type_name = "REAL"; - float fv = static_cast(e.double_value); - std::memcpy(&value, &fv, sizeof fv); + // 按目标 func 装载:LREAL(F64)位模式,否则 REAL(F32) + if (dst_func == func_of_name("LREAL")) { + type_name = "LREAL"; + std::memcpy(&value, &e.double_value, sizeof(double)); + } else { + type_name = "REAL"; + float fv = static_cast(e.double_value); + std::memcpy(&value, &fv, sizeof fv); + } break; } case ExprKind::LitDate: type_name = "DATE"; break;