Skip to content

Implement if/unless as an instruction #83

Open
@macournoyer

Description

@macournoyer

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions