compiler

package
v0.0.0-...-c93ad0d Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CmdSys is the command for delimiters
	CmdSys   cmd = 0xff
	CmdUnary     = 50
)
View Source
const (
	// MapConst represents a constant value.
	MapConst = iota
	// MapVar represents a variable.
	MapVar
	// MapMap represents a map.
	MapMap
	// MapExtend represents an extended variable.
	MapExtend
	// MapArray represents an array.
	MapArray
)
View Source
const (
	// MustKey represents a key.
	MustKey = iota
	// MustColon represents a colon.
	MustColon
	// MustComma represents a comma.
	MustComma
	// MustValue represents a value.
	MustValue
)
View Source
const (
	SliceLow = iota
	SliceLowNum
	SliceHigh
	SliceHighNum
)

Variables

View Source
var CodeBlockTypeName = map[int32]string{
	1: "CodeBlockDefault",
	2: "CodeBlockOwner",
	3: "CodeBlockContract",
	4: "CodeBlockFunction",
	5: "CodeBlockIf",
	6: "CodeBlockElse",
	7: "CodeBlockWhile",
}
View Source
var KeywordValue = map[string]Token{
	"contract":   CONTRACT,
	"func":       FUNC,
	"return":     RETURN,
	"if":         IF,
	"elif":       ELIF,
	"else":       ELSE,
	"while":      WHILE,
	"true":       TRUE,
	"false":      FALSE,
	"var":        VAR,
	"data":       FIELD,
	"settings":   SETTINGS,
	"break":      BREAK,
	"continue":   CONTINUE,
	"warning":    ERRWARNING,
	"info":       ERRINFO,
	"nil":        NIL,
	"action":     ACTION,
	"conditions": CONDITIONS,
	"...":        TAIL,
	"error":      ERROR,
}

KeywordValue is a map of keywords to tokens

View Source
var ObjectTypeName = map[int32]string{
	0: "Default",
	1: "CodeBlock",
	2: "ExtFunc",
	3: "Variable",
	4: "ExtVar",
}

ObjectTypeName maps the integer values of ObjectType to their string representations.

View Source
var TypeNameReflect = map[Token]reflect.Type{
	BOOL:    reflect.TypeOf(true),
	BYTES:   reflect.TypeOf([]byte{}),
	INT:     reflect.TypeOf(int64(0)),
	ADDRESS: reflect.TypeOf(int64(0)),
	ARRAY:   reflect.TypeOf([]any{}),
	MAP:     reflect.TypeOf(&Map{}),
	MONEY:   reflect.TypeOf(decimal.Zero),
	FLOAT:   reflect.TypeOf(0.0),
	STRING:  reflect.TypeOf(""),
	FILE:    reflect.TypeOf(&Map{}),
}

TypeNameReflect is a map of types to reflect.Type

View Source
var TypeNameValue = map[string]Token{
	"bool":    BOOL,
	"bytes":   BYTES,
	"int":     INT,
	"address": ADDRESS,
	"array":   ARRAY,
	"map":     MAP,
	"money":   MONEY,
	"float":   FLOAT,
	"string":  STRING,
	"file":    FILE,
}

TypeNameValue is a map of types to tokens

Functions

func ContractsList

func ContractsList(value string) ([]string, error)

ContractsList parses the given value string and returns a list of contract names found.

func ConvertMap

func ConvertMap(in any) any

ConvertMap converts the input to a linked hash map.

func FunctionsList

func FunctionsList(value string) ([]string, error)

FunctionsList parses the given value string and returns a list of function names found.

func GetFieldDefaultValue

func GetFieldDefaultValue(fieldType Token) any

GetFieldDefaultValue returns default value for field type

func StateName

func StateName(state uint32, name string) string

StateName checks the name of the contract and modifies it to @[state]name if it is necessary. If the name does not start with '@', it returns the name prefixed with the state number. If the name starts with '@' and the second character is not a digit, it returns the name prefixed with the state number. Otherwise, it returns the name as is.

Types

type ByteCode

