From e9fac0577587a776b2cd2c65fde89622812a8205 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 11 Nov 2022 10:19:06 +0200 Subject: [PATCH] cgen: fix `v -cc tcc -live run examples/hot_reload/graph.v` too --- vlib/v/gen/c/cgen.v | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index bec6af88c0..f5d61e83a0 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -4839,6 +4839,18 @@ fn (mut g Gen) const_decl_precomputed(mod string, name string, field_name string } fn (mut g Gen) const_decl_write_precomputed(mod string, styp string, cname string, field_name string, ct_value string) { + if g.pref.is_livemain || g.pref.is_liveshared { + // Note: tcc has problems reloading .so files with consts in them, when the consts are then used inside the reloaded + // live functions. As a workaround, just use simple #define macros in this case. + // + // If you change it, please also test with `v -live run examples/hot_reload/graph.v` which uses `math.pi` . + g.global_const_defs[util.no_dots(field_name)] = GlobalConstDef{ + mod: mod + def: '#define $cname $ct_value // precomputed3, -live mode' + order: -1 + } + return + } g.global_const_defs[util.no_dots(field_name)] = GlobalConstDef{ mod: mod def: '$g.static_modifier const $styp $cname = $ct_value; // precomputed2'