Documentation ¶
Index ¶
- Constants
- Variables
- func Assemble(instructions ...interface{}) (script []byte, err error)
- func CompileInstr(s interface{}) ([]byte, error)
- func IsArray(v Var) bool
- func IsNum(v Var) bool
- func IsOpCode(s string) bool
- func IsPtr(v Var) bool
- func MatchRegexp(reg string, str []byte) bool
- func PreParse(data string) (mainInput, initInput string)
- func PreProcess(s string) (source string, err error)
- func VarLength(v Var) int
- type ArgList
- type Array
- type AstType
- type CompilerFrontend
- type Function
- func (self *Function) Call(args []*SyntaxTree, gen *IntGen, scope Scope) *IntInstr
- func (self *Function) GenOffset() int
- func (self *Function) GetVar(id string) Var
- func (self *Function) MakeReturn(expr *SyntaxTree, gen *IntGen) *IntInstr
- func (self *Function) NewVar(id string, typ varType) (Var, error)
- func (self *Function) PushArg(v Var)
- func (self *Function) SetVar(v Var)
- func (self *Function) Size() (size int)
- func (self *Function) String() string
- type InlineCode
- type Instr
- type IntGen
- func (self *IntGen) CheckGlobal() bool
- func (self *IntGen) CurrentScope() Scope
- func (p *IntGen) Errorf(tree *SyntaxTree, format string, v ...interface{}) (*IntInstr, error)
- func (self *IntGen) GetVar(id string) Var
- func (gen *IntGen) MakeIntCode(tree *SyntaxTree) *IntInstr
- func (self *IntGen) MakeReturn(tree *SyntaxTree, gen *IntGen) *IntInstr
- func (self *IntGen) NewVar(id string, typ varType) (Var, error)
- func (gen *IntGen) Pop() *IntInstr
- func (self *IntGen) PopScope() Scope
- func (self *IntGen) PopStack() *IntInstr
- func (gen *IntGen) Push() *IntInstr
- func (gen *IntGen) PushScope(scope Scope)
- func (self *IntGen) PushStack() *IntInstr
- func (self *IntGen) SetStackPtr(ptr int) *IntInstr
- func (self *IntGen) SetVar(v Var)
- func (self *IntGen) Size() (size int)
- type IntInstr
- type Lexer
- type LocalScope
- type Pointer
- type Scope
- type SyntaxTree
- type Var
- type Variable
- func (self *Variable) Id() string
- func (self *Variable) Instr() *IntInstr
- func (self *Variable) Offset() int
- func (self *Variable) SetInstr(instr *IntInstr)
- func (self *Variable) SetSize(s int)
- func (self *Variable) SetType(t varType)
- func (self *Variable) Size() int
- func (self *Variable) Type() varType
- type Variables
Constants ¶
View Source
const ADDR = 57350
View Source
const ADDRESS = 57370
View Source
const AND = 57414
View Source
const ARRAY = 57401
View Source
const ASM = 57391
View Source
const ASSIGN = 57377
View Source
const Alpha = "abcdefghijklmnopqrstuwvxyzABCDEFGHIJKLMNOPQRSTUWVXYZ"
View Source
const BALANCE = 57362
View Source
const BLOCK = 57346
View Source
const BLOCKNUM = 57367
View Source
const BOOLEAN = 57411
View Source
const BYTE = 57371
View Source
const CALL = 57357
View Source
const CALLCODE = 57358
View Source
const CALLDATALOAD = 57354
View Source
const CALLDATASIZE = 57355
View Source
const CALLER = 57352
View Source
const CALLVAL = 57353
View Source
const CODE = 57412
View Source
const COINBASE = 57368
View Source
const COLON = 57382
View Source
const COMMA = 57402
View Source
const CONST = 57396
View Source
const CONTRACT = 57348
View Source
const CREATE = 57361
View Source
const DIFFICULTY = 57364
View Source
const DOP = 57409
View Source
const DOT = 57400
View Source
const ELSE = 57385
View Source
const END_STMT = 57379
View Source
const EQUAL = 57378
View Source
const EXIT = 57360
View Source
const FOR = 57386
View Source
const FUNC = 57397
View Source
const FUNC_CALL = 57398
View Source
const GAS = 57369
View Source
const GASPRICE = 57356
View Source
const ID = 57405
View Source
const IF = 57384
View Source
const IMPORT = 57399
View Source
const INLINE_ASM = 57407
View Source
const LAMBDA = 57381
View Source
const LEFT_BRACES = 57387
View Source
const LEFT_BRACKET = 57389
View Source
const LEFT_PAR = 57392
View Source
const MSG = 57349
View Source
const MUL = 57415
View Source
const NIL = 57380
View Source
const NUMBER = 57406
View Source
const Numbers = "1234567890"
View Source
const OP = 57408
View Source
const ORIGIN = 57351
View Source
const POP = 57373
View Source
const PREVHASH = 57365
View Source
const PRINT = 57404
View Source
const PUSH = 57372
View Source
const QUOTE = 57403
View Source
const RETURN = 57383
View Source
const RIGHT_BRACES = 57388
View Source
const RIGHT_BRACKET = 57390
View Source
const RIGHT_PAR = 57393
View Source
const SHA3 = 57363
View Source
const SIZEOF = 57359
View Source
const STOP = 57394
View Source
const STORE = 57375
View Source
const STR = 57410
View Source
const SUICIDE = 57376
View Source
const TIMESTAMP = 57366
View Source
const TRANSACT = 57374
View Source
const TX = 57347
View Source
const VAR = 57395
Variables ¶
View Source
var Lineno int
View Source
var OpCodes = map[string]byte{}/* 120 elements not displayed */
Functions ¶
func CompileInstr ¶
Compile instruction
Attempts to compile and parse the given instruction in "s" and returns the byte sequence
func MatchRegexp ¶
func PreParse ¶
Pre parse script
Take data apart and attempt to find the "init" section and "main" section. `main { } init { }`
func PreProcess ¶
Types ¶
type AstType ¶
type AstType byte
const ( InvalidTy AstType = iota EmptyTy StatementListTy AssignmentTy IdentifierTy ConstantTy BoolTy SetLocalTy BlockTy IfThenTy IfThenElseTy ForThenTy EqualTy GtTy LtTy OpTy StoreTy SetStoreTy InlineAsmTy StopTy ExitTy ReturnTy RefTy DerefPtrTy Sha3Ty OriginTy AddressTy CallerTy CallValTy CallDataLoadTy CallDataSizeTy GasPriceTy DiffTy PrevHashTy TimestampTy CoinbaseTy BalanceTy GasTy BlockNumTy SuicideTy NewArrayTy NewVarTy ArrayTy AssignArrayTy CallTy CallCodeTy TransactTy CreateTy ArgTy SizeofTy StringTy LambdaTy FuncDefTy FuncCallTy PushTy PopTy ScopeTy ImportTy ByteTy PrintTy NilTy InitListTy )
type CompilerFrontend ¶
type CompilerFrontend interface { Compile(io.Reader) ([]byte, []error) Intermediate(io.Reader) (*IntInstr, []error) }
var Compiler CompilerFrontend
type Function ¶
type Function struct { CallTarget *IntInstr Id string ArgCount int Ret bool VarTable Variables ArgTable ArgList // contains filtered or unexported fields }
func (*Function) Call ¶
func (self *Function) Call(args []*SyntaxTree, gen *IntGen, scope Scope) *IntInstr
func (*Function) MakeReturn ¶
func (self *Function) MakeReturn(expr *SyntaxTree, gen *IntGen) *IntInstr
type InlineCode ¶
type Instr ¶
type Instr byte
const ( IntEqual Instr = iota IntErr IntPc IntGt IntLt IntMul IntAdd IntDiv IntSub IntExp IntMod IntXor IntOr IntAnd IntAssign IntConst IntEmpty IntJump IntTarget IntPush1 IntPush2 IntPush3 IntPush4 IntPush5 IntPush6 IntPush7 IntPush8 IntPush9 IntPush10 IntPush11 IntPush12 IntPush13 IntPush14 IntPush15 IntPush16 IntPush17 IntPush18 IntPush19 IntPush20 IntPush21 IntPush22 IntPush23 IntPush24 IntPush25 IntPush26 IntPush27 IntPush28 IntPush29 IntPush30 IntPush31 IntPush32 IntPop IntDup1 IntDup2 IntDup3 IntDup4 IntDup5 IntDup6 IntDup7 IntDup8 IntDup9 IntDup10 IntDup11 IntDup12 IntDup13 IntDup14 IntDup15 IntDup16 IntSwp1 IntSwp2 IntSwp3 IntSwp4 IntSwp5 IntSwp6 IntSwp7 IntSwp8 IntSwp9 IntSwp10 IntSwp11 IntSwp12 IntSwp13 IntSwp14 IntSwp15 IntSwp16 IntMStore IntMLoad IntMSize IntNot IntJumpi IntSStore IntSLoad IntStop IntOrigin IntAddress IntCodeCopy IntCaller IntCallVal IntCallDataLoad IntCallDataSize IntGasPrice IntDiff IntPrevHash IntTimestamp IntCoinbase IntBalance IntGas IntBlockNum IntReturn IntSuicide IntFuncDef IntFuncCall IntASM IntArray IntCall IntCallCode IntCreate IntSizeof IntByte IntAddMod IntMulMod IntSha3 IntIgnore IntInlineCode )
type IntGen ¶
type IntGen struct { VarTable map[string]Var Errors []error InlineCode []InlineCode // contains filtered or unexported fields }
func (*IntGen) CheckGlobal ¶
func (*IntGen) CurrentScope ¶
func (*IntGen) Errorf ¶
func (p *IntGen) Errorf(tree *SyntaxTree, format string, v ...interface{}) (*IntInstr, error)
Creates an error and returns an ignore instruction
func (*IntGen) MakeIntCode ¶
func (gen *IntGen) MakeIntCode(tree *SyntaxTree) *IntInstr
Recursive Intermediate code generator
func (*IntGen) MakeReturn ¶
func (self *IntGen) MakeReturn(tree *SyntaxTree, gen *IntGen) *IntInstr
func (*IntGen) SetStackPtr ¶
type IntInstr ¶
type IntInstr struct { Code Instr Constant interface{} ConstRef string Number int Next *IntInstr Target *IntInstr TargetNum *IntInstr LineNo int // contains filtered or unexported fields }
func (*IntInstr) LinkCode ¶
func (self *IntInstr) LinkCode(inlineCode []InlineCode)
func (*IntInstr) LinkTargets ¶
func (self *IntInstr) LinkTargets()
func (*IntInstr) SetNumbers ¶
type LocalScope ¶
type LocalScope struct {
VarTable Variables
}
func NewLocalScope ¶
func NewLocalScope() *LocalScope
func (*LocalScope) GetVar ¶
func (self *LocalScope) GetVar(id string) Var
func (*LocalScope) MakeReturn ¶
func (self *LocalScope) MakeReturn(expr *SyntaxTree, gen *IntGen) *IntInstr
func (*LocalScope) SetVar ¶
func (self *LocalScope) SetVar(v Var)
func (*LocalScope) Size ¶
func (self *LocalScope) Size() (size int)
type SyntaxTree ¶
type SyntaxTree struct { Type AstType Children []*SyntaxTree Constant string VarType string Size string Lineno int HasRet bool Ptr bool ArgList []*SyntaxTree }
Basic tree node for the AST
var Tree *SyntaxTree
func MakeAst ¶
func MakeAst(source string) (*SyntaxTree, error)
func NewNode ¶
func NewNode(typ AstType, v ...*SyntaxTree) *SyntaxTree
func (*SyntaxTree) String ¶
func (p *SyntaxTree) String() string
type Variable ¶
type Variable struct {
// contains filtered or unexported fields
}
func NewNumeric ¶
Click to show internal directories.
Click to hide internal directories.