type ByteCode struct {
	Cmd    Cmd
	Lexeme *Lexeme
	// Types that are assignable to Value:
	//
	//  *FuncTailCmd, assigned to CmdFuncTail.
	//  *IndexInfo, assigned to CmdGetIndex, CmdSetIndex.
	//	*VarInfo, assigned to CmdVar.
	//	*CodeBlock, assigned to CmdIf, CmdElse, CmdWhile
	//	*Object, assigned to CmdCall, CmdCallVariadic both for CodeBlockFunction, ObjExtFunc and CodeBlockContract
	//	*SliceItem, assigned to CmdSliceColon
	//	*Map, assigned to CmdMapInit
	//	*[]*VarInfo, assigned to CmdAssignVar
	//	*MapItemList, assigned to CmdArrayInit
	//	*Lexeme.Value, assigned to CmdPush, CmdError
	//	*map[string][]any, assigned to CmdPush for function tail
	//	*string, assigned to CmdPush, CmdCallExtend, CmdExtend
	//	*uint32, assigned to CmdPush for OwnerInfo.StateId
	//	*uint16, assigned to CmdSys, op.Cmd is operatorPriority
	//	*int, assigned to CmdReturn, CmdBreak, CmdContinue, CmdWhile, CmdPush, CmdAssign, CmdUnwrapArr, CmdLabel
	Value any
}

ByteCode stores a command and an additional parameter.

func (*ByteCode) CodeBlock

func (b *ByteCode) CodeBlock() *CodeBlock

func (*ByteCode) FuncTailCmd

func (b *ByteCode) FuncTailCmd() *FuncTailCmd

func (*ByteCode) IndexInfo

func (b *ByteCode) IndexInfo() *IndexInfo

func (*ByteCode) Map

func (b *ByteCode) Map() *Map

func (*ByteCode) MapItemList

func (b *ByteCode) MapItemList() *MapItemList

func (*ByteCode) Object

func (b *ByteCode) Object() *Object

func (*ByteCode) SliceItem

func (b *ByteCode) SliceItem() *SliceItem

func (*ByteCode) VarInfo

func (b *ByteCode) VarInfo() *VarInfo

func (*ByteCode) VarInfos

func (b *ByteCode) VarInfos() []*VarInfo

type ByteCodes

type ByteCodes []*ByteCode

ByteCodes is the slice of ByteCode items

func (*ByteCodes) String

func (b *ByteCodes) String() string

type Cmd

type Cmd uint16
const (
	CmdPush         Cmd = iota + 1 // Push value to stack
	CmdVar                         // Push variable to stack
	CmdExtend                      // Push extend variable to stack
	CmdCallExtend                  // Call extend function
	CmdPushStr                     // Push identifier as string
	CmdCall                        // call a function
	CmdCallVariadic                // call a variadic function
	CmdReturn                      // return from function
	CmdIf                          // run block if Value is true
	CmdElse                        // run block if Value is false
	CmdAssignVar                   // list of assigned var
	CmdAssign                      // assign
	CmdLabel                       // label for continue
	CmdContinue                    // continue from label
	CmdWhile                       // while
	CmdBreak                       // break
	CmdGetIndex                    // get index []
	CmdSetIndex                    // set index []
	CmdFuncTail                    // set func tail Func(...).tail(...)
	CmdUnwrapArr                   // unwrap array to stack
	CmdMapInit                     // map initialization
	CmdArrayInit                   // array initialization
	CmdError                       // error command
	CmdSliceColon                  // slice [:]
	CmdNot                         // !
	CmdSign                        // unary sign
)

here are described the commands of bytecode

const (
	CmdInc          Cmd = iota | 0x0100 // ++
	CmdDec                              // --
	CmdAssignAdd                        // +=
	CmdAssignSub                        // -=
	CmdAssignMul                        // *=
	CmdAssignDiv                        // /=
	CmdAssignMod                        // %=
	CmdAssignAnd                        // &=
	CmdAssignOr                         // |=
	CmdAssignXor                        // ^=
	CmdAssignLShift                     // <<=
	CmdAssignRShift                     // >>=
)

the commands for operations in expressions are listed below

