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

Implement if/unless as an instruction #83

Open
macournoyer opened this issue Oct 12, 2020 · 2 comments
Open

Implement if/unless as an instruction #83

macournoyer opened this issue Oct 12, 2020 · 2 comments

Comments

@macournoyer
Copy link
Contributor

Introducing an OP_BRANCHUNLESS <offset> instruction (inspired by Ruby).

Pseudo bytecode:

<condition>         <= evaled condition is on stack
OP_BRANCHUNLESS  2  <= jump +2 bytes unless stack_pop
<2 bytes of body>
<end if>

To keep things simple at first, we could compile only the if/unless without any else branches.

This would be the first jump type instruction. if is the simplest one, so it's a good starting point. After this, porting for, case, and, or to instructions will be possible.

However, I think this is where the const_ptr pointer breaks. Any instruction using the const_ptr inside a loop/jump will cause it to be out of sync w/ ip. This should be fixed first.

@dylanahsmith
Copy link
Contributor

However, I think this is where the const_ptr pointer breaks. Any instruction using the const_ptr inside a loop/jump will cause it to be out of sync w/ ip. This should be fixed first.

I would say the benefits of it start to break, since it would essentially rely on fat pointers, which include an offset for both the ip and const_ptr. I agree that we should move away from the constant pointer before implementing the control flow tags.

@dylanahsmith
Copy link
Contributor

Added issue #84 for migrating away from using a moving const_ptr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants