trealla-prolog / go Goto Github PK
View Code? Open in Web Editor NEWTrealla Prolog embedded in Go using WASM
License: MIT License
Trealla Prolog embedded in Go using WASM
License: MIT License
It's possible to exhaust the memory of the interpreter (4GB) by throwing a ton of concurrent queries at it. Using wasm64 should fix this.
Currently I'm just kind of shoving the modules from lib/
into Trealla and building it. Need to improve this by maybe: automating this process, or including json/toplevel in the main project, or work around this with better consulting.
FYI, I plan on moving this to the @trealla-prolog organization. See discussion here: trealla-prolog/trealla#450 (comment)
Package name will probably become something like github.com/trealla-prolog/go/trealla
(or maybe /prolog
? ๐ค)
Currently all queries go through a fresh interpreter. It would be nice to keep them alive so they can keep their knowledge base contents between requests.
I'm not sure how easy it will be because the stdin interfaces for Go WASM libraries don't look so great. Would be really nice to be able to pass an io.Reader
to them.
Might be possible to work around by exporting Go/C functions and calling from Trealla FFI (need to add FFI to Trealla WASM first).
@guregu hi! ~
could you help me resolve this? just trying go build
for stream but getting stopped at these errors. haven't encountered this before. also just updated go version; if that matters. Windows 11.
(sorry for posting here , but idk how else to contact you ๐
)
$ WASMTIME_BACKTRACE_DETAILS=1 go test -v ./trealla
=== RUN TestInterop/custom_function
2023/07/19 18:29:51 query: interop_test(X).
2023/07/19 18:29:51 query: X is 1 + 1.
=== NAME TestInterop
interop_test.go:34: trealla: query error: error while executing at wasm backtrace:
0: <unknown>!pl_query
1: 0x1fe1db - fn_sys_host_call_2
at /Users/guregu/code/trealla/fork/src/predicates.c:7692:12
2: 0x234bc6 - start
at /Users/guregu/code/trealla/fork/src/query.c:1611:14
3: 0x23b115 - execute
at /Users/guregu/code/trealla/fork/src/query.c:1823:9
4: 0xf8327 - run
at /Users/guregu/code/trealla/fork/src/parser.c:3630:3
5: 0x223e56 - pl_query
at /Users/guregu/code/trealla/fork/src/prolog.c:162:12
Caused by:
wasm trap: call stack exhausted
Works ok on macOS+arm64 so probably something weird going on. This is running in a VM though.
Cool project! Would you accept contributions to support more Prologs? Or embed in other languages different than Go?
Back in 2019 we created a script to run/install many Prolog systems for the LP/CP programming contest:
https://github.com/lpcp-contest/docker-lpcpsys/blob/master/scripts/build.sh
It builds a docker file but maybe it is not hard to target WASM.
Would wasmtime
provide any advantage over wasmer
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.