const (
	CmdAdd    Cmd = iota | 0x0200 // +
	CmdSub                        // -
	CmdMul                        // *
	CmdDiv                        // /
	CmdMod                        // %
	CmdAnd                        // &&
	CmdBitAnd                     // &
	CmdBitXor                     // ^
	CmdBitOr                      // |
	CmdOr                         // ||
	CmdEqual                      // ==
	CmdNotEq                      // !=
	CmdLess                       // <
	CmdGrEq                       // >=
	CmdGreat                      // >
	CmdLessEq                     // <=
	CmdShiftL                     // <<
	CmdShiftR                     // >>
)

func (Cmd) String

func (i Cmd) String() string

type CodeBlock

type CodeBlock struct {
	Objects map[string]*Object
	Type    CodeBlockType
	// Types that are assignable to Info:
	//
	//  *FunctionInfo
	//  *ContractInfo
	//  *OwnerInfo
	//  *CodeBlockIfInfo
	//  *CodeBlockElseInfo
	//  *CodeBlockWhileInfo
	Info   isCodeBlockInfo
	Parent *CodeBlock
	Vars   []Token
	Code   ByteCodes
	// PredeclaredVar is a list of variables that are declared in the block
	PredeclaredVar []string
	Children       CodeBlocks
}

CodeBlock contains all information about compiled block {...} and its children

func CompileBlock

func CompileBlock(input []rune, conf *CompConfig) (*CodeBlock, error)

CompileBlock compiles a block of input runes into a CodeBlock using the provided CompConfig.

func NewCodeBlock

func NewCodeBlock(conf *CompConfig) *CodeBlock

func (*CodeBlock) AssertVar

func (bc *CodeBlock) AssertVar(name string) bool

AssertVar checks if the variable is declared in the block

func (*CodeBlock) CheckLoop

func (bc *CodeBlock) CheckLoop() bool

CheckLoop checks if the current block or any of its parent blocks is of type 'ObjWhile', which represents a loop in the code. If a loop is found, it returns true, otherwise false.

func (*CodeBlock) CodeToString

func (bc *CodeBlock) CodeToString() string

func (*CodeBlock) GetContractInfo

func (bc *CodeBlock) GetContractInfo() *ContractInfo

func (*CodeBlock) GetFunctionInfo

func (bc *CodeBlock) GetFunctionInfo() *FunctionInfo

func (*CodeBlock) GetInfo

func (bc *CodeBlock) GetInfo() isCodeBlockInfo

func (*CodeBlock) GetName

func (bc *CodeBlock) GetName() string

GetName returns the name of the block.

func (*CodeBlock) GetObjByName

func (bc *CodeBlock) GetObjByName(name string) (ret *Object)

func (*CodeBlock) GetOwnerInfo

func (bc *CodeBlock) GetOwnerInfo() *OwnerInfo

func (*CodeBlock) GetType

func (bc *CodeBlock) GetType() CodeBlockType

GetType returns the type of the block.

func (*CodeBlock) IsParentContract

func (bc *CodeBlock) IsParentContract() bool

func (*CodeBlock) SetExtendFunc

func (bc *CodeBlock) SetExtendFunc(ext []ExtendFunc)

func (*CodeBlock) SetInfo

func (bc *CodeBlock) SetInfo(info isCodeBlockInfo)

SetInfo sets the type of the block. It could be a function, contract, if, else or while.

type CodeBlockElseInfo

type CodeBlockElseInfo struct{}

type CodeBlockIfInfo

type CodeBlockIfInfo struct{}

type CodeBlockType

type CodeBlockType int32
const (
	CodeBlockDefault CodeBlockType = iota + 1
	CodeBlockOwner
	CodeBlockContract
	CodeBlockFunction
	CodeBlockIf
	CodeBlockElse
	CodeBlockWhile
)

func (CodeBlockType) String

func (c CodeBlockType) String() string

type CodeBlockWhileInfo

type CodeBlockWhileInfo struct{}

type CodeBlocks

type CodeBlocks []*CodeBlock

CodeBlocks is a slice of blocks

func (*CodeBlocks) ParentOwner

func (bs *CodeBlocks) ParentOwner() *OwnerInfo

type CompConfig

type CompConfig struct {
	Owner     *OwnerInfo
	Func      []ExtendFunc
	PreVar    []string
	Objects   map[string]*Object
	IgnoreObj IgnoreLevel
}

CompConfig is used for the definition of the extended functions and variables

func (*CompConfig) MakeConfig

func (cfg *CompConfig) MakeConfig() *CompConfig

MakeConfig sets default values and returns the CompConfig.

func (*CompConfig) MakeExtFunc

func (cfg *CompConfig) MakeExtFunc() map[string]*Object

MakeExtFunc returns a map of the object of the extended functions

type ContractInfo

type ContractInfo struct {
	Id       uint32
	Name     string
	Owner    *OwnerInfo
	Used     map[string]bool // Called contracts
	Field    *[]*FieldInfo   // contract fields
	Settings map[string]any
	CanWrite bool // true if the function can update DB
}

ContractInfo contains the contract information.

func (*ContractInfo) TxMap

func (c *ContractInfo) TxMap() map[string]*FieldInfo

TxMap returns the map of the contract fields.

type ExtFuncInfo

type ExtFuncInfo struct {
	Name     string
	Params   []reflect.Type
	Results  []reflect.Type
	Auto     []string
	Variadic bool
	Func     any
	CanWrite bool // If the function can update DB
}

ExtFuncInfo is the structure for the extended golang function.

func (*ExtFuncInfo) AutoParamsCount

func (e *ExtFuncInfo) AutoParamsCount() int

AutoParamsCount returns the number of auto params.

func (*ExtFuncInfo) Call

func (e *ExtFuncInfo) Call(params []any) (ret []any)

Call executes the function with the provided parameters. It takes a slice of any type as an argument which represents the parameters to be passed to the function. It returns a slice of any type which represents the return values of the function.

type ExtendFunc

type ExtendFunc struct {
	Name string
	// Func is the function to be called, it must be a function type
	Func     any
	CanWrite bool
	AutoPars map[string]string
}

ExtendFunc is used for the definition of the extended functions

func (*ExtendFunc) ExtFuncInfo

func (item *ExtendFunc) ExtFuncInfo() *ExtFuncInfo

ExtFuncInfo returns an ExtFuncInfo if the Func is a function type.

func (*ExtendFunc) MakeObject

func (item *ExtendFunc) MakeObject() *Object

MakeObject returns an Object if the ExtendFuncInfo is not nil.

type FieldInfo

type FieldInfo struct {
	Name     string
	Type     Token
	Original Token
	Tags     string
}

FieldInfo describes the field of the data structure.

func (*FieldInfo) ContainsTag

func (fi *FieldInfo) ContainsTag(tag string) bool

ContainsTag returns whether the tag is contained in this field.

type FuncTail

type FuncTail struct {
	Name     string
	Params   []Token
	Offset   []int
	Variadic bool
}

FuncTail contains the tail function information

func (FuncTail) IsParamEmpty

func (f FuncTail) IsParamEmpty(i int) bool

IsParamEmpty checks if the parameter at the given index is empty (nil).

type FuncTailCmd

type FuncTailCmd struct {
	Count    int
	FuncTail FuncTail
}

FuncTailCmd contains the function tail and the count of parameters.

type FunctionInfo

type FunctionInfo struct {
	Id      uint32
	Name    string
	Params  []Token
	Results []Token
	// tail function
	Tails    map[string]FuncTail
	Variadic bool
	CanWrite bool // If the function can update DB
}

FunctionInfo contains the function information.

func (*FunctionInfo) HasTails

func (e *FunctionInfo) HasTails() bool

HasTails returns whether the function has tails function.

func (*FunctionInfo) ParamsCount

func (e *FunctionInfo) ParamsCount() int

ParamsCount returns the number of parameters of the function.

type IgnoreLevel

type IgnoreLevel int
const (
	IgnoreNone IgnoreLevel = iota
	// IgnoreIdent ignore not found identifiers object.
	// If it is not found, it will be treated as a contract object.
	IgnoreIdent
)

type IndexInfo

type IndexInfo struct {
	VarOffset int
	Owner     *CodeBlock
	Extend    string
}

IndexInfo contains the information for SetIndex.

type Lexeme

type Lexeme struct {
	Type Token
	// Types that are assignable to Value:
	//
	//  *LexemeString
	//  *LexemeNumber
	//  *LexemeToken
	//  *LexemeBoolean
	//  *LexemeNil
	Value  isLexemeValue
	Line   int
	Column int
}

Lexeme is a lexical token of the program.

func NewLexeme

func NewLexeme(Type Token, value isLexemeValue, line int, column int) *Lexeme

NewLexeme creates a new Lexeme with the given parameters.

func (*Lexeme) GetBoolean

func (l *Lexeme) GetBoolean() bool

GetBoolean returns the boolean value of the lexeme.

func (*Lexeme) GetFloat64

func (l *Lexeme) GetFloat64() float64

GetFloat64 returns the float64 value of the lexeme.

func (*Lexeme) GetInt64

func (l *Lexeme) GetInt64() int64

GetInt64 returns the int64 value of the lexeme.

func (*Lexeme) GetLogger

func (l *Lexeme) GetLogger() *log.Entry

GetLogger returns a logger with fields containing lexeme information.

func (*Lexeme) GetString

func (l *Lexeme) GetString() string

GetString returns the string value of the lexeme.

func (*Lexeme) GetToken

func (l *Lexeme) GetToken() Token

GetToken returns the token of the lexeme.

func (*Lexeme) Interface

func (l *Lexeme) Interface() any

Interface returns the value of the lexeme as an interface{}.

func (*Lexeme) IsInteger

func (l *Lexeme) IsInteger() bool

IsInteger returns true if the lexeme is an integer.

func (*Lexeme) Position

func (l *Lexeme) Position() string

Position returns a string representation of the position of the lexeme.

func (*Lexeme) String

func (l *Lexeme) String() string

type LexemeBoolean

type LexemeBoolean struct {
	Value bool
}

LexemeBoolean is a boolean lexeme.

func NewLexemeBoolean

func NewLexemeBoolean(value bool) *LexemeBoolean

func (*LexemeBoolean) String

func (b *LexemeBoolean) String() string

type LexemeNil

type LexemeNil struct{}

func NewLexemeNil

func NewLexemeNil() *LexemeNil

func (*LexemeNil) String

func (n *LexemeNil) String() string

type LexemeNumber

type LexemeNumber struct {
	Int64     int64
	Float64   float64
	IsInteger bool
}

LexemeNumber is a number lexeme.

func NewLexemeNumber

func NewLexemeNumber(value any) *LexemeNumber

func (*LexemeNumber) String

func (n *LexemeNumber) String() string

type LexemeString

type LexemeString struct {
	Value string
}

LexemeString is a string lexeme.

func NewLexemeString

func NewLexemeString(value string) *LexemeString

func (*LexemeString) String

func (s *LexemeString) String() string

type LexemeToken

type LexemeToken struct {
	Value Token
}

LexemeToken is a token lexeme.

func NewLexemeToken

func NewLexemeToken(value Token) *LexemeToken

func (*LexemeToken) String

func (t *LexemeToken) String() string

type Lexemes

type Lexemes []*Lexeme

Lexemes is a slice of pointers to Lexeme.

func NewLexer

func NewLexer(input []rune) (Lexemes, error)

NewLexer creates a new Lexemes the given input.

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

Link represents a node of doubly linked list.

type Map

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

Map holds the elements in go's native map, also maintains the head and tail link to keep the elements in insertion order.

func LoadMap

func LoadMap(init map[string]any) (ret *Map)

LoadMap instantiates a linked hash map and initializing it from map[string]any.

func NewFile

func NewFile() *Map

NewFile creates a new file with default values.

func NewFileFromMap

func NewFileFromMap(m map[string]any) (f *Map, ok bool)

NewFileFromMap creates a new file from a map.

func NewMap

func NewMap() *Map

NewMap instantiates a linked hash map.

func (*Map) Clear

func (m *Map) Clear()

Clear removes all elements from the map.

func (*Map) Get

func (m *Map) Get(key string) (value any, found bool)

Get searches the element in the map by key and returns its value or nil if key doesn't exists. Second return parameter is true if key was found, otherwise false.

func (*Map) IsEmpty

func (m *Map) IsEmpty() bool

IsEmpty returns true if map does not contain any elements.

func (*Map) Keys

func (m *Map) Keys() []string

Keys returns all keys of the map (insertion order).

func (*Map) MarshalJSON

func (m *Map) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Map into JSON.

func (*Map) Remove

func (m *Map) Remove(key string)

Remove removes the element from the map by key.

func (*Map) Set

func (m *Map) Set(key string, value any)

Set inserts an element into the map.

func (*Map) Size

func (m *Map) Size() int

Size returns number of elements in the map.

func (*Map) String

func (m *Map) String() string

String returns a string representation of container.

func (*Map) Values

func (m *Map) Values() []any

Values returns all values of the map (insertion order).

type MapItem

type MapItem struct {
	KeyType  int
	KeyValue *VarInfo
	Type     int
	Value    isMapItemValue
}

MapItem represents a map item with a type and value.

func NewMapItem

func NewMapItem(v isMapItemValue) *MapItem

func (*MapItem) GetLexeme

func (m *MapItem) GetLexeme() *Lexeme

func (*MapItem) GetMap

func (m *MapItem) GetMap() *Map

func (*MapItem) GetMapItemList

func (m *MapItem) GetMapItemList() *MapItemList

func (*MapItem) GetVarInfo

func (m *MapItem) GetVarInfo() *VarInfo

type MapItemList

type MapItemList []*MapItem

type ObjInfoExtendVariable

type ObjInfoExtendVariable struct {
	// Name is the name of the extended variable.
	Name string
}

ObjInfoExtendVariable is the structure for the extended variable.

type ObjInfoVariable

type ObjInfoVariable struct {
	// Name is the name of the local variable.
	Name string
	// Index is the position of the variable in the current block.
	Index int
}

ObjInfoVariable is the structure for the local variable.

type Object

type Object struct {
	Type ObjectType
	// Types that are assignable to Value:
	//
	//	*CodeBlock
	//  *ExtFuncInfo
	//  *ObjInfoVariable
	//  *ObjInfoExtendVariable
	Value isObjValue
}

Object is the common object type that can be compiled.

func NewObject

func NewObject(v isObjValue) *Object

NewObject creates a new Object with the given value and determines its ObjectType.

func (*Object) GetCodeBlock

func (obj *Object) GetCodeBlock() *CodeBlock

GetCodeBlock returns the CodeBlock of the object if it exists.

func (*Object) GetContractInfo

func (obj *Object) GetContractInfo() *ContractInfo

GetContractInfo returns the ContractInfo of the object if it exists.

func (*Object) GetExtFuncInfo

func (obj *Object) GetExtFuncInfo() *ExtFuncInfo

GetExtFuncInfo returns the ExtFuncInfo of the object if it exists.

func (*Object) GetExtendVariable

func (obj *Object) GetExtendVariable() *ObjInfoExtendVariable

GetExtendVariable returns the ObjInfoExtendVariable of the object if it exists.

func (*Object) GetFunctionInfo

func (obj *Object) GetFunctionInfo() *FunctionInfo

GetFunctionInfo returns the FunctionInfo of the object if it exists.

func (*Object) GetName

func (obj *Object) GetName() string

GetName returns the name of the object.

func (*Object) GetParamsLen

func (obj *Object) GetParamsLen() int

GetParamsLen returns the number of parameters of the object if it is a function or extended function.

func (*Object) GetResultsLen

func (obj *Object) GetResultsLen() int

GetResultsLen returns the number of results of the object if it is a function or extended function.

func (*Object) GetValue

func (obj *Object) GetValue() isObjValue

GetValue returns the value of the object.

func (*Object) GetVariable

func (obj *Object) GetVariable() *ObjInfoVariable

GetVariable returns the ObjInfoVariable of the object if it exists.

func (*Object) GetVariadic

func (obj *Object) GetVariadic() bool

GetVariadic returns whether the object is a variadic function or extended function.

func (*Object) IsCodeBlockContract

func (obj *Object) IsCodeBlockContract() bool

func (*Object) IsCodeBlockFunction

func (obj *Object) IsCodeBlockFunction() bool

type ObjectType

type ObjectType int32

ObjectType Types of the compiled objects

const (
	// ObjDefault is an default object.
	ObjDefault ObjectType = iota
	// ObjCodeBlock is a code block object.
	ObjCodeBlock
	// ObjExtFunc is an extended build in function object.
	ObjExtFunc
	// ObjVariable is a variable object.
	ObjVariable
	// ObjExtVar is an extended build in variable.
	ObjExtVar
)

