Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
a56343f
Adding fix for case where function is self recursive and uses let key…
artella-coding Jul 20, 2013
512f572
adding build script for windows
artella-coding Jul 20, 2013
3aad872
jdk1.8.0-b102 : updating to Shen 13.1
artella-coding Aug 12, 2013
9589d59
b105 : b102 built fine with 500k stackspace. However b105 is failing …
artella-coding Sep 1, 2013
6241bde
b105 : updating with Shen 13.2.1
artella-coding Sep 4, 2013
ef1f9f9
b105 : updating with intelliJ formatting
artella-coding Sep 7, 2013
7399dd5
b105 : taking a step towards making b106 compatible
artella-coding Sep 7, 2013
fc00809
replacing file with version from https://github.com/hraberg/Shen.java
artella-coding Dec 1, 2013
bdb0cc1
making changes to allow Shen.java to work with let recursive function…
artella-coding Dec 1, 2013
ff6d45d
updating with Shen 14 sources
artella-coding Dec 1, 2013
8adb38f
updating README
artella-coding Dec 1, 2013
c8b7d6a
updating readme
artella-coding Dec 1, 2013
5c2209c
updating readme
artella-coding Dec 1, 2013
ad1ee51
updating readme
artella-coding Dec 1, 2013
4c683fd
updating readme
artella-coding Dec 1, 2013
b420be3
updating readme
artella-coding Dec 1, 2013
f3836ec
updating readme
artella-coding Dec 1, 2013
7aa12c4
updating readme
artella-coding Dec 1, 2013
e6a2891
updating readme
artella-coding Dec 1, 2013
e0c7e5b
updating readme
artella-coding Dec 2, 2013
564d055
updating readme
artella-coding Dec 2, 2013
82ef400
updating shen.java script
artella-coding Dec 2, 2013
0dccebf
adding file illustrating error
artella-coding Dec 2, 2013
5baa8c5
updating errors file
artella-coding Dec 2, 2013
4267bd4
narrowed down error for Shen 14
artella-coding Dec 8, 2013
d382f59
labelling which function causes error
artella-coding Dec 8, 2013
80db4f5
more verbose outputting for executable script shen.java
artella-coding Dec 10, 2013
a34876e
illustrating how using old prolog-macro gets rid of error
artella-coding Dec 10, 2013
5c5858e
expanding on documentation of bug in Shen.java
artella-coding Dec 10, 2013
3934ffa
updating to Shen 14.2
artella-coding Jan 26, 2014
e40b7f1
updating README
artella-coding Jan 26, 2014
3ee946f
updating to Shen 15
artella-coding Feb 11, 2014
9a32358
updating README
artella-coding Feb 11, 2014
168e7cf
more detailed documentation and error debugging file
artella-coding Feb 15, 2014
594a166
updating README
artella-coding Feb 15, 2014
fcb00fb
updating README
artella-coding Feb 15, 2014
70b945f
updating README
artella-coding Feb 15, 2014
87ca392
updating README and updating buildAndRunWindows.bat to reflect change…
artella-coding Feb 15, 2014
0c9c558
updating README
artella-coding Feb 15, 2014
a254df5
updating error files
artella-coding Feb 15, 2014
a6f7ea5
updating errors file
artella-coding Feb 15, 2014
7bfac4d
updating error files
artella-coding Feb 16, 2014
7dcd7a5
updating errors files
artella-coding Feb 16, 2014
822ed13
updating errors files
artella-coding Feb 16, 2014
285bfbe
updating errors files
artella-coding Feb 16, 2014
049d72f
updating errors file
artella-coding Feb 16, 2014
283684a
reorganising code
artella-coding Feb 22, 2014
0e67649
reorganising code
artella-coding Feb 22, 2014
52c57f8
fixing bug in compiler which yields errors with prolog tests
artella-coding Feb 22, 2014
6921f98
updating README
artella-coding Feb 22, 2014
03bf4c8
documenting
artella-coding Feb 23, 2014
689f083
documenting
artella-coding Feb 23, 2014
412f0f9
updating README
artella-coding Jun 1, 2014
f3c9028
updating README
artella-coding Jun 1, 2014
eb90a2b
updating readme
artella-coding Aug 26, 2014
4b64535
updating readme
artella-coding Aug 26, 2014
9dd5b10
Shen 16
artella-coding Sep 20, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 52 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 神.java | Shen for Java
# 神.java | Shen for Java (Shen 16)

http://shenlanguage.org/

Expand All @@ -17,21 +17,22 @@ See also: [shen.clj](https://github.com/hraberg/shen.clj)

## This Java Port

**Shen.java is an [invokedynamic](http://www.slideshare.net/CharlesNutter/jax-2012-invoke-dynamic-keynote) based [K Lambda](http://www.shenlanguage.org/documentation/shendoc.htm) compiler.** I don't vouch for any of the implementation details regarding this - I'm learning as we go. All code lives in [`Shen.java`](https://github.com/hraberg/Shen.java/blob/master/src/shen/Shen.java). It passes the Shen test suite.

The main [Shen JVM port](https://www.assembla.com/code/shen-on-java/git/nodes) is done by Joel Shellman and might be used for [Babel](http://www.shenlanguage.org/babel/babel.htm), Mark's IDE project.
**Shen.java is an [invokedynamic](http://www.slideshare.net/CharlesNutter/jax-2012-invoke-dynamic-keynote) based [K Lambda](http://www.shenlanguage.org/documentation/shendoc.htm) compiler.** All code lives in [`Shen.java`](https://github.com/hraberg/Shen.java/blob/master/src/shen/Shen.java). It passes the Shen test suite.

This port is loosely based on [`shen.clj`](https://github.com/hraberg/shen.clj), but has no dependency on Clojure.
Started as an [interpreter](https://github.com/hraberg/Shen.java/blob/2359095c59435597e5761c72dbe9f0246fad0864/src/shen/Shen.java) using [MethodHandles](http://docs.oracle.com/javase/7/docs/api/java/lang/invoke/MethodHandle.html) as a primitive. It's about 2x faster than `shen.clj`.

This is pretty experimental, and this entire project acts as a playground for various JDK 8 and JVM language stuff. There's an IntelliJ project, which requires [IDEA 12](http://www.jetbrains.com/idea/download/index.html) and [JDK 8 with Lambda support](http://jdk8.java.net/lambda/) (b98 - there are often small but breaking changes). It's based on this [Maven project](https://github.com/hraberg/Shen.java/blob/master/pom.xml).
Core requirements :
* [JDK 8u40 Build b06](https://jdk8.java.net/download.html). Thanks to Vicente Arturo Romero Zaldivar of Oracle Corporation for fixing [bug JDK-8046357](https://bugs.openjdk.java.net/browse/JDK-8046357)
* [Maven](http://maven.apache.org/). See [Maven project file](https://github.com/artella-coding/Shen.java/blob/master/pom.xml).

Optional requirements : There's an IntelliJ project, which requires [IDEA 12](http://www.jetbrains.com/idea/download/index.html).

JDK 8 with lamdba can be downloaded at the following locations :
* [Latest JDK 8 with lambda](https://jdk8.java.net/lambda/)
* [Older releases of JDK 8 with lamdba](http://download.java.net/lambda/)

### To run the REPL:

#### In Linux :

export JAVA_HOME=/path/to/jdk1.8.0/with/lambdas
./shen.java

Expand Down Expand Up @@ -69,22 +70,62 @@ JDK 8 with lamdba can be downloaded at the following locations :
(/. X (integer? (/ X 3))))
[0 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60... etc]

#### In Windows XP & 7 :

* Click "Download ZIP" button at https://github.com/artella-coding/Shen.java.
Alternatively : https://github.com/artella-coding/Shen.java/archive/master.zip.

* Download Apache maven from http://maven.apache.org/download.cgi & extract.
Suppose extracted directory is C:\Program Files\maven\apache-maven-2.2.1.

* Download jdk8 from https://jdk8.java.net/download.html

To extract in Windows 7 simply unzip.

To extract in Windows XP :

* Right click on jdk-8-fcs-bin-b129-windows-i586-07_feb_2014.exe

* Choose 7-Zip, then choose 'extract to "jdk-8-fcs-bin-b129-windows-i586-07_feb_2014"'. Suppose extracted dictory is :

C:\Program Files\jdk-8-fcs-bin-b129-windows-i586-07_feb_2014

* Then within extracted directory, choose tools.zip, right click, choose 7-Zip, and "Extract Here".

Then create a file run.bat with the following contents at the top level of the jdk directory :

@echo off

set "JAVA_HOME=C:\Program Files\jdk-8-fcs-bin-b129-windows-i586-07_feb_2014"

FOR /R %%f IN (*.pack) DO "%JAVA_HOME%\bin\unpack200.exe" -r -v "%%f" "%%~pf%%~nf.jar"

and run it.

* In **buildAndRunWindows.bat** :

* Set **JAVA_HOME** appropriately (i.e. C:\Program Files\jdk-8-fcs-bin-b129-windows-i586-07_feb_2014 if performed as above).
* Set **MAVEN_HOME** appropriately (i.e. C:\Program Files\maven\apache-maven-2.2.1) if performed as above).

Then first run of **buildAndRunWindows.bat** performs build.
Subsequent invocations runs the repl.


### The Shen Test Suite

Now passes. It is run at the end of the build:
Passes all tests. It is run at the end of the build:

./build # or ./tests if the jar already exists.

[... loads of output ...]
passed ... 146
passed ... 128
failed ...0
pass rate ...100.0%

ok
0

run time: 9.882 secs
run time: 37.771 secs


It's close to 2x faster than [`shen.clj`](https://github.com/hraberg/shen.clj).
Expand Down
23 changes: 23 additions & 0 deletions buildAndRunWindows.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@echo off

set "JAVA_HOME=C:\Program Files\jdk-8-fcs-bin-b129-windows-i586-07_feb_2014"
set "MAVEN_HOME=C:\Program Files\maven\apache-maven-2.2.1"

IF NOT EXIST "%JAVA_HOME%" (
echo "%JAVA_HOME% does not exist"
EXIT /B
)

IF NOT EXIST "%MAVEN_HOME%" (
echo "%MAVEN_HOME% does not exist"
EXIT /B
)

IF EXIST "./target/shen.java-0.1.0-SNAPSHOT.jar" (
echo "Project has been already been build. See ./target directory"
) ELSE (
echo "Building project"
"%MAVEN_HOME%\bin\mvn.bat" package
)

"%JAVA_HOME%\bin\java" -Xss1000K -jar target/shen.java-0.1.0-SNAPSHOT.jar
6 changes: 6 additions & 0 deletions errors.shen
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
\\To make errors disappear uncomment out the
\\line below

\\(load "errors_oldProlog.shen")

(load "errors_illustrate.shen")
43 changes: 43 additions & 0 deletions errors_debug.shen
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
\*
See following two posts :

https://groups.google.com/d/msg/qilang/3DXJWo0hcRc/wNUU5OKdDMkJ

https://groups.google.com/d/msg/qilang/9WxbCbxg8f4/dJsJtLmREkcJ

Note that you can only track functions which are not made
external. For example if you add "bind" to the list below,
Shen complains that it is not a legitimate function name
*\

(package shen []

\\from prolog.shen
(define deref
[X | Y] ProcessN -> [(deref X ProcessN) | (deref Y ProcessN)]
X ProcessN -> (if (pvar? X)
(let Value (valvector X ProcessN)
(if (= Value -null-)
X
(deref Value ProcessN)))
X))

\\from prolog.shen
(define lazyderef
X ProcessN -> (if (pvar? X)
(let Value (valvector X ProcessN)
(if (= Value -null-)
X
(lazyderef Value ProcessN)))
X))
\*
\\from prolog.shen
(define bind
X Y ProcessN Continuation -> (do (bindv X Y ProcessN)
(let Result (thaw Continuation)
(do (unbindv X ProcessN)
Result))))
*\
)

(map (function track) [shen.deref shen.lazyderef])
88 changes: 88 additions & 0 deletions errors_illustrate.shen
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
\\See errors.shen file

(defprolog mem
X [X | _] <--;
X [Y | Z] <-- (mem X Z);)

\*
The mem function above works fine. However
it is the mem function below which, in conjunction with
the new form of the prolog-macro, and the
"(return X)" which seems to cause the error.
Tracking the mem function shows that it returns
fine.
*\

(defprolog mem
X (mode [X | _] -) <--;
X (mode [_ | Y] -) <-- (mem X Y);)

\*
(defun mem (V542 V543 V544 V545)
(let Case
(let V531 (shen.lazyderef V543 V544)
(if (cons? V531)
(let X (hd V531) (do (shen.incinfs) (unify! X V542 V544 V545)))
false))
(if (= Case false)
(let V532 (shen.lazyderef V543 V544)
(if (cons? V532) (let Y (tl V532) (do (shen.incinfs) (mem V542 Y V544 V545))) false))
Case)))
*\

\\This line causes the problem
(prolog? (mem 1 [X | 2]) (return X))

\*

Note that the following works fine :

(prolog? (mem 1 [X | 2]) (return [X]))
(prolog? (return 2))
(prolog? (mem 1 [X | 2]) (return "2"))
(prolog? (mem 1 [X | 2]) (return Y))
(prolog? (mem "1" [X | 2]) (return X))

But the following does not :

(prolog? (mem 1 [X | 2]) (return 2))

Also if you track mem, then the line above works fine.
But as soon as you untrack, the error returns. To see
this do :

(track mem)

(prolog? (mem 1 [X | 2]) (return X))

(untrack mem)

(prolog? (mem 1 [X | 2]) (return X))

See also the post at :

https://groups.google.com/d/msg/qilang/3DXJWo0hcRc/Q5iXoYaF-FsJ

*****[EXTRA BRACKET PHENOMENON]*****

Also found if you define mem as (notice extra brackets around
"(mem X Y)"):

(defprolog mem
X (mode [X | _] -) <--;
X (mode [_ | Y] -) <-- ((mem X Y));)

(prolog? (mem 1 [X | 2]) (return X))

then the problem line of code works fine. You can also
put the extra brackets upon the invocation of mem i.e
the following code works fine :

(defprolog mem
X (mode [X | _] -) <--;
X (mode [_ | Y] -) <-- (mem X Y);)

\\Notice extra brackets below
(prolog? ((mem 1 [X | 2])) (return X))

*\
15 changes: 15 additions & 0 deletions errors_oldProlog.shen
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
\\See errors.shen file
\\overwriting prolog-macro with old
\\version seems to get rid of errors.

(package shen []

\\This is the old prolog-macro
(define prolog-macro
[prolog? | X] -> [intprolog (prolog-form X)]
X -> X)

(define prolog-form
X -> (cons_form (map (function cons_form) X)))

)
14 changes: 11 additions & 3 deletions shen.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

rlwrap=$(which rlwrap) || "" &> /dev/null
java="$rlwrap $JAVA_HOME/bin/java $JAVA_OPTS"
shen="find . -name shen.java-*.jar"

test -z `$shen` && mvn package
$java -Xss500k -jar `$shen`
if [ "`which shen.java`" != "" ]; then
DIR=$(dirname `which shen.java`)
echo "Using installation in "$DIR
else
DIR="."
fi

shen="find $DIR -name shen.java-*.jar"

test -z `$shen` && mvn -f $DIR"/pom.xml" package
$java -Xss1000k -jar `$shen`
26 changes: 0 additions & 26 deletions shen/Test Programs/Chap13/problems.txt

This file was deleted.

5 changes: 3 additions & 2 deletions shen/Test Programs/einstein.shen
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
X Y List <-- (iright Y X List);)

(defprolog iright
L R [L | [R | _]] <--;
L R [_ | Rest] <-- (iright L R Rest);)
L R (mode [L | [R | _]] -) <--;
L R (mode [_ | Rest] -) <-- (iright L R Rest);)

6 changes: 3 additions & 3 deletions shen/Test Programs/qmachine.shen
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@

(define forall
{(progression A) --> (A --> boolean) --> boolean}
Progression P -> (super Progression P and true))
Progression P -> (super Progression P (function and) true))

(define exists
{(progression A) --> (A --> boolean) --> boolean}
Progression P -> (super Progression P or false))
Progression P -> (super Progression P (function or) false))

(define for
{(progression A) --> (A --> B) --> number}
Progression P -> (super Progression P progn 0))
Progression P -> (super Progression P (function progn) 0))

(define progn
{A --> B --> B}
Expand Down
3 changes: 1 addition & 2 deletions shen/Test Programs/strings.shen
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
Rep "" Ss -> (@s Rep Ss)
Rep (@s S Ss) (@s S Ss') -> (subst-string' Rep Ss Ss')
_ _ _ -> "failed!")



(define rwilli
{string --> string}
"" -> ""
Expand Down
Binary file removed shen/benchmarks/heatwave.gif
Binary file not shown.
Loading