Skip to content

Commit

Permalink
Remove regex matches from stack frame
Browse files Browse the repository at this point in the history
  • Loading branch information
richardmarshall committed Apr 5, 2024
1 parent 765ebef commit a42813b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 10 deletions.
8 changes: 1 addition & 7 deletions interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const MaxStackDepth = 100

type StackFrame struct {
Locals variable.LocalVariables
Regex map[string]*value.String
Subroutine *ast.SubroutineDeclaration
}

Expand All @@ -49,12 +48,7 @@ type Interpreter struct {
}

func New(options ...context.Option) *Interpreter {
stack := []*StackFrame{
{
Locals: variable.LocalVariables{},
Regex: map[string]*value.String{},
},
}
stack := []*StackFrame{{Locals: variable.LocalVariables{}}}
return &Interpreter{
options: options,
cache: cache.New(),
Expand Down
3 changes: 0 additions & 3 deletions interpreter/subroutine.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ func (i *Interpreter) subroutineInStack(sub *ast.SubroutineDeclaration) bool {
func (i *Interpreter) pushStackFrame(sub *ast.SubroutineDeclaration) error {
sf := &StackFrame{
Locals: variable.LocalVariables{},
Regex: make(map[string]*value.String),
Subroutine: sub,
}
i.Stack = append(i.Stack, sf)
if len(i.Stack) > MaxStackDepth {
return errors.WithStack(exception.Runtime(&sub.Token, "max stack depth exceeded"))
}
i.StackPointer = sf
i.ctx.RegexMatchedValues = sf.Regex
return nil
}

Expand All @@ -53,7 +51,6 @@ func (i *Interpreter) popStackFrame() {
i.StackPointer = nil
}
i.ctx.SubroutineCalls[sf.Subroutine.Name.Value]++
i.ctx.RegexMatchedValues = sf.Regex
}

func (i *Interpreter) ProcessSubroutine(sub *ast.SubroutineDeclaration, ds DebugState) (State, error) {
Expand Down

0 comments on commit a42813b

Please sign in to comment.