diff --git a/src/trealla b/src/trealla index 7917680..c91cf8c 160000 --- a/src/trealla +++ b/src/trealla @@ -1 +1 @@ -Subproject commit 79176802554b869d45b1a8aea38a2651c3dded52 +Subproject commit c91cf8c4bce299c641cc2b127bb69e5679a82543 diff --git a/trealla/example_test.go b/trealla/example_test.go index d894875..7b85acc 100644 --- a/trealla/example_test.go +++ b/trealla/example_test.go @@ -19,7 +19,7 @@ func Example() { } // start a new query - query := pl.Query(ctx, "member(X, [1, foo(bar), c]).") + query := pl.Query(ctx, "use_module(library(lists)), member(X, [1, foo(bar), c]).") // calling Close is not necessary if you iterate through the whole query, but it doesn't hurt defer query.Close() diff --git a/trealla/interop.go b/trealla/interop.go index 5347da0..920e48f 100644 --- a/trealla/interop.go +++ b/trealla/interop.go @@ -52,7 +52,7 @@ func (pl *prolog) register(ctx context.Context, name string, arity int, proc Pre pl.procs[pi.String()] = proc vars := numbervars(arity) head := functor.Of(vars...) - body := Atom("host_rpc").Of(head) + body := Atom(":").Of(Atom("wasm_generic"), Atom("host_rpc").Of(head)) clause := fmt.Sprintf(`%s :- %s.`, head.String(), body.String()) return pl.consultText(ctx, "user", clause) } diff --git a/trealla/libtpl.wasm b/trealla/libtpl.wasm index 86bb64c..8c819bf 100755 Binary files a/trealla/libtpl.wasm and b/trealla/libtpl.wasm differ diff --git a/trealla/prolog.go b/trealla/prolog.go index 91025de..8fce3ed 100644 --- a/trealla/prolog.go +++ b/trealla/prolog.go @@ -53,9 +53,11 @@ type prolog struct { spawning map[uint32]*query limiter chan struct{} - ptr uint32 - realloc wasmFunc - free wasmFunc + ptr uint32 + // from stdlib + realloc wasmFunc + free wasmFunc + // from trealla.h pl_consult wasmFunc pl_capture wasmFunc pl_capture_read wasmFunc @@ -63,6 +65,7 @@ type prolog struct { pl_query wasmFunc pl_redo wasmFunc pl_done wasmFunc + pl_error wasmFunc procs map[string]Predicate coros map[int64]coroutine @@ -104,7 +107,7 @@ func New(opts ...Option) (Prolog, error) { } func (pl *prolog) argv() []string { - args := []string{"tpl", "-g", "halt", "--ns"} + args := []string{"tpl", "--ns"} if pl.library != "" { args = append(args, "--library", pl.library) } @@ -130,6 +133,7 @@ func (pl *prolog) init(parent *prolog) error { cfg := wazero.NewModuleConfig().WithName("").WithArgs(argv...).WithFSConfig(fs). WithSysWalltime().WithSysNanotime().WithSysNanosleep(). WithOsyield(runtime.Gosched). + // WithStdout(os.Stdout).WithStderr(os.Stderr). // for debugging output capture WithRandSource(rand.Reader) // run once to initialize global interpreter @@ -190,6 +194,11 @@ func (pl *prolog) init(parent *prolog) error { return err } + pl.pl_error, err = pl.function("pl_error") + if err != nil { + return err + } + pl.pl_consult, err = pl.function("pl_consult") if err != nil { return err diff --git a/trealla/query.go b/trealla/query.go index f2430a0..c24b0be 100644 --- a/trealla/query.go +++ b/trealla/query.go @@ -511,7 +511,7 @@ func (q *query) Err() error { func escapeQuery(query string) string { query = queryEscaper.Replace(query) - return fmt.Sprintf(`js_ask(%s).`, escapeString(query)) + return fmt.Sprintf(`wasm:js_ask(%s).`, escapeString(query)) } // QueryOption is an optional parameter for queries.