1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cc.v: build with "implicit-function-declaration" and fix declarations

required for the webassembly backend

2
This commit is contained in:
Alexander Medvednikov 2019-08-23 23:55:45 +03:00
parent 1b3a21f197
commit d98c20466e
5 changed files with 63 additions and 46 deletions

View File

@ -39,6 +39,9 @@ fn (v mut V) cc() {
else { else {
a << '-g' a << '-g'
} }
if v.os != .msvc {
a << '-Werror=implicit-function-declaration'
}
for f in v.generate_hotcode_reloading_compiler_flags() { for f in v.generate_hotcode_reloading_compiler_flags() {
a << f a << f

View File

@ -11,6 +11,11 @@ CommonCHeaders = '
#include <inttypes.h> // int64_t etc #include <inttypes.h> // int64_t etc
#include <string.h> // memcpy #include <string.h> // memcpy
#ifndef _WIN32
#include <ctype.h>
#include <locale.h> // tolower
#endif
#define EMPTY_STRUCT_DECLARATION #define EMPTY_STRUCT_DECLARATION
#define OPTION_CAST(x) (x) #define OPTION_CAST(x) (x)

View File

@ -8,7 +8,10 @@ module os
#include <signal.h> #include <signal.h>
#include <errno.h> #include <errno.h>
//#include <execinfo.h> // for backtrace_symbols_fd $if mac {
#include <execinfo.h> // for backtrace and backtrace_symbols_fd
#include <libproc.h> // proc_pidpath
}
/* /*
struct dirent { struct dirent {

View File

@ -1,10 +1,10 @@
module os module os
#include <dirent.h> #include <dirent.h>
#include <unistd.h> #include <unistd.h>
const ( const (
PathSeparator = '/' PathSeparator = '/'
) )
@ -19,7 +19,7 @@ pub fn get_error_msg(code int) string {
pub fn ls(path string) []string { pub fn ls(path string) []string {
mut res := []string mut res := []string
dir := C.opendir(path.str) dir := C.opendir(path.str)
if isnil(dir) { if isnil(dir) {
println('ls() couldnt open dir "$path"') println('ls() couldnt open dir "$path"')
print_c_errno() print_c_errno()

View File

@ -12,6 +12,12 @@ const (
) )
#include <time.h> #include <time.h>
$if !windows {
#include <sys/time.h>
#include <sys/wait.h>
}
struct Time { struct Time {
pub: pub:
year int year int
@ -26,7 +32,7 @@ pub:
fn C.localtime(int) *C.tm fn C.localtime(int) *C.tm
fn remove_me_when_c_bug_is_fixed() { // TODO fn remove_me_when_c_bug_is_fixed() { // TODO
} }
struct C.tm { struct C.tm {
@ -56,7 +62,7 @@ const (
// The unsigned zero year for internal calculations. // The unsigned zero year for internal calculations.
// Must be 1 mod 400, and times before it will not compute correctly, // Must be 1 mod 400, and times before it will not compute correctly,
// but otherwise can be changed at will. // but otherwise can be changed at will.
absoluteZeroYear = i64(-292277022399) absoluteZeroYear = i64(-292277022399)
secondsPerMinute = 60 secondsPerMinute = 60
secondsPerHour = 60 * secondsPerMinute secondsPerHour = 60 * secondsPerMinute
@ -66,7 +72,7 @@ const (
daysPer100Years = 365*100 + 24 daysPer100Years = 365*100 + 24
daysPer4Years = 365*4 + 1 daysPer4Years = 365*4 + 1
daysBefore = [ daysBefore = [
0, 0,
31, 31,
31 + 28, 31 + 28,
@ -80,13 +86,13 @@ const (
31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31, 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30, 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30,
31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31, 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31,
] ]
)
// Based on Go's time package. )
// Copyright 2009 The Go Authors.
// Based on Go's time package.
// Copyright 2009 The Go Authors.
pub fn unix(abs int) Time { pub fn unix(abs int) Time {
// Split into time and day. // Split into time and day.
mut d := abs / secondsPerDay mut d := abs / secondsPerDay
@ -122,29 +128,29 @@ pub fn unix(abs int) Time {
d -= 365 * n d -= 365 * n
yday := int(d) yday := int(d)
mut day := yday mut day := yday
year := abs / int(3.154e+7) + 1970 //int(i64(y) + absoluteZeroYear) year := abs / int(3.154e+7) + 1970 //int(i64(y) + absoluteZeroYear)
hour := int(abs%secondsPerDay) / secondsPerHour hour := int(abs%secondsPerDay) / secondsPerHour
minute := int(abs % secondsPerHour) / secondsPerMinute minute := int(abs % secondsPerHour) / secondsPerMinute
second := int(abs % secondsPerMinute) second := int(abs % secondsPerMinute)
if is_leap_year(year) { if is_leap_year(year) {
// Leap year // Leap year
if day > 31+29-1 { if day > 31+29-1 {
// After leap day; pretend it wasn't there. // After leap day; pretend it wasn't there.
day-- day--
} else if day == 31+29-1 { } else if day == 31+29-1 {
// Leap day. // Leap day.
day = 29 day = 29
return Time{year:year, month:2, day:day, hour:hour, minute: minute, second: second} return Time{year:year, month:2, day:day, hour:hour, minute: minute, second: second}
} }
} }
// Estimate month on assumption that every month has 31 days. // Estimate month on assumption that every month has 31 days.
// The estimate may be too low by at most one month, so adjust. // The estimate may be too low by at most one month, so adjust.
mut month := day / 31 mut month := day / 31
mut begin := 0 mut begin := 0
end := int(daysBefore[month+1]) end := int(daysBefore[month+1])
if day >= end { if day >= end {
month++ month++
@ -155,7 +161,7 @@ pub fn unix(abs int) Time {
month++ // because January is 1 month++ // because January is 1
day = day - begin + 1 day = day - begin + 1
return Time{year:year, month: month, day:day, hour:hour, minute: minute, second: second} return Time{year:year, month: month, day:day, hour:hour, minute: minute, second: second}
} }
pub fn convert_ctime(t tm) Time { pub fn convert_ctime(t tm) Time {
@ -166,7 +172,7 @@ pub fn convert_ctime(t tm) Time {
hour: t.tm_hour hour: t.tm_hour
minute: t.tm_min minute: t.tm_min
second: t.tm_sec second: t.tm_sec
uni: C.mktime(&t) uni: C.mktime(&t)
} }
} }
@ -377,52 +383,52 @@ pub fn (t Time) weekday_str() string {
struct C.timeval { struct C.timeval {
tv_sec int tv_sec int
tv_usec int tv_usec int
} }
// in ms // in ms
pub fn ticks() i64 { pub fn ticks() i64 {
$if windows { $if windows {
return C.GetTickCount() return C.GetTickCount()
} }
$else { $else {
ts := C.timeval{} ts := C.timeval{}
C.gettimeofday(&ts,0) C.gettimeofday(&ts,0)
return ts.tv_sec * 1000 + (ts.tv_usec / 1000) return ts.tv_sec * 1000 + (ts.tv_usec / 1000)
} }
/* /*
t := i64(C.mach_absolute_time()) t := i64(C.mach_absolute_time())
# Nanoseconds elapsedNano = AbsoluteToNanoseconds( *(AbsoluteTime *) &t ); # Nanoseconds elapsedNano = AbsoluteToNanoseconds( *(AbsoluteTime *) &t );
# return (double)(* (uint64_t *) &elapsedNano) / 1000000; # return (double)(* (uint64_t *) &elapsedNano) / 1000000;
*/ */
} }
pub fn sleep(seconds int) { pub fn sleep(seconds int) {
$if windows { $if windows {
C._sleep(seconds * 1000) C._sleep(seconds * 1000)
} }
$else { $else {
C.sleep(seconds) C.sleep(seconds)
} }
} }
pub fn usleep(n int) { pub fn usleep(n int) {
$if windows { $if windows {
//C._usleep(n) //C._usleep(n)
} }
$else { $else {
C.usleep(n) C.usleep(n)
} }
} }
pub fn sleep_ms(n int) { pub fn sleep_ms(n int) {
$if windows { $if windows {
C.Sleep(n) C.Sleep(n)
} }
$else { $else {
C.usleep(n * 1000) C.usleep(n * 1000)
} }
} }
// Determine whether a year is a leap year. // Determine whether a year is a leap year.
@ -436,6 +442,6 @@ pub fn days_in_month(month, year int) ?int {
return error('Invalid month: $month') return error('Invalid month: $month')
} }
extra := if month == 2 && is_leap_year(year) {1} else {0} extra := if month == 2 && is_leap_year(year) {1} else {0}
res := MonthDays[month-1] + extra res := MonthDays[month-1] + extra
return res return res
} }