mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v2: enable compilation of short programs with no 'import os'
This commit is contained in:
parent
d8bcd13e86
commit
fb4f7b6827
|
@ -665,11 +665,13 @@ fn (g mut Gen) gen_fn_decl(it ast.FnDecl) {
|
||||||
}
|
}
|
||||||
if is_main {
|
if is_main {
|
||||||
g.writeln('_vinit();')
|
g.writeln('_vinit();')
|
||||||
|
if g.is_importing_os() {
|
||||||
if g.autofree {
|
if g.autofree {
|
||||||
g.writeln('free(_const_os__args.data); // empty, inited in _vinit()')
|
g.writeln('free(_const_os__args.data); // empty, inited in _vinit()')
|
||||||
}
|
}
|
||||||
g.writeln('_const_os__args = os__init_os_args(argc, (byteptr*)argv);')
|
g.writeln('_const_os__args = os__init_os_args(argc, (byteptr*)argv);')
|
||||||
}
|
}
|
||||||
|
}
|
||||||
g.stmts(it.stmts)
|
g.stmts(it.stmts)
|
||||||
// ////////////
|
// ////////////
|
||||||
if g.autofree {
|
if g.autofree {
|
||||||
|
@ -1794,7 +1796,10 @@ fn (g mut Gen) write_init_function() {
|
||||||
if g.autofree {
|
if g.autofree {
|
||||||
g.writeln('void _vcleanup() {')
|
g.writeln('void _vcleanup() {')
|
||||||
g.writeln('puts("cleaning up...");')
|
g.writeln('puts("cleaning up...");')
|
||||||
|
if g.is_importing_os() {
|
||||||
g.writeln('free(_const_os__args.data);')
|
g.writeln('free(_const_os__args.data);')
|
||||||
|
g.writeln('string_free(_const_os__wd_at_startup);')
|
||||||
|
}
|
||||||
g.writeln('free(_const_strconv__ftoa__powers_of_10.data);')
|
g.writeln('free(_const_strconv__ftoa__powers_of_10.data);')
|
||||||
g.writeln('}')
|
g.writeln('}')
|
||||||
}
|
}
|
||||||
|
@ -2318,3 +2323,7 @@ pub fn (g mut Gen) write_tests_main() {
|
||||||
}
|
}
|
||||||
g.writeln('return 0; }')
|
g.writeln('return 0; }')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn (g &Gen) is_importing_os() bool {
|
||||||
|
return 'os' in g.table.imports
|
||||||
|
}
|
||||||
|
|
|
@ -62,9 +62,9 @@ fn compare_texts(a, b, path string) bool {
|
||||||
line_b := lines_b[i]
|
line_b := lines_b[i]
|
||||||
if line_a.trim_space() != line_b.trim_space() {
|
if line_a.trim_space() != line_b.trim_space() {
|
||||||
println('${path}: Got\n$a')
|
println('${path}: Got\n$a')
|
||||||
println('${term_fail} near line: ${i}')
|
println('${path}:${i}: ${term_fail}')
|
||||||
println(term.red('actual :${line_a}'))
|
println(term.bold(term.bright_yellow('actual : ')) + line_a)
|
||||||
println(term.red('expected:${line_b}'))
|
println(term.green('expected: ') + line_b)
|
||||||
println(lines_b[i + 1])
|
println(lines_b[i + 1])
|
||||||
println(lines_b[i + 2])
|
println(lines_b[i + 2])
|
||||||
// exit(1)
|
// exit(1)
|
||||||
|
|
|
@ -48,7 +48,6 @@ struct varg_int {
|
||||||
//
|
//
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
_vinit();
|
_vinit();
|
||||||
_const_os__args = os__init_os_args(argc, (byteptr*)argv);
|
|
||||||
int a = 10;
|
int a = 10;
|
||||||
a++;
|
a++;
|
||||||
int negative = -a;
|
int negative = -a;
|
||||||
|
|
|
@ -78,7 +78,6 @@ void end() {
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
_vinit();
|
_vinit();
|
||||||
_const_os__args = os__init_os_args(argc, (byteptr*)argv);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,6 @@ void handle_expr(Expr e) {
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
_vinit();
|
_vinit();
|
||||||
_const_os__args = os__init_os_args(argc, (byteptr*)argv);
|
|
||||||
User user = (User){
|
User user = (User){
|
||||||
.age = 0,
|
.age = 0,
|
||||||
.name = tos3(""),
|
.name = tos3(""),
|
||||||
|
|
|
@ -24,7 +24,6 @@ int Bar_testa(Bar* b);
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
_vinit();
|
_vinit();
|
||||||
_const_os__args = os__init_os_args(argc, (byteptr*)argv);
|
|
||||||
Bar b = (Bar){
|
Bar b = (Bar){
|
||||||
.a = 122,
|
.a = 122,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user