-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 12ba29f
Showing
39 changed files
with
3,883 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
shen | ||
*.mo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
all: shen | ||
|
||
MO = \ | ||
compiled/core.kl.mo \ | ||
compiled/macros.kl.mo \ | ||
compiled/sequent.kl.mo \ | ||
compiled/track.kl.mo \ | ||
compiled/writer.kl.mo \ | ||
compiled/declarations.kl.mo \ | ||
compiled/prolog.kl.mo \ | ||
compiled/sys.kl.mo \ | ||
compiled/t-star.kl.mo \ | ||
compiled/yacc.kl.mo \ | ||
compiled/load.kl.mo \ | ||
compiled/reader.kl.mo \ | ||
compiled/toplevel.kl.mo \ | ||
compiled/types.kl.mo | ||
|
||
KL = \ | ||
kl/core.kl \ | ||
kl/macros.kl \ | ||
kl/sequent.kl \ | ||
kl/track.kl \ | ||
kl/writer.kl \ | ||
kl/declarations.kl \ | ||
kl/prolog.kl \ | ||
kl/sys.kl \ | ||
kl/t-star.kl \ | ||
kl/yacc.kl \ | ||
kl/load.kl \ | ||
kl/reader.kl \ | ||
kl/toplevel.kl \ | ||
kl/types.kl | ||
|
||
compiled/core.kl.mo: compiled/core.kl.ms | ||
waspc compiled/core.kl.ms | ||
|
||
compiled/macros.kl.mo: compiled/macros.kl.ms | ||
waspc compiled/macros.kl.ms | ||
|
||
compiled/sequent.kl.mo: compiled/sequent.kl.ms | ||
waspc compiled/sequent.kl.ms | ||
|
||
compiled/track.kl.mo: compiled/track.kl.ms | ||
waspc compiled/track.kl.ms | ||
|
||
compiled/writer.kl.mo: compiled/writer.kl.ms | ||
waspc compiled/writer.kl.ms | ||
|
||
compiled/declarations.kl.mo: compiled/declarations.kl.ms | ||
waspc compiled/declarations.kl.ms | ||
|
||
compiled/prolog.kl.mo: compiled/prolog.kl.ms | ||
waspc compiled/prolog.kl.ms | ||
|
||
compiled/sys.kl.mo: compiled/sys.kl.ms | ||
waspc compiled/sys.kl.ms | ||
|
||
compiled/t-star.kl.mo: compiled/t-star.kl.ms | ||
waspc compiled/t-star.kl.ms | ||
|
||
compiled/yacc.kl.mo: compiled/yacc.kl.ms | ||
waspc compiled/yacc.kl.ms | ||
|
||
compiled/load.kl.mo: compiled/load.kl.ms | ||
waspc compiled/load.kl.ms | ||
|
||
compiled/reader.kl.mo: compiled/reader.kl.ms | ||
waspc compiled/reader.kl.ms | ||
|
||
compiled/toplevel.kl.mo: compiled/toplevel.kl.ms | ||
waspc compiled/toplevel.kl.ms | ||
|
||
compiled/types.kl.mo: compiled/types.kl.ms | ||
waspc compiled/types.kl.ms | ||
|
||
compiler.mo: compiler.ms | ||
waspc declarations.ms | ||
|
||
driver.mo: driver.ms primitives.ms declarations.ms compiler.ms | ||
waspc driver.ms | ||
|
||
overwrites-internal.mo: overwrites-internal.ms | ||
waspc overwrites-internal.ms | ||
|
||
primitives.mo: primitives.ms | ||
waspc primitives.ms | ||
|
||
shen.mo: shen.ms $(MO) | ||
waspc shen.ms | ||
|
||
shen: compiler.mo driver.mo overwrites-internal.mo primitives.mo shen.mo $(MO) $(KL) | ||
waspc -exe shen shen.ms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
# Wasp/Shen, a Wasp Lisp port of the Shen Language | ||
|
||
[Shen](http://shenlanguage.org/) is a functional programming language with a number of interesting features. These include: | ||
|
||
* Optional static type checking | ||
* Pattern matching | ||
* Integrated Prolog system | ||
* Parsing libraries | ||
|
||
Shen can be ported without too much effort to other language systems. Many of the community ports are available from the [Shen download page](http://shenlanguage.org/download_form.html). A commercial port of Shen is available as part of [Shen Professional](http://shenlanguage.org/professional.html). | ||
|
||
This port runs on top of [Wasp Lisp](http://bluishcoder.co.nz/tags/waspvm/), a small Lisp system with concurrency and distributed features. Wasp Lisp is not actively developed but the author [Scott Dunlop](https://waspvm.blogspot.com/) monitors the [github repository](https://github.com/swdunlop/WaspVM/) and processes pull requests. Shen requires features that Wasp Lisp doesn't currently support, like real numbers. I maintain a [fork on github](https://github.com/doublec/WaspVM/tree/shen) that implements the features that Shen needs. | ||
|
||
The reason for this port is that I use Wasp Lisp in some projects and wanted to try Shen in some of the areas where I use Wasp and [MOSREF](https://bluishcoder.co.nz/2009/11/28/using-wasp-lisp-secure-remote-injection.html). The port is incomplete but is at a state where it works well enough to publish and get feedback. | ||
|
||
This port is heavily based on the [Shen Scheme](https://github.com/tizoc/shen-scheme) implementation. Much of the code is ported from Scheme to Wasp Lisp and the structure is kept the same. The license for code I wrote is the same as the Shen Scheme License, BSD3-Clause. | ||
|
||
## Building | ||
|
||
First step, build the fork of Wasp Lisp needed to run: | ||
|
||
$ git clone --branch shen https://github.com/doublec/WaspVM wasp-shen | ||
$ cd wasp-shen | ||
$ make install | ||
|
||
Follow the prompts for the location to install the wasp lisp binaries and add that `bin` directory of that location to your path: | ||
|
||
$ export PATH=$PATH:/path/to/install/bin | ||
|
||
Shen is provided in source code format from the [Shen Sources](https://github.com/Shen-Language/shen-sources) github repository. The code is written in Shen. It needs a working Shen system to compile that code to [KLambda](http://www.shenlanguage.org/learn-shen/shendoc.htm#The%20Primitive%20Functions%20of%20K%20Lambda), a small Lisp subset that Shen uses as a virtual machine. This KLamda code can be found in the `kl` directory in this repository. These KLambda files are compiled to Wasp Lisp and stored as compiled code in the `compiled` directory. The repsitory includes a recent version of these files. To generate, or re-generate, run the following commands: | ||
|
||
$ rlwrap wasp | ||
>> (import "driver") | ||
>> (compile-all) | ||
Compiling toplevel.kl | ||
Compiling core.kl | ||
Compiling sys.kl | ||
Compiling sequent.kl | ||
Compiling yacc.kl | ||
Compiling reader.kl | ||
Compiling prolog.kl | ||
Compiling track.kl | ||
Compiling load.kl | ||
Compiling writer.kl | ||
Compiling macros.kl | ||
Compiling declarations.kl | ||
Compiling types.kl | ||
Compiling t-star.kl | ||
|
||
This will create files with the Wasp Lisp code in the `compiled/*.ms` files, and the compiled bytecode in `compiled/*.mo` files. | ||
|
||
Creating a Shen executable can be done with: | ||
|
||
$ waspc -exe shen shen.ms | ||
$ chmod +x shen | ||
$ rlwrap ./shen | ||
Shen, copyright (C) 2010-2015 Mark Tarver | ||
www.shenlanguage.org, Shen 19.3.1 | ||
running under Wasp Lisp, implementation: WaspVM | ||
port 0.1 ported by Chris Double | ||
|
||
|
||
(0-) | ||
|
||
Note that it takes a while to startup as it runs through the Shen and KLambda initialization. | ||
|
||
## Running from the Wasp REPL | ||
|
||
Shen can be run and debugged from the Wasp REPL. To load the compiled code and run Shen: | ||
|
||
$ rlwrap wasp | ||
>> (import "driver") | ||
>> (load-all) | ||
>> (kl:shen) | ||
Shen, copyright (C) 2010-2015 Mark Tarver | ||
www.shenlanguage.org, Shen 19.3.1 | ||
running under Wasp Lisp, implementation: WaspVM | ||
port 0.1 ported by Chris Double | ||
|
||
|
||
(0-) | ||
|
||
When developing on the compiler it's useful to use `eval-all` instead of `load-all`. This will load the KLambda files, compile then to Scheme and `eval` them: | ||
|
||
>> (eval-all) | ||
>> (kl:shen) | ||
... | ||
|
||
A single input like of Shen can be entered and run, returning to the Wasp REPL with: | ||
|
||
>> (kl:shen.read-evaluate-print) | ||
(+ 1 2) | ||
3:: 3 | ||
|
||
KLambda functions can be called from Wasp by prefixing them with `kl:`. For example: | ||
|
||
>> (kl:shen.read-evaluate-print) | ||
(define factorial | ||
1 -> 1 | ||
X -> (* X (factorial (- X 1)))) | ||
factorial:: factorial | ||
>> (kl:factorial 10) | ||
:: 3628800 | ||
|
||
Shen allows introspecting compiled Shen functions and examining the KLambda code. From the Wasp REPL this is useful for viewing the KLambda and comparing with the generated Wasp Lisp: | ||
|
||
>> (kl:ps 'factorial) | ||
:: (defun factorial (V1172) (cond (...) (...))) | ||
>> (pretty (kl:ps 'factorial)) | ||
(defun factorial (V1172 ) (cond ((= 1 V1172 ) 1 ) (#t (* V1172 (factorial (- V1172 1 ) ) ) ) ) ) :: null | ||
>> (pretty (kl->wasp (kl:ps 'factorial))) | ||
(begin (register-function-arity (quote factorial ) 1 ) | ||
(define (kl:factorial V1172) | ||
(cond | ||
((kl:= 1 V1172) 1) | ||
(#t (* V1172 (kl:factorial (- V1172 1)))))) | ||
(quote factorial ) ) :: null | ||
|
||
## Cross Compilation | ||
|
||
Wasp binaries are a small Wasp VM stub plus the compiled Lisp code appended to it. This makes building for other platforms easy as long as you have the stub for that platform. Given a Windows stub in the correct location you can build a Windows binary with: | ||
|
||
$ waspc -exe shen -platform win32-stub shen.ms | ||
|
||
Wasp can be built for [Android](https://bluishcoder.co.nz/2013/05/09/building-wasp-lisp-and-mosref-for-android.html) and [static binaries via musl](https://bluishcoder.co.nz/2016/06/05/building-static-wasp-lisp-binaries.html) are possible. | ||
|
||
## Current Port State | ||
|
||
This is a very early version. I've only just got it working. The [Shen tests](https://github.com/Shen-Language/shen-sources/tree/master/tests) pass with the exception of the [Proof Assistant test](https://github.com/Shen-Language/shen-sources/blob/master/tests/proof%20assistant.shen) which hangs when loading. | ||
|
||
The port is quite slow - about half the speed of the Shen C interpreter and significantly slower than Shen Scheme and Shen on SBCL. I've done some work on optimizing tail calls in the fork of the Wasp VM for Shen but there's much more work on the entire port that could improve things. | ||
|
||
I'd like to wrap some of the Wasp concurrency code and see how well Shen works in areas I use Wasp for. | ||
|
||
## Learning Shen | ||
|
||
Some places to go to learn Shen: | ||
|
||
* The [Shen OS Kernel Manual](http://shenlanguage.org/learn-shen/index.html) has a good overview of what the open source version of Shen can do. | ||
* [Kicking the tires of Shen Prolog](https://bluishcoder.co.nz/2016/08/30/kicking-the-tires-of-shen-prolog.html) | ||
* [Shen, A Sufficiently Advanced Lisp](https://www.youtube.com/watch?v=lMcRBdSdO_U) | ||
* [Shen Trick Shots](https://www.youtube.com/watch?v=BUJNyHAeAc8) | ||
* [The Book of Shen](https://www.amazon.co.uk/Book-Shen-Third-Mark-Tarver/dp/1784562130) | ||
|
||
## Other Ports | ||
|
||
* [Shen Scheme](https://github.com/tizoc/shen-scheme) | ||
* [Shen Elisp](http://github.com/deech/shen-elisp) | ||
* [Shen Ruby](https://github.com/gregspurrier/shen-ruby) | ||
* [Shen Haskell](https://github.com/mthom/shentong) | ||
* [Shen C](https://github.com/otabat/shen-c/) | ||
|
||
## License | ||
|
||
- Shen, Copyright © 2010-2015 Mark Tarver - [License](http://www.shenlanguage.org/license.pdf). | ||
- Portions of the code adapted from shen-scheme, Copyright © 2012-2015 Bruno Deferrari under [BSD 3-Clause License](http://opensource.org/licenses/BSD-3-Clause). | ||
- shen-wasp, Coyright © 2017 Chris Double under [BSD 3-Clause License](http://opensource.org/licenses/BSD-3-Clause). |
Oops, something went wrong.