From 31e011d53139cf02df8e33562025ca5d7cbed659 Mon Sep 17 00:00:00 2001 From: lash Date: Sun, 2 Apr 2023 10:20:25 +0100 Subject: [PATCH] Add interactive runner --- README.md | 28 +++++++++++++++++++++++++++- go/dev/interactive.go | 6 +++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fbdc6e2..d62b608 100644 --- 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/ ` + +Outputs bytecodes and templates for test data scenarios used in `engine` unit tests. + + +### Interactive runner + +`go run ./dev [-d ] [--root ]` + +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 index c3d50f1..2fc05f5 100644 --- 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)