阶段5-1:修 LREAL 字面量装载(compile_expr 携带目标 func,F64/F32 位模式区分)
This commit is contained in:
+24
-10
@@ -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<float>(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<float>(e.double_value);
|
||||
std::memcpy(&value, &fv, sizeof fv);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ExprKind::LitDate: type_name = "DATE"; break;
|
||||
|
||||
Reference in New Issue
Block a user