register fn args; remove dup code
parent
460b35137a
commit
a6a9958cfc
2
v2.v
2
v2.v
|
@ -14,7 +14,7 @@ cdefs = '
|
|||
typedef int bool;
|
||||
typedef struct { char* str; } string;
|
||||
typedef double f64;
|
||||
string tos3(char* s) { return (string){ .str = s }; }
|
||||
string tos3(char* s) { return (string){ .str = s, len = strlen(s) }; }
|
||||
')
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -70,10 +70,12 @@ fn (p mut Parser) fn_decl() ast.FnDecl {
|
|||
for p.tok.kind != .rpar {
|
||||
arg_name := p.check_name()
|
||||
typ := p.parse_type()
|
||||
args << table.Var{
|
||||
arg := table.Var{
|
||||
name: arg_name
|
||||
typ: typ
|
||||
}
|
||||
args << arg
|
||||
p.table.register_var(arg)
|
||||
ast_args << ast.Arg{
|
||||
typ: typ
|
||||
name: arg_name
|
||||
|
@ -103,12 +105,12 @@ fn (p mut Parser) fn_decl() ast.FnDecl {
|
|||
}
|
||||
|
||||
pub fn (p &Parser) check_fn_calls() {
|
||||
println('CHEKC FN CALLS')
|
||||
println('check fn calls')
|
||||
for call in p.table.unknown_calls {
|
||||
f := p.table.find_fn(call.name) or {
|
||||
p.error_at_line('unknown function `$call.name`', call.tok.line_nr)
|
||||
return
|
||||
}
|
||||
println(call.name)
|
||||
println(f.name)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ pub fn parse_stmt(text string, table &table.Table) ast.Stmt {
|
|||
}
|
||||
|
||||
pub fn parse_file(path string, table &table.Table) ast.File {
|
||||
println('parse file "$path"')
|
||||
text := os.read_file(path) or {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -66,33 +67,7 @@ pub fn parse_file(path string, table &table.Table) ast.File {
|
|||
pub fn parse_files(paths []string, table &table.Table) []ast.File {
|
||||
mut files := []ast.File
|
||||
for path in paths {
|
||||
println('parse file "$path"')
|
||||
mut stmts := []ast.Stmt
|
||||
text := os.read_file(path) or {
|
||||
panic(err)
|
||||
}
|
||||
mut p := Parser{
|
||||
scanner: scanner.new_scanner(text)
|
||||
table: table
|
||||
file_name: path
|
||||
}
|
||||
p.read_first_token()
|
||||
for {
|
||||
// res := s.scan()
|
||||
if p.tok.kind == .eof {
|
||||
break
|
||||
}
|
||||
// println('expr at ' + p.tok.str())
|
||||
s := p.stmt()
|
||||
// println(s)
|
||||
stmts << s // p.stmt()
|
||||
}
|
||||
p.check_fn_calls()
|
||||
// println('nr stmts = $stmts.len')
|
||||
// println(stmts[0])
|
||||
files << ast.File{
|
||||
stmts: stmts
|
||||
}
|
||||
files << parse_file(path, table)
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue