v2: for in checker
parent
39c4842bf9
commit
19520ccf4e
|
@ -209,6 +209,7 @@ pub fn (c byte) is_capital() bool {
|
||||||
|
|
||||||
pub fn (b []byte) clone() []byte {
|
pub fn (b []byte) clone() []byte {
|
||||||
mut res := [byte(0)].repeat(b.len)
|
mut res := [byte(0)].repeat(b.len)
|
||||||
|
//mut res := make([]byte, {repeat:b.len})
|
||||||
for i := 0; i < b.len; i++ {
|
for i := 0; i < b.len; i++ {
|
||||||
res[i] = b[i]
|
res[i] = b[i]
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,14 @@ import (
|
||||||
v.table
|
v.table
|
||||||
)
|
)
|
||||||
|
|
||||||
pub type Expr = InfixExpr | IfExpr | StringLiteral | IntegerLiteral | CharLiteral |
|
pub type Expr = InfixExpr | IfExpr | StringLiteral | IntegerLiteral | CharLiteral |
|
||||||
FloatLiteral | Ident | CallExpr | BoolLiteral | StructInit | ArrayInit | SelectorExpr | PostfixExpr |
|
FloatLiteral | Ident | CallExpr | BoolLiteral | StructInit | ArrayInit | SelectorExpr | PostfixExpr |
|
||||||
AssignExpr | PrefixExpr | MethodCallExpr | IndexExpr | RangeExpr | MatchExpr |
|
AssignExpr | PrefixExpr | MethodCallExpr | IndexExpr | RangeExpr | MatchExpr |
|
||||||
CastExpr | EnumVal | Assoc | SizeOf
|
CastExpr | EnumVal | Assoc | SizeOf
|
||||||
|
|
||||||
pub type Stmt = VarDecl | GlobalDecl | FnDecl | Return | Module | Import | ExprStmt |
|
pub type Stmt = VarDecl | 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
|
LineComment | MultiLineComment
|
||||||
|
|
||||||
pub type Type = StructType | ArrayType
|
pub type Type = StructType | ArrayType
|
||||||
|
@ -348,6 +348,7 @@ pub:
|
||||||
var string
|
var string
|
||||||
cond Expr
|
cond Expr
|
||||||
stmts []Stmt
|
stmts []Stmt
|
||||||
|
pos token.Position
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ForCStmt {
|
pub struct ForCStmt {
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
|
||||||
pref: &pref.Preferences{}
|
pref: &pref.Preferences{}
|
||||||
scope: scope
|
scope: scope
|
||||||
// scope: &ast.Scope{start_pos: 0, parent: 0}
|
// scope: &ast.Scope{start_pos: 0, parent: 0}
|
||||||
|
|
||||||
}
|
}
|
||||||
p.init_parse_fns()
|
p.init_parse_fns()
|
||||||
p.read_first_token()
|
p.read_first_token()
|
||||||
|
@ -319,7 +319,7 @@ pub fn (p mut Parser) stmt() ast.Stmt {
|
||||||
return ast.ExprStmt{
|
return ast.ExprStmt{
|
||||||
expr: expr
|
expr: expr
|
||||||
// typ: typ
|
// typ: typ
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -994,7 +994,7 @@ fn (p mut Parser) for_statement() ast.Stmt {
|
||||||
stmts := p.parse_block()
|
stmts := p.parse_block()
|
||||||
// println('nr stmts=$stmts.len')
|
// println('nr stmts=$stmts.len')
|
||||||
p.close_scope()
|
p.close_scope()
|
||||||
return ast.ForStmt{
|
return ast.ForInStmt{
|
||||||
stmts: stmts
|
stmts: stmts
|
||||||
pos: p.tok.position()
|
pos: p.tok.position()
|
||||||
}
|
}
|
||||||
|
@ -1061,10 +1061,10 @@ fn (p mut Parser) if_expr() ast.Expr {
|
||||||
stmts: stmts
|
stmts: stmts
|
||||||
else_stmts: else_stmts
|
else_stmts: else_stmts
|
||||||
// typ: typ
|
// typ: typ
|
||||||
|
|
||||||
pos: p.tok.position()
|
pos: p.tok.position()
|
||||||
// left: left
|
// left: left
|
||||||
|
|
||||||
}
|
}
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
@ -1450,10 +1450,10 @@ fn (p mut Parser) var_decl() ast.VarDecl {
|
||||||
node := ast.VarDecl{
|
node := ast.VarDecl{
|
||||||
name: name
|
name: name
|
||||||
expr: expr // p.expr(token.lowest_prec)
|
expr: expr // p.expr(token.lowest_prec)
|
||||||
|
|
||||||
is_mut: is_mut
|
is_mut: is_mut
|
||||||
// typ: typ
|
// typ: typ
|
||||||
|
|
||||||
pos: p.tok.position()
|
pos: p.tok.position()
|
||||||
}
|
}
|
||||||
p.scope.register_var(node)
|
p.scope.register_var(node)
|
||||||
|
@ -1572,7 +1572,7 @@ fn (p mut Parser) match_expr() ast.Expr {
|
||||||
blocks: blocks
|
blocks: blocks
|
||||||
match_exprs: match_exprs
|
match_exprs: match_exprs
|
||||||
// typ: typ
|
// typ: typ
|
||||||
|
|
||||||
cond: cond
|
cond: cond
|
||||||
}
|
}
|
||||||
return node
|
return node
|
||||||
|
|
|
@ -377,15 +377,20 @@ pub fn (t &Table) check(got, expected Type) bool {
|
||||||
if got_type_sym.is_number() && exp_type_sym.is_number() {
|
if got_type_sym.is_number() && exp_type_sym.is_number() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
// TODO
|
||||||
|
// if got_type_sym.kind == .array && exp_type_sym.kind == .array {
|
||||||
|
// return true
|
||||||
|
// }
|
||||||
if got_type_sym.kind == .array_fixed && exp_type_sym.kind == .byteptr {
|
if got_type_sym.kind == .array_fixed && exp_type_sym.kind == .byteptr {
|
||||||
info := got_type_sym.info as ArrayFixed
|
info := got_type_sym.info as ArrayFixed
|
||||||
if type_idx(info.elem_type) == byte_type_idx {
|
if type_idx(info.elem_type) == byte_type_idx {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if expected.name == 'array' {
|
// TODO
|
||||||
// return true
|
if exp_type_sym.name == 'array' || got_type_sym.name == 'array' {
|
||||||
// }
|
return true
|
||||||
|
}
|
||||||
if got_idx != exp_idx {
|
if got_idx != exp_idx {
|
||||||
// && got.typ.name != expected.typ.name*/
|
// && got.typ.name != expected.typ.name*/
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in New Issue