Documentation
¶
Index ¶
- Variables
- func DefaultBuiltinGlobals() *activations.Activation[GlobalImport]
- type BuiltinFunction
- type BuiltinGlobalsProvider
- type ByteCodeGen
- type BytecodeShiftPair
- type CodeGen
- type Compiler
- func NewBytecodeCompiler(program *interpreter.Program, location common.Location, config *Config) *Compiler[byte, []byte]
- func NewInstructionCompiler(program *interpreter.Program, location common.Location) *Compiler[opcode.Instruction, bbq.StaticType]
- func NewInstructionCompilerWithConfig(program *interpreter.Program, location common.Location, config *Config) *Compiler[opcode.Instruction, bbq.StaticType]
- func (c *Compiler[E, T]) Compile() *bbq.Program[E, T]
- func (c *Compiler[_, _]) VisitArrayExpression(array *ast.ArrayExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitAssignmentStatement(statement *ast.AssignmentStatement) (_ struct{})
- func (c *Compiler[_, _]) VisitAttachExpression(expression *ast.AttachExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitAttachmentDeclaration(declaration *ast.AttachmentDeclaration) (_ struct{})
- func (c *Compiler[_, _]) VisitBinaryExpression(expression *ast.BinaryExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitBoolExpression(expression *ast.BoolExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitBreakStatement(_ *ast.BreakStatement) (_ struct{})
- func (c *Compiler[_, _]) VisitCastingExpression(expression *ast.CastingExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitCompositeDeclaration(declaration *ast.CompositeDeclaration) (_ struct{})
- func (c *Compiler[_, _]) VisitConditionalExpression(expression *ast.ConditionalExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitContinueStatement(_ *ast.ContinueStatement) (_ struct{})
- func (c *Compiler[_, _]) VisitCreateExpression(expression *ast.CreateExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitDestroyExpression(expression *ast.DestroyExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitDictionaryExpression(dictionary *ast.DictionaryExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitEmitStatement(statement *ast.EmitStatement) (_ struct{})
- func (c *Compiler[_, _]) VisitEntitlementDeclaration(_ *ast.EntitlementDeclaration) (_ struct{})
- func (c *Compiler[_, _]) VisitEntitlementMappingDeclaration(_ *ast.EntitlementMappingDeclaration) (_ struct{})
- func (c *Compiler[_, _]) VisitEnumCaseDeclaration(_ *ast.EnumCaseDeclaration) (_ struct{})
- func (c *Compiler[_, _]) VisitExpressionStatement(statement *ast.ExpressionStatement) (_ struct{})
- func (c *Compiler[_, _]) VisitFieldDeclaration(_ *ast.FieldDeclaration) (_ struct{})
- func (c *Compiler[_, _]) VisitFixedPointExpression(expression *ast.FixedPointExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitForStatement(statement *ast.ForStatement) (_ struct{})
- func (c *Compiler[_, _]) VisitForceExpression(expression *ast.ForceExpression) (_ struct{})
- func (c *Compiler[E, _]) VisitFunctionDeclaration(declaration *ast.FunctionDeclaration, _ bool) (_ struct{})
- func (c *Compiler[_, _]) VisitFunctionExpression(expression *ast.FunctionExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitIdentifierExpression(expression *ast.IdentifierExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitIfStatement(statement *ast.IfStatement) (_ struct{})
- func (c *Compiler[_, _]) VisitImportDeclaration(declaration *ast.ImportDeclaration) (_ struct{})
- func (c *Compiler[_, _]) VisitIndexExpression(expression *ast.IndexExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitIntegerExpression(expression *ast.IntegerExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitInterfaceDeclaration(declaration *ast.InterfaceDeclaration) (_ struct{})
- func (c *Compiler[_, _]) VisitInvocationExpression(expression *ast.InvocationExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitMemberExpression(expression *ast.MemberExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitNilExpression(_ *ast.NilExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitPathExpression(expression *ast.PathExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitPragmaDeclaration(_ *ast.PragmaDeclaration) (_ struct{})
- func (c *Compiler[_, _]) VisitReferenceExpression(expression *ast.ReferenceExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitRemoveStatement(statement *ast.RemoveStatement) (_ struct{})
- func (c *Compiler[_, _]) VisitReturnStatement(statement *ast.ReturnStatement) (_ struct{})
- func (c *Compiler[_, _]) VisitSpecialFunctionDeclaration(declaration *ast.SpecialFunctionDeclaration) (_ struct{})
- func (c *Compiler[_, _]) VisitStringExpression(expression *ast.StringExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitStringTemplateExpression(expression *ast.StringTemplateExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitSwapStatement(statement *ast.SwapStatement) (_ struct{})
- func (c *Compiler[_, _]) VisitSwitchStatement(statement *ast.SwitchStatement) (_ struct{})
- func (c *Compiler[_, _]) VisitTransactionDeclaration(declaration *ast.TransactionDeclaration) (_ struct{})
- func (c *Compiler[_, _]) VisitUnaryExpression(expression *ast.UnaryExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitVariableDeclaration(declaration *ast.VariableDeclaration) (_ struct{})
- func (c *Compiler[_, _]) VisitVoidExpression(_ *ast.VoidExpression) (_ struct{})
- func (c *Compiler[_, _]) VisitWhileStatement(statement *ast.WhileStatement) (_ struct{})
- type Config
- type Constant
- type DecodedConstant
- type DecodedTypeGen
- type Desugar
- func (d *Desugar) DesugarFunctionExpression(expression *ast.FunctionExpression) *ast.FunctionExpression
- func (d *Desugar) DesugarInnerFunction(declaration *ast.FunctionDeclaration) *ast.FunctionDeclaration
- func (d *Desugar) Run() DesugaredProgram
- func (d *Desugar) VisitAttachmentDeclaration(declaration *ast.AttachmentDeclaration) ast.Declaration
- func (d *Desugar) VisitCompositeDeclaration(declaration *ast.CompositeDeclaration) ast.Declaration
- func (d *Desugar) VisitEntitlementDeclaration(declaration *ast.EntitlementDeclaration) ast.Declaration
- func (d *Desugar) VisitEntitlementMappingDeclaration(declaration *ast.EntitlementMappingDeclaration) ast.Declaration
- func (d *Desugar) VisitEnumCaseDeclaration(declaration *ast.EnumCaseDeclaration) ast.Declaration
- func (d *Desugar) VisitFieldDeclaration(declaration *ast.FieldDeclaration) ast.Declaration
- func (d *Desugar) VisitFunctionDeclaration(declaration *ast.FunctionDeclaration, _ bool) ast.Declaration
- func (d *Desugar) VisitImportDeclaration(declaration *ast.ImportDeclaration) ast.Declaration
- func (d *Desugar) VisitInterfaceDeclaration(declaration *ast.InterfaceDeclaration) ast.Declaration
- func (d *Desugar) VisitPragmaDeclaration(declaration *ast.PragmaDeclaration) ast.Declaration
- func (d *Desugar) VisitSpecialFunctionDeclaration(declaration *ast.SpecialFunctionDeclaration) ast.Declaration
- func (d *Desugar) VisitTransactionDeclaration(transaction *ast.TransactionDeclaration) ast.Declaration
- func (d *Desugar) VisitVariableDeclaration(declaration *ast.VariableDeclaration) ast.Declaration
- type DesugaredElaboration
- func (e *DesugaredElaboration) AllImportDeclarationsResolvedLocations() map[*ast.ImportDeclaration][]sema.ResolvedLocation
- func (e *DesugaredElaboration) ArrayExpressionTypes(expression *ast.ArrayExpression) sema.ArrayExpressionTypes
- func (e *DesugaredElaboration) AssignmentStatementTypes(assignment *ast.AssignmentStatement) sema.AssignmentStatementTypes
- func (e *DesugaredElaboration) AttachTypes(expression *ast.AttachExpression) sema.AttachExpressionTypes
- func (e *DesugaredElaboration) AttachmentAccessTypes(expression *ast.IndexExpression) (ty sema.Type, ok bool)
- func (e *DesugaredElaboration) AttachmentRemoveTypes(statement *ast.RemoveStatement) (ty sema.Type)
- func (e *DesugaredElaboration) CastingExpressionTypes(expression *ast.CastingExpression) sema.CastingExpressionTypes
- func (e *DesugaredElaboration) CompositeDeclarationType(declaration ast.CompositeLikeDeclaration) *sema.CompositeType
- func (e *DesugaredElaboration) CompositeType(typeID common.TypeID) *sema.CompositeType
- func (e *DesugaredElaboration) DefaultDestroyDeclaration(declaration ast.Declaration) *ast.CompositeDeclaration
- func (e *DesugaredElaboration) DictionaryExpressionTypes(expression *ast.DictionaryExpression) sema.DictionaryExpressionTypes
- func (e *DesugaredElaboration) EmitStatementEventType(statement *ast.EmitStatement) *sema.CompositeType
- func (e *DesugaredElaboration) EntitlementMapType(typeID common.TypeID) *sema.EntitlementMapType
- func (e *DesugaredElaboration) EntitlementType(typeID common.TypeID) *sema.EntitlementType
- func (e *DesugaredElaboration) EnumLookupFunctionType(enumType *sema.CompositeType) *sema.FunctionType
- func (e *DesugaredElaboration) FixedPointExpressionType(expression *ast.FixedPointExpression) sema.Type
- func (e *DesugaredElaboration) ForStatementType(statement *ast.ForStatement) (types sema.ForStatementTypes)
- func (e *DesugaredElaboration) FunctionDeclarationFunctionType(declaration *ast.FunctionDeclaration) *sema.FunctionType
- func (e *DesugaredElaboration) FunctionExpressionFunctionType(expression *ast.FunctionExpression) *sema.FunctionType
- func (e *DesugaredElaboration) GetGlobalType(name string) (*sema.Variable, bool)
- func (e *DesugaredElaboration) IndexExpressionTypes(expression *ast.IndexExpression) (types sema.IndexExpressionTypes, contains bool)
- func (e *DesugaredElaboration) IntegerExpressionType(expression *ast.IntegerExpression) sema.Type
- func (e *DesugaredElaboration) InterfaceDeclarationType(decl *ast.InterfaceDeclaration) *sema.InterfaceType
- func (e *DesugaredElaboration) InterfaceType(typeID common.TypeID) *sema.InterfaceType
- func (e *DesugaredElaboration) InterfaceTypeDeclaration(interfaceType *sema.InterfaceType) *ast.InterfaceDeclaration
- func (e *DesugaredElaboration) InvocationExpressionTypes(expression *ast.InvocationExpression) sema.InvocationExpressionTypes
- func (e *DesugaredElaboration) IsInterfaceMethodStaticCall(invocation *ast.InvocationExpression) bool
- func (e *DesugaredElaboration) IsNestedResourceMoveExpression(expression ast.Expression) bool
- func (e *DesugaredElaboration) MemberExpressionMemberAccessInfo(expression *ast.MemberExpression) (memberInfo sema.MemberAccessInfo, ok bool)
- func (e *DesugaredElaboration) OriginalElaboration() *sema.Elaboration
- func (e *DesugaredElaboration) PostConditionsRewrite(conditions *ast.Conditions) sema.PostConditionsRewrite
- func (e *DesugaredElaboration) ReferenceExpressionBorrowType(expression *ast.ReferenceExpression) sema.Type
- func (e *DesugaredElaboration) ResultVariableType(enclosingBlock ast.Element) (typ sema.Type, exist bool)
- func (e *DesugaredElaboration) ReturnStatementTypes(statement *ast.ReturnStatement) sema.ReturnStatementTypes
- func (e *DesugaredElaboration) SetArrayExpressionTypes(expression *ast.ArrayExpression, types sema.ArrayExpressionTypes)
- func (e *DesugaredElaboration) SetAssignmentStatementTypes(assignment *ast.AssignmentStatement, types sema.AssignmentStatementTypes)
- func (e *DesugaredElaboration) SetCompositeDeclarationType(declaration ast.CompositeLikeDeclaration, compositeType *sema.CompositeType)
- func (e *DesugaredElaboration) SetCompositeType(typeID common.TypeID, compositeType *sema.CompositeType)
- func (e *DesugaredElaboration) SetEmitStatementEventType(statement *ast.EmitStatement, compositeType *sema.CompositeType)
- func (e *DesugaredElaboration) SetFunctionDeclarationFunctionType(declaration *ast.FunctionDeclaration, functionType *sema.FunctionType)
- func (e *DesugaredElaboration) SetFunctionExpressionFunctionType(expression *ast.FunctionExpression, functionType *sema.FunctionType)
- func (e *DesugaredElaboration) SetIntegerExpressionType(expression *ast.IntegerExpression, valueType sema.Type)
- func (e *DesugaredElaboration) SetInterfaceDeclarationType(decl *ast.InterfaceDeclaration, interfaceType *sema.InterfaceType)
- func (e *DesugaredElaboration) SetInterfaceMethodStaticCall(invocation *ast.InvocationExpression)
- func (e *DesugaredElaboration) SetInvocationExpressionTypes(expression *ast.InvocationExpression, types sema.InvocationExpressionTypes)
- func (e *DesugaredElaboration) SetMemberExpressionMemberAccessInfo(expression *ast.MemberExpression, memberAccessInfo sema.MemberAccessInfo)
- func (e *DesugaredElaboration) SetReferenceExpressionBorrowType(expression *ast.ReferenceExpression, ty sema.Type)
- func (e *DesugaredElaboration) SetResultVariableType(declaration ast.Element, typ sema.Type)
- func (e *DesugaredElaboration) SetReturnStatementTypes(statement *ast.ReturnStatement, types sema.ReturnStatementTypes)
- func (e *DesugaredElaboration) SetVariableDeclarationTypes(declaration *ast.VariableDeclaration, types sema.VariableDeclarationTypes)
- func (e *DesugaredElaboration) StringExpressionType(expression *ast.StringExpression) sema.Type
- func (e *DesugaredElaboration) SwapStatementTypes(statement *ast.SwapStatement) sema.SwapStatementTypes
- func (e *DesugaredElaboration) TransactionDeclarationType(declaration *ast.TransactionDeclaration) *sema.TransactionType
- func (e *DesugaredElaboration) VariableDeclarationTypes(declaration *ast.VariableDeclaration) sema.VariableDeclarationTypes
- type DesugaredProgram
- type ElaborationResolver
- type EncodedTypeGen
- type GlobalImport
- type InstructionCodeGen
- func (g *InstructionCodeGen) Emit(instruction opcode.Instruction)
- func (g *InstructionCodeGen) LastInstruction() opcode.Instruction
- func (g *InstructionCodeGen) Offset() int
- func (g *InstructionCodeGen) PatchJump(offset int, newTarget uint16)
- func (g *InstructionCodeGen) SetTarget(target *[]opcode.Instruction)
- type PeepholeInstructionStaticTypeOptimizer
- type PeepholeNoopOptimizer
- type PeepholeOptimizer
- type PeepholePattern
- type Stack
- type TypeGen
Constants ¶
This section is empty.
Variables ¶
var AllPatterns = []PeepholePattern{ GetFieldLocalPattern, ConstantTransferAndConvertPattern, PathTransferAndConvertPattern, NilTransferAndConvertPattern, }
var CommonBuiltinTypeBoundFunctions = []BuiltinFunction{ { Name: sema.GetTypeFunctionName, Type: sema.GetTypeFunctionType, }, { Name: sema.IsInstanceFunctionName, Type: sema.IsInstanceFunctionType, }, }
var ConstantTransferAndConvertPattern = PeepholePattern{ Name: "ConstantTransferAndConvert", Opcodes: []opcode.Opcode{opcode.GetConstant, opcode.TransferAndConvert}, Replacement: func(instructions []opcode.Instruction, compiler *Compiler[opcode.Instruction, interpreter.StaticType]) []opcode.Instruction { getConstant := instructions[0].(opcode.InstructionGetConstant) transferAndConvert := instructions[1].(opcode.InstructionTransferAndConvert) constantKind := compiler.constants[getConstant.Constant].kind targetType := compiler.types[transferAndConvert.Type] if constantKind == constant.FromSemaType(targetType) { return []opcode.Instruction{getConstant} } return instructions }, }
GetConstant -> TransferAndConvert, unnecessary transfer if constant is of the same type
var GetFieldLocalPattern = PeepholePattern{ Name: "GetFieldLocal", Opcodes: []opcode.Opcode{opcode.GetLocal, opcode.GetField}, Replacement: func(instructions []opcode.Instruction, compiler *Compiler[opcode.Instruction, interpreter.StaticType]) []opcode.Instruction { getLocal := instructions[0].(opcode.InstructionGetLocal) getField := instructions[1].(opcode.InstructionGetField) return []opcode.Instruction{opcode.InstructionGetFieldLocal{ FieldName: getField.FieldName, AccessedType: getField.AccessedType, Local: getLocal.Local, }} }, }
GetLocal -> GetField, combined because commonly found in token transfer
var NilTransferAndConvertPattern = PeepholePattern{ Name: "NilTransferAndConvert", Opcodes: []opcode.Opcode{opcode.Nil, opcode.TransferAndConvert}, Replacement: func(instructions []opcode.Instruction, compiler *Compiler[opcode.Instruction, interpreter.StaticType]) []opcode.Instruction { nilInstruction := instructions[0].(opcode.InstructionNil) return []opcode.Instruction{nilInstruction} }, }
Nil -> TransferAndConvert, unnecessary transfer if value is nil
var PathTransferAndConvertPattern = PeepholePattern{ Name: "PathTransferAndConvert", Opcodes: []opcode.Opcode{opcode.NewPath, opcode.TransferAndConvert}, Replacement: func(instructions []opcode.Instruction, compiler *Compiler[opcode.Instruction, interpreter.StaticType]) []opcode.Instruction { getPath := instructions[0].(opcode.InstructionNewPath) transferAndConvert := instructions[1].(opcode.InstructionTransferAndConvert) semaType := compiler.types[transferAndConvert.Type] switch getPath.Domain { case common.PathDomainPublic: if semaType == sema.PublicPathType { return []opcode.Instruction{getPath} } case common.PathDomainPrivate: if semaType == sema.PrivatePathType { return []opcode.Instruction{getPath} } case common.PathDomainStorage: if semaType == sema.StoragePathType { return []opcode.Instruction{getPath} } default: panic(errors.NewUnreachableError()) } return instructions }, }
NewPath -> TransferAndConvert, unnecessary transfer if path is of the same type
var PatternsByOpcode map[opcode.Opcode][]PeepholePattern
look up table to improve pattern matching performance
Functions ¶
func DefaultBuiltinGlobals ¶
func DefaultBuiltinGlobals() *activations.Activation[GlobalImport]
Types ¶
type BuiltinFunction ¶
type BuiltinFunction struct {
Name string
Type *sema.FunctionType
}
type BuiltinGlobalsProvider ¶
type BuiltinGlobalsProvider func(location common.Location) *activations.Activation[GlobalImport]
type ByteCodeGen ¶
type ByteCodeGen struct {
// contains filtered or unexported fields
}
ByteCodeGen is a CodeGen implementation that emits bytecode
func (*ByteCodeGen) Emit ¶
func (g *ByteCodeGen) Emit(instruction opcode.Instruction)
func (*ByteCodeGen) LastInstruction ¶
func (g *ByteCodeGen) LastInstruction() opcode.Instruction
func (*ByteCodeGen) Offset ¶
func (g *ByteCodeGen) Offset() int
func (*ByteCodeGen) PatchJump ¶
func (g *ByteCodeGen) PatchJump(offset int, newTarget uint16)
func (*ByteCodeGen) SetTarget ¶
func (g *ByteCodeGen) SetTarget(target *[]byte)
type BytecodeShiftPair ¶ added in v1.8.4
type CodeGen ¶
type CodeGen[E any] interface { Offset() int SetTarget(code *[]E) Emit(instruction opcode.Instruction) PatchJump(offset int, newTarget uint16) LastInstruction() opcode.Instruction }
type Compiler ¶
type Compiler[E, T any] struct { Program *ast.Program DesugaredElaboration *DesugaredElaboration Config *Config Globals map[string]bbq.Global // contains filtered or unexported fields }
func NewBytecodeCompiler ¶
func NewInstructionCompiler ¶
func NewInstructionCompiler( program *interpreter.Program, location common.Location, ) *Compiler[opcode.Instruction, bbq.StaticType]
func NewInstructionCompilerWithConfig ¶
func NewInstructionCompilerWithConfig( program *interpreter.Program, location common.Location, config *Config, ) *Compiler[opcode.Instruction, bbq.StaticType]
func (*Compiler[_, _]) VisitArrayExpression ¶
func (c *Compiler[_, _]) VisitArrayExpression(array *ast.ArrayExpression) (_ struct{})
func (*Compiler[_, _]) VisitAssignmentStatement ¶
func (c *Compiler[_, _]) VisitAssignmentStatement(statement *ast.AssignmentStatement) (_ struct{})
func (*Compiler[_, _]) VisitAttachExpression ¶
func (c *Compiler[_, _]) VisitAttachExpression(expression *ast.AttachExpression) (_ struct{})
func (*Compiler[_, _]) VisitAttachmentDeclaration ¶
func (c *Compiler[_, _]) VisitAttachmentDeclaration(declaration *ast.AttachmentDeclaration) (_ struct{})
func (*Compiler[_, _]) VisitBinaryExpression ¶
func (c *Compiler[_, _]) VisitBinaryExpression(expression *ast.BinaryExpression) (_ struct{})
func (*Compiler[_, _]) VisitBoolExpression ¶
func (c *Compiler[_, _]) VisitBoolExpression(expression *ast.BoolExpression) (_ struct{})
func (*Compiler[_, _]) VisitBreakStatement ¶
func (c *Compiler[_, _]) VisitBreakStatement(_ *ast.BreakStatement) (_ struct{})
func (*Compiler[_, _]) VisitCastingExpression ¶
func (c *Compiler[_, _]) VisitCastingExpression(expression *ast.CastingExpression) (_ struct{})
func (*Compiler[_, _]) VisitCompositeDeclaration ¶
func (c *Compiler[_, _]) VisitCompositeDeclaration(declaration *ast.CompositeDeclaration) (_ struct{})
func (*Compiler[_, _]) VisitConditionalExpression ¶
func (c *Compiler[_, _]) VisitConditionalExpression(expression *ast.ConditionalExpression) (_ struct{})
func (*Compiler[_, _]) VisitContinueStatement ¶
func (c *Compiler[_, _]) VisitContinueStatement(_ *ast.ContinueStatement) (_ struct{})
func (*Compiler[_, _]) VisitCreateExpression ¶
func (c *Compiler[_, _]) VisitCreateExpression(expression *ast.CreateExpression) (_ struct{})
func (*Compiler[_, _]) VisitDestroyExpression ¶
func (c *Compiler[_, _]) VisitDestroyExpression(expression *ast.DestroyExpression) (_ struct{})
func (*Compiler[_, _]) VisitDictionaryExpression ¶
func (c *Compiler[_, _]) VisitDictionaryExpression(dictionary *ast.DictionaryExpression) (_ struct{})
func (*Compiler[_, _]) VisitEmitStatement ¶
func (c *Compiler[_, _]) VisitEmitStatement(statement *ast.EmitStatement) (_ struct{})
func (*Compiler[_, _]) VisitEntitlementDeclaration ¶
func (c *Compiler[_, _]) VisitEntitlementDeclaration(_ *ast.EntitlementDeclaration) (_ struct{})
func (*Compiler[_, _]) VisitEntitlementMappingDeclaration ¶
func (c *Compiler[_, _]) VisitEntitlementMappingDeclaration(_ *ast.EntitlementMappingDeclaration) (_ struct{})
func (*Compiler[_, _]) VisitEnumCaseDeclaration ¶
func (c *Compiler[_, _]) VisitEnumCaseDeclaration(_ *ast.EnumCaseDeclaration) (_ struct{})
func (*Compiler[_, _]) VisitExpressionStatement ¶
func (c *Compiler[_, _]) VisitExpressionStatement(statement *ast.ExpressionStatement) (_ struct{})
func (*Compiler[_, _]) VisitFieldDeclaration ¶
func (c *Compiler[_, _]) VisitFieldDeclaration(_ *ast.FieldDeclaration) (_ struct{})
func (*Compiler[_, _]) VisitFixedPointExpression ¶
func (c *Compiler[_, _]) VisitFixedPointExpression(expression *ast.FixedPointExpression) (_ struct{})
func (*Compiler[_, _]) VisitForStatement ¶
func (c *Compiler[_, _]) VisitForStatement(statement *ast.ForStatement) (_ struct{})
func (*Compiler[_, _]) VisitForceExpression ¶
func (c *Compiler[_, _]) VisitForceExpression(expression *ast.ForceExpression) (_ struct{})
func (*Compiler[E, _]) VisitFunctionDeclaration ¶
func (c *Compiler[E, _]) VisitFunctionDeclaration(declaration *ast.FunctionDeclaration, _ bool) (_ struct{})
func (*Compiler[_, _]) VisitFunctionExpression ¶
func (c *Compiler[_, _]) VisitFunctionExpression(expression *ast.FunctionExpression) (_ struct{})
func (*Compiler[_, _]) VisitIdentifierExpression ¶
func (c *Compiler[_, _]) VisitIdentifierExpression(expression *ast.IdentifierExpression) (_ struct{})
func (*Compiler[_, _]) VisitIfStatement ¶
func (c *Compiler[_, _]) VisitIfStatement(statement *ast.IfStatement) (_ struct{})
func (*Compiler[_, _]) VisitImportDeclaration ¶
func (c *Compiler[_, _]) VisitImportDeclaration(declaration *ast.ImportDeclaration) (_ struct{})
func (*Compiler[_, _]) VisitIndexExpression ¶
func (c *Compiler[_, _]) VisitIndexExpression(expression *ast.IndexExpression) (_ struct{})
func (*Compiler[_, _]) VisitIntegerExpression ¶
func (c *Compiler[_, _]) VisitIntegerExpression(expression *ast.IntegerExpression) (_ struct{})
func (*Compiler[_, _]) VisitInterfaceDeclaration ¶
func (c *Compiler[_, _]) VisitInterfaceDeclaration(declaration *ast.InterfaceDeclaration) (_ struct{})
func (*Compiler[_, _]) VisitInvocationExpression ¶
func (c *Compiler[_, _]) VisitInvocationExpression(expression *ast.InvocationExpression) (_ struct{})
func (*Compiler[_, _]) VisitMemberExpression ¶
func (c *Compiler[_, _]) VisitMemberExpression(expression *ast.MemberExpression) (_ struct{})
func (*Compiler[_, _]) VisitNilExpression ¶
func (c *Compiler[_, _]) VisitNilExpression(_ *ast.NilExpression) (_ struct{})
func (*Compiler[_, _]) VisitPathExpression ¶
func (c *Compiler[_, _]) VisitPathExpression(expression *ast.PathExpression) (_ struct{})
func (*Compiler[_, _]) VisitPragmaDeclaration ¶
func (c *Compiler[_, _]) VisitPragmaDeclaration(_ *ast.PragmaDeclaration) (_ struct{})
func (*Compiler[_, _]) VisitReferenceExpression ¶
func (c *Compiler[_, _]) VisitReferenceExpression(expression *ast.ReferenceExpression) (_ struct{})
func (*Compiler[_, _]) VisitRemoveStatement ¶
func (c *Compiler[_, _]) VisitRemoveStatement(statement *ast.RemoveStatement) (_ struct{})
func (*Compiler[_, _]) VisitReturnStatement ¶
func (c *Compiler[_, _]) VisitReturnStatement(statement *ast.ReturnStatement) (_ struct{})
func (*Compiler[_, _]) VisitSpecialFunctionDeclaration ¶
func (c *Compiler[_, _]) VisitSpecialFunctionDeclaration(declaration *ast.SpecialFunctionDeclaration) (_ struct{})
func (*Compiler[_, _]) VisitStringExpression ¶
func (c *Compiler[_, _]) VisitStringExpression(expression *ast.StringExpression) (_ struct{})
func (*Compiler[_, _]) VisitStringTemplateExpression ¶
func (c *Compiler[_, _]) VisitStringTemplateExpression(expression *ast.StringTemplateExpression) (_ struct{})
func (*Compiler[_, _]) VisitSwapStatement ¶
func (c *Compiler[_, _]) VisitSwapStatement(statement *ast.SwapStatement) (_ struct{})
func (*Compiler[_, _]) VisitSwitchStatement ¶
func (c *Compiler[_, _]) VisitSwitchStatement(statement *ast.SwitchStatement) (_ struct{})
func (*Compiler[_, _]) VisitTransactionDeclaration ¶
func (c *Compiler[_, _]) VisitTransactionDeclaration(declaration *ast.TransactionDeclaration) (_ struct{})
func (*Compiler[_, _]) VisitUnaryExpression ¶
func (c *Compiler[_, _]) VisitUnaryExpression(expression *ast.UnaryExpression) (_ struct{})
func (*Compiler[_, _]) VisitVariableDeclaration ¶
func (c *Compiler[_, _]) VisitVariableDeclaration(declaration *ast.VariableDeclaration) (_ struct{})
func (*Compiler[_, _]) VisitVoidExpression ¶
func (c *Compiler[_, _]) VisitVoidExpression(_ *ast.VoidExpression) (_ struct{})
func (*Compiler[_, _]) VisitWhileStatement ¶
func (c *Compiler[_, _]) VisitWhileStatement(statement *ast.WhileStatement) (_ struct{})
type Config ¶
type Config struct {
MemoryGauge common.MemoryGauge
ImportHandler commons.ImportHandler
LocationHandler commons.LocationHandler
ElaborationResolver ElaborationResolver
// BuiltinGlobalsProvider provides the built-in globals for a given location.
// NOTE: all global imports must be for location nil!
BuiltinGlobalsProvider BuiltinGlobalsProvider
PeepholeOptimizationsEnabled bool
}
type DecodedConstant ¶ added in v1.8.0
type DecodedConstant = Constant[constant.ConstantData]
func NewDecodedConstant ¶ added in v1.8.0
func NewDecodedConstant( gauge common.MemoryGauge, index uint16, kind constant.Kind, data constant.ConstantData, ) *DecodedConstant
type DecodedTypeGen ¶
type DecodedTypeGen struct {
}
func (DecodedTypeGen) CompileType ¶
func (d DecodedTypeGen) CompileType(staticType bbq.StaticType) bbq.StaticType
type Desugar ¶
type Desugar struct {
// contains filtered or unexported fields
}
Desugar will rewrite the AST from high-level abstractions to a much lower-level abstractions, so the compiler and vm could work with a minimal set of language features.
func NewDesugar ¶
func NewDesugar( memoryGauge common.MemoryGauge, compilerConfig *Config, program *ast.Program, elaboration *DesugaredElaboration, location common.Location, ) *Desugar
func (*Desugar) DesugarFunctionExpression ¶
func (d *Desugar) DesugarFunctionExpression(expression *ast.FunctionExpression) *ast.FunctionExpression
func (*Desugar) DesugarInnerFunction ¶
func (d *Desugar) DesugarInnerFunction(declaration *ast.FunctionDeclaration) *ast.FunctionDeclaration
func (*Desugar) Run ¶
func (d *Desugar) Run() DesugaredProgram
Run desugars and rewrites the top-level declarations. It will not desugar/rewrite any statements or expressions.
func (*Desugar) VisitAttachmentDeclaration ¶
func (d *Desugar) VisitAttachmentDeclaration(declaration *ast.AttachmentDeclaration) ast.Declaration
func (*Desugar) VisitCompositeDeclaration ¶
func (d *Desugar) VisitCompositeDeclaration(declaration *ast.CompositeDeclaration) ast.Declaration
func (*Desugar) VisitEntitlementDeclaration ¶
func (d *Desugar) VisitEntitlementDeclaration(declaration *ast.EntitlementDeclaration) ast.Declaration
func (*Desugar) VisitEntitlementMappingDeclaration ¶
func (d *Desugar) VisitEntitlementMappingDeclaration(declaration *ast.EntitlementMappingDeclaration) ast.Declaration
func (*Desugar) VisitEnumCaseDeclaration ¶
func (d *Desugar) VisitEnumCaseDeclaration(declaration *ast.EnumCaseDeclaration) ast.Declaration
func (*Desugar) VisitFieldDeclaration ¶
func (d *Desugar) VisitFieldDeclaration(declaration *ast.FieldDeclaration) ast.Declaration
func (*Desugar) VisitFunctionDeclaration ¶
func (d *Desugar) VisitFunctionDeclaration(declaration *ast.FunctionDeclaration, _ bool) ast.Declaration
func (*Desugar) VisitImportDeclaration ¶
func (d *Desugar) VisitImportDeclaration(declaration *ast.ImportDeclaration) ast.Declaration
func (*Desugar) VisitInterfaceDeclaration ¶
func (d *Desugar) VisitInterfaceDeclaration(declaration *ast.InterfaceDeclaration) ast.Declaration
func (*Desugar) VisitPragmaDeclaration ¶
func (d *Desugar) VisitPragmaDeclaration(declaration *ast.PragmaDeclaration) ast.Declaration
func (*Desugar) VisitSpecialFunctionDeclaration ¶
func (d *Desugar) VisitSpecialFunctionDeclaration(declaration *ast.SpecialFunctionDeclaration) ast.Declaration
func (*Desugar) VisitTransactionDeclaration ¶
func (d *Desugar) VisitTransactionDeclaration(transaction *ast.TransactionDeclaration) ast.Declaration
func (*Desugar) VisitVariableDeclaration ¶
func (d *Desugar) VisitVariableDeclaration(declaration *ast.VariableDeclaration) ast.Declaration
type DesugaredElaboration ¶
type DesugaredElaboration struct {
// contains filtered or unexported fields
}
func NewDesugaredElaboration ¶
func NewDesugaredElaboration(elaboration *sema.Elaboration) *DesugaredElaboration
func (*DesugaredElaboration) AllImportDeclarationsResolvedLocations ¶
func (e *DesugaredElaboration) AllImportDeclarationsResolvedLocations() map[*ast.ImportDeclaration][]sema.ResolvedLocation
func (*DesugaredElaboration) ArrayExpressionTypes ¶
func (e *DesugaredElaboration) ArrayExpressionTypes(expression *ast.ArrayExpression) sema.ArrayExpressionTypes
func (*DesugaredElaboration) AssignmentStatementTypes ¶
func (e *DesugaredElaboration) AssignmentStatementTypes(assignment *ast.AssignmentStatement) sema.AssignmentStatementTypes
func (*DesugaredElaboration) AttachTypes ¶ added in v1.8.0
func (e *DesugaredElaboration) AttachTypes(expression *ast.AttachExpression) sema.AttachExpressionTypes
func (*DesugaredElaboration) AttachmentAccessTypes ¶ added in v1.8.0
func (e *DesugaredElaboration) AttachmentAccessTypes(expression *ast.IndexExpression) (ty sema.Type, ok bool)
func (*DesugaredElaboration) AttachmentRemoveTypes ¶ added in v1.8.0
func (e *DesugaredElaboration) AttachmentRemoveTypes(statement *ast.RemoveStatement) (ty sema.Type)
func (*DesugaredElaboration) CastingExpressionTypes ¶
func (e *DesugaredElaboration) CastingExpressionTypes(expression *ast.CastingExpression) sema.CastingExpressionTypes
func (*DesugaredElaboration) CompositeDeclarationType ¶
func (e *DesugaredElaboration) CompositeDeclarationType(declaration ast.CompositeLikeDeclaration) *sema.CompositeType
func (*DesugaredElaboration) CompositeType ¶
func (e *DesugaredElaboration) CompositeType(typeID common.TypeID) *sema.CompositeType
func (*DesugaredElaboration) DefaultDestroyDeclaration ¶
func (e *DesugaredElaboration) DefaultDestroyDeclaration(declaration ast.Declaration) *ast.CompositeDeclaration
func (*DesugaredElaboration) DictionaryExpressionTypes ¶
func (e *DesugaredElaboration) DictionaryExpressionTypes(expression *ast.DictionaryExpression) sema.DictionaryExpressionTypes
func (*DesugaredElaboration) EmitStatementEventType ¶
func (e *DesugaredElaboration) EmitStatementEventType(statement *ast.EmitStatement) *sema.CompositeType
func (*DesugaredElaboration) EntitlementMapType ¶
func (e *DesugaredElaboration) EntitlementMapType(typeID common.TypeID) *sema.EntitlementMapType
func (*DesugaredElaboration) EntitlementType ¶
func (e *DesugaredElaboration) EntitlementType(typeID common.TypeID) *sema.EntitlementType
func (*DesugaredElaboration) EnumLookupFunctionType ¶
func (e *DesugaredElaboration) EnumLookupFunctionType(enumType *sema.CompositeType) *sema.FunctionType
func (*DesugaredElaboration) FixedPointExpressionType ¶
func (e *DesugaredElaboration) FixedPointExpressionType(expression *ast.FixedPointExpression) sema.Type
func (*DesugaredElaboration) ForStatementType ¶
func (e *DesugaredElaboration) ForStatementType(statement *ast.ForStatement) (types sema.ForStatementTypes)
func (*DesugaredElaboration) FunctionDeclarationFunctionType ¶
func (e *DesugaredElaboration) FunctionDeclarationFunctionType(declaration *ast.FunctionDeclaration) *sema.FunctionType
func (*DesugaredElaboration) FunctionExpressionFunctionType ¶
func (e *DesugaredElaboration) FunctionExpressionFunctionType(expression *ast.FunctionExpression) *sema.FunctionType
func (*DesugaredElaboration) GetGlobalType ¶
func (e *DesugaredElaboration) GetGlobalType(name string) (*sema.Variable, bool)
func (*DesugaredElaboration) IndexExpressionTypes ¶
func (e *DesugaredElaboration) IndexExpressionTypes(expression *ast.IndexExpression) (types sema.IndexExpressionTypes, contains bool)
func (*DesugaredElaboration) IntegerExpressionType ¶
func (e *DesugaredElaboration) IntegerExpressionType(expression *ast.IntegerExpression) sema.Type
func (*DesugaredElaboration) InterfaceDeclarationType ¶
func (e *DesugaredElaboration) InterfaceDeclarationType(decl *ast.InterfaceDeclaration) *sema.InterfaceType
func (*DesugaredElaboration) InterfaceType ¶
func (e *DesugaredElaboration) InterfaceType(typeID common.TypeID) *sema.InterfaceType
func (*DesugaredElaboration) InterfaceTypeDeclaration ¶
func (e *DesugaredElaboration) InterfaceTypeDeclaration(interfaceType *sema.InterfaceType) *ast.InterfaceDeclaration
func (*DesugaredElaboration) InvocationExpressionTypes ¶
func (e *DesugaredElaboration) InvocationExpressionTypes( expression *ast.InvocationExpression, ) sema.InvocationExpressionTypes
func (*DesugaredElaboration) IsInterfaceMethodStaticCall ¶
func (e *DesugaredElaboration) IsInterfaceMethodStaticCall(invocation *ast.InvocationExpression) bool
func (*DesugaredElaboration) IsNestedResourceMoveExpression ¶
func (e *DesugaredElaboration) IsNestedResourceMoveExpression(expression ast.Expression) bool
func (*DesugaredElaboration) MemberExpressionMemberAccessInfo ¶
func (e *DesugaredElaboration) MemberExpressionMemberAccessInfo(expression *ast.MemberExpression) (memberInfo sema.MemberAccessInfo, ok bool)
func (*DesugaredElaboration) OriginalElaboration ¶
func (e *DesugaredElaboration) OriginalElaboration() *sema.Elaboration
OriginalElaboration returns the underlying elaboration. IMPORTANT: Only use the original elaboration for type-checking use-cases. It is safe to use in type-checker, since the type checker doesn't rely on extra information added by the desugar phase. Never use it in the compiler or desugar, as it may not include the type information added during the desugar phase.
func (*DesugaredElaboration) PostConditionsRewrite ¶
func (e *DesugaredElaboration) PostConditionsRewrite(conditions *ast.Conditions) sema.PostConditionsRewrite
func (*DesugaredElaboration) ReferenceExpressionBorrowType ¶
func (e *DesugaredElaboration) ReferenceExpressionBorrowType(expression *ast.ReferenceExpression) sema.Type
func (*DesugaredElaboration) ResultVariableType ¶
func (*DesugaredElaboration) ReturnStatementTypes ¶
func (e *DesugaredElaboration) ReturnStatementTypes(statement *ast.ReturnStatement) sema.ReturnStatementTypes
func (*DesugaredElaboration) SetArrayExpressionTypes ¶
func (e *DesugaredElaboration) SetArrayExpressionTypes(expression *ast.ArrayExpression, types sema.ArrayExpressionTypes)
func (*DesugaredElaboration) SetAssignmentStatementTypes ¶
func (e *DesugaredElaboration) SetAssignmentStatementTypes( assignment *ast.AssignmentStatement, types sema.AssignmentStatementTypes, )
func (*DesugaredElaboration) SetCompositeDeclarationType ¶
func (e *DesugaredElaboration) SetCompositeDeclarationType( declaration ast.CompositeLikeDeclaration, compositeType *sema.CompositeType, )
func (*DesugaredElaboration) SetCompositeType ¶
func (e *DesugaredElaboration) SetCompositeType(typeID common.TypeID, compositeType *sema.CompositeType)
func (*DesugaredElaboration) SetEmitStatementEventType ¶
func (e *DesugaredElaboration) SetEmitStatementEventType(statement *ast.EmitStatement, compositeType *sema.CompositeType)
func (*DesugaredElaboration) SetFunctionDeclarationFunctionType ¶
func (e *DesugaredElaboration) SetFunctionDeclarationFunctionType( declaration *ast.FunctionDeclaration, functionType *sema.FunctionType, )
func (*DesugaredElaboration) SetFunctionExpressionFunctionType ¶
func (e *DesugaredElaboration) SetFunctionExpressionFunctionType( expression *ast.FunctionExpression, functionType *sema.FunctionType, )
func (*DesugaredElaboration) SetIntegerExpressionType ¶
func (e *DesugaredElaboration) SetIntegerExpressionType(expression *ast.IntegerExpression, valueType sema.Type)
func (*DesugaredElaboration) SetInterfaceDeclarationType ¶
func (e *DesugaredElaboration) SetInterfaceDeclarationType(decl *ast.InterfaceDeclaration, interfaceType *sema.InterfaceType)
func (*DesugaredElaboration) SetInterfaceMethodStaticCall ¶
func (e *DesugaredElaboration) SetInterfaceMethodStaticCall(invocation *ast.InvocationExpression)
func (*DesugaredElaboration) SetInvocationExpressionTypes ¶
func (e *DesugaredElaboration) SetInvocationExpressionTypes( expression *ast.InvocationExpression, types sema.InvocationExpressionTypes, )
func (*DesugaredElaboration) SetMemberExpressionMemberAccessInfo ¶
func (e *DesugaredElaboration) SetMemberExpressionMemberAccessInfo(expression *ast.MemberExpression, memberAccessInfo sema.MemberAccessInfo)
func (*DesugaredElaboration) SetReferenceExpressionBorrowType ¶
func (e *DesugaredElaboration) SetReferenceExpressionBorrowType(expression *ast.ReferenceExpression, ty sema.Type)
func (*DesugaredElaboration) SetResultVariableType ¶
func (e *DesugaredElaboration) SetResultVariableType(declaration ast.Element, typ sema.Type)
func (*DesugaredElaboration) SetReturnStatementTypes ¶
func (e *DesugaredElaboration) SetReturnStatementTypes(statement *ast.ReturnStatement, types sema.ReturnStatementTypes)
func (*DesugaredElaboration) SetVariableDeclarationTypes ¶
func (e *DesugaredElaboration) SetVariableDeclarationTypes( declaration *ast.VariableDeclaration, types sema.VariableDeclarationTypes, )
func (*DesugaredElaboration) StringExpressionType ¶
func (e *DesugaredElaboration) StringExpressionType(expression *ast.StringExpression) sema.Type
func (*DesugaredElaboration) SwapStatementTypes ¶
func (e *DesugaredElaboration) SwapStatementTypes(statement *ast.SwapStatement) sema.SwapStatementTypes
func (*DesugaredElaboration) TransactionDeclarationType ¶
func (e *DesugaredElaboration) TransactionDeclarationType(declaration *ast.TransactionDeclaration) *sema.TransactionType
func (*DesugaredElaboration) VariableDeclarationTypes ¶
func (e *DesugaredElaboration) VariableDeclarationTypes(declaration *ast.VariableDeclaration) sema.VariableDeclarationTypes
type DesugaredProgram ¶
type DesugaredProgram struct {
// contains filtered or unexported fields
}
type ElaborationResolver ¶
type ElaborationResolver func(location common.Location) (*DesugaredElaboration, error)
type EncodedTypeGen ¶
type EncodedTypeGen struct {
}
func (EncodedTypeGen) CompileType ¶
func (d EncodedTypeGen) CompileType(staticType bbq.StaticType) []byte
type GlobalImport ¶
type GlobalImport struct {
Location common.Location
// Need to maintain both "qualified" and "unqualified" names for a given import,
// because when type-aliasing is used, imported name becomes qualified.
// However, the same import must use the unqualified name when linking.
// TODO: We can simplify this by always using qualified names for all imports.
QualifiedName string
Name string
}
func NewGlobalImport ¶ added in v1.8.0
func NewGlobalImport(name string) GlobalImport
type InstructionCodeGen ¶
type InstructionCodeGen struct {
// contains filtered or unexported fields
}
InstructionCodeGen is a CodeGen implementation that emits opcode.Instruction
func (*InstructionCodeGen) Emit ¶
func (g *InstructionCodeGen) Emit(instruction opcode.Instruction)
func (*InstructionCodeGen) LastInstruction ¶
func (g *InstructionCodeGen) LastInstruction() opcode.Instruction
func (*InstructionCodeGen) Offset ¶
func (g *InstructionCodeGen) Offset() int
func (*InstructionCodeGen) PatchJump ¶
func (g *InstructionCodeGen) PatchJump(offset int, newTarget uint16)
func (*InstructionCodeGen) SetTarget ¶
func (g *InstructionCodeGen) SetTarget(target *[]opcode.Instruction)
type PeepholeInstructionStaticTypeOptimizer ¶ added in v1.8.4
type PeepholeInstructionStaticTypeOptimizer struct {
// contains filtered or unexported fields
}
func (*PeepholeInstructionStaticTypeOptimizer) Optimize ¶ added in v1.8.4
func (o *PeepholeInstructionStaticTypeOptimizer) Optimize(code []opcode.Instruction) []opcode.Instruction
func (*PeepholeInstructionStaticTypeOptimizer) OptimizeInstructions ¶ added in v1.8.4
func (o *PeepholeInstructionStaticTypeOptimizer) OptimizeInstructions(instructions []opcode.Instruction) []opcode.Instruction
type PeepholeNoopOptimizer ¶ added in v1.8.4
type PeepholeNoopOptimizer[E any] struct { }
func (PeepholeNoopOptimizer[E]) Optimize ¶ added in v1.8.4
func (PeepholeNoopOptimizer[E]) Optimize(code []E) []E
type PeepholeOptimizer ¶ added in v1.8.4
type PeepholeOptimizer[E any] interface { Optimize(code []E) []E }
func NewPeepholeOptimizer ¶ added in v1.8.4
func NewPeepholeOptimizer[E, T any](compiler *Compiler[E, T]) PeepholeOptimizer[E]
type PeepholePattern ¶ added in v1.8.4
type PeepholePattern struct {
Name string
// never match a jump instruction
Opcodes []opcode.Opcode
Replacement func(instructions []opcode.Instruction, compiler *Compiler[opcode.Instruction, interpreter.StaticType]) []opcode.Instruction
}
func (*PeepholePattern) Match ¶ added in v1.8.4
func (p *PeepholePattern) Match(instructions []opcode.Instruction, bytecodeOffset int, jumpTargets map[int]struct{}) bool
type TypeGen ¶
type TypeGen[T any] interface { CompileType(staticType bbq.StaticType) T }