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
|
.PHONY: profile
|
||||||
|
|
||||||
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=$(basename $f)
|
||||||
b=${b%.*}
|
b=${b%.*}
|
||||||
go run ./dev/asm $1/$b.vis > $1/$b.bin
|
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
|
RELOAD myname
|
||||||
MOVE _
|
MOVE _
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
@ -22,6 +23,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func nameSave(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
func nameSave(sym string, input []byte, ctx context.Context) (resource.Result, error) {
|
||||||
|
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)
|
||||||
return resource.Result{}, err
|
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
|
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.
|
// GetFlag returns the state of the flag at the given bit field index.
|
||||||
//
|
//
|
||||||
// Fails if bit field index is out of range.
|
// Fails if bit field index is out of range.
|
||||||
|
23
vm/runner.go
23
vm/runner.go
@ -60,7 +60,11 @@ func(vm *Vm) Run(b []byte, ctx context.Context) ([]byte, error) {
|
|||||||
log.Printf("terminate set! bailing!")
|
log.Printf("terminate set! bailing!")
|
||||||
return []byte{}, nil
|
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)
|
_, err = vm.st.SetFlag(state.FLAG_DIRTY)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -271,13 +275,14 @@ 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
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
change, err := vm.st.SetFlag(state.FLAG_READIN)
|
reading, err := vm.st.GetFlag(state.FLAG_READIN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -286,7 +291,7 @@ func(vm *Vm) RunInCmp(b []byte, ctx context.Context) ([]byte, error) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if have {
|
if have {
|
||||||
if change {
|
if !reading {
|
||||||
_, err = vm.st.ResetFlag(state.FLAG_INMATCH)
|
_, err = vm.st.ResetFlag(state.FLAG_INMATCH)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -295,18 +300,24 @@ func(vm *Vm) RunInCmp(b []byte, ctx context.Context) ([]byte, error) {
|
|||||||
log.Printf("ignoring input %s, already have match", sym)
|
log.Printf("ignoring input %s, already have match", sym)
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
_, err = vm.st.SetFlag(state.FLAG_READIN)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
input, err := vm.st.GetInput()
|
input, err := vm.st.GetInput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return b, err
|
return b, err
|
||||||
}
|
}
|
||||||
log.Printf("sym is %s", sym)
|
log.Printf("testing sym %s input %s", sym, input)
|
||||||
if sym == "*" {
|
|
||||||
|
if !have && sym == "*" {
|
||||||
log.Printf("input wildcard match ('%s'), target '%s'", input, target)
|
log.Printf("input wildcard match ('%s'), target '%s'", input, target)
|
||||||
} else {
|
} else {
|
||||||
if sym != string(input) {
|
if sym != string(input) {
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
log.Printf("input match for '%s', target '%s'", input, target)
|
log.Printf("input match for '%s', target '%s'", input, target)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,7 +426,6 @@ func TestRunReturn(t *testing.T) {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
st.Down("root")
|
st.Down("root")
|
||||||
st.SetInput([]byte("0"))
|
|
||||||
b := NewLine(nil, INCMP, []string{"0", "bar"}, nil, nil)
|
b := NewLine(nil, INCMP, []string{"0", "bar"}, nil, nil)
|
||||||
b = NewLine(b, HALT, nil, nil, nil)
|
b = NewLine(b, HALT, nil, nil, nil)
|
||||||
b = NewLine(b, INCMP, []string{"1", "_"}, nil, nil)
|
b = NewLine(b, INCMP, []string{"1", "_"}, nil, nil)
|
||||||
@ -434,6 +433,7 @@ func TestRunReturn(t *testing.T) {
|
|||||||
|
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
|
|
||||||
|
st.SetInput([]byte("0"))
|
||||||
b, err = vm.Run(b, ctx)
|
b, err = vm.Run(b, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -522,3 +522,57 @@ func TestInputBranch(t *testing.T) {
|
|||||||
t.Fatalf("expected 'one', got %s", location)
|
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