Add interactive runner

This commit is contained in:
lash 2023-04-02 10:20:25 +01:00
parent 71d7c1466e
commit 31e011d531
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 30 additions and 4 deletions

View File

@ -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**

View File

@ -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)