asm

package
v0.0.9-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package asm parses and compiles vise assembly code to bytecode.

Index

Constants

View Source
const (
	MENU_DOWN     = _MENU_OFFSET
	MENU_UP       = _MENU_OFFSET + 1
	MENU_NEXT     = _MENU_OFFSET + 2
	MENU_PREVIOUS = _MENU_OFFSET + 3
)

Variables

This section is empty.

Functions

func Parse

func Parse(s string, w io.Writer) (int, error)

Parse one or more lines of assembly code, and write assembled bytecode to the provided writer.

Types

type Arg

type Arg struct {
	Sym      *string `(@Sym Whitespace?)?`
	Size     *uint32 `(@Size Whitespace?)?`
	Flag     *uint8  `(@Size Whitespace?)?`
	Selector *string `(@Sym Whitespace?)?`
	Desc     *string `(Quote ((@Sym | @Size) @Whitespace?)+ Quote Whitespace?)?`
}

Arg holds all parsed argument elements of a single line of assembly code.

func (Arg) String

func (a Arg) String() string

String implements the String interface.

type Asm

type Asm struct {
	Instructions []*Instruction `@@*`
}

Asm assembles bytecode from the vise assembly mini-language.

type BatchCode

type BatchCode uint16

BatchCode defines quasi-opcodes that expand to mulitple individual vm instructions.

type Batcher

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

Batcher handles assembly commands that generates multiple instructions, such as menu navigation commands.

func NewBatcher

func NewBatcher(mp MenuProcessor) Batcher

NewBatcher creates a new Batcher objcet.

func (*Batcher) Exit

func (bt *Batcher) Exit(w io.Writer) (int, error)

Exit is a synonym for MenuExit

func (*Batcher) MenuAdd

func (bt *Batcher) MenuAdd(w io.Writer, code string, arg Arg) (int, error)

MenuAdd adds a new menu instruction to the batcher.

func (*Batcher) MenuExit

func (bt *Batcher) MenuExit(w io.Writer) (int, error)

MenuExit generates the instructions for the batch and writes them to the given io.Writer.

type Instruction

type Instruction struct {
	OpCode  string `@Ident`
	OpArg   Arg    `(Whitespace @@)?`
	Comment string `Comment? EOL`
}

Instruction represents one full line of assembly code.

func (Instruction) String

func (i Instruction) String() string

String implement the String interface.

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

MenuProcessor handles code lines with BatchCode quasi-opcodes that control menu generation.

It creates vm instructions for display of menu and handling of input on either size of a vm.HALT instruction.

func NewMenuProcessor

func NewMenuProcessor() MenuProcessor

NewMenuProcessor creates a new MenuProcessor object.

func (mp *MenuProcessor) Add(bop string, choice string, display string, target string) error

Add a menu batch instruction to be processed.

Instructions will be rendered in the order in which they have been added.

func (mp *MenuProcessor) ToLines() []byte

ToLines returns the generated bytecode from the added menu batch instructions.

Jump to

Keyboard shortcuts

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