show an info message if a C compiler is not installed

pull/2924/head
Alexander Medvednikov 2019-11-28 16:49:35 +03:00
parent e31d892598
commit 9e19472c33
6 changed files with 87 additions and 41 deletions

View File

@ -38,11 +38,10 @@
- declarative ui with hot reload (similar to swiftui)
- "building a simple blog with vweb" tutorial + youtube video
+ fix interfaces
- merge v.c and v_win.c
+ fast.vlang.io
+ bare metal support
+ inline assembly
+ x64 machine code generation (ELF)
- require explicit C.fn definitions, add all missing definitions
+ require explicit C.fn definitions, add all missing definitions

View File

@ -1,11 +1,14 @@
fn test_fn() {
println('test fn')
}
fn main() {
println('x64 test')
for _ in 0..5 {
println('Hello world from V x64 machine code generator!')
}
println('Hello again!')
test_fn()
println('dne')
}
fn test_fn() {
println('test fn')
}

View File

@ -311,12 +311,14 @@ start:
goto start
}
}
verror('C compiler error, while attempting to run: \n' +
'-----------------------------------------------------------\n' +
'$cmd\n' +
'-----------------------------------------------------------\n' +
'Probably your C compiler is missing. \n' +
'Please reinstall it, or make it available in your PATH.')
'Please reinstall it, or make it available in your PATH.\n\n' +
missing_compiler_info())
}
if v.pref.is_debug {
@ -512,3 +514,16 @@ fn get_cmdline_cflags(args []string) string {
}
return cflags
}
fn missing_compiler_info() string {
$if windows {
return 'https://github.com/vlang/v/wiki/Installing-a-C-compiler-on-Windows'
}
$if linux {
return 'On Debian/Ubuntu, run `sudo apt install build-essential`'
}
$if mac {
return 'Install command line XCode tools with `xcode-select --install`'
}
return ''
}

View File

@ -512,6 +512,9 @@ fn (p mut Parser) fn_decl() {
f.defer_text[f.scope_level] = ' ${cgen_name}_time += time__ticks() - _PROF_START;'
}
}
if p.pref.x64 {
p.x64.register_function_address(f.name)
}
p.statements_no_rcbr()
//p.cgen.nogen = false
// Print counting result after all statements in main
@ -712,6 +715,9 @@ fn (p mut Parser) fn_call(f mut Fn, method_ph int, receiver_var, receiver_type s
if is_comptime_define {
p.cgen.nogen = true
}
if p.pref.x64 && !p.first_pass() {
p.x64.call_fn(f.name)
}
p.calling_c = f.is_c
if f.is_c && !p.builtin_mod {
if f.name == 'free' {

View File

@ -15,6 +15,7 @@ mut:
file_size_pos i64
main_fn_addr i64
code_start_pos i64 // location of the start of the assembly instructions
fn_addr map[string]i64
//string_addr map[string]i64
}
@ -44,6 +45,10 @@ pub fn new_gen(out_name string) &Gen {
}
}
pub fn (g &Gen) pos() i64 {
return g.buf.len
}
fn (g mut Gen) write8(n int) {
// write 1 byte
@ -155,10 +160,13 @@ fn (g mut Gen) mov64(reg Register, val i64) {
g.write64(val)
}
fn (g mut Gen) call(val int) {
//println('call val=$val')
fn (g mut Gen) call(addr int) {
//rel := g.abs_to_rel_addr(addr)
rel := 0xffffffff - int(abs(addr - g.buf.len))-1
println('call addr=$addr rel_addr=$addr pos=$g.buf.len')
g.write8(0xe8)
g.write32(val)
g.write32(addr)
}
fn (g mut Gen) syscall() {
@ -228,4 +236,19 @@ fn (g mut Gen) mov(reg Register, val int) {
g.write32(val)
}
pub fn (g mut Gen) register_function_address(name string) {
addr := g.pos()
println('reg fn addr $name $addr')
g.fn_addr[name] = addr
}
pub fn (g mut Gen) call_fn(name string) {
if !name.contains('__') {
return
}
addr := g.fn_addr[name]
g.call(int(addr))
println('call $name $addr')
}