cgen: GoStmt; experimental parallel parser
parent
c947e6ebe6
commit
0f160707a4
|
@ -49,8 +49,8 @@ mut:
|
|||
items []voidptr
|
||||
results []voidptr
|
||||
ntask int // writing to this should be locked by ntask_mtx.
|
||||
ntask_mtx &sync.Mutex
|
||||
waitgroup &sync.WaitGroup
|
||||
ntask_mtx &Mutex
|
||||
waitgroup &WaitGroup
|
||||
shared_context voidptr
|
||||
thread_contexts []voidptr
|
||||
}
|
||||
|
@ -77,8 +77,8 @@ pub fn new_pool_processor(context PoolProcessorConfig) &PoolProcessor {
|
|||
thread_contexts: []
|
||||
njobs: context.maxjobs
|
||||
ntask: 0
|
||||
ntask_mtx: sync.new_mutex()
|
||||
waitgroup: sync.new_waitgroup()
|
||||
ntask_mtx: new_mutex()
|
||||
waitgroup: new_waitgroup()
|
||||
thread_cb: context.callback
|
||||
}
|
||||
return pool
|
||||
|
@ -149,15 +149,15 @@ pub fn (pool &PoolProcessor) get_item<T>(idx int) T {
|
|||
return *(&T(pool.items[idx]))
|
||||
}
|
||||
|
||||
// get_string_item - called by the worker callback.
|
||||
// get_string_item - called by the worker callback.
|
||||
// It does not use generics so it does not mess up vfmt.
|
||||
// TODO: remove the need for this when vfmt becomes smarter.
|
||||
pub fn (pool &PoolProcessor) get_string_item(idx int) string {
|
||||
return *(&string(pool.items[idx]))
|
||||
}
|
||||
|
||||
// get_int_item - called by the worker callback.
|
||||
// It does not use generics so it does not mess up vfmt.
|
||||
// get_int_item - called by the worker callback.
|
||||
// It does not use generics so it does not mess up vfmt.
|
||||
// TODO: remove the need for this when vfmt becomes smarter.
|
||||
pub fn (pool &PoolProcessor) get_int_item(idx int) int {
|
||||
return *(&int(pool.items[idx]))
|
||||
|
|
|
@ -19,7 +19,7 @@ ConcatExpr | Type | AsCast
|
|||
pub type Stmt = GlobalDecl | FnDecl | Return | Module | Import | ExprStmt |
|
||||
ForStmt | StructDecl | ForCStmt | ForInStmt | CompIf | ConstDecl | Attr | BranchStmt |
|
||||
HashStmt | AssignStmt | EnumDecl | TypeDecl | DeferStmt | GotoLabel | GotoStmt |
|
||||
LineComment | MultiLineComment | AssertStmt | UnsafeStmt
|
||||
LineComment | MultiLineComment | AssertStmt | UnsafeStmt | GoStmt
|
||||
// pub type Type = StructType | ArrayType
|
||||
// pub struct StructType {
|
||||
// fields []Field
|
||||
|
@ -504,6 +504,11 @@ mut:
|
|||
right_type table.Type
|
||||
}
|
||||
|
||||
pub struct GoStmt {
|
||||
pub:
|
||||
expr Expr
|
||||
}
|
||||
|
||||
pub struct GotoLabel {
|
||||
pub:
|
||||
name string
|
||||
|
|
|
@ -11,6 +11,9 @@ import (
|
|||
v.pref
|
||||
term
|
||||
os
|
||||
//runtime
|
||||
sync
|
||||
//time
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -48,7 +51,7 @@ pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
|
|||
pref: &pref.Preferences{}
|
||||
scope: scope
|
||||
// scope: &ast.Scope{start_pos: 0, parent: 0}
|
||||
|
||||
|
||||
}
|
||||
p.init_parse_fns()
|
||||
p.read_first_token()
|
||||
|
@ -72,7 +75,7 @@ pub fn parse_file(path string, table &table.Table, comments_mode scanner.Comment
|
|||
parent: 0
|
||||
}
|
||||
// comments_mode: comments_mode
|
||||
|
||||
|
||||
}
|
||||
p.read_first_token()
|
||||
// p.scope = &ast.Scope{start_pos: p.tok.position(), parent: 0}
|
||||
|
@ -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 {
|
||||
/*
|
||||
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
|
||||
for path in paths {
|
||||
files << parse_file(path, table, .skip_comments)
|
||||
|
@ -324,6 +369,12 @@ pub fn (p mut Parser) stmt() ast.Stmt {
|
|||
stmts: stmts
|
||||
}
|
||||
}
|
||||
.key_go {
|
||||
p.next()
|
||||
return ast.GoStmt{
|
||||
expr: p.expr(0)
|
||||
}
|
||||
}
|
||||
.key_goto {
|
||||
p.next()
|
||||
name := p.check_name()
|
||||
|
@ -610,7 +661,7 @@ pub fn (p mut Parser) name_expr() ast.Expr {
|
|||
p.expr_mod = ''
|
||||
return ast.EnumVal{
|
||||
enum_name: enum_name // lp.prepend_mod(enum_name)
|
||||
|
||||
|
||||
val: val
|
||||
pos: p.tok.position()
|
||||
mod: mod
|
||||
|
@ -941,7 +992,7 @@ fn (p mut Parser) infix_expr(left ast.Expr) ast.Expr {
|
|||
left: left
|
||||
right: right
|
||||
// right_type: typ
|
||||
|
||||
|
||||
op: op
|
||||
pos: pos
|
||||
}
|
||||
|
@ -1055,7 +1106,7 @@ fn (p mut Parser) for_statement() ast.Stmt {
|
|||
p.scope.register_var(ast.Var{
|
||||
name: var_name
|
||||
// expr: cond
|
||||
|
||||
|
||||
})
|
||||
stmts := p.parse_block()
|
||||
// println('nr stmts=$stmts.len')
|
||||
|
@ -1150,11 +1201,11 @@ fn (p mut Parser) if_expr() ast.Expr {
|
|||
stmts: stmts
|
||||
else_stmts: else_stmts
|
||||
// typ: typ
|
||||
|
||||
|
||||
pos: pos
|
||||
has_else: has_else
|
||||
// left: left
|
||||
|
||||
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
@ -1329,7 +1380,7 @@ fn (p mut Parser) const_decl() ast.ConstDecl {
|
|||
fields << ast.Field{
|
||||
name: name
|
||||
// typ: typ
|
||||
|
||||
|
||||
}
|
||||
exprs << expr
|
||||
// TODO: once consts are fixed reg here & update in checker
|
||||
|
|
Loading…
Reference in New Issue