emu

package
v0.0.0-...-9687f63 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package emu provides a generalised virtual machine for executing toy programs that operate solely on integers. It is implemented using a kind of degenerate JIT compilation. Instructions are translated into Go, which is compiled into a plugin, which is then loaded using the plugin package.

This code is not security-hardened in any way. Using this code is a bad idea.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Translate

func Translate(w io.Writer, program []string, translators map[string]TranslatorFunc) error

Translate translates a program into a Go implementation and writes it to w.

Types

type RunFunc

type RunFunc = func(r, m []int, send func(int) error, recv func() (int, error)) error

RunFunc is the type of the function that is compiled.

func Transpile

func Transpile(program []string, translators map[string]TranslatorFunc) (RunFunc, error)

Transpile transpiles a program using a set of opcode translators, and returns a func natively implementing the program.

type TranslatorFunc

type TranslatorFunc func(line int, args []string) (impl string, jumpTargets []int, err error)

TranslatorFunc translates an input line number and line of code into an implementation (one or more lines of Go) and a set of absolute jump targets (line numbers). A TranslatorFunc should not produce labels; Transpile takes care of inserting necessary labels. However, a TranslatorFunc must implement its own jumps (e.g. `goto l%d`).

Jump to

Keyboard shortcuts

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