Skip to content

Commit f80b757

Browse files
committed
feat: add debug print statements and update Interpret method signature
- Add debug print statements in Interpret and Eval methods for troubleshooting - Modify Interpret method to accept pre-created environment instead of creating a new one - Update method to preserve and restore GlobalEnv during interpretation - Include additional logging for error tracking and method flow
1 parent e9e35e3 commit f80b757

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

internal/lox/interpreter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ func BasicInterpret(expression Expr, stdout io.Writer, stderr io.Writer) {
2929
fmt.Fprintln(stdout, result)
3030
}
3131

32-
func Interpret(statements []Stmt, locals Locals, stdout io.Writer, stderr io.Writer) {
33-
env := NewGlobal()
32+
func Interpret(statements []Stmt, env *Environment, locals Locals, stdout io.Writer, stderr io.Writer) {
3433
OldGlobalEnv := GlobalEnv
3534
GlobalEnv = env
3635
InitializeNativeFunctions()
36+
3737
for _, stmt := range statements {
3838
_, err := Eval(stmt, env, locals, stdout, stderr)
3939
if err != nil {
@@ -293,7 +293,7 @@ func Eval(node Node, environment *Environment, locals Locals, stdout io.Writer,
293293
}
294294
return nil, nil
295295
case *Function:
296-
function := NewUserFunction(n, environment)
296+
function := NewUserFunction(n, environment, locals)
297297
environment.Define(n.Name.Lexeme, function)
298298
return nil, nil
299299
case *Return:

0 commit comments

Comments
 (0)