-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store function call state in a stack #294
base: main
Are you sure you want to change the base?
Store function call state in a stack #294
Conversation
As functions are called store the current execution state for the function in a stack. This includes the local variables and re.group.{N} variables. This stack is used to detect recursion and prevent an interpreter panic. In the future this information could be used for including a VCL stack trace in error output or for accessing calling function state in the debugger.
b26ea74
to
c5db1f1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good approach, LGTM
Regex: make(map[string]*value.String), | ||
Subroutine: sub, | ||
} | ||
i.Stack = append(i.Stack, sf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tentatively we can define the max call stack frames and raise an error if exceeded, probably around 100 would be enough but up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that seems reasonable. I did a test and generated a silly call chain of 200 functions in a fiddle and it didn't cause an error. Seems like the limiting factor isn't the call depth but the overall workspace memory usage which would eventually be exhausted.
f07942c
to
a42813b
Compare
@richardmarshall Sorry I forgot to merge this PR and treid to resolve conflicts but some testing errors are found due to the head branch changes. I'm so happy if you could adjust to main branch but of course I could do after merging this PR, thanks |
As functions are called store the current execution state for the function in a stack. This includes the local variables and re.group.{N} variables.
This stack is used to detect recursion and prevent an interpreter panic.
In the future this information could be used for including a VCL stack trace in error output or for accessing calling function state in the debugger.
Note: The current code structure makes accessing the re.group variables directly from the stack pointer a challenge. To keep things simple I retained the save / restore model we currently have for those. If there is consensus on the idea of using a stack frame model we can decide if it makes sense to restructure things to make access through the stack pointer possible.
Resolves #293, #297