summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/d5/tengo/compiler/compiler_module.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2020-01-09 21:52:19 +0100
committerGitHub <noreply@github.com>2020-01-09 21:52:19 +0100
commit9d84d6dd643c4017074e81465671cd9b25f9539a (patch)
tree8a767f91d655a6cf21d476e4fb7aa6fd8a952df8 /vendor/github.com/d5/tengo/compiler/compiler_module.go
parent0f708daf2d14dcca261ef98cc698a1b1f2a6aa74 (diff)
downloadmatterbridge-msglm-9d84d6dd643c4017074e81465671cd9b25f9539a.tar.gz
matterbridge-msglm-9d84d6dd643c4017074e81465671cd9b25f9539a.tar.bz2
matterbridge-msglm-9d84d6dd643c4017074e81465671cd9b25f9539a.zip
Update to tengo v2 (#976)
Diffstat (limited to 'vendor/github.com/d5/tengo/compiler/compiler_module.go')
-rw-r--r--vendor/github.com/d5/tengo/compiler/compiler_module.go79
1 files changed, 0 insertions, 79 deletions
diff --git a/vendor/github.com/d5/tengo/compiler/compiler_module.go b/vendor/github.com/d5/tengo/compiler/compiler_module.go
deleted file mode 100644
index 8a3671ce..00000000
--- a/vendor/github.com/d5/tengo/compiler/compiler_module.go
+++ /dev/null
@@ -1,79 +0,0 @@
-package compiler
-
-import (
- "github.com/d5/tengo/compiler/ast"
- "github.com/d5/tengo/compiler/parser"
- "github.com/d5/tengo/objects"
-)
-
-func (c *Compiler) checkCyclicImports(node ast.Node, modulePath string) error {
- if c.modulePath == modulePath {
- return c.errorf(node, "cyclic module import: %s", modulePath)
- } else if c.parent != nil {
- return c.parent.checkCyclicImports(node, modulePath)
- }
-
- return nil
-}
-
-func (c *Compiler) compileModule(node ast.Node, moduleName, modulePath string, src []byte) (*objects.CompiledFunction, error) {
- if err := c.checkCyclicImports(node, modulePath); err != nil {
- return nil, err
- }
-
- compiledModule, exists := c.loadCompiledModule(modulePath)
- if exists {
- return compiledModule, nil
- }
-
- modFile := c.file.Set().AddFile(moduleName, -1, len(src))
- p := parser.NewParser(modFile, src, nil)
- file, err := p.ParseFile()
- if err != nil {
- return nil, err
- }
-
- symbolTable := NewSymbolTable()
-
- // inherit builtin functions
- for _, sym := range c.symbolTable.BuiltinSymbols() {
- symbolTable.DefineBuiltin(sym.Index, sym.Name)
- }
-
- // no global scope for the module
- symbolTable = symbolTable.Fork(false)
-
- // compile module
- moduleCompiler := c.fork(modFile, modulePath, symbolTable)
- if err := moduleCompiler.Compile(file); err != nil {
- return nil, err
- }
-
- // code optimization
- moduleCompiler.optimizeFunc(node)
-
- compiledFunc := moduleCompiler.Bytecode().MainFunction
- compiledFunc.NumLocals = symbolTable.MaxSymbols()
-
- c.storeCompiledModule(modulePath, compiledFunc)
-
- return compiledFunc, nil
-}
-
-func (c *Compiler) loadCompiledModule(modulePath string) (mod *objects.CompiledFunction, ok bool) {
- if c.parent != nil {
- return c.parent.loadCompiledModule(modulePath)
- }
-
- mod, ok = c.compiledModules[modulePath]
-
- return
-}
-
-func (c *Compiler) storeCompiledModule(modulePath string, module *objects.CompiledFunction) {
- if c.parent != nil {
- c.parent.storeCompiledModule(modulePath, module)
- }
-
- c.compiledModules[modulePath] = module
-}