diff --git a/build/build.go b/build/build.go index cafe0c7..425bbab 100644 --- a/build/build.go +++ b/build/build.go @@ -47,7 +47,7 @@ func (sp *SourceProgram) Build(backend asm.Backend, emitAsmOnly bool, toPrint To id := 0 addRootNode := func(task task) int { - l.Debugf("registering root task %d", id) + l.Debugf("registering root task %d %q", id, task.Name()) node := &node{task: task} nodes[id] = node rootNodes = append(rootNodes, id) @@ -56,7 +56,7 @@ func (sp *SourceProgram) Build(backend asm.Backend, emitAsmOnly bool, toPrint To } addNode := func(task task, deps ...int) int { - l.Debugf("registering task %d", id) + l.Debugf("registering task %d %q", id, task.Name()) if len(deps) <= 0 { panic("node without dep is useless") } diff --git a/build/task.go b/build/task.go index aa6805c..ee4e9d0 100644 --- a/build/task.go +++ b/build/task.go @@ -260,8 +260,8 @@ func runTasks(nodes map[int]*node, rootNodes []int, l *utils.Logger) error { if done[id] != notStarted { panic(fmt.Sprintf("tried starting task %d twice", id)) } - l.Debugf("executing task %d", id) node := nodes[id] + l.Debugf("executing task %d %q", id, node.task.Name()) output[id] = &strings.Builder{} go node.task.Run(id, output[id], doneChan) running = append(running, id) @@ -299,7 +299,7 @@ func runTasks(nodes map[int]*node, rootNodes []int, l *utils.Logger) error { for !allFinished { select { case result := <-doneChan: - l.Debugf("task %d is done with err: %v", result.Id, result.Err) + l.Debugf("task %d %q is done with err: %v", result.Id, nodes[result.Id].task.Name(), result.Err) for i, id := range running { if id == result.Id { running = slices.Delete(running, i, i+1) diff --git a/design.md b/design.md new file mode 100644 index 0000000..95ae87c --- /dev/null +++ b/design.md @@ -0,0 +1,18 @@ +# Designs + +Playground for language design dessisions + +## Function Calls + +```tt +fn hi(hello: i32) = { + 3 +}; + +fn main() = { + hi!; + hi(); + hi; +}; + +``` diff --git a/language.md b/language.md index 839dc05..67b167b 100644 --- a/language.md +++ b/language.md @@ -3,9 +3,8 @@ ## Syntax ```tt -// Return type is i64 fn main() = { - i : = 3; + i := 3; i }; ``` diff --git a/parser/parser.go b/parser/parser.go index fea2462..475ca0d 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -192,6 +192,9 @@ func (p *Parser) parseArgumentList() ([]ast.Argument, bool) { for p.peekTokenIs(token.Ident) { p.nextToken() name := p.curToken.Literal + if ok, _ := p.expectPeek(token.Colon); !ok { + return args, false + } p.nextToken() t, ok := p.parseType() diff --git a/test.tt b/test.tt index bbeb911..588b55f 100644 --- a/test.tt +++ b/test.tt @@ -1,13 +1,17 @@ fn main() = { - hi := 4; + i := 5; - if hi == 4 { - test2 := 3; - hi = 0 + if i == 5 { + 0 + } else { + 1 } - else { - hi = 1 - }; }; -fn test2() = {}; +fn test2(hello: i32,) = { + hello +}; + +fn test2(hello: i32,) = { + hello +}; diff --git a/todo.md b/todo.md index 8b1aeaf..64ef373 100644 --- a/todo.md +++ b/todo.md @@ -1,3 +1,4 @@ - [ ] Fix inconsensity in asm, change all structs to pointer - [ ] Fix inconsensity in Tests - [ ] Find a better way todo tests, like to generate a test case +- [ ] Add packages diff --git a/typechecker/variable_resolution.go b/typechecker/variable_resolution.go index a5f6481..9e2bcac 100644 --- a/typechecker/variable_resolution.go +++ b/typechecker/variable_resolution.go @@ -73,6 +73,11 @@ func VarResolve(p *ast.Program) (map[string]Scope, error) { for _, d := range p.Declarations { switch d := d.(type) { case *ast.FunctionDeclaration: + _, ok := functionToScope[d.Name] + if ok { + return functionToScope, errorf(d.Token, "duplicate function name %q", d.Name) + } + s := Scope{Variables: make(map[string]Var)} for _, arg := range d.Args { s.SetUniq(arg.Name)