mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: add support for v -printfn main file.v
This commit is contained in:
@@ -60,6 +60,7 @@ struct Gen {
|
||||
mut:
|
||||
file ast.File
|
||||
fn_decl &ast.FnDecl // pointer to the FnDecl we are currently inside otherwise 0
|
||||
last_fn_c_name string
|
||||
tmp_count int
|
||||
variadic_args map[string]int
|
||||
is_c_call bool // e.g. `C.printf("v")`
|
||||
@@ -479,8 +480,12 @@ fn (mut g Gen) stmt(node ast.Stmt) {
|
||||
}
|
||||
}
|
||||
ast.FnDecl {
|
||||
fn_start_pos := g.out.len
|
||||
g.fn_decl = it // &it
|
||||
g.gen_fn_decl(it)
|
||||
if g.last_fn_c_name in g.pref.printfn_list {
|
||||
println(g.out.after(fn_start_pos))
|
||||
}
|
||||
g.writeln('')
|
||||
}
|
||||
ast.ForCStmt {
|
||||
|
||||
@@ -19,12 +19,15 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) {
|
||||
if g.is_gui_app() {
|
||||
// GUI application
|
||||
g.writeln('int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance, LPWSTR cmd_line, int show_cmd')
|
||||
g.last_fn_c_name = 'wWinMain'
|
||||
} else {
|
||||
// Console application
|
||||
g.writeln('int wmain(int ___argc, wchar_t* ___argv[], wchar_t* ___envp[]')
|
||||
g.last_fn_c_name = 'wmain'
|
||||
}
|
||||
} else {
|
||||
g.write('int ${it.name}(int ___argc, char** ___argv')
|
||||
g.last_fn_c_name = it.name
|
||||
}
|
||||
} else {
|
||||
mut name := it.name
|
||||
@@ -46,6 +49,7 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) {
|
||||
// type_name := g.table.Type_to_str(it.return_type)
|
||||
type_name := g.typ(it.return_type)
|
||||
g.write('$type_name ${name}(')
|
||||
g.last_fn_c_name = name
|
||||
g.definitions.write('$type_name ${name}(')
|
||||
}
|
||||
// Receiver is the first argument
|
||||
|
||||
@@ -77,8 +77,8 @@ pub mut:
|
||||
compile_defines_all []string // contains both: ['vfmt','another']
|
||||
|
||||
mod string
|
||||
run_args []string // `v run x.v 1 2 3` => `1 2 3`
|
||||
|
||||
run_args []string // `v run x.v 1 2 3` => `1 2 3`
|
||||
printfn_list []string // a list of generated function names, whose source should be shown, for debugging
|
||||
}
|
||||
|
||||
pub fn backend_from_string(s string) ?Backend {
|
||||
@@ -97,4 +97,3 @@ pub fn backend_from_string(s string) ?Backend {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user