razyk 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/LICENSE +56 -0
- data/README.rdoc +17 -0
- data/Rakefile +62 -0
- data/VERSION +1 -0
- data/bin/razyk +72 -0
- data/examples/lazier.scm +328 -0
- data/examples/prelude.scm +86 -0
- data/examples/prime.lazy +20 -0
- data/examples/reverse.lazy +4 -0
- data/examples/reverse.scm +12 -0
- data/lib/razyk/graph.rb +66 -0
- data/lib/razyk/node.rb +117 -0
- data/lib/razyk/parser.rb +423 -0
- data/lib/razyk/parser.y +227 -0
- data/lib/razyk/vm.rb +212 -0
- data/lib/razyk/webapp/templates/main.html +69 -0
- data/lib/razyk/webapp.rb +161 -0
- data/lib/razyk.rb +20 -0
- data/spec/node_spec.rb +58 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/vm_spec.rb +128 -0
- metadata +129 -0
data/spec/node_spec.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative "spec_helper"
|
4
|
+
|
5
|
+
require "razyk/node"
|
6
|
+
|
7
|
+
include RazyK
|
8
|
+
|
9
|
+
describe Combinator do
|
10
|
+
it "should be created with label" do
|
11
|
+
Combinator.new(:l).label.should == :l
|
12
|
+
end
|
13
|
+
|
14
|
+
it "#to_s return label string" do
|
15
|
+
Combinator.new(:name).to_s.should == "name"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe Pair do
|
20
|
+
it "should be created with two Combinator" do
|
21
|
+
a = Combinator.new :a
|
22
|
+
b = Combinator.new :b
|
23
|
+
pair = Pair.new(a, b)
|
24
|
+
pair.car.should == a
|
25
|
+
pair.cdr.should == b
|
26
|
+
pair.to_s.should == "(a b)"
|
27
|
+
a.from.should == [pair]
|
28
|
+
b.from.should == [pair]
|
29
|
+
end
|
30
|
+
|
31
|
+
it "#car= should replace car" do
|
32
|
+
a = Combinator.new :a
|
33
|
+
b = Combinator.new :b
|
34
|
+
pair = Pair.new(a, b)
|
35
|
+
c = Combinator.new :c
|
36
|
+
pair.car = c
|
37
|
+
pair.car.should == c
|
38
|
+
pair.cdr.should == b
|
39
|
+
a.from.should be_empty
|
40
|
+
c.from.should == [pair]
|
41
|
+
b.from.should == [pair]
|
42
|
+
pair.to_s.should == "(c b)"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "#cdr= should replace cdr" do
|
46
|
+
a = Combinator.new :a
|
47
|
+
b = Combinator.new :b
|
48
|
+
pair = Pair.new(a, b)
|
49
|
+
c = Combinator.new :c
|
50
|
+
pair.cdr = c
|
51
|
+
pair.car.should == a
|
52
|
+
pair.cdr.should == c
|
53
|
+
a.from.should == [pair]
|
54
|
+
b.from.should be_empty
|
55
|
+
c.from.should == [pair]
|
56
|
+
pair.to_s.should == "(a c)"
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/vm_spec.rb
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative "spec_helper"
|
4
|
+
|
5
|
+
require "razyk/vm"
|
6
|
+
require "stringio"
|
7
|
+
|
8
|
+
include RazyK
|
9
|
+
|
10
|
+
describe VM do
|
11
|
+
it "should reduce I combinator" do
|
12
|
+
i = Combinator.new(:I)
|
13
|
+
x = Combinator.new(:X)
|
14
|
+
cons = Pair.new(i, x)
|
15
|
+
vm = VM.new(cons)
|
16
|
+
vm.tree.should == cons
|
17
|
+
x.from.size.should == 1
|
18
|
+
x.from[0].should == cons
|
19
|
+
vm.reduce
|
20
|
+
vm.tree.should == x
|
21
|
+
x.from.size.should == 1
|
22
|
+
x.from[0].should_not == cons
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should reduce K combinator" do
|
26
|
+
k = Combinator.new(:K)
|
27
|
+
x = Combinator.new(:X)
|
28
|
+
y = Combinator.new(:Y)
|
29
|
+
cons1 = Pair.new(k, x)
|
30
|
+
cons2 = Pair.new(cons1, y)
|
31
|
+
vm = VM.new(cons2)
|
32
|
+
vm.tree.should == cons2
|
33
|
+
x.from.size.should == 1
|
34
|
+
x.from[0].should == cons1
|
35
|
+
vm.reduce
|
36
|
+
vm.tree.should == x
|
37
|
+
x.from.size.should == 1
|
38
|
+
x.from[0].should_not == cons1
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should reduce S combinator" do
|
42
|
+
s = Combinator.new(:S)
|
43
|
+
x = Combinator.new(:X)
|
44
|
+
y = Combinator.new(:Y)
|
45
|
+
z = Combinator.new(:Z)
|
46
|
+
cons1 = Pair.new(s, x)
|
47
|
+
cons2 = Pair.new(cons1, y)
|
48
|
+
cons3 = Pair.new(cons2, z)
|
49
|
+
vm = VM.new(cons3)
|
50
|
+
vm.tree.should == cons3
|
51
|
+
x.from.should == [ cons1 ]
|
52
|
+
y.from.should == [ cons2 ]
|
53
|
+
z.from.should == [ cons3 ]
|
54
|
+
vm.reduce
|
55
|
+
vm.tree.inspect.should == "((X Z) (Y Z))"
|
56
|
+
x.from.size.should == 1
|
57
|
+
x.from.should_not == [ cons1 ]
|
58
|
+
y.from.size.should == 1
|
59
|
+
y.from.should_not == [ cons2 ]
|
60
|
+
z.from.size.should == 2
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should reduce CONS and CAR combinator" do
|
64
|
+
cons = Combinator.new(:CONS)
|
65
|
+
a = Combinator.new(:A)
|
66
|
+
b = Combinator.new(:B)
|
67
|
+
list = Pair.new(Pair.new(cons, a), b)
|
68
|
+
car = Combinator.new(:CAR)
|
69
|
+
root = Pair.new(car, list)
|
70
|
+
vm = VM.new(root)
|
71
|
+
vm.evaluate(vm.tree)
|
72
|
+
vm.tree.should == a
|
73
|
+
a.from.size.should == 1
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should reduce CONS and CDR combinator" do
|
77
|
+
cons = Combinator.new(:CONS)
|
78
|
+
a = Combinator.new(:A)
|
79
|
+
b = Combinator.new(:B)
|
80
|
+
list = Pair.new(Pair.new(cons, a), b)
|
81
|
+
cdr = Combinator.new(:CDR)
|
82
|
+
root = Pair.new(cdr, list)
|
83
|
+
vm = VM.new(root)
|
84
|
+
vm.evaluate(vm.tree)
|
85
|
+
vm.tree.should == b
|
86
|
+
b.from.size.should == 1
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should reduce IN combinator (CAR)" do
|
90
|
+
input = Combinator.new(:IN)
|
91
|
+
car = Combinator.new(:CAR)
|
92
|
+
root = Pair.new(car, input)
|
93
|
+
buf = StringIO.new([100, 200].pack("C"))
|
94
|
+
vm = VM.new(root, buf)
|
95
|
+
vm.evaluate(vm.tree)
|
96
|
+
vm.tree.should be_is_a(Combinator)
|
97
|
+
vm.tree.label.should == 100
|
98
|
+
buf.pos.should == 1
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should reduce IN combinator (CDR)" do
|
102
|
+
input = Combinator.new(:IN)
|
103
|
+
cdr = Combinator.new(:CDR)
|
104
|
+
root = Pair.new(cdr, input)
|
105
|
+
buf = StringIO.new([100, 200].pack("C*"))
|
106
|
+
vm = VM.new(root, buf)
|
107
|
+
vm.evaluate(vm.tree)
|
108
|
+
vm.tree.should be_is_a(Pair)
|
109
|
+
vm.tree.cdr.label == :IN
|
110
|
+
vm.tree.from.size.should == 1
|
111
|
+
buf.pos.should == 2
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should reduce PUTC combinator" do
|
115
|
+
putc = Combinator.new(:PUTC)
|
116
|
+
a = Combinator.new(97)
|
117
|
+
x = Combinator.new(:X)
|
118
|
+
decode = Pair.new(Pair.new(a, :INC), 0)
|
119
|
+
root = Pair.new(Pair.new(putc, decode), x)
|
120
|
+
ibuf = StringIO.new("")
|
121
|
+
obuf = StringIO.new("")
|
122
|
+
vm = VM.new(root,ibuf, obuf)
|
123
|
+
vm.evaluate(vm.tree)
|
124
|
+
obuf.string.should == "a"
|
125
|
+
vm.tree.should == x
|
126
|
+
x.from.size.should == 1
|
127
|
+
end
|
128
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: razyk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 0.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- nagachika
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-11-19 00:00:00 +09:00
|
18
|
+
default_executable: razyk
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 2
|
31
|
+
- 9
|
32
|
+
version: 1.2.9
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rack
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: ruby-graphviz
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
type: :runtime
|
60
|
+
version_requirements: *id003
|
61
|
+
description: RazyK is a LazyK implementetion by pure ruby
|
62
|
+
email: nagachika00@gmail.com
|
63
|
+
executables:
|
64
|
+
- razyk
|
65
|
+
extensions: []
|
66
|
+
|
67
|
+
extra_rdoc_files:
|
68
|
+
- LICENSE
|
69
|
+
- README.rdoc
|
70
|
+
files:
|
71
|
+
- .document
|
72
|
+
- .rspec
|
73
|
+
- LICENSE
|
74
|
+
- README.rdoc
|
75
|
+
- Rakefile
|
76
|
+
- VERSION
|
77
|
+
- bin/razyk
|
78
|
+
- examples/lazier.scm
|
79
|
+
- examples/prelude.scm
|
80
|
+
- examples/prime.lazy
|
81
|
+
- examples/reverse.lazy
|
82
|
+
- examples/reverse.scm
|
83
|
+
- lib/razyk.rb
|
84
|
+
- lib/razyk/graph.rb
|
85
|
+
- lib/razyk/node.rb
|
86
|
+
- lib/razyk/parser.rb
|
87
|
+
- lib/razyk/parser.y
|
88
|
+
- lib/razyk/vm.rb
|
89
|
+
- lib/razyk/webapp.rb
|
90
|
+
- lib/razyk/webapp/templates/main.html
|
91
|
+
- spec/node_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
- spec/vm_spec.rb
|
94
|
+
has_rdoc: true
|
95
|
+
homepage: http://github.com/nagachika/razyk
|
96
|
+
licenses: []
|
97
|
+
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
119
|
+
requirements: []
|
120
|
+
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 1.3.7
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: pure ruby LazyK implementation
|
126
|
+
test_files:
|
127
|
+
- spec/node_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
- spec/vm_spec.rb
|