frontend

package
v0.0.0-...-194e379 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2015 License: MIT Imports: 17 Imported by: 0

Documentation

Index

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 Assemble

func Assemble(instructions ...interface{}) (script []byte, err error)

Assemble

Assembles the given instructions and returns EVM byte code

func CompileInstr

func CompileInstr(s interface{}) ([]byte, error)

Compile instruction

Attempts to compile and parse the given instruction in "s" and returns the byte sequence

func IsArray

func IsArray(v Var) bool

func IsNum

func IsNum(v Var) bool

func IsOpCode

func IsOpCode(s string) bool

Is op code

Check whether the given string matches anything in the OpCode list

func IsPtr

func IsPtr(v Var) bool

func MatchRegexp

func MatchRegexp(reg string, str []byte) bool

func PreParse

func PreParse(data string) (mainInput, initInput string)

Pre parse script

Take data apart and attempt to find the "init" section and "main" section. `main { } init { }`

func PreProcess

func PreProcess(s string) (source string, err error)

func VarLength

func VarLength(v Var) int

Types

type ArgList

type ArgList []Var

type Array

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

func (*Array) Id

func (self *Array) Id() string

func (*Array) Instr

func (self *Array) Instr() *IntInstr

func (*Array) Offset

func (self *Array) Offset() int

func (*Array) SetInstr

func (self *Array) SetInstr(instr *IntInstr)

func (*Array) Size

func (self *Array) Size() int

func (*Array) Type

func (self *Array) Type() varType

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
)

func (AstType) String

func (ast AstType) String() string

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 NewFunction

func NewFunction(id string, target *IntInstr, ac int, ret bool) *Function

func (*Function) Call

func (self *Function) Call(args []*SyntaxTree, gen *IntGen, scope Scope) *IntInstr

func (*Function) GenOffset

func (self *Function) GenOffset() int

func (*Function) GetVar

func (self *Function) GetVar(id string) Var

func (*Function) MakeReturn

func (self *Function) MakeReturn(expr *SyntaxTree, gen *IntGen) *IntInstr

func (*Function) NewVar

func (self *Function) NewVar(id string, typ varType) (Var, error)

func (*Function) PushArg

func (self *Function) PushArg(v Var)

func (*Function) SetVar

func (self *Function) SetVar(v Var)

func (*Function) Size

func (self *Function) Size() (size int)

func (*Function) String

func (self *Function) String() string

type InlineCode

type InlineCode struct {
	Code        []byte
	OffsetInstr *IntInstr
	Offset      int
}

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
)

func (Instr) String

func (op Instr) String() string

type IntGen

type IntGen struct {
	VarTable map[string]Var

	Errors []error

	InlineCode []InlineCode
	// contains filtered or unexported fields
}

func NewGen

func NewGen() *IntGen

func (*IntGen) CheckGlobal

func (self *IntGen) CheckGlobal() bool

func (*IntGen) CurrentScope

func (self *IntGen) CurrentScope() Scope

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) GetVar

func (self *IntGen) GetVar(id string) Var

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) NewVar

func (self *IntGen) NewVar(id string, typ varType) (Var, error)

func (*IntGen) Pop

func (gen *IntGen) Pop() *IntInstr

func (*IntGen) PopScope

func (self *IntGen) PopScope() Scope

func (*IntGen) PopStack

func (self *IntGen) PopStack() *IntInstr

func (*IntGen) Push

func (gen *IntGen) Push() *IntInstr

func (*IntGen) PushScope

func (gen *IntGen) PushScope(scope Scope)

func (*IntGen) PushStack

func (self *IntGen) PushStack() *IntInstr

func (*IntGen) SetStackPtr

func (self *IntGen) SetStackPtr(ptr int) *IntInstr

func (*IntGen) SetVar

func (self *IntGen) SetVar(v Var)

func (*IntGen) Size

func (self *IntGen) Size() (size int)

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 Concat

func Concat(a, b *IntInstr) *IntInstr

func (*IntInstr) LinkCode

func (self *IntInstr) LinkCode(inlineCode []InlineCode)

func (*IntInstr) LinkTargets

func (self *IntInstr) LinkTargets()

func (*IntInstr) SetNumbers

func (instr *IntInstr) SetNumbers(i int, gen *IntGen)

func (*IntInstr) String

func (instr *IntInstr) String() string

type Lexer

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

func (*Lexer) Error

func (l *Lexer) Error(s string)

func (*Lexer) Lex

func (l *Lexer) Lex(lval *yySymType) int

yacc's lexing method

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) NewVar

func (self *LocalScope) NewVar(id string, typ varType) (Var, error)

func (*LocalScope) SetVar

func (self *LocalScope) SetVar(v Var)

func (*LocalScope) Size

func (self *LocalScope) Size() (size int)

type Pointer

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

func NewPointer

func NewPointer(id string, offset int, ptrTy varType) *Pointer

func (*Pointer) Id

func (self *Pointer) Id() string

func (*Pointer) Instr

func (self *Pointer) Instr() *IntInstr

func (*Pointer) Offset

func (self *Pointer) Offset() int

func (*Pointer) SetInstr

func (self *Pointer) SetInstr(instr *IntInstr)

func (*Pointer) Size

func (self *Pointer) Size() int

func (*Pointer) Type

func (self *Pointer) Type() varType

type Scope

type Scope interface {
	NewVar(id string, typ varType) (Var, error)
	SetVar(Var)
	GetVar(string) Var
	Size() int

	MakeReturn(expr *SyntaxTree, gen *IntGen) *IntInstr
}

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 Var

type Var interface {
	Id() string

	Type() varType
	SetType(t varType)

	Size() int
	SetSize(int)

	Offset() int
	Instr() *IntInstr
	SetInstr(*IntInstr)
}

type Variable

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

func NewArray

func NewArray(id string, offset, count int) *Variable

func NewNumeric

func NewNumeric(id string, offset int) *Variable

func (*Variable) Id

func (self *Variable) Id() string

func (*Variable) Instr

func (self *Variable) Instr() *IntInstr

func (*Variable) Offset

func (self *Variable) Offset() int

func (*Variable) SetInstr

func (self *Variable) SetInstr(instr *IntInstr)

func (*Variable) SetSize

func (self *Variable) SetSize(s int)

func (*Variable) SetType

func (self *Variable) SetType(t varType)

func (*Variable) Size

func (self *Variable) Size() int

func (*Variable) Type

func (self *Variable) Type() varType

type Variables

type Variables map[string]Var

func (Variables) String

func (self Variables) String() (ret string)

Jump to

Keyboard shortcuts

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