Skip to content
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

Fixes #2451 with addition to boilerplate loader #2476

Merged

Conversation

Dunbaratu
Copy link
Member

Fixes #2451

The solution is explained in the comment in the code.

When RUN ONCE skipped the actual program call, it wasn't
cleaning out the args and KOSArgMarker the program call was
supposed to be popping. When you use RUN ONCE with a program
that takes no args, that's not horrible, as it just
left one extra KOSArgMarker on the stack which was fine
but slightly wasted stack space if you do RUN ONCE a lot.
But when you use RUN ONCE interleaved with calls to other
programs that DO expect arguments, and start putting the
PARAMETER statement AFTER the RUN ONCE's, then the fact
that this extra KOSArgMarker was there caused misalignment
of the stack.

My solution was that in the clause where RUN ONCE choses to
skip the program call, have the @lr boilerplate program do
the same thing to the stack that a call would have done, that
is have it pop everything down to an including the topmost
KOSArgMarker. I did that by coding a small kRISC loop there:
like so:

// Keep popping till next thing is argbottom, then pop that too:
pop           <---.
testargbottom     |
br.true ---.      |
jump ------+------'
pop   <----'

The solution is explained in the comment in the code.

When RUN ONCE skipped the actual program call, it wasn't
cleaning out the args and KOSArgMarker the program call was
supposed to be popping.  When you use RUN ONCE with a program
that takes no args, that's not horrible, as it just
left one extra KOSArgMarker on the stack which was fine
but slightly wasted stack space if you do RUN ONCE a lot.
But when you use RUN ONCE interleaved with calls to other
programs that DO expect arguments, and start putting the
PARAMETER statement AFTER the RUN ONCE's, then the fact
that this extra KOSArgMarker was there caused misalignment
of the stack.

My solution was that in the clause where RUN ONCE choses to
skip the program call, have the @lr boilerplate program do
the same thing to the stack that a call would have done, that
is have it pop everything down to an including the topmost
KOSArgMarker.  I did that by coding a small kRISC loop there:
like so:

// Keep popping till next thing is argbottom, then pop that too:
pop           <---.
testargbottom     |
br.true ---.      |
jump ------+------'
pop   <----'
@Dunbaratu Dunbaratu added the bug Weird outcome is probably not what the mod programmer expected. label Mar 28, 2019
@Dunbaratu Dunbaratu merged commit 32a762d into KSP-KOS:develop Apr 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Weird outcome is probably not what the mod programmer expected.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant