diff options
| author | Marc Vertes <mvertes@free.fr> | 2025-11-27 14:50:07 +0100 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2025-11-27 14:50:07 +0100 |
| commit | 22b020225ae77ca1cf9f9984817df9b7fd1aaa12 (patch) | |
| tree | fdbb8d0ccae08b248c1e1d787ba66d624ab6a34c /interpreter/interpreter.go | |
| parent | 8e32cc1a5617f84d0bd7bf1fd898251675d5a653 (diff) | |
fix: improve parser, compiler and interpreter APIs
Pass a language spec as an argument when create a new parser,
compiler or interpreter.
Also move the REPL code in interpreter package.
Diffstat (limited to 'interpreter/interpreter.go')
| -rw-r--r-- | interpreter/interpreter.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/interpreter/interpreter.go b/interpreter/interpreter.go index 06a4bc1..62b593b 100644 --- a/interpreter/interpreter.go +++ b/interpreter/interpreter.go @@ -4,25 +4,25 @@ import ( "reflect" "github.com/mvertes/parscan/compiler" - "github.com/mvertes/parscan/scanner" + "github.com/mvertes/parscan/lang" "github.com/mvertes/parscan/vm" ) const debug = true -// Interpreter represents the state of an interpreter. -type Interpreter struct { +// Interp represents the state of an interpreter. +type Interp struct { *compiler.Compiler *vm.Machine } -// NewInterpreter returns a new interpreter state. -func NewInterpreter(s *scanner.Scanner) *Interpreter { - return &Interpreter{compiler.NewCompiler(s), &vm.Machine{}} +// NewInterpreter returns a new interpreter. +func NewInterpreter(s *lang.Spec) *Interp { + return &Interp{compiler.NewCompiler(s), &vm.Machine{}} } -// Eval interprets a src program and return the last produced value if any, or an error. -func (i *Interpreter) Eval(src string) (res reflect.Value, err error) { +// Eval evaluates code string and return the last produced value if any, or an error. +func (i *Interp) Eval(src string) (res reflect.Value, err error) { codeOffset := len(i.Code) dataOffset := 0 if codeOffset > 0 { |
