v2: fix hello world compilation with tcc
parent
9c536f2233
commit
efe21fed66
|
@ -704,8 +704,9 @@ fn (g mut Gen) expr(node ast.Expr) {
|
|||
g.write('new_array($it.exprs.len, $it.exprs.len, sizeof($elem_type_str))')
|
||||
}
|
||||
else {
|
||||
g.write('new_array_from_c_array($it.exprs.len, $it.exprs.len, sizeof($elem_type_str), ')
|
||||
g.writeln('($elem_type_str[]){\t')
|
||||
len := it.exprs.len
|
||||
g.write('new_array_from_c_array($len, $len, sizeof($elem_type_str), ')
|
||||
g.writeln('($elem_type_str[$len]){\t')
|
||||
for expr in it.exprs {
|
||||
g.expr(expr)
|
||||
g.write(', ')
|
||||
|
|
|
@ -17,10 +17,9 @@ fn test_c_files() {
|
|||
vroot := os.dir(vexe)
|
||||
for i in 1 .. (nr_tests + 1) {
|
||||
path := '$vroot/vlib/v/gen/tests/${i}.vv'
|
||||
mut ctext := os.read_file('$vroot/vlib/v/gen/tests/${i}.c') or {
|
||||
ctext := os.read_file('$vroot/vlib/v/gen/tests/${i}.c') or {
|
||||
panic(err)
|
||||
}
|
||||
ctext = ctext // unused warn
|
||||
mut b := builder.new_builder(pref.Preferences{})
|
||||
b.module_search_paths = ['$vroot/vlib/v/gen/tests/']
|
||||
mut res := b.gen_c([path]).after('#endbuiltin')
|
||||
|
@ -44,7 +43,9 @@ fn compare_texts(a, b, path string) bool {
|
|||
lines_a_ := a.trim_space().split_into_lines()
|
||||
lines_b_ := b.trim_space().split_into_lines()
|
||||
lines_a := lines_a_.filter(it != '')
|
||||
lines_b := lines_b_.filter(it != '')
|
||||
mut lines_b := lines_b_.filter(it != '')
|
||||
lines_b << ''
|
||||
lines_b << ''
|
||||
/*
|
||||
if lines_a.len != lines_b.len {
|
||||
println(term.red('different len'))
|
||||
|
@ -60,9 +61,10 @@ fn compare_texts(a, b, path string) bool {
|
|||
}
|
||||
line_b := lines_b[i]
|
||||
if line_a.trim_space() != line_b.trim_space() {
|
||||
println('${path}: got\n$a')
|
||||
println('${term_fail} ${i}')
|
||||
println(term.red('i=$i "$line_a" expected="$line_b"'))
|
||||
println('${path}: Got\n$a')
|
||||
println('${term_fail} near line: ${i}')
|
||||
println(term.red('actual :${line_a}'))
|
||||
println(term.red('expected:${line_b}'))
|
||||
println(lines_b[i + 1])
|
||||
println(lines_b[i + 2])
|
||||
// exit(1)
|
||||
|
|
|
@ -75,7 +75,7 @@ void foo(int a) {
|
|||
for (int i = 0;
|
||||
i < 10; i++) {
|
||||
}
|
||||
array_int nums = new_array_from_c_array(3, 3, sizeof(int), (int[]){
|
||||
array_int nums = new_array_from_c_array(3, 3, sizeof(int), (int[3]){
|
||||
1, 2, 3,
|
||||
});
|
||||
array_int nums2 = array_slice(nums, 0, 2);
|
||||
|
@ -83,16 +83,16 @@ i < 10; i++) {
|
|||
array_int nums4 = array_slice(nums, 1, nums.len);
|
||||
int number = (*(int*)array_get(nums, 0));
|
||||
array_set(&nums, 1, &(int[]) { 10 });
|
||||
array_bool bools = new_array_from_c_array(2, 2, sizeof(bool), (bool[]){
|
||||
array_bool bools = new_array_from_c_array(2, 2, sizeof(bool), (bool[2]){
|
||||
true, false,
|
||||
});
|
||||
array_User users = new_array_from_c_array(1, 1, sizeof(User), (User[]){
|
||||
array_User users = new_array_from_c_array(1, 1, sizeof(User), (User[1]){
|
||||
(User){
|
||||
.age = 0,
|
||||
},
|
||||
});
|
||||
bool b = (*(bool*)array_get(bools, 0));
|
||||
array_string mystrings = new_array_from_c_array(2, 2, sizeof(string), (string[]){
|
||||
array_string mystrings = new_array_from_c_array(2, 2, sizeof(string), (string[2]){
|
||||
tos3("a"), tos3("b"),
|
||||
});
|
||||
string s = (*(string*)array_get(mystrings, 0));
|
||||
|
|
|
@ -66,7 +66,7 @@ void function2() {
|
|||
}
|
||||
|
||||
void init_array() {
|
||||
array_int nums = new_array_from_c_array(3, 3, sizeof(int), (int[]){
|
||||
array_int nums = new_array_from_c_array(3, 3, sizeof(int), (int[3]){
|
||||
4, 2, 3,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ Option_int get_opt() {
|
|||
|
||||
void User_foo(User* u) {
|
||||
int age = u->age;
|
||||
array_string zzz = array_repeat(new_array_from_c_array(1, 1, sizeof(string), (string[]){
|
||||
array_string zzz = array_repeat(new_array_from_c_array(1, 1, sizeof(string), (string[1]){
|
||||
tos3(""),
|
||||
}), u->age);
|
||||
int a = 10;
|
||||
|
|
|
@ -43,13 +43,13 @@ int main(int argc, char** argv) {
|
|||
string e = tos3("hello");
|
||||
e = testb(111);
|
||||
e = tos3("world");
|
||||
array_int f = new_array_from_c_array(4, 4, sizeof(int), (int[]){
|
||||
array_int f = new_array_from_c_array(4, 4, sizeof(int), (int[4]){
|
||||
testa(), 2, 3, 4,
|
||||
});
|
||||
array_string g = new_array_from_c_array(2, 2, sizeof(string), (string[]){
|
||||
array_string g = new_array_from_c_array(2, 2, sizeof(string), (string[2]){
|
||||
testb(1), tos3("hello"),
|
||||
});
|
||||
array_Foo arr_foo = new_array_from_c_array(1, 1, sizeof(Foo), (Foo[]){
|
||||
array_Foo arr_foo = new_array_from_c_array(1, 1, sizeof(Foo), (Foo[1]){
|
||||
a,
|
||||
});
|
||||
Foo af_idx_el = (*(Foo*)array_get(arr_foo, 0));
|
||||
|
|
Loading…
Reference in New Issue