nydp 0.5.1 → 0.6.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 +4 -4
- data/.gitignore +1 -0
- data/README.md +77 -56
- data/lib/lisp/core-000.nydp +1 -1
- data/lib/lisp/core-010-precompile.nydp +49 -29
- data/lib/lisp/core-012-utils.nydp +12 -8
- data/lib/lisp/core-015-documentation.nydp +41 -15
- data/lib/lisp/core-017-builtin-dox.nydp +621 -100
- data/lib/lisp/core-020-utils.nydp +33 -6
- data/lib/lisp/core-025-warnings.nydp +1 -1
- data/lib/lisp/core-030-syntax.nydp +64 -48
- data/lib/lisp/core-035-flow-control.nydp +20 -28
- data/lib/lisp/core-037-list-utils.nydp +84 -21
- data/lib/lisp/core-040-utils.nydp +8 -5
- data/lib/lisp/core-041-string-utils.nydp +17 -11
- data/lib/lisp/core-043-list-utils.nydp +140 -77
- data/lib/lisp/core-045-dox-utils.nydp +1 -0
- data/lib/lisp/core-050-test-runner.nydp +8 -12
- data/lib/lisp/core-070-prefix-list.nydp +19 -15
- data/lib/lisp/core-080-pretty-print.nydp +13 -5
- data/lib/lisp/core-090-hook.nydp +11 -11
- data/lib/lisp/core-100-utils.nydp +51 -66
- data/lib/lisp/core-110-hash-utils.nydp +34 -7
- data/lib/lisp/core-120-settings.nydp +14 -9
- data/lib/lisp/core-130-validations.nydp +28 -13
- data/lib/lisp/core-900-benchmarking.nydp +420 -47
- data/lib/lisp/tests/000-empty-args-examples.nydp +5 -0
- data/lib/lisp/tests/andify-examples.nydp +1 -1
- data/lib/lisp/tests/auto-hash-examples.nydp +6 -1
- data/lib/lisp/tests/best-examples.nydp +1 -1
- data/lib/lisp/tests/boot-tests.nydp +1 -1
- data/lib/lisp/tests/date-examples.nydp +129 -102
- data/lib/lisp/tests/destructuring-examples.nydp +1 -1
- data/lib/lisp/tests/dox-tests.nydp +2 -2
- data/lib/lisp/tests/hash-examples.nydp +58 -33
- data/lib/lisp/tests/list-tests.nydp +137 -1
- data/lib/lisp/tests/pretty-print-tests.nydp +12 -0
- data/lib/lisp/tests/rotate-2d-array-examples.nydp +26 -0
- data/lib/lisp/tests/sort-examples.nydp +5 -5
- data/lib/lisp/tests/string-tests.nydp +16 -5
- data/lib/lisp/tests/syntax-tests.nydp +10 -2
- data/lib/lisp/tests/time-examples.nydp +8 -1
- data/lib/lisp/tests/unparse-tests.nydp +13 -7
- data/lib/nydp/assignment.rb +15 -28
- data/lib/nydp/builtin/abs.rb +4 -3
- data/lib/nydp/builtin/apply.rb +8 -10
- data/lib/nydp/builtin/cdr_set.rb +1 -1
- data/lib/nydp/builtin/comment.rb +1 -3
- data/lib/nydp/builtin/date.rb +11 -28
- data/lib/nydp/builtin/divide.rb +3 -10
- data/lib/nydp/builtin/ensuring.rb +6 -21
- data/lib/nydp/builtin/error.rb +2 -4
- data/lib/nydp/builtin/eval.rb +9 -4
- data/lib/nydp/builtin/greater_than.rb +7 -8
- data/lib/nydp/builtin/handle_error.rb +10 -34
- data/lib/nydp/builtin/hash.rb +24 -45
- data/lib/nydp/builtin/inspect.rb +1 -3
- data/lib/nydp/builtin/is_equal.rb +4 -7
- data/lib/nydp/builtin/less_than.rb +6 -7
- data/lib/nydp/builtin/log.rb +7 -0
- data/lib/nydp/builtin/math_ceiling.rb +1 -3
- data/lib/nydp/builtin/math_floor.rb +1 -3
- data/lib/nydp/builtin/math_power.rb +1 -3
- data/lib/nydp/builtin/math_round.rb +2 -2
- data/lib/nydp/builtin/minus.rb +7 -14
- data/lib/nydp/builtin/parse.rb +5 -5
- data/lib/nydp/builtin/parse_in_string.rb +5 -7
- data/lib/nydp/builtin/plus.rb +14 -31
- data/lib/nydp/builtin/pre_compile.rb +1 -3
- data/lib/nydp/builtin/puts.rb +4 -8
- data/lib/nydp/builtin/quit.rb +1 -1
- data/lib/nydp/builtin/rand.rb +6 -11
- data/lib/nydp/builtin/random_string.rb +2 -4
- data/lib/nydp/builtin/rng.rb +25 -0
- data/lib/nydp/builtin/ruby_wrap.rb +27 -14
- data/lib/nydp/builtin/script_run.rb +1 -3
- data/lib/nydp/builtin/set_intersection.rb +3 -4
- data/lib/nydp/builtin/set_union.rb +3 -4
- data/lib/nydp/builtin/sort.rb +2 -7
- data/lib/nydp/builtin/string_match.rb +5 -13
- data/lib/nydp/builtin/string_replace.rb +2 -7
- data/lib/nydp/builtin/string_split.rb +3 -8
- data/lib/nydp/builtin/sym.rb +2 -9
- data/lib/nydp/builtin/thread_locals.rb +2 -2
- data/lib/nydp/builtin/time.rb +38 -44
- data/lib/nydp/builtin/times.rb +6 -15
- data/lib/nydp/builtin/to_integer.rb +8 -14
- data/lib/nydp/builtin/to_string.rb +2 -13
- data/lib/nydp/builtin/type_of.rb +10 -16
- data/lib/nydp/builtin/vm_info.rb +2 -10
- data/lib/nydp/builtin.rb +15 -37
- data/lib/nydp/compiler.rb +29 -19
- data/lib/nydp/cond.rb +95 -88
- data/lib/nydp/context_symbol.rb +11 -9
- data/lib/nydp/core.rb +74 -73
- data/lib/nydp/core_ext.rb +87 -26
- data/lib/nydp/date.rb +22 -19
- data/lib/nydp/error.rb +2 -3
- data/lib/nydp/function_invocation.rb +76 -289
- data/lib/nydp/helper.rb +18 -9
- data/lib/nydp/interpreted_function.rb +159 -25
- data/lib/nydp/lexical_context.rb +9 -8
- data/lib/nydp/lexical_context_builder.rb +1 -1
- data/lib/nydp/literal.rb +3 -7
- data/lib/nydp/loop.rb +72 -0
- data/lib/nydp/namespace.rb +52 -0
- data/lib/nydp/pair.rb +146 -50
- data/lib/nydp/parser.rb +9 -11
- data/lib/nydp/plugin.rb +88 -19
- data/lib/nydp/runner.rb +141 -23
- data/lib/nydp/symbol.rb +16 -26
- data/lib/nydp/symbol_lookup.rb +3 -2
- data/lib/nydp/tokeniser.rb +1 -1
- data/lib/nydp/truth.rb +2 -37
- data/lib/nydp/version.rb +1 -1
- data/lib/nydp.rb +33 -44
- data/nydp.gemspec +2 -1
- data/spec/date_spec.rb +26 -32
- data/spec/embedded_spec.rb +22 -22
- data/spec/error_spec.rb +12 -16
- data/spec/foreign_hash_spec.rb +21 -36
- data/spec/hash_non_hash_behaviour_spec.rb +12 -29
- data/spec/hash_spec.rb +36 -49
- data/spec/literal_spec.rb +6 -6
- data/spec/nydp_spec.rb +14 -14
- data/spec/pair_spec.rb +8 -8
- data/spec/parser_spec.rb +41 -37
- data/spec/rand_spec.rb +1 -4
- data/spec/spec_helper.rb +3 -3
- data/spec/string_atom_spec.rb +15 -16
- data/spec/symbol_spec.rb +27 -52
- data/spec/thread_local_spec.rb +23 -8
- data/spec/time_spec.rb +4 -10
- data/spec/tokeniser_spec.rb +10 -10
- metadata +25 -13
- data/lib/nydp/builtin/modulo.rb +0 -11
- data/lib/nydp/builtin/regexp.rb +0 -7
- data/lib/nydp/builtin/sqrt.rb +0 -7
- data/lib/nydp/builtin/string_pad_left.rb +0 -7
- data/lib/nydp/builtin/string_pad_right.rb +0 -7
- data/lib/nydp/hash.rb +0 -9
- data/lib/nydp/image_store.rb +0 -21
- data/lib/nydp/vm.rb +0 -129
|
@@ -1,42 +1,29 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
|
-
describe
|
|
4
|
-
let(:vm) { Nydp::VM.new(ns) }
|
|
3
|
+
describe ::Hash do
|
|
5
4
|
|
|
6
5
|
describe "friendly non-hashes" do
|
|
7
6
|
let(:ahash) { TestThing.new 123, "hello there", "private" }
|
|
8
7
|
|
|
9
8
|
describe "hash get" do
|
|
10
9
|
it "returns a plain number" do
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Nydp::Builtin::HashGet.instance.invoke vm, pair_list(args)
|
|
15
|
-
expect(vm.args.pop).to eq 123
|
|
10
|
+
a = Nydp::Builtin::HashGet.instance.call ahash, :a
|
|
11
|
+
expect(a).to eq 123
|
|
16
12
|
end
|
|
17
13
|
|
|
18
14
|
it "converts ruby value to nydp value" do
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
Nydp::Builtin::HashGet.instance.invoke vm, pair_list(args)
|
|
23
|
-
expect(vm.args.pop).to eq "hello there"
|
|
15
|
+
a = Nydp::Builtin::HashGet.instance.call ahash, :b
|
|
16
|
+
expect(a).to eq "hello there"
|
|
24
17
|
end
|
|
25
18
|
|
|
26
19
|
it "converts string keys to method names" do
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Nydp::Builtin::HashGet.instance.invoke vm, pair_list(args)
|
|
31
|
-
expect(vm.args.pop).to eq "hello there"
|
|
20
|
+
a = Nydp::Builtin::HashGet.instance.call ahash, "b"
|
|
21
|
+
expect(a).to eq "hello there"
|
|
32
22
|
end
|
|
33
23
|
|
|
34
24
|
it "returns nil for unavailable methods" do
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
Nydp::Builtin::HashGet.instance.invoke vm, pair_list(args)
|
|
39
|
-
expect(vm.args.pop).to eq Nydp::NIL
|
|
25
|
+
a = Nydp::Builtin::HashGet.instance.call ahash, :c
|
|
26
|
+
expect(a).to eq Nydp::NIL
|
|
40
27
|
end
|
|
41
28
|
end
|
|
42
29
|
end
|
|
@@ -50,12 +37,11 @@ describe Nydp::Hash do
|
|
|
50
37
|
|
|
51
38
|
describe "hash set" do
|
|
52
39
|
it "does nothing, returns its value" do
|
|
53
|
-
k =
|
|
40
|
+
k = :keysym
|
|
54
41
|
v = "foobar"
|
|
55
|
-
args = pair_list [ahash, k, v]
|
|
56
42
|
|
|
57
43
|
begin
|
|
58
|
-
Nydp::Builtin::HashSet.instance.
|
|
44
|
+
Nydp::Builtin::HashSet.instance.call ahash, k, v
|
|
59
45
|
rescue StandardError => e
|
|
60
46
|
error = e
|
|
61
47
|
end
|
|
@@ -72,11 +58,8 @@ with args
|
|
|
72
58
|
|
|
73
59
|
describe "hash get" do
|
|
74
60
|
it "converts ruby value to nydp value" do
|
|
75
|
-
k = Nydp::Symbol.mk "keysym", ns
|
|
76
|
-
args = [ ahash, k ]
|
|
77
|
-
|
|
78
61
|
begin
|
|
79
|
-
Nydp::Builtin::HashGet.instance.
|
|
62
|
+
Nydp::Builtin::HashGet.instance.call ahash, :keysym
|
|
80
63
|
rescue StandardError => e
|
|
81
64
|
error = e
|
|
82
65
|
end
|
data/spec/hash_spec.rb
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
|
-
describe
|
|
4
|
-
|
|
5
|
-
let(:vm) { Nydp::VM.new(ns) }
|
|
3
|
+
describe ::Hash do
|
|
6
4
|
|
|
7
5
|
describe "#to_ruby" do
|
|
8
6
|
it "converts ruby symbol key to nydp symbol key" do
|
|
9
|
-
hash =
|
|
7
|
+
hash = ::Hash.new
|
|
10
8
|
hash[sym "boo"] = 42
|
|
11
9
|
|
|
12
10
|
rhash = hash.to_ruby
|
|
@@ -15,7 +13,7 @@ describe Nydp::Hash do
|
|
|
15
13
|
end
|
|
16
14
|
|
|
17
15
|
it "converts ruby string key to nydp string key" do
|
|
18
|
-
hash =
|
|
16
|
+
hash = ::Hash.new
|
|
19
17
|
hash["boo"] = 42
|
|
20
18
|
|
|
21
19
|
rhash = hash.to_ruby
|
|
@@ -24,7 +22,7 @@ describe Nydp::Hash do
|
|
|
24
22
|
end
|
|
25
23
|
|
|
26
24
|
it "uses integer keys unconverted" do
|
|
27
|
-
hash =
|
|
25
|
+
hash = ::Hash.new
|
|
28
26
|
hash[21] = 42
|
|
29
27
|
|
|
30
28
|
rhash = hash.to_ruby
|
|
@@ -35,7 +33,6 @@ describe Nydp::Hash do
|
|
|
35
33
|
|
|
36
34
|
describe "hash merge" do
|
|
37
35
|
it "merges two hashes" do
|
|
38
|
-
ns = { }
|
|
39
36
|
Nydp.setup(ns)
|
|
40
37
|
hash_0 = { foo: 12, bar: 34}
|
|
41
38
|
hash_1 = { foo: 49, zap: 87}
|
|
@@ -49,120 +46,110 @@ describe Nydp::Hash do
|
|
|
49
46
|
describe "nydp hashes" do
|
|
50
47
|
describe "new hash" do
|
|
51
48
|
it "returns a new Nydp hash" do
|
|
52
|
-
Nydp::Builtin::Hash.instance.
|
|
53
|
-
h
|
|
54
|
-
expect(h).to be_a Nydp::Hash
|
|
49
|
+
h = Nydp::Builtin::Hash.instance.call
|
|
50
|
+
expect(h).to be_a ::Hash
|
|
55
51
|
end
|
|
56
52
|
end
|
|
57
53
|
|
|
58
54
|
describe "hash set" do
|
|
59
55
|
it "sets a value on a hash" do
|
|
60
|
-
h =
|
|
61
|
-
|
|
62
|
-
v = 42
|
|
63
|
-
args = Nydp::Pair.from_list([h, k, v])
|
|
64
|
-
Nydp::Builtin::HashSet.instance.invoke vm, args
|
|
56
|
+
h = ::Hash.new
|
|
57
|
+
a = Nydp::Builtin::HashSet.instance.call h, :keysym, 42
|
|
65
58
|
|
|
66
|
-
expect(h.keys). to eq [
|
|
67
|
-
expect(h[
|
|
68
|
-
expect(
|
|
59
|
+
expect(h.keys). to eq [:keysym]
|
|
60
|
+
expect(h[:keysym]).to eq 42
|
|
61
|
+
expect(a). to eq 42
|
|
69
62
|
end
|
|
70
63
|
end
|
|
71
64
|
|
|
72
65
|
describe "hash get" do
|
|
73
66
|
it "gets a value from a hash" do
|
|
74
|
-
h =
|
|
75
|
-
k =
|
|
67
|
+
h = ::Hash.new
|
|
68
|
+
k = :keysym
|
|
76
69
|
v = 42
|
|
77
70
|
h[k] = v
|
|
78
71
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
expect(vm.args.pop).to eq v
|
|
72
|
+
a = Nydp::Builtin::HashGet.instance.call h, k
|
|
73
|
+
expect(a).to eq v
|
|
82
74
|
end
|
|
83
75
|
end
|
|
84
76
|
|
|
85
77
|
describe "key?" do
|
|
86
78
|
it "returns t when key is present" do
|
|
87
|
-
h =
|
|
79
|
+
h = ::Hash.new
|
|
88
80
|
k = sym "jerry"
|
|
89
81
|
v = 42
|
|
90
82
|
h[k] = v
|
|
91
83
|
|
|
92
|
-
Nydp::Builtin::HashKeyPresent.instance.
|
|
84
|
+
a = Nydp::Builtin::HashKeyPresent.instance.call h, k
|
|
93
85
|
|
|
94
|
-
expect(
|
|
86
|
+
expect(a).to eq true
|
|
95
87
|
end
|
|
96
88
|
|
|
97
89
|
it "returns nil when key is absent" do
|
|
98
|
-
h =
|
|
90
|
+
h = ::Hash.new
|
|
99
91
|
k = sym "benjamin"
|
|
100
92
|
|
|
101
|
-
Nydp::Builtin::HashKeyPresent.instance.
|
|
93
|
+
a = Nydp::Builtin::HashKeyPresent.instance.call h, k
|
|
102
94
|
|
|
103
|
-
expect(
|
|
95
|
+
expect(a).to eq nil
|
|
104
96
|
end
|
|
105
97
|
end
|
|
106
98
|
|
|
107
99
|
describe "hash keys" do
|
|
108
100
|
it "returns a list of keys" do
|
|
109
|
-
h =
|
|
101
|
+
h = ::Hash.new
|
|
110
102
|
h[sym "k0"] = 42
|
|
111
103
|
h[sym "k1"] = 84
|
|
112
104
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
expect(vm.args.pop).to eq pair_list [sym("k0"), sym("k1")]
|
|
105
|
+
a = Nydp::Builtin::HashKeys.instance.call h
|
|
106
|
+
expect(a).to eq pair_list [sym("k0"), sym("k1")]
|
|
116
107
|
end
|
|
117
108
|
end
|
|
118
109
|
end
|
|
119
110
|
|
|
120
111
|
describe "get/set nil" do
|
|
121
|
-
let(:ahash) {
|
|
112
|
+
let(:ahash) { nil }
|
|
122
113
|
|
|
123
114
|
describe "hash set" do
|
|
124
115
|
it "does nothing, returns its value" do
|
|
125
|
-
k =
|
|
116
|
+
k = :keysym
|
|
126
117
|
v = "foobar"
|
|
127
|
-
|
|
128
|
-
Nydp::Builtin::HashSet.instance.invoke vm, args
|
|
118
|
+
a = Nydp::Builtin::HashSet.instance.call ahash, k, v
|
|
129
119
|
|
|
130
|
-
expect(ahash). to eq
|
|
131
|
-
expect(
|
|
120
|
+
expect(ahash). to eq nil
|
|
121
|
+
expect(a). to eq v
|
|
132
122
|
end
|
|
133
123
|
end
|
|
134
124
|
|
|
135
125
|
describe "hash get" do
|
|
136
126
|
it "converts ruby value to nydp value" do
|
|
137
|
-
k =
|
|
138
|
-
args = [ ahash, k ]
|
|
127
|
+
k = :keysym
|
|
139
128
|
|
|
140
|
-
Nydp::Builtin::HashGet.instance.
|
|
129
|
+
a = Nydp::Builtin::HashGet.instance.call ahash, k
|
|
141
130
|
|
|
142
|
-
expect(
|
|
131
|
+
expect(a).to eq nil
|
|
143
132
|
end
|
|
144
133
|
end
|
|
145
134
|
end
|
|
146
135
|
|
|
147
136
|
describe "hash-slice" do
|
|
148
137
|
it "returns a new hash containing only the given keys from the old hash" do
|
|
149
|
-
hash =
|
|
138
|
+
hash = ::Hash.new
|
|
150
139
|
sfoo = sym "foo"
|
|
151
140
|
sbar = sym "bar"
|
|
152
141
|
syak = sym "yak"
|
|
153
142
|
szeb = sym "zeb"
|
|
154
143
|
|
|
155
|
-
h =
|
|
144
|
+
h = ::Hash.new
|
|
156
145
|
|
|
157
146
|
h[sfoo] = 16
|
|
158
147
|
h[sbar] = 42
|
|
159
148
|
h[szeb] = 99
|
|
160
149
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
Nydp::Builtin::HashSlice.instance.invoke vm, pair_list(args)
|
|
150
|
+
a = Nydp::Builtin::HashSlice.instance.call h, pair_list([sbar, syak, szeb])
|
|
164
151
|
|
|
165
|
-
expect(
|
|
152
|
+
expect(a).to eq({ sbar => 42, szeb => 99 })
|
|
166
153
|
end
|
|
167
154
|
end
|
|
168
155
|
end
|
data/spec/literal_spec.rb
CHANGED
|
@@ -2,28 +2,28 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe Nydp::Literal do
|
|
4
4
|
it "returns a ruby symbol in #to_ruby" do
|
|
5
|
-
sym =
|
|
5
|
+
sym = :foo
|
|
6
6
|
lit = Nydp::Literal.new sym
|
|
7
7
|
expect(lit.to_ruby).to eq :foo
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
describe "t" do
|
|
11
11
|
it "is #true in ruby" do
|
|
12
|
-
expect(
|
|
12
|
+
expect(true.to_ruby).to eq true
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
describe "nil" do
|
|
17
17
|
it "is #nil in ruby" do
|
|
18
|
-
expect(
|
|
18
|
+
expect(nil.to_ruby).to eq nil
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
describe "false" do
|
|
23
23
|
it "is stored in toplevel namespace" do
|
|
24
|
-
Nydp::
|
|
25
|
-
|
|
26
|
-
expect(
|
|
24
|
+
false_ns = Nydp::Namespace.new
|
|
25
|
+
Nydp::Core.new.setup false_ns
|
|
26
|
+
expect(false_ns.ns_false).to eq false
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
data/spec/nydp_spec.rb
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Nydp do
|
|
4
|
-
let(:parser) { Nydp.new_parser
|
|
5
|
-
let(:vm) { Nydp::VM.new(ns) }
|
|
4
|
+
let(:parser) { Nydp.new_parser }
|
|
6
5
|
|
|
7
6
|
def run txt
|
|
8
7
|
Nydp.setup ns
|
|
@@ -14,7 +13,7 @@ describe Nydp do
|
|
|
14
13
|
end
|
|
15
14
|
|
|
16
15
|
it "should make a symbol from a string" do
|
|
17
|
-
expect(run '(sym "the-family")').to eq
|
|
16
|
+
expect(run '(sym "the-family")').to eq :"the-family"
|
|
18
17
|
end
|
|
19
18
|
|
|
20
19
|
it "should sum integers" do
|
|
@@ -83,16 +82,17 @@ describe Nydp do
|
|
|
83
82
|
expect(result).to eq 100
|
|
84
83
|
end
|
|
85
84
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
85
|
+
# no longer true or meaningful, nydp stack is implemented on top of ruby stack now, unlimited recursion is no longer available by default
|
|
86
|
+
# it "should recurse without consuming extra memory" do
|
|
87
|
+
# program = "(assign f1 (fn (x acc)
|
|
88
|
+
# (cond (< x 1)
|
|
89
|
+
# (vm-info)
|
|
90
|
+
# (f1 (- x 1)
|
|
91
|
+
# (+ x acc)))))
|
|
92
|
+
# (f1 1000 0)"
|
|
93
|
+
# expected = parse "((contexts . 0) (instructions . 0) (args . 0))"
|
|
94
|
+
# expect(run program).to eq expected
|
|
95
|
+
# end
|
|
96
96
|
|
|
97
97
|
describe :cond do
|
|
98
98
|
it "should execute false conditionals" do
|
|
@@ -115,7 +115,7 @@ describe Nydp do
|
|
|
115
115
|
|
|
116
116
|
describe "proc from ruby object" do
|
|
117
117
|
it "invokes a proc like a builtin function" do
|
|
118
|
-
|
|
118
|
+
ns.ns_tt = TestThing.new(42, 720, 9699690)
|
|
119
119
|
|
|
120
120
|
one_thing = run "((hash-get tt 'one_thing) 24)"
|
|
121
121
|
expect(one_thing).to eq(42 + 24)
|
data/spec/pair_spec.rb
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
3
|
describe Nydp::Pair do
|
|
4
|
-
let(:a) {
|
|
5
|
-
let(:b) {
|
|
6
|
-
let(:c) {
|
|
7
|
-
let(:d) {
|
|
8
|
-
let(:foo) {
|
|
9
|
-
let(:dot) {
|
|
4
|
+
let(:a) { :a }
|
|
5
|
+
let(:b) { :b }
|
|
6
|
+
let(:c) { :c }
|
|
7
|
+
let(:d) { :d }
|
|
8
|
+
let(:foo) { :foo }
|
|
9
|
+
let(:dot) { ".".to_sym }
|
|
10
10
|
|
|
11
11
|
describe "#map" do
|
|
12
12
|
it "behaves like ruby #map" do
|
|
13
13
|
list = pair_list [1,2,3]
|
|
14
14
|
mapped = list.map { |x| x * 2 }
|
|
15
|
-
expect(mapped).to eq [2,4,6]
|
|
15
|
+
expect(mapped).to eq pair_list([2,4,6])
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
@@ -28,7 +28,7 @@ describe Nydp::Pair do
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
it "is false for (nil) == nil" do
|
|
31
|
-
expect(Nydp::Pair.from_list([
|
|
31
|
+
expect(Nydp::Pair.from_list([nil]) == nil).to eq false
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
it "should be true for nested empty lists" do
|
data/spec/parser_spec.rb
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Nydp::Parser do
|
|
4
|
-
let(:empty) {
|
|
5
|
-
let(:aa) {
|
|
6
|
-
let(:a) {
|
|
7
|
-
let(:b) {
|
|
8
|
-
let(:c) {
|
|
9
|
-
let(:d) {
|
|
10
|
-
let(:zz) {
|
|
11
|
-
let(:foo) {
|
|
12
|
-
let(:bar) {
|
|
13
|
-
let(:foobar) {
|
|
14
|
-
let(:zab) {
|
|
15
|
-
let(:quote) {
|
|
16
|
-
let(:quasiquote) {
|
|
17
|
-
let(:unquote) {
|
|
18
|
-
let(:prefix_list) {
|
|
19
|
-
let(:unquote_splicing) {
|
|
20
|
-
let(:comment) {
|
|
21
|
-
let(:dotsyn) {
|
|
22
|
-
let(:cocosyn) {
|
|
23
|
-
let(:colosyn) {
|
|
24
|
-
let(:atsyn) {
|
|
25
|
-
let(:string_pieces) {
|
|
4
|
+
let(:empty) { :"" }
|
|
5
|
+
let(:aa) { :aa }
|
|
6
|
+
let(:a) { :a }
|
|
7
|
+
let(:b) { :b }
|
|
8
|
+
let(:c) { :c }
|
|
9
|
+
let(:d) { :d }
|
|
10
|
+
let(:zz) { :zz }
|
|
11
|
+
let(:foo) { :foo }
|
|
12
|
+
let(:bar) { :bar }
|
|
13
|
+
let(:foobar) { :foobar }
|
|
14
|
+
let(:zab) { :zab }
|
|
15
|
+
let(:quote) { :quote }
|
|
16
|
+
let(:quasiquote) { :quasiquote }
|
|
17
|
+
let(:unquote) { :unquote }
|
|
18
|
+
let(:prefix_list) { :"prefix-list" }
|
|
19
|
+
let(:unquote_splicing) { :"unquote-splicing" }
|
|
20
|
+
let(:comment) { :comment }
|
|
21
|
+
let(:dotsyn) { :"dot-syntax" }
|
|
22
|
+
let(:cocosyn) { :"colon-colon-syntax" }
|
|
23
|
+
let(:colosyn) { :"colon-syntax" }
|
|
24
|
+
let(:atsyn) { :"at-syntax" }
|
|
25
|
+
let(:string_pieces) { :"string-pieces" }
|
|
26
26
|
|
|
27
27
|
it "should return a stream of tokens" do
|
|
28
|
-
reader = Nydp::StringReader.new ""
|
|
28
|
+
reader = Nydp::StringReader.new "test", ""
|
|
29
29
|
t = Nydp.new_tokeniser reader
|
|
30
30
|
expect(t.next_token).to eq nil
|
|
31
31
|
end
|
|
@@ -49,6 +49,10 @@ describe Nydp::Parser do
|
|
|
49
49
|
expect(parse "(|foo bar| || |\" hello, there, silly billy!\"|)").to eq pair_list([s0, s1, s2])
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
+
it "returns ruby nil for token nil" do
|
|
53
|
+
expect(parse "(nil nil nil)").to eq pair_list([nil, nil, nil])
|
|
54
|
+
end
|
|
55
|
+
|
|
52
56
|
it "should parse untidy symbols with special syntax" do
|
|
53
57
|
quote_foo_bar = parse "'|foo bar|"
|
|
54
58
|
expect(quote_foo_bar).to eq pair_list([quote, sym("foo bar")])
|
|
@@ -139,15 +143,15 @@ describe Nydp::Parser do
|
|
|
139
143
|
|
|
140
144
|
it "should spot numbers hiding in special syntax" do
|
|
141
145
|
parsed = parse("foo.2:3:4")
|
|
142
|
-
expect(parsed.
|
|
146
|
+
expect(parsed._nydp_inspect).to eq "(colon-syntax (dot-syntax foo 2) 3 4)"
|
|
143
147
|
|
|
144
|
-
expect(parsed.map &:class).to eq [
|
|
145
|
-
expect(parsed.cdr.car.map &:class).to eq [
|
|
148
|
+
expect(parsed.map &:class).to eq pair_list([::Symbol, Nydp::Pair, Integer, Integer])
|
|
149
|
+
expect(parsed.cdr.car.map &:class).to eq pair_list([::Symbol, ::Symbol, Integer])
|
|
146
150
|
end
|
|
147
151
|
|
|
148
152
|
it "should handle prefix and postfix syntax also" do
|
|
149
153
|
parsed = parse(".foo123:")
|
|
150
|
-
expect(parsed.
|
|
154
|
+
expect(parsed._nydp_inspect).to eq "(colon-syntax (dot-syntax || foo123) ||)"
|
|
151
155
|
end
|
|
152
156
|
|
|
153
157
|
it "should parse a dotted symbol" do
|
|
@@ -199,7 +203,7 @@ describe Nydp::Parser do
|
|
|
199
203
|
end
|
|
200
204
|
|
|
201
205
|
it "should unquote-unquote_splicing symbols" do
|
|
202
|
-
expect(parse(",,@foo").
|
|
206
|
+
expect(parse(",,@foo")._nydp_inspect).to eq "(unquote (unquote-splicing foo))"
|
|
203
207
|
end
|
|
204
208
|
|
|
205
209
|
it "should quote lists" do
|
|
@@ -219,21 +223,21 @@ describe Nydp::Parser do
|
|
|
219
223
|
end
|
|
220
224
|
|
|
221
225
|
it "should do some complicated unquote stuff with lists" do
|
|
222
|
-
expect(parse("`(a b `(c d ,(+ 1 2) ,,(+ 3 4)))").
|
|
226
|
+
expect(parse("`(a b `(c d ,(+ 1 2) ,,(+ 3 4)))")._nydp_inspect).to eq "(quasiquote (a b (quasiquote (c d (unquote (+ 1 2)) (unquote (unquote (+ 3 4)))))))"
|
|
223
227
|
end
|
|
224
228
|
|
|
225
229
|
it "should do some complicated unquote stuff with mixed lists and symbols" do
|
|
226
|
-
expect(parse("`(a b `(c d ,,@foo e f))").
|
|
227
|
-
expect(parse("`(a b `(c d ,@,foo e f))").
|
|
228
|
-
expect(parse("`(a b `(c d ,',foo e f))").
|
|
230
|
+
expect(parse("`(a b `(c d ,,@foo e f))")._nydp_inspect).to eq "(quasiquote (a b (quasiquote (c d (unquote (unquote-splicing foo)) e f))))"
|
|
231
|
+
expect(parse("`(a b `(c d ,@,foo e f))")._nydp_inspect).to eq "(quasiquote (a b (quasiquote (c d (unquote-splicing (unquote foo)) e f))))"
|
|
232
|
+
expect(parse("`(a b `(c d ,',foo e f))")._nydp_inspect).to eq "(quasiquote (a b (quasiquote (c d (unquote (quote (unquote foo))) e f))))"
|
|
229
233
|
end
|
|
230
234
|
|
|
231
235
|
it "should do some complicated unquote stuff with lists" do
|
|
232
|
-
expect(parse("`(a b `(c d ,(+ 1 2) ,,@(list 3 4)))").
|
|
236
|
+
expect(parse("`(a b `(c d ,(+ 1 2) ,,@(list 3 4)))")._nydp_inspect).to eq "(quasiquote (a b (quasiquote (c d (unquote (+ 1 2)) (unquote (unquote-splicing (list 3 4)))))))"
|
|
233
237
|
end
|
|
234
238
|
|
|
235
239
|
it "should do some complicated unquote stuff with symbols" do
|
|
236
|
-
expect(parse("`(a b `(c d ,(+ 1 2) ,,x))").
|
|
240
|
+
expect(parse("`(a b `(c d ,(+ 1 2) ,,x))")._nydp_inspect).to eq "(quasiquote (a b (quasiquote (c d (unquote (+ 1 2)) (unquote (unquote x))))))"
|
|
237
241
|
end
|
|
238
242
|
|
|
239
243
|
it "should unquote-splicing atoms" do
|
|
@@ -294,8 +298,8 @@ describe Nydp::Parser do
|
|
|
294
298
|
"
|
|
295
299
|
c1 = pair_list([comment, "here's a comment"])
|
|
296
300
|
fbar = pair_list([bar])
|
|
297
|
-
fzab = pair_list([
|
|
298
|
-
fdef =
|
|
301
|
+
fzab = pair_list([:zab])
|
|
302
|
+
fdef = :def
|
|
299
303
|
expr = pair_list([fdef, foo, fbar, c1, fzab])
|
|
300
304
|
expect(parse txt).to eq expr
|
|
301
305
|
end
|
|
@@ -304,7 +308,7 @@ describe Nydp::Parser do
|
|
|
304
308
|
txt = <<NYDP
|
|
305
309
|
(def plugin-end (name) (assign this-plugin nil ) (chapter-end))
|
|
306
310
|
NYDP
|
|
307
|
-
expect(parse(txt).to_a.
|
|
311
|
+
expect(parse(txt).to_a._nydp_inspect).to eq "[def plugin-end (name) (assign this-plugin nil) (chapter-end)]"
|
|
308
312
|
end
|
|
309
313
|
|
|
310
314
|
it "parses a more complete expression" do
|
data/spec/rand_spec.rb
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
3
|
describe Nydp::Builtin::Rand do
|
|
4
|
-
let(:vm) { Nydp::VM.new(ns) }
|
|
5
|
-
|
|
6
4
|
let(:randf) { Nydp::Builtin::Rand.instance }
|
|
7
5
|
|
|
8
6
|
def get_rand *args
|
|
9
|
-
randf.
|
|
10
|
-
vm.pop_args(1).first
|
|
7
|
+
randf.call *args
|
|
11
8
|
end
|
|
12
9
|
|
|
13
10
|
describe "zero args" do
|
data/spec/spec_helper.rb
CHANGED
|
@@ -3,11 +3,11 @@ require 'nydp/symbol'
|
|
|
3
3
|
|
|
4
4
|
module SpecHelper
|
|
5
5
|
def sym name
|
|
6
|
-
|
|
6
|
+
name.to_s.to_sym
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def parse txt
|
|
10
|
-
Nydp.new_parser
|
|
10
|
+
Nydp.new_parser.expression(Nydp.new_tokeniser Nydp::StringReader.new("test", txt))
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def pair_list xs, last=Nydp::NIL
|
|
@@ -15,7 +15,7 @@ module SpecHelper
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def self.included base
|
|
18
|
-
base.let(:ns) {
|
|
18
|
+
base.let(:ns) { Nydp::Namespace.new }
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
data/spec/string_atom_spec.rb
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
3
|
describe Nydp::StringAtom do
|
|
4
|
-
let(:bar) {
|
|
5
|
-
let(:foo) {
|
|
6
|
-
let(:vm) { Nydp::VM.new(ns) }
|
|
4
|
+
let(:bar) { "BAR" }
|
|
5
|
+
let(:foo) { "FOO" }
|
|
7
6
|
|
|
8
7
|
it "is not equal to a symbol with the same represenation" do
|
|
9
|
-
string =
|
|
10
|
-
symbol =
|
|
11
|
-
compare =
|
|
8
|
+
string = "harrypotter"
|
|
9
|
+
symbol = :harrypotter
|
|
10
|
+
compare = symbol.to_s
|
|
12
11
|
expect(string == compare).to eq true
|
|
13
12
|
expect(string == symbol) .to eq false
|
|
14
13
|
end
|
|
15
14
|
|
|
16
15
|
it "is not equal to a list with the same represenation" do
|
|
17
|
-
string =
|
|
16
|
+
string = '("FOO" "BAR")'
|
|
18
17
|
list = Nydp::Pair.from_list [foo, bar]
|
|
19
|
-
compare =
|
|
18
|
+
compare = list.to_s
|
|
20
19
|
expect(string == compare).to eq true
|
|
21
20
|
expect(string == list) .to eq false
|
|
22
21
|
end
|
|
@@ -30,32 +29,32 @@ describe Nydp::StringAtom do
|
|
|
30
29
|
it "works with builtin greater-than when true" do
|
|
31
30
|
f = Nydp::Builtin::GreaterThan.instance
|
|
32
31
|
|
|
33
|
-
f.
|
|
32
|
+
a = f.call foo, bar
|
|
34
33
|
|
|
35
|
-
expect(
|
|
34
|
+
expect(a).to eq bar
|
|
36
35
|
end
|
|
37
36
|
|
|
38
37
|
it "works with builtin greater-than when false" do
|
|
39
38
|
f = Nydp::Builtin::GreaterThan.instance
|
|
40
39
|
|
|
41
|
-
f.
|
|
40
|
+
a = f.call bar, foo
|
|
42
41
|
|
|
43
|
-
expect(
|
|
42
|
+
expect(a).to eq Nydp::NIL
|
|
44
43
|
end
|
|
45
44
|
|
|
46
45
|
it "works with builtin less-than when true" do
|
|
47
46
|
f = Nydp::Builtin::LessThan.instance
|
|
48
47
|
|
|
49
|
-
f.
|
|
48
|
+
a = f.call bar, foo
|
|
50
49
|
|
|
51
|
-
expect(
|
|
50
|
+
expect(a).to eq foo
|
|
52
51
|
end
|
|
53
52
|
|
|
54
53
|
it "works with builtin less-than when false" do
|
|
55
54
|
f = Nydp::Builtin::LessThan.instance
|
|
56
55
|
|
|
57
|
-
f.
|
|
56
|
+
a = f.call foo, bar
|
|
58
57
|
|
|
59
|
-
expect(
|
|
58
|
+
expect(a).to eq Nydp::NIL
|
|
60
59
|
end
|
|
61
60
|
end
|