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
|
||||
|
||||
**Not yet implemeennted**
|
||||
**Not yet implemented**
|
||||
|
||||
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/lexer"
|
||||
|
||||
"git.defalsify.org/vise/vm"
|
||||
"git.grassecon.net/kamikazechaser/vise/vm"
|
||||
)
|
||||
|
||||
|
||||
// Asm assembles bytecode from the vise assembly mini-language.
|
||||
type Asm struct {
|
||||
Instructions []*Instruction `@@*`
|
||||
@ -312,7 +311,7 @@ func writeSize(w *bytes.Buffer, n uint32) (int, error) {
|
||||
}
|
||||
w.Write([]byte{byte(sz)})
|
||||
binary.BigEndian.PutUint32(bn[:], n)
|
||||
c := 4-sz
|
||||
c := 4 - sz
|
||||
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.
|
||||
func(bt *Batcher) MenuExit(w io.Writer) (int, error) {
|
||||
func (bt *Batcher) MenuExit(w io.Writer) (int, error) {
|
||||
if !bt.inMenu {
|
||||
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.
|
||||
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
|
||||
var selector 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
|
||||
func(bt *Batcher) Exit(w io.Writer) (int, error) {
|
||||
func (bt *Batcher) Exit(w io.Writer) (int, error) {
|
||||
return bt.MenuExit(w)
|
||||
}
|
||||
|
||||
@ -373,9 +372,7 @@ func Parse(s string, w io.Writer) (int, error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
batch := Batcher{
|
||||
|
||||
}
|
||||
batch := Batcher{}
|
||||
|
||||
var rn int
|
||||
for _, v := range ast.Instructions {
|
||||
|
@ -7,10 +7,9 @@ import (
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
"git.defalsify.org/vise/vm"
|
||||
"git.grassecon.net/kamikazechaser/vise/vm"
|
||||
)
|
||||
|
||||
|
||||
func TestParserInit(t *testing.T) {
|
||||
var b []byte
|
||||
b = vm.NewLine(b, vm.HALT, nil, nil, nil)
|
||||
|
@ -3,7 +3,7 @@ package asm
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.defalsify.org/vise/vm"
|
||||
"git.grassecon.net/kamikazechaser/vise/vm"
|
||||
)
|
||||
|
||||
// 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.
|
||||
//
|
||||
// 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]
|
||||
if bopCode == 0 {
|
||||
return fmt.Errorf("unknown menu instruction: %v", bop)
|
||||
|
@ -3,10 +3,9 @@ package asm
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.defalsify.org/vise/vm"
|
||||
"git.grassecon.net/kamikazechaser/vise/vm"
|
||||
)
|
||||
|
||||
|
||||
func TestMenuInterpreter(t *testing.T) {
|
||||
m := NewMenuProcessor()
|
||||
err := m.Add("DOWN", "0", "inky", "foo")
|
||||
|
@ -6,11 +6,11 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"git.defalsify.org/vise/asm"
|
||||
"git.grassecon.net/kamikazechaser/vise/asm"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if (len(os.Args) < 2) {
|
||||
if len(os.Args) < 2 {
|
||||
os.Exit(1)
|
||||
}
|
||||
fp := os.Args[1]
|
||||
|
@ -2,14 +2,14 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"git.defalsify.org/vise/vm"
|
||||
"git.grassecon.net/kamikazechaser/vise/vm"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if (len(os.Args) < 2) {
|
||||
if len(os.Args) < 2 {
|
||||
os.Exit(1)
|
||||
}
|
||||
fp := os.Args[1]
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.defalsify.org/vise/testdata"
|
||||
"git.grassecon.net/kamikazechaser/vise/testdata"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.defalsify.org/vise/engine"
|
||||
"git.grassecon.net/kamikazechaser/vise/engine"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -3,9 +3,9 @@ package engine
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.defalsify.org/vise/cache"
|
||||
"git.defalsify.org/vise/resource"
|
||||
"git.defalsify.org/vise/state"
|
||||
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||
"git.grassecon.net/kamikazechaser/vise/state"
|
||||
)
|
||||
|
||||
// NewDefaultEngine is a convenience function to instantiate a filesystem-backed engine with no output constraints.
|
||||
|
@ -6,11 +6,11 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
|
||||
"git.defalsify.org/vise/cache"
|
||||
"git.defalsify.org/vise/render"
|
||||
"git.defalsify.org/vise/resource"
|
||||
"git.defalsify.org/vise/state"
|
||||
"git.defalsify.org/vise/vm"
|
||||
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||
"git.grassecon.net/kamikazechaser/vise/render"
|
||||
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||
"git.grassecon.net/kamikazechaser/vise/state"
|
||||
"git.grassecon.net/kamikazechaser/vise/vm"
|
||||
)
|
||||
|
||||
// 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.
|
||||
//
|
||||
// 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 {
|
||||
log.Printf("already initialized")
|
||||
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.
|
||||
// - 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.
|
||||
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)
|
||||
if err != nil {
|
||||
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.
|
||||
func(en *Engine) reset(ctx context.Context) (bool, error) {
|
||||
func (en *Engine) reset(ctx context.Context) (bool, error) {
|
||||
var err error
|
||||
var isTop bool
|
||||
for !isTop {
|
||||
|
@ -8,10 +8,10 @@ import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"git.defalsify.org/vise/cache"
|
||||
"git.defalsify.org/vise/resource"
|
||||
"git.defalsify.org/vise/state"
|
||||
"git.defalsify.org/vise/testdata"
|
||||
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||
"git.grassecon.net/kamikazechaser/vise/state"
|
||||
"git.grassecon.net/kamikazechaser/vise/testdata"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -26,7 +26,7 @@ type FsWrapper struct {
|
||||
|
||||
func NewFsWrapper(path string, st *state.State) FsWrapper {
|
||||
rs := resource.NewFsResource(path)
|
||||
wr := FsWrapper {
|
||||
wr := FsWrapper{
|
||||
&rs,
|
||||
st,
|
||||
}
|
||||
@ -36,26 +36,26 @@ func NewFsWrapper(path string, st *state.State) FsWrapper {
|
||||
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{
|
||||
Content: "one",
|
||||
}, 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{
|
||||
Content: "tinkywinky",
|
||||
}, 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)
|
||||
return resource.Result{
|
||||
Content: r,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func(fs FsWrapper) GetCode(sym string) ([]byte, error) {
|
||||
func (fs FsWrapper) GetCode(sym string) ([]byte, error) {
|
||||
sym += ".bin"
|
||||
fp := path.Join(fs.Path, sym)
|
||||
r, err := ioutil.ReadFile(fp)
|
||||
@ -137,7 +137,6 @@ func TestEngineExecInvalidInput(t *testing.T) {
|
||||
rs := NewFsWrapper(dataDir, &st)
|
||||
ca := cache.NewCache().WithCacheSize(1024)
|
||||
|
||||
|
||||
en := NewEngine(Config{
|
||||
Root: "root",
|
||||
}, &st, &rs, ca, ctx)
|
||||
|
@ -8,9 +8,9 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.defalsify.org/vise/cache"
|
||||
"git.defalsify.org/vise/resource"
|
||||
"git.defalsify.org/vise/state"
|
||||
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||
"git.grassecon.net/kamikazechaser/vise/state"
|
||||
)
|
||||
|
||||
func TestLoopTop(t *testing.T) {
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"git.defalsify.org/vise/persist"
|
||||
"git.defalsify.org/vise/resource"
|
||||
"git.grassecon.net/kamikazechaser/vise/persist"
|
||||
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||
)
|
||||
|
||||
// RunPersisted performs a single vm execution from client input using a persisted state.
|
||||
|
@ -6,9 +6,9 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"git.defalsify.org/vise/cache"
|
||||
"git.defalsify.org/vise/persist"
|
||||
"git.defalsify.org/vise/state"
|
||||
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||
"git.grassecon.net/kamikazechaser/vise/persist"
|
||||
"git.grassecon.net/kamikazechaser/vise/state"
|
||||
)
|
||||
|
||||
func TestPersist(t *testing.T) {
|
||||
|
@ -11,10 +11,10 @@ import (
|
||||
|
||||
testdataloader "github.com/peteole/testdata-loader"
|
||||
|
||||
"git.defalsify.org/vise/cache"
|
||||
"git.defalsify.org/vise/engine"
|
||||
"git.defalsify.org/vise/resource"
|
||||
"git.defalsify.org/vise/state"
|
||||
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||
"git.grassecon.net/kamikazechaser/vise/engine"
|
||||
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||
"git.grassecon.net/kamikazechaser/vise/state"
|
||||
)
|
||||
|
||||
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)
|
||||
if pr.haveEntered {
|
||||
return nil
|
||||
@ -66,7 +66,7 @@ func(pr *profileResource) checkEntry() error {
|
||||
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")
|
||||
fp := path.Join(scriptDir, "myname.txt")
|
||||
err := ioutil.WriteFile(fp, input, 0600)
|
||||
@ -83,7 +83,7 @@ func(pr profileResource) nameSave(sym string, input []byte, ctx context.Context)
|
||||
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")
|
||||
fp := path.Join(scriptDir, "myemail.txt")
|
||||
err := ioutil.WriteFile(fp, input, 0600)
|
||||
|
@ -11,10 +11,10 @@ import (
|
||||
|
||||
testdataloader "github.com/peteole/testdata-loader"
|
||||
|
||||
"git.defalsify.org/vise/cache"
|
||||
"git.defalsify.org/vise/engine"
|
||||
"git.defalsify.org/vise/resource"
|
||||
"git.defalsify.org/vise/state"
|
||||
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||
"git.grassecon.net/kamikazechaser/vise/engine"
|
||||
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||
"git.grassecon.net/kamikazechaser/vise/state"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -9,10 +9,10 @@ import (
|
||||
|
||||
testdataloader "github.com/peteole/testdata-loader"
|
||||
|
||||
"git.defalsify.org/vise/cache"
|
||||
"git.defalsify.org/vise/engine"
|
||||
"git.defalsify.org/vise/resource"
|
||||
"git.defalsify.org/vise/state"
|
||||
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||
"git.grassecon.net/kamikazechaser/vise/engine"
|
||||
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||
"git.grassecon.net/kamikazechaser/vise/state"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -30,7 +30,7 @@ type verifyResource struct {
|
||||
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
|
||||
if string(input) == "something" {
|
||||
_, err = vr.st.SetFlag(USERFLAG_HAVESOMETHING)
|
||||
@ -40,7 +40,7 @@ func(vr *verifyResource) verify(sym string, input []byte, ctx context.Context) (
|
||||
}, 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
|
||||
_, err = vr.st.ResetFlag(USERFLAG_HAVESOMETHING)
|
||||
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
|
||||
|
||||
|
@ -5,10 +5,11 @@ import (
|
||||
"log"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/fxamacker/cbor/v2"
|
||||
|
||||
"git.defalsify.org/vise/cache"
|
||||
"git.defalsify.org/vise/state"
|
||||
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||
"git.grassecon.net/kamikazechaser/vise/state"
|
||||
)
|
||||
|
||||
// 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.
|
||||
//
|
||||
// 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.Memory = ca
|
||||
return p
|
||||
}
|
||||
|
||||
// GetState implements the Persister interface.
|
||||
func(p *FsPersister) GetState() *state.State {
|
||||
func (p *FsPersister) GetState() *state.State {
|
||||
return p.State
|
||||
}
|
||||
|
||||
// GetState implements the Persister interface.
|
||||
func(p *FsPersister) GetMemory() cache.Memory {
|
||||
func (p *FsPersister) GetMemory() cache.Memory {
|
||||
return p.Memory
|
||||
}
|
||||
|
||||
// GetState implements the Persister interface.
|
||||
func(p *FsPersister) Serialize() ([]byte, error) {
|
||||
func (p *FsPersister) Serialize() ([]byte, error) {
|
||||
return cbor.Marshal(p)
|
||||
}
|
||||
|
||||
// GetState implements the Persister interface.
|
||||
func(p *FsPersister) Deserialize(b []byte) error {
|
||||
func (p *FsPersister) Deserialize(b []byte) error {
|
||||
err := cbor.Unmarshal(b, p)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetState implements the Persister interface.
|
||||
func(p *FsPersister) Save(key string) error {
|
||||
func (p *FsPersister) Save(key string) error {
|
||||
b, err := p.Serialize()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -73,7 +74,7 @@ func(p *FsPersister) Save(key string) error {
|
||||
}
|
||||
|
||||
// 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)
|
||||
b, err := ioutil.ReadFile(fp)
|
||||
if err != nil {
|
||||
|
@ -7,9 +7,9 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"git.defalsify.org/vise/cache"
|
||||
"git.defalsify.org/vise/state"
|
||||
"git.defalsify.org/vise/vm"
|
||||
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||
"git.grassecon.net/kamikazechaser/vise/state"
|
||||
"git.grassecon.net/kamikazechaser/vise/vm"
|
||||
)
|
||||
|
||||
func TestSerializeState(t *testing.T) {
|
||||
|
@ -1,8 +1,8 @@
|
||||
package persist
|
||||
|
||||
import (
|
||||
"git.defalsify.org/vise/cache"
|
||||
"git.defalsify.org/vise/state"
|
||||
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||
"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.
|
||||
@ -14,4 +14,3 @@ type Persister interface {
|
||||
GetState() *state.State // Get the currently loaded State object.
|
||||
GetMemory() cache.Memory // Get the currently loaded Cache object.
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"git.defalsify.org/vise/cache"
|
||||
"git.defalsify.org/vise/resource"
|
||||
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||
)
|
||||
|
||||
// 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.
|
||||
func(pg *Page) WithMenu(menu *Menu) *Page {
|
||||
func (pg *Page) WithMenu(menu *Menu) *Page {
|
||||
pg.menu = menu
|
||||
if pg.sizer != nil {
|
||||
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.
|
||||
func(pg *Page) WithSizer(sizer *Sizer) *Page {
|
||||
func (pg *Page) WithSizer(sizer *Sizer) *Page {
|
||||
pg.sizer = sizer
|
||||
if pg.menu != nil {
|
||||
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
|
||||
func(pg *Page) Usage() (uint32, uint32, error) {
|
||||
func (pg *Page) Usage() (uint32, uint32, error) {
|
||||
var l int
|
||||
var c uint16
|
||||
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)
|
||||
}
|
||||
r := uint32(l)
|
||||
rsv := uint32(c)-r
|
||||
rsv := uint32(c) - r
|
||||
if pg.menu != nil {
|
||||
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.
|
||||
//
|
||||
// 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)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -103,7 +103,7 @@ func(pg *Page) Map(key string) error {
|
||||
// Val gets the mapped content for the given symbol.
|
||||
//
|
||||
// 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]
|
||||
if len(r) == 0 {
|
||||
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.
|
||||
func(pg *Page) Sizes() (map[string]uint16, error) {
|
||||
func (pg *Page) Sizes() (map[string]uint16, error) {
|
||||
sizes := make(map[string]uint16)
|
||||
var haveSink bool
|
||||
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.
|
||||
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)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@ -151,7 +151,6 @@ func(pg *Page) RenderTemplate(sym string, values map[string]string, idx uint16)
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
b := bytes.NewBuffer([]byte{})
|
||||
err = tp.Execute(b, values)
|
||||
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.
|
||||
func(pg *Page) Render(sym string, idx uint16) (string, error) {
|
||||
func (pg *Page) Render(sym string, idx uint16) (string, error) {
|
||||
var err error
|
||||
|
||||
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.
|
||||
//
|
||||
// It clears mappings and removes the sink definition.
|
||||
func(pg *Page) Reset() {
|
||||
func (pg *Page) Reset() {
|
||||
pg.sink = nil
|
||||
pg.cacheMap = make(map[string]string)
|
||||
}
|
||||
|
||||
// render menu and all syms except sink, split sink into display chunks
|
||||
// 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
|
||||
|
||||
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 {
|
||||
l += len(v)
|
||||
log.Printf("processing sinkvalue %v: %s", i, v)
|
||||
if uint32(l) > netRemaining - 1 {
|
||||
if uint32(l) > netRemaining-1 {
|
||||
if tb.Len() == 0 {
|
||||
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).
|
||||
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
|
||||
r := ""
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -3,10 +3,9 @@ package render
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.defalsify.org/vise/cache"
|
||||
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||
)
|
||||
|
||||
|
||||
func TestPageCurrentSize(t *testing.T) {
|
||||
t.Skip("usage is not in use, and it is unclear how it should be calculated")
|
||||
ca := cache.NewCache()
|
||||
|
@ -5,9 +5,9 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"git.defalsify.org/vise/state"
|
||||
"git.defalsify.org/vise/resource"
|
||||
"git.defalsify.org/vise/cache"
|
||||
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||
"git.grassecon.net/kamikazechaser/vise/state"
|
||||
)
|
||||
|
||||
type TestSizeResource struct {
|
||||
@ -172,7 +172,6 @@ lala poo
|
||||
1:foo the foo
|
||||
2:go to bar`
|
||||
|
||||
|
||||
if r != expect {
|
||||
t.Fatalf("expected:\n\t%x\ngot:\n\t%x\n", expect, r)
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package resource
|
||||
|
||||
import (
|
||||
"git.defalsify.org/vise/state"
|
||||
"git.grassecon.net/kamikazechaser/vise/state"
|
||||
)
|
||||
|
||||
type StateResource struct {
|
||||
@ -14,13 +14,13 @@ func ToStateResource(rs Resource) *StateResource {
|
||||
}
|
||||
|
||||
func NewStateResource(st *state.State) *StateResource {
|
||||
return &StateResource {
|
||||
return &StateResource{
|
||||
NewMenuResource(),
|
||||
st,
|
||||
}
|
||||
}
|
||||
|
||||
func(sr *StateResource) WithState(st *state.State) *StateResource {
|
||||
func (sr *StateResource) WithState(st *state.State) *StateResource {
|
||||
if sr.st != nil {
|
||||
panic("state already set")
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package resource
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.defalsify.org/vise/state"
|
||||
"git.grassecon.net/kamikazechaser/vise/state"
|
||||
)
|
||||
|
||||
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"
|
||||
|
||||
"git.defalsify.org/vise/vm"
|
||||
"git.grassecon.net/kamikazechaser/vise/vm"
|
||||
)
|
||||
|
||||
type genFunc func() error
|
||||
@ -177,7 +177,6 @@ func Generate() (string, error) {
|
||||
return dir, err
|
||||
}
|
||||
|
||||
|
||||
// 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.
|
||||
|
@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"git.defalsify.org/vise/cache"
|
||||
"git.defalsify.org/vise/state"
|
||||
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||
"git.grassecon.net/kamikazechaser/vise/state"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -16,7 +16,6 @@ var (
|
||||
ctrlRegex = regexp.MustCompile(ctrlRegexStr)
|
||||
symRegexStr = "^[a-zA-Z0-9][a-zA-Z0-9_]+$"
|
||||
symRegex = regexp.MustCompile(symRegexStr)
|
||||
|
||||
)
|
||||
|
||||
// CheckInput validates the given byte string as client input.
|
||||
|
43
vm/runner.go
43
vm/runner.go
@ -5,10 +5,10 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"git.defalsify.org/vise/cache"
|
||||
"git.defalsify.org/vise/render"
|
||||
"git.defalsify.org/vise/resource"
|
||||
"git.defalsify.org/vise/state"
|
||||
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||
"git.grassecon.net/kamikazechaser/vise/render"
|
||||
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||
"git.grassecon.net/kamikazechaser/vise/state"
|
||||
)
|
||||
|
||||
// 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.
|
||||
func(vmi *Vm) Reset() {
|
||||
func (vmi *Vm) Reset() {
|
||||
vmi.mn = render.NewMenu()
|
||||
vmi.pg.Reset()
|
||||
vmi.pg = vmi.pg.WithMenu(vmi.mn)
|
||||
@ -50,7 +50,7 @@ func(vmi *Vm) Reset() {
|
||||
// Each step may update the state.
|
||||
//
|
||||
// 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
|
||||
for running {
|
||||
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 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 {
|
||||
return b, nil
|
||||
}
|
||||
@ -167,7 +167,6 @@ func(vm *Vm) RunDeadCheck(b []byte, ctx context.Context) ([]byte, error) {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
|
||||
log.Printf("no code remaining but not terminating")
|
||||
location, _ := vm.st.Where()
|
||||
if location == "" {
|
||||
@ -178,14 +177,14 @@ func(vm *Vm) RunDeadCheck(b []byte, ctx context.Context) ([]byte, error) {
|
||||
}
|
||||
|
||||
// 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)
|
||||
err = vm.pg.Map(sym)
|
||||
return b, err
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
return b, err
|
||||
@ -220,7 +219,7 @@ func(vm *Vm) RunCatch(b []byte, ctx context.Context) ([]byte, error) {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
return b, err
|
||||
@ -240,7 +239,7 @@ func(vm *Vm) RunCroak(b []byte, ctx context.Context) ([]byte, error) {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
return b, err
|
||||
@ -254,7 +253,7 @@ func(vm *Vm) RunLoad(b []byte, ctx context.Context) ([]byte, error) {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
return b, err
|
||||
@ -275,7 +274,7 @@ func(vm *Vm) RunReload(b []byte, ctx context.Context) ([]byte, error) {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
return b, err
|
||||
@ -300,7 +299,7 @@ func(vm *Vm) RunMove(b []byte, ctx context.Context) ([]byte, error) {
|
||||
|
||||
// RunIncmp executes the INCMP opcode
|
||||
// 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)
|
||||
if err != nil {
|
||||
return b, err
|
||||
@ -377,7 +376,7 @@ func(vm *Vm) RunInCmp(b []byte, ctx context.Context) ([]byte, error) {
|
||||
}
|
||||
|
||||
// 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
|
||||
b, err = ParseHalt(b)
|
||||
if err != nil {
|
||||
@ -393,14 +392,14 @@ func(vm *Vm) RunHalt(b []byte, ctx context.Context) ([]byte, error) {
|
||||
}
|
||||
|
||||
// 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")
|
||||
_, _, b, err := ParseMSize(b)
|
||||
return b, err
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
return b, err
|
||||
@ -410,7 +409,7 @@ func(vm *Vm) RunMOut(b []byte, ctx context.Context) ([]byte, error) {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
return b, err
|
||||
@ -424,7 +423,7 @@ func(vm *Vm) RunMNext(b []byte, ctx context.Context) ([]byte, error) {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
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.
|
||||
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)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -464,7 +463,7 @@ func(vm *Vm) Render(ctx context.Context) (string, error) {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -7,10 +7,10 @@ import (
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
"git.defalsify.org/vise/cache"
|
||||
"git.defalsify.org/vise/render"
|
||||
"git.defalsify.org/vise/resource"
|
||||
"git.defalsify.org/vise/state"
|
||||
"git.grassecon.net/kamikazechaser/vise/cache"
|
||||
"git.grassecon.net/kamikazechaser/vise/render"
|
||||
"git.grassecon.net/kamikazechaser/vise/resource"
|
||||
"git.grassecon.net/kamikazechaser/vise/state"
|
||||
)
|
||||
|
||||
var dynVal = "three"
|
||||
@ -105,14 +105,14 @@ func (r TestResource) FuncFor(sym string) (resource.EntryFunc, error) {
|
||||
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()
|
||||
return resource.Result{
|
||||
Content: string(v),
|
||||
}, err
|
||||
}
|
||||
|
||||
func(r TestResource) GetCode(sym string) ([]byte, error) {
|
||||
func (r TestResource) GetCode(sym string) ([]byte, error) {
|
||||
var b []byte
|
||||
switch sym {
|
||||
case "_catch":
|
||||
@ -456,7 +456,6 @@ func TestRunReturn(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func TestRunLoadInput(t *testing.T) {
|
||||
st := state.NewState(5)
|
||||
rs := TestResource{}
|
||||
|
Loading…
Reference in New Issue
Block a user