From b633246af891ed2c1a938df98c80b5a4ee22a08f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20B=C3=A4rtschi?= Date: Fri, 7 Mar 2025 16:38:14 +0100 Subject: [PATCH] direnv and some arg fixes --- .envrc | 1 + .gitignore | 1 + build/build.go | 2 +- lexer/lexer.go | 6 ++++++ test.tt | 7 ++----- ttir/ttir.go | 1 + typechecker/variable_resolution.go | 5 +++-- 7 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index b2be92b..726d2d6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ result +.direnv diff --git a/build/build.go b/build/build.go index 425bbab..a51fd7e 100644 --- a/build/build.go +++ b/build/build.go @@ -40,7 +40,7 @@ func NewSourceProgram(inputFile string, outputFile string) *SourceProgram { } func (sp *SourceProgram) Build(backend asm.Backend, emitAsmOnly bool, toPrint ToPrintFlags) error { - l := utils.NewLogger(os.Stderr, "[build] ", utils.Info) + l := utils.NewLogger(os.Stderr, "[build] ", utils.Debug) nodes := make(map[int]*node) rootNodes := []int{} diff --git a/lexer/lexer.go b/lexer/lexer.go index 1e50dbc..96faf7b 100644 --- a/lexer/lexer.go +++ b/lexer/lexer.go @@ -110,6 +110,12 @@ func (l *Lexer) NextToken() token.Token { case '*': tok = l.newToken(token.Asterisk) case '/': + if l.peekByte() == '/' { + for l.ch != '\n' { + l.readChar() + } + return l.NextToken() + } tok = l.newToken(token.Slash) case '{': tok = l.newToken(token.OpenBrack) diff --git a/test.tt b/test.tt index 588b55f..4c9dbd4 100644 --- a/test.tt +++ b/test.tt @@ -8,10 +8,7 @@ fn main() = { } }; -fn test2(hello: i32,) = { - hello +fn test2(hello: i64,) = { + hello // Comment test }; -fn test2(hello: i32,) = { - hello -}; diff --git a/ttir/ttir.go b/ttir/ttir.go index 06a62fc..fa945b1 100644 --- a/ttir/ttir.go +++ b/ttir/ttir.go @@ -22,6 +22,7 @@ func (p *Program) String() string { type Function struct { Name string + Arguments []string Instructions []Instruction HasReturnValue bool } diff --git a/typechecker/variable_resolution.go b/typechecker/variable_resolution.go index 9e2bcac..40ac400 100644 --- a/typechecker/variable_resolution.go +++ b/typechecker/variable_resolution.go @@ -79,8 +79,9 @@ func VarResolve(p *ast.Program) (map[string]Scope, error) { } s := Scope{Variables: make(map[string]Var)} - for _, arg := range d.Args { - s.SetUniq(arg.Name) + for i, arg := range d.Args { + uniq := s.SetUniq(arg.Name) + d.Args[i].Name = uniq } err := VarResolveExpr(&s, d.Body) functionToScope[d.Name] = s