go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

commit 31e011d53139cf02df8e33562025ca5d7cbed659
parent 71d7c1466e23057e3af569b1ded8fadcf0a96981
Author: lash <dev@holbrook.no>
Date:   Sun,  2 Apr 2023 10:20:25 +0100

Add interactive runner

Diffstat:
MREADME.md | 28+++++++++++++++++++++++++++-
Mgo/dev/interactive.go | 6+++---
2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md @@ -5,6 +5,7 @@ An attempt at defining a small VM to handle menu interaction for size-constraine Original motivation was to create a simple templating renderer for USSD clients, combined with an agnostic data-retrieval reference that may conceal any level of complexity. + ## Opcodes The VM defines the following opcode symbols: @@ -138,7 +139,32 @@ It expects all replacement symbols to be available at time of rendering, and has 0007 # HALT - stop execution ``` -## Assembly language +## Development tools + +Located in the `dev/` directory. + + +### Test data generation + +`go run ./dev/testdata/ <directory>` + +Outputs bytecodes and templates for test data scenarios used in `engine` unit tests. + + +### Interactive runner + +`go run ./dev [-d <data_directory>] [--root <root_symbol>]` + +Creates a new interactive session using `engine.DefaultEngine`, starting execution at symbol `root_symbol` + +`data_directory` points to a directory where templates and bytecode is to be found (in the same format as generated by `dev/testdata`). + +If `data_directory` is not set, current directory will be used. + +if `root_symbol` is not set, the symbol `root` will be used. + + +### Assembler **TBD** diff --git a/go/dev/interactive.go b/go/dev/interactive.go @@ -22,7 +22,7 @@ func main() { ctx := context.Background() en := engine.NewDefaultEngine(dir) - err := en.Init("root", ctx) + err := en.Init(root, ctx) if err != nil { fmt.Fprintf(os.Stderr, "cannot init: %v\n", err) os.Exit(1) @@ -33,13 +33,13 @@ func main() { reader := bufio.NewReader(os.Stdin) in, err := reader.ReadString('\n') if err != nil { - fmt.Fprintf(os.Stderr, "cannot read input: %v", err) + fmt.Fprintf(os.Stderr, "cannot read input: %v\n", err) os.Exit(1) } in = strings.TrimSpace(in) err = en.Exec([]byte(in), ctx) if err != nil { - fmt.Fprintf(os.Stderr, "execution terminated: %v", err) + fmt.Fprintf(os.Stderr, "execution terminated: %v\n", err) os.Exit(1) } b := bytes.NewBuffer(nil)