Documentation ¶
Index ¶
- func CreateBinaryOp(intstr, fltstr string, blk *ir.BasicBlock, t types.Type, ...) value.Value
- func DumpTree(in <-chan Node, useJSON bool) <-chan Node
- func MangleFunctionName(origName string, argTypes ...types.Type) string
- func Parse(tokens chan lexer.Token) <-chan Node
- func UnescapeString(str string) []byte
- func UnmangleFunctionName(mangled string) string
- type BinaryNode
- type BlockNode
- type CastNode
- type CharNode
- type ClassNode
- type CompileTarget
- type Compiler
- type DependencyNode
- type FloatNode
- type ForNode
- type FunctionCallNode
- type FunctionNode
- func (n FunctionNode) Arguments(scope *Scope) ([]*types.Param, []types.Type)
- func (n FunctionNode) Codegen(scope *Scope, c *Compiler) value.Value
- func (n FunctionNode) Declare(scope *Scope, c *Compiler) *ir.Function
- func (n FunctionNode) InferType(scope *Scope) types.Type
- func (n FunctionNode) MangledName(scope *Scope, c *Compiler) string
- func (n FunctionNode) NameString() string
- type FunctionScopeItem
- type GeodeBinaryInstr
- func (inst *GeodeBinaryInstr) GetName() string
- func (inst *GeodeBinaryInstr) GetParent() *ir.BasicBlock
- func (inst *GeodeBinaryInstr) Ident() string
- func (inst *GeodeBinaryInstr) SetName(name string)
- func (inst *GeodeBinaryInstr) SetParent(parent *ir.BasicBlock)
- func (inst *GeodeBinaryInstr) String() string
- func (inst *GeodeBinaryInstr) Type() types.Type
- type GeodeTypeRef
- type IfNode
- type IntNode
- type LLVMIdent
- func (inst *LLVMIdent) GetName() string
- func (inst *LLVMIdent) GetParent() *ir.BasicBlock
- func (inst *LLVMIdent) Ident() string
- func (inst *LLVMIdent) SetName(name string)
- func (inst *LLVMIdent) SetParent(parent *ir.BasicBlock)
- func (inst *LLVMIdent) String() string
- func (inst *LLVMIdent) Type() types.Type
- type Linker
- type NamespaceNode
- type Node
- type NodeType
- type Package
- func (p *Package) AddClinkage(libPath string)
- func (p *Package) AddDepPackage(pkg *Package)
- func (p *Package) Compile() chan *Package
- func (p *Package) Emit(buildDir string) string
- func (p *Package) Hash() []byte
- func (p *Package) Inject(c *Package)
- func (p *Package) InjectExternalFunction(from *Package, fn *ir.Function)
- func (p *Package) LoadDep(depPath string) *Package
- func (p *Package) Parse() chan *Package
- func (p *Package) String() string
- type Parser
- type ReferenceType
- type ReturnNode
- type Scope
- type ScopeItem
- type ScopeItemType
- type StringNode
- type TypeDef
- type UnaryNode
- type VariableNode
- type VariableScopeItem
- type Visibility
- type WhileNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateBinaryOp ¶
func CreateBinaryOp(intstr, fltstr string, blk *ir.BasicBlock, t types.Type, left, right value.Value) value.Value
CreateBinaryOp produces a geode binary op (just a wrapper around llir/llvm's binary instructions)
func DumpTree ¶
DumpTree takes a channel of nodes and prints all Nodes it recieves, then pushes them back out a new channel it makes and returns
func MangleFunctionName ¶
MangleFunctionName will mangle a function name like how cpp does :)
func Parse ¶
Parse creates and runs a new lexer, that returns the chan that the nodes will be passed through with
func UnescapeString ¶
UnescapeString UTF-8 string e.g. convert "\u0e27\u0e23\u0e0d\u0e32" to "วรญา"
func UnmangleFunctionName ¶
UnmangleFunctionName takes some mangled name and returns the unmangled one
Types ¶
type BinaryNode ¶ added in v0.0.7
BinaryNode is a binary operation representation
func (BinaryNode) Codegen ¶ added in v0.0.7
func (n BinaryNode) Codegen(scope *Scope, c *Compiler) value.Value
Codegen implements Node.Codegen for BinaryNode
func (BinaryNode) InferType ¶ added in v0.0.7
func (n BinaryNode) InferType(scope *Scope) types.Type
InferType implements Node.InferType
func (BinaryNode) NameString ¶ added in v0.0.7
func (n BinaryNode) NameString() string
NameString implements Node.NameString
type BlockNode ¶ added in v0.0.7
BlockNode is a block statement. A block statement is just an array of Nodes that run in sequence.
func (BlockNode) NameString ¶ added in v0.0.7
NameString implements Node.NameString
type CastNode ¶ added in v0.0.7
CastNode is a type cast "function" call. TODO: Replace this with normal function calls and check in the function call codegen function
func (CastNode) NameString ¶ added in v0.0.7
NameString implements Node.NameString
type CharNode ¶ added in v0.0.7
CharNode is a char literal TODO: get parsing working for this.
func (CharNode) NameString ¶ added in v0.0.7
NameString implements Node.NameString
type ClassNode ¶ added in v0.0.7
type ClassNode struct { NodeType Name string Methods []FunctionNode Variables []VariableNode }
ClassNode -
func (ClassNode) NameString ¶ added in v0.0.7
NameString implements Node.NameString
type CompileTarget ¶
type CompileTarget int
CompileTarget is a target to build a binary for
const ( ASMTarget CompileTarget = iota BinaryTarget )
Some default targets
type Compiler ¶
type Compiler struct { Name string // A reference to the scope in the package for easier access Scope *Scope Package *Package Module *ir.Module FN *ir.Function // current funciton being compiled // contains filtered or unexported fields }
Compiler contains all information to compile a program from nodes to llvm ir
func NewCompiler ¶
NewCompiler returns a pointer to a new Compiler object.
func (*Compiler) FunctionDefined ¶
FunctionDefined returns whether or not a function with a name has been defined in the module's scope
type DependencyNode ¶ added in v0.0.7
DependencyNode is a way of representing the need to include a dependency or multiple dependencies. It also works to link a c program as well. Paths contains a list of paths to the dependencies that the user entered into the statement. These paths are not resolved and may not contain a geode source file.
Example:
Paths = ["std:io"] CLinkage = false
/
func (DependencyNode) Codegen ¶ added in v0.0.7
func (n DependencyNode) Codegen(scope *Scope, c *Compiler) value.Value
Codegen implements Node.Codegen for DependencyNode
func (DependencyNode) Handle ¶ added in v0.0.7
func (n DependencyNode) Handle(c *Compiler) value.Value
Handle will do ast-level handling for a dependency node
func (DependencyNode) InferType ¶ added in v0.0.7
func (n DependencyNode) InferType(scope *Scope) types.Type
InferType implements Node.InferType
func (DependencyNode) NameString ¶ added in v0.0.7
func (n DependencyNode) NameString() string
NameString implements Node.NameString
type FloatNode ¶ added in v0.0.7
FloatNode is a float literla
func (FloatNode) NameString ¶ added in v0.0.7
NameString implements Node.NameString
type ForNode ¶ added in v0.0.7
ForNode is a for loop structure representation
func (ForNode) NameString ¶ added in v0.0.7
NameString implements Node.NameString
type FunctionCallNode ¶ added in v0.0.7
FunctionCallNode is a function call, example: `foo(a, b, c)`. This would be:
Name = "foo" Args = [a, b, c] <- these are Node references
func (FunctionCallNode) Codegen ¶ added in v0.0.7
func (n FunctionCallNode) Codegen(scope *Scope, c *Compiler) value.Value
Codegen implements Node.Codegen for FunctionCallNode
func (FunctionCallNode) InferType ¶ added in v0.0.7
func (n FunctionCallNode) InferType(scope *Scope) types.Type
InferType implements Node.InferType
func (FunctionCallNode) NameString ¶ added in v0.0.7
func (n FunctionCallNode) NameString() string
NameString implements Node.NameString
type FunctionNode ¶ added in v0.0.7
type FunctionNode struct { NodeType Name string Args []VariableNode Body BlockNode External bool Variadic bool Nomangle bool ReturnType GeodeTypeRef }
FunctionNode is the representation of some function. It has methods on it to declare the function as well as codegen. A function has a list of VariableNodes for arguments and a single block for a body, all of which are codegenned.
func (FunctionNode) Codegen ¶ added in v0.0.7
func (n FunctionNode) Codegen(scope *Scope, c *Compiler) value.Value
Codegen implements Node.Codegen for FunctionNode
func (FunctionNode) Declare ¶ added in v0.0.7
func (n FunctionNode) Declare(scope *Scope, c *Compiler) *ir.Function
Declare declares some FunctionNode's sig
func (FunctionNode) InferType ¶ added in v0.0.7
func (n FunctionNode) InferType(scope *Scope) types.Type
InferType implements Node.InferType
func (FunctionNode) MangledName ¶ added in v0.0.7
func (n FunctionNode) MangledName(scope *Scope, c *Compiler) string
MangledName will return the mangled name for a function node
func (FunctionNode) NameString ¶ added in v0.0.7
func (n FunctionNode) NameString() string
NameString implements Node.NameString
type FunctionScopeItem ¶
type FunctionScopeItem struct {
// contains filtered or unexported fields
}
FunctionScopeItem implements ScopeItem. This is used so we can store functions in the scope (mainly in the root scope)
func NewFunctionScopeItem ¶
func NewFunctionScopeItem(name string, function *ir.Function, vis Visibility) FunctionScopeItem
NewFunctionScopeItem constructs a function scope item
func (FunctionScopeItem) Mangled ¶
func (item FunctionScopeItem) Mangled() bool
Mangled implements ScopeItem.Mangled()
func (FunctionScopeItem) Name ¶
func (item FunctionScopeItem) Name() string
Name implements ScopeItem.Name()
func (FunctionScopeItem) SetMangled ¶
func (item FunctionScopeItem) SetMangled(m bool)
SetMangled implements ScopeItem.SetMangled()
func (FunctionScopeItem) Type ¶
func (item FunctionScopeItem) Type() ScopeItemType
Type implements ScopeItem.Type()
func (FunctionScopeItem) Value ¶
func (item FunctionScopeItem) Value() value.Value
Value implements ScopeItem.Value()
func (FunctionScopeItem) Visibility ¶
func (item FunctionScopeItem) Visibility() Visibility
Visibility implements ScopeItem.Visibility()
type GeodeBinaryInstr ¶
type GeodeBinaryInstr struct { // Parent basic block. Parent *ir.BasicBlock // Name of the local variable associated with the instruction. Name string // Operator string. Operator string // Operands. X, Y value.Value // Map from metadata identifier (e.g. !dbg) to metadata associated with the // instruction. Metadata map[string]*metadata.Metadata }
GeodeBinaryInstr implements ir.Instruction This will be easier than doing individual work per operation
func NewGeodeBinaryInstr ¶
func NewGeodeBinaryInstr(op string, x, y value.Value) *GeodeBinaryInstr
NewGeodeBinaryInstr returns a new geode binary instruction
func (*GeodeBinaryInstr) GetName ¶
func (inst *GeodeBinaryInstr) GetName() string
GetName returns the name of the local variable associated with the instruction.
func (*GeodeBinaryInstr) GetParent ¶
func (inst *GeodeBinaryInstr) GetParent() *ir.BasicBlock
GetParent returns the parent basic block of the instruction.
func (*GeodeBinaryInstr) Ident ¶
func (inst *GeodeBinaryInstr) Ident() string
Ident returns the identifier associated with the instruction.
func (*GeodeBinaryInstr) SetName ¶
func (inst *GeodeBinaryInstr) SetName(name string)
SetName sets the name of the local variable associated with the instruction.
func (*GeodeBinaryInstr) SetParent ¶
func (inst *GeodeBinaryInstr) SetParent(parent *ir.BasicBlock)
SetParent sets the parent basic block of the instruction.
func (*GeodeBinaryInstr) String ¶
func (inst *GeodeBinaryInstr) String() string
String returns the LLVM syntax representation of the instruction.
func (*GeodeBinaryInstr) Type ¶
func (inst *GeodeBinaryInstr) Type() types.Type
Type returns the type of the instruction.
type GeodeTypeRef ¶
GeodeTypeRef -
func (GeodeTypeRef) BuildPointerType ¶
func (r GeodeTypeRef) BuildPointerType(t types.Type) types.Type
BuildPointerType will take some type and apply a level of nested pointers
type IfNode ¶ added in v0.0.7
IfNode is an if statement representation
func (IfNode) NameString ¶ added in v0.0.7
NameString implements Node.NameString
type IntNode ¶ added in v0.0.7
IntNode is an integer literal
func (IntNode) NameString ¶ added in v0.0.7
NameString implements Node.NameString
type LLVMIdent ¶ added in v0.0.7
type LLVMIdent struct { // Parent basic block. Parent *ir.BasicBlock // Map from metadata identifier (e.g. !dbg) to metadata associated with the // instruction. Metadata map[string]*metadata.Metadata // contains filtered or unexported fields }
LLVMIdent implements ir.Instruction This will be easier than doing individual work per operation
func NewLLVMIdent ¶ added in v0.0.7
NewLLVMIdent returns a new geode binary instruction
func (*LLVMIdent) GetName ¶ added in v0.0.7
GetName returns the name of the local variable associated with the instruction.
func (*LLVMIdent) GetParent ¶ added in v0.0.7
func (inst *LLVMIdent) GetParent() *ir.BasicBlock
GetParent returns the parent basic block of the instruction.
func (*LLVMIdent) Ident ¶ added in v0.0.7
Ident returns the identifier associated with the instruction.
func (*LLVMIdent) SetName ¶ added in v0.0.7
SetName sets the name of the local variable associated with the instruction.
func (*LLVMIdent) SetParent ¶ added in v0.0.7
func (inst *LLVMIdent) SetParent(parent *ir.BasicBlock)
SetParent sets the parent basic block of the instruction.
type Linker ¶
type Linker struct {
// contains filtered or unexported fields
}
Linker is an instance that can link several object files into a single binary or other format
func (*Linker) Run ¶
func (l *Linker) Run()
Run a list of objects through a linker and build into a single outfile with the given target
func (*Linker) SetTarget ¶
func (l *Linker) SetTarget(t CompileTarget)
SetTarget sets the target output format of the linker be it binary, asm, etc...
type NamespaceNode ¶ added in v0.0.7
NamespaceNode -
func (NamespaceNode) Codegen ¶ added in v0.0.7
func (n NamespaceNode) Codegen(scope *Scope, c *Compiler) value.Value
Codegen returns some NamespaceNode's arguments
func (NamespaceNode) InferType ¶ added in v0.0.7
func (n NamespaceNode) InferType(scope *Scope) types.Type
InferType implements Node.InferType
func (NamespaceNode) NameString ¶ added in v0.0.7
func (n NamespaceNode) NameString() string
NameString implements Node.NameString
type Node ¶
type Node interface { Kind() NodeType NameString() string Codegen(*Scope, *Compiler) value.Value InferType(scope *Scope) types.Type }
Node -
func QuickParseExpression ¶ added in v0.0.7
QuickParseExpression takes a stream of tokens and lexes them into a single node
func QuickParseFunction ¶ added in v0.0.7
QuickParseFunction takes a stream of tokens and lexes them into a single node
func QuickParseIdentifier ¶ added in v0.0.7
QuickParseIdentifier takes a stream of tokens and lexes them into a single node
type Package ¶
type Package struct { fmt.Stringer Name string Source *lexer.Sourcefile Nodes []Node Dependencies []*Package Scope *Scope Compiler *Compiler IsRuntime bool Compiled bool CLinkages []string NamespaceName string // contains filtered or unexported fields }
Package is a wrapper around a module. It is able to compile and emit code, as well as lex and parse it.
var RuntimePackage *Package
RuntimePackage is the global runtime package
func NewPackage ¶
func NewPackage(name string, source *lexer.Sourcefile) *Package
NewPackage returns a pointer to a new package
func (*Package) AddClinkage ¶ added in v0.0.7
AddClinkage - takes an absolute path to a c file, and adds it to the link list
func (*Package) AddDepPackage ¶ added in v0.0.7
AddDepPackage appends a dependency from a pacakge
func (*Package) Inject ¶
Inject another Package's defintions into this Package This is how external dependencies work
func (*Package) InjectExternalFunction ¶
InjectExternalFunction injects the function without the body, just the sig
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser -
func NewQuickParser ¶ added in v0.0.7
NewQuickParser is used to lex and build a parser from tokens quickly for small lexing tasks
type ReferenceType ¶
type ReferenceType int
ReferenceType is how we go about accessing a variable. Do we just want the value, or do we want to assign to it
const ( ReferenceDefine ReferenceType = iota ReferenceAssign ReferenceAccessValue ReferenceAccessStackAddress ReferenceDereference )
The different ways you can access a VariableNode
type ReturnNode ¶ added in v0.0.7
ReturnNode is how functions return values from any block A return node contains the value (another Node) that will be codegenned and used in a `NewRet()` call on the parent function
func (ReturnNode) Codegen ¶ added in v0.0.7
func (n ReturnNode) Codegen(scope *Scope, c *Compiler) value.Value
Codegen implements Node.Codegen for ReturnNode
func (ReturnNode) InferType ¶ added in v0.0.7
func (n ReturnNode) InferType(scope *Scope) types.Type
InferType implements Node.InferType
func (ReturnNode) NameString ¶ added in v0.0.7
func (n ReturnNode) NameString() string
NameString implements Node.NameString
type Scope ¶
Scope trees represent block scoping by having a root scope and children scopes that point back to their parent scope.
func NewScope ¶
func NewScope() *Scope
NewScope creates a scope (for use when generating root scopes)
func (*Scope) FindFunctions ¶
func (s *Scope) FindFunctions(needle string) []FunctionScopeItem
FindFunctions returns a list of functions that might match the name provided The needle can be any of the following: bare name, mangled name
func (*Scope) InjectPrimitives ¶ added in v0.0.7
func (s *Scope) InjectPrimitives()
InjectPrimitives injects primitve types like int, byte, etc
func (*Scope) SpawnChild ¶
SpawnChild takes a parent scope and creates a new variable scope for scoped variable access.
type ScopeItem ¶
type ScopeItem interface { Type() ScopeItemType Value() value.Value // an llvm value Visibility() Visibility Name() string Mangled() bool SetMangled(m bool) }
ScopeItem is what the scope contains.ScopeItem When you set a value in the scope, you must wrap it in a struct implementing ScopeItem
type ScopeItemType ¶
type ScopeItemType int
ScopeItemType -
const ( ScopeItemFunctionType ScopeItemType = iota ScopeItemVariableType ScopeItemTypeType )
The ScopeItemTypes available
type StringNode ¶ added in v0.0.7
StringNode is a string literal
func (StringNode) Codegen ¶ added in v0.0.7
func (n StringNode) Codegen(scope *Scope, c *Compiler) value.Value
Codegen implements Node.Codegen for StringNode
func (StringNode) InferType ¶ added in v0.0.7
func (n StringNode) InferType(scope *Scope) types.Type
InferType implements Node.InferType
func (StringNode) NameString ¶ added in v0.0.7
func (n StringNode) NameString() string
NameString implements Node.NameString
type TypeDef ¶ added in v0.0.7
TypeDef is a storage for types in the scope. They are stored seperately from variables.
func NewTypeDef ¶ added in v0.0.7
NewTypeDef constructs a function scope item
func (*TypeDef) InjectInto ¶ added in v0.0.7
InjectInto will inject the type into a given scope
type UnaryNode ¶ added in v0.0.7
UnaryNode is a unary operation representation. Example:
- !a
- &value
func (UnaryNode) NameString ¶ added in v0.0.7
NameString implements Node.NameString
type VariableNode ¶ added in v0.0.7
type VariableNode struct { NodeType Type GeodeTypeRef HasValue bool Name string IsPointer bool RefType ReferenceType IndexExpr Node IsArray bool Reassignment bool Body Node }
VariableNode is a generic variable statement representation this contains a reference type inside it that tellst the code generator what kind of variable statement to build
func (VariableNode) Codegen ¶ added in v0.0.7
func (n VariableNode) Codegen(scope *Scope, c *Compiler) value.Value
Codegen implements Node.Codegen for VariableNode
func (VariableNode) InferType ¶ added in v0.0.7
func (n VariableNode) InferType(scope *Scope) types.Type
InferType implements Node.InferType
func (VariableNode) NameString ¶ added in v0.0.7
func (n VariableNode) NameString() string
NameString implements Node.NameString
type VariableScopeItem ¶
type VariableScopeItem struct {
// contains filtered or unexported fields
}
VariableScopeItem implements ScopeItem. This is used so we can store functions in the scope (mainly in the root scope)
func NewVariableScopeItem ¶
func NewVariableScopeItem(name string, value value.Value, vis Visibility) VariableScopeItem
NewVariableScopeItem constructs a function scope item
func (VariableScopeItem) Mangled ¶
func (item VariableScopeItem) Mangled() bool
Mangled implements ScopeItem.Mangled()
func (VariableScopeItem) Name ¶
func (item VariableScopeItem) Name() string
Name implements ScopeItem.Name()
func (VariableScopeItem) SetMangled ¶
func (item VariableScopeItem) SetMangled(m bool)
SetMangled implements ScopeItem.SetMangled()
func (VariableScopeItem) Type ¶
func (item VariableScopeItem) Type() ScopeItemType
Type implements ScopeItem.Type()
func (VariableScopeItem) Value ¶
func (item VariableScopeItem) Value() value.Value
Value implements ScopeItem.Value()
func (VariableScopeItem) Visibility ¶
func (item VariableScopeItem) Visibility() Visibility
Visibility implements ScopeItem.Visibility()
type Visibility ¶
type Visibility int
Visibility is the access modifier of some scope variable.
const ( PublicVisibility Visibility = iota PrivateVisibility )
Visibility options for scope items
type WhileNode ¶ added in v0.0.7
WhileNode is a while loop representationvbnm,bvbnm
func (WhileNode) NameString ¶ added in v0.0.7
NameString implements Node.NameString
Source Files ¶
- AST.go
- BlockNode.go
- ClassNode.go
- Compiler.go
- FunctionNode.go
- GeodeBinaryOp.go
- LLVMIdent.go
- Linker.go
- Mangle.go
- Nodes.go
- Package.go
- Scope.go
- VariableNode.go
- codegen.go
- parseBinaryOpRHS.go
- parseBlockStmt.go
- parseClassDefn.go
- parseDependencyStmt.go
- parseExpression.go
- parseFnDefn.go
- parseForStmt.go
- parseIdentifierExpr.go
- parseIfStmt.go
- parseIndexExpr.go
- parseName.go
- parseNamespace.go
- parseNumericExpr.go
- parseParenExpr.go
- parsePrimary.go
- parseReturnStmt.go
- parseStringExpr.go
- parseType.go
- parseTypeCast.go
- parseUnary.go
- parseVariableDefn.go
- parseWhileStmt.go