Pass through wildcard when have match in incmp
This commit is contained in:
parent
355b466746
commit
0ab6868eca
2
Makefile
2
Makefile
@ -3,4 +3,4 @@ examples: profile
|
||||
.PHONY: profile
|
||||
|
||||
profile:
|
||||
bash examples/compile.sh examples/profile
|
||||
bash examples/compile.bash examples/profile
|
||||
|
@ -1,4 +1,4 @@
|
||||
for f in $(ls $1); do
|
||||
for f in $(ls $1/*.vis); do
|
||||
b=$(basename $f)
|
||||
b=${b%.*}
|
||||
go run ./dev/asm $1/$b.vis > $1/$b.bin
|
||||
|
2
examples/profile/entry_email
Normal file
2
examples/profile/entry_email
Normal file
@ -0,0 +1,2 @@
|
||||
Your email is now: {{.myemail}}
|
||||
Enter new email.
|
3
examples/profile/entry_email.save.vis
Normal file
3
examples/profile/entry_email.save.vis
Normal file
@ -0,0 +1,3 @@
|
||||
LOAD entry_email_save 0
|
||||
RELOAD myemail
|
||||
MOVE _
|
6
examples/profile/entry_email.vis
Normal file
6
examples/profile/entry_email.vis
Normal file
@ -0,0 +1,6 @@
|
||||
LOAD myemail 32
|
||||
MAP myemail
|
||||
MOUT 0 "abort"
|
||||
HALT
|
||||
INCMP 0 _
|
||||
INCMP * entry_email_save
|
@ -1,3 +1,2 @@
|
||||
LOAD entry_name_save 0
|
||||
RELOAD myname
|
||||
MOVE _
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
@ -22,6 +23,7 @@ var (
|
||||
)
|
||||
|
||||
func 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)
|
||||
return resource.Result{}, err
|
||||
|
1
examples/profile/myemail.txt
Normal file
1
examples/profile/myemail.txt
Normal file
@ -0,0 +1 @@
|
||||
not set
|
@ -1 +1 @@
|
||||
inky
|
||||
not set
|
@ -113,11 +113,6 @@ func(st *State) ResetFlag(bitIndex uint32) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// ResetBaseFlags restes all builtin flags not writeable by client.
|
||||
func(st *State) ResetBaseFlags() {
|
||||
st.Flags[0] = 0
|
||||
}
|
||||
|
||||
// GetFlag returns the state of the flag at the given bit field index.
|
||||
//
|
||||
// Fails if bit field index is out of range.
|
||||
|
21
vm/runner.go
21
vm/runner.go
@ -60,7 +60,11 @@ func(vm *Vm) Run(b []byte, ctx context.Context) ([]byte, error) {
|
||||
log.Printf("terminate set! bailing!")
|
||||
return []byte{}, nil
|
||||
}
|
||||
vm.st.ResetBaseFlags()
|
||||
//vm.st.ResetBaseFlags()
|
||||
_, err = vm.st.ResetFlag(state.FLAG_TERMINATE)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_, err = vm.st.SetFlag(state.FLAG_DIRTY)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -271,13 +275,14 @@ 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) {
|
||||
sym, target, b, err := ParseInCmp(b)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
|
||||
change, err := vm.st.SetFlag(state.FLAG_READIN)
|
||||
reading, err := vm.st.GetFlag(state.FLAG_READIN)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -286,7 +291,7 @@ func(vm *Vm) RunInCmp(b []byte, ctx context.Context) ([]byte, error) {
|
||||
panic(err)
|
||||
}
|
||||
if have {
|
||||
if change {
|
||||
if !reading {
|
||||
_, err = vm.st.ResetFlag(state.FLAG_INMATCH)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -295,13 +300,19 @@ func(vm *Vm) RunInCmp(b []byte, ctx context.Context) ([]byte, error) {
|
||||
log.Printf("ignoring input %s, already have match", sym)
|
||||
return b, nil
|
||||
}
|
||||
} else {
|
||||
_, err = vm.st.SetFlag(state.FLAG_READIN)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
input, err := vm.st.GetInput()
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
log.Printf("sym is %s", sym)
|
||||
if sym == "*" {
|
||||
log.Printf("testing sym %s input %s", sym, input)
|
||||
|
||||
if !have && sym == "*" {
|
||||
log.Printf("input wildcard match ('%s'), target '%s'", input, target)
|
||||
} else {
|
||||
if sym != string(input) {
|
||||
|
@ -426,7 +426,6 @@ func TestRunReturn(t *testing.T) {
|
||||
var err error
|
||||
|
||||
st.Down("root")
|
||||
st.SetInput([]byte("0"))
|
||||
b := NewLine(nil, INCMP, []string{"0", "bar"}, nil, nil)
|
||||
b = NewLine(b, HALT, nil, nil, nil)
|
||||
b = NewLine(b, INCMP, []string{"1", "_"}, nil, nil)
|
||||
@ -434,6 +433,7 @@ func TestRunReturn(t *testing.T) {
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
st.SetInput([]byte("0"))
|
||||
b, err = vm.Run(b, ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -522,3 +522,57 @@ func TestInputBranch(t *testing.T) {
|
||||
t.Fatalf("expected 'one', got %s", location)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInputIgnore(t *testing.T) {
|
||||
st := state.NewState(5)
|
||||
rs := TestResource{}
|
||||
ca := cache.NewCache()
|
||||
vm := NewVm(&st, &rs, ca, nil)
|
||||
|
||||
var err error
|
||||
|
||||
st.Down("root")
|
||||
|
||||
b := NewLine(nil, INCMP, []string{"foo", "one"}, nil, nil)
|
||||
b = NewLine(b, INCMP, []string{"bar", "two"}, nil, nil)
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
st.SetInput([]byte("foo"))
|
||||
b, err = vm.Run(b, ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
location, _ := st.Where()
|
||||
if location != "one" {
|
||||
t.Fatalf("expected 'one', got %s", location)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInputIgnoreWildcard(t *testing.T) {
|
||||
st := state.NewState(5)
|
||||
rs := TestResource{}
|
||||
ca := cache.NewCache()
|
||||
vm := NewVm(&st, &rs, ca, nil)
|
||||
|
||||
var err error
|
||||
|
||||
st.Down("root")
|
||||
|
||||
b := NewLine(nil, INCMP, []string{"foo", "one"}, nil, nil)
|
||||
b = NewLine(b, INCMP, []string{"*", "two"}, nil, nil)
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
st.SetInput([]byte("foo"))
|
||||
b, err = vm.Run(b, ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
location, _ := st.Where()
|
||||
if location != "one" {
|
||||
t.Fatalf("expected 'one', got %s", location)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user