From 6c4de001b802e47799c16460d0c75df61fa39b27 Mon Sep 17 00:00:00 2001 From: Alexey Date: Fri, 3 Apr 2020 14:27:19 +0300 Subject: [PATCH] cgen: add `builtin.init` call inside of `_vinit` --- vlib/builtin/builtin.v | 9 --------- vlib/builtin/builtin_nix.v | 4 ++++ vlib/builtin/builtin_windows.v | 7 +++++++ vlib/v/gen/cgen.v | 1 + 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/vlib/builtin/builtin.v b/vlib/builtin/builtin.v index 3d391a7748..139e234ad9 100644 --- a/vlib/builtin/builtin.v +++ b/vlib/builtin/builtin.v @@ -6,15 +6,6 @@ module builtin __global g_m2_buf byteptr __global g_m2_ptr byteptr -fn init() { - $if windows { - if is_atty(1) > 0 { - C.SetConsoleMode(C.GetStdHandle(C.STD_OUTPUT_HANDLE), C.ENABLE_PROCESSED_OUTPUT | 0x0004) // ENABLE_VIRTUAL_TERMINAL_PROCESSING - C.setbuf(C.stdout, 0) - } - } -} - pub fn exit(code int) { C.exit(code) } diff --git a/vlib/builtin/builtin_nix.v b/vlib/builtin/builtin_nix.v index afd1d61612..2f7e64dc94 100644 --- a/vlib/builtin/builtin_nix.v +++ b/vlib/builtin/builtin_nix.v @@ -21,6 +21,10 @@ const ( fn C.puts(charptr) */ +fn init() { + // Do nothing +} + pub fn println(s string) { // TODO: a syscall sys_write on linux works, except for the v repl. // Probably it is a stdio buffering issue. Needs more testing... diff --git a/vlib/builtin/builtin_windows.v b/vlib/builtin/builtin_windows.v index 15070d8278..eb4d0d40db 100644 --- a/vlib/builtin/builtin_windows.v +++ b/vlib/builtin/builtin_windows.v @@ -58,6 +58,13 @@ const ( SYMOPT_DEBUG = 0x80000000 ) +fn init() { + if is_atty(1) > 0 { + C.SetConsoleMode(C.GetStdHandle(C.STD_OUTPUT_HANDLE), C.ENABLE_PROCESSED_OUTPUT | 0x0004) // ENABLE_VIRTUAL_TERMINAL_PROCESSING + C.setbuf(C.stdout, 0) + } +} + fn print_backtrace_skipping_top_frames_msvc(skipframes int) bool { $if msvc { diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 716060e696..724efc7623 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -2024,6 +2024,7 @@ fn verror(s string) { fn (g mut Gen) write_init_function() { g.writeln('void _vinit() {') + g.writeln('init(); // builtin.init') g.writeln(g.inits.str()) g.writeln('}') if g.autofree {