actions

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: BSD-1-Clause Imports: 8 Imported by: 2

Documentation

Index

Constants

View Source
const (
	OP_EQUAL = iota
	OP_UNEQUAL

	OP_BITAND
	OP_BITXOR
	OP_BITOR
	OP_BITCLEAR

	OP_MUL
	OP_DIV
	OP_MOD
	OP_ADD
	OP_SUB
	OP_BITSHL
	OP_BITSHR
	OP_LT
	OP_GT
	OP_LTEQ
	OP_GTEQ
)

to decide what shorthand op to use

View Source
const (
	// type of selector
	SELECT_TYP_PKG = iota
	SELECT_TYP_FUNC
	SELECT_TYP_STRCT
)
View Source
const (
	SEL_ELSEIF = iota
	SEL_ELSEIFELSE
)

Variables

View Source
var CurrentFile string
View Source
var DataOffset int = STACK_SIZE
View Source
var InFn bool = false

var dStack bool = false

View Source
var LineNo int
View Source
var PRGRM *CXProgram
View Source
var ReplTargetFn string = ""
View Source
var ReplTargetMod string = ""
View Source
var ReplTargetStrct string = ""
View Source
var SysInitExprs []*CXExpression

Functions

func AddJmpToReturnExpressions

func AddJmpToReturnExpressions(exprs ReturnExpressions) []*CXExpression

AddJmpToReturnExpressions adds an jump expression that makes a function stop its execution

func AddPointer

func AddPointer(fn *CXFunction, sym *CXArgument)

AddPointer checks if `sym` or its last field, if a struct, behaves like a pointer (slice, pointer, string). If this is the case, `sym` is added to `fn.ListOfPointers` so the CX runtime does not have to determine this.

func AffordanceStructs

func AffordanceStructs(pkg *CXPackage, currentFile string, lineNo int)

func ArrayLiteralAssignment

func ArrayLiteralAssignment(to []*CXExpression, from []*CXExpression) []*CXExpression

func ArrayLiteralExpression

func ArrayLiteralExpression(arrSizes []int, typSpec int, exprs []*CXExpression) []*CXExpression

func Assignment

func Assignment(to []*CXExpression, assignOp string, from []*CXExpression) []*CXExpression

Assignment handles assignment statements with different operators, like =, :=, +=, *=.

func AssociateReturnExpressions

func AssociateReturnExpressions(idx int, retExprs []*CXExpression) []*CXExpression

AssociateReturnExpressions associates the output of `retExprs` to the `idx`th output parameter of the current function.

func BreakExpressions

func BreakExpressions() []*CXExpression

func CheckConcatStr

func CheckConcatStr(expr *CXExpression)

CheckConcatStr checks if `expr`'s operator is OP_UND_ADD and if its operands are of type str. If this is the case, the operator is changed to OP_STR_CONCAT to concatenate the strings.

func CheckRedeclared

func CheckRedeclared(symbols *[]map[string]*CXArgument, expr *CXExpression, sym *CXArgument)

CheckRedeclared checks if `expr` represents a variable declaration and then checks if an instance of that variable has already been declared.

func CheckTypes

func CheckTypes(expr *CXExpression)

func CheckUndValidTypes

func CheckUndValidTypes(expr *CXExpression)

CheckUndValidTypes checks if an expression with a generic operator (operators that accept `TYPE_UNDEFINED` arguments) is receiving arguments of valid types. For example, the expression `sa + sb` is not valid if they are struct instances.

func ContinueExpressions

func ContinueExpressions() []*CXExpression

func CopyArgFields

func CopyArgFields(sym *CXArgument, arg *CXArgument)

func DeclarationSpecifiers

func DeclarationSpecifiers(declSpec *CXArgument, arrayLengths []int, opTyp int) *CXArgument

DeclarationSpecifiers is called to build a type of a variable or parameter.

It is called repeatedly while the type is parsed.

declSpec:     The incoming type
arrayLengths: The lengths of the array if `opTyp` = DECL_ARRAY
opTyp:        The type of modification to `declSpec` (array of, pointer to, ...)

Returns the new type build from `declSpec` and `opTyp`.

func DeclarationSpecifiersBasic

func DeclarationSpecifiersBasic(typ int) *CXArgument

DeclarationSpecifiersBasic() returns a type specifier created from one of the builtin types.

func DeclarationSpecifiersStruct

func DeclarationSpecifiersStruct(ident string, pkgName string,
	isExternal bool, currentFile string, lineNo int) *CXArgument

DeclarationSpecifiersStruct() declares a struct

func DeclareGlobal

func DeclareGlobal(declarator *CXArgument, declarationSpecifiers *CXArgument,
	initializer []*CXExpression, doesInitialize bool)

DeclareGlobal creates a global variable in the current package.

If `doesInitialize` is true, then `initializer` is used to initialize the new variable. This function is a wrapper around DeclareGlobalInPackage() which does the real work.

FIXME: This function should be merged with DeclareGlobalInPackage.

