mirror of
https://github.com/RoBaertschi/tt.git
synced 2025-04-19 23:33:30 +00:00
Compare commits
No commits in common. "45dad474e09da94bade3c7df7d894b410654b7fe" and "508b3fdc7ad5e550594ec619257e62c29d38c15c" have entirely different histories.
45dad474e0
...
508b3fdc7a
@ -173,12 +173,9 @@ func (be *BinaryExpression) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type BlockExpression struct {
|
type BlockExpression struct {
|
||||||
Token token.Token // The '{'
|
Token token.Token // The '{'
|
||||||
Expressions []Expression
|
Expressions []Expression
|
||||||
// NOTE: Nullable
|
ReturnExpression Expression // A expression that does not end with a semicolon, there can only be one of those and it hast to be at the end
|
||||||
//
|
|
||||||
// A expression that does not end with a semicolon, there can only be one of those and it has to be at the end
|
|
||||||
ReturnExpression Expression
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (be *BlockExpression) expressionNode() {}
|
func (be *BlockExpression) expressionNode() {}
|
||||||
|
@ -47,7 +47,7 @@ func (sp *SourceProgram) Build(backend asm.Backend, emitAsmOnly bool, toPrint To
|
|||||||
id := 0
|
id := 0
|
||||||
|
|
||||||
addRootNode := func(task task) int {
|
addRootNode := func(task task) int {
|
||||||
l.Debugf("registering root task %d %q", id, task.Name())
|
l.Debugf("registering root task %d", id)
|
||||||
node := &node{task: task}
|
node := &node{task: task}
|
||||||
nodes[id] = node
|
nodes[id] = node
|
||||||
rootNodes = append(rootNodes, id)
|
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 {
|
addNode := func(task task, deps ...int) int {
|
||||||
l.Debugf("registering task %d %q", id, task.Name())
|
l.Debugf("registering task %d", id)
|
||||||
if len(deps) <= 0 {
|
if len(deps) <= 0 {
|
||||||
panic("node without dep is useless")
|
panic("node without dep is useless")
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime/debug"
|
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -150,7 +149,7 @@ func build(outputWriter io.Writer, input string, output string, toPrint ToPrintF
|
|||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if panicErr := recover(); panicErr != nil {
|
if panicErr := recover(); panicErr != nil {
|
||||||
err = fmt.Errorf("panic in build: %#v\n%s", panicErr, debug.Stack())
|
err = fmt.Errorf("panic in build: %#v", panicErr)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -260,8 +259,8 @@ func runTasks(nodes map[int]*node, rootNodes []int, l *utils.Logger) error {
|
|||||||
if done[id] != notStarted {
|
if done[id] != notStarted {
|
||||||
panic(fmt.Sprintf("tried starting task %d twice", id))
|
panic(fmt.Sprintf("tried starting task %d twice", id))
|
||||||
}
|
}
|
||||||
|
l.Debugf("executing task %d", id)
|
||||||
node := nodes[id]
|
node := nodes[id]
|
||||||
l.Debugf("executing task %d %q", id, node.task.Name())
|
|
||||||
output[id] = &strings.Builder{}
|
output[id] = &strings.Builder{}
|
||||||
go node.task.Run(id, output[id], doneChan)
|
go node.task.Run(id, output[id], doneChan)
|
||||||
running = append(running, id)
|
running = append(running, id)
|
||||||
@ -299,7 +298,7 @@ func runTasks(nodes map[int]*node, rootNodes []int, l *utils.Logger) error {
|
|||||||
for !allFinished {
|
for !allFinished {
|
||||||
select {
|
select {
|
||||||
case result := <-doneChan:
|
case result := <-doneChan:
|
||||||
l.Debugf("task %d %q is done with err: %v", result.Id, nodes[result.Id].task.Name(), result.Err)
|
l.Debugf("task %d is done with err: %v", result.Id, result.Err)
|
||||||
for i, id := range running {
|
for i, id := range running {
|
||||||
if id == result.Id {
|
if id == result.Id {
|
||||||
running = slices.Delete(running, i, i+1)
|
running = slices.Delete(running, i, i+1)
|
||||||
|
18
design.md
18
design.md
@ -1,18 +0,0 @@
|
|||||||
# Designs
|
|
||||||
|
|
||||||
Playground for language design dessisions
|
|
||||||
|
|
||||||
## Function Calls
|
|
||||||
|
|
||||||
```tt
|
|
||||||
fn hi(hello: i32) = {
|
|
||||||
3
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() = {
|
|
||||||
hi!;
|
|
||||||
hi();
|
|
||||||
hi;
|
|
||||||
};
|
|
||||||
|
|
||||||
```
|
|
@ -3,8 +3,9 @@
|
|||||||
## Syntax
|
## Syntax
|
||||||
|
|
||||||
```tt
|
```tt
|
||||||
|
// Return type is i64
|
||||||
fn main() = {
|
fn main() = {
|
||||||
i := 3;
|
i : = 3;
|
||||||
i
|
i
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -192,9 +192,6 @@ func (p *Parser) parseArgumentList() ([]ast.Argument, bool) {
|
|||||||
for p.peekTokenIs(token.Ident) {
|
for p.peekTokenIs(token.Ident) {
|
||||||
p.nextToken()
|
p.nextToken()
|
||||||
name := p.curToken.Literal
|
name := p.curToken.Literal
|
||||||
if ok, _ := p.expectPeek(token.Colon); !ok {
|
|
||||||
return args, false
|
|
||||||
}
|
|
||||||
p.nextToken()
|
p.nextToken()
|
||||||
t, ok := p.parseType()
|
t, ok := p.parseType()
|
||||||
|
|
||||||
|
20
test.tt
20
test.tt
@ -1,17 +1,13 @@
|
|||||||
fn main() = {
|
fn main() = {
|
||||||
i := 5;
|
hi := 4;
|
||||||
|
|
||||||
if i == 5 {
|
if hi == 4 {
|
||||||
0
|
test2 := 3;
|
||||||
} else {
|
hi = 0
|
||||||
1
|
|
||||||
}
|
}
|
||||||
};
|
else {
|
||||||
|
hi = 1
|
||||||
|
};
|
||||||
|
|
||||||
fn test2(hello: i32,) = {
|
test2
|
||||||
hello
|
|
||||||
};
|
|
||||||
|
|
||||||
fn test2(hello: i32,) = {
|
|
||||||
hello
|
|
||||||
};
|
};
|
||||||
|
1
todo.md
1
todo.md
@ -1,4 +1,3 @@
|
|||||||
- [ ] Fix inconsensity in asm, change all structs to pointer
|
- [ ] Fix inconsensity in asm, change all structs to pointer
|
||||||
- [ ] Fix inconsensity in Tests
|
- [ ] Fix inconsensity in Tests
|
||||||
- [ ] Find a better way todo tests, like to generate a test case
|
- [ ] Find a better way todo tests, like to generate a test case
|
||||||
- [ ] Add packages
|
|
||||||
|
@ -73,11 +73,6 @@ func VarResolve(p *ast.Program) (map[string]Scope, error) {
|
|||||||
for _, d := range p.Declarations {
|
for _, d := range p.Declarations {
|
||||||
switch d := d.(type) {
|
switch d := d.(type) {
|
||||||
case *ast.FunctionDeclaration:
|
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)}
|
s := Scope{Variables: make(map[string]Var)}
|
||||||
for _, arg := range d.Args {
|
for _, arg := range d.Args {
|
||||||
s.SetUniq(arg.Name)
|
s.SetUniq(arg.Name)
|
||||||
@ -123,9 +118,7 @@ func VarResolveExpr(s *Scope, e ast.Expression) error {
|
|||||||
for _, e := range e.Expressions {
|
for _, e := range e.Expressions {
|
||||||
errs = append(errs, VarResolveExpr(&newS, e))
|
errs = append(errs, VarResolveExpr(&newS, e))
|
||||||
}
|
}
|
||||||
if e.ReturnExpression != nil {
|
errs = append(errs, VarResolveExpr(&newS, e.ReturnExpression))
|
||||||
errs = append(errs, VarResolveExpr(&newS, e.ReturnExpression))
|
|
||||||
}
|
|
||||||
|
|
||||||
return errors.Join(errs...)
|
return errors.Join(errs...)
|
||||||
case *ast.IfExpression:
|
case *ast.IfExpression:
|
||||||
@ -152,7 +145,7 @@ func VarResolveExpr(s *Scope, e ast.Expression) error {
|
|||||||
return errorf(e.Token, "variable %q redefined", e.Identifier)
|
return errorf(e.Token, "variable %q redefined", e.Identifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Identifier = s.SetUniq(e.Identifier)
|
s.SetUniq(e.Identifier)
|
||||||
case *ast.VariableReference:
|
case *ast.VariableReference:
|
||||||
v, ok := s.Get(e.Identifier)
|
v, ok := s.Get(e.Identifier)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user