ic11

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDiv0 = errors.New("division by 0")
View Source
var ErrInvalidFuncCall = errors.New("invalid function call")
View Source
var ErrInvalidState = errors.New("parser produced invalid state")
View Source
var ErrNoMain = errors.New("main function is missing")
View Source
var ErrOutOfTempRegisters = errors.New("compiler ran out of temporary registers")
View Source
var ErrTooManyVars = errors.New("maximum number of variables supported is 15")
View Source
var ErrUnknownLabel = errors.New("unknown label")
View Source
var ErrUnknownVar = errors.New("variable is not known")

Functions

func ComputeHash added in v0.4.0

func ComputeHash(str string) int

Types

type Assignment

type Assignment struct {
	Pos lexer.Position

	Left  string `@Ident "="`
	Right *Expr  `@@`
}

type Binary

type Binary struct {
	Pos lexer.Position

	LHS *Primary `@@`
	Op  string   `@( "|" "|" | "&" "&" | "!" "=" | ("!"|"<"|">") "="? | "=" "=" | "+" | "-" | "/" | "*" )`
	RHS *Primary `@@`
}

type BuiltinArity0Func

type BuiltinArity0Func struct {
	Pos lexer.Position
	Op  string `@("yield" | "rand") "(" ")"`
}

type BuiltinArity1Func

type BuiltinArity1Func struct {
	Pos lexer.Position
	Op  string `` /* 180-byte string literal not displayed */

	Arg *Expr `"(" @@ ")"`
}

type BuiltinArity2Func

type BuiltinArity2Func struct {
	Pos  lexer.Position
	Op   string `@("load" | "mod" | "xor" | "nor" | "max" | "min" )`
	Arg1 *Expr  `"(" @@ ","`
	Arg2 *Expr  `@@ ")"`
}

type BuiltinArity3Func

type BuiltinArity3Func struct {
	Pos  lexer.Position
	Op   string `@("store" | "store_batch" | "load_batch")`
	Arg1 *Expr  `"(" @@ ","`
	Arg2 *Expr  ` @@ ","`
	Arg3 *Expr  `@@ ")"`
}

type CallFunc

type CallFunc struct {
	Pos lexer.Position

	Ident string  `@Ident`
	Index []*Expr `"(" (@@ ("," @@)*)? ")"`
}

type Compiler

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

func NewCompiler

func NewCompiler(files []io.Reader, conf CompilerOpts, printer printer.Printer) (*Compiler, error)

func (*Compiler) Compile

func (comp *Compiler) Compile() (string, error)

type CompilerError

type CompilerError struct {
	Pos      *lexer.Position
	Err      error
	CausedBy *CompilerError
}

func (CompilerError) Error

func (ce CompilerError) Error() string

type CompilerOpts

type CompilerOpts struct {
	OptimizeLabels     bool
	PrecomputeExprs    bool
	OptimizeJumps      bool
	PropagateVariables bool
	EmitDeviceAliases  bool
	PrecomputeHashes   bool
}

func AllCompilerOpts

func AllCompilerOpts() CompilerOpts

func NoCompilerOpts

func NoCompilerOpts() CompilerOpts

type DefineDec

type DefineDec struct {
	Pos    lexer.Position
	Name   string  `Define @Ident`
	Device string  `@Device`
	Value  *Number `| @@`
}

type Expr

type Expr struct {
	Pos lexer.Position

	Binary  *Binary  ` @@`
	Primary *Primary `| @@`
	Unary   *Unary   `| @@`
}

type FunBody

type FunBody struct {
	Pos lexer.Position

	Locals []*VarDec `(@@ ";")*`
	Stmts  *Stmts    `@@`
}

type FunDec

type FunDec struct {
	Pos lexer.Position

	ReturnType string       `@(Type | "void")`
	Name       string       `@Ident`
	Parameters []*Parameter `"(" ((@@ ("," @@)*) | "void") ")"`
	FunBody    *FunBody     `(";" | "{" @@ "}")`
}

type HashConst

type HashConst struct {
	Pos lexer.Position

	Arg string `"hash" "(" @QuotedStr ")"`
}

Special function types

type IfStmt

type IfStmt struct {
	Pos lexer.Position

	Condition *Expr `"if" "(" @@ ")"`
	Body      *Stmt `@@`
	Else      *Stmt `("else" @@)?`
}

type Number

type Number struct {
	Number float64 `@('-'? (Float | Int))`
}

Int | Float union type

type Parameter

type Parameter struct {
	Pos lexer.Position

	Scalar ScalarDec `@@`
}

type Primary

type Primary struct {
	Pos lexer.Position

	HashConst         *HashConst         `  @@`
	Device            string             `| @Device`
	BuiltinArity3Func *BuiltinArity3Func `| @@`
	BuiltinArity2Func *BuiltinArity2Func `| @@`
	BuiltinArity1Func *BuiltinArity1Func `| @@`
	BuiltinArity0Func *BuiltinArity0Func `| @@`
	CallFunc          *CallFunc          `| @@`
	Number            *Number            `| @@`
	Ident             string             `| @Ident`
	StringValue       string             "| @QuotedStr"
	SubExpression     *Expr              `| "(" @@ ")" `
}

type Program

type Program struct {
	Pos lexer.Position

	TopDec []*TopDec `@@*`
}

type ReturnStmt

type ReturnStmt struct {
	Pos lexer.Position

	Result *Expr `"return" @@?`
}

type ScalarDec

type ScalarDec struct {
	Pos lexer.Position

	Name string `Type @Ident`
}

type Stmt

type Stmt struct {
	Pos lexer.Position

	IfStmt     *IfStmt     `  @@`
	ReturnStmt *ReturnStmt `| @@`
	WhileStmt  *WhileStmt  `| @@`
	Assignment *Assignment `| @@`
	Expr       *Expr       `| @@`
	Block      *Stmts      `| "{" @@ "}"`
	Empty      bool        `| @";"`
}

type Stmts

type Stmts struct {
	Pos lexer.Position

	Stmts []*Stmt `@@*`
}

type TopDec

type TopDec struct {
	Pos lexer.Position

	FunDec    *FunDec    `  @@`
	DefineDec *DefineDec `| @@`
	VarDec    *VarDec    `| @@ ";"`
}

type Unary

type Unary struct {
	Pos lexer.Position

	Op  string   `@( "-" | "!" )`
	RHS *Primary `@@`
}

type VarDec

type VarDec struct {
	Pos lexer.Position

	ScalarDec ScalarDec `@@`
}

type WhileStmt

type WhileStmt struct {
	Pos lexer.Position

	Condition *Expr `"while" "(" @@ ")"`
	Body      *Stmt `@@`
}

Jump to

Keyboard shortcuts

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