mirror of
https://github.com/hanzoai/expr.git
synced 2026-09-24 16:58:58 +00:00
@@ -7,3 +7,4 @@
|
||||
*.out
|
||||
*.html
|
||||
custom_tests.json
|
||||
pro/
|
||||
|
||||
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user