Documentation
¶
Index ¶
- Constants
- Variables
- func Commit() string
- func CompileAndRun(ctx context.Context, data []byte, inputFile string) (err error)
- func CompileOnly(data []byte, inputFile, outputFile string) (err error)
- func NewCli(ui cli.ActionFunc) (*cli.App, error)
- func RunCompiled(ctx context.Context, data []byte) (err error)
- func RunREPL(ctx context.Context, in io.Reader, out io.Writer, prompt string)
- func Version() string
- type Program
- func (p *Program) Bytecode() *vvm.Bytecode
- func (p *Program) Clone() *Program
- func (p *Program) Equals(other *Program) bool
- func (p *Program) Get(name string) *Variable
- func (p *Program) GetAll() []*Variable
- func (p *Program) IsDefined(name string) bool
- func (p *Program) Marshal() ([]byte, error)
- func (p *Program) Run() error
- func (p *Program) RunContext(ctx context.Context) (err error)
- func (p *Program) Set(name string, value interface{}) error
- func (p *Program) Unmarshal(b []byte) (err error)
- type Script
- func (s *Script) Add(name string, value interface{}) error
- func (s *Script) Compile() (*Program, error)
- func (s *Script) EnableFileImport(enable bool)
- func (s *Script) Remove(name string) bool
- func (s *Script) Run() (program *Program, err error)
- func (s *Script) RunContext(ctx context.Context) (program *Program, err error)
- func (s *Script) SetImportDir(dir string) error
- func (s *Script) SetImports(modules *vvm.ModuleMap)
- func (s *Script) SetMaxAllocs(n int64)
- func (s *Script) SetMaxConstObjects(n int)
- func (s *Script) SetName(name string)
- type Variable
- func (v *Variable) Array() []interface{}
- func (v *Variable) Bool() bool
- func (v *Variable) Bytes() []byte
- func (v *Variable) Char() rune
- func (v *Variable) Error() error
- func (v *Variable) Float() float64
- func (v *Variable) Int() int
- func (v *Variable) Int64() int64
- func (v *Variable) IsUndefined() bool
- func (v *Variable) Map() map[string]interface{}
- func (v *Variable) Name() string
- func (v *Variable) Object() vvm.Object
- func (v *Variable) String() string
- func (v *Variable) Value() interface{}
- func (v *Variable) ValueType() string
Constants ¶
const Magic = "VVC\x00"
Magic is a magic number every encoded Program starts with. format: [4]MAGIC [4]SIZE [N]DATA [8]CRC64(ECMA)
Variables ¶
var Modules = stdlib.GetModuleMap(stdlib.AllModuleNames()...)
Functions ¶
func CompileAndRun ¶
CompileAndRun compiles the source code and executes it.
func CompileOnly ¶
CompileOnly compiles the source code and writes the compiled binary into outputFile.
func RunCompiled ¶
RunCompiled reads the compiled binary from file and executes it.
Types ¶
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program is a compiled instance of the user script. Use Script.Compile() to create Compiled object.
func (*Program) Clone ¶
Clone creates a new copy of Compiled. Cloned copies are safe for concurrent use by multiple goroutines.
func (*Program) IsDefined ¶
IsDefined returns true if the variable name is defined (has value) before or after the execution.
func (*Program) RunContext ¶
RunContext is like Run but includes a context.
type Script ¶
type Script struct {
// contains filtered or unexported fields
}
Script can simplify compilation and execution of embedded scripts.
func (*Script) Compile ¶
Compile compiles the script with all the defined variables and returns Program object.
func (*Script) EnableFileImport ¶
EnableFileImport enables or disables module loading from local files. Local file modules are disabled by default.
func (*Script) Remove ¶
Remove removes (undefines) an existing variable for the script. It returns false if the variable name is not defined.
func (*Script) Run ¶
Run compiles and runs the scripts. Use returned compiled object to access global variables.
func (*Script) RunContext ¶
RunContext is like Run but includes a context.
func (*Script) SetImportDir ¶
SetImportDir sets the initial import directory for script files.
func (*Script) SetImports ¶
SetImports sets import modules.
func (*Script) SetMaxAllocs ¶
SetMaxAllocs sets the maximum number of objects allocations during the run time. Compiled script will return ErrObjectAllocLimit error if it exceeds this limit.
func (*Script) SetMaxConstObjects ¶
SetMaxConstObjects sets the maximum number of objects in the compiled constants.
type Variable ¶
type Variable struct {
// contains filtered or unexported fields
}
Variable is a user-defined variable for the script.
func NewVariable ¶
NewVariable creates a Variable.
func (*Variable) Array ¶
func (v *Variable) Array() []interface{}
Array returns []interface value of the variable value. It returns 0 if the value is not convertible to []interface.
func (*Variable) Bool ¶
Bool returns bool value of the variable value. It returns 0 if the value is not convertible to bool.
func (*Variable) Bytes ¶
Bytes returns a byte slice of the variable value. It returns nil if the value is not convertible to byte slice.
func (*Variable) Char ¶
Char returns rune value of the variable value. It returns 0 if the value is not convertible to rune.
func (*Variable) Error ¶
Error returns an error if the underlying value is error object. If not, this returns nil.
func (*Variable) Float ¶
Float returns float64 value of the variable value. It returns 0.0 if the value is not convertible to float64.
func (*Variable) Int ¶
Int returns int value of the variable value. It returns 0 if the value is not convertible to int.
func (*Variable) Int64 ¶
Int64 returns int64 value of the variable value. It returns 0 if the value is not convertible to int64.
func (*Variable) IsUndefined ¶
IsUndefined returns true if the underlying value is undefined.
func (*Variable) Map ¶
Map returns map[string]interface{} value of the variable value. It returns 0 if the value is not convertible to map[string]interface{}.
func (*Variable) Object ¶
Object returns an underlying Object of the variable value. Note that returned Object is a copy of an actual Object used in the script.
func (*Variable) String ¶
String returns string value of the variable value. It returns 0 if the value is not convertible to string.
Directories
¶
Path | Synopsis |
---|---|
pkg
|
|
cli
Package cli provides a minimal framework for creating and organizing command line Go applications.
|
Package cli provides a minimal framework for creating and organizing command line Go applications. |
sh/readline/term
Package term provides support functions for dealing with terminals, as commonly found on UNIX systems.
|
Package term provides support functions for dealing with terminals, as commonly found on UNIX systems. |
encoding
Package encoding provides functions to marshal and unmarshal data types.
|
Package encoding provides functions to marshal and unmarshal data types. |