parser: parallel parser, part 1
							parent
							
								
									2f171bf5d9
								
							
						
					
					
						commit
						1e853072dc
					
				|  | @ -11,6 +11,9 @@ import v.pref | |||
| import v.util | ||||
| import v.errors | ||||
| import os | ||||
| import runtime | ||||
| import sync | ||||
| import time | ||||
| 
 | ||||
| pub struct Parser { | ||||
| 	scanner           &scanner.Scanner | ||||
|  | @ -134,17 +137,20 @@ pub fn parse_file(path string, b_table &table.Table, comments_mode scanner.Comme | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| /* | ||||
| struct Queue { | ||||
| mut: | ||||
| 	idx              int | ||||
| 	mu               sync.Mutex | ||||
| 	mu               &sync.Mutex | ||||
| 	mu2              &sync.Mutex | ||||
| 	paths            []string | ||||
| 	table            &table.Table | ||||
| 	parsed_ast_files []ast.File | ||||
| 	pref             &pref.Preferences | ||||
| 	global_scope     &ast.Scope | ||||
| } | ||||
| 
 | ||||
| fn (q mut Queue) run() { | ||||
| fn (mut q Queue) run() { | ||||
| 	for { | ||||
| 		q.mu.lock() | ||||
| 		idx := q.idx | ||||
| 		if idx >= q.paths.len { | ||||
|  | @ -153,29 +159,37 @@ fn (q mut Queue) run() { | |||
| 		} | ||||
| 		q.idx++ | ||||
| 		q.mu.unlock() | ||||
| 		println('run(idx=$idx)') | ||||
| 		path := q.paths[idx] | ||||
| 	file := parse_file(path, q.table, .skip_comments) | ||||
| 	q.mu.lock() | ||||
| 		file := parse_file(path, q.table, .skip_comments, q.pref, q.global_scope) | ||||
| 		q.mu2.lock() | ||||
| 		q.parsed_ast_files << file | ||||
| 	q.mu.unlock() | ||||
| 		q.mu2.unlock() | ||||
| 		println('run done(idx=$idx)') | ||||
| 	} | ||||
| } | ||||
| */ | ||||
| 
 | ||||
| pub fn parse_files(paths []string, table &table.Table, pref &pref.Preferences, global_scope &ast.Scope) []ast.File { | ||||
| 	/* | ||||
| 	println('\n\n\nparse_files()') | ||||
| 	// println('nr_cpus= $nr_cpus')
 | ||||
| 	if pref.is_parallel && paths[0].contains('/array.v') { | ||||
| 		println('\n\n\nparse_files() nr_files=$paths.len') | ||||
| 		println(paths) | ||||
| 		nr_cpus := runtime.nr_cpus() | ||||
| 	println('nr_cpus= $nr_cpus') | ||||
| 		mut q := &Queue{ | ||||
| 			paths: paths | ||||
| 			table: table | ||||
| 			pref: pref | ||||
| 			global_scope: global_scope | ||||
| 			mu: sync.new_mutex() | ||||
| 			mu2: sync.new_mutex() | ||||
| 		} | ||||
| 	for i in 0 .. nr_cpus { | ||||
| 		for _ in 0 .. nr_cpus - 1 { | ||||
| 			go q.run() | ||||
| 		} | ||||
| 	time.sleep_ms(100) | ||||
| 		time.sleep_ms(1000) | ||||
| 		println('all done') | ||||
| 		return q.parsed_ast_files | ||||
| 	*/ | ||||
| 	} | ||||
| 	// ///////////////
 | ||||
| 	mut files := []ast.File{} | ||||
| 	for path in paths { | ||||
|  |  | |||
|  | @ -108,6 +108,7 @@ pub mut: | |||
| 	skip_running        bool     // when true, do no try to run the produced file (set by b.cc(), when -o x.c or -o x.js)
 | ||||
| 	skip_warnings       bool     // like C's "-w"
 | ||||
| 	use_color           ColorOutput // whether the warnings/errors should use ANSI color escapes.
 | ||||
| 	is_parallel bool | ||||
| } | ||||
| 
 | ||||
| pub fn parse_args(args []string) (&Preferences, string) { | ||||
|  | @ -188,6 +189,9 @@ pub fn parse_args(args []string) (&Preferences, string) { | |||
| 			'-keepc' { | ||||
| 				res.keep_c = true | ||||
| 			} | ||||
| 			'-parallel' { | ||||
| 				res.is_parallel = true | ||||
| 			} | ||||
| 			'-x64' { | ||||
| 				res.backend = .x64 | ||||
| 			} | ||||
|  |  | |||
|  | @ -6,6 +6,8 @@ fn simple<T>(p T) T { | |||
| } | ||||
| 
 | ||||
| fn plus<T>(a, b T) T { | ||||
| 	// x := a
 | ||||
| 	// y := b
 | ||||
| 	// ww := ww
 | ||||
| 	// q := xx + 1
 | ||||
| 	return a + b | ||||
|  | @ -17,6 +19,8 @@ fn test_generic_fn() { | |||
| 	assert simple<string>('g') == 'g' | ||||
| 	assert simple<string>('g') + 'h' == 'gh' | ||||
| 	a := plus<int>(2, 3) | ||||
| 	assert a == 5 | ||||
| 	assert plus<int>(10, 1) == 11 | ||||
| 	// plus<string>('a', 'b')
 | ||||
| 	println(a) | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue