All Projects → JanWielemaker → Swi Prolog Wasm

JanWielemaker / Swi Prolog Wasm

SWI-Prolog ported to WebAssembly

Programming Languages

prolog
421 projects

Projects that are alternatives of or similar to Swi Prolog Wasm

Webrtc
Pure Go implementation of the WebRTC API
Stars: ✭ 8,399 (+26146.88%)
Mutual labels:  webassembly
Wavm
A High Performance XuperChain WASM Virtual Machine based on WAVM
Stars: ✭ 20 (-37.5%)
Mutual labels:  webassembly
Gameoflife Ts
Stars: ✭ 29 (-9.37%)
Mutual labels:  webassembly
Notecalc3
NoteCalc is a handy calculator trying to bring the advantages of Soulver to the web.
Stars: ✭ 879 (+2646.88%)
Mutual labels:  webassembly
Wps Backend
Smart contract for the Worker Proposal System
Stars: ✭ 15 (-53.12%)
Mutual labels:  webassembly
Mondeto
An open, flexible, and secure online virtual reality system.
Stars: ✭ 28 (-12.5%)
Mutual labels:  webassembly
Zemeroth
😠⚔️😈 A minimalistic 2D turn-based tactical game in Rust
Stars: ✭ 940 (+2837.5%)
Mutual labels:  webassembly
Wasmsign
A tool to add and verify digital signatures to/from WASM binaries
Stars: ✭ 31 (-3.12%)
Mutual labels:  webassembly
Slate
🌌 A new, strongly-typed, fast, and secure programming language made for WebAssembly.
Stars: ✭ 15 (-53.12%)
Mutual labels:  webassembly
Smartcircle
✂️Automatically determine where to crop a circular image out of a rectangular.
Stars: ✭ 29 (-9.37%)
Mutual labels:  webassembly
Schnorrkel Js
a Javascript wrapper for schnorrkel signatures on Ristretto using WebAssembly.
Stars: ✭ 14 (-56.25%)
Mutual labels:  webassembly
Wagon
wagon, a WebAssembly-based Go interpreter, for Go.
Stars: ✭ 882 (+2656.25%)
Mutual labels:  webassembly
Bionic
** Bionic - An Ionic CLI clone for Blazor projects ** moved to:
Stars: ✭ 28 (-12.5%)
Mutual labels:  webassembly
Csla
A home for your business logic in any .NET application.
Stars: ✭ 865 (+2603.13%)
Mutual labels:  webassembly
Wasm Check
TypeScript / JavaScript library for detect WebAssembly features in node.js & browser
Stars: ✭ 30 (-6.25%)
Mutual labels:  webassembly
Nearcore
Reference client for NEAR Protocol
Stars: ✭ 840 (+2525%)
Mutual labels:  webassembly
Terrarium Templates
Template and example projects for Fastly Labs Terrarium https://wasm.fastlylabs.com
Stars: ✭ 21 (-34.37%)
Mutual labels:  webassembly
Rhai
Rhai - An embedded scripting language for Rust.
Stars: ✭ 958 (+2893.75%)
Mutual labels:  webassembly
Cppwasm Book
📚 WebAssembly friendly programming with C/C++ -- Emscripten practice
Stars: ✭ 956 (+2887.5%)
Mutual labels:  webassembly
Node Wasm
Import and use wasm in node
Stars: ✭ 28 (-12.5%)
Mutual labels:  webassembly

SWI-Prolog ported to WebAssembly

This repository contains instructions to compile a Prolog implementation SWI-Prolog (http://swi-prolog.org) to WebAssembly.

Compilation

These compilation instructions assume Linux-based host machine. The resulting WebAssembly binary is platform-independent.

Preparation

You need to download the Emscripten compiler. Follow the instruction on its homepage.

After the successful installation load the Emscripten environment into the current terminal session (asjust path):

source ./emsdk_env.sh

Dependencies

SWI-Prolog depends on zlib. To compile it to WebAssembly:

wget https://zlib.net/zlib-1.2.11.tar.gz -O "$HOME/zlib-1.2.11.tar.gz"
tar -xf "$HOME/zlib-1.2.11.tar.gz" -C "$HOME"
cd "$HOME/zlib-1.2.11"
emconfigure ./configure
emmake make

This will download and build zlib into the zlib-1.2.11 subdirectory in your home directory.

Build SWI-Prolog

git clone https://github.com/rla/swipl-devel.git "$HOME/swipl-devel"
cd "$HOME/swipl-devel"
git fetch
git checkout wasm
./prepare

This will ask:

Do you want me to run git submodule update --init? [Y/n]

As we are not yet building packages, say "n".

If it asks:

Could not find documentation.  What do you want to do?

Then say "3". We do not need documentation to build it.

After this we can run configure and compile:

cd "$HOME/swipl-devel/src"
LDFLAGS=-L"$HOME/zlib-1.2.11" \
  LIBS=-lzlib \
  CPPFLAGS=-I"$HOME/zlib-1.2.11" \
  COFLAGS=-O3 emconfigure ./configure \
    --disable-mt \
    --disable-gmp \
    --disable-custom-flags
emmake make

This will build the necessary 3 files in $HOME/swipl-devel/src. See "Distribution".

Distribution

Binary distribution (in the dist directory) contains the files:

  • swipl-web.wasm - binary distribution of SWI-Prolog executable.
  • swipl-web.dat - necessary files to initialize the runtime and the library.
  • swipl-web.js - JavaScript wrapper that loads the wasm code and prepares the virtual filesystem with the runtime initialization file and the library.

Usage

Please see "Foreign Language Interface" (FLI) in the SWI-Prolog manual. A very limited set of function findings into JavaScript can be seen in the demo. The bindings use cwrap from Emscripten.

General workflow:

  • Set up a stub Module object with noInitialRun: true and other options.
  • Set up FLI bindings in Module.onRuntimeInitialized.
  • Use the bindings to call PL_initialise.
  • Set up the location for standard library.
  • Use the FS API to write code files into the virtual filesystem.
  • Load the code files from SWI-Prolog side using consult/1 or a similar way.
  • Interact with SWI-Prolog through its FLI.

Demo

See example/index.html as a simple example. It can be found online at http://demos.rlaanemets.com/swi-prolog-wasm/example/. The commented code inside the demo provides the documentation.

To test it out locally, you need to serve the files through an HTTP server.

TODO

  • Provide full set of bindings?
  • A way to call JavaScript from SWI-Prolog.
  • Compile and add useful packages.
  • Provide a mechanism to load packs?
  • Easier way to turn Prolog terms into JS objects?
  • See where WebAssembly goes and what interfaces could be added (direct DOM access?).

License

SWI-Prolog is covered with the Simplified BSD license. See http://www.swi-prolog.org/license.html

zlib is covered with the zlib license. See https://zlib.net/zlib_license.html

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].