Operator overload refactor via re-entrant threads, list operator overload improvement #2003
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Operator overloads were extremely complex because they are calling user procs. This meant that operator overloads had to be "tail called" at the end of an opcode handler, so that we could return
ProcStatus.Called
.This posed a huge problem, as the opcode handler loses control after the user proc is executed. This causes multiple issues:
AssignRefProcState
, so we could properly handle the return value of the operator overload. Yuck.ProcStatus
around the place.operator[]()
properly, as it would always need to be called from the start of an opcode handler.This however is all fixable with the following revelation: operator overloads in BYOND are implicitly
waitfor = FALSE
. This means that if we can simply call the proc without needing to useProcStatus.Called
, we can just immediately get the return value from it.This commit does that:
DreamThread
now allows re-entrantly resuming with a new call stack proc, right from the opcode handler. This means operator overloads can just be details that immediately return a value.With this power I was able to clean all of the above issues up. The code is cleaner and less complex.
operator[]()
andoperator[]=()
work. Adding new operator overloads in the future should be easier.