struct field check + enable v2 again
parent
2ab7b40f2f
commit
9861b24bc3
|
@ -8,12 +8,10 @@ import (
|
|||
os.cmdline
|
||||
strings
|
||||
filepath
|
||||
//compiler.x64
|
||||
// v.gen.x64
|
||||
//v.types
|
||||
// v.table
|
||||
// v.parser
|
||||
// v.gen
|
||||
v.gen.x64
|
||||
v.table
|
||||
v.parser
|
||||
v.gen
|
||||
time
|
||||
)
|
||||
|
||||
|
@ -382,8 +380,6 @@ pub fn (v mut V) compile() {
|
|||
v.cc()
|
||||
}
|
||||
|
||||
pub fn (v &V) compile2() {}
|
||||
/*
|
||||
pub fn (v mut V) compile2() {
|
||||
if os.user_os() != 'windows' && v.pref.ccompiler == 'msvc' {
|
||||
verror('Cannot build with msvc on ${os.user_os()}')
|
||||
|
@ -418,10 +414,7 @@ pub fn (v mut V) compile2() {
|
|||
v.cc()
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn (v &V) compile_x64() {}
|
||||
/*
|
||||
pub fn (v mut V) compile_x64() {
|
||||
$if !linux {
|
||||
println('v -x64 can only generate Linux binaries for now')
|
||||
|
@ -436,16 +429,7 @@ pub fn (v mut V) compile_x64() {
|
|||
println('PARSE: ${time.ticks() - ticks}ms')
|
||||
x64.gen(files, v.out_name)
|
||||
println('x64 GEN: ${time.ticks() - ticks}ms')
|
||||
/*
|
||||
for f in v.files {
|
||||
v.parse(f, .decl)
|
||||
}
|
||||
for f in v.files {
|
||||
v.parse(f, .main)
|
||||
}
|
||||
*/
|
||||
}
|
||||
*/
|
||||
|
||||
fn (v mut V) generate_init() {
|
||||
$if js {
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
strings
|
||||
v.ast
|
||||
v.table
|
||||
v.types
|
||||
// v.types
|
||||
term
|
||||
)
|
||||
|
||||
|
|
|
@ -269,6 +269,10 @@ pub fn (p mut Parser) name_expr() (ast.Expr,types.TypeIdent) {
|
|||
p.next()
|
||||
p.check(.dot)
|
||||
}
|
||||
else if p.tok.lit in ['strings'] {
|
||||
p.next()
|
||||
p.check(.dot)
|
||||
}
|
||||
// fn call
|
||||
if p.peek_tok.kind == .lpar {
|
||||
x,ti2 := p.call_expr() // TODO `node,typ :=` should work
|
||||
|
@ -363,7 +367,7 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,types.TypeIdent) {
|
|||
node = p.assign_expr(node)
|
||||
}
|
||||
else if p.tok.kind == .dot {
|
||||
node,ti = p.dot_expr(node)
|
||||
node,ti = p.dot_expr(node, ti)
|
||||
}
|
||||
else if p.tok.kind == .lsbr {
|
||||
node,ti = p.index_expr(node)
|
||||
|
@ -416,9 +420,20 @@ fn (p mut Parser) index_expr(left ast.Expr) (ast.Expr,types.TypeIdent) {
|
|||
return node,ti
|
||||
}
|
||||
|
||||
fn (p mut Parser) dot_expr(left ast.Expr) (ast.Expr,types.TypeIdent) {
|
||||
fn (p mut Parser) dot_expr(left ast.Expr, ti types.TypeIdent) (ast.Expr,types.TypeIdent) {
|
||||
p.next()
|
||||
field_name := p.check_name()
|
||||
typ := p.table.types[ti.idx] as types.Struct
|
||||
mut ok := false
|
||||
for field in typ.fields {
|
||||
if field.name == field_name {
|
||||
ok = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !ok {
|
||||
p.error('type `$typ.name` has no field or method `$field_name`')
|
||||
}
|
||||
// Method call
|
||||
if p.tok.kind == .lpar {
|
||||
p.next()
|
||||
|
|
|
@ -227,6 +227,7 @@ pub:
|
|||
idx int
|
||||
name string
|
||||
fields []Field
|
||||
// methods
|
||||
}
|
||||
|
||||
pub struct Field {
|
||||
|
@ -365,6 +366,13 @@ pub fn (t Variadic) str() string {
|
|||
return 'variadic_$t.ti.kind.str()'
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn (s &Struct) has_field(name string) bool {
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
pub const (
|
||||
void_type = Void{}
|
||||
voidptr_type = Voidptr{}
|
||||
|
|
Loading…
Reference in New Issue