Just use pkg=nil to indicate that CurrentPackage should be used.

func DeclareGlobalInPackage

func DeclareGlobalInPackage(pkg *CXPackage,
	declarator *CXArgument, declaration_specifiers *CXArgument,
	initializer []*CXExpression, doesInitialize bool)

DeclareGlobalInPackage creates a global variable in a specified package

If `doesInitialize` is true, then `initializer` is used to initialize the new variable.

func DeclareImport

func DeclareImport(name string, currentFile string, lineNo int)

DeclareImport()

func DeclareLocal

func DeclareLocal(declarator *CXArgument, declarationSpecifiers *CXArgument,
	initializer []*CXExpression, doesInitialize bool) []*CXExpression

DeclareLocal() creates a local variable inside a function. If `doesInitialize` is true, then `initializer` contains the initial values of the variable(s).

Returns a list of expressions that contains the initialization, if any.

func DeclarePackage

func DeclarePackage(ident string)

DeclarePackage() switches the current package in the program.

func DeclareStruct

func DeclareStruct(ident string, strctFlds []*CXArgument)

DeclareStruct takes a name of a struct and a slice of fields representing the members and adds the struct to the package.

func DefineNewScope

func DefineNewScope(exprs []*CXExpression)

DefineNewScope marks the first and last expressions to define the boundaries of a scope.

func FunctionAddParameters

func FunctionAddParameters(fn *CXFunction, inputs, outputs []*CXArgument)

func FunctionCall

func FunctionCall(exprs []*CXExpression, args []*CXExpression) []*CXExpression

func FunctionDeclaration

func FunctionDeclaration(fn *CXFunction, inputs, outputs []*CXArgument, exprs []*CXExpression)

func FunctionHeader

func FunctionHeader(ident string, receiver []*CXArgument, isMethod bool) *CXFunction

FunctionHeader takes a function name ('ident') and either creates the function if it's not known before or returns the already existing function if it is.

If the function is a method (isMethod = true), then it adds the object that it's called on as the first argument.

func FunctionProcessParameters

func FunctionProcessParameters(symbols *[]map[string]*CXArgument, symbolsScope *map[string]bool, offset *int, fn *CXFunction, params []*CXArgument)

func GetGlobalSymbol

func GetGlobalSymbol(symbols *[]map[string]*CXArgument, symPkg *CXPackage, ident string)

GetGlobalSymbol tries to retrieve `ident` from `symPkg`'s globals if `ident` is not found in the local scope.

func GiveOffset

func GiveOffset(symbols *[]map[string]*CXArgument, sym *CXArgument, offset *int, shouldExist bool)

func IsAllArgsBasicTypes

func IsAllArgsBasicTypes(expr *CXExpression) bool

IsAllArgsBasicTypes checks if all the input arguments in an expressions are of basic type.

func IsArgBasicType

func IsArgBasicType(arg *CXArgument) bool

IsArgBasicType returns true if `arg`'s type is a basic type, false otherwise.

func IsUndOp

func IsUndOp(fn *CXFunction) bool

IsUndOp returns true if the operator receives undefined types as input parameters.

func IsUndOpBasicTypes

func IsUndOpBasicTypes(fn *CXFunction) bool

IsUndOp returns true if the operator receives undefined types as input parameters and if it's an operator that only works with basic types. For example, `sa + sb` shouldn't work with struct instances.

func IsUndOpMimicInput

func IsUndOpMimicInput(fn *CXFunction) bool

IsUndOpMimicInput returns true if the operator receives undefined types as input parameters but also an operator that needs to mimic its input's type. For example, == should not return its input type, as it is always going to return a boolean.

func IterationExpressions

func IterationExpressions(init []*CXExpression, cond []*CXExpression, incr []*CXExpression, statements []*CXExpression) []*CXExpression

func PostfixExpressionArray

func PostfixExpressionArray(prevExprs []*CXExpression, postExprs []*CXExpression) []*CXExpression

PostfixExpressionArray...

func PostfixExpressionEmptyFunCall

func PostfixExpressionEmptyFunCall(prevExprs []*CXExpression) []*CXExpression

func PostfixExpressionField

func PostfixExpressionField(prevExprs []*CXExpression, ident string) []*CXExpression

PostfixExpressionField handles the dot notation that can follow an identifier. Examples are: `foo.bar`, `foo().bar`, `pkg.foo`

func PostfixExpressionFunCall

func PostfixExpressionFunCall(prevExprs []*CXExpression, args []*CXExpression) []*CXExpression

func PostfixExpressionIncDec

func PostfixExpressionIncDec(prevExprs []*CXExpression, isInc bool) []*CXExpression

func PostfixExpressionNative

func PostfixExpressionNative(typCode int, opStrCode string) []*CXExpression

func PreFinalSize

func PreFinalSize(finalSize *int, sym *CXArgument, arg *CXArgument)

func PrimaryIdentifier

func PrimaryIdentifier(ident string) []*CXExpression

func PrimaryStructLiteral

