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