Skip to content

Commit

Permalink
Added folder for evm files
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkLord017 committed Nov 2, 2024
1 parent 4d58747 commit 9d7c0cd
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions evm/tables.go
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}
}

0 comments on commit 9d7c0cd

Please sign in to comment.