Add ast tree to program (#528)

* Add pro holder

* explain
This commit is contained in:
Anton Medvedev
2024-01-17 20:01:34 +01:00
committed by GitHub
parent 9b73bb722e
commit 84f18d7e5d
3 changed files with 16 additions and 5 deletions
+1
View File
@@ -7,3 +7,4 @@
*.out
*.html
custom_tests.json
pro/
+1
View File
@@ -49,6 +49,7 @@ func Compile(tree *parser.Tree, config *conf.Config) (program *Program, err erro
program = NewProgram(
tree.Source,
tree.Node,
c.locations,
c.variables,
c.constants,
+14 -5
View File
@@ -9,6 +9,7 @@ import (
"strings"
"text/tabwriter"
"github.com/expr-lang/expr/ast"
"github.com/expr-lang/expr/builtin"
"github.com/expr-lang/expr/file"
"github.com/expr-lang/expr/vm/runtime"
@@ -21,6 +22,7 @@ type Program struct {
Constants []any
source *file.Source
node ast.Node
locations []file.Location
variables int
functions []Function
@@ -30,6 +32,7 @@ type Program struct {
// NewProgram returns a new Program. It's used by the compiler.
func NewProgram(
source *file.Source,
node ast.Node,
locations []file.Location,
variables int,
constants []any,
@@ -40,6 +43,7 @@ func NewProgram(
) *Program {
return &Program{
source: source,
node: node,
locations: locations,
variables: variables,
Constants: constants,
@@ -50,6 +54,16 @@ func NewProgram(
}
}
// Source returns origin file.Source.
func (program *Program) Source() *file.Source {
return program.source
}
// Node returns origin ast.Node.
func (program *Program) Node() ast.Node {
return program.node
}
// Disassemble returns opcodes as a string.
func (program *Program) Disassemble() string {
var buf bytes.Buffer
@@ -346,8 +360,3 @@ func (program *Program) DisassembleWriter(w io.Writer) {
}
}
}
// Source returns origin file.Source.
func (program *Program) Source() *file.Source {
return program.source
}