Skip to content

Commit

Permalink
core/asm: use strings.Builder and fix godoc issues (#24861)
Browse files Browse the repository at this point in the history
  • Loading branch information
s7v7nislands committed May 16, 2022
1 parent fcbc05c commit 330e53f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions core/asm/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

// Provides support for dealing with EVM assembly instructions (e.g., disassembling them).
// Package asm provides support for dealing with EVM assembly instructions (e.g., disassembling them).
package asm

import (
Expand All @@ -34,14 +34,14 @@ type instructionIterator struct {
started bool
}

// Create a new instruction iterator.
// NewInstructionIterator create a new instruction iterator.
func NewInstructionIterator(code []byte) *instructionIterator {
it := new(instructionIterator)
it.code = code
return it
}

// Returns true if there is a next instruction and moves on.
// Next returns true if there is a next instruction and moves on.
func (it *instructionIterator) Next() bool {
if it.error != nil || uint64(len(it.code)) <= it.pc {
// We previously reached an error or the end.
Expand Down Expand Up @@ -79,27 +79,27 @@ func (it *instructionIterator) Next() bool {
return true
}

// Returns any error that may have been encountered.
// Error returns any error that may have been encountered.
func (it *instructionIterator) Error() error {
return it.error
}

// Returns the PC of the current instruction.
// PC returns the PC of the current instruction.
func (it *instructionIterator) PC() uint64 {
return it.pc
}

// Returns the opcode of the current instruction.
// Op returns the opcode of the current instruction.
func (it *instructionIterator) Op() vm.OpCode {
return it.op
}

// Returns the argument of the current instruction.
// Arg returns the argument of the current instruction.
func (it *instructionIterator) Arg() []byte {
return it.arg
}

// Pretty-print all disassembled EVM instructions to stdout.
// PrintDisassembled pretty-print all disassembled EVM instructions to stdout.
func PrintDisassembled(code string) error {
script, err := hex.DecodeString(code)
if err != nil {
Expand All @@ -117,7 +117,7 @@ func PrintDisassembled(code string) error {
return it.Error()
}

// Return all disassembled EVM instructions in human-readable format.
// Disassemble returns all disassembled EVM instructions in human-readable format.
func Disassemble(script []byte) ([]string, error) {
instrs := make([]string, 0)

Expand Down
10 changes: 5 additions & 5 deletions core/asm/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Compiler struct {
debug bool
}

// newCompiler returns a new allocated compiler.
// NewCompiler returns a new allocated compiler.
func NewCompiler(debug bool) *Compiler {
return &Compiler{
labels: make(map[string]int),
Expand Down Expand Up @@ -105,16 +105,16 @@ func (c *Compiler) Compile() (string, []error) {
}

// turn the binary to hex
var bin string
var bin strings.Builder
for _, v := range c.binary {
switch v := v.(type) {
case vm.OpCode:
bin += fmt.Sprintf("%x", []byte{byte(v)})
bin.WriteString(fmt.Sprintf("%x", []byte{byte(v)}))
case []byte:
bin += fmt.Sprintf("%x", v)
bin.WriteString(fmt.Sprintf("%x", v))
}
}
return bin, errors
return bin.String(), errors
}

// next returns the next token and increments the
Expand Down
2 changes: 1 addition & 1 deletion core/asm/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type lexer struct {
debug bool // flag for triggering debug output
}

// lex lexes the program by name with the given source. It returns a
// Lex lexes the program by name with the given source. It returns a
// channel on which the tokens are delivered.
func Lex(source []byte, debug bool) <-chan token {
ch := make(chan token)
Expand Down

0 comments on commit 330e53f

Please sign in to comment.