-
Notifications
You must be signed in to change notification settings - Fork 127
Implement caller
#2517
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
Open
ike709
wants to merge
4
commits into
OpenDreamProject:master
Choose a base branch
from
ike709:callhermaybe
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Implement caller
#2517
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /datum/meep/proc/bar() | ||
| ASSERT(caller.caller.caller.name == "ihateithere") | ||
|
|
||
| /datum/proc/foo() | ||
| var/datum/meep/M = new | ||
| ASSERT(caller.name == "ihateithere") | ||
| M.bar() | ||
|
|
||
| /proc/ihateithere() | ||
| var/datum/D = new | ||
| ASSERT(caller.name == "RunTest") | ||
| D.foo() | ||
|
|
||
| /proc/RunTest() | ||
| // RunTest()'s caller is null due to how unit tests are invoked | ||
| ihateithere() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,39 +3,49 @@ | |
|
|
||
| namespace OpenDreamRuntime.Objects.Types; | ||
|
|
||
| public sealed class DreamObjectCallee(DreamObjectDefinition objectDefinition) : DreamObject(objectDefinition) { | ||
| public DMProcState? ProcState; | ||
| public sealed class DreamObjectCallee : DreamObject { | ||
| public ProcState? ProcState; | ||
| public long ProcStateId; // Used to ensure the proc state hasn't been reused for another proc | ||
| private DreamObjectCallee? _caller; // Caching caller prevents issues with returning incorrect info when the proc ends or calls another proc | ||
|
|
||
| public DreamObjectCallee(DreamObjectDefinition objectDefinition) : base(objectDefinition) { | ||
| SetCaller(); // we need to cache _caller recursively | ||
| } | ||
|
|
||
| protected override bool TryGetVar(string varName, out DreamValue value) { | ||
| // TODO: This ProcState check doesn't match byond behavior? | ||
| if (ProcState == null || ProcState.Id != ProcStateId) | ||
| throw new Exception("This callee has expired"); | ||
|
|
||
| switch (varName) { | ||
| case "proc": | ||
| value = new(ProcState.Proc); | ||
| value = ProcState.Proc != null ? new(ProcState.Proc) : DreamValue.Null; | ||
| return true; | ||
| case "args": | ||
| value = new(new ProcArgsList(ObjectTree.List.ObjectDefinition, ProcState)); | ||
| return true; | ||
| case "caller": | ||
| // TODO | ||
| value = DreamValue.Null; | ||
| SetCaller(); // sometimes ProcState is null in the constructor? | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why wouldn't |
||
| value = new DreamValue(_caller); | ||
| return true; | ||
| case "name": | ||
| value = new(ProcState.Proc.VerbName); | ||
| value = ProcState.Proc?.VerbName != null ? new(ProcState.Proc.VerbName) : DreamValue.Null; | ||
| return true; | ||
| case "desc": | ||
| value = ProcState.Proc.VerbDesc != null ? new(ProcState.Proc.VerbDesc) : DreamValue.Null; | ||
| value = ProcState.Proc?.VerbDesc != null ? new(ProcState.Proc.VerbDesc) : DreamValue.Null; | ||
| return true; | ||
| case "category": | ||
| value = ProcState.Proc.VerbCategory != null ? new(ProcState.Proc.VerbCategory) : DreamValue.Null; | ||
| value = ProcState.Proc?.VerbCategory != null ? new(ProcState.Proc.VerbCategory) : DreamValue.Null; | ||
| return true; | ||
| case "file": | ||
| value = new(ProcState.Proc.GetSourceAtOffset(0).Source); | ||
| value = ProcState.Proc is DMProc procFile | ||
| ? new DreamValue(procFile.GetSourceAtOffset(0).Source) | ||
| : DreamValue.Null; | ||
| return true; | ||
| case "line": | ||
| value = new(ProcState.Proc.GetSourceAtOffset(0).Line); | ||
| value = ProcState.Proc is DMProc procLine | ||
| ? new DreamValue(procLine.GetSourceAtOffset(0).Line) | ||
| : DreamValue.Null; | ||
| return true; | ||
| case "src": | ||
| value = new(ProcState.Instance); | ||
|
|
@@ -54,6 +64,19 @@ protected override bool TryGetVar(string varName, out DreamValue value) { | |
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Sets <see cref="_caller"/> if it hasn't been already and <see cref="ProcState"/> is not null | ||
| /// </summary> | ||
| private void SetCaller() { | ||
| if (ProcState is null || _caller is not null) return; | ||
| if (ProcState.Thread.PeekStack(1) is not DMProcState dmProcState) return; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always passing an index of 1 is incorrect |
||
|
|
||
| var caller = ObjectTree.CreateObject<DreamObjectCallee>(ObjectTree.Callee); | ||
| caller.ProcState = dmProcState; | ||
| caller.ProcStateId = dmProcState.Id; | ||
| _caller = caller; | ||
| } | ||
|
|
||
| protected override void SetVar(string varName, DreamValue value) { | ||
| throw new Exception($"Cannot set var {varName} on /callee"); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
Should this not be
"RunTest"?Could also be using
nameof(/proc/RunTest)for these asserts instead.