cgen: bring back Windows fixes

pull/4246/head
Alexey 2020-04-05 17:08:16 +03:00 committed by GitHub
parent 206c1f4ca1
commit 781c20a6ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 7 deletions

View File

@ -21,7 +21,7 @@ const (
fn C.puts(charptr)
*/
fn init() {
fn builtin_init() {
// Do nothing
}

View File

@ -58,7 +58,7 @@ const (
SYMOPT_DEBUG = 0x80000000
)
fn init() {
fn builtin_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)

View File

@ -594,16 +594,20 @@ fn (g mut Gen) gen_assert_stmt(a ast.AssertStmt) {
g.writeln('// assert')
g.write('if( ')
g.expr(a.expr)
s_assertion := a.expr.str().replace('"', "\'")
g.write(' )')
s_assertion := a.expr.str().replace('"', "\'")
mut mod_path := g.file.path
$if windows {
mod_path = g.file.path.replace('\\', '\\\\')
}
if g.is_test {
g.writeln('{')
g.writeln(' g_test_oks++;')
g.writeln(' cb_assertion_ok( _STR("${g.file.path}"), ${a.pos.line_nr}, _STR("assert ${s_assertion}"), _STR("${g.fn_decl.name}()") );')
// g.writeln(' println(_STR("OK ${g.file.path}:${a.pos.line_nr}: fn ${g.fn_decl.name}(): assert $s_assertion"));')
g.writeln(' cb_assertion_ok( _STR("${mod_path}"), ${a.pos.line_nr}, _STR("assert ${s_assertion}"), _STR("${g.fn_decl.name}()") );')
// g.writeln(' println(_STR("OK ${mod_path}:${a.pos.line_nr}: fn ${g.fn_decl.name}(): assert $s_assertion"));')
g.writeln('}else{')
g.writeln(' g_test_fails++;')
g.writeln(' cb_assertion_failed( _STR("${g.file.path}"), ${a.pos.line_nr}, _STR("assert ${s_assertion}"), _STR("${g.fn_decl.name}()") );')
g.writeln(' cb_assertion_failed( _STR("${mod_path}"), ${a.pos.line_nr}, _STR("assert ${s_assertion}"), _STR("${g.fn_decl.name}()") );')
g.writeln(' exit(1);')
g.writeln(' // TODO')
g.writeln(' // Maybe print all vars in a test function if it fails?')
@ -611,7 +615,7 @@ fn (g mut Gen) gen_assert_stmt(a ast.AssertStmt) {
return
}
g.writeln('{}else{')
g.writeln(' eprintln(_STR("${g.file.path}:${a.pos.line_nr}: FAIL: fn ${g.fn_decl.name}(): assert $s_assertion"));')
g.writeln(' eprintln(_STR("${mod_path}:${a.pos.line_nr}: FAIL: fn ${g.fn_decl.name}(): assert $s_assertion"));')
g.writeln(' exit(1);')
g.writeln('}')
}
@ -2072,6 +2076,7 @@ fn verror(s string) {
fn (g mut Gen) write_init_function() {
g.writeln('void _vinit() {')
g.writeln('\tbuiltin_init();')
g.writeln('\tvinit_string_literals();')
g.writeln(g.inits.str())
g.writeln('}')