namespace: change -> git.grassecon.net/kamikazechaser/vise

This commit is contained in:
Mohamed Sohail 2023-04-17 12:56:56 +00:00
parent 194522fd95
commit d8ef336919
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D
31 changed files with 274 additions and 288 deletions

View File

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

View File

@ -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 `@@*`
@ -24,11 +23,11 @@ type Asm struct {
// Arg holds all parsed argument elements of a single line of assembly code. // Arg holds all parsed argument elements of a single line of assembly code.
type Arg struct { type Arg struct {
Sym *string `(@Sym Whitespace?)?` Sym *string `(@Sym Whitespace?)?`
Size *uint32 `(@Size Whitespace?)?` Size *uint32 `(@Size Whitespace?)?`
Flag *uint8 `(@Size Whitespace?)?` Flag *uint8 `(@Size Whitespace?)?`
Selector *string `(@Sym Whitespace?)?` Selector *string `(@Sym Whitespace?)?`
Desc *string `(Quote ((@Sym | @Size) @Whitespace?)+ Quote Whitespace?)?` Desc *string `(Quote ((@Sym | @Size) @Whitespace?)+ Quote Whitespace?)?`
} }
func flush(b *bytes.Buffer, w io.Writer) (int, error) { func flush(b *bytes.Buffer, w io.Writer) (int, error) {
@ -168,7 +167,7 @@ func parseOne(op vm.Opcode, instruction *Instruction, w io.Writer) (int, error)
n, err := writeOpcode(b, op) n, err := writeOpcode(b, op)
n_buf += n n_buf += n
if err != nil { if err != nil {
return n_out, err return n_out, err
} }
@ -245,8 +244,8 @@ func (a Arg) String() string {
// Instruction represents one full line of assembly code. // Instruction represents one full line of assembly code.
type Instruction struct { type Instruction struct {
OpCode string `@Ident` OpCode string `@Ident`
OpArg Arg `(Whitespace @@)?` OpArg Arg `(Whitespace @@)?`
Comment string `Comment? EOL` Comment string `Comment? EOL`
} }
@ -273,7 +272,7 @@ var (
func numSize(n uint32) int { func numSize(n uint32) int {
v := math.Log2(float64(n)) v := math.Log2(float64(n))
return int((v / 8) + 1) return int((v / 8) + 1)
} }
func writeOpcode(w *bytes.Buffer, op vm.Opcode) (int, error) { func writeOpcode(w *bytes.Buffer, op vm.Opcode) (int, error) {
@ -312,14 +311,14 @@ 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:])
} }
// Batcher handles assembly commands that generates multiple instructions, such as menu navigation commands. // Batcher handles assembly commands that generates multiple instructions, such as menu navigation commands.
type Batcher struct { type Batcher struct {
menuProcessor MenuProcessor menuProcessor MenuProcessor
inMenu bool inMenu bool
} }
// NewBatcher creates a new Batcher objcet. // NewBatcher creates a new Batcher objcet.
@ -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 {

View File

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

View File

@ -3,34 +3,34 @@ 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.
type BatchCode uint16 type BatchCode uint16
const ( const (
_MENU_OFFSET = 256 _MENU_OFFSET = 256
MENU_DOWN = _MENU_OFFSET MENU_DOWN = _MENU_OFFSET
MENU_UP = _MENU_OFFSET + 1 MENU_UP = _MENU_OFFSET + 1
MENU_NEXT = _MENU_OFFSET + 2 MENU_NEXT = _MENU_OFFSET + 2
MENU_PREVIOUS = _MENU_OFFSET + 3 MENU_PREVIOUS = _MENU_OFFSET + 3
) )
var ( var (
batchCode = map[string]BatchCode{ batchCode = map[string]BatchCode{
"DOWN": MENU_DOWN, "DOWN": MENU_DOWN,
"UP": MENU_UP, "UP": MENU_UP,
"NEXT": MENU_NEXT, "NEXT": MENU_NEXT,
"PREVIOUS": MENU_PREVIOUS, "PREVIOUS": MENU_PREVIOUS,
} }
) )
type menuItem struct { type menuItem struct {
code BatchCode code BatchCode
choice string choice string
display string display string
target string target string
} }
// MenuProcessor handles code lines with BatchCode quasi-opcodes that control menu generation. // MenuProcessor handles code lines with BatchCode quasi-opcodes that control menu generation.
@ -38,7 +38,7 @@ type menuItem struct {
// It creates vm instructions for display of menu and handling of input on either size of a vm.HALT instruction. // It creates vm instructions for display of menu and handling of input on either size of a vm.HALT instruction.
type MenuProcessor struct { type MenuProcessor struct {
items []menuItem items []menuItem
size uint32 size uint32
} }
// NewMenuProcessor creates a new MenuProcessor object. // NewMenuProcessor creates a new MenuProcessor object.
@ -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)
@ -58,10 +58,10 @@ func(mp *MenuProcessor) Add(bop string, choice string, display string, target st
return fmt.Errorf("target is only valid for DOWN") return fmt.Errorf("target is only valid for DOWN")
} }
m := menuItem{ m := menuItem{
code: bopCode, code: bopCode,
choice: choice, choice: choice,
display: display, display: display,
target: target, target: target,
} }
mp.items = append(mp.items, m) mp.items = append(mp.items, m)
return nil return nil

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"git.defalsify.org/vise/testdata" "git.grassecon.net/kamikazechaser/vise/testdata"
) )
func main() { func main() {

View File

@ -6,7 +6,7 @@ import (
"fmt" "fmt"
"os" "os"
"git.defalsify.org/vise/engine" "git.grassecon.net/kamikazechaser/vise/engine"
) )
func main() { func main() {

View File

@ -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.
@ -27,7 +27,7 @@ func NewSizedEngine(dir string, size uint32) Engine {
ca := cache.NewCache() ca := cache.NewCache()
cfg := Config{ cfg := Config{
OutputSize: size, OutputSize: size,
Root: "root", Root: "root",
} }
ctx := context.TODO() ctx := context.TODO()
return NewEngine(cfg, &st, &rs, ca, ctx) return NewEngine(cfg, &st, &rs, ca, ctx)

View File

@ -6,29 +6,29 @@ 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.
type Config struct { type Config struct {
OutputSize uint32 // Maximum size of output from a single rendered page OutputSize uint32 // Maximum size of output from a single rendered page
SessionId string SessionId string
Root string Root string
FlagCount uint32 FlagCount uint32
CacheSize uint32 CacheSize uint32
} }
// Engine is an execution engine that handles top-level errors when running client inputs against code in the bytecode buffer. // Engine is an execution engine that handles top-level errors when running client inputs against code in the bytecode buffer.
type Engine struct { type Engine struct {
st *state.State st *state.State
rs resource.Resource rs resource.Resource
ca cache.Memory ca cache.Memory
vm *vm.Vm vm *vm.Vm
root string root string
initd bool initd bool
} }
@ -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 {

View File

@ -8,15 +8,15 @@ 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 (
dataGenerated bool = false dataGenerated bool = false
dataDir string = testdata.DataDir dataDir string = testdata.DataDir
) )
type FsWrapper struct { type FsWrapper struct {
@ -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)

View File

@ -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) {
@ -34,7 +34,7 @@ func TestLoopTop(t *testing.T) {
"2", "2",
"j", "j",
"1", "1",
} }
inputStr := strings.Join(input, "\n") inputStr := strings.Join(input, "\n")
inputBuf := bytes.NewBuffer(append([]byte(inputStr), 0x0a)) inputBuf := bytes.NewBuffer(append([]byte(inputStr), 0x0a))
outputBuf := bytes.NewBuffer(nil) outputBuf := bytes.NewBuffer(nil)
@ -72,7 +72,7 @@ func TestLoopBackForth(t *testing.T) {
"0", "0",
"1", "1",
"0", "0",
} }
inputStr := strings.Join(input, "\n") inputStr := strings.Join(input, "\n")
inputBuf := bytes.NewBuffer(append([]byte(inputStr), 0x0a)) inputBuf := bytes.NewBuffer(append([]byte(inputStr), 0x0a))
outputBuf := bytes.NewBuffer(nil) outputBuf := bytes.NewBuffer(nil)
@ -93,7 +93,7 @@ func TestLoopBrowse(t *testing.T) {
cfg := Config{ cfg := Config{
OutputSize: 68, OutputSize: 68,
Root: "root", Root: "root",
} }
en := NewEngine(cfg, &st, &rs, ca, ctx) en := NewEngine(cfg, &st, &rs, ca, ctx)
var err error var err error
@ -108,7 +108,7 @@ func TestLoopBrowse(t *testing.T) {
"00", "00",
"11", "11",
"00", "00",
} }
inputStr := strings.Join(input, "\n") inputStr := strings.Join(input, "\n")
inputBuf := bytes.NewBuffer(append([]byte(inputStr), 0x0a)) inputBuf := bytes.NewBuffer(append([]byte(inputStr), 0x0a))
outputBuf := bytes.NewBuffer(nil) outputBuf := bytes.NewBuffer(nil)

View File

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

View File

@ -6,17 +6,17 @@ 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) {
generateTestData(t) generateTestData(t)
cfg := Config{ cfg := Config{
OutputSize: 83, OutputSize: 83,
SessionId: "xyzzy", SessionId: "xyzzy",
Root: "root", Root: "root",
} }
rs := NewFsWrapper(dataDir, nil) rs := NewFsWrapper(dataDir, nil)
@ -47,7 +47,7 @@ func TestPersist(t *testing.T) {
"1", "1",
"2", "2",
"00", "00",
} }
for _, v := range inputs { for _, v := range inputs {
err = RunPersisted(cfg, rs, pr, []byte(v), w, ctx) err = RunPersisted(cfg, rs, pr, []byte(v), w, ctx)
if err != nil { if err != nil {

View File

@ -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 (
@ -24,14 +24,14 @@ const (
) )
var ( var (
baseDir = testdataloader.GetBasePath() baseDir = testdataloader.GetBasePath()
scriptDir = path.Join(baseDir, "examples", "profile") scriptDir = path.Join(baseDir, "examples", "profile")
emptyResult = resource.Result{} emptyResult = resource.Result{}
) )
type profileResource struct { type profileResource struct {
*resource.FsResource *resource.FsResource
st *state.State st *state.State
haveEntered bool haveEntered bool
} }
@ -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)
@ -118,8 +118,8 @@ func main() {
rs.AddLocalFunc("do_email_save", rs.emailSave) rs.AddLocalFunc("do_email_save", rs.emailSave)
ca := cache.NewCache() ca := cache.NewCache()
cfg := engine.Config{ cfg := engine.Config{
Root: "root", Root: "root",
SessionId: sessionId, SessionId: sessionId,
OutputSize: uint32(size), OutputSize: uint32(size),
} }
ctx := context.Background() ctx := context.Background()

View File

@ -11,15 +11,15 @@ 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 (
baseDir = testdataloader.GetBasePath() baseDir = testdataloader.GetBasePath()
scriptDir = path.Join(baseDir, "examples", "session") scriptDir = path.Join(baseDir, "examples", "session")
emptyResult = resource.Result{} emptyResult = resource.Result{}
) )
@ -65,8 +65,8 @@ func main() {
rs.AddLocalFunc("do_save", save) rs.AddLocalFunc("do_save", save)
ca := cache.NewCache() ca := cache.NewCache()
cfg := engine.Config{ cfg := engine.Config{
Root: "root", Root: "root",
SessionId: sessionId, SessionId: sessionId,
OutputSize: uint32(size), OutputSize: uint32(size),
} }
ctx := context.Background() ctx := context.Background()

View File

@ -9,15 +9,15 @@ 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 (
baseDir = testdataloader.GetBasePath() baseDir = testdataloader.GetBasePath()
scriptDir = path.Join(baseDir, "examples", "validate") scriptDir = path.Join(baseDir, "examples", "validate")
emptyResult = resource.Result{} emptyResult = resource.Result{}
) )
@ -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
@ -63,8 +63,8 @@ func main() {
rs.AddLocalFunc("again", rs.again) rs.AddLocalFunc("again", rs.again)
ca := cache.NewCache() ca := cache.NewCache()
cfg := engine.Config{ cfg := engine.Config{
Root: "root", Root: "root",
SessionId: sessionId, SessionId: sessionId,
OutputSize: uint32(size), OutputSize: uint32(size),
} }
ctx := context.Background() ctx := context.Background()

2
go.mod
View File

@ -1,4 +1,4 @@
module git.defalsify.org/vise module git.grassecon.net/kamikazechaser/vise
go 1.20 go 1.20

View File

@ -5,17 +5,18 @@ 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.
type FsPersister struct { type FsPersister struct {
State *state.State State *state.State
Memory *cache.Cache Memory *cache.Cache
dir string dir string
} }
// NewFsPersister creates a new FsPersister. // NewFsPersister creates a new FsPersister.
@ -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 {

View File

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

View File

@ -1,17 +1,16 @@
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.
type Persister interface { type Persister interface {
Serialize() ([]byte, error) // Output serializes representation of the state. Serialize() ([]byte, error) // Output serializes representation of the state.
Deserialize(b []byte) error // Restore state from a serialized state. Deserialize(b []byte) error // Restore state from a serialized state.
Save(key string) error // Serialize and commit the state representation to persisted storage. Save(key string) error // Serialize and commit the state representation to persisted storage.
Load(key string) error // Load the state representation from persisted storage and Deserialize. Load(key string) error // Load the state representation from persisted storage and Deserialize.
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.
} }

View File

@ -7,31 +7,31 @@ 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.
type Page struct { type Page struct {
cacheMap map[string]string // Mapped content symbols cacheMap map[string]string // Mapped content symbols
cache cache.Memory // Content store. cache cache.Memory // Content store.
resource resource.Resource // Symbol resolver. resource resource.Resource // Symbol resolver.
menu *Menu // Menu rendererer. menu *Menu // Menu rendererer.
sink *string // Content symbol rendered by dynamic size. sink *string // Content symbol rendered by dynamic size.
sizer *Sizer // Process size constraints. sizer *Sizer // Process size constraints.
} }
// NewPage creates a new Page object. // NewPage creates a new Page object.
func NewPage(cache cache.Memory, rs resource.Resource) *Page { func NewPage(cache cache.Memory, rs resource.Resource) *Page {
return &Page{ return &Page{
cache: cache, cache: cache,
cacheMap: make(map[string]string), cacheMap: make(map[string]string),
resource: rs, resource: rs,
} }
} }
// 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
} }

View File

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

View File

@ -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 {
@ -159,7 +159,7 @@ func TestSizePages(t *testing.T) {
mn.Put("1", "foo the foo") mn.Put("1", "foo the foo")
mn.Put("2", "go to bar") mn.Put("2", "go to bar")
r, err := pg.Render("pages", 0) r, err := pg.Render("pages", 0)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -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)
} }

View File

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

View File

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

View File

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

View File

@ -5,18 +5,17 @@ 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 (
inputRegexStr = "^[a-zA-Z0-9].*$" inputRegexStr = "^[a-zA-Z0-9].*$"
inputRegex = regexp.MustCompile(inputRegexStr) inputRegex = regexp.MustCompile(inputRegexStr)
ctrlRegexStr = "^[><_^.]$" ctrlRegexStr = "^[><_^.]$"
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.

View File

@ -5,29 +5,29 @@ 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.
type Vm struct { type Vm struct {
st *state.State // Navigation and error states. st *state.State // Navigation and error states.
rs resource.Resource // Retrieves content, code, and templates for symbols. rs resource.Resource // Retrieves content, code, and templates for symbols.
ca cache.Memory // Loaded content. ca cache.Memory // Loaded content.
mn *render.Menu // Menu component of page. mn *render.Menu // Menu component of page.
sizer *render.Sizer // Apply size constraints to output. sizer *render.Sizer // Apply size constraints to output.
pg *render.Page // Render outputs with menues to size constraints. pg *render.Page // Render outputs with menues to size constraints.
} }
// NewVm creates a new Vm. // NewVm creates a new Vm.
func NewVm(st *state.State, rs resource.Resource, ca cache.Memory, sizer *render.Sizer) *Vm { func NewVm(st *state.State, rs resource.Resource, ca cache.Memory, sizer *render.Sizer) *Vm {
vmi := &Vm{ vmi := &Vm{
st: st, st: st,
rs: rs, rs: rs,
ca: ca, ca: ca,
pg: render.NewPage(ca, rs), pg: render.NewPage(ca, rs),
sizer: sizer, sizer: sizer,
} }
vmi.Reset() vmi.Reset()
@ -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,35 +409,35 @@ 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
} }
cfg := vm.mn.GetBrowseConfig() cfg := vm.mn.GetBrowseConfig()
cfg.NextSelector = selector cfg.NextSelector = selector
cfg.NextTitle = display cfg.NextTitle = display
cfg.NextAvailable = true cfg.NextAvailable = true
vm.mn = vm.mn.WithBrowseConfig(cfg) vm.mn = vm.mn.WithBrowseConfig(cfg)
return b, nil return b, nil
} }
// 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
} }
cfg := vm.mn.GetBrowseConfig() cfg := vm.mn.GetBrowseConfig()
cfg.PreviousSelector = selector cfg.PreviousSelector = selector
cfg.PreviousTitle = display cfg.PreviousTitle = display
cfg.PreviousAvailable = true cfg.PreviousAvailable = true
vm.mn = vm.mn.WithBrowseConfig(cfg) vm.mn = vm.mn.WithBrowseConfig(cfg)
return b, nil return b, nil
} }
// 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

View File

@ -7,17 +7,17 @@ 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"
type TestResource struct { type TestResource struct {
resource.MenuResource resource.MenuResource
state *state.State state *state.State
RootCode []byte RootCode []byte
} }
@ -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{}