Reference

The functions and structures for using the Gentee programming language in Golang projects are described here.

Types

type Custom

The Custom type is used for additional configuration of the compiler and virtual machine. It is passed when the Customize function is called.

  • Embedded []EmbedItem - an array of additional functions for the standard library.

type EmbedItem

The EmbedItem type describes the function to be embedded in the standard library. It is used in the Custom type.

  • Prototype string - a description of the function in the Gentee language. For example, myfunc(str,int) int.

  • Object interface{} - the corresponding golang function.

type Settings

The Settings type is used to specify additional parameters when starting the bytecode in the Run method.

  • CmdLine []string - an array of command line parameters.

  • Stdin *os.File - custom standard input.

  • Stdout *os.File - custom standard output.

  • Input []byte - predefined standard input (stdin). Can be used, for example, in the function ReadString.

  • Cycle uint64 - maximum number of iterations in the loop. By default, it is 1600000000.

  • Depth uint32 - maximum nesting of executable blocks. Limits the recursion depth. By default, it is equal to 1000.

  • SysChan chan int - the channel for sending SysSuspend (1), SysResume (2), SysTerminate (3) commands. It allows you to control the script execution from the outside.

    • SysSuspend - suspend the script execution and all its threads.

    • SysResume - resume the script execution and all its threads.

    • SysTerminate - terminate the script and all its threads.

settings.SysChan = make(chan int)
go func() {
_, err = exec.Run(settings)
}()
settings.SysChan <- gentee.SysTerminate

Functions and methods

Customize(custom *Custom) error

The Customize function is used for additional settings of the compiler and virtual machine. It should be called before all the functions. The function returns the error value.

New() *Gentee

The New function creates a workspace for compiling source code.

(g *Gentee) Compile(input, path string) (*Exec, int, error)

The Compile function compiles the script passed to input. You can specify the path to the script in the path parameter. The function returns a bytecode structure, module number and error value.

(g *Gentee) CompileAndRun(filename string) (interface{}, error)

The CompileAndRun function compiles the script from the filename file and executes it. The function returns the result of the script and the error value.

(g *Gentee) CompileFile(filename string) (*Exec, int, error)

The CompileFile function compiles the script from the filename file. The function returns a bytecode structure, module number, and error value.

(exec *Exec) Run(settings Settings) (interface{}, error)

The Run function executes bytecode from the exec structure. You can specify additional settings in the settings parameter. The function returns the result of the script and the error value.

Version() string

The Version function returns the current version number of the language.