improve code generation and add test & compilation checking
This commit is contained in:
@@ -2,6 +2,7 @@ module code
|
|||||||
|
|
||||||
import freeflowuniverse.herolib.core.pathlib
|
import freeflowuniverse.herolib.core.pathlib
|
||||||
import os
|
import os
|
||||||
|
import log
|
||||||
|
|
||||||
pub struct Module {
|
pub struct Module {
|
||||||
pub mut:
|
pub mut:
|
||||||
@@ -44,7 +45,18 @@ pub fn (mod Module) write(path string, options WriteOptions) ! {
|
|||||||
if options.format {
|
if options.format {
|
||||||
os.execute('v fmt -w ${module_dir.path}')
|
os.execute('v fmt -w ${module_dir.path}')
|
||||||
}
|
}
|
||||||
|
if options.compile {
|
||||||
|
os.execute_opt('v -n -w -enable-globals -shared ${module_dir.path}') or {
|
||||||
|
log.fatal(err.msg())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if options.test {
|
||||||
|
os.execute_opt('v -n -w -enable-globals test ${module_dir.path}') or {
|
||||||
|
log.fatal(err.msg())
|
||||||
|
}
|
||||||
|
}
|
||||||
if options.document {
|
if options.document {
|
||||||
os.execute('v doc -f html -o ${module_dir.path}/docs ${module_dir.path}')
|
os.execute('v doc -f html -o ${module_dir.path}/docs ${module_dir.path}')
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,9 +143,9 @@ pub fn (function Function) vgen(options WriteOptions) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
params := params_.filter(!it.is_optional).map('${it.name} ${it.typ.symbol}').join(', ')
|
params := params_.filter(!it.is_optional).map(it.vgen()).join(', ')
|
||||||
|
|
||||||
receiver := if function.receiver.vgen() != '' {
|
receiver := if function.receiver.vgen().trim_space() != '' {
|
||||||
'(${function.receiver.vgen()})'
|
'(${function.receiver.vgen()})'
|
||||||
} else {''}
|
} else {''}
|
||||||
|
|
||||||
@@ -153,7 +153,6 @@ pub fn (function Function) vgen(options WriteOptions) string {
|
|||||||
result := Param{...function.result,
|
result := Param{...function.result,
|
||||||
name: ''
|
name: ''
|
||||||
}.vgen()
|
}.vgen()
|
||||||
println('debugzo ${result}')
|
|
||||||
|
|
||||||
mut function_str := $tmpl('templates/function/function.v.template')
|
mut function_str := $tmpl('templates/function/function.v.template')
|
||||||
|
|
||||||
@@ -181,11 +180,14 @@ pub fn (param Param) vgen() string {
|
|||||||
} else {
|
} else {
|
||||||
param.typ.symbol
|
param.typ.symbol
|
||||||
}
|
}
|
||||||
|
param_name := texttools.name_fix_snake(param.name)
|
||||||
mut vstr := '${param.name} ${sym}'
|
mut vstr := '${param_name} ${sym}'
|
||||||
if param.typ.is_reference {
|
if param.typ.is_reference {
|
||||||
vstr = '&${vstr}'
|
vstr = '&${vstr}'
|
||||||
}
|
}
|
||||||
|
if param.is_result {
|
||||||
|
vstr = '!${vstr}'
|
||||||
|
}
|
||||||
if param.mutable {
|
if param.mutable {
|
||||||
vstr = 'mut ${vstr}'
|
vstr = 'mut ${vstr}'
|
||||||
}
|
}
|
||||||
@@ -278,4 +280,6 @@ pub:
|
|||||||
overwrite bool
|
overwrite bool
|
||||||
document bool
|
document bool
|
||||||
prefix string
|
prefix string
|
||||||
|
compile bool // whether to compile the written code
|
||||||
|
test bool // whether to test the written code
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user