namespace: change -> git.grassecon.net/kamikazechaser/vise
This commit is contained in:
parent
194522fd95
commit
d8ef336919
@ -156,7 +156,7 @@ Multipage outputs, like listings, are handled using the _sink_ output constraint
|
|||||||
|
|
||||||
### Languages support
|
### Languages support
|
||||||
|
|
||||||
**Not yet implemeennted**
|
**Not yet implemented**
|
||||||
|
|
||||||
Language for rendering is determined at the top-level state.
|
Language for rendering is determined at the top-level state.
|
||||||
|
|
||||||
|
15
asm/asm.go
15
asm/asm.go
@ -13,10 +13,9 @@ import (
|
|||||||
"github.com/alecthomas/participle/v2"
|
"github.com/alecthomas/participle/v2"
|
||||||
"github.com/alecthomas/participle/v2/lexer"
|
"github.com/alecthomas/participle/v2/lexer"
|
||||||
|
|
||||||
"git.defalsify.org/vise/vm"
|
"git.grassecon.net/kamikazechaser/vise/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// Asm assembles bytecode from the vise assembly mini-language.
|
// Asm assembles bytecode from the vise assembly mini-language.
|
||||||
type Asm struct {
|
type Asm struct {
|
||||||
Instructions []*Instruction `@@*`
|
Instructions []*Instruction `@@*`
|
||||||
@ -312,7 +311,7 @@ func writeSize(w *bytes.Buffer, n uint32) (int, error) {
|
|||||||
}
|
}
|
||||||
w.Write([]byte{byte(sz)})
|
w.Write([]byte{byte(sz)})
|
||||||
binary.BigEndian.PutUint32(bn[:], n)
|
binary.BigEndian.PutUint32(bn[:], n)
|
||||||
c := 4-sz
|
c := 4 - sz
|
||||||
return w.Write(bn[c:])
|
return w.Write(bn[c:])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,7 +329,7 @@ func NewBatcher(mp MenuProcessor) Batcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MenuExit generates the instructions for the batch and writes them to the given io.Writer.
|
// MenuExit generates the instructions for the batch and writes them to the given io.Writer.
|
||||||
func(bt *Batcher) MenuExit(w io.Writer) (int, error) {
|
func (bt *Batcher) MenuExit(w io.Writer) (int, error) {
|
||||||
if !bt.inMenu {
|
if !bt.inMenu {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
@ -340,7 +339,7 @@ func(bt *Batcher) MenuExit(w io.Writer) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MenuAdd adds a new menu instruction to the batcher.
|
// MenuAdd adds a new menu instruction to the batcher.
|
||||||
func(bt *Batcher) MenuAdd(w io.Writer, code string, arg Arg) (int, error) {
|
func (bt *Batcher) MenuAdd(w io.Writer, code string, arg Arg) (int, error) {
|
||||||
bt.inMenu = true
|
bt.inMenu = true
|
||||||
var selector string
|
var selector string
|
||||||
var sym string
|
var sym string
|
||||||
@ -361,7 +360,7 @@ func(bt *Batcher) MenuAdd(w io.Writer, code string, arg Arg) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Exit is a synonym for MenuExit
|
// Exit is a synonym for MenuExit
|
||||||
func(bt *Batcher) Exit(w io.Writer) (int, error) {
|
func (bt *Batcher) Exit(w io.Writer) (int, error) {
|
||||||
return bt.MenuExit(w)
|
return bt.MenuExit(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,9 +372,7 @@ func Parse(s string, w io.Writer) (int, error) {
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
batch := Batcher{
|
batch := Batcher{}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
var rn int
|
var rn int
|
||||||
for _, v := range ast.Instructions {
|
for _, v := range ast.Instructions {
|
||||||
|
@ -7,10 +7,9 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.defalsify.org/vise/vm"
|
"git.grassecon.net/kamikazechaser/vise/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func TestParserInit(t *testing.T) {
|
func TestParserInit(t *testing.T) {
|
||||||
var b []byte
|
var b []byte
|
||||||
b = vm.NewLine(b, vm.HALT, nil, nil, nil)
|
b = vm.NewLine(b, vm.HALT, nil, nil, nil)
|
||||||
|
@ -3,7 +3,7 @@ package asm
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.defalsify.org/vise/vm"
|
"git.grassecon.net/kamikazechaser/vise/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BatchCode defines quasi-opcodes that expand to mulitple individual vm instructions.
|
// BatchCode defines quasi-opcodes that expand to mulitple individual vm instructions.
|
||||||
@ -49,7 +49,7 @@ func NewMenuProcessor() MenuProcessor {
|
|||||||
// Add a menu batch instruction to be processed.
|
// Add a menu batch instruction to be processed.
|
||||||
//
|
//
|
||||||
// Instructions will be rendered in the order in which they have been added.
|
// Instructions will be rendered in the order in which they have been added.
|
||||||
func(mp *MenuProcessor) Add(bop string, choice string, display string, target string) error {
|
func (mp *MenuProcessor) Add(bop string, choice string, display string, target string) error {
|
||||||
bopCode := batchCode[bop]
|
bopCode := batchCode[bop]
|
||||||
if bopCode == 0 {
|
if bopCode == 0 {
|
||||||
return fmt.Errorf("unknown menu instruction: %v", bop)
|
return fmt.Errorf("unknown menu instruction: %v", bop)
|
||||||
|
@ -3,10 +3,9 @@ package asm
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.defalsify.org/vise/vm"
|
"git.grassecon.net/kamikazechaser/vise/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func TestMenuInterpreter(t *testing.T) {
|
func TestMenuInterpreter(t *testing.T) {
|
||||||
m := NewMenuProcessor()
|
m := NewMenuProcessor()
|
||||||
err := m.Add("DOWN", "0", "inky", "foo")
|
err := m.Add("DOWN", "0", "inky", "foo")
|
||||||
|
@ -6,11 +6,11 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.defalsify.org/vise/asm"
|
"git.grassecon.net/kamikazechaser/vise/asm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if (len(os.Args) < 2) {
|
if len(os.Args) < 2 {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
fp := os.Args[1]
|
fp := os.Args[1]
|
||||||
|
@ -2,14 +2,14 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
|
||||||
"git.defalsify.org/vise/vm"
|
"git.grassecon.net/kamikazechaser/vise/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if (len(os.Args) < 2) {
|
if len(os.Args) < 2 {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
fp := os.Args[1]
|
fp := os.Args[1]
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.defalsify.org/vise/testdata"
|
"git.grassecon.net/kamikazechaser/vise/testdata"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.defalsify.org/vise/engine"
|
"git.grassecon.net/kamikazechaser/vise/engine"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -3,9 +3,9 @@ package engine
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.defalsify.org/vise/cache"
|
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||||
"git.defalsify.org/vise/resource"
|
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||||
"git.defalsify.org/vise/state"
|
"git.grassecon.net/kamikazechaser/vise/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewDefaultEngine is a convenience function to instantiate a filesystem-backed engine with no output constraints.
|
// NewDefaultEngine is a convenience function to instantiate a filesystem-backed engine with no output constraints.
|
||||||
|
@ -6,11 +6,11 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"git.defalsify.org/vise/cache"
|
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||||
"git.defalsify.org/vise/render"
|
"git.grassecon.net/kamikazechaser/vise/render"
|
||||||
"git.defalsify.org/vise/resource"
|
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||||
"git.defalsify.org/vise/state"
|
"git.grassecon.net/kamikazechaser/vise/state"
|
||||||
"git.defalsify.org/vise/vm"
|
"git.grassecon.net/kamikazechaser/vise/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config globally defines behavior of all components driven by the engine.
|
// Config globally defines behavior of all components driven by the engine.
|
||||||
@ -53,7 +53,7 @@ func NewEngine(cfg Config, st *state.State, rs resource.Resource, ca cache.Memor
|
|||||||
// Init must be explicitly called before using the Engine instance.
|
// Init must be explicitly called before using the Engine instance.
|
||||||
//
|
//
|
||||||
// It loads and executes code for the start node.
|
// It loads and executes code for the start node.
|
||||||
func(en *Engine) Init(ctx context.Context) (bool, error) {
|
func (en *Engine) Init(ctx context.Context) (bool, error) {
|
||||||
if en.initd {
|
if en.initd {
|
||||||
log.Printf("already initialized")
|
log.Printf("already initialized")
|
||||||
return true, nil
|
return true, nil
|
||||||
@ -154,7 +154,7 @@ func (en *Engine) Exec(input []byte, ctx context.Context) (bool, error) {
|
|||||||
// - required data inputs to the template are not available.
|
// - required data inputs to the template are not available.
|
||||||
// - the template for the given node point is note available for retrieval using the resource.Resource implementer.
|
// - the template for the given node point is note available for retrieval using the resource.Resource implementer.
|
||||||
// - the supplied writer fails to process the writes.
|
// - the supplied writer fails to process the writes.
|
||||||
func(en *Engine) WriteResult(w io.Writer, ctx context.Context) (int, error) {
|
func (en *Engine) WriteResult(w io.Writer, ctx context.Context) (int, error) {
|
||||||
r, err := en.vm.Render(ctx)
|
r, err := en.vm.Render(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -163,7 +163,7 @@ func(en *Engine) WriteResult(w io.Writer, ctx context.Context) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// start execution over at top node while keeping current state of client error flags.
|
// start execution over at top node while keeping current state of client error flags.
|
||||||
func(en *Engine) reset(ctx context.Context) (bool, error) {
|
func (en *Engine) reset(ctx context.Context) (bool, error) {
|
||||||
var err error
|
var err error
|
||||||
var isTop bool
|
var isTop bool
|
||||||
for !isTop {
|
for !isTop {
|
||||||
|
@ -8,10 +8,10 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.defalsify.org/vise/cache"
|
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||||
"git.defalsify.org/vise/resource"
|
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||||
"git.defalsify.org/vise/state"
|
"git.grassecon.net/kamikazechaser/vise/state"
|
||||||
"git.defalsify.org/vise/testdata"
|
"git.grassecon.net/kamikazechaser/vise/testdata"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -26,7 +26,7 @@ type FsWrapper struct {
|
|||||||
|
|
||||||
func NewFsWrapper(path string, st *state.State) FsWrapper {
|
func NewFsWrapper(path string, st *state.State) FsWrapper {
|
||||||
rs := resource.NewFsResource(path)
|
rs := resource.NewFsResource(path)
|
||||||
wr := FsWrapper {
|
wr := FsWrapper{
|
||||||
&rs,
|
&rs,
|
||||||
st,
|
st,
|
||||||
}
|
}
|
||||||
@ -36,26 +36,26 @@ func NewFsWrapper(path string, st *state.State) FsWrapper {
|
|||||||
return wr
|
return wr
|
||||||
}
|
}
|
||||||
|
|
||||||
func(fs FsWrapper) one(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
func (fs FsWrapper) one(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
||||||
return resource.Result{
|
return resource.Result{
|
||||||
Content: "one",
|
Content: "one",
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(fs FsWrapper) inky(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
func (fs FsWrapper) inky(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
||||||
return resource.Result{
|
return resource.Result{
|
||||||
Content: "tinkywinky",
|
Content: "tinkywinky",
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(fs FsWrapper) pinky(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
func (fs FsWrapper) pinky(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
||||||
r := fmt.Sprintf("xyzzy: %x", input)
|
r := fmt.Sprintf("xyzzy: %x", input)
|
||||||
return resource.Result{
|
return resource.Result{
|
||||||
Content: r,
|
Content: r,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(fs FsWrapper) GetCode(sym string) ([]byte, error) {
|
func (fs FsWrapper) GetCode(sym string) ([]byte, error) {
|
||||||
sym += ".bin"
|
sym += ".bin"
|
||||||
fp := path.Join(fs.Path, sym)
|
fp := path.Join(fs.Path, sym)
|
||||||
r, err := ioutil.ReadFile(fp)
|
r, err := ioutil.ReadFile(fp)
|
||||||
@ -137,7 +137,6 @@ func TestEngineExecInvalidInput(t *testing.T) {
|
|||||||
rs := NewFsWrapper(dataDir, &st)
|
rs := NewFsWrapper(dataDir, &st)
|
||||||
ca := cache.NewCache().WithCacheSize(1024)
|
ca := cache.NewCache().WithCacheSize(1024)
|
||||||
|
|
||||||
|
|
||||||
en := NewEngine(Config{
|
en := NewEngine(Config{
|
||||||
Root: "root",
|
Root: "root",
|
||||||
}, &st, &rs, ca, ctx)
|
}, &st, &rs, ca, ctx)
|
||||||
|
@ -8,9 +8,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.defalsify.org/vise/cache"
|
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||||
"git.defalsify.org/vise/resource"
|
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||||
"git.defalsify.org/vise/state"
|
"git.grassecon.net/kamikazechaser/vise/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoopTop(t *testing.T) {
|
func TestLoopTop(t *testing.T) {
|
||||||
|
@ -4,8 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"git.defalsify.org/vise/persist"
|
"git.grassecon.net/kamikazechaser/vise/persist"
|
||||||
"git.defalsify.org/vise/resource"
|
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RunPersisted performs a single vm execution from client input using a persisted state.
|
// RunPersisted performs a single vm execution from client input using a persisted state.
|
||||||
|
@ -6,9 +6,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.defalsify.org/vise/cache"
|
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||||
"git.defalsify.org/vise/persist"
|
"git.grassecon.net/kamikazechaser/vise/persist"
|
||||||
"git.defalsify.org/vise/state"
|
"git.grassecon.net/kamikazechaser/vise/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPersist(t *testing.T) {
|
func TestPersist(t *testing.T) {
|
||||||
|
@ -11,10 +11,10 @@ import (
|
|||||||
|
|
||||||
testdataloader "github.com/peteole/testdata-loader"
|
testdataloader "github.com/peteole/testdata-loader"
|
||||||
|
|
||||||
"git.defalsify.org/vise/cache"
|
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||||
"git.defalsify.org/vise/engine"
|
"git.grassecon.net/kamikazechaser/vise/engine"
|
||||||
"git.defalsify.org/vise/resource"
|
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||||
"git.defalsify.org/vise/state"
|
"git.grassecon.net/kamikazechaser/vise/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -43,7 +43,7 @@ func newProfileResource(st *state.State, rs *resource.FsResource) *profileResour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func(pr *profileResource) checkEntry() error {
|
func (pr *profileResource) checkEntry() error {
|
||||||
log.Printf("%v %v", USERFLAG_IDENTIFIED, USERFLAG_HAVENAME)
|
log.Printf("%v %v", USERFLAG_IDENTIFIED, USERFLAG_HAVENAME)
|
||||||
if pr.haveEntered {
|
if pr.haveEntered {
|
||||||
return nil
|
return nil
|
||||||
@ -66,7 +66,7 @@ func(pr *profileResource) checkEntry() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(pr profileResource) nameSave(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
func (pr profileResource) nameSave(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
||||||
log.Printf("writing name to file")
|
log.Printf("writing name to file")
|
||||||
fp := path.Join(scriptDir, "myname.txt")
|
fp := path.Join(scriptDir, "myname.txt")
|
||||||
err := ioutil.WriteFile(fp, input, 0600)
|
err := ioutil.WriteFile(fp, input, 0600)
|
||||||
@ -83,7 +83,7 @@ func(pr profileResource) nameSave(sym string, input []byte, ctx context.Context)
|
|||||||
return emptyResult, err
|
return emptyResult, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func(pr profileResource) emailSave(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
func (pr profileResource) emailSave(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
||||||
log.Printf("writing email to file")
|
log.Printf("writing email to file")
|
||||||
fp := path.Join(scriptDir, "myemail.txt")
|
fp := path.Join(scriptDir, "myemail.txt")
|
||||||
err := ioutil.WriteFile(fp, input, 0600)
|
err := ioutil.WriteFile(fp, input, 0600)
|
||||||
|
@ -11,10 +11,10 @@ import (
|
|||||||
|
|
||||||
testdataloader "github.com/peteole/testdata-loader"
|
testdataloader "github.com/peteole/testdata-loader"
|
||||||
|
|
||||||
"git.defalsify.org/vise/cache"
|
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||||
"git.defalsify.org/vise/engine"
|
"git.grassecon.net/kamikazechaser/vise/engine"
|
||||||
"git.defalsify.org/vise/resource"
|
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||||
"git.defalsify.org/vise/state"
|
"git.grassecon.net/kamikazechaser/vise/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -9,10 +9,10 @@ import (
|
|||||||
|
|
||||||
testdataloader "github.com/peteole/testdata-loader"
|
testdataloader "github.com/peteole/testdata-loader"
|
||||||
|
|
||||||
"git.defalsify.org/vise/cache"
|
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||||
"git.defalsify.org/vise/engine"
|
"git.grassecon.net/kamikazechaser/vise/engine"
|
||||||
"git.defalsify.org/vise/resource"
|
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||||
"git.defalsify.org/vise/state"
|
"git.grassecon.net/kamikazechaser/vise/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -30,7 +30,7 @@ type verifyResource struct {
|
|||||||
st *state.State
|
st *state.State
|
||||||
}
|
}
|
||||||
|
|
||||||
func(vr *verifyResource) verify(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
func (vr *verifyResource) verify(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
||||||
var err error
|
var err error
|
||||||
if string(input) == "something" {
|
if string(input) == "something" {
|
||||||
_, err = vr.st.SetFlag(USERFLAG_HAVESOMETHING)
|
_, err = vr.st.SetFlag(USERFLAG_HAVESOMETHING)
|
||||||
@ -40,7 +40,7 @@ func(vr *verifyResource) verify(sym string, input []byte, ctx context.Context) (
|
|||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func(vr *verifyResource) again(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
func (vr *verifyResource) again(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
||||||
var err error
|
var err error
|
||||||
_, err = vr.st.ResetFlag(USERFLAG_HAVESOMETHING)
|
_, err = vr.st.ResetFlag(USERFLAG_HAVESOMETHING)
|
||||||
return resource.Result{}, err
|
return resource.Result{}, err
|
||||||
|
2
go.mod
2
go.mod
@ -1,4 +1,4 @@
|
|||||||
module git.defalsify.org/vise
|
module git.grassecon.net/kamikazechaser/vise
|
||||||
|
|
||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
|
@ -5,10 +5,11 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/fxamacker/cbor/v2"
|
"github.com/fxamacker/cbor/v2"
|
||||||
|
|
||||||
"git.defalsify.org/vise/cache"
|
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||||
"git.defalsify.org/vise/state"
|
"git.grassecon.net/kamikazechaser/vise/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FsPersister is an implementation of Persister that saves state to the file system.
|
// FsPersister is an implementation of Persister that saves state to the file system.
|
||||||
@ -34,35 +35,35 @@ func NewFsPersister(dir string) *FsPersister {
|
|||||||
// WithContent sets a current State and Cache object.
|
// WithContent sets a current State and Cache object.
|
||||||
//
|
//
|
||||||
// This method is normally called before Serialize / Save.
|
// This method is normally called before Serialize / Save.
|
||||||
func(p *FsPersister) WithContent(st *state.State, ca *cache.Cache) *FsPersister {
|
func (p *FsPersister) WithContent(st *state.State, ca *cache.Cache) *FsPersister {
|
||||||
p.State = st
|
p.State = st
|
||||||
p.Memory = ca
|
p.Memory = ca
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetState implements the Persister interface.
|
// GetState implements the Persister interface.
|
||||||
func(p *FsPersister) GetState() *state.State {
|
func (p *FsPersister) GetState() *state.State {
|
||||||
return p.State
|
return p.State
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetState implements the Persister interface.
|
// GetState implements the Persister interface.
|
||||||
func(p *FsPersister) GetMemory() cache.Memory {
|
func (p *FsPersister) GetMemory() cache.Memory {
|
||||||
return p.Memory
|
return p.Memory
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetState implements the Persister interface.
|
// GetState implements the Persister interface.
|
||||||
func(p *FsPersister) Serialize() ([]byte, error) {
|
func (p *FsPersister) Serialize() ([]byte, error) {
|
||||||
return cbor.Marshal(p)
|
return cbor.Marshal(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetState implements the Persister interface.
|
// GetState implements the Persister interface.
|
||||||
func(p *FsPersister) Deserialize(b []byte) error {
|
func (p *FsPersister) Deserialize(b []byte) error {
|
||||||
err := cbor.Unmarshal(b, p)
|
err := cbor.Unmarshal(b, p)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetState implements the Persister interface.
|
// GetState implements the Persister interface.
|
||||||
func(p *FsPersister) Save(key string) error {
|
func (p *FsPersister) Save(key string) error {
|
||||||
b, err := p.Serialize()
|
b, err := p.Serialize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -73,7 +74,7 @@ func(p *FsPersister) Save(key string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetState implements the Persister interface.
|
// GetState implements the Persister interface.
|
||||||
func(p *FsPersister) Load(key string) error {
|
func (p *FsPersister) Load(key string) error {
|
||||||
fp := path.Join(p.dir, key)
|
fp := path.Join(p.dir, key)
|
||||||
b, err := ioutil.ReadFile(fp)
|
b, err := ioutil.ReadFile(fp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -7,9 +7,9 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.defalsify.org/vise/cache"
|
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||||
"git.defalsify.org/vise/state"
|
"git.grassecon.net/kamikazechaser/vise/state"
|
||||||
"git.defalsify.org/vise/vm"
|
"git.grassecon.net/kamikazechaser/vise/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSerializeState(t *testing.T) {
|
func TestSerializeState(t *testing.T) {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package persist
|
package persist
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.defalsify.org/vise/cache"
|
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||||
"git.defalsify.org/vise/state"
|
"git.grassecon.net/kamikazechaser/vise/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Persister interface defines the methods needed for a component that can store the execution state to a storage location.
|
// Persister interface defines the methods needed for a component that can store the execution state to a storage location.
|
||||||
@ -14,4 +14,3 @@ type Persister interface {
|
|||||||
GetState() *state.State // Get the currently loaded State object.
|
GetState() *state.State // Get the currently loaded State object.
|
||||||
GetMemory() cache.Memory // Get the currently loaded Cache object.
|
GetMemory() cache.Memory // Get the currently loaded Cache object.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,8 +7,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"git.defalsify.org/vise/cache"
|
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||||
"git.defalsify.org/vise/resource"
|
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Page exectues output rendering into pages constrained by size.
|
// Page exectues output rendering into pages constrained by size.
|
||||||
@ -31,7 +31,7 @@ func NewPage(cache cache.Memory, rs resource.Resource) *Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithMenu sets a menu renderer for the page.
|
// WithMenu sets a menu renderer for the page.
|
||||||
func(pg *Page) WithMenu(menu *Menu) *Page {
|
func (pg *Page) WithMenu(menu *Menu) *Page {
|
||||||
pg.menu = menu
|
pg.menu = menu
|
||||||
if pg.sizer != nil {
|
if pg.sizer != nil {
|
||||||
pg.sizer = pg.sizer.WithMenuSize(pg.menu.ReservedSize())
|
pg.sizer = pg.sizer.WithMenuSize(pg.menu.ReservedSize())
|
||||||
@ -40,7 +40,7 @@ func(pg *Page) WithMenu(menu *Menu) *Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithSizer sets a size constraints definition for the page.
|
// WithSizer sets a size constraints definition for the page.
|
||||||
func(pg *Page) WithSizer(sizer *Sizer) *Page {
|
func (pg *Page) WithSizer(sizer *Sizer) *Page {
|
||||||
pg.sizer = sizer
|
pg.sizer = sizer
|
||||||
if pg.menu != nil {
|
if pg.menu != nil {
|
||||||
pg.sizer = pg.sizer.WithMenuSize(pg.menu.ReservedSize())
|
pg.sizer = pg.sizer.WithMenuSize(pg.menu.ReservedSize())
|
||||||
@ -49,7 +49,7 @@ func(pg *Page) WithSizer(sizer *Sizer) *Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Usage returns size used by values and menu, and remaining size available
|
// Usage returns size used by values and menu, and remaining size available
|
||||||
func(pg *Page) Usage() (uint32, uint32, error) {
|
func (pg *Page) Usage() (uint32, uint32, error) {
|
||||||
var l int
|
var l int
|
||||||
var c uint16
|
var c uint16
|
||||||
for k, v := range pg.cacheMap {
|
for k, v := range pg.cacheMap {
|
||||||
@ -62,7 +62,7 @@ func(pg *Page) Usage() (uint32, uint32, error) {
|
|||||||
log.Printf("v %x %v %v %v %v", []byte(v), len(v), l, sz, c)
|
log.Printf("v %x %v %v %v %v", []byte(v), len(v), l, sz, c)
|
||||||
}
|
}
|
||||||
r := uint32(l)
|
r := uint32(l)
|
||||||
rsv := uint32(c)-r
|
rsv := uint32(c) - r
|
||||||
if pg.menu != nil {
|
if pg.menu != nil {
|
||||||
r += uint32(pg.menu.ReservedSize())
|
r += uint32(pg.menu.ReservedSize())
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ func(pg *Page) Usage() (uint32, uint32, error) {
|
|||||||
// After this, Val() will return the value for the key, and Size() will include the value size and limitations in its calculations.
|
// After this, Val() will return the value for the key, and Size() will include the value size and limitations in its calculations.
|
||||||
//
|
//
|
||||||
// Only one symbol with no size limitation may be mapped at the current level.
|
// Only one symbol with no size limitation may be mapped at the current level.
|
||||||
func(pg *Page) Map(key string) error {
|
func (pg *Page) Map(key string) error {
|
||||||
v, err := pg.cache.Get(key)
|
v, err := pg.cache.Get(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -103,7 +103,7 @@ func(pg *Page) Map(key string) error {
|
|||||||
// Val gets the mapped content for the given symbol.
|
// Val gets the mapped content for the given symbol.
|
||||||
//
|
//
|
||||||
// Fails if key is not mapped.
|
// Fails if key is not mapped.
|
||||||
func(pg *Page) Val(key string) (string, error) {
|
func (pg *Page) Val(key string) (string, error) {
|
||||||
r := pg.cacheMap[key]
|
r := pg.cacheMap[key]
|
||||||
if len(r) == 0 {
|
if len(r) == 0 {
|
||||||
return "", fmt.Errorf("key %v not mapped", key)
|
return "", fmt.Errorf("key %v not mapped", key)
|
||||||
@ -112,7 +112,7 @@ func(pg *Page) Val(key string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sizes returned the actual used bytes by each mapped symbol.
|
// Sizes returned the actual used bytes by each mapped symbol.
|
||||||
func(pg *Page) Sizes() (map[string]uint16, error) {
|
func (pg *Page) Sizes() (map[string]uint16, error) {
|
||||||
sizes := make(map[string]uint16)
|
sizes := make(map[string]uint16)
|
||||||
var haveSink bool
|
var haveSink bool
|
||||||
for k, _ := range pg.cacheMap {
|
for k, _ := range pg.cacheMap {
|
||||||
@ -131,7 +131,7 @@ func(pg *Page) Sizes() (map[string]uint16, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RenderTemplate is an adapter to implement the builtin golang text template renderer as resource.RenderTemplate.
|
// RenderTemplate is an adapter to implement the builtin golang text template renderer as resource.RenderTemplate.
|
||||||
func(pg *Page) RenderTemplate(sym string, values map[string]string, idx uint16) (string, error) {
|
func (pg *Page) RenderTemplate(sym string, values map[string]string, idx uint16) (string, error) {
|
||||||
tpl, err := pg.resource.GetTemplate(sym)
|
tpl, err := pg.resource.GetTemplate(sym)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -151,7 +151,6 @@ func(pg *Page) RenderTemplate(sym string, values map[string]string, idx uint16)
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
b := bytes.NewBuffer([]byte{})
|
b := bytes.NewBuffer([]byte{})
|
||||||
err = tp.Execute(b, values)
|
err = tp.Execute(b, values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -161,7 +160,7 @@ func(pg *Page) RenderTemplate(sym string, values map[string]string, idx uint16)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render renders the current mapped content and menu state against the template associated with the symbol.
|
// Render renders the current mapped content and menu state against the template associated with the symbol.
|
||||||
func(pg *Page) Render(sym string, idx uint16) (string, error) {
|
func (pg *Page) Render(sym string, idx uint16) (string, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
values, err := pg.prepare(sym, pg.cacheMap, idx)
|
values, err := pg.prepare(sym, pg.cacheMap, idx)
|
||||||
@ -175,14 +174,14 @@ func(pg *Page) Render(sym string, idx uint16) (string, error) {
|
|||||||
// Reset prepared the Page object for re-use.
|
// Reset prepared the Page object for re-use.
|
||||||
//
|
//
|
||||||
// It clears mappings and removes the sink definition.
|
// It clears mappings and removes the sink definition.
|
||||||
func(pg *Page) Reset() {
|
func (pg *Page) Reset() {
|
||||||
pg.sink = nil
|
pg.sink = nil
|
||||||
pg.cacheMap = make(map[string]string)
|
pg.cacheMap = make(map[string]string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// render menu and all syms except sink, split sink into display chunks
|
// render menu and all syms except sink, split sink into display chunks
|
||||||
// TODO: Function too long, split up
|
// TODO: Function too long, split up
|
||||||
func(pg *Page) prepare(sym string, values map[string]string, idx uint16) (map[string]string, error) {
|
func (pg *Page) prepare(sym string, values map[string]string, idx uint16) (map[string]string, error) {
|
||||||
var sink string
|
var sink string
|
||||||
|
|
||||||
if pg.sizer == nil {
|
if pg.sizer == nil {
|
||||||
@ -259,7 +258,7 @@ func(pg *Page) prepare(sym string, values map[string]string, idx uint16) (map[st
|
|||||||
for i, v := range sinkValues {
|
for i, v := range sinkValues {
|
||||||
l += len(v)
|
l += len(v)
|
||||||
log.Printf("processing sinkvalue %v: %s", i, v)
|
log.Printf("processing sinkvalue %v: %s", i, v)
|
||||||
if uint32(l) > netRemaining - 1 {
|
if uint32(l) > netRemaining-1 {
|
||||||
if tb.Len() == 0 {
|
if tb.Len() == 0 {
|
||||||
return nil, fmt.Errorf("capacity insufficient for sink field %v", i)
|
return nil, fmt.Errorf("capacity insufficient for sink field %v", i)
|
||||||
}
|
}
|
||||||
@ -303,7 +302,7 @@ func(pg *Page) prepare(sym string, values map[string]string, idx uint16) (map[st
|
|||||||
}
|
}
|
||||||
|
|
||||||
// render template, menu (if it exists), and audit size constraint (if it exists).
|
// render template, menu (if it exists), and audit size constraint (if it exists).
|
||||||
func(pg *Page) render(sym string, values map[string]string, idx uint16) (string, error) {
|
func (pg *Page) render(sym string, values map[string]string, idx uint16) (string, error) {
|
||||||
var ok bool
|
var ok bool
|
||||||
r := ""
|
r := ""
|
||||||
s, err := pg.RenderTemplate(sym, values, idx)
|
s, err := pg.RenderTemplate(sym, values, idx)
|
||||||
@ -332,4 +331,3 @@ func(pg *Page) render(sym string, values map[string]string, idx uint16) (string,
|
|||||||
}
|
}
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,10 +3,9 @@ package render
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.defalsify.org/vise/cache"
|
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func TestPageCurrentSize(t *testing.T) {
|
func TestPageCurrentSize(t *testing.T) {
|
||||||
t.Skip("usage is not in use, and it is unclear how it should be calculated")
|
t.Skip("usage is not in use, and it is unclear how it should be calculated")
|
||||||
ca := cache.NewCache()
|
ca := cache.NewCache()
|
||||||
|
@ -5,9 +5,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.defalsify.org/vise/state"
|
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||||
"git.defalsify.org/vise/resource"
|
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||||
"git.defalsify.org/vise/cache"
|
"git.grassecon.net/kamikazechaser/vise/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestSizeResource struct {
|
type TestSizeResource struct {
|
||||||
@ -172,7 +172,6 @@ lala poo
|
|||||||
1:foo the foo
|
1:foo the foo
|
||||||
2:go to bar`
|
2:go to bar`
|
||||||
|
|
||||||
|
|
||||||
if r != expect {
|
if r != expect {
|
||||||
t.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, r)
|
t.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, r)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.defalsify.org/vise/state"
|
"git.grassecon.net/kamikazechaser/vise/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StateResource struct {
|
type StateResource struct {
|
||||||
@ -14,13 +14,13 @@ func ToStateResource(rs Resource) *StateResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewStateResource(st *state.State) *StateResource {
|
func NewStateResource(st *state.State) *StateResource {
|
||||||
return &StateResource {
|
return &StateResource{
|
||||||
NewMenuResource(),
|
NewMenuResource(),
|
||||||
st,
|
st,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func(sr *StateResource) WithState(st *state.State) *StateResource {
|
func (sr *StateResource) WithState(st *state.State) *StateResource {
|
||||||
if sr.st != nil {
|
if sr.st != nil {
|
||||||
panic("state already set")
|
panic("state already set")
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package resource
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.defalsify.org/vise/state"
|
"git.grassecon.net/kamikazechaser/vise/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStateResourceInit(t *testing.T) {
|
func TestStateResourceInit(t *testing.T) {
|
||||||
|
3
testdata/testdata.go
vendored
3
testdata/testdata.go
vendored
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
testdataloader "github.com/peteole/testdata-loader"
|
testdataloader "github.com/peteole/testdata-loader"
|
||||||
|
|
||||||
"git.defalsify.org/vise/vm"
|
"git.grassecon.net/kamikazechaser/vise/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type genFunc func() error
|
type genFunc func() error
|
||||||
@ -177,7 +177,6 @@ func Generate() (string, error) {
|
|||||||
return dir, err
|
return dir, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Generate outputs bytecode, templates and content symbols to a specified directory.
|
// Generate outputs bytecode, templates and content symbols to a specified directory.
|
||||||
//
|
//
|
||||||
// The directory must exist, and must not have been used already in the same code execution.
|
// The directory must exist, and must not have been used already in the same code execution.
|
||||||
|
@ -5,8 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"git.defalsify.org/vise/cache"
|
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||||
"git.defalsify.org/vise/state"
|
"git.grassecon.net/kamikazechaser/vise/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -16,7 +16,6 @@ var (
|
|||||||
ctrlRegex = regexp.MustCompile(ctrlRegexStr)
|
ctrlRegex = regexp.MustCompile(ctrlRegexStr)
|
||||||
symRegexStr = "^[a-zA-Z0-9][a-zA-Z0-9_]+$"
|
symRegexStr = "^[a-zA-Z0-9][a-zA-Z0-9_]+$"
|
||||||
symRegex = regexp.MustCompile(symRegexStr)
|
symRegex = regexp.MustCompile(symRegexStr)
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// CheckInput validates the given byte string as client input.
|
// CheckInput validates the given byte string as client input.
|
||||||
|
43
vm/runner.go
43
vm/runner.go
@ -5,10 +5,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"git.defalsify.org/vise/cache"
|
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||||
"git.defalsify.org/vise/render"
|
"git.grassecon.net/kamikazechaser/vise/render"
|
||||||
"git.defalsify.org/vise/resource"
|
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||||
"git.defalsify.org/vise/state"
|
"git.grassecon.net/kamikazechaser/vise/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Vm holds sub-components mutated by the vm execution.
|
// Vm holds sub-components mutated by the vm execution.
|
||||||
@ -36,7 +36,7 @@ func NewVm(st *state.State, rs resource.Resource, ca cache.Memory, sizer *render
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reset re-initializes sub-components for output rendering.
|
// Reset re-initializes sub-components for output rendering.
|
||||||
func(vmi *Vm) Reset() {
|
func (vmi *Vm) Reset() {
|
||||||
vmi.mn = render.NewMenu()
|
vmi.mn = render.NewMenu()
|
||||||
vmi.pg.Reset()
|
vmi.pg.Reset()
|
||||||
vmi.pg = vmi.pg.WithMenu(vmi.mn)
|
vmi.pg = vmi.pg.WithMenu(vmi.mn)
|
||||||
@ -50,7 +50,7 @@ func(vmi *Vm) Reset() {
|
|||||||
// Each step may update the state.
|
// Each step may update the state.
|
||||||
//
|
//
|
||||||
// On error, the remaining instructions will be returned. State will not be rolled back.
|
// On error, the remaining instructions will be returned. State will not be rolled back.
|
||||||
func(vm *Vm) Run(b []byte, ctx context.Context) ([]byte, error) {
|
func (vm *Vm) Run(b []byte, ctx context.Context) ([]byte, error) {
|
||||||
running := true
|
running := true
|
||||||
for running {
|
for running {
|
||||||
r, err := vm.st.MatchFlag(state.FLAG_TERMINATE, false)
|
r, err := vm.st.MatchFlag(state.FLAG_TERMINATE, false)
|
||||||
@ -142,7 +142,7 @@ func(vm *Vm) Run(b []byte, ctx context.Context) ([]byte, error) {
|
|||||||
// If input has not been matched, a default invalid input page should be generated aswell as a possiblity of return to last screen (or exit).
|
// If input has not been matched, a default invalid input page should be generated aswell as a possiblity of return to last screen (or exit).
|
||||||
//
|
//
|
||||||
// If the termination flag has been set but not yet handled, execution is allowed to terminate.
|
// If the termination flag has been set but not yet handled, execution is allowed to terminate.
|
||||||
func(vm *Vm) RunDeadCheck(b []byte, ctx context.Context) ([]byte, error) {
|
func (vm *Vm) RunDeadCheck(b []byte, ctx context.Context) ([]byte, error) {
|
||||||
if len(b) > 0 {
|
if len(b) > 0 {
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
@ -167,7 +167,6 @@ func(vm *Vm) RunDeadCheck(b []byte, ctx context.Context) ([]byte, error) {
|
|||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
log.Printf("no code remaining but not terminating")
|
log.Printf("no code remaining but not terminating")
|
||||||
location, _ := vm.st.Where()
|
location, _ := vm.st.Where()
|
||||||
if location == "" {
|
if location == "" {
|
||||||
@ -178,14 +177,14 @@ func(vm *Vm) RunDeadCheck(b []byte, ctx context.Context) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RunMap executes the MAP opcode
|
// RunMap executes the MAP opcode
|
||||||
func(vm *Vm) RunMap(b []byte, ctx context.Context) ([]byte, error) {
|
func (vm *Vm) RunMap(b []byte, ctx context.Context) ([]byte, error) {
|
||||||
sym, b, err := ParseMap(b)
|
sym, b, err := ParseMap(b)
|
||||||
err = vm.pg.Map(sym)
|
err = vm.pg.Map(sym)
|
||||||
return b, err
|
return b, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunMap executes the CATCH opcode
|
// RunMap executes the CATCH opcode
|
||||||
func(vm *Vm) RunCatch(b []byte, ctx context.Context) ([]byte, error) {
|
func (vm *Vm) RunCatch(b []byte, ctx context.Context) ([]byte, error) {
|
||||||
sym, sig, mode, b, err := ParseCatch(b)
|
sym, sig, mode, b, err := ParseCatch(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return b, err
|
return b, err
|
||||||
@ -220,7 +219,7 @@ func(vm *Vm) RunCatch(b []byte, ctx context.Context) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RunMap executes the CROAK opcode
|
// RunMap executes the CROAK opcode
|
||||||
func(vm *Vm) RunCroak(b []byte, ctx context.Context) ([]byte, error) {
|
func (vm *Vm) RunCroak(b []byte, ctx context.Context) ([]byte, error) {
|
||||||
sig, mode, b, err := ParseCroak(b)
|
sig, mode, b, err := ParseCroak(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return b, err
|
return b, err
|
||||||
@ -240,7 +239,7 @@ func(vm *Vm) RunCroak(b []byte, ctx context.Context) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RunLoad executes the LOAD opcode
|
// RunLoad executes the LOAD opcode
|
||||||
func(vm *Vm) RunLoad(b []byte, ctx context.Context) ([]byte, error) {
|
func (vm *Vm) RunLoad(b []byte, ctx context.Context) ([]byte, error) {
|
||||||
sym, sz, b, err := ParseLoad(b)
|
sym, sz, b, err := ParseLoad(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return b, err
|
return b, err
|
||||||
@ -254,7 +253,7 @@ func(vm *Vm) RunLoad(b []byte, ctx context.Context) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RunLoad executes the RELOAD opcode
|
// RunLoad executes the RELOAD opcode
|
||||||
func(vm *Vm) RunReload(b []byte, ctx context.Context) ([]byte, error) {
|
func (vm *Vm) RunReload(b []byte, ctx context.Context) ([]byte, error) {
|
||||||
sym, b, err := ParseReload(b)
|
sym, b, err := ParseReload(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return b, err
|
return b, err
|
||||||
@ -275,7 +274,7 @@ func(vm *Vm) RunReload(b []byte, ctx context.Context) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RunLoad executes the MOVE opcode
|
// RunLoad executes the MOVE opcode
|
||||||
func(vm *Vm) RunMove(b []byte, ctx context.Context) ([]byte, error) {
|
func (vm *Vm) RunMove(b []byte, ctx context.Context) ([]byte, error) {
|
||||||
sym, b, err := ParseMove(b)
|
sym, b, err := ParseMove(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return b, err
|
return b, err
|
||||||
@ -300,7 +299,7 @@ func(vm *Vm) RunMove(b []byte, ctx context.Context) ([]byte, error) {
|
|||||||
|
|
||||||
// RunIncmp executes the INCMP opcode
|
// RunIncmp executes the INCMP opcode
|
||||||
// TODO: create state transition table and simplify flow
|
// TODO: create state transition table and simplify flow
|
||||||
func(vm *Vm) RunInCmp(b []byte, ctx context.Context) ([]byte, error) {
|
func (vm *Vm) RunInCmp(b []byte, ctx context.Context) ([]byte, error) {
|
||||||
sym, target, b, err := ParseInCmp(b)
|
sym, target, b, err := ParseInCmp(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return b, err
|
return b, err
|
||||||
@ -377,7 +376,7 @@ func(vm *Vm) RunInCmp(b []byte, ctx context.Context) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RunHalt executes the HALT opcode
|
// RunHalt executes the HALT opcode
|
||||||
func(vm *Vm) RunHalt(b []byte, ctx context.Context) ([]byte, error) {
|
func (vm *Vm) RunHalt(b []byte, ctx context.Context) ([]byte, error) {
|
||||||
var err error
|
var err error
|
||||||
b, err = ParseHalt(b)
|
b, err = ParseHalt(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -393,14 +392,14 @@ func(vm *Vm) RunHalt(b []byte, ctx context.Context) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RunMSize executes the MSIZE opcode
|
// RunMSize executes the MSIZE opcode
|
||||||
func(vm *Vm) RunMSize(b []byte, ctx context.Context) ([]byte, error) {
|
func (vm *Vm) RunMSize(b []byte, ctx context.Context) ([]byte, error) {
|
||||||
log.Printf("WARNING MSIZE not yet implemented")
|
log.Printf("WARNING MSIZE not yet implemented")
|
||||||
_, _, b, err := ParseMSize(b)
|
_, _, b, err := ParseMSize(b)
|
||||||
return b, err
|
return b, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunMOut executes the MOUT opcode
|
// RunMOut executes the MOUT opcode
|
||||||
func(vm *Vm) RunMOut(b []byte, ctx context.Context) ([]byte, error) {
|
func (vm *Vm) RunMOut(b []byte, ctx context.Context) ([]byte, error) {
|
||||||
choice, title, b, err := ParseMOut(b)
|
choice, title, b, err := ParseMOut(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return b, err
|
return b, err
|
||||||
@ -410,7 +409,7 @@ func(vm *Vm) RunMOut(b []byte, ctx context.Context) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RunMNext executes the MNEXT opcode
|
// RunMNext executes the MNEXT opcode
|
||||||
func(vm *Vm) RunMNext(b []byte, ctx context.Context) ([]byte, error) {
|
func (vm *Vm) RunMNext(b []byte, ctx context.Context) ([]byte, error) {
|
||||||
selector, display, b, err := ParseMNext(b)
|
selector, display, b, err := ParseMNext(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return b, err
|
return b, err
|
||||||
@ -424,7 +423,7 @@ func(vm *Vm) RunMNext(b []byte, ctx context.Context) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RunMPrev executes the MPREV opcode
|
// RunMPrev executes the MPREV opcode
|
||||||
func(vm *Vm) RunMPrev(b []byte, ctx context.Context) ([]byte, error) {
|
func (vm *Vm) RunMPrev(b []byte, ctx context.Context) ([]byte, error) {
|
||||||
selector, display, b, err := ParseMPrev(b)
|
selector, display, b, err := ParseMPrev(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return b, err
|
return b, err
|
||||||
@ -438,7 +437,7 @@ func(vm *Vm) RunMPrev(b []byte, ctx context.Context) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render wraps output rendering, and handles error when attempting to browse beyond the rendered page count.
|
// Render wraps output rendering, and handles error when attempting to browse beyond the rendered page count.
|
||||||
func(vm *Vm) Render(ctx context.Context) (string, error) {
|
func (vm *Vm) Render(ctx context.Context) (string, error) {
|
||||||
changed, err := vm.st.ResetFlag(state.FLAG_DIRTY)
|
changed, err := vm.st.ResetFlag(state.FLAG_DIRTY)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -464,7 +463,7 @@ func(vm *Vm) Render(ctx context.Context) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// retrieve data for key
|
// retrieve data for key
|
||||||
func(vm *Vm) refresh(key string, rs resource.Resource, ctx context.Context) (string, error) {
|
func (vm *Vm) refresh(key string, rs resource.Resource, ctx context.Context) (string, error) {
|
||||||
fn, err := rs.FuncFor(key)
|
fn, err := rs.FuncFor(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -7,10 +7,10 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.defalsify.org/vise/cache"
|
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||||
"git.defalsify.org/vise/render"
|
"git.grassecon.net/kamikazechaser/vise/render"
|
||||||
"git.defalsify.org/vise/resource"
|
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||||
"git.defalsify.org/vise/state"
|
"git.grassecon.net/kamikazechaser/vise/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
var dynVal = "three"
|
var dynVal = "three"
|
||||||
@ -105,14 +105,14 @@ func (r TestResource) FuncFor(sym string) (resource.EntryFunc, error) {
|
|||||||
return nil, fmt.Errorf("invalid function: '%s'", sym)
|
return nil, fmt.Errorf("invalid function: '%s'", sym)
|
||||||
}
|
}
|
||||||
|
|
||||||
func(r TestResource) getInput(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
func (r TestResource) getInput(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
||||||
v, err := r.state.GetInput()
|
v, err := r.state.GetInput()
|
||||||
return resource.Result{
|
return resource.Result{
|
||||||
Content: string(v),
|
Content: string(v),
|
||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func(r TestResource) GetCode(sym string) ([]byte, error) {
|
func (r TestResource) GetCode(sym string) ([]byte, error) {
|
||||||
var b []byte
|
var b []byte
|
||||||
switch sym {
|
switch sym {
|
||||||
case "_catch":
|
case "_catch":
|
||||||
@ -456,7 +456,6 @@ func TestRunReturn(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func TestRunLoadInput(t *testing.T) {
|
func TestRunLoadInput(t *testing.T) {
|
||||||
st := state.NewState(5)
|
st := state.NewState(5)
|
||||||
rs := TestResource{}
|
rs := TestResource{}
|
||||||
|
Loading…
Reference in New Issue
Block a user