compiler

package
v0.0.0-...-4e5b205 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2020 License: GPL-3.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
const AssigneableRegisters = 4
View Source
const CalcTypeRegexAsm = `^asm\s*\{.*?\}$`
View Source
const CalcTypeRegexLiteral = `^((0(x|X))[0-9a-fA-F]+|\d+)$`

Careful here, we want to match base 10, 16, but not variables (e.g. 0xfAb = match, 0xno_u = no match, technically a variable [though it has a leading 0?])

View Source
const CalcTypeRegexMath = `^(?:\=\=|\!\=|\<\=|\>\=|\<\<|\>\>|\+|\-|\<|\>|\*|\/|\%|\(|\)|\s|,|\~|\||\&|\^|[a-zA-Z0-9_$\.])*$`
View Source
const FAULT_NO_RETURN = "0x0"
View Source
const LexerRegex = `(?s)(\s+)|` +
	`(?P<Int>(?:(?:0(x|X))[0-9a-fA-F]+|\d+))|` +
	`(?P<String>"(?:[^"\\]|\\.)*")|` +
	`(?P<Eval>\[.*?\])|` +
	`(?P<ASM>_asm\s*\{.*?\})|` +
	`(?P<IdentWithDot>(?:[a-zA-Z0-9_$]+\.)+[a-zA-Z0-9_$]+)|` +
	`(?P<Ident>[a-zA-Z_$][a-zA-Z0-9_$]*)|` +
	`(?P<AssignmentOperator>\+\=|\-\=|\*\=|\/\=|\%\=|\=)|` +
	`(?P<Operator>\=\=|\!\=|\<\=|\>\=|\<\<|\>\>|\+|\-|\<|\>|\*|\/|\%)|` +
	`(?P<RawToken>\S)`

Variables

This section is empty.

Functions

func Preprocess

func Preprocess(inputFile, outputFile string)

Types

type AST

type AST struct {
	TopExpressions []*TopExpression `{ @@ }`

	CommentHeaders []string
}

func GenerateAST

func GenerateAST(inputFile string) *AST

func (*AST) GenerateASM

func (ast *AST) GenerateASM(bootloader, verbose, optimizeDisable bool) string

type Assignment

type Assignment struct {
	Pos lexer.Position

	Name     string        `@(IdentWithDot|Ident)`
	Operator string        `@AssignmentOperator`
	Value    *RuntimeValue `@@`
}

type Conditional

type Conditional struct {
	Pos lexer.Position

	Condition string        `"if" @Eval`
	BodyIf    []*Expression `"{" { @@ } "}"`
	BodyElse  []*Expression `["else" "{" { @@ } "}"]`
}

type Expression

type Expression struct {
	Pos lexer.Position

	Assignment   *Assignment   `(( @@`
	FunctionCall *FunctionCall `| @@`
	Variable     *Variable     `| @@`
	Return       *RuntimeValue `| "return" @@) ";")`

	WhileLoop *WhileLoop `| @@`
	//	ForLoop     *ForLoop     `| @@`
	IfCondition *Conditional `| @@`
	Asm         *string      `| @ASM`
}

type Function

type Function struct {
	Pos lexer.Position

	Inline     bool                 `"func" [@"inline"]`
	Type       string               `@Ident`
	Name       string               `@Ident`
	Parameters []*FunctionParameter `"(" { @@ [","] } ")"`
	Body       []*Expression        `"{" { @@ } "}"`
}

type FunctionCall

type FunctionCall struct {
	Pos lexer.Position

	FunctionName string          `@Ident`
	Parameters   []*RuntimeValue `"(" { @@ [","] } ")"`
}

type FunctionParameter

type FunctionParameter struct {
	Pos lexer.Position

	Type string `@Ident`
	Name string `@Ident`
}

type Global

type Global struct {
	Pos lexer.Position

	Type  string `"global" @Ident`
	Name  string `@Ident`
	Value *Value `["=" @@]`
}

type RVFunctionCall

type RVFunctionCall struct {
	Pos lexer.Position

	FunctionName string          `@Ident`
	Parameters   []*RuntimeValue `"(" { @@ [","] } ")"`
}

type RuntimeValue

type RuntimeValue struct {
	Pos lexer.Position

	FunctionCall *RVFunctionCall `  @@`
	Eval         *string         `| @Eval`
	Number       *int            `| @Int`
	Variable     *string         `| @(IdentWithDot|Ident)`
}

type Struct

type Struct struct {
	Pos lexer.Position

	Name    string          `"struct" @Ident`
	Members []*StructMember `"{" { @@ } "}"`
}

type StructMember

type StructMember struct {
	Pos lexer.Position

	Type string `@Ident`
	Name string `@Ident ";"`
}

type TopExpression

type TopExpression struct {
	Pos lexer.Position

	Function *Function `@@`
	Struct   *Struct   `| @@`
	Global   *Global   `| @@ ";"`
	View     *View     `| @@ ";"`
}

type Value

type Value struct {
	Pos lexer.Position

	Text   *string `  @String`
	Number *int    `| @Int`
}

type Variable

type Variable struct {
	Pos lexer.Position

	Type  string        `@Ident`
	Name  string        `@Ident`
	Value *RuntimeValue `["=" @@]`
}

type View

type View struct {
	Pos lexer.Position

	Name    string `"view" @Ident`
	Address int    `"@"@Int`
}

type WhileLoop

type WhileLoop struct {
	Pos lexer.Position

	Condition string        `"while" @Eval`
	Body      []*Expression `"{" { @@ } "}"`
}

type YardToken

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

Jump to

Keyboard shortcuts

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