Documentation ¶
Index ¶
- Variables
- func ExampleDecodeEmbed(b64encoded string, key string) []byte
- func GetDefaultImportNamespace(ip string) string
- func IsBuiltInGoType(s string) bool
- func IsDefaultImport(ip string) bool
- type Compiler
- func (c *Compiler) AddScript(scriptPath string) error
- func (c *Compiler) BuildGolangASTs() error
- func (c *Compiler) BuildNativeBinary() error
- func (c *Compiler) CreateBuildDir() error
- func (c *Compiler) CreateEntryPoint() error
- func (c *Compiler) DetectVersions() error
- func (c *Compiler) Do() error
- func (c *Compiler) EncodeAssets() error
- func (c *Compiler) GatherAssets() error
- func (c *Compiler) GetIDLiterals() []string
- func (c *Compiler) InitializeImports() error
- func (c *Compiler) IsProductionBuild() bool
- func (c *Compiler) LocateGoDependencies() error
- func (c *Compiler) MapVMsByPriority() error
- func (c *Compiler) PerformPostCompileObfuscation() error
- func (c *Compiler) PerformPreCompileObfuscation() error
- func (c *Compiler) ProcessMacros() error
- func (c *Compiler) SanityCheckScriptToNativeMapping() error
- func (c *Compiler) SanityCheckSwizzles() error
- func (c *Compiler) SetLogger(l logger.Logger)
- func (c *Compiler) SwizzleNativeCalls() error
- func (c *Compiler) WalkGenesisASTs() error
- func (c *Compiler) WritePreloads() error
- func (c *Compiler) WriteScripts() error
- func (c *Compiler) WriteVMBundles() error
- type EmbeddedFile
- type FunctionCall
- type GenesisVM
- func (g *GenesisVM) BuildGolangAST() error
- func (g *GenesisVM) CacheAssets() error
- func (g *GenesisVM) DetectTargetEngineVersion() error
- func (g *GenesisVM) EnableStandardLibrary(name string) (*GoPackage, error)
- func (g *GenesisVM) EncodeBundledAssets() error
- func (g *GenesisVM) FunctionKey(k string) string
- func (g *GenesisVM) GenerateFunctionKeys()
- func (g *GenesisVM) GetIDLiterals() []string
- func (g *GenesisVM) GetMaskedImports() []*MaskedImport
- func (g *GenesisVM) GetNewDecryptionKey() string
- func (g *GenesisVM) GetSimpleMacroValue(key string) string
- func (g *GenesisVM) GetTimeout() int
- func (g *GenesisVM) HasDebuggingEnabled() bool
- func (g *GenesisVM) HasLoggingEnabled() bool
- func (g *GenesisVM) InitializeGoImports() error
- func (g *GenesisVM) LocateGoPackages() error
- func (g *GenesisVM) Priority() int
- func (g *GenesisVM) ProcessMacros() error
- func (g *GenesisVM) RenderVMBundle(templateFile string) error
- func (g *GenesisVM) RetrieveAsset(m *Macro) error
- func (g *GenesisVM) SanityCheckLinkedSymbols() error
- func (g *GenesisVM) SanityCheckNativeFunctionCalls() error
- func (g *GenesisVM) ShouldIncludeAssetPackage() bool
- func (g *GenesisVM) SwizzleNativeFunctionCalls() error
- func (g *GenesisVM) UnresolvedGoPackages() []string
- func (g *GenesisVM) WalkGenesisAST() error
- func (g *GenesisVM) WalkGoPackageAST(gop *GoPackage, wg *sync.WaitGroup, errChan chan error)
- func (g *GenesisVM) WriteGenesisScript(name string, src []byte) (*EmbeddedFile, error)
- func (g *GenesisVM) WritePreload() error
- func (g *GenesisVM) WriteScript() error
- func (g *GenesisVM) WriteVMBundle() error
- type GoConst
- type GoPackage
- func (gop *GoPackage) NewConst(name string) *GoConst
- func (gop *GoPackage) NewGoVar(goast *ast.File, vs *ast.ValueSpec, offset int, ident *ast.Ident, ...) (*GoVar, error)
- func (gop *GoPackage) ParseFuncDecl(goast *ast.File, funcdecl *ast.FuncDecl, wg *sync.WaitGroup, ...)
- func (gop *GoPackage) ParseStructDef(goast *ast.File, v *ast.TypeSpec, t *ast.StructType, wg *sync.WaitGroup, ...)
- func (gop *GoPackage) ParseTypeSpec(goast *ast.File, v *ast.TypeSpec, wg *sync.WaitGroup, errChan chan error)
- func (gop *GoPackage) ParseVarSpec(goast *ast.File, vardecl *ast.ValueSpec, offset int, wg *sync.WaitGroup, ...)
- func (gop *GoPackage) SanityCheckScriptCallers() error
- func (gop *GoPackage) SuccessfullyLinkedFuncs() []*LinkedFunction
- func (gop *GoPackage) ValidVars() []*GoVar
- func (gop *GoPackage) WalkGoFileAST(goast *ast.File, wg *sync.WaitGroup, errChan chan error)
- type GoParamDef
- func (p *GoParamDef) BuiltInJSType() string
- func (p *GoParamDef) BuiltInTranslationRequired() bool
- func (p *GoParamDef) Interpret(i interface{}) error
- func (p *GoParamDef) MappedType(pkg, sel string) string
- func (p *GoParamDef) ParseArrayType(a *ast.ArrayType) error
- func (p *GoParamDef) ParseIdent(a *ast.Ident) error
- func (p *GoParamDef) ParseInterfaceType(i *ast.InterfaceType) error
- func (p *GoParamDef) ParseMapType(a *ast.MapType) error
- func (p *GoParamDef) ParseSelectorExpr(a *ast.SelectorExpr) error
- func (p *GoParamDef) ParseStarExpr(a *ast.StarExpr) error
- type GoStructDef
- type GoVar
- type LegacyArgDef
- type LegacyFunctionCall
- type LegacyLibrary
- type LegacyRetDef
- type LinkedFunction
- func (l *LinkedFunction) CanResolveImportDep(pkg string) (string, error)
- func (l *LinkedFunction) GenerateArgString(prefix string) string
- func (l *LinkedFunction) GenerateReturnString(prefix string) string
- func (l *LinkedFunction) SwizzleToTheLeft() error
- func (l *LinkedFunction) SwizzleToTheRight() error
- type Linker
- type Macro
- type MaskedImport
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultPriority is the default value for a script's priority during execution DefaultPriority = 100 // DefaultTimeout is the default time in seconds a script will be allowed to run DefaultTimeout = 30 )
var ( //CallablesByEngineVersion is a table that maps the entry points to the expected script versions CallablesByEngineVersion = map[int][]string{ 1: []string{ "BeforeDeploy", "Deploy", "AfterDeploy", }, 2: []string{ "Deploy", }, } )
var ( // NamespaceConversionMap is a temporary mapping to allow genesis scripts // written in the v0 specification to be backwards compatible with v1 scripts. // The major difference is that v1 did not have namespaces for the standard library // where as v1 implements them with a deprecation and v2 will remove them entirely NamespaceConversionMap = map[string]*LegacyFunctionCall{} )
Functions ¶
func ExampleDecodeEmbed ¶
ExampleDecodeEmbed is a reference implementation of how embedded assets should be unpacked inside of a genesis engine
func GetDefaultImportNamespace ¶
GetDefaultImportNamespace returns the corrasponding namespace to the import path provided that is used in the intermediate representation
func IsBuiltInGoType ¶
IsBuiltInGoType takes a string argument and determines if is a valid built-in type in golang
func IsDefaultImport ¶
IsDefaultImport tests a golang import path to determine if it is already defined in the intermediate representation
Types ¶
type Compiler ¶
type Compiler struct { // lock to prevent race conditions during compilation sync.RWMutex // array of VMs that will be bundled into this build VMs []*GenesisVM // a map that places subsets of VMs into buckets according to their priority SortedVMs map[int][]*GenesisVM // logging object to be used Logger logger.Logger // a slice of unique priorities that can be found within this VMs bundled into this build UniqPriorities []int // configuration object for the compiler computil.Options // contains filtered or unexported fields }
Compiler is the primary type for building native binaries with gscript
func (*Compiler) AddScript ¶
AddScript attempts to create a virtual machine object based on the given parameter to be included in compilation
func (*Compiler) BuildGolangASTs ¶
BuildGolangASTs enumerates each genesis vm's golang native packages and matches exported function declarations to their genesis script caller. This creates a reference in the VM's linker object which will be used to generate native interfaces between the genesis VM and the underlying golang packages.
func (*Compiler) BuildNativeBinary ¶
BuildNativeBinary uses the golang compiler to attempt to build a native binary for the target platform specified in the compiler options
func (*Compiler) CreateBuildDir ¶
CreateBuildDir creates the compiler's build directory, with an additional asset directory as well
func (*Compiler) CreateEntryPoint ¶
CreateEntryPoint renders the final main() entry point for the final binary in the build directory
func (*Compiler) DetectVersions ¶
DetectVersions enumerates all VMs to determine the engine version based on the entrypoint. For more information on this, look at GenesisVM.DetectTargetEngineVersion()
func (*Compiler) EncodeAssets ¶
EncodeAssets renders all embedded assets into intermediate representation
func (*Compiler) GatherAssets ¶
GatherAssets enumerates all bundled virtual machines for any embedded assets and copies them into the build directory's asset cache
func (*Compiler) GetIDLiterals ¶
GetIDLiterals returns all interesting IDs used by this compiler
func (*Compiler) InitializeImports ¶
InitializeImports enumerates the compiler's genesis VMs and writes a cached version of the genesis source to the asset directory to prevent race condiditons with script filesystem locations
func (*Compiler) IsProductionBuild ¶
IsProductionBuild is an convienience method for checking to see if dumping a stack trace should be disabled for production builds
func (*Compiler) LocateGoDependencies ¶
LocateGoDependencies gathers a list of all installed golang packages, hands a copy to each VM, then has every VM resolve it's own golang dependencies from that package list
func (*Compiler) MapVMsByPriority ¶
MapVMsByPriority creates a pointer mapping of each VM by it's unique priority
func (*Compiler) PerformPostCompileObfuscation ¶
PerformPostCompileObfuscation runs the post-compilation obfuscation routines on compiled binary
func (*Compiler) PerformPreCompileObfuscation ¶
PerformPreCompileObfuscation runs the pre-compilation obfuscation routines on the intermediate representation
func (*Compiler) ProcessMacros ¶
ProcessMacros enumerates the compilers virtual machines with the pre-processor to extract compiler macros for each virtual machine
func (*Compiler) SanityCheckScriptToNativeMapping ¶
SanityCheckScriptToNativeMapping enumerates all VMs ensuring that the script calls to native functions actually exist within that native go package and were resolved by the linker
func (*Compiler) SanityCheckSwizzles ¶
SanityCheckSwizzles enumerates all VMs to make sure their linked native functions are being called correctly by the corrasponding javascript callers
func (*Compiler) SetLogger ¶
SetLogger overrides the logger for the compiler (defaults to an engine.NullLogger)
func (*Compiler) SwizzleNativeCalls ¶
SwizzleNativeCalls enumerates all native golang function calls mapped to genesis script function calls and generates the type declarations for both arguments and return values.
func (*Compiler) WalkGenesisASTs ¶
WalkGenesisASTs scans all genesis VMs scripts to identify Golang packages that have been called from inside the script using the namespace identifier from the compiler macros
func (*Compiler) WritePreloads ¶
WritePreloads renders preload libraries for every virtual machine in the compilers asset directory
func (*Compiler) WriteScripts ¶
WriteScripts enumerates the compiler's genesis VMs and writes a cached version of the genesis source to the asset directory to prevent race condiditons with script filesystem locations
func (*Compiler) WriteVMBundles ¶
WriteVMBundles writes the intermediate representation for each virtual machine to it's vm bundle file within the build directory
type EmbeddedFile ¶
type EmbeddedFile struct { // local file path to the target file SourcePath string // url to the target file (optional) CachedPath string // the composite ($ID_$OrigName) filename of the referenced file Filename string // the original basename of the referenced file OrigName string // unique identifier that is used by the compiler to reference file contents ID string // unique identifier that is used by the compiler to swizzle the file decoding and decrypting into a function pointer FuncID string // uncompressed embedded file data Uncompressed []byte // compressed embedded file data Compressed []byte // used to AES encrypt the embedded assets EncryptionKey []byte // temporary buffer used to generate the intermediate representation of the compressed data EmbedData *bytes.Buffer }
EmbeddedFile is an object that manages the lifecycle of resolving and translating embedded assets referenced in the Genesis VM into callable values that are embedded by the compiler
func NewEmbeddedFile ¶
func NewEmbeddedFile(source string, key []byte) (*EmbeddedFile, error)
NewEmbeddedFile takes a path on the local file system and returns an EmbeddedFile object reference
func (*EmbeddedFile) CacheFile ¶
func (e *EmbeddedFile) CacheFile(cacheDir string) error
CacheFile attempts to copy the files original location (e.SourcePath) to the destination cacheDir provided as an argument to this function call
func (*EmbeddedFile) Data ¶
func (e *EmbeddedFile) Data() string
Data retrieves the current EmbedData's buffer as a string
func (*EmbeddedFile) GenerateEmbedData ¶
func (e *EmbeddedFile) GenerateEmbedData() error
GenerateEmbedData enumerates the compressed embed and creates a byte slice representation of it
type FunctionCall ¶
type FunctionCall struct { // genesis vm namespace the function call corrasponds to Namespace string // name of the function call as used in the genesis vm FuncName string // list of arguments passed to the genesis vm function caller ArgumentList []gast.Expression }
FunctionCall contains information relating to a Golang native function call that is being used within a genesis vm
type GenesisVM ¶
type GenesisVM struct { // mutex for compiler manipulation sync.RWMutex // generated script ID ID string `json:"id"` // Absolute path to the script file SourceFile string `json:"source"` // map of embedded files Embeds map[string]*EmbeddedFile // name of the script (base name of file) Name string // raw script contents Data []byte // FileSet for parsing the genesis ASTs FileSet *gfile.FileSet // represents script as an GenesisAST GenesisAST *gast.Program // holds the value of parsed macros Macros []*Macro // maps the current build environment's golang imports // key = golang import path // value = reference to go package object GoPackageByImport map[string]*GoPackage // maps the namespace of genesis go imports to their // corrasponding go packages // key = genesis import namespace // value = reference to a go package object GoPackageByNamespace map[string]*GoPackage // StandardLibraries holds all references to used genesis standard library // packages that will be included in the build EnabledStandardLibs map[string]*GoPackage // required operating system for this script (GOOS) RequiredOS string // required architecture for this script (GOARCH) RequiredArch string // Object that holds the translation targets between golang and gscript Linker *Linker // maintains a map of the function names to the obfuscated references EntryPointMapping map[string]string // unique variable name to reference this scripts entry point PreloadAlias string // list of functions that need to be waterfalled for successful execution of the VM // usually either single element (Deploy) or the legacy compatible BeforeDeploy, Deploy, AfterDeploy EngineVersion int // reference to compiler options computil.Options // GenesisFile holds the intermediate representation of this VM's bundle code GenesisFile *bytes.Buffer // Logger to publish output from Logger logger.Logger // EnginePackage is the go package this engine should use EnginePackage *GoPackage // StandardLibs holds references to all possible standard libs StandardLibs map[string]*GoPackage }
GenesisVM is the object representation of a genesis script including it's imports and dynamic linking targets
func NewGenesisVM ¶
func NewGenesisVM(name, path string, data []byte, prog *gast.Program, opts computil.Options, logger logger.Logger) *GenesisVM
NewGenesisVM creates a new virtual machine object for the compiler
func (*GenesisVM) BuildGolangAST ¶
BuildGolangAST walks the golang packages imported into the script to build a mapping of functions, the files they're in, imports to each file (for aliases), and locations in the genesis script where these are referenced
func (*GenesisVM) CacheAssets ¶
CacheAssets indexes all //import: compiler macros and retrieves the corrasponding asset
func (*GenesisVM) DetectTargetEngineVersion ¶
DetectTargetEngineVersion examines the genesis script's GenesisAST to determine whether required top level functions exist, and if so, for what version of the engine they target. This mapping can be found in CallablesByEngineVersion
func (*GenesisVM) EnableStandardLibrary ¶
EnableStandardLibrary attempts to resolve a discovered standard library and returns either the package or an error
func (*GenesisVM) EncodeBundledAssets ¶
EncodeBundledAssets encodes all assets within the asset pack into their compressed format
func (*GenesisVM) FunctionKey ¶
FunctionKey is used by the intermediate representation generator to map specific functions in the virtual machine's constructors to unique identifiers in the IR
func (*GenesisVM) GenerateFunctionKeys ¶
func (g *GenesisVM) GenerateFunctionKeys()
GenerateFunctionKeys creates random functions for the various parts of the VM's source file
func (*GenesisVM) GetIDLiterals ¶
GetIDLiterals returns all interesting IDs used by this GenesisVM
func (*GenesisVM) GetMaskedImports ¶
func (g *GenesisVM) GetMaskedImports() []*MaskedImport
GetMaskedImports is a helper function to gather the masked imports during rendering of the vm bundle
func (*GenesisVM) GetNewDecryptionKey ¶
GetNewDecryptionKey creates a new decryption key
func (*GenesisVM) GetSimpleMacroValue ¶
GetSimpleMacroValue returns a string of the VM's macro defined by key argument
func (*GenesisVM) GetTimeout ¶
GetTimeout attempts to get the timeout value set in the macro (if it was set)
func (*GenesisVM) HasDebuggingEnabled ¶
HasDebuggingEnabled is an convienience method for checking to see if the debugger should be included
func (*GenesisVM) HasLoggingEnabled ¶
HasLoggingEnabled is an convienience method for checking to see if logging should be included
func (*GenesisVM) InitializeGoImports ¶
InitializeGoImports enumerates the go_import macros to initialize mappings for dynamic linking
func (*GenesisVM) LocateGoPackages ¶
LocateGoPackages enumerates the installed go packages on the current system and appends directory and namespace information to golang packages being declared by this script
func (*GenesisVM) Priority ¶
Priority returns the priority value if defined in the macros, else returns default
func (*GenesisVM) ProcessMacros ¶
ProcessMacros runs the preprocessor to locate and extract genesis macro's out of the script to be used during compilation
func (*GenesisVM) RenderVMBundle ¶
RenderVMBundle generates the virtual machine's bundled intermediate representation file
func (*GenesisVM) RetrieveAsset ¶
RetrieveAsset attempts to copy the asset into the build directory
func (*GenesisVM) SanityCheckLinkedSymbols ¶
SanityCheckLinkedSymbols checks to make sure all linked functions do not violate caller conventions between the javascript and golang method signatures.
func (*GenesisVM) SanityCheckNativeFunctionCalls ¶
SanityCheckNativeFunctionCalls enumerates the VMs go packages ensuring that there are no script callers who do not exist within the GoPackage symbol table
func (*GenesisVM) ShouldIncludeAssetPackage ¶
ShouldIncludeAssetPackage is a helper function for VM bundle rendering to asset whether it needs to create asset functions in the intermediate representation
func (*GenesisVM) SwizzleNativeFunctionCalls ¶
SwizzleNativeFunctionCalls enumerates all LinkedFunctions held by the linker and generates structured mappings of both arguments (left swizzle) and returns (right swizzle) so the compiler can map the function's shim in the intermediate representation
func (*GenesisVM) UnresolvedGoPackages ¶
UnresolvedGoPackages enumerates the import table to determine if any packages have not been resolved to local dependencies yet. Returns a string slice of go import paths that have yet to be resolved.
func (*GenesisVM) WalkGenesisAST ¶
WalkGenesisAST walks the genesis script in order to inspect function calls that should be targeted for both legacy dynamic linking as well as native golang dynamic linking. Reference type genesisWalker and it's associated functions inside genesis_ast.go
func (*GenesisVM) WalkGoPackageAST ¶
WalkGoPackageAST parses the GoPackage directory for all AST files and concurrently walks each child file's AST looking for functions that should be included by the linker
func (*GenesisVM) WriteGenesisScript ¶
func (g *GenesisVM) WriteGenesisScript(name string, src []byte) (*EmbeddedFile, error)
WriteGenesisScript writes a genesis script to the asset directory and returns a reference to an embeddedfile for use by the compiler
func (*GenesisVM) WritePreload ¶
WritePreload writes the preload library to the asset directory and tags it in the embed table as the preload library for the virtual machine
func (*GenesisVM) WriteScript ¶
WriteScript writes the initial user supplied script to the asset directory and tags it in the embed table as the entry point for the user defined functions
func (*GenesisVM) WriteVMBundle ¶
WriteVMBundle generates the VM bundle's intermediate representation using RenderVMBundle and then writes it to the compilers build directory
type GoConst ¶
type GoConst struct { // Name refers to the const name within the package Name string // Key refers to the unique identifier for a const in the intermediate representation Key string }
GoConst defines the name of a golang constant declaration
type GoPackage ¶
type GoPackage struct { sync.RWMutex // Dir is the local path where this package is found Dir string // MaskedName is the masked import representation of this gopackage MaskedName string // ImportPath is the golang import path used for this package ImportPath string // Name defines the go package's name Name string // VM references the script that is importing this package VM *GenesisVM // Namespace is the namespace aliased in the parent script Namespace string // ImportKey is the import path defined in the parent script ImportKey string // ScriptCallers maps the go package function names to genesis AST function calls ScriptCallers map[string]*FunctionCall // ImportsByFile is the map of each file within the package and what dependencies it imports ImportsByFile map[string][]*ast.ImportSpec // ImportsByAlias is a map of each import's alias and its dependency information ImportsByAlias map[string]*ast.ImportSpec // FuncToFileMap maps each public function within the package to it's corrasponding source file FuncToFileMap map[string]string // FuncTable is the map of each function name to it's Golang AST declaration FuncTable map[string]*ast.FuncDecl // LinkedFuncs defines references to the dynamically linked functions for this go package LinkedFuncs []*LinkedFunction // Reference to know if this go package is part of the standard library IsStandardLib bool // FileSet is used by the parser to interpret the current golang's file tokens FileSet *token.FileSet // GoTypes are struct type declarations that need to be accounted for in the engine GoTypes map[string]*GoStructDef // GoConsts are const declarations that need to be accounted for in the engine GoConsts map[string]*GoConst // GoVars are top level var declarations that need to be accounted for in the engine GoVars map[string]*GoVar }
GoPackage holds all the information about a Golang package that is being resolved to a given script
func NewGoPackage ¶
NewGoPackage is a constructor for a gopackage that will be used in dynamically linking native code
func (*GoPackage) NewGoVar ¶
func (gop *GoPackage) NewGoVar(goast *ast.File, vs *ast.ValueSpec, offset int, ident *ast.Ident, expr ast.Expr, name string) (*GoVar, error)
NewGoVar creates a new GoVar object if one doesn't already exist with that name in the GoPackage
func (*GoPackage) ParseFuncDecl ¶
func (gop *GoPackage) ParseFuncDecl(goast *ast.File, funcdecl *ast.FuncDecl, wg *sync.WaitGroup, errChan chan error)
ParseFuncDecl walks a func declaration inside of a gopackage to result it's method signature
func (*GoPackage) ParseStructDef ¶
func (gop *GoPackage) ParseStructDef(goast *ast.File, v *ast.TypeSpec, t *ast.StructType, wg *sync.WaitGroup, errChan chan error)
ParseStructDef creates a new mapping between a go package and a struct type definition
func (*GoPackage) ParseTypeSpec ¶
func (gop *GoPackage) ParseTypeSpec(goast *ast.File, v *ast.TypeSpec, wg *sync.WaitGroup, errChan chan error)
ParseTypeSpec attempts to filter type spec definitions within the AST to only struct types
func (*GoPackage) ParseVarSpec ¶
func (gop *GoPackage) ParseVarSpec(goast *ast.File, vardecl *ast.ValueSpec, offset int, wg *sync.WaitGroup, errChan chan error)
ParseVarSpec walks a var declaration inside of a gopackage to make sure it can sanely be accounted for by the compiler
func (*GoPackage) SanityCheckScriptCallers ¶
SanityCheckScriptCallers enumerates all of the parent gopackage's script callers looking for any callers who do not have an entry in this go package's symbol table
func (*GoPackage) SuccessfullyLinkedFuncs ¶
func (gop *GoPackage) SuccessfullyLinkedFuncs() []*LinkedFunction
SuccessfullyLinkedFuncs is used during rendering to make sure that only linked functions that successfully swizzled are going to be built into the source
func (*GoPackage) ValidVars ¶
ValidVars is used during rendering to ensure that only valid var declarations that have been processed by the swizzler are included in the intermediate representation
func (*GoPackage) WalkGoFileAST ¶
WalkGoFileAST walks the AST of a golang file and determines if it should be included as a linked function based on one of the following statements being true: Parent GoPackage is a member of the standard library OR Compiler option ImportAllNativeFunc is set to true OR VM Script calls this function explicitly
type GoParamDef ¶
type GoParamDef struct { // Type denotes the type of parameter def (struct, function, etc.) Type string // OriginalName is to reference the original name of the field incase of problems OriginalName string // SigBuffer is used to create a definition to the actual type declaration in the genesis compiler's linker SigBuffer bytes.Buffer // NameBuffer is used to create a label that the genesis linker can use to create it's translations NameBuffer bytes.Buffer // ImportRefs holds a mapping of any golang dependencies required for this parameter's type declaration ImportRefs map[string]*ast.ImportSpec // VarName holds a representation of the logical representation of a parameter's label with it's offset appended VarName string // ParamIdx will be the relative position within the parameter declaration. // This is inclusive to multiple declarations of the same type. Example: // // func Foo(a, b string, c int) {} // GoParamDef objects for "a" and "b" would hold the same ParamIdx, but different // ArgOffset values ParamIdx int // ArgOffset defines the absolute position within the parameter declaration. It will increment // Regardless of multiple labels defined in the same type. // This is used by the linker to correctly translate arguments for golang functions ArgOffset int // ExtSig will hold the final result of the SigBuffer rendering as a string ExtSig string // GoLabel is used to represent the label name within Golang GoLabel string // NeedsMapping defines a hard coded type mapping between golang and javascript types NeedsMapping bool // MappedTypeAlias is a helper method to look up the type a method should be MappedTypeAlias string // LinkedFUnction is used to reference the parent LinkedFunction object LinkedFunction *LinkedFunction // IsInterfaceType defines ifthe GoParamDef an interface type? IsInterfaceType bool // SkipResolution defines whether the left recursive lexer should skip package resolution SkipResolution bool // Reference to the parent GoPackage GoPackage *GoPackage // False, unless the interpretation fails Errored bool // Holds the error message if the interpretation fails ErrorMessage string }
GoParamDef defines a type to represent parameters found in a Golang function declaration (arguments or return types)
func NewGoParamDef ¶
func NewGoParamDef(l *LinkedFunction, idx int) *GoParamDef
NewGoParamDef creates a new definition object for a go parameter (either return or argument) and returns a pointer to itself.
func (*GoParamDef) BuiltInJSType ¶
func (p *GoParamDef) BuiltInJSType() string
BuiltInJSType returns the type that JS will return that we need to convert the ParamDef to golang
func (*GoParamDef) BuiltInTranslationRequired ¶
func (p *GoParamDef) BuiltInTranslationRequired() bool
BuiltInTranslationRequired is a compiler helper to determine if the param definition requires a built in translation
func (*GoParamDef) Interpret ¶
func (p *GoParamDef) Interpret(i interface{}) error
Interpret is a recursive walk function that is used to dispatch the next walker depending on the type of the provided interface (i). This is used to build up buffers of both names and golang type declarations to be used during linking.
func (*GoParamDef) MappedType ¶
func (p *GoParamDef) MappedType(pkg, sel string) string
MappedType looks at whether there is a type mapping that needs to be honored
func (*GoParamDef) ParseArrayType ¶
func (p *GoParamDef) ParseArrayType(a *ast.ArrayType) error
ParseArrayType interprets a golang array/slice type into the appropriate GoParamDef structure
func (*GoParamDef) ParseIdent ¶
func (p *GoParamDef) ParseIdent(a *ast.Ident) error
ParseIdent interprets a golang identifier into the appropriate GoParamDef structure
func (*GoParamDef) ParseInterfaceType ¶
func (p *GoParamDef) ParseInterfaceType(i *ast.InterfaceType) error
ParseInterfaceType is used to parse an interface type that is being passed into a linked function
func (*GoParamDef) ParseMapType ¶
func (p *GoParamDef) ParseMapType(a *ast.MapType) error
ParseMapType interprets a golang map type into the appropriate GoParamDef structure
func (*GoParamDef) ParseSelectorExpr ¶
func (p *GoParamDef) ParseSelectorExpr(a *ast.SelectorExpr) error
ParseSelectorExpr interprets a golang namespace external to the function declarations package and maps it into the appropriate GoParamDef structure
func (*GoParamDef) ParseStarExpr ¶
func (p *GoParamDef) ParseStarExpr(a *ast.StarExpr) error
ParseStarExpr interprets a golang pointer into the appropriate GoParamDef structure
type GoStructDef ¶
type GoStructDef struct { sync.RWMutex // Package is a reference to the parent GoPackage Package *GoPackage // File is a reference to the parent AST file File *ast.File // TypeSpec references the typespec node within the file's AST TypeSpec *ast.TypeSpec // AST references the actual struct definition within the file's AST AST *ast.StructType // Name represents the name of the struct definition Name string // Key represents the masked name of the function declaration in the intermediate representation Key string // ImportRefs hold a mapping of any golang dependencies required for this type declaration ImportRefs map[string]*ast.ImportSpec // Fields are the fields that can be used within this struct (compatible with genesis type conversion) Fields map[string]*GoParamDef // Incompatible are fields that CANNOT be used with genesis Incompatible map[string]*GoParamDef // Embeds is a convenience reference showing any embedded types that might exist within this struct Embeds map[string]*GoParamDef }
GoStructDef defines a struct type definition to be used within the genesis engine
func (*GoStructDef) ParseStructField ¶
func (gsd *GoStructDef) ParseStructField(f *ast.Field, name string, offset int, wg *sync.WaitGroup, errChan chan error)
ParseStructField attempts to interpret the struct fields within exported go types
func (*GoStructDef) WalkStruct ¶
func (gsd *GoStructDef) WalkStruct(wg *sync.WaitGroup, errChan chan error)
WalkStruct walks the type definition AST for exported struct fields
type GoVar ¶
type GoVar struct { sync.RWMutex // Package is a reference to the parent GoPackage Package *GoPackage // File is a reference to the parent AST file File *ast.File // ValueSpec is the parent ValueSpec declaration in the AST ValueSpec *ast.ValueSpec // VSOffset is the offset within the ValueSpec's Ident this var is found VSOffset int // Ident is a reference to the actual Golang AST ident object Ident *ast.Ident // Expr holds the data we are checking out! Expr ast.Expr // Name is the name of the exported var Name string // Key is the swizzled unique identifier to the declaration Key string // Valid means it has passed swizzle sanity check for types we can't mess with Valid bool // Def is the swizzling point of reference for this particular package Def *GoParamDef }
GoVar defines a top level var declaration within a Golang package
func (*GoVar) ParseDeclaration ¶
ParseDeclaration attempts to parse a top level var declaration and account for any incompatible types
type LegacyArgDef ¶
type LegacyArgDef struct { // the name of the argument passed into the function Name string `yaml:"label"` // the golang type argument is expected to be GoType string `yaml:"gotype"` }
LegacyArgDef is used by LegacyFunctionCall objects to create mappings for legacy function argument's for the linker to inject into the build
type LegacyFunctionCall ¶
type LegacyFunctionCall struct { // name of the legacy function Name string `yaml:"name"` // description of the legacy function Description string `yaml:"description"` // owner of the legacy function Author string `yaml:"author"` // package name the legacy function is in Package string `yaml:"package"` // the expected arguments to the legacy function call ExpectedArgTypes []LegacyArgDef `yaml:"args"` // the expected returns to the legacy function call ExpectedReturnTypes []LegacyRetDef `yaml:"returns"` }
LegacyFunctionCall uses the old generator to represent v0 standard library functions so they can be deprecated in subsequent versions without forcing users to convert all v0 scripts to v1 at this time
type LegacyLibrary ¶
type LegacyLibrary struct { // name of the owning package in the legacy standard library Name string `yaml:"package"` // path to the golang file located in which this library is implemented Path string `yaml:"path"` // file set for the AST walk and re-write FSet *token.FileSet `yaml:"-"` // Golang AST representation of the library's source file AST *ast.File `yaml:"-"` // map of the function names to their LegacyFunctionCall objects Funcs map[string]*LegacyFunctionCall `yaml:"-"` // the raw file data for the legacy library source Source []byte `yaml:"-"` }
LegacyLibrary defines one of the original standard library golang packages for backward compatibility during linking to associate global namespace function calls with the v1 package style
type LegacyRetDef ¶
type LegacyRetDef struct { // name of the rerturn value parameter Name string `yaml:"label"` // the golang type return parameter is expected to be GoType string `yaml:"gotype"` // optional value to determine if you wish to return this value to the VM ReturnToVM bool `yaml:"return,omitempty"` }
LegacyRetDef is used by LegacyFunctionCall objects to create mappings for legacy return values for the linker to inject into the build
type LinkedFunction ¶
type LinkedFunction struct { // ID of the function that is linked ID string // string representation of the function basename Function string // reference to the caller in the genesis script AST Caller *FunctionCall // reference to the golang AST tree of the file this function is declared in File *ast.File // reference to the declaration of this function in the golang AST GoDecl *ast.FuncDecl // list of references to any imports needed in declaring argument and return parameters // for this linked function Imports []*ast.ImportSpec // reference to the compiler's go package object GoPackage *GoPackage // a slice of all the go parameters that make up the argument signature GoArgs []*GoParamDef // a slice of all the go parameters that make up the return signature GoReturns []*GoParamDef // a reference to the parent genesis VM GenesisVM *GenesisVM // reference back to the parent linker Linker *Linker // A check to make sure this swizzle was successful SwizzleSuccessful bool // Any errors from the swizzling of this function SwizzleError error // Signature is a saved version of the golang's method signature Signature string }
LinkedFunction is the type that represents the gscript <=> golang native binding so proper interfaces can be generated at compile time for calling native go from the genesis VM.
func (*LinkedFunction) CanResolveImportDep ¶
func (l *LinkedFunction) CanResolveImportDep(pkg string) (string, error)
CanResolveImportDep takes a package string and compares it against the linked functions known import table to determine if the referenced namespace is declared in the golang AST as a referenced sub-type
func (*LinkedFunction) GenerateArgString ¶
func (l *LinkedFunction) GenerateArgString(prefix string) string
GenerateArgString generates a golang argument string to use in the interface code based on the number of arguments required for the supplied function
func (*LinkedFunction) GenerateReturnString ¶
func (l *LinkedFunction) GenerateReturnString(prefix string) string
GenerateReturnString generates a golang return signature to use in the interface code
func (*LinkedFunction) SwizzleToTheLeft ¶
func (l *LinkedFunction) SwizzleToTheLeft() error
SwizzleToTheLeft enumerates the function arguments of both the caller and the native function to build a structured list of parameters and their types. It also compares the caller argument signature and throws an error if the caller is providing an incompatible number of arguments.
func (*LinkedFunction) SwizzleToTheRight ¶
func (l *LinkedFunction) SwizzleToTheRight() error
SwizzleToTheRight enumerates the function returns of the native function to build a structured list of the return value types. This is then used by the linker to generate a special wrapper to allow multiple return values to be returned in single value context (required by javascript)
type Linker ¶
type Linker struct { sync.RWMutex // a reference to the parent genesis VM VM *GenesisVM // mapping of function name to the linked function object used during generation Funcs map[string]*LinkedFunction // mapping of type definitions to be linked into the engine Types map[string]*GoStructDef // MaskedImports map a golang dependency by import path into a translated path MaskedImports map[string]*MaskedImport }
Linker holds the maps between functions called from the genesis script and their associated golang equivalent, including package references. The linker will use this mapping to generate import shims for each golang public golang function called.
func (*Linker) NewLinkedFunction ¶
func (l *Linker) NewLinkedFunction(fnName string, caller *FunctionCall, file *ast.File, godecl *ast.FuncDecl, imports []*ast.ImportSpec, gopkg *GoPackage) (*LinkedFunction, error)
NewLinkedFunction creates a function mapping in the VMs linker between golang AST function declearations and genesis AST function calls so the compiler can build the function interfaces between the virtual machine and the native golang package
func (*Linker) SuccessfullyLinkedFuncs ¶
func (l *Linker) SuccessfullyLinkedFuncs() []*LinkedFunction
SuccessfullyLinkedFuncs is a helper method for the linker for any edge case packages to the standard library (asset for example)
type Macro ¶
type Macro struct { // the genesis compiler option's name for this macro Key string // map of the values associated with this macro Params map[string]string }
Macro defines the object created by each macro parsed by the preprocessor
func ScanForMacros ¶
func ScanForMacros(commentMap gast.CommentMap) []*Macro
ScanForMacros takes the genesis comments from the AST and parses known macros out for the compiler
type MaskedImport ¶
type MaskedImport struct { // ImportPath of the masked Import ImportPath string // OldAlias represents the alias in the target package source OldAlias string // NewAlias represents the aliased package name in the intermediate representation NewAlias string }
MaskedImport is used to separate import namespaces within the intermediate representation
func NewMaskedImport ¶
func NewMaskedImport(ip, oa string) *MaskedImport
NewMaskedImport creates a new import mask based on an import path and old alias
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Code generated for package computil by go-bindata DO NOT EDIT.
|
Code generated for package computil by go-bindata DO NOT EDIT. |