mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: C++ compiler support
This commit is contained in:
@ -19,10 +19,10 @@ pub mut:
|
||||
fn __new_array(mylen int, cap int, elm_size int) array {
|
||||
cap_ := if cap < mylen { mylen } else { cap }
|
||||
arr := array{
|
||||
len: mylen
|
||||
cap: cap_
|
||||
element_size: elm_size
|
||||
data: vcalloc(cap_ * elm_size)
|
||||
len: mylen
|
||||
cap: cap_
|
||||
}
|
||||
return arr
|
||||
}
|
||||
@ -30,10 +30,10 @@ fn __new_array(mylen int, cap int, elm_size int) array {
|
||||
fn __new_array_with_default(mylen int, cap int, elm_size int, val voidptr) array {
|
||||
cap_ := if cap < mylen { mylen } else { cap }
|
||||
arr := array{
|
||||
len: mylen
|
||||
cap: cap_
|
||||
element_size: elm_size
|
||||
data: vcalloc(cap_ * elm_size)
|
||||
len: mylen
|
||||
cap: cap_
|
||||
}
|
||||
if val != 0 {
|
||||
for i in 0..arr.len {
|
||||
@ -48,10 +48,10 @@ fn new_array_from_c_array(len, cap, elm_size int, c_array voidptr) array {
|
||||
cap_ := if cap < len { len } else { cap }
|
||||
|
||||
arr := array{
|
||||
len: len
|
||||
cap: cap_
|
||||
element_size: elm_size
|
||||
data: vcalloc(cap_ * elm_size)
|
||||
len: len
|
||||
cap: cap_
|
||||
}
|
||||
// TODO Write all memory functions (like memcpy) in V
|
||||
C.memcpy(arr.data, c_array, len * elm_size)
|
||||
@ -61,10 +61,10 @@ fn new_array_from_c_array(len, cap, elm_size int, c_array voidptr) array {
|
||||
// Private function, used by V (`nums := [1, 2, 3] !`)
|
||||
fn new_array_from_c_array_no_alloc(len, cap, elm_size int, c_array voidptr) array {
|
||||
arr := array{
|
||||
len: len
|
||||
cap: cap
|
||||
element_size: elm_size
|
||||
data: c_array
|
||||
len: len
|
||||
cap: cap
|
||||
}
|
||||
return arr
|
||||
}
|
||||
@ -98,10 +98,10 @@ pub fn (a array) repeat(count int) array {
|
||||
size = a.element_size
|
||||
}
|
||||
arr := array{
|
||||
len: count * a.len
|
||||
cap: count * a.len
|
||||
element_size: a.element_size
|
||||
data: vcalloc(size)
|
||||
len: count * a.len
|
||||
cap: count * a.len
|
||||
}
|
||||
for i in 0..count {
|
||||
C.memcpy(byteptr(arr.data) + i * a.len * a.element_size, byteptr(a.data), a.len * a.element_size)
|
||||
@ -241,10 +241,10 @@ pub fn (a &array) clone() array {
|
||||
size++
|
||||
}
|
||||
arr := array{
|
||||
len: a.len
|
||||
cap: a.cap
|
||||
element_size: a.element_size
|
||||
data: vcalloc(size)
|
||||
len: a.len
|
||||
cap: a.cap
|
||||
}
|
||||
C.memcpy(byteptr(arr.data), a.data, a.cap * a.element_size)
|
||||
return arr
|
||||
@ -312,10 +312,10 @@ pub fn (a array) reverse() array {
|
||||
return a
|
||||
}
|
||||
arr := array{
|
||||
len: a.len
|
||||
cap: a.cap
|
||||
element_size: a.element_size
|
||||
data: vcalloc(a.cap * a.element_size)
|
||||
len: a.len
|
||||
cap: a.cap
|
||||
}
|
||||
for i in 0..a.len {
|
||||
//C.memcpy(arr.data + i * arr.element_size, &a[a.len - 1 - i], arr.element_size)
|
||||
|
@ -116,7 +116,7 @@ fn print_backtrace_skipping_top_frames_linux(skipframes int) bool {
|
||||
buf := [1000]byte
|
||||
mut output := ''
|
||||
for C.fgets(charptr(buf), 1000, f) != 0 {
|
||||
output += tos(buf, vstrlen(buf))
|
||||
output += tos(byteptr(buf), vstrlen(byteptr(buf)))
|
||||
}
|
||||
output = output.trim_space() + ':'
|
||||
if C.pclose(f) != 0 {
|
||||
|
@ -12,7 +12,7 @@ fn C.free(ptr voidptr)
|
||||
fn C.exit(code int)
|
||||
|
||||
|
||||
fn C.qsort(voidptr, int, int, voidptr)
|
||||
fn C.qsort(voidptr, int, int, qsort_callback_func)
|
||||
|
||||
|
||||
fn C.sprintf(a ...voidptr) int
|
||||
|
@ -383,8 +383,8 @@ pub fn (c rune) str() string {
|
||||
|
||||
pub fn (c byte) str() string {
|
||||
mut str := string{
|
||||
len: 1
|
||||
str: malloc(2)
|
||||
len: 1
|
||||
}
|
||||
str.str[0] = c
|
||||
str.str[1] = `\0`
|
||||
|
@ -4,21 +4,21 @@
|
||||
module builtin
|
||||
/*
|
||||
struct Option2<T> {
|
||||
data T
|
||||
error string
|
||||
ecode int
|
||||
ok bool
|
||||
is_none bool
|
||||
error string
|
||||
ecode int
|
||||
data T
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
struct Option {
|
||||
data [400]byte
|
||||
error string
|
||||
ecode int
|
||||
ok bool
|
||||
is_none bool
|
||||
error string
|
||||
ecode int
|
||||
data [400]byte
|
||||
}
|
||||
|
||||
pub fn (o Option) str() string {
|
||||
@ -46,19 +46,24 @@ fn opt_ok(data voidptr, size int) Option {
|
||||
// used internally when returning `none`
|
||||
fn opt_none() Option {
|
||||
return Option{
|
||||
ok: false
|
||||
is_none: true
|
||||
}
|
||||
}
|
||||
|
||||
pub fn error(s string) Option {
|
||||
return Option{
|
||||
ok: false
|
||||
is_none: false
|
||||
error: s
|
||||
}
|
||||
}
|
||||
|
||||
pub fn error_with_code(s string, code int) Option {
|
||||
return Option{
|
||||
ok: false
|
||||
is_none: false
|
||||
error: s
|
||||
ecode: code
|
||||
}
|
||||
}
|
||||
}
|
@ -31,10 +31,10 @@ pub mut:
|
||||
|
||||
struct mapnode {
|
||||
mut:
|
||||
keys [11]string // TODO: Should use `max_size`
|
||||
values [11]voidptr // TODO: Should use `max_size`
|
||||
children &voidptr
|
||||
size int
|
||||
keys [11]string // TODO: Should use `max_size`
|
||||
values [11]voidptr // TODO: Should use `max_size`
|
||||
}
|
||||
|
||||
fn new_sorted_map(n, value_bytes int) SortedMap { // TODO: Remove `n`
|
||||
|
@ -122,8 +122,8 @@ fn (a string) clone_static() string {
|
||||
|
||||
pub fn (a string) clone() string {
|
||||
mut b := string{
|
||||
len: a.len
|
||||
str: malloc(a.len + 1)
|
||||
len: a.len
|
||||
}
|
||||
for i in 0..a.len {
|
||||
b.str[i] = a.str[i]
|
||||
@ -399,8 +399,8 @@ fn (s string) ge(a string) bool {
|
||||
fn (s string) add(a string) string {
|
||||
new_len := a.len + s.len
|
||||
mut res := string{
|
||||
len: new_len
|
||||
str: malloc(new_len + 1)
|
||||
len: new_len
|
||||
}
|
||||
for j in 0..s.len {
|
||||
res.str[j] = s.str[j]
|
||||
@ -537,8 +537,8 @@ pub fn (s string) substr(start, end int) string {
|
||||
}
|
||||
len := end - start
|
||||
mut res := string{
|
||||
len: len
|
||||
str: malloc(len + 1)
|
||||
len: len
|
||||
}
|
||||
for i in 0..len {
|
||||
res.str[i] = s.str[start + i]
|
||||
@ -1284,8 +1284,8 @@ pub fn (s string) reverse() string {
|
||||
return s
|
||||
}
|
||||
mut res := string{
|
||||
len: s.len
|
||||
str: malloc(s.len)
|
||||
len: s.len
|
||||
}
|
||||
for i := s.len - 1; i >= 0; i-- {
|
||||
res.str[s.len - i - 1] = s[i]
|
||||
|
Reference in New Issue
Block a user