mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
freestanding: init consts
This commit is contained in:
parent
590566f8c4
commit
eb20dd39b1
@ -25,6 +25,7 @@ fn vcheck(vfile string) {
|
||||
fn main() {
|
||||
vcheck("string")
|
||||
vcheck("linuxsys")
|
||||
vcheck("consts")
|
||||
exit(0)
|
||||
}
|
||||
|
||||
|
15
vlib/builtin/bare/.checks/consts/consts.v
Normal file
15
vlib/builtin/bare/.checks/consts/consts.v
Normal file
@ -0,0 +1,15 @@
|
||||
module main
|
||||
|
||||
const (
|
||||
integer1 = 111
|
||||
integer2 = 222
|
||||
integer3 = 333
|
||||
integer9 = integer3 * 3
|
||||
abc = "123"
|
||||
)
|
||||
|
||||
fn main(){
|
||||
assert abc == "123"
|
||||
assert integer9 == 999
|
||||
println("constants are properly initialized")
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
module builtin
|
||||
|
||||
// called by the generated main/init
|
||||
fn init() {
|
||||
}
|
||||
|
||||
pub fn isnil(p voidptr) bool {
|
||||
return p == 0
|
||||
}
|
||||
|
@ -395,6 +395,19 @@ fn (v mut V) generate_init() {
|
||||
}
|
||||
}
|
||||
consts_init_body := v.cgen.consts_init.join_lines()
|
||||
|
||||
if v.pref.is_bare {
|
||||
// vlib can't have init_consts()
|
||||
v.cgen.genln('
|
||||
void init() {
|
||||
$call_mod_init_consts
|
||||
$consts_init_body
|
||||
builtin__init();
|
||||
$call_mod_init
|
||||
}
|
||||
')
|
||||
}
|
||||
|
||||
if !v.pref.is_bare {
|
||||
// vlib can't have `init_consts()`
|
||||
v.cgen.genln('void init() {
|
||||
@ -510,9 +523,9 @@ pub fn (v mut V) generate_main() {
|
||||
|
||||
pub fn (v mut V) gen_main_start(add_os_args bool){
|
||||
v.cgen.genln('int main(int argc, char** argv) { ')
|
||||
if !v.pref.is_bare {
|
||||
v.cgen.genln(' init();')
|
||||
}
|
||||
|
||||
v.cgen.genln(' init();')
|
||||
|
||||
if add_os_args && 'os' in v.table.imports {
|
||||
v.cgen.genln(' os__args = os__init_os_args(argc, (byteptr*)argv);')
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
pop rdi
|
||||
mov rsi,rsp
|
||||
and rsp,-16
|
||||
call main__main
|
||||
call main
|
||||
|
||||
mov rdi,rax /* syscall param 1 = rax (ret value of main) */
|
||||
mov rax,60 /* SYS_exit */
|
||||
|
Loading…
Reference in New Issue
Block a user