v2: add some comments in parser & checker

pull/3931/head
Joe Conigliaro 2020-03-05 22:44:33 +11:00
parent 6de44db4eb
commit 9921897aa6
2 changed files with 6 additions and 5 deletions

View File

@ -416,6 +416,7 @@ fn (c mut Checker) stmt(node ast.Stmt) {
for i, expr in it.exprs { for i, expr in it.exprs {
mut field := it.fields[i] mut field := it.fields[i]
typ := c.expr(expr) typ := c.expr(expr)
// TODO: once consts are fixed update here
c.table.register_const(table.Var{ c.table.register_const(table.Var{
name: field.name name: field.name
typ: typ typ: typ
@ -438,6 +439,8 @@ fn (c mut Checker) stmt(node ast.Stmt) {
if !it.is_inf && table.type_idx(typ) != table.bool_type_idx { if !it.is_inf && table.type_idx(typ) != table.bool_type_idx {
c.error('non-bool used as for condition', it.pos) c.error('non-bool used as for condition', it.pos)
} }
// TODO: update loop var type
// how does this work currenly?
for stmt in it.stmts { for stmt in it.stmts {
c.stmt(stmt) c.stmt(stmt)
} }

View File

@ -1058,10 +1058,6 @@ fn (p mut Parser) for_statement() ast.Stmt {
if p.tok.kind == .comma { if p.tok.kind == .comma {
p.check(.comma) p.check(.comma)
val_name = p.check_name() val_name = p.check_name()
// p.table.register_var(table.Var{
// name: val_name
// typ: table.int_type
// })
p.scope.register_var(ast.VarDecl{ p.scope.register_var(ast.VarDecl{
name: val_name name: val_name
typ: table.int_type typ: table.int_type
@ -1080,9 +1076,10 @@ fn (p mut Parser) for_statement() ast.Stmt {
p.check(.dotdot) p.check(.dotdot)
high_expr = p.expr(0) high_expr = p.expr(0)
} }
// TODO: update var type in checker
p.scope.register_var(ast.VarDecl{ p.scope.register_var(ast.VarDecl{
name: var_name name: var_name
expr: cond // expr: cond
}) })
stmts := p.parse_block() stmts := p.parse_block()
// println('nr stmts=$stmts.len') // println('nr stmts=$stmts.len')
@ -1357,6 +1354,7 @@ fn (p mut Parser) const_decl() ast.ConstDecl {
// typ: typ // typ: typ
} }
exprs << expr exprs << expr
// TODO: once consts are fixed reg here & update in checker
// p.table.register_const(table.Var{ // p.table.register_const(table.Var{
// name: name // name: name
// // typ: typ // // typ: typ