interpreter

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorFileExtension   = errors.New("error: target image must be .png")
	ErrorOpenImage       = errors.New("error: unable to open specified image")
	ErrorRandomGenerator = errors.New("error: trying to generate a random number with n <= 0")
	ErrorDecodeImage     = errors.New("error: unable to decode specified image")
	ErrorOutOfBounds     = errors.New("error: out of bounds")
	ErrorInvalidHex      = errors.New("error: invalid hex format")
	ErrorLoadConfig      = errors.New("error: unable to load config file")
	ErrorCloseFile       = errors.New("error: unable to close the file")
	ErrorInputScanning   = errors.New("error: problems reading input")
)

* Interpreter's throwable errors

View Source
var (
	ErrorPop       = errors.New("error: trying to pop an empty stack")
	ErrorFullStack = errors.New("error: trying to push in a full stack")
)
View Source
var OPERATIONS = map[string]*Pixel{
	"INPUT_INT":    {R: 255, G: 255, B: 255},
	"OUTPUT_INT":   {R: 0, G: 0, B: 0},
	"SUM":          {R: 0, G: 206, B: 209},
	"SUB":          {R: 255, G: 165, B: 0},
	"DIV":          {R: 138, G: 43, B: 226},
	"MUL":          {R: 139, G: 0, B: 0},
	"MOD":          {R: 255, G: 218, B: 185},
	"RND":          {R: 0, G: 128, B: 0},
	"AND":          {R: 236, G: 243, B: 220},
	"OR":           {R: 183, G: 198, B: 230},
	"XOR":          {R: 245, G: 227, B: 215},
	"NAND":         {R: 225, G: 211, B: 239},
	"NOT":          {R: 255, G: 154, B: 162},
	"INPUT_ASCII":  {R: 227, G: 227, B: 227},
	"OUTPUT_ASCII": {R: 75, G: 75, B: 75},
	"POP":          {R: 204, G: 158, B: 6},
	"SWAP":         {R: 255, G: 189, B: 74},
	"CYCLE":        {R: 227, G: 127, B: 157},
	"RCYCLE":       {R: 233, G: 148, B: 174},
	"DUP":          {R: 0, G: 105, B: 148},
	"REVERSE":      {R: 165, G: 165, B: 141},
	"QUIT":         {R: 183, G: 228, B: 199},
	"OUTPUT":       {R: 155, G: 34, B: 66},
	"WHILE":        {R: 46, G: 26, B: 71},
	"WHILE_END":    {R: 104, G: 71, B: 141},
}

* A map of all interpreter's operations

Functions

func Btoi

func Btoi(b bool) int

Converts a bool to integer

func Itob

func Itob(i int) bool

Converts an integer to bool

Types

type Interpreter

type Interpreter struct {
	// contains filtered or unexported fields
}

Interpreter structure

func NewInterpreter

func NewInterpreter(debug bool, configs string, maxSize int) *Interpreter

Interpreter's constructor. Params are flags value from CLI app.

func (*Interpreter) LoadImage

func (i *Interpreter) LoadImage(path string) error

Loads image from OS and puts the stream into the interpreter image reference

func (*Interpreter) Run

func (i *Interpreter) Run()

* Executes the image interpretation doing Step() while the image program is terminated. * It is responsible to increase the program counter and calling the debugger if the flag is set.

func (*Interpreter) Step

func (i *Interpreter) Step() (bool, string)

Interprets and executes next pixel in the given image

type Pixel

type Pixel struct {
	R uint8
	G uint8
	B uint8
}

func (*Pixel) Equals

func (p *Pixel) Equals(other Pixel) bool

func (*Pixel) String

func (p *Pixel) String() string

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

func NewStack

func NewStack(maxSize int) *Stack

func (*Stack) Cycle

func (stack *Stack) Cycle()

func (*Stack) GetItemAt

func (stack *Stack) GetItemAt(i int) int

func (*Stack) IsEmpty

func (stack *Stack) IsEmpty() bool

func (*Stack) Output

func (stack *Stack) Output()

func (*Stack) Peek

func (stack *Stack) Peek() int

func (*Stack) Pop

func (stack *Stack) Pop() (int, error)

func (*Stack) Push

func (stack *Stack) Push(val int) error

func (*Stack) RCycle

func (stack *Stack) RCycle()

func (*Stack) Reverse

func (stack *Stack) Reverse()

func (*Stack) Size

func (stack *Stack) Size() int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL