fix fn main generation

pull/3271/head
Alexander Medvednikov 2019-12-30 09:23:17 +01:00
parent f725aa2e8d
commit 1d9916f93e
4 changed files with 23 additions and 15 deletions

22
v.v
View File

@ -13,21 +13,21 @@ import (
const ( const (
known_commands = ['run', 'build', 'version', 'doc'] known_commands = ['run', 'build', 'version', 'doc']
simple_tools = ['fmt', 'up', 'create', 'test', 'test-fmt', 'test-compiler', 'build-tools', 'build-examples', 'build-vbinaries'] simple_tools = ['fmt', 'up', 'create', 'test', 'test-fmt', 'test-compiler', 'build-tools',
'build-examples', 'build-vbinaries']
) )
fn main() { fn main() {
is_verbose := '-verbose' in os.args || '--verbose' in os.args is_verbose := '-verbose' in os.args || '--verbose' in os.args
// t := time.ticks() // t := time.ticks()
// defer { println(time.ticks() - t) } // defer { println(time.ticks() - t) }
args := compiler.env_vflags_and_os_args() args := compiler.env_vflags_and_os_args()
options, command := compiler.get_v_options_and_main_command( args ) options,command := compiler.get_v_options_and_main_command(args)
if is_verbose { if is_verbose {
eprintln('v args: $args') eprintln('v args: $args')
eprintln('v command: $command') eprintln('v command: $command')
eprintln('v options: $options') eprintln('v options: $options')
} }
// external tool // external tool
if command in simple_tools { if command in simple_tools {
compiler.launch_tool('v' + command) compiler.launch_tool('v' + command)
@ -114,7 +114,9 @@ fn v_command(command string, args []string) {
mod := args.last() mod := args.last()
os.system('$vexe build module vlib$os.path_separator' + args.last()) os.system('$vexe build module vlib$os.path_separator' + args.last())
vhfile := filepath.join(compiler.v_modules_path,'vlib','${mod}.vh') vhfile := filepath.join(compiler.v_modules_path,'vlib','${mod}.vh')
txt := os.read_file(vhfile) or { panic(err) } txt := os.read_file(vhfile) or {
panic(err)
}
println(txt) println(txt)
// v.gen_doc_html_for_module(args.last()) // v.gen_doc_html_for_module(args.last())
} }

View File

@ -40,7 +40,12 @@ fn (g mut Gen) stmt(node ast.Stmt) {
g.writeln(';') g.writeln(';')
} }
ast.FnDecl { ast.FnDecl {
g.write('$it.typ.name ${it.name}(') if it.name == 'main' {
g.write('int ${it.name}(')
}
else {
g.write('$it.typ.name ${it.name}(')
}
for arg in it.args { for arg in it.args {
g.write(arg.typ.name + ' ' + arg.name) g.write(arg.typ.name + ' ' + arg.name)
} }
@ -48,6 +53,9 @@ fn (g mut Gen) stmt(node ast.Stmt) {
for stmt in it.stmts { for stmt in it.stmts {
g.stmt(stmt) g.stmt(stmt)
} }
if it.name == 'main' {
g.writeln('return 0;')
}
g.writeln('}') g.writeln('}')
} }
ast.Return { ast.Return {

View File

@ -1,4 +1,3 @@
fn main() int { fn main() {
a := 10 a := 10
return 0
} }

View File

@ -48,8 +48,7 @@ fn init_user() {
} }
} }
fn main() int { fn main() {
return 0
} }