cgen: GoStmt; experimental parallel parser

pull/4038/head
Alexander Medvednikov 2020-03-16 08:33:42 +01:00
parent c947e6ebe6
commit 0f160707a4
3 changed files with 72 additions and 16 deletions

View File

@ -49,8 +49,8 @@ mut:
items []voidptr items []voidptr
results []voidptr results []voidptr
ntask int // writing to this should be locked by ntask_mtx. ntask int // writing to this should be locked by ntask_mtx.
ntask_mtx &sync.Mutex ntask_mtx &Mutex
waitgroup &sync.WaitGroup waitgroup &WaitGroup
shared_context voidptr shared_context voidptr
thread_contexts []voidptr thread_contexts []voidptr
} }
@ -77,8 +77,8 @@ pub fn new_pool_processor(context PoolProcessorConfig) &PoolProcessor {
thread_contexts: [] thread_contexts: []
njobs: context.maxjobs njobs: context.maxjobs
ntask: 0 ntask: 0
ntask_mtx: sync.new_mutex() ntask_mtx: new_mutex()
waitgroup: sync.new_waitgroup() waitgroup: new_waitgroup()
thread_cb: context.callback thread_cb: context.callback
} }
return pool return pool

View File

@ -19,7 +19,7 @@ ConcatExpr | Type | AsCast
pub type Stmt = GlobalDecl | FnDecl | Return | Module | Import | ExprStmt | pub type Stmt = GlobalDecl | FnDecl | Return | Module | Import | ExprStmt |
ForStmt | StructDecl | ForCStmt | ForInStmt | CompIf | ConstDecl | Attr | BranchStmt | ForStmt | StructDecl | ForCStmt | ForInStmt | CompIf | ConstDecl | Attr | BranchStmt |
HashStmt | AssignStmt | EnumDecl | TypeDecl | DeferStmt | GotoLabel | GotoStmt | HashStmt | AssignStmt | EnumDecl | TypeDecl | DeferStmt | GotoLabel | GotoStmt |
LineComment | MultiLineComment | AssertStmt | UnsafeStmt LineComment | MultiLineComment | AssertStmt | UnsafeStmt | GoStmt
// pub type Type = StructType | ArrayType // pub type Type = StructType | ArrayType
// pub struct StructType { // pub struct StructType {
// fields []Field // fields []Field
@ -504,6 +504,11 @@ mut:
right_type table.Type right_type table.Type
} }
pub struct GoStmt {
pub:
expr Expr
}
pub struct GotoLabel { pub struct GotoLabel {
pub: pub:
name string name string

View File

@ -11,6 +11,9 @@ import (
v.pref v.pref
term term
os os
//runtime
sync
//time
) )
const ( const (
@ -110,7 +113,49 @@ pub fn parse_file(path string, table &table.Table, comments_mode scanner.Comment
} }
} }
struct Queue {
mut:
idx int
mu sync.Mutex
paths []string
table &table.Table
parsed_ast_files []ast.File
}
fn (q mut Queue) run() {
q.mu.lock()
idx := q.idx
if idx >= q.paths.len {
q.mu.unlock()
return
}
q.idx++
q.mu.unlock()
path := q.paths[idx]
file := parse_file(path, q.table, .skip_comments)
q.mu.lock()
q.parsed_ast_files << file
q.mu.unlock()
}
pub fn parse_files(paths []string, table &table.Table) []ast.File { pub fn parse_files(paths []string, table &table.Table) []ast.File {
/*
println('\n\n\nparse_files()')
println(paths)
nr_cpus := runtime.nr_cpus()
println('nr_cpus= $nr_cpus')
mut q := &Queue{
paths: paths
table: table
}
for i in 0 .. nr_cpus {
go q.run()
}
time.sleep_ms(100)
return q.parsed_ast_files
*/
// ///////////////
mut files := []ast.File mut files := []ast.File
for path in paths { for path in paths {
files << parse_file(path, table, .skip_comments) files << parse_file(path, table, .skip_comments)
@ -324,6 +369,12 @@ pub fn (p mut Parser) stmt() ast.Stmt {
stmts: stmts stmts: stmts
} }
} }
.key_go {
p.next()
return ast.GoStmt{
expr: p.expr(0)
}
}
.key_goto { .key_goto {
p.next() p.next()
name := p.check_name() name := p.check_name()