-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
DarkLord017
committed
Nov 2, 2024
1 parent
4d58747
commit 9d7c0cd
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package evm | ||
|
||
// Instruction is a function type that takes an Interpreter and a generic type H. | ||
type Instruction[H any] func(interpreter *Interpreter, h *H) | ||
|
||
// InstructionTable is a list of 256 instructions mapped to EVM opcodes. | ||
type InstructionTable[H any] [256]Instruction[H] | ||
|
||
// DynInstruction is a function type signature for dynamic instructions. | ||
type DynInstruction[H any] func(interpreter *Interpreter, h *H) | ||
|
||
// BoxedInstruction wraps a DynInstruction in a pointer, enabling dynamic dispatch. | ||
type BoxedInstruction[H any] *DynInstruction[H] | ||
|
||
// BoxedInstructionTable is an array of 256 boxed instructions. | ||
type BoxedInstructionTable[H any] [256]BoxedInstruction[H] | ||
|
||
const ( | ||
PlainTableMode = iota | ||
BoxedTableMode | ||
) | ||
|
||
type InstructionTables[H any] struct { | ||
PlainTable *InstructionTable[H] | ||
BoxedTable *BoxedInstructionTable[H] | ||
Mode int // Indicates which table is in use (Plain or Boxed) | ||
} | ||
|
||
// Mode contains 0 and 1 | ||
// NewPlainInstructionTable creates an InstructionTables instance with a PlainTable. | ||
func NewPlainInstructionTable[H any](table InstructionTable[H]) InstructionTables[H] { | ||
return InstructionTables[H]{PlainTable: &table, Mode: PlainTableMode} | ||
} | ||
|
||
// NewBoxedInstructionTable creates an InstructionTables instance with a BoxedTable. | ||
func NewBoxedInstructionTable[H any](table BoxedInstructionTable[H]) InstructionTables[H] { | ||
return InstructionTables[H]{BoxedTable: &table, Mode: BoxedTableMode} | ||
} |