Documentation ¶
Index ¶
- Constants
- Variables
- func AddJmpToReturnExpressions(exprs ReturnExpressions) []*CXExpression
- func AddPointer(fn *CXFunction, sym *CXArgument)
- func AffordanceStructs(pkg *CXPackage, currentFile string, lineNo int)
- func ArrayLiteralAssignment(to []*CXExpression, from []*CXExpression) []*CXExpression
- func ArrayLiteralExpression(arrSizes []int, typSpec int, exprs []*CXExpression) []*CXExpression
- func Assignment(to []*CXExpression, assignOp string, from []*CXExpression) []*CXExpression
- func AssociateReturnExpressions(idx int, retExprs []*CXExpression) []*CXExpression
- func BreakExpressions() []*CXExpression
- func CheckConcatStr(expr *CXExpression)
- func CheckRedeclared(symbols *[]map[string]*CXArgument, expr *CXExpression, sym *CXArgument)
- func CheckTypes(expr *CXExpression)
- func CheckUndValidTypes(expr *CXExpression)
- func ContinueExpressions() []*CXExpression
- func CopyArgFields(sym *CXArgument, arg *CXArgument)
- func DeclarationSpecifiers(declSpec *CXArgument, arrayLengths []int, opTyp int) *CXArgument
- func DeclarationSpecifiersBasic(typ int) *CXArgument
- func DeclarationSpecifiersStruct(ident string, pkgName string, isExternal bool, currentFile string, lineNo int) *CXArgument
- func DeclareGlobal(declarator *CXArgument, declarationSpecifiers *CXArgument, ...)
- func DeclareGlobalInPackage(pkg *CXPackage, declarator *CXArgument, declaration_specifiers *CXArgument, ...)
- func DeclareImport(name string, currentFile string, lineNo int)
- func DeclareLocal(declarator *CXArgument, declarationSpecifiers *CXArgument, ...) []*CXExpression
- func DeclarePackage(ident string)
- func DeclareStruct(ident string, strctFlds []*CXArgument)
- func DefineNewScope(exprs []*CXExpression)
- func FunctionAddParameters(fn *CXFunction, inputs, outputs []*CXArgument)
- func FunctionCall(exprs []*CXExpression, args []*CXExpression) []*CXExpression
- func FunctionDeclaration(fn *CXFunction, inputs, outputs []*CXArgument, exprs []*CXExpression)
- func FunctionHeader(ident string, receiver []*CXArgument, isMethod bool) *CXFunction
- func FunctionProcessParameters(symbols *[]map[string]*CXArgument, symbolsScope *map[string]bool, offset *int, ...)
- func GetGlobalSymbol(symbols *[]map[string]*CXArgument, symPkg *CXPackage, ident string)
- func GiveOffset(symbols *[]map[string]*CXArgument, sym *CXArgument, offset *int, ...)
- func IsAllArgsBasicTypes(expr *CXExpression) bool
- func IsArgBasicType(arg *CXArgument) bool
- func IsUndOp(fn *CXFunction) bool
- func IsUndOpBasicTypes(fn *CXFunction) bool
- func IsUndOpMimicInput(fn *CXFunction) bool
- func IterationExpressions(init []*CXExpression, cond []*CXExpression, incr []*CXExpression, ...) []*CXExpression
- func PostfixExpressionArray(prevExprs []*CXExpression, postExprs []*CXExpression) []*CXExpression
- func PostfixExpressionEmptyFunCall(prevExprs []*CXExpression) []*CXExpression
- func PostfixExpressionField(prevExprs []*CXExpression, ident string) []*CXExpression
- func PostfixExpressionFunCall(prevExprs []*CXExpression, args []*CXExpression) []*CXExpression
- func PostfixExpressionIncDec(prevExprs []*CXExpression, isInc bool) []*CXExpression
- func PostfixExpressionNative(typCode int, opStrCode string) []*CXExpression
- func PreFinalSize(finalSize *int, sym *CXArgument, arg *CXArgument)
- func PrimaryIdentifier(ident string) []*CXExpression
- func PrimaryStructLiteral(ident string, strctFlds []*CXExpression) []*CXExpression
- func PrimaryStructLiteralExternal(impName string, ident string, strctFlds []*CXExpression) []*CXExpression
- func ProcessExpressionArguments(symbols *[]map[string]*CXArgument, symbolsScope *map[string]bool, offset *int, ...)
- func ProcessGoTos(fn *CXFunction, exprs []*CXExpression)
- func ProcessLocalDeclaration(symbols *[]map[string]*CXArgument, symbolsScope *map[string]bool, ...)
- func ProcessMethodCall(expr *CXExpression, symbols *[]map[string]*CXArgument, offset *int, ...)
- func ProcessPointerStructs(expr *CXExpression)
- func ProcessReferenceAssignment(expr *CXExpression)
- func ProcessSlice(inp *CXArgument)
- func ProcessSliceAssignment(expr *CXExpression)
- func ProcessStringAssignment(expr *CXExpression)
- func ProcessSymbolFields(sym *CXArgument, arg *CXArgument)
- func ProcessTempVariable(expr *CXExpression)
- func ProcessUndExpression(expr *CXExpression)
- func SelectProgram(prgrm *CXProgram)
- func SelectionExpressions(condExprs []*CXExpression, thenExprs []*CXExpression, ...) []*CXExpression
- func SelectionStatement(predExprs []*CXExpression, thenExprs []*CXExpression, ...) []*CXExpression
- func Selector(ident string, selTyp int) string
- func SetCorrectArithmeticOp(expr *CXExpression)
- func SetFinalSize(symbols *[]map[string]*CXArgument, sym *CXArgument)
- func ShortAssignment(expr *CXExpression, to []*CXExpression, from []*CXExpression, pkg *CXPackage, ...) []*CXExpression
- func ShorthandExpression(leftExprs []*CXExpression, rightExprs []*CXExpression, op int) []*CXExpression
- func SliceLiteralExpression(typSpec int, exprs []*CXExpression) []*CXExpression
- func Stepping(steps int, delay int, withDelay bool)
- func StructLiteralAssignment(to []*CXExpression, from []*CXExpression) []*CXExpression
- func StructLiteralFields(ident string) *CXExpression
- func TotalLength(lengths []int) int
- func UnaryExpression(op string, prevExprs []*CXExpression) []*CXExpression
- func UndefinedTypeOperation(leftExprs []*CXExpression, rightExprs []*CXExpression, operator *CXFunction) (out []*CXExpression)
- func UpdateSymbolsTable(symbols *[]map[string]*CXArgument, sym *CXArgument, offset *int, ...)
- func UserHome() string
- func WritePrimary(typ int, byts []byte, isGlobal bool) []*CXExpression
- type ReturnExpressions
- type SelectStatement
Constants ¶
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
const ( // type of selector SELECT_TYP_PKG = iota SELECT_TYP_FUNC SELECT_TYP_STRCT )
const ( SEL_ELSEIF = iota SEL_ELSEIFELSE )
Variables ¶
var CurrentFile string
var DataOffset int = STACK_SIZE
var InFn bool = false
var dStack bool = false
var LineNo int
var PRGRM *CXProgram
var ReplTargetFn string = ""
var ReplTargetMod string = ""
var ReplTargetStrct string = ""
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 ArrayLiteralAssignment ¶
func ArrayLiteralAssignment(to []*CXExpression, from []*CXExpression) []*CXExpression
func ArrayLiteralExpression ¶
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 ¶
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 ¶
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 ¶
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 GetGlobalSymbol ¶
GetGlobalSymbol tries to retrieve `ident` from `symPkg`'s globals if `ident` is not found in the local scope.
func GiveOffset ¶
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 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 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 ProcessMethodCall ¶
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 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 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 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 ¶
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