Skip to content

switch instruction doesn't jump to an offset #74

@jsjolen

Description

@jsjolen

Hi,

switch-like jump table.  Top of stack is a variable reference.  Below that is ahash table mapping compared values to instructions offsets.

The hash table values aren't offsets, they're pc values.

So it's not:

pc = pc + ht.lookup(TOS);

It's:

pc = ht.lookup(TOS);

This is seen in bytecode.c:

	op_branch:
	  op -= pc - bytestr_data;
	op_relative_branch:
	  pc += op;
	  NEXT;

Inlining the computation we get pc = pc + op - pc - byte_strdata == op - byte_strdata.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions