membuild

package
v0.0.0-...-e689c96 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package membuild converts a B++ AST tree into a series of lambdas which can then be executed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Type  parser.DataType
	Value interface{}
}

Data represents a value in B++

func NewBlankData

func NewBlankData() Data

NewBlankData is a utility function to create a valid NULL value

func ParserDataToData

func ParserDataToData(d *parser.Data) Data

ParserDataToData converts parser's Data format to membuild's Data format

type Function

type Function struct {
	Body   []Instruction
	Name   string
	Type   parser.FunctionType
	Return Instruction
}

Function stores the data for a compiled function.

type Instruction

type Instruction func(p *Program) (Data, error)

Instruction stores the data for an instruction, or a callable B++ expression

func ArgsStmt

func ArgsStmt(p *Program, stm *parser.ArgsStmt) (Instruction, error)

ArgsStmt compiles an ARGS statement

func ArrayStmt

func ArrayStmt(p *Program, stm *parser.ArrayStmt) (Instruction, error)

ArrayStmt compiles an ARRAY definition

func BuildStmt

func BuildStmt(p *Program, stmt parser.Statement, instructionum ...int) (Instruction, error)

BuildStmt compiles a statement

func CeilStmt

func CeilStmt(p *Program, stm *parser.CeilStmt) (Instruction, error)

CeilStmt compiles a CEIL statement

func ChooseStmt

func ChooseStmt(p *Program, stm *parser.ChooseStmt) (Instruction, error)

ChooseStmt compiles a CHOOSE statement

func CompareStmt

func CompareStmt(p *Program, stm *parser.ComparisonStmt) (Instruction, error)

CompareStmt compiles a COMPARE statement

func ConcatStmt

func ConcatStmt(p *Program, stm *parser.ConcatStmt) (Instruction, error)

ConcatStmt compiles a CONCAT statement

func DefineStmt

func DefineStmt(p *Program, stm *parser.DefineStmt) (Instruction, error)

DefineStmt compiles a DEFINE statement

func FloorStmt

func FloorStmt(p *Program, stm *parser.FloorStmt) (Instruction, error)

FloorStmt compiles a FLOOR statement

func FunctionBlock

func FunctionBlock(p *Program, stm *parser.FunctionBlock) (Instruction, error)

FunctionBlock compiles a FUNCTION block.

func FunctionCallStmt

func FunctionCallStmt(p *Program, stm *parser.FunctionCallStmt) (Instruction, error)

FunctionCallStmt compiles a function call

func IfBlock

func IfBlock(p *Program, stm *parser.IfBlock) (Instruction, error)

IfBlock compiles an if block (IFB)

func IfStmt

func IfStmt(p *Program, stm *parser.IfStmt) (Instruction, error)

IfStmt compiles an IF statement

func ImportStmt

func ImportStmt(p *Program, stm *parser.ImportStmt) (Instruction, error)

ImportStmt compiles an IMPORT statement

func IndexStmt

func IndexStmt(p *Program, stm *parser.IndexStmt) (Instruction, error)

IndexStmt compiles an INDEX statement

func MathStmt

func MathStmt(p *Program, stm *parser.MathStmt) (Instruction, error)

MathStmt compiles a MATH statement

func NewBlankInstruction

func NewBlankInstruction() Instruction

NewBlankInstruction is a utility function to create an empty, but valid instruction

func RandintStmt

func RandintStmt(p *Program, stm *parser.RandintStmt) (Instruction, error)

RandintStmt compiles a RANDINT statement

func RandomStmt

func RandomStmt(p *Program, stm *parser.RandomStmt) (Instruction, error)

RandomStmt compiles a RANDOM statement

func RepeatStmt

func RepeatStmt(p *Program, stm *parser.RepeatStmt) (Instruction, error)

RepeatStmt compiles a REPEAT statement

func RoundStmt

func RoundStmt(p *Program, stm *parser.RoundStmt) (Instruction, error)

RoundStmt compiles a ROUND statement

func TypeCastStmt

func TypeCastStmt(p *Program, stm *parser.TypeCastStmt) (Instruction, error)

TypeCastStmt compiles a type-cast statement

func VarStmt

func VarStmt(p *Program, stm *parser.VarStmt) (Instruction, error)

VarStmt compiles a VAR statement

func WhileBlock

func WhileBlock(p *Program, stm *parser.WhileBlock) (Instruction, error)

WhileBlock compiles a WHILE block

type Program

type Program struct {
	Instructions []Instruction
	Memory       map[string]Data
	Functions    map[string]Function

	// Inputs
	Args   []string
	Runner func(Data) error
}

Program stores a compiled B++ program with Variables, Functions, and allows for inputs

func Build

func Build(prog *parser.Program) (*Program, error)

Build compiles a B++ program

func (*Program) Run

func (p *Program) Run() error

Run runs the program

Jump to

Keyboard shortcuts

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