cgen: fix the tests
							parent
							
								
									b2d1f55702
								
							
						
					
					
						commit
						7ad1441c81
					
				|  | @ -43,7 +43,7 @@ pub fn cgen(files []ast.File, table &table.Table) string { | ||||||
| 		g.stmts(file.stmts) | 		g.stmts(file.stmts) | ||||||
| 	} | 	} | ||||||
| 	g.write_variadic_types() | 	g.write_variadic_types() | ||||||
| 	g.write_str_definitions() | 	// g.write_str_definitions()
 | ||||||
| 	g.write_init_function() | 	g.write_init_function() | ||||||
| 	return g.typedefs.str() + g.definitions.str() + g.out.str() | 	return g.typedefs.str() + g.definitions.str() + g.out.str() | ||||||
| } | } | ||||||
|  | @ -57,6 +57,7 @@ pub fn (g mut Gen) init() { | ||||||
| 	g.definitions.writeln('\nstring _STR_TMP(const char*, ...);\n') | 	g.definitions.writeln('\nstring _STR_TMP(const char*, ...);\n') | ||||||
| 	g.write_builtin_types() | 	g.write_builtin_types() | ||||||
| 	g.write_typedef_types() | 	g.write_typedef_types() | ||||||
|  | 	g.write_str_definitions() | ||||||
| 	g.write_sorted_types() | 	g.write_sorted_types() | ||||||
| 	g.write_multi_return_types() | 	g.write_multi_return_types() | ||||||
| 	g.definitions.writeln('// end of definitions #endif') | 	g.definitions.writeln('// end of definitions #endif') | ||||||
|  | @ -1591,13 +1592,12 @@ string _STR_TMP(const char *fmt, ...) { | ||||||
| 	//puts(g_str_buf);
 | 	//puts(g_str_buf);
 | ||||||
| #endif | #endif | ||||||
| 	return tos2(g_str_buf); | 	return tos2(g_str_buf); | ||||||
| } | } // endof _STR_TMP
 | ||||||
| 
 | 
 | ||||||
| ') | ') | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const ( | const ( | ||||||
| // TODO all builtin types must be lowercase
 |  | ||||||
| 	builtins = ['string', 'array', 'KeyValue', 'DenseArray', 'map', 'Option'] | 	builtins = ['string', 'array', 'KeyValue', 'DenseArray', 'map', 'Option'] | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | @ -1625,7 +1625,6 @@ fn (g mut Gen) write_sorted_types() { | ||||||
| 	types_sorted := g.sort_structs(types) | 	types_sorted := g.sort_structs(types) | ||||||
| 	// Generate C code
 | 	// Generate C code
 | ||||||
| 	g.definitions.writeln('// builtin types:') | 	g.definitions.writeln('// builtin types:') | ||||||
| 	// g.write_types(builtin_types)
 |  | ||||||
| 	g.definitions.writeln('//------------------ #endbuiltin') | 	g.definitions.writeln('//------------------ #endbuiltin') | ||||||
| 	g.write_types(types_sorted) | 	g.write_types(types_sorted) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -23,7 +23,14 @@ fn test_c_files() { | ||||||
| 		ctext = ctext // unused warn
 | 		ctext = ctext // unused warn
 | ||||||
| 		mut b := builder.new_builder(pref.Preferences{}) | 		mut b := builder.new_builder(pref.Preferences{}) | ||||||
| 		b.module_search_paths = ['$vroot/vlib/v/gen/tests/'] | 		b.module_search_paths = ['$vroot/vlib/v/gen/tests/'] | ||||||
| 		res := b.gen_c([path]).after('#endbuiltin') | 		mut res := b.gen_c([path]).after('#endbuiltin') | ||||||
|  | 		if res.contains('string _STR') { | ||||||
|  | 			pos := res.index('string _STR') or { | ||||||
|  | 				-1 | ||||||
|  | 			} | ||||||
|  | 			end := res.index_after('endof _STR_TMP', pos) | ||||||
|  | 			res = res[..pos] + res[end + 15..] | ||||||
|  | 		} | ||||||
| 		if compare_texts(res, ctext, path) { | 		if compare_texts(res, ctext, path) { | ||||||
| 			println('${term_ok} ${i}') | 			println('${term_ok} ${i}') | ||||||
| 		} | 		} | ||||||
|  | @ -47,6 +54,15 @@ fn compare_texts(a, b, path string) bool { | ||||||
| 	*/ | 	*/ | ||||||
| 
 | 
 | ||||||
| 	for i, line_a in lines_a { | 	for i, line_a in lines_a { | ||||||
|  | 		// mut j := 0
 | ||||||
|  | 		// for i := 0; i < lines_a.len; i++ {
 | ||||||
|  | 		// line_a := lines_a[i]
 | ||||||
|  | 		// if line_a.contains('string _STR') {
 | ||||||
|  | 		// println(' SKIPPING!!')
 | ||||||
|  | 		// for !lines_a[i].contains('}') {
 | ||||||
|  | 		// i++
 | ||||||
|  | 		// }
 | ||||||
|  | 		// }
 | ||||||
| 		if i >= lines_b.len { | 		if i >= lines_b.len { | ||||||
| 			println(line_a) | 			println(line_a) | ||||||
| 			return false | 			return false | ||||||
|  |  | ||||||
|  | @ -304,6 +304,7 @@ typedef array array_u64; | ||||||
| typedef map map_int; | typedef map map_int; | ||||||
| typedef map map_string; | typedef map map_string; | ||||||
| typedef byte array_fixed_byte_300 [300]; | typedef byte array_fixed_byte_300 [300]; | ||||||
|  | typedef byte array_fixed_byte_400 [400]; | ||||||
| #ifndef bool | #ifndef bool | ||||||
| 	typedef int bool; | 	typedef int bool; | ||||||
| 	#define true 1 | 	#define true 1 | ||||||
|  |  | ||||||
|  | @ -76,7 +76,13 @@ void end() { | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| int main(int argc, char** argv) { | int main(int argc, char** argv) { | ||||||
|  | 	_init(); | ||||||
|  | 	os__args = os__init_os_args(argc, (byteptr*)argv); | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void _init() { | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -63,6 +63,8 @@ void handle_expr(Expr e) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int main(int argc, char** argv) { | int main(int argc, char** argv) { | ||||||
|  | 	_init(); | ||||||
|  | 	os__args = os__init_os_args(argc, (byteptr*)argv); | ||||||
| 	User user = (User){ | 	User user = (User){ | ||||||
| 0}; | 0}; | ||||||
| 	user.age = 10; | 	user.age = 10; | ||||||
|  | @ -74,3 +76,7 @@ int main(int argc, char** argv) { | ||||||
| 0}); | 0}); | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | void _init() { | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -22,7 +22,9 @@ int Foo_testa(Foo* f); | ||||||
| int Foo_testb(Foo* f); | int Foo_testb(Foo* f); | ||||||
| int Bar_testa(Bar* b); | int Bar_testa(Bar* b); | ||||||
| 
 | 
 | ||||||
| int main() { | int main(int argc, char** argv) { | ||||||
|  | 	_init(); | ||||||
|  | 	os__args = os__init_os_args(argc, (byteptr*)argv); | ||||||
|     Bar b = (Bar){ |     Bar b = (Bar){ | ||||||
|         .a = 122, |         .a = 122, | ||||||
|     }; |     }; | ||||||
|  | @ -91,3 +93,6 @@ int Foo_testb(Foo* f) { | ||||||
| int Bar_testa(Bar* b) { | int Bar_testa(Bar* b) { | ||||||
|     return 4; |     return 4; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | void _init() { | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue