Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

chore: Refactor how Opcodes are created/lookup #20

Merged
merged 3 commits into from
Mar 13, 2024
Merged

chore: Refactor how Opcodes are created/lookup #20

merged 3 commits into from
Mar 13, 2024

Conversation

Christopher-Chianelli
Copy link
Collaborator

  • PythonBytecodeInstruction becomes a record
  • Removed the 200+ constants OpcodeIdentifier enum and replaced with a sealed interface OpcodeDescriptor, this allows the enum to be split across several classes (and for many switches to be total without a default branch).
  • Replace opcode lookup switches with a method call on the new OpcodeDescriptor class

- PythonBytecodeInstruction becomes a record
- Removed the 200+ constants OpcodeIdentifier enum and replaced
  with a sealed interface OpcodeDescriptor, this allows the enum
  to be split across several classes (and for many switches to be
  total without a default branch).
- Replace opcode lookup switches with a method call on the new
  OpcodeDescriptor class
- testGeneratorWithTryExcept is failing, but no other tests fail.
  This make me suspect there a bug with the rewritten
  PythonFunctionBuilder or ExceptBuilder that is used exclusively
  in tests.
… early

Previously, PythonBytecodeInstruction was mutable. This meant that
the test function builder can pass the except builder a dummy
instruction for the try goto when its exit early.

PythonBytecodeInstruction is now immutable, which means
to update the instruction, you must replace it in the list.
This causes issues when the dummy instruction is used, since
the dummy instruction will replace a real instruction.

The test function builder will now pass null instead of
a dummy instruction, which except builder need to check
before updating the list.
Copy link
Contributor

@triceo triceo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful refactor!
LGTM with minor comments.

@triceo triceo merged commit 4349d20 into TimefoldAI:main Mar 13, 2024
1 check passed
@triceo triceo deleted the refactor-switches branch March 13, 2024 14:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants