Skip to content

Commit

Permalink
use host_rpc_eval for $coro_next
Browse files Browse the repository at this point in the history
  • Loading branch information
guregu committed Aug 18, 2024
1 parent 3b1787c commit 8effaba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions trealla/interop.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ func sys_coro_next_2(pl Prolog, subquery Subquery, goal Term) Term {
if !ok {
return throwTerm(domainError("integer", g.Args[0], g.pi()))
}
t, ok := plc.CoroNext(subquery, id)
if !ok || t == nil {
result, ok := plc.CoroNext(subquery, id)
if !ok || result == nil {
return Atom("fail")
}
// call(( Goal = Result ; '$coro_next'(ID, Goal) ))
// call(( wasm_generic:host_rpc_eval(Goal, Result, [], []) ; '$coro_next'(ID, Goal) ))
return Atom("call").Of(
Atom(";").Of(
Atom("=").Of(g.Args[1], t),
Atom(":").Of(Atom("wasm_generic"), Atom("host_rpc_eval").Of(result, g.Args[1], Atom("[]"), Atom("[]"))),
Atom("$coro_next").Of(id, g.Args[1]),
),
)
Expand Down
4 changes: 3 additions & 1 deletion trealla/interop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ func BenchmarkInteropNondet(b *testing.B) {
b.Fatal("query failed", query.Err())
}
}
query.Close()
if err := query.Close(); err != nil {
b.Error("close error:", err)
}
if leftovers := len(pl.(*prolog).coros); leftovers > 0 {
b.Error("coroutines weren't cleaned up:", leftovers)
}
Expand Down
2 changes: 1 addition & 1 deletion trealla/terms/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Example_nondet_predicate() {
// betwixt(+Min, +Max, ?N).
pl.RegisterNondet(ctx, "betwixt", 3, func(_ trealla.Prolog, _ trealla.Subquery, goal0 trealla.Term) iter.Seq[trealla.Term] {
return func(yield func(trealla.Term) bool) {
// goal is the goal called by Prolog, such as: base32("hello", X).
// goal is the goal called by Prolog, such as: betwixt(1, 10, X).
// Guaranteed to match up with the registered arity and name.
goal := goal0.(trealla.Compound)

Expand Down

0 comments on commit 8effaba

Please sign in to comment.