# 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.

```go
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

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 [**Settings**](/golang/reference.md#type-settings) allows you to pass command line parameters and specify additional settings for the virtual machine.

```go
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)
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gentee.org/golang/howtouse.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