func PrimaryStructLiteral(ident string, strctFlds []*CXExpression) []*CXExpression

func PrimaryStructLiteralExternal

func PrimaryStructLiteralExternal(impName string, ident string, strctFlds []*CXExpression) []*CXExpression

func ProcessExpressionArguments

func ProcessExpressionArguments(symbols *[]map[string]*CXArgument, symbolsScope *map[string]bool, offset *int, fn *CXFunction, args []*CXArgument, expr *CXExpression, isInput bool)

ProcessExpressionArguments performs a series of checks and processes to an expresion's inputs and outputs. Some of these checks are: checking if a an input has not been declared, assign a relative offset to the argument, and calculate the correct size of the argument.

func ProcessGoTos

func ProcessGoTos(fn *CXFunction, exprs []*CXExpression)

func ProcessLocalDeclaration

func ProcessLocalDeclaration(symbols *[]map[string]*CXArgument, symbolsScope *map[string]bool, arg *CXArgument)

func ProcessMethodCall

func ProcessMethodCall(expr *CXExpression, symbols *[]map[string]*CXArgument, offset *int, shouldExist bool)

func ProcessPointerStructs

func ProcessPointerStructs(expr *CXExpression)

func ProcessReferenceAssignment

func ProcessReferenceAssignment(expr *CXExpression)

ProcessReferenceAssignment checks if the reference of a symbol can be assigned to the expression's output. For example: `var foo i32; var bar i32; bar = &foo` is not valid.

func ProcessSlice

func ProcessSlice(inp *CXArgument)

func ProcessSliceAssignment

func ProcessSliceAssignment(expr *CXExpression)

func ProcessStringAssignment

func ProcessStringAssignment(expr *CXExpression)

func ProcessSymbolFields

func ProcessSymbolFields(sym *CXArgument, arg *CXArgument)

func ProcessTempVariable

func ProcessTempVariable(expr *CXExpression)

func ProcessUndExpression

func ProcessUndExpression(expr *CXExpression)

func SelectProgram

func SelectProgram(prgrm *CXProgram)

func SelectionExpressions

func SelectionExpressions(condExprs []*CXExpression, thenExprs []*CXExpression, elseExprs []*CXExpression) []*CXExpression

func SelectionStatement

func SelectionStatement(predExprs []*CXExpression, thenExprs []*CXExpression, elseifExprs []SelectStatement, elseExprs []*CXExpression, op int) []*CXExpression

func Selector

func Selector(ident string, selTyp int) string

func SetCorrectArithmeticOp

func SetCorrectArithmeticOp(expr *CXExpression)

func SetFinalSize

func SetFinalSize(symbols *[]map[string]*CXArgument, sym *CXArgument)

func ShortAssignment

func ShortAssignment(expr *CXExpression, to []*CXExpression, from []*CXExpression, pkg *CXPackage, idx int) []*CXExpression

func ShorthandExpression

func ShorthandExpression(leftExprs []*CXExpression, rightExprs []*CXExpression, op int) []*CXExpression

func SliceLiteralExpression

func SliceLiteralExpression(typSpec int, exprs []*CXExpression) []*CXExpression

SliceLiteralExpression handles literal expressions by converting it to a series of `append` expressions.

func Stepping

func Stepping(steps int, delay int, withDelay bool)

func StructLiteralAssignment

func StructLiteralAssignment(to []*CXExpression, from []*CXExpression) []*CXExpression

StructLiteralAssignment handles struct literals, e.g. `Item{x: 10, y: 20}`, and references to struct literals, e.g. `&Item{x: 10, y: 20}` in assignment expressions.

func StructLiteralFields

func StructLiteralFields(ident string) *CXExpression

func TotalLength

func TotalLength(lengths []int) int

func UnaryExpression

func UnaryExpression(op string, prevExprs []*CXExpression) []*CXExpression

func UndefinedTypeOperation

func UndefinedTypeOperation(leftExprs []*CXExpression, rightExprs []*CXExpression, operator *CXFunction) (out []*CXExpression)

func UpdateSymbolsTable

func UpdateSymbolsTable(symbols *[]map[string]*CXArgument, sym *CXArgument, offset *int, shouldExist bool)

UpdateSymbolsTable adds `sym` to the innermost scope (last element of slice) in `symbols`.

func UserHome

func UserHome() string

UserHome returns the current user home path. Code taken from fiber-init.

func WritePrimary

func WritePrimary(typ int, byts []byte, isGlobal bool) []*CXExpression

This function writes those bytes to PRGRM.Data

Types

type ReturnExpressions

type ReturnExpressions struct {
	Size        int
	Expressions []*CXExpression
}

ReturnExpressions stores the `Size` of the return arguments represented by `Expressions`. For example: `return foo() + bar()` is a set of 3 expressions and they represent a single return argument

type SelectStatement

type SelectStatement struct {
	Condition []*CXExpression
	Then      []*CXExpression
	Else      []*CXExpression
}

used for selection_statement to layout its outputs

Jump to

Keyboard shortcuts

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