go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

commit a1f69bc1058915abcb7752c98721c79acff36d77
parent 2b636b9f00efb6f0556c0c19aa0116dfc61c5da3
Author: lash <dev@holbrook.no>
Date:   Wed, 25 Sep 2024 16:57:52 +0100

Add staticload toggle example

Diffstat:
Aexamples/static/8out | 1+
Aexamples/static/Makefile | 10++++++++++
Aexamples/static/main.go | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aexamples/static/root.vis | 3+++
4 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/examples/static/8out b/examples/static/8out @@ -0,0 +1 @@ +bar diff --git a/examples/static/Makefile b/examples/static/Makefile @@ -0,0 +1,10 @@ +INPUTS = $(wildcard ./*.vis) +TXTS = $(wildcard ./*.txt.orig) + +%.vis: + go run ../../dev/asm $(basename $@).vis > $(basename $@).bin + +all: $(INPUTS) $(TXTS) + +%.txt.orig: + cp -v $(basename $@).orig $(basename $@) diff --git a/examples/static/main.go b/examples/static/main.go @@ -0,0 +1,73 @@ +// Example: Profile data completion menu. +package main + +import ( + "context" + "flag" + "fmt" + "os" + "path" + + testdataloader "github.com/peteole/testdata-loader" + + "git.defalsify.org/vise.git/cache" + "git.defalsify.org/vise.git/engine" + "git.defalsify.org/vise.git/resource" + "git.defalsify.org/vise.git/state" + "git.defalsify.org/vise.git/db" + fsdb "git.defalsify.org/vise.git/db/fs" +) + +var ( + baseDir = testdataloader.GetBasePath() + scriptDir = path.Join(baseDir, "examples", "static") + emptyResult = resource.Result{} +) + +func out(ctx context.Context, sym string, input []byte) (resource.Result, error) { + return resource.Result{ + Content: "foo", + }, nil +} + + +func main() { + var useInternal bool + root := "root" + dir := scriptDir + flag.BoolVar(&useInternal, "i", false, "use internal function for render") + flag.Parse() + fmt.Fprintf(os.Stderr, "starting session at symbol '%s' using resource dir: %s\n", root, dir) + + ctx := context.Background() + st := state.NewState(0) + store := fsdb.NewFsDb() + err := store.Connect(ctx, scriptDir) + if err != nil { + panic(err) + } + rs := resource.NewDbResource(store) + rs.With(db.DATATYPE_STATICLOAD) + + if useInternal { + rs.AddLocalFunc("out", out) + } + ca := cache.NewCache() + cfg := engine.Config{ + Root: root, + } + en := engine.NewEngine(cfg, rs) + en = en.WithState(st) + en = en.WithMemory(ca) + + _, err = en.Exec(ctx, []byte{}) + if err != nil { + fmt.Fprintf(os.Stderr, "exec error: %v\n", err) + os.Exit(1) + } + _, err = en.Flush(ctx, os.Stdout) + if err != nil { + fmt.Fprintf(os.Stderr, "flush error: %v\n", err) + os.Exit(1) + } +} diff --git a/examples/static/root.vis b/examples/static/root.vis @@ -0,0 +1,3 @@ +LOAD out 0 +MAP out +HALT