Compare commits

..

4 Commits

10 changed files with 127 additions and 0 deletions

87
cmd/main.go Normal file
View File

@ -0,0 +1,87 @@
package main
import (
"context"
"flag"
"fmt"
"os"
"path"
"git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/resource"
"git.defalsify.org/vise.git/state"
)
const (
USERFLAG_LANGUAGE_SET = iota + state.FLAG_USERSTART
)
type fsData struct {
path string
}
func (fsd *fsData) SetLanguageSelected(ctx context.Context, sym string, input []byte) (resource.Result, error) {
inputStr := string(input)
res := resource.Result{}
switch inputStr {
case "0":
res.FlagSet = []uint32{state.FLAG_LANG}
res.Content = "eng"
case "1":
res.FlagSet = []uint32{state.FLAG_LANG}
res.Content = "swa"
default:
}
return res, nil
}
func main() {
var dir string
var root string
var size uint
var sessionId string
var persist bool
flag.StringVar(&dir, "d", ".", "resource dir to read from")
flag.UintVar(&size, "s", 0, "max size of output")
flag.StringVar(&root, "root", "root", "entry point symbol")
flag.StringVar(&sessionId, "session-id", "default", "session id")
flag.BoolVar(&persist, "persist", false, "use state persistence")
flag.Parse()
fmt.Fprintf(os.Stderr, "starting session at symbol '%s' using resource dir: %s\n", root, dir)
fp := path.Join(dir, sessionId)
fs := &fsData{
path: fp,
}
ctx := context.Background()
en, rs, err := engine.NewSizedEnginee(dir, uint32(size), persist, &sessionId)
rs.AddLocalFunc("select_language", fs.SetLanguageSelected)
if err != nil {
fmt.Fprintf(os.Stderr, "engine create error: %v", err)
os.Exit(1)
}
cont, err := en.Init(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "engine init exited with error: %v\n", err)
os.Exit(1)
}
if !cont {
_, err = en.WriteResult(ctx, os.Stdout)
if err != nil {
fmt.Fprintf(os.Stderr, "dead init write error: %v\n", err)
os.Exit(1)
}
os.Stdout.Write([]byte{0x0a})
os.Exit(0)
}
err = engine.Loop(ctx, en, os.Stdin, os.Stdout)
if err != nil {
fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err)
os.Exit(1)
}
}

7
go.work Normal file
View File

@ -0,0 +1,7 @@
go 1.22.6
use (
./go-vise
.
)

3
go.work.sum Normal file
View File

@ -0,0 +1,3 @@
github.com/alecthomas/assert/v2 v2.2.2/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ=
github.com/alecthomas/repr v0.2.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=

View File

@ -0,0 +1,17 @@
# Variables to match files in the current directory
INPUTS = $(wildcard ./*.vis)
TXTS = $(wildcard ./*.txt.orig)
# Rule to build .bin files from .vis files
%.vis:
go run ../../go-vise/dev/asm $(basename $@).vis > $(basename $@).bin
@echo "Built $(basename $@).bin from $(basename $@).vis"
# Rule to copy .orig files to .txt
%.txt.orig:
cp -v $(basename $@).orig $(basename $@)
@echo "Copied $(basename $@).orig to $(basename $@)"
# 'all' target depends on all .vis and .txt.orig files
all: $(INPUTS) $(TXTS)
@echo "Running all: $(INPUTS) $(TXTS)"

View File

@ -0,0 +1 @@
Welcome to Sarafu Network

View File

@ -0,0 +1,7 @@
LOAD select_language 0
MOUT english 0
MOUT kiswahili 1
HALT
INCMP terms 0
INCMP terms 1
RELOAD select_language

View File

@ -0,0 +1 @@
Karibu Sarafu Network

View File

@ -0,0 +1 @@
Do you agree to terms and conditions?

View File

@ -0,0 +1,2 @@
MOUT yes 0
MOUT no 1

View File

@ -0,0 +1 @@
Kwa kutumia hii huduma umekubali sheria na masharti?