Improved variable lifetime tracking

This commit is contained in:
Eduard Urbach 2024-06-30 00:17:14 +02:00
parent 1510f88165
commit b8c011d742
Signed by: eduard
GPG key ID: 49226B848C78F6C8
17 changed files with 114 additions and 31 deletions

View file

@ -1,6 +1,8 @@
package build
import (
"fmt"
"git.akyoto.dev/cli/q/src/build/config"
"git.akyoto.dev/cli/q/src/build/expression"
"git.akyoto.dev/cli/q/src/build/fs"
@ -44,6 +46,10 @@ func (f *Function) CompileTokens(body token.List) error {
instruction := body[start:i]
if config.Verbose {
f.Logf("compiling: %s", instruction)
}
if config.Assembler {
f.debug = append(f.debug, debug{
position: len(f.assembler.Instructions),
source: instruction,
@ -108,6 +114,11 @@ func (f *Function) CompileInstruction(line token.List) error {
}
}
// Logf formats a message for verbose output.
func (f *Function) Logf(format string, data ...any) {
fmt.Printf("[%s @ %d] %s\n", f, len(f.assembler.Instructions), fmt.Sprintf(format, data...))
}
// String returns the function name.
func (f *Function) String() string {
return f.Name