31 lines
607 B
Go
31 lines
607 B
Go
package tengo
|
|
|
|
import (
|
|
"github.com/d5/tengo/compiler"
|
|
"github.com/d5/tengo/parser"
|
|
"github.com/d5/tengo/source"
|
|
"github.com/d5/tengo/vm"
|
|
)
|
|
|
|
func Compile(input []byte, filename string) (*compiler.Bytecode, error) {
|
|
fileSet := source.NewFileSet()
|
|
|
|
p := parser.NewParser(fileSet.AddFile(filename, -1, len(input)), input, nil)
|
|
file, err := p.ParseFile()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
c := compiler.NewCompiler(nil, nil)
|
|
if err := c.Compile(file); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return c.Bytecode(), nil
|
|
}
|
|
|
|
func Run(b *compiler.Bytecode) error {
|
|
v := vm.NewVM(b, nil)
|
|
|
|
return v.Run()
|
|
}
|