Documentation ¶
Overview ¶
Package ast defines the types for kl source files trees.
Index ¶
- Constants
- func ElementTypeOf(value Value) token.Token
- func IsValueArray(value Value) bool
- func IsValueComposite(value Value) bool
- func IsValueScalar(value Value) bool
- type Comment
- type Condition
- type Error
- type FileExtension
- type GlobalTag
- type LabelTag
- type Location
- type Param
- type Position
- type Stmt
- type StmtAsm
- type StmtAssign
- type StmtAssignDiv
- type StmtAssignGlobal
- type StmtAssignGlobalByIndex
- type StmtAssignGlobalByVar
- type StmtAssignMem
- type StmtAssignMinMax
- type StmtBuiltinAssert
- type StmtBuiltinExit
- type StmtBuiltinPanic
- type StmtBuiltinPop
- type StmtBuiltinPrint
- type StmtBuiltinPush
- type StmtBuiltinPushValue
- type StmtBuiltinSyscall
- type StmtCall
- type StmtComment
- type StmtEOF
- type StmtElse
- type StmtEndFor
- type StmtEndIf
- type StmtEndSwitch
- type StmtEndWhile
- type StmtFor
- type StmtGlobal
- type StmtGoto
- type StmtIf
- type StmtImport
- type StmtLabel
- type StmtLabelCallable
- type StmtNewline
- type StmtNoop
- type StmtReturn
- type StmtSwitch
- type StmtSwitchCase
- type StmtSwitchCaseDefault
- type StmtVarDec
- type StmtVarInc
- type StmtWhile
- type Symbol
- type Value
- type ValueEmbedEnv
- type ValueEmbedFile
- type ValueFormat
- type ValueFromGlobal
- type ValueFromGlobalArrayByIndex
- type ValueFromGlobalArrayByIndexLen
- type ValueFromGlobalArrayByVar
- type ValueFromGlobalArrayByVarLen
- type ValueLen
- type ValueLoad
- type ValueSigned
- type ValueSignedArray
- type ValueSize
- type ValueStore
- type ValueString
- type ValueStringArray
- type ValueUnsigned
- type ValueUnsignedArray
- type ValueVar
- type ValueVarByIndex
- type ValueVarByVar
- type ValueVarLen
- type ValueVarSize
Constants ¶
const ( SourceExt FileExtension = ".kl" TestExt FileExtension = ".klt" PackageFile = "kl.pkg" // TestingPkg is the name of the package used when writing tests, // to access the content of the tested package. TestingPkg = "testing" // BuiltinsFilesGlobal is the name for the kl global that holds the files // making up a package. It is inserted by Sema. BuiltinsFilesGlobal = "builtins_files" BuiltinsStackStartGlobal = "builtins_stack_start" InternPackageTag = "kl_intern_strings" )
Variables ¶
This section is empty.
Functions ¶
func ElementTypeOf ¶
func IsValueArray ¶
func IsValueComposite ¶
A composite is one of: ValueUnsignedArray, ValueSignedArray, ValueStringArray, ValueEmbed, ValueString
func IsValueScalar ¶
Types ¶
type Condition ¶
It is garanteed that Left or Right has a valid type. If both have a type, they have the same one.
type FileExtension ¶
type FileExtension string
type StmtAsm ¶
StmtAsm allows inserting assembly code as is. TODO dependent on the backend and platform
func (StmtAsm) TrailingComment ¶
type StmtAssign ¶
type StmtAssign struct { Location Comment Comment Var token.Token Op token.Token Value Value // !IsValueArray() }
Assign a literal to a variable. e.g. r2 = 10u16
func (StmtAssign) String ¶
func (st StmtAssign) String() string
func (StmtAssign) TrailingComment ¶
func (s StmtAssign) TrailingComment() Comment
type StmtAssignDiv ¶
type StmtAssignDiv struct { Location Comment Comment Quotient token.Token Remainder token.Token Value Value }
func (StmtAssignDiv) String ¶
func (st StmtAssignDiv) String() string
func (StmtAssignDiv) TrailingComment ¶
func (s StmtAssignDiv) TrailingComment() Comment
type StmtAssignGlobal ¶
Assign a literal to a global declaration (non array). e.g. @x = 10u16
func (StmtAssignGlobal) String ¶
func (st StmtAssignGlobal) String() string
func (StmtAssignGlobal) TrailingComment ¶
func (s StmtAssignGlobal) TrailingComment() Comment
type StmtAssignGlobalByIndex ¶
type StmtAssignGlobalByIndex struct { Location Comment Comment Symbol Symbol Index uint64 Value Value }
Assign a literal to a global declaration. e.g. @x[2] = 10u16
func (StmtAssignGlobalByIndex) String ¶
func (st StmtAssignGlobalByIndex) String() string
func (StmtAssignGlobalByIndex) TrailingComment ¶
func (s StmtAssignGlobalByIndex) TrailingComment() Comment
type StmtAssignGlobalByVar ¶
type StmtAssignGlobalByVar struct { Location Comment Comment Symbol Symbol Var token.Token Value Value }
Assign a variable to a global declaration. e.g. @x[r2] = r0
func (StmtAssignGlobalByVar) String ¶
func (st StmtAssignGlobalByVar) String() string
func (StmtAssignGlobalByVar) TrailingComment ¶
func (s StmtAssignGlobalByVar) TrailingComment() Comment
type StmtAssignMem ¶
Assign a literal to a variable. e.g. *r2 = 10 u16
func (StmtAssignMem) String ¶
func (st StmtAssignMem) String() string
func (StmtAssignMem) TrailingComment ¶
func (s StmtAssignMem) TrailingComment() Comment
type StmtAssignMinMax ¶
type StmtAssignMinMax struct { Location Comment Comment Var token.Token Op token.Token V1 Value V2 Value }
func (StmtAssignMinMax) String ¶
func (st StmtAssignMinMax) String() string
func (StmtAssignMinMax) TrailingComment ¶
func (s StmtAssignMinMax) TrailingComment() Comment
type StmtBuiltinAssert ¶
func (StmtBuiltinAssert) String ¶
func (st StmtBuiltinAssert) String() string
func (StmtBuiltinAssert) TrailingComment ¶
func (s StmtBuiltinAssert) TrailingComment() Comment
type StmtBuiltinExit ¶
func (StmtBuiltinExit) String ¶
func (st StmtBuiltinExit) String() string
func (StmtBuiltinExit) TrailingComment ¶
func (s StmtBuiltinExit) TrailingComment() Comment
type StmtBuiltinPanic ¶
func (StmtBuiltinPanic) String ¶
func (st StmtBuiltinPanic) String() string
func (StmtBuiltinPanic) TrailingComment ¶
func (s StmtBuiltinPanic) TrailingComment() Comment
type StmtBuiltinPop ¶
func (StmtBuiltinPop) String ¶
func (st StmtBuiltinPop) String() string
func (StmtBuiltinPop) TrailingComment ¶
func (s StmtBuiltinPop) TrailingComment() Comment
type StmtBuiltinPrint ¶
func (StmtBuiltinPrint) String ¶
func (st StmtBuiltinPrint) String() string
func (StmtBuiltinPrint) TrailingComment ¶
func (s StmtBuiltinPrint) TrailingComment() Comment
type StmtBuiltinPush ¶
func (StmtBuiltinPush) String ¶
func (st StmtBuiltinPush) String() string
func (StmtBuiltinPush) TrailingComment ¶
func (s StmtBuiltinPush) TrailingComment() Comment
type StmtBuiltinPushValue ¶
func (StmtBuiltinPushValue) String ¶
func (st StmtBuiltinPushValue) String() string
func (StmtBuiltinPushValue) TrailingComment ¶
func (s StmtBuiltinPushValue) TrailingComment() Comment
type StmtBuiltinSyscall ¶
func (StmtBuiltinSyscall) String ¶
func (st StmtBuiltinSyscall) String() string
func (StmtBuiltinSyscall) TrailingComment ¶
func (s StmtBuiltinSyscall) TrailingComment() Comment
type StmtCall ¶
func (StmtCall) TrailingComment ¶
type StmtComment ¶
type StmtComment struct {
Comment
}
func (StmtComment) TrailingComment ¶
func (s StmtComment) TrailingComment() Comment
type StmtEOF ¶
type StmtEOF struct{}
StmtEOF indicates the end of statements for a file.
func (StmtEOF) TrailingComment ¶
type StmtElse ¶
func (StmtElse) TrailingComment ¶
type StmtEndFor ¶
func (StmtEndFor) String ¶
func (st StmtEndFor) String() string
func (StmtEndFor) TrailingComment ¶
func (s StmtEndFor) TrailingComment() Comment
type StmtEndIf ¶
func (StmtEndIf) TrailingComment ¶
type StmtEndSwitch ¶
func (StmtEndSwitch) String ¶
func (st StmtEndSwitch) String() string
func (StmtEndSwitch) TrailingComment ¶
func (s StmtEndSwitch) TrailingComment() Comment
type StmtEndWhile ¶
func (StmtEndWhile) String ¶
func (st StmtEndWhile) String() string
func (StmtEndWhile) TrailingComment ¶
func (s StmtEndWhile) TrailingComment() Comment
type StmtFor ¶
type StmtFor struct { Location Comment Comment Composite Value // IsValueComposite() || // IsValueComposite(ValueFromGlobal.Value) || // ValueFromGlobalArrayByIndex is ValueString || // ValueFromGlobalArrayByVar is ValueString Value token.Token Index token.Token }
func (StmtFor) TrailingComment ¶
type StmtGlobal ¶
type StmtGlobal struct { Location Comment Comment Name string State GlobalTag Value Value // ValueUnsigned, ValueUnsignedArray, ValueSigned, ValueSignedArray, ValueString, ValueStringArray, ValueEmbed }
Global declaration.
func (StmtGlobal) String ¶
func (st StmtGlobal) String() string
func (StmtGlobal) TrailingComment ¶
func (s StmtGlobal) TrailingComment() Comment
type StmtGoto ¶
func (StmtGoto) TrailingComment ¶
type StmtIf ¶
type StmtIf struct { Location // must be properly set for codegen Comment Comment Condition Condition }
func (StmtIf) TrailingComment ¶
type StmtImport ¶
type StmtImport struct { Location Comment Comment // Tag defines the namespace for the import. // It can be empty, in which case special care of duplicate identifiers need to be taken. Tag string // Name identifies a package resource: // - directory on the local filesystem, absolute or relative to the file this statement is contained // - url (TODO) Name string }
func (StmtImport) String ¶
func (st StmtImport) String() string
func (StmtImport) TrailingComment ¶
func (s StmtImport) TrailingComment() Comment
type StmtLabel ¶
func (StmtLabel) TrailingComment ¶
type StmtLabelCallable ¶
type StmtLabelCallable struct { Location Comment Comment Name string Tag LabelTag Input []Param Output []Param }
func (StmtLabelCallable) String ¶
func (st StmtLabelCallable) String() string
func (StmtLabelCallable) TrailingComment ¶
func (s StmtLabelCallable) TrailingComment() Comment
type StmtNewline ¶
type StmtNewline struct{}
func (StmtNewline) Loc ¶
func (st StmtNewline) Loc() Location
func (StmtNewline) String ¶
func (st StmtNewline) String() string
func (StmtNewline) TrailingComment ¶
func (s StmtNewline) TrailingComment() Comment
type StmtReturn ¶
func (StmtReturn) String ¶
func (st StmtReturn) String() string
func (StmtReturn) TrailingComment ¶
func (s StmtReturn) TrailingComment() Comment
type StmtSwitch ¶
func (StmtSwitch) String ¶
func (st StmtSwitch) String() string
func (StmtSwitch) TrailingComment ¶
func (s StmtSwitch) TrailingComment() Comment
type StmtSwitchCase ¶
func (StmtSwitchCase) String ¶
func (st StmtSwitchCase) String() string
func (StmtSwitchCase) TrailingComment ¶
func (s StmtSwitchCase) TrailingComment() Comment
type StmtSwitchCaseDefault ¶
func (StmtSwitchCaseDefault) String ¶
func (st StmtSwitchCaseDefault) String() string
func (StmtSwitchCaseDefault) TrailingComment ¶
func (s StmtSwitchCaseDefault) TrailingComment() Comment
type StmtVarDec ¶
func (StmtVarDec) String ¶
func (st StmtVarDec) String() string
func (StmtVarDec) TrailingComment ¶
func (s StmtVarDec) TrailingComment() Comment
type StmtVarInc ¶
func (StmtVarInc) String ¶
func (st StmtVarInc) String() string
func (StmtVarInc) TrailingComment ¶
func (s StmtVarInc) TrailingComment() Comment
type StmtWhile ¶
func (StmtWhile) TrailingComment ¶
type Symbol ¶
Symbol defines a (potentially external to the package) reference to a label.
func InternStringSymbol ¶
InternStringID returns the label to use for codegen.
func (Symbol) Get ¶
func (s Symbol) Get(data map[Symbol]*StmtGlobal) *StmtGlobal
Get the Global for this symbol.
type ValueEmbedEnv ¶
type ValueEmbedEnv struct { Location Env string // Name of its Global. Name string // resolved by sema // Size of the file content. Size uint64 // resolved by sema }
func (ValueEmbedEnv) BuiltinType ¶
func (v ValueEmbedEnv) BuiltinType() token.Token
func (ValueEmbedEnv) Equal ¶
func (val ValueEmbedEnv) Equal(v Value) bool
func (ValueEmbedEnv) Less ¶
func (val ValueEmbedEnv) Less(v Value) bool
func (ValueEmbedEnv) String ¶
func (val ValueEmbedEnv) String() string
type ValueEmbedFile ¶
type ValueEmbedFile struct { Location File string // Name of its Global. Name string // resolved by sema // Size of the file content. Size uint64 // resolved by sema }
func (ValueEmbedFile) BuiltinType ¶
func (v ValueEmbedFile) BuiltinType() token.Token
func (ValueEmbedFile) Equal ¶
func (val ValueEmbedFile) Equal(v Value) bool
func (ValueEmbedFile) Less ¶
func (val ValueEmbedFile) Less(v Value) bool
func (ValueEmbedFile) String ¶
func (val ValueEmbedFile) String() string
type ValueFormat ¶
type ValueFormat uint8
const ( Decimal ValueFormat = iota // 123 Hexadecimal // 0x Binary // 0b Character // ' ' )
type ValueFromGlobal ¶
type ValueFromGlobal struct { Location Symbol Symbol // Type is the global type or its element type if an array. Type token.Token // set by sema }
@arr
func (ValueFromGlobal) BuiltinType ¶
func (v ValueFromGlobal) BuiltinType() token.Token
func (ValueFromGlobal) Equal ¶
func (val ValueFromGlobal) Equal(v Value) bool
func (ValueFromGlobal) Less ¶
func (val ValueFromGlobal) Less(v Value) bool
func (ValueFromGlobal) String ¶
func (val ValueFromGlobal) String() string
type ValueFromGlobalArrayByIndex ¶
type ValueFromGlobalArrayByIndex struct { Location Symbol Symbol Type token.Token // set by sema Index uint64 }
@arr[0]
func (ValueFromGlobalArrayByIndex) BuiltinType ¶
func (v ValueFromGlobalArrayByIndex) BuiltinType() token.Token
func (ValueFromGlobalArrayByIndex) Equal ¶
func (val ValueFromGlobalArrayByIndex) Equal(v Value) bool
func (ValueFromGlobalArrayByIndex) Less ¶
func (val ValueFromGlobalArrayByIndex) Less(v Value) bool
func (ValueFromGlobalArrayByIndex) String ¶
func (val ValueFromGlobalArrayByIndex) String() string
type ValueFromGlobalArrayByIndexLen ¶
@arr[0].len
func (ValueFromGlobalArrayByIndexLen) BuiltinType ¶
func (v ValueFromGlobalArrayByIndexLen) BuiltinType() token.Token
func (ValueFromGlobalArrayByIndexLen) Equal ¶
func (val ValueFromGlobalArrayByIndexLen) Equal(v Value) bool
func (ValueFromGlobalArrayByIndexLen) Less ¶
func (val ValueFromGlobalArrayByIndexLen) Less(v Value) bool
func (ValueFromGlobalArrayByIndexLen) String ¶
func (val ValueFromGlobalArrayByIndexLen) String() string
type ValueFromGlobalArrayByVar ¶
type ValueFromGlobalArrayByVar struct { Location Symbol Symbol Type token.Token // set by sema Var token.Token }
@arr[r0]
func (ValueFromGlobalArrayByVar) BuiltinType ¶
func (v ValueFromGlobalArrayByVar) BuiltinType() token.Token
func (ValueFromGlobalArrayByVar) Equal ¶
func (val ValueFromGlobalArrayByVar) Equal(v Value) bool
func (ValueFromGlobalArrayByVar) Less ¶
func (val ValueFromGlobalArrayByVar) Less(v Value) bool
func (ValueFromGlobalArrayByVar) String ¶
func (val ValueFromGlobalArrayByVar) String() string
type ValueFromGlobalArrayByVarLen ¶
@arr[r0].len
func (ValueFromGlobalArrayByVarLen) BuiltinType ¶
func (v ValueFromGlobalArrayByVarLen) BuiltinType() token.Token
func (ValueFromGlobalArrayByVarLen) Equal ¶
func (val ValueFromGlobalArrayByVarLen) Equal(v Value) bool
func (ValueFromGlobalArrayByVarLen) Less ¶
func (val ValueFromGlobalArrayByVarLen) Less(v Value) bool
func (ValueFromGlobalArrayByVarLen) String ¶
func (val ValueFromGlobalArrayByVarLen) String() string
type ValueLoad ¶
type ValueLoad struct { Location Type token.Token Address Value // ValueVar, ValueUnsigned, ValueFromGlobal Scale struct { Var token.Token Mul uint64 } Displacement int64 }
*r0 u8
func (ValueLoad) BuiltinType ¶
type ValueSigned ¶
type ValueSigned struct { Location Format ValueFormat Type token.Token Value int64 }
func (ValueSigned) BuiltinType ¶
func (v ValueSigned) BuiltinType() token.Token
func (ValueSigned) Equal ¶
func (val ValueSigned) Equal(v Value) bool
func (ValueSigned) Less ¶
func (val ValueSigned) Less(v Value) bool
func (ValueSigned) String ¶
func (val ValueSigned) String() string
type ValueSignedArray ¶
type ValueSignedArray struct { Location Type token.Token Length uint64 Default int64 Values []int64 }
func (ValueSignedArray) BuiltinType ¶
func (v ValueSignedArray) BuiltinType() token.Token
func (ValueSignedArray) Equal ¶
func (val ValueSignedArray) Equal(v Value) bool
func (ValueSignedArray) Less ¶
func (val ValueSignedArray) Less(v Value) bool
func (ValueSignedArray) String ¶
func (val ValueSignedArray) String() string
type ValueStore ¶
type ValueStore struct { Location Type token.Token Address Value // ValueVar, ValueUnsigned, ValueFromGlobal Scale struct { Var token.Token Mul uint64 } Displacement uint64 }
*r0 u8 =
func (ValueStore) BuiltinType ¶
func (v ValueStore) BuiltinType() token.Token
func (ValueStore) Equal ¶
func (val ValueStore) Equal(v Value) bool
func (ValueStore) Less ¶
func (val ValueStore) Less(v Value) bool
func (ValueStore) String ¶
func (val ValueStore) String() string
type ValueString ¶
func (ValueString) BuiltinType ¶
func (v ValueString) BuiltinType() token.Token
func (ValueString) Equal ¶
func (val ValueString) Equal(v Value) bool
func (ValueString) Less ¶
func (val ValueString) Less(v Value) bool
func (ValueString) String ¶
func (val ValueString) String() string
type ValueStringArray ¶
type ValueStringArray struct { Location Length uint64 Default string Values []Value // ValueString, ValueFromGlobal after string interning }
func (ValueStringArray) BuiltinType ¶
func (v ValueStringArray) BuiltinType() token.Token
func (ValueStringArray) Equal ¶
func (val ValueStringArray) Equal(v Value) bool
func (ValueStringArray) Less ¶
func (val ValueStringArray) Less(v Value) bool
func (ValueStringArray) String ¶
func (val ValueStringArray) String() string
type ValueUnsigned ¶
type ValueUnsigned struct { Location Format ValueFormat Type token.Token Value uint64 }
func (ValueUnsigned) BuiltinType ¶
func (v ValueUnsigned) BuiltinType() token.Token
func (ValueUnsigned) Equal ¶
func (val ValueUnsigned) Equal(v Value) bool
func (ValueUnsigned) Less ¶
func (val ValueUnsigned) Less(v Value) bool
func (ValueUnsigned) String ¶
func (val ValueUnsigned) String() string
type ValueUnsignedArray ¶
type ValueUnsignedArray struct { Location Type token.Token Format ValueFormat Length uint64 Default uint64 Values []uint64 }
func (ValueUnsignedArray) BuiltinType ¶
func (v ValueUnsignedArray) BuiltinType() token.Token
func (ValueUnsignedArray) Equal ¶
func (val ValueUnsignedArray) Equal(v Value) bool
func (ValueUnsignedArray) Less ¶
func (val ValueUnsignedArray) Less(v Value) bool
func (ValueUnsignedArray) String ¶
func (val ValueUnsignedArray) String() string
type ValueVar ¶
func (ValueVar) BuiltinType ¶
type ValueVarByIndex ¶
WIP r0[0]
func (ValueVarByIndex) BuiltinType ¶
func (v ValueVarByIndex) BuiltinType() token.Token
func (ValueVarByIndex) Equal ¶
func (val ValueVarByIndex) Equal(v Value) bool
func (ValueVarByIndex) Less ¶
func (val ValueVarByIndex) Less(v Value) bool
func (ValueVarByIndex) String ¶
func (val ValueVarByIndex) String() string
type ValueVarByVar ¶
WIP r0[r1]
func (ValueVarByVar) BuiltinType ¶
func (v ValueVarByVar) BuiltinType() token.Token
func (ValueVarByVar) Equal ¶
func (val ValueVarByVar) Equal(v Value) bool
func (ValueVarByVar) Less ¶
func (val ValueVarByVar) Less(v Value) bool
func (ValueVarByVar) String ¶
func (val ValueVarByVar) String() string
type ValueVarLen ¶
ValueVarLen gives the length of the array or string stored in Var. e.g. r0.len
func (ValueVarLen) BuiltinType ¶
func (v ValueVarLen) BuiltinType() token.Token
func (ValueVarLen) Equal ¶
func (val ValueVarLen) Equal(v Value) bool
func (ValueVarLen) Less ¶
func (val ValueVarLen) Less(v Value) bool
func (ValueVarLen) String ¶
func (val ValueVarLen) String() string
type ValueVarSize ¶
ValueVarSize gives the size of the array or string elements stored in Var. e.g. r0.size
func (ValueVarSize) BuiltinType ¶
func (v ValueVarSize) BuiltinType() token.Token
func (ValueVarSize) Equal ¶
func (val ValueVarSize) Equal(v Value) bool
func (ValueVarSize) Less ¶
func (val ValueVarSize) Less(v Value) bool
func (ValueVarSize) String ¶
func (val ValueVarSize) String() string