checker: fix Assoc
parent
85f67a3f73
commit
27ce38937c
|
@ -513,9 +513,10 @@ pub:
|
|||
|
||||
pub struct Assoc {
|
||||
pub:
|
||||
name string
|
||||
var_name string
|
||||
fields []string
|
||||
exprs []Expr
|
||||
pos token.Position
|
||||
}
|
||||
|
||||
pub struct SizeOf {
|
||||
|
|
|
@ -431,6 +431,15 @@ pub fn (c mut Checker) expr(node ast.Expr) table.Type {
|
|||
ast.AssignExpr {
|
||||
c.check_assign_expr(it)
|
||||
}
|
||||
ast.Assoc {
|
||||
scope := c.file.scope.innermost(it.pos.pos) or {
|
||||
c.file.scope
|
||||
}
|
||||
var := scope.find_var(it.var_name) or {
|
||||
panic(err)
|
||||
}
|
||||
return var.typ
|
||||
}
|
||||
ast.EnumVal {
|
||||
return c.enum_val(it)
|
||||
}
|
||||
|
@ -733,8 +742,7 @@ pub fn (c mut Checker) enum_val(node ast.EnumVal) table.Type {
|
|||
typ_idx := if node.enum_name == '' { c.expected_type } else { //
|
||||
c.table.find_type_idx(node.enum_name) }
|
||||
typ := c.table.get_type_symbol(table.Type(typ_idx))
|
||||
|
||||
//info := typ.info as table.Enum
|
||||
// info := typ.info as table.Enum
|
||||
info := typ.enum_info()
|
||||
// rintln('checker: x = $info.x enum val $c.expected_type $typ.name')
|
||||
// println(info.vals)
|
||||
|
|
|
@ -310,7 +310,7 @@ fn (f mut Fmt) expr(node ast.Expr) {
|
|||
ast.Assoc {
|
||||
f.writeln('{')
|
||||
// f.indent++
|
||||
f.writeln('\t$it.name |')
|
||||
f.writeln('\t$it.var_name |')
|
||||
// TODO StructInit copy pasta
|
||||
for i, field in it.fields {
|
||||
f.write('\t$field: ')
|
||||
|
|
|
@ -58,7 +58,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()
|
||||
|
@ -82,7 +82,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}
|
||||
|
@ -359,7 +359,7 @@ pub fn (p mut Parser) stmt() ast.Stmt {
|
|||
return ast.ExprStmt{
|
||||
expr: expr
|
||||
// typ: typ
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -657,7 +657,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()
|
||||
}
|
||||
|
@ -793,9 +793,10 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,table.Type) {
|
|||
}
|
||||
}
|
||||
node = ast.Assoc{
|
||||
name: name
|
||||
var_name: name
|
||||
fields: fields
|
||||
exprs: vals
|
||||
pos:p.tok.position()
|
||||
}
|
||||
}
|
||||
p.check(.rcbr)
|
||||
|
@ -1214,11 +1215,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
|
||||
}
|
||||
|
@ -1644,12 +1645,12 @@ fn (p mut Parser) var_decl_and_assign_stmt() ast.Stmt {
|
|||
return ast.VarDecl{
|
||||
name: ident.name
|
||||
// name2: name2
|
||||
|
||||
|
||||
expr: expr // p.expr(token.lowest_prec)
|
||||
|
||||
|
||||
is_mut: info0.is_mut
|
||||
// typ: typ
|
||||
|
||||
|
||||
pos: p.tok.position()
|
||||
}
|
||||
// return p.var_decl(ident[0], exprs[0])
|
||||
|
@ -1787,7 +1788,7 @@ fn (p mut Parser) match_expr() ast.Expr {
|
|||
blocks: blocks
|
||||
match_exprs: match_exprs
|
||||
// typ: typ
|
||||
|
||||
|
||||
cond: cond
|
||||
}
|
||||
return node
|
||||
|
|
|
@ -76,7 +76,7 @@ x := 10
|
|||
8+4
|
||||
'
|
||||
table := &table.Table{}
|
||||
prog := parse_file(s, table)
|
||||
prog := parse_file(s, table, .skip_comments)
|
||||
mut checker := checker.new_checker(table)
|
||||
checker.check(prog)
|
||||
res := gen.cgen([prog], table)
|
||||
|
|
Loading…
Reference in New Issue