diff --git a/vlib/strings/builder.c.v b/vlib/strings/builder.c.v index 76a5f92d4f..c59718ca84 100644 --- a/vlib/strings/builder.c.v +++ b/vlib/strings/builder.c.v @@ -47,6 +47,11 @@ pub fn (b mut Builder) go_back(n int) { b.len -= n } +pub fn (b mut Builder) go_back_to(pos int) { + b.buf.trim(pos) + b.len = pos +} + pub fn (b mut Builder) writeln(s string) { // for c in s { // b.buf << c diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index e5a53d8243..c7cffa7430 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -308,7 +308,7 @@ fn (mut v Builder) cc() { if v.pref.use_cache { //vexe := pref.vexe_path() - cached_modules:= [ 'builtin', 'os' ]//, 'math'] + cached_modules:= [ 'builtin', 'os', 'math', 'strconv', 'strings'] for cfile in cached_modules{ ofile := os.join_path(pref.default_module_path, 'cache', 'vlib', cfile + '.o') if !os.exists(ofile) { diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index aebac12d51..5478c1bc37 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -58,6 +58,7 @@ struct Gen { pcs_declarations strings.Builder // -prof profile counter declarations for each function table &table.Table pref &pref.Preferences + module_built string mut: file ast.File fn_decl &ast.FnDecl // pointer to the FnDecl we are currently inside otherwise 0 @@ -86,6 +87,8 @@ mut: array_fn_definitions []string // array equality functions that have been defined is_json_fn bool // inside json.encode() pcs []ProfileCounterMeta // -prof profile counter fn_names => fn counter name + attr string + is_builtin_mod bool } const ( @@ -122,6 +125,7 @@ pub fn cgen(files []ast.File, table &table.Table, pref &pref.Preferences) string fn_decl: 0 autofree: true indent: -1 + module_built: pref.path.after('vlib/') } g.init() // @@ -159,7 +163,6 @@ pub fn cgen(files []ast.File, table &table.Table, pref &pref.Preferences) string // g.finish() // - b := strings.new_builder(250000) b.writeln(g.hashes()) b.writeln(g.comptime_defines.str()) @@ -238,7 +241,6 @@ pub fn (mut g Gen) finish() { } g.stringliterals.writeln('// << string literal consts') g.stringliterals.writeln('') - if g.pref.is_prof { g.gen_vprint_profile_stats() } @@ -446,8 +448,9 @@ fn (mut g Gen) stmt(node ast.Stmt) { g.gen_assign_stmt(it) } ast.Attr { + g.attr = it.name if it.name == 'inline' { - g.writeln(it.name) + //g.writeln(it.name) } else { g.writeln('//[$it.name]') } @@ -512,12 +515,30 @@ fn (mut g Gen) stmt(node ast.Stmt) { } } ast.FnDecl { + mut skip := false + pos := g.out.buf.len + if g.pref.build_mode==.build_module { + if !it.name.starts_with(g.module_built + '.'){ + // Skip functions that don't have to be generated + // for this module. + skip = true + } + if g.is_builtin_mod && g.module_built == 'builtin' { + skip=false + } + if !skip { + println('build module `$g.module_built` fn `$it.name`') + } + } fn_start_pos := g.out.len g.fn_decl = it // &it g.gen_fn_decl(it) if g.pref.printfn_list.len > 0 && g.last_fn_c_name in g.pref.printfn_list { println(g.out.after(fn_start_pos)) } + if skip { + g.out.go_back_to(pos) + } g.writeln('') } ast.ForCStmt { @@ -584,7 +605,9 @@ fn (mut g Gen) stmt(node ast.Stmt) { g.definitions.writeln('\tint _interface_idx;') g.definitions.writeln('} $it.name;') } - ast.Module {} + ast.Module { + g.is_builtin_mod = it.name=='builtin' + } ast.Return { g.write_defer_stmts_when_needed() g.return_statement(it) diff --git a/vlib/v/gen/fn.v b/vlib/v/gen/fn.v index e0941ed3ca..163ff5d2bd 100644 --- a/vlib/v/gen/fn.v +++ b/vlib/v/gen/fn.v @@ -12,6 +12,10 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) { // || it.no_body { return } + if g.attr == 'inline' { + g.write('inline ') + g.attr = '' + } g.reset_tmp_count() is_main := it.name == 'main' if is_main {