v2: enable compilation of short programs with no 'import os'
parent
d8bcd13e86
commit
fb4f7b6827
|
@ -665,10 +665,12 @@ fn (g mut Gen) gen_fn_decl(it ast.FnDecl) {
|
|||
}
|
||||
if is_main {
|
||||
g.writeln('_vinit();')
|
||||
if g.autofree {
|
||||
g.writeln('free(_const_os__args.data); // empty, inited in _vinit()')
|
||||
if g.is_importing_os() {
|
||||
if g.autofree {
|
||||
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)
|
||||
// ////////////
|
||||
|
@ -1794,7 +1796,10 @@ fn (g mut Gen) write_init_function() {
|
|||
if g.autofree {
|
||||
g.writeln('void _vcleanup() {')
|
||||
g.writeln('puts("cleaning up...");')
|
||||
g.writeln('free(_const_os__args.data);')
|
||||
if g.is_importing_os() {
|
||||
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('}')
|
||||
}
|
||||
|
@ -2318,3 +2323,7 @@ pub fn (g mut Gen) write_tests_main() {
|
|||
}
|
||||
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]
|
||||
if line_a.trim_space() != line_b.trim_space() {
|
||||
println('${path}: Got\n$a')
|
||||
println('${term_fail} near line: ${i}')
|
||||
println(term.red('actual :${line_a}'))
|
||||
println(term.red('expected:${line_b}'))
|
||||
println('${path}:${i}: ${term_fail}')
|
||||
println(term.bold(term.bright_yellow('actual : ')) + line_a)
|
||||
println(term.green('expected: ') + line_b)
|
||||
println(lines_b[i + 1])
|
||||
println(lines_b[i + 2])
|
||||
// exit(1)
|
||||
|
|
|
@ -48,7 +48,6 @@ struct varg_int {
|
|||
//
|
||||
int main(int argc, char** argv) {
|
||||
_vinit();
|
||||
_const_os__args = os__init_os_args(argc, (byteptr*)argv);
|
||||
int a = 10;
|
||||
a++;
|
||||
int negative = -a;
|
||||
|
|
|
@ -78,7 +78,6 @@ void end() {
|
|||
|
||||
int main(int argc, char** argv) {
|
||||
_vinit();
|
||||
_const_os__args = os__init_os_args(argc, (byteptr*)argv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,6 @@ void handle_expr(Expr e) {
|
|||
|
||||
int main(int argc, char** argv) {
|
||||
_vinit();
|
||||
_const_os__args = os__init_os_args(argc, (byteptr*)argv);
|
||||
User user = (User){
|
||||
.age = 0,
|
||||
.name = tos3(""),
|
||||
|
|
|
@ -24,7 +24,6 @@ int Bar_testa(Bar* b);
|
|||
|
||||
int main(int argc, char** argv) {
|
||||
_vinit();
|
||||
_const_os__args = os__init_os_args(argc, (byteptr*)argv);
|
||||
Bar b = (Bar){
|
||||
.a = 122,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue