Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
*.out
*.html
custom_tests.json
pro/
1 change: 1 addition & 0 deletions compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 14 additions & 5 deletions vm/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -21,6 +22,7 @@ type Program struct {
Constants []any

source *file.Source
node ast.Node
locations []file.Location
variables int
functions []Function
Expand All @@ -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,
Expand All @@ -40,6 +43,7 @@ func NewProgram(
) *Program {
return &Program{
source: source,
node: node,
locations: locations,
variables: variables,
Constants: constants,
Expand All @@ -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
Expand Down Expand Up @@ -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
}