diff --git a/compiler/cc.v b/compiler/cc.v index aa6c7e5d57..4f4b1b79dd 100644 --- a/compiler/cc.v +++ b/compiler/cc.v @@ -106,25 +106,29 @@ fn (v mut V) cc() { a << f } - libs := ''// builtin.o os.o http.o etc + mut libs := ''// builtin.o os.o http.o etc if v.pref.build_mode == .build_module { a << '-c' } - else if v.pref.build_mode == .default_mode { + else if v.pref.is_debug { + libs = '$v_modules_path/vlib/builtin.o ' + + '$v_modules_path/vlib/strings.o '+ + '$v_modules_path/vlib/math.o ' /* - // TODO - libs = '$v_modules_path/vlib/builtin.o' if !os.file_exists(libs) { println('object file `$libs` not found') exit(1) } + */ for imp in v.table.imports { if imp == 'webview' { continue } - libs += ' "$v_modules_path/vlib/${imp}.o"' + path := '"$v_modules_path/vlib/${imp}.o"' + if os.file_exists(path) { + libs += ' ' + path + } } - */ } if v.pref.sanitize { a << '-fsanitize=leak' diff --git a/compiler/module_header.v b/compiler/module_header.v index 058d69d33a..86edf0ac56 100644 --- a/compiler/module_header.v +++ b/compiler/module_header.v @@ -11,7 +11,7 @@ import ( /* .vh generation logic. - .vh files contains only function signatures, consts, and types. + .vh files contain only function signatures, consts, and types. They are used together with pre-compiled modules. */ @@ -95,7 +95,11 @@ fn v_type_str(typ_ string) string { return '[]' + typ.right(6) } if typ.contains('__') { - return typ.all_after('__') + opt := typ.starts_with('?') + typ = typ.all_after('__') + if opt { + typ = '?' + typ + } } return typ } @@ -213,8 +217,8 @@ fn (v &V) generate_vh() { // Methods file.writeln('\n// Methods //////////////////') for _, typ in v.table.typesmap { - if typ.mod != v.mod { //&& typ.mod != '' { - //println('skipping method typ $typ.name mod=$typ.mod') + if typ.mod != v.mod && !(v.mod == 'builtin' && typ.mod == '') { + println('skipping method typ $typ.name mod=$typ.mod') continue } for method in typ.methods { diff --git a/compiler/parser.v b/compiler/parser.v index 18dd91fab7..ab814b856f 100644 --- a/compiler/parser.v +++ b/compiler/parser.v @@ -509,6 +509,8 @@ fn (p mut Parser) const_decl() { // .vh files don't have const values, just types: `const (a int)` typ = p.get_type() p.table.register_const(name, typ, p.mod) + p.cgen.consts << ('extern ' + + p.table.cgen_name_type_pair(name, typ)) + ';' continue // Don't generate C code when building a .vh file } else { p.check_space(.assign) @@ -524,7 +526,9 @@ fn (p mut Parser) const_decl() { // TODO hack // cur_line has const's value right now. if it's just a number, then optimize generation: // output a #define so that we don't pollute the binary with unnecessary global vars - if is_compile_time_const(p.cgen.cur_line) { + // Do not do this when building a module, otherwise the consts + // will not be accessible. + if p.pref.build_mode != .build_module && is_compile_time_const(p.cgen.cur_line) { p.cgen.consts << '#define $name $p.cgen.cur_line' p.cgen.resetln('') p.fgenln('')