func (ObjectType) String

func (x ObjectType) String() string

type OwnerInfo

type OwnerInfo struct {
	StateId  uint32
	Active   bool
	TableId  int64
	WalletId int64
	TokenId  int64
}

OwnerInfo contains the owner information of the contract.

type Parser

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

Parser is a parser for the compiler.

func NewParser

func NewParser(lexemes Lexemes, conf *CompConfig) *Parser

NewParser returns a new parser for the given lexemes and configuration.

func (*Parser) Parse

func (p *Parser) Parse() (*CodeBlock, error)

Parse parses the lexemes and returns the root code block. It handles different states and transitions between them based on the lexemes.

type SliceItem

type SliceItem struct {
	Index [2]int
}

SliceItem is a slice item, Index[0] is low, Index[1] is high.

func (*SliceItem) SetHigh

func (i *SliceItem) SetHigh(high int)

SetHigh sets the high index of the SliceItem.

func (*SliceItem) SetLow

func (i *SliceItem) SetLow(low int)

SetLow sets the low index of the SliceItem.

type Token

type Token uint

Token is the incoming program is implemented in this file. It is the first phase of compilation where the incoming text is divided into a sequence of lexemes.

const (
	UNKNOWN    Token = iota
	DELIMITER        // Delimiters
	OPERATOR         // Operators
	NUMBER           // integer or float
	IDENTIFIER       // IDENTIFIER, including KEYWORD, TYPENAME, EXTEND
	NEWLINE          // Line translation
	LITERAL          // string or char
	COMMENT          // Comment
	KEYWORD          // keyword of IDENTIFIER
	TYPENAME         // name of the type of IDENTIFIER
	EXTEND           // Referring to an external variable of IDENTIFIER
)

represents the lexical token type of the program.

const (
	LPAREN Token = DELIMITER<<8 | iota
	RPAREN
	COMMA
	DOT
	COLON
	EQ
	LBRACK
	RBRACK
	LBRACE
	RBRACE
)

The list of delimiters for DELIMITER.

const (
	Not Token = OPERATOR<<8 | iota
	Mul
	Add
	Sub
	Quo
	MOD
	Less
	Great
	Assign
	NotEq
	And
	LessEq
	EqEq
	GrEq
	Or
	BitAnd
	BitOr
	BitXor
	LSHIFT
	RSHIFT
	AddEq
	SubEq
	MulEq
	DivEq
	ModEq
	LshEq
	RshEq
	AndEq
	OrEq
	XorEq
	Inc
	Dec
)

The list of operators for OPERATOR.

const (
	CONTRACT Token = KEYWORD<<8 | iota
	FUNC
	RETURN
	IF
	ELIF
	ELSE
	WHILE
	TRUE
	FALSE
	VAR
	FIELD
	SETTINGS
	BREAK
	CONTINUE
	ERRWARNING
	ERRINFO
	NIL
	ACTION
	CONDITIONS
	TAIL
	ERROR
)

The list of keyword identifiers for IDENTIFIER.

const (
	BOOL Token = TYPENAME<<8 | iota
	BYTES
	INT
	ADDRESS
	ARRAY
	MAP
	MONEY
	FLOAT
	STRING
	FILE
)

The list of data types for parameters and variables for TYPENAME.

func Lookup

func Lookup(ident string) (Token, bool)

Lookup maps an identifier to its keyword token

func (Token) Contains

func (tok Token) Contains(list []Token) bool

Contains checks if a token is in a list of tokens

func (Token) EqualsType

func (tok Token) EqualsType(t any) bool

func (Token) Kind

func (tok Token) Kind() Token

Kind returns the kind of token

func (Token) ReflectType

func (tok Token) ReflectType() reflect.Type

func (Token) String

func (i Token) String() string

func (Token) ToString

func (tok Token) ToString() string

type VarInfo

type VarInfo struct {
	Obj   *Object
	Owner *CodeBlock // is nil if the variable is global
}

VarInfo contains the variable or extended variable information.

Jump to

Keyboard shortcuts

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