Gentee
  • Gentee script programming language
  • Language Reference
    • Lexical elements
    • Types
    • Declarations
    • Statements
    • Error handling
    • Expressions
    • Running programs
    • Multithreading
    • Include and import
  • Standard Library Reference
    • Archiving
    • Array
    • Boolean
    • Buffer
    • Characters
    • Console
    • Constants
    • Context
    • Cryptography
    • Encoding
    • Files
    • Float numbers
    • Integer
    • Map
    • Multithreading
    • Network
    • Object
    • Path
    • Process
    • Regular expressions
    • Runtime
    • Sets
    • Strings
    • System
    • Time
  • Go Integration
    • Reference
    • Compilation and execution
    • Advanced features
    • Playground
  • Change language
    • Русский
Powered by GitBook
On this page
  • Compilation
  • Bytecode Execution

Was this helpful?

  1. Go Integration

Compilation and execution

Let's see how to use the Gentee compiler and virtual machine in projects in the Go programming language.

Compilation

To get started, you need to create the Gentee structure using the New function. This structure will store all information about compiled scripts. You just need to create one instance and compile any number of scripts.

To compile scripts, you need to use the methods Compile, CompileFile, CompileAndRun. The methods Compile, CompileFile, in case of successful compilation, return the structure Exec, which contains the bytecode. You can save or pass this structure for later execution using the Run method. The CompileAndRun method immediately after compilation executes the script and returns its result.

package main
import (
    "fmt"
    "log"

    "github.com/gentee/gentee"
)

func main() {
    g := gentee.New()

    exec,_, err := g.Compile("run : Print(`Hello, world!`)", "")
    if err != nil {
        log.Fatal(err)
    }
    exec.Run(gentee.Settings{})
    exec,_, err = g.CompileFile("/home/ak/scripts/myscript.g")
    if err != nil {
        log.Fatal(err)
    }
    exec.Run(gentee.Settings{})

    var result interface{}
    result, err = g.CompileAndRun("../torun.g")
    fmt.Println(`Error:`, err, `Result:`, result)
}

Bytecode Execution

package main
import (
    "fmt"
    "log"

    "github.com/gentee/gentee"
)

func main() {
    g := gentee.New()

    exec,_, err := g.CompileFile("myscript.g")
    if err != nil {
        log.Fatal(err)
    }
    var result interface{}
    result, err = exec.Run(gentee.Settings{
        CmdLine: []string{
            "-par1",
            "-o",
            "/home/ak/tmp",
        },
    })
    fmt.Println(`Error:`, err, `Result:`, result)
}
PreviousReferenceNextAdvanced features

Last updated 4 years ago

Was this helpful?

The ready byte code of the script is stored in a structure of the Exec type. To execute it, call the Run method. The parameter of the type allows you to pass command line parameters and specify additional settings for the virtual machine.

Settings