razyk 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +54 -0
- data/Rakefile +7 -55
- data/bin/razyk +1 -67
- data/examples/air_on_the_g_string.lazy +489 -0
- data/examples/air_on_the_g_string.score +14 -0
- data/examples/encoder.rb +62 -0
- data/examples/hello_world.lazy +39 -0
- data/examples/major_scale.lazy +20 -0
- data/examples/minor_scale.lazy +20 -0
- data/examples/score2lazy.rb +38 -0
- data/lib/razyk.rb +7 -2
- data/lib/razyk/application.rb +108 -0
- data/lib/razyk/audio.rb +8 -0
- data/lib/razyk/audio/player.rb +68 -0
- data/lib/razyk/audio/port.rb +36 -0
- data/lib/razyk/node.rb +49 -1
- data/lib/razyk/parser.rb +16 -20
- data/lib/razyk/parser.y +15 -19
- data/lib/razyk/version.rb +3 -0
- data/lib/razyk/vm.rb +52 -54
- data/lib/razyk/webapp.rb +61 -108
- data/lib/razyk/webapp/templates/main.html +216 -49
- data/razyk.gemspec +27 -66
- metadata +163 -86
- data/spec/node_spec.rb +0 -58
- data/spec/spec_helper.rb +0 -5
- data/spec/vm_spec.rb +0 -128
data/spec/spec_helper.rb
DELETED
data/spec/vm_spec.rb
DELETED
@@ -1,128 +0,0 @@
|
|
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
|