asm

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2025 License: AGPL-3.0 Imports: 15 Imported by: 2

Documentation

Overview

Package asm parses and compiles vise assembly code to bytecode.

Index

Constants

This section is empty.

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 `(@Sym Whitespace?)?`
}

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

TODO: Conceal from outside use

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.

TODO: Conceal from outside use

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 FlagParser

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

FlagParser is used to resolve flag strings to corresponding flag index integer values.

func NewFlagParser

func NewFlagParser() *FlagParser

NewFlagParser creates a new FlagParser

func (*FlagParser) GetAsString

func (pp *FlagParser) GetAsString(key string) (string, error)

GetFlag returns the flag index value for a given flag string as a numeric string.

If flag string has not been registered, an error is returned.

func (*FlagParser) GetDescription

func (pp *FlagParser) GetDescription(idx uint32) (string, error)

GetDescription returns a flag description for a given flag index, if available.

If no description has been provided, an error is returned.

func (*FlagParser) GetFlag

func (pp *FlagParser) GetFlag(key string) (uint32, error)

GetFlag returns the flag index integer value for a given flag string

If flag string has not been registered, an error is returned.

func (*FlagParser) Last

func (pp *FlagParser) Last() uint32

Last returns the highest registered flag index value

func (*FlagParser) Load

func (pp *FlagParser) Load(fp string) (int, error)

Load parses a Comma Seperated Value file under the given filepath to provide mappings between flag strings and flag indices.

The expected format is:

Field 1: The literal string "flag" Field 2: Flag string Field 3: Flag index Field 4: Flag description (optional)

func (*FlagParser) WithDebug

func (pp *FlagParser) WithDebug() *FlagParser

type Instruction

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

Instruction represents one full line of assembly code.

TODO: Conceal from outside use

func (Instruction) String

func (i Instruction) String() string

String implements 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