shen-ruby 0.12.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +5 -0
- data/README.md +8 -12
- data/Rakefile +4 -9
- data/bin/shen_test_suite.rb +0 -1
- data/bin/srrepl +2 -4
- data/lib/shen_ruby/shen.rb +98 -0
- data/lib/shen_ruby/version.rb +1 -1
- data/shen-ruby.gemspec +3 -3
- data/shen/README.txt +9 -13
- data/shen/release/BSD +24 -0
- data/shen/release/klambda/core.kl +157 -0
- data/shen/release/klambda/declarations.kl +109 -0
- data/shen/release/klambda/load.kl +59 -0
- data/shen/release/klambda/macros.kl +91 -0
- data/shen/release/klambda/prolog.kl +228 -0
- data/shen/release/klambda/reader.kl +198 -0
- data/shen/release/klambda/sequent.kl +142 -0
- data/shen/release/klambda/sys.kl +253 -0
- data/shen/release/klambda/t-star.kl +123 -0
- data/shen/release/klambda/toplevel.kl +110 -0
- data/shen/release/klambda/track.kl +79 -0
- data/shen/release/{k_lambda → klambda}/types.kl +41 -63
- data/shen/release/klambda/writer.kl +81 -0
- data/shen/release/klambda/yacc.kl +87 -0
- data/shen/release/license.pdf +0 -0
- data/shen/release/test_programs/Chap13/problems.txt +26 -26
- data/shen/release/test_programs/README.shen +52 -52
- data/shen/release/test_programs/TinyLispFunctions.txt +15 -15
- data/shen/release/test_programs/TinyTypes.shen +55 -55
- data/shen/release/test_programs/binary.shen +24 -24
- data/shen/release/test_programs/bubble_version_1.shen +28 -28
- data/shen/release/test_programs/bubble_version_2.shen +22 -22
- data/shen/release/test_programs/calculator.shen +21 -21
- data/shen/release/test_programs/cartprod.shen +23 -23
- data/shen/release/test_programs/change.shen +25 -25
- data/shen/release/test_programs/classes-defaults.shen +94 -94
- data/shen/release/test_programs/classes-inheritance.shen +100 -100
- data/shen/release/test_programs/classes-typed.shen +74 -74
- data/shen/release/test_programs/classes-untyped.shen +46 -46
- data/shen/release/test_programs/depth_.shen +14 -14
- data/shen/release/test_programs/einstein.shen +34 -34
- data/shen/release/test_programs/fruit_machine.shen +46 -46
- data/shen/release/test_programs/interpreter.shen +217 -217
- data/shen/release/test_programs/metaprog.shen +85 -85
- data/shen/release/test_programs/minim.shen +192 -192
- data/shen/release/test_programs/mutual.shen +11 -11
- data/shen/release/test_programs/n_queens.shen +45 -45
- data/shen/release/test_programs/newton_version_1.shen +33 -33
- data/shen/release/test_programs/newton_version_2.shen +24 -24
- data/shen/release/test_programs/parse.prl +14 -14
- data/shen/release/test_programs/parser.shen +51 -51
- data/shen/release/test_programs/powerset.shen +10 -10
- data/shen/release/test_programs/prime.shen +10 -10
- data/shen/release/test_programs/prolog.shen +78 -78
- data/shen/release/test_programs/proof_assistant.shen +80 -80
- data/shen/release/test_programs/proplog_version_1.shen +25 -25
- data/shen/release/test_programs/proplog_version_2.shen +27 -27
- data/shen/release/test_programs/qmachine.shen +66 -66
- data/shen/release/test_programs/red-black.shen +54 -54
- data/shen/release/test_programs/search.shen +55 -55
- data/shen/release/test_programs/semantic_net.shen +44 -44
- data/shen/release/test_programs/spreadsheet.shen +34 -34
- data/shen/release/test_programs/stack.shen +27 -27
- data/shen/release/test_programs/streams.shen +20 -20
- data/shen/release/test_programs/strings.shen +57 -57
- data/shen/release/test_programs/structures-typed.shen +71 -71
- data/shen/release/test_programs/structures-untyped.shen +41 -41
- data/shen/release/test_programs/tests.shen +232 -232
- data/shen/release/test_programs/types.shen +11 -11
- data/shen/release/test_programs/whist.shen +239 -239
- data/shen/release/test_programs/yacc.shen +132 -132
- metadata +21 -35
- data/shen/lib/shen_ruby/shen.rb +0 -160
- data/shen/license.txt +0 -34
- data/shen/release/benchmarks/N_queens.shen +0 -45
- data/shen/release/benchmarks/README.shen +0 -14
- data/shen/release/benchmarks/benchmarks.shen +0 -52
- data/shen/release/benchmarks/bigprog +0 -2173
- data/shen/release/benchmarks/einstein.shen +0 -33
- data/shen/release/benchmarks/heatwave.gif +0 -0
- data/shen/release/benchmarks/interpreter.shen +0 -219
- data/shen/release/benchmarks/jnk.shen +0 -194
- data/shen/release/benchmarks/picture.jpg +0 -0
- data/shen/release/benchmarks/plato.jpg +0 -0
- data/shen/release/benchmarks/powerset.shen +0 -10
- data/shen/release/benchmarks/prime.shen +0 -10
- data/shen/release/benchmarks/short.shen +0 -129
- data/shen/release/benchmarks/text.txt +0 -68
- data/shen/release/k_lambda/core.kl +0 -181
- data/shen/release/k_lambda/declarations.kl +0 -131
- data/shen/release/k_lambda/load.kl +0 -84
- data/shen/release/k_lambda/macros.kl +0 -112
- data/shen/release/k_lambda/prolog.kl +0 -252
- data/shen/release/k_lambda/reader.kl +0 -222
- data/shen/release/k_lambda/sequent.kl +0 -166
- data/shen/release/k_lambda/sys.kl +0 -271
- data/shen/release/k_lambda/t-star.kl +0 -139
- data/shen/release/k_lambda/toplevel.kl +0 -135
- data/shen/release/k_lambda/track.kl +0 -103
- data/shen/release/k_lambda/writer.kl +0 -105
- data/shen/release/k_lambda/yacc.kl +0 -113
@@ -1,132 +1,132 @@
|
|
1
|
-
(defcc <sent>
|
2
|
-
<np> <vp>;)
|
3
|
-
|
4
|
-
(defcc <det>
|
5
|
-
the; a;)
|
6
|
-
|
7
|
-
(defcc <np>
|
8
|
-
<det> <n>;
|
9
|
-
<name1>;)
|
10
|
-
|
11
|
-
(defcc <n>
|
12
|
-
cat; dog;)
|
13
|
-
|
14
|
-
(defcc <name1>
|
15
|
-
X := X where (element? X [(protect Bill) (protect Ben)]);)
|
16
|
-
|
17
|
-
(defcc <vp>
|
18
|
-
<vtrans> <np>;)
|
19
|
-
|
20
|
-
(defcc <vtrans>
|
21
|
-
likes; chases;)
|
22
|
-
|
23
|
-
(defcc <des>
|
24
|
-
[<ds>] [<es>] := (append <ds> <es>);)
|
25
|
-
|
26
|
-
(defcc <ds>
|
27
|
-
d <ds>;
|
28
|
-
d;)
|
29
|
-
|
30
|
-
(defcc <es>
|
31
|
-
e <es>;
|
32
|
-
e;)
|
33
|
-
|
34
|
-
(defcc <sent'>
|
35
|
-
<np> <vp> := (question <np> <vp>);)
|
36
|
-
|
37
|
-
(define question
|
38
|
-
NP VP -> (append [is it true that your father] VP [?]))
|
39
|
-
|
40
|
-
(defcc <as->bs>
|
41
|
-
a <a->bs> := [b | <a->bs>];
|
42
|
-
a := [b];)
|
43
|
-
|
44
|
-
(defcc <find-digit>
|
45
|
-
<digit> <morestuff> := <digit>;
|
46
|
-
<digit> := <digit>;
|
47
|
-
X <find-digit> := <find-digit>;)
|
48
|
-
|
49
|
-
(defcc <morestuff>
|
50
|
-
X <morestuff>;
|
51
|
-
X;)
|
52
|
-
|
53
|
-
(defcc <digit>
|
54
|
-
0; 1; 2; 3; 4; 5; 6; 7; 8; 9;)
|
55
|
-
|
56
|
-
(defcc <find-digit'>
|
57
|
-
<digit> <morestuff>;
|
58
|
-
<digit> := <digit>;
|
59
|
-
X <find-digit'> := <find-digit'>;)
|
60
|
-
|
61
|
-
(defcc <asbscs>
|
62
|
-
<as> <bs> <cs>;)
|
63
|
-
|
64
|
-
(defcc <as>
|
65
|
-
a <as>;
|
66
|
-
a;)
|
67
|
-
|
68
|
-
(defcc <bs>
|
69
|
-
b <bs>;
|
70
|
-
b;
|
71
|
-
<e>;)
|
72
|
-
|
73
|
-
(defcc <cs>
|
74
|
-
c <cs>;
|
75
|
-
c;)
|
76
|
-
|
77
|
-
(defcc <asbs'cs>
|
78
|
-
<as> <bs'> <cs>;)
|
79
|
-
|
80
|
-
(defcc <bs'>
|
81
|
-
b <bs'>;
|
82
|
-
b;
|
83
|
-
<e>;)
|
84
|
-
|
85
|
-
(defcc <find-digit''>
|
86
|
-
<digit''> <morestuff> := <digit''>;
|
87
|
-
<digit''> := <digit''>;
|
88
|
-
X <find-digit''> := <find-digit''>;)
|
89
|
-
|
90
|
-
(defcc <digit''>
|
91
|
-
X := X where (element? X [0 1 2 3 4 5 6 7 8 9]);)
|
92
|
-
|
93
|
-
(defcc <anbncn>
|
94
|
-
<as> <bs> <cs> := (appendall [<as> <bs> <cs>])
|
95
|
-
where (equal-length? [<as> <bs> <cs>]);)
|
96
|
-
|
97
|
-
(defcc <as>
|
98
|
-
a <as>;
|
99
|
-
a;)
|
100
|
-
|
101
|
-
(defcc <bs>
|
102
|
-
b <bs>;
|
103
|
-
b;)
|
104
|
-
|
105
|
-
(defcc <cs>
|
106
|
-
c <cs>;
|
107
|
-
c;)
|
108
|
-
|
109
|
-
(define equal-length?
|
110
|
-
[] -> true
|
111
|
-
[L] -> true
|
112
|
-
[L1 L2 | Ls] -> (and (= (length L1) (length L2)) (equal-length? [L2 | Ls])))
|
113
|
-
|
114
|
-
(define appendall
|
115
|
-
[] -> []
|
116
|
-
[L | Ls] -> (append L (appendall Ls)))
|
117
|
-
|
118
|
-
(defcc <a*s>
|
119
|
-
[a] := a;)
|
120
|
-
|
121
|
-
(defcc <b*>
|
122
|
-
[b] b;)
|
123
|
-
|
124
|
-
(defcc <c*>
|
125
|
-
[<c*>] := [<c*>];
|
126
|
-
c;)
|
127
|
-
|
128
|
-
(defcc <d*>
|
129
|
-
[<d*>] <d*> := [[<d*>] | <d*>];
|
130
|
-
d <d*> := [d | <d*>];
|
131
|
-
d := [d];)
|
132
|
-
|
1
|
+
(defcc <sent>
|
2
|
+
<np> <vp>;)
|
3
|
+
|
4
|
+
(defcc <det>
|
5
|
+
the; a;)
|
6
|
+
|
7
|
+
(defcc <np>
|
8
|
+
<det> <n>;
|
9
|
+
<name1>;)
|
10
|
+
|
11
|
+
(defcc <n>
|
12
|
+
cat; dog;)
|
13
|
+
|
14
|
+
(defcc <name1>
|
15
|
+
X := X where (element? X [(protect Bill) (protect Ben)]);)
|
16
|
+
|
17
|
+
(defcc <vp>
|
18
|
+
<vtrans> <np>;)
|
19
|
+
|
20
|
+
(defcc <vtrans>
|
21
|
+
likes; chases;)
|
22
|
+
|
23
|
+
(defcc <des>
|
24
|
+
[<ds>] [<es>] := (append <ds> <es>);)
|
25
|
+
|
26
|
+
(defcc <ds>
|
27
|
+
d <ds>;
|
28
|
+
d;)
|
29
|
+
|
30
|
+
(defcc <es>
|
31
|
+
e <es>;
|
32
|
+
e;)
|
33
|
+
|
34
|
+
(defcc <sent'>
|
35
|
+
<np> <vp> := (question <np> <vp>);)
|
36
|
+
|
37
|
+
(define question
|
38
|
+
NP VP -> (append [is it true that your father] VP [?]))
|
39
|
+
|
40
|
+
(defcc <as->bs>
|
41
|
+
a <a->bs> := [b | <a->bs>];
|
42
|
+
a := [b];)
|
43
|
+
|
44
|
+
(defcc <find-digit>
|
45
|
+
<digit> <morestuff> := <digit>;
|
46
|
+
<digit> := <digit>;
|
47
|
+
X <find-digit> := <find-digit>;)
|
48
|
+
|
49
|
+
(defcc <morestuff>
|
50
|
+
X <morestuff>;
|
51
|
+
X;)
|
52
|
+
|
53
|
+
(defcc <digit>
|
54
|
+
0; 1; 2; 3; 4; 5; 6; 7; 8; 9;)
|
55
|
+
|
56
|
+
(defcc <find-digit'>
|
57
|
+
<digit> <morestuff>;
|
58
|
+
<digit> := <digit>;
|
59
|
+
X <find-digit'> := <find-digit'>;)
|
60
|
+
|
61
|
+
(defcc <asbscs>
|
62
|
+
<as> <bs> <cs>;)
|
63
|
+
|
64
|
+
(defcc <as>
|
65
|
+
a <as>;
|
66
|
+
a;)
|
67
|
+
|
68
|
+
(defcc <bs>
|
69
|
+
b <bs>;
|
70
|
+
b;
|
71
|
+
<e>;)
|
72
|
+
|
73
|
+
(defcc <cs>
|
74
|
+
c <cs>;
|
75
|
+
c;)
|
76
|
+
|
77
|
+
(defcc <asbs'cs>
|
78
|
+
<as> <bs'> <cs>;)
|
79
|
+
|
80
|
+
(defcc <bs'>
|
81
|
+
b <bs'>;
|
82
|
+
b;
|
83
|
+
<e>;)
|
84
|
+
|
85
|
+
(defcc <find-digit''>
|
86
|
+
<digit''> <morestuff> := <digit''>;
|
87
|
+
<digit''> := <digit''>;
|
88
|
+
X <find-digit''> := <find-digit''>;)
|
89
|
+
|
90
|
+
(defcc <digit''>
|
91
|
+
X := X where (element? X [0 1 2 3 4 5 6 7 8 9]);)
|
92
|
+
|
93
|
+
(defcc <anbncn>
|
94
|
+
<as> <bs> <cs> := (appendall [<as> <bs> <cs>])
|
95
|
+
where (equal-length? [<as> <bs> <cs>]);)
|
96
|
+
|
97
|
+
(defcc <as>
|
98
|
+
a <as>;
|
99
|
+
a;)
|
100
|
+
|
101
|
+
(defcc <bs>
|
102
|
+
b <bs>;
|
103
|
+
b;)
|
104
|
+
|
105
|
+
(defcc <cs>
|
106
|
+
c <cs>;
|
107
|
+
c;)
|
108
|
+
|
109
|
+
(define equal-length?
|
110
|
+
[] -> true
|
111
|
+
[L] -> true
|
112
|
+
[L1 L2 | Ls] -> (and (= (length L1) (length L2)) (equal-length? [L2 | Ls])))
|
113
|
+
|
114
|
+
(define appendall
|
115
|
+
[] -> []
|
116
|
+
[L | Ls] -> (append L (appendall Ls)))
|
117
|
+
|
118
|
+
(defcc <a*s>
|
119
|
+
[a] := a;)
|
120
|
+
|
121
|
+
(defcc <b*>
|
122
|
+
[b] b;)
|
123
|
+
|
124
|
+
(defcc <c*>
|
125
|
+
[<c*>] := [<c*>];
|
126
|
+
c;)
|
127
|
+
|
128
|
+
(defcc <d*>
|
129
|
+
[<d*>] <d*> := [[<d*>] | <d*>];
|
130
|
+
d <d*> := [d | <d*>];
|
131
|
+
d := [d];)
|
132
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shen-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Spurrier
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-02-
|
12
|
+
date: 2015-02-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: klam
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: 3.1.0
|
68
68
|
description: ShenRuby is a port of the Shen programming language to Ruby. It currently
|
69
|
-
supports Shen version
|
69
|
+
supports Shen version 17.
|
70
70
|
email:
|
71
71
|
- greg@sourcematters.org
|
72
72
|
executables:
|
@@ -87,40 +87,27 @@ files:
|
|
87
87
|
- lib/shen_ruby.rb
|
88
88
|
- lib/shen_ruby/converters.rb
|
89
89
|
- lib/shen_ruby/rb.shen
|
90
|
+
- lib/shen_ruby/shen.rb
|
90
91
|
- lib/shen_ruby/shen_ruby.shen
|
91
92
|
- lib/shen_ruby/version.rb
|
92
93
|
- shen-ruby.gemspec
|
93
94
|
- shen/README.txt
|
94
|
-
- shen/
|
95
|
-
- shen/
|
96
|
-
- shen/release/
|
97
|
-
- shen/release/
|
98
|
-
- shen/release/
|
99
|
-
- shen/release/
|
100
|
-
- shen/release/
|
101
|
-
- shen/release/
|
102
|
-
- shen/release/
|
103
|
-
- shen/release/
|
104
|
-
- shen/release/
|
105
|
-
- shen/release/
|
106
|
-
- shen/release/
|
107
|
-
- shen/release/
|
108
|
-
- shen/release/
|
109
|
-
- shen/release/
|
110
|
-
- shen/release/k_lambda/core.kl
|
111
|
-
- shen/release/k_lambda/declarations.kl
|
112
|
-
- shen/release/k_lambda/load.kl
|
113
|
-
- shen/release/k_lambda/macros.kl
|
114
|
-
- shen/release/k_lambda/prolog.kl
|
115
|
-
- shen/release/k_lambda/reader.kl
|
116
|
-
- shen/release/k_lambda/sequent.kl
|
117
|
-
- shen/release/k_lambda/sys.kl
|
118
|
-
- shen/release/k_lambda/t-star.kl
|
119
|
-
- shen/release/k_lambda/toplevel.kl
|
120
|
-
- shen/release/k_lambda/track.kl
|
121
|
-
- shen/release/k_lambda/types.kl
|
122
|
-
- shen/release/k_lambda/writer.kl
|
123
|
-
- shen/release/k_lambda/yacc.kl
|
95
|
+
- shen/release/BSD
|
96
|
+
- shen/release/klambda/core.kl
|
97
|
+
- shen/release/klambda/declarations.kl
|
98
|
+
- shen/release/klambda/load.kl
|
99
|
+
- shen/release/klambda/macros.kl
|
100
|
+
- shen/release/klambda/prolog.kl
|
101
|
+
- shen/release/klambda/reader.kl
|
102
|
+
- shen/release/klambda/sequent.kl
|
103
|
+
- shen/release/klambda/sys.kl
|
104
|
+
- shen/release/klambda/t-star.kl
|
105
|
+
- shen/release/klambda/toplevel.kl
|
106
|
+
- shen/release/klambda/track.kl
|
107
|
+
- shen/release/klambda/types.kl
|
108
|
+
- shen/release/klambda/writer.kl
|
109
|
+
- shen/release/klambda/yacc.kl
|
110
|
+
- shen/release/license.pdf
|
124
111
|
- shen/release/test_programs/Chap13/problems.txt
|
125
112
|
- shen/release/test_programs/README.shen
|
126
113
|
- shen/release/test_programs/TinyLispFunctions.txt
|
@@ -172,13 +159,12 @@ files:
|
|
172
159
|
- spec/spec_helper.rb
|
173
160
|
homepage: https://github.com/gregspurrier/shen-ruby
|
174
161
|
licenses:
|
175
|
-
-
|
162
|
+
- BSD/MIT
|
176
163
|
metadata: {}
|
177
164
|
post_install_message:
|
178
165
|
rdoc_options: []
|
179
166
|
require_paths:
|
180
167
|
- lib
|
181
|
-
- shen/lib
|
182
168
|
required_ruby_version: !ruby/object:Gem::Requirement
|
183
169
|
requirements:
|
184
170
|
- - ">="
|
data/shen/lib/shen_ruby/shen.rb
DELETED
@@ -1,160 +0,0 @@
|
|
1
|
-
############################################################################
|
2
|
-
# License
|
3
|
-
# -------
|
4
|
-
# The user is free to produce commercial applications with the
|
5
|
-
# software, to distribute these applications in source or binary form,
|
6
|
-
# and to charge monies for them as he sees fit and in concordance with
|
7
|
-
# the laws of the land subject to the following license.
|
8
|
-
#
|
9
|
-
# 1. The license applies to all the software and all derived software
|
10
|
-
# and must appear on such.
|
11
|
-
#
|
12
|
-
# 2. It is illegal to distribute the software without this license
|
13
|
-
# attached to it and use of the software implies agreement with the
|
14
|
-
# license as such. It is illegal for anyone who is not the copyright
|
15
|
-
# holder to tamper with or change the license.
|
16
|
-
#
|
17
|
-
# 3. Neither the names of Lambda Associates or the copyright holder
|
18
|
-
# may be used to endorse or promote products built using the software
|
19
|
-
# without specific prior written permission from the copyright holder.
|
20
|
-
#
|
21
|
-
# 4. That possession of this license does not confer on the copyright
|
22
|
-
# holder any special contractual obligation towards the user. That in
|
23
|
-
# no event shall the copyright holder be liable for any direct,
|
24
|
-
# indirect, incidental, special, exemplary or consequential damages
|
25
|
-
# (including but not limited to procurement of substitute goods or
|
26
|
-
# services, loss of use, data, or profits; or business interruption),
|
27
|
-
# however caused and on any theory of liability, whether in contract,
|
28
|
-
# strict liability or tort (including negligence) arising in any way
|
29
|
-
# out of the use of the software, even if advised of the possibility
|
30
|
-
# of such damage.
|
31
|
-
#
|
32
|
-
# 5. It is permitted for the user to change the software, for the
|
33
|
-
# purpose of improving performance, correcting an error, or porting to
|
34
|
-
# a new platform, and distribute the modified version of Shen
|
35
|
-
# (hereafter the modified version) provided the resulting program
|
36
|
-
# conforms in all respects to the Shen standard and is issued under
|
37
|
-
# that title. The user must make it clear with his distribution that
|
38
|
-
# he/she is the author of the changes and what these changes are and
|
39
|
-
# why.
|
40
|
-
#
|
41
|
-
# 6. Derived versions of this software in whatever form are subject to
|
42
|
-
# the same restrictions. In particular it is not permitted to make
|
43
|
-
# derived copies of this software which do not conform to the Shen
|
44
|
-
# standard or appear under a different title.
|
45
|
-
#
|
46
|
-
# 7. It is permitted to distribute versions of Shen which incorporate
|
47
|
-
# libraries, graphics or other facilities which are not part of the
|
48
|
-
# Shen standard.
|
49
|
-
#
|
50
|
-
# For an explication of this license see
|
51
|
-
# http://www.lambdassociates.org/News/june11/license.htm which
|
52
|
-
# explains this license in full.
|
53
|
-
#
|
54
|
-
############################################################################
|
55
|
-
#
|
56
|
-
# This file was written by Greg Spurrier as part of the ShenRuby
|
57
|
-
# project. It is essentially a shell into which the K Lambda sources
|
58
|
-
# of Shen are loaded at runtime as part of object initialization to
|
59
|
-
# produce a working Shen environment. It is thefore a derivative work
|
60
|
-
# of the Shen sources and is subject to the Shen License.
|
61
|
-
#
|
62
|
-
############################################################################
|
63
|
-
|
64
|
-
module ShenRuby
|
65
|
-
# Instances of the ShenRuby::Shen class provide a Shen environment
|
66
|
-
# running within a Klam environment
|
67
|
-
class Shen < Klam::Environment
|
68
|
-
def initialize
|
69
|
-
super
|
70
|
-
|
71
|
-
# Set the global variables
|
72
|
-
set("*language*".to_sym, "Ruby")
|
73
|
-
set("*implementation*".to_sym, "#{::RUBY_ENGINE} #{::RUBY_VERSION}")
|
74
|
-
set("*release*".to_sym, ::RUBY_VERSION)
|
75
|
-
set("*port*".to_sym, ::ShenRuby::VERSION)
|
76
|
-
set("*porters*".to_sym, "Greg Spurrier")
|
77
|
-
set("*home-directory*".to_sym, ::Dir.pwd)
|
78
|
-
set("*stinput*".to_sym, ::STDIN)
|
79
|
-
set("*stoutput*".to_sym, ::STDOUT)
|
80
|
-
|
81
|
-
# Load the K Lambda files
|
82
|
-
kl_root = ::File.expand_path('../../../release/k_lambda', __FILE__)
|
83
|
-
%w(toplevel core sys).each do |kl_filename|
|
84
|
-
::ShenRuby::Shen.load_file(self, ::File.join(kl_root, kl_filename + ".kl"))
|
85
|
-
end
|
86
|
-
|
87
|
-
# Overrides
|
88
|
-
class << self
|
89
|
-
# Give a way to bail out
|
90
|
-
def quit
|
91
|
-
::Kernel.exit(0)
|
92
|
-
end
|
93
|
-
|
94
|
-
# Add a way to evaluate strings, intended for use with Ruby interop.
|
95
|
-
# Returns the result of the last expression evaluated.
|
96
|
-
def eval_string(s)
|
97
|
-
forms = __send__(:"read-from-string", s)
|
98
|
-
result = nil
|
99
|
-
while forms
|
100
|
-
result = eval(head(forms))
|
101
|
-
forms = tail(forms)
|
102
|
-
end
|
103
|
-
result
|
104
|
-
end
|
105
|
-
alias_method :"eval-string", :eval_string
|
106
|
-
|
107
|
-
# The performance of `element?` is critical
|
108
|
-
def element?(x, l)
|
109
|
-
while l
|
110
|
-
return true if l.hd == x
|
111
|
-
l = l.tl
|
112
|
-
end
|
113
|
-
return false
|
114
|
-
rescue => e
|
115
|
-
__send(:"shen.sys-error", :element?)
|
116
|
-
end
|
117
|
-
|
118
|
-
def vector(n)
|
119
|
-
v = ::Klam::Absvector.new(n + 1, :"shen.fail!")
|
120
|
-
v[0] = n
|
121
|
-
v
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
# Load the rest of the K Lambda files
|
126
|
-
%w(sequent yacc
|
127
|
-
reader prolog track load writer
|
128
|
-
macros declarations types t-star
|
129
|
-
).each do |kl_filename|
|
130
|
-
::ShenRuby::Shen.load_file(self, ::File.join(kl_root, kl_filename + ".kl"))
|
131
|
-
end
|
132
|
-
|
133
|
-
# Give type signatures to the new functions added above
|
134
|
-
declare :quit, cons(:"-->", cons(:unit, nil))
|
135
|
-
declare :eval_string, cons(:string, cons(:"-->", cons(:unit, nil)))
|
136
|
-
declare :"eval-string", cons(:string, cons(:"-->", cons(:unit, nil)))
|
137
|
-
|
138
|
-
systemf :"rb-const"
|
139
|
-
systemf :"rb-send"
|
140
|
-
systemf :"rb-send-block"
|
141
|
-
|
142
|
-
old_hush = value(:"*hush*")
|
143
|
-
set :"*hush*", true
|
144
|
-
load ::File.expand_path('../../../../lib/shen_ruby/rb.shen', __FILE__)
|
145
|
-
load ::File.expand_path('../../../../lib/shen_ruby/shen_ruby.shen', __FILE__)
|
146
|
-
set :"*hush*", old_hush
|
147
|
-
end
|
148
|
-
|
149
|
-
class << self
|
150
|
-
def load_file(env, path)
|
151
|
-
::File.open(path, 'r') do |file|
|
152
|
-
reader = ::Klam::Reader.new(file)
|
153
|
-
while form = reader.next
|
154
|
-
env.__send__(:"eval-kl", form)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|