befunge

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 30, 2020 License: MIT Imports: 9 Imported by: 0

README

Befunge

Build Status Go Report Card GoDoc GitHub license

A Befunge-93 interpreter written in Golang with a built-in debugger.

License

Pouch is licensed under the MIT License. See LICENSE for the full license text.

Documentation

Index

Constants

View Source
const (
	OpAdd         = '+' // Addition: Pop a and b, then push a+b.
	OpSub         = '-' // Subtraction: Pop a and b, then push b-a.
	OpMult        = '*' // Multiplication: Pop a and b, then push a*b.
	OpDiv         = '/' // Integer division: Pop a and b, then push b/a, rounded down. If a is zero, push zero.
	OpMod         = '%' // Modulo: Pop a and b, then push the b%a. If a is zero, push zero.
	OpNot         = '!' // Logical NOT: Pop a value. If the value is zero, push 1; otherwise, push zero.
	OpGreaterThan = '`' // Greater than: Pop a and b, then push 1 if b>a, otherwise push zero.

	OpDup        = ':'  // Duplicate value on top of the stack. If there is nothing on top of the stack, push a 0.
	OpSwap       = '\\' // Swap two values on top of the stack. If there is only one value, pretend there is an extra 0 on bottom of the stack.
	OpStringMode = '"'  // Start string mode: push each character's ASCII value all the way up to the next ".
	OpPop        = '$'  // Pop value from the stack and discard it.

	OpOutInt  = '.' // Pop value and output as an integer.
	OpOutRune = ',' // Pop value and output the ASCII character represented by the integer code that is stored in the value.
	OpInInt   = '&' // Ask user for a number and push it
	OpInRune  = '~' // Ask user for a character and push its ASCII value

	OpGetCode = 'g' // A "get" call (a way to retrieve data in storage). Pop y and x, then push ASCII value of the character at that position in the program
	OpPutCode = 'p' // A "put" call (a way to store a value for later use). Pop y, x and v, then change the character at the position (x,y) in the program to the character with ASCII value v.

	OpModRight  = '>' // Start moving right.
	OpMovLeft   = '<' // Start moving left.
	OpMovUp     = '^' // Start moving up.
	OpMovDown   = 'v' // Start moving down.
	OpMovRandom = '?' // Start moving in a random cardinal direction.
	OpIfHoriz   = '_' // Pop a value; move right if value = 0, left otherwise.
	OpIfVert    = '|' // Pop a value; move down if value = 0, up otherwise.
	OpBridge    = '#' // Trampoline: Skip next cell.
	OpBlank     = ' ' // (i.e. a space) No-op. Does nothing.
	OpEnd       = '@' // End program.

	OpOther = math.MaxUint8
	OpNone  = 0
)

https://en.wikipedia.org/wiki/Befunge 0-9 Push this number on the stack.

Variables

This section is empty.

Functions

This section is empty.

Types

type Runner

type Runner struct {
	Scanner
	// contains filtered or unexported fields
}

Runner befunge runner.

func NewRunner

func NewRunner(s []byte) *Runner

NewRunner create a new befunge codes runner.

func (*Runner) Duplicate

func (r *Runner) Duplicate()

Duplicate value on top of the stack.

func (*Runner) Errors added in v0.1.2

func (r *Runner) Errors() []error

Errors of the Runner

func (*Runner) Get

func (r *Runner) Get() int

Get value from of the stack.

func (*Runner) Output added in v0.1.2

func (r *Runner) Output(s string)

Output print

func (*Runner) Put

func (r *Runner) Put(i int)

Put value to the stack.

func (*Runner) Run

func (r *Runner) Run() error

Run befunge code.

func (*Runner) SetDebug

func (r *Runner) SetDebug(e bool)

SetDebug sets debug.

func (*Runner) SetInput

func (r *Runner) SetInput(input io.Reader)

SetInput sets input.

func (*Runner) SetOutput

func (r *Runner) SetOutput(output io.Writer)

SetOutput sets output.

func (*Runner) SetRandFunc added in v0.1.4

func (r *Runner) SetRandFunc(randFunc func(n int) int)

SetRandFunc sets randFunc.

func (*Runner) SetStep

func (r *Runner) SetStep(f func())

SetStep sets step.

func (*Runner) Stack

func (r *Runner) Stack() []int

Stack returns stack.

func (*Runner) Swap

func (r *Runner) Swap()

Swap two values on top of the stack.

type Scanner

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

Scanner befunge scanner.

func NewScanner

func NewScanner(src []byte) *Scanner

NewScanner create a new befunge codes scanner.

func (*Scanner) GetCode

func (s *Scanner) GetCode(x, y int) int

GetCode get code.

func (*Scanner) Next

func (s *Scanner) Next(i int)

Next scan next

func (*Scanner) Point

func (s *Scanner) Point() (int, int)

Point returns current point

func (*Scanner) PutCode

func (s *Scanner) PutCode(x, y, v int)

PutCode put code.

func (*Scanner) Scan

func (s *Scanner) Scan() (int, byte)

Scan returns scan a code.

func (*Scanner) SetRudder

func (s *Scanner) SetRudder(ru byte)

SetRudder set rudder.

func (*Scanner) Size

func (s *Scanner) Size() (int, int)

Size returns current size

func (*Scanner) String

func (s *Scanner) String() string

String returns the current codes.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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