diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index a9398c143c..869576b3c0 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -619,6 +619,14 @@ fn (mut g Gen) typ(t ast.Type) string { } fn (mut g Gen) base_type(t ast.Type) string { + if g.pref.nofloat { + // todo compile time if for perf? + if t == ast.f32_type { + return 'u32' + } else if t == ast.f64_type { + return 'u64' + } + } share := t.share() mut styp := if share == .atomic_t { t.atomic_typename() } else { g.cc_type(t, true) } if t.has_flag(.shared_f) { diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index ae410f8fd3..6e60186c7e 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -192,6 +192,7 @@ pub mut: is_cstrict bool // turn on more C warnings; slightly slower assert_failure_mode AssertFailureMode // whether to call abort() or print_backtrace() after an assertion failure message_limit int = 100 // the maximum amount of warnings/errors/notices that will be accumulated + nofloat bool // for low level code, like kernels: replaces f32 with u32 and f64 with u64 // checker settings: checker_match_exhaustive_cutoff_limit int = 12 } @@ -277,6 +278,9 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences '-cstrict' { res.is_cstrict = true } + '-nofloat' { + res.nofloat = true + } '-gc' { gc_mode := cmdline.option(current_args, '-gc', '') match gc_mode {