nydp 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- 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 +30 -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 +88 -24
- 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
data/spec/symbol_spec.rb
CHANGED
@@ -1,108 +1,83 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Nydp::Symbol 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
|
describe "#inspect" do
|
9
8
|
it "wraps itself in pipe chars if empty" do
|
10
|
-
sym =
|
11
|
-
expect(sym.
|
9
|
+
sym = :""
|
10
|
+
expect(sym._nydp_inspect).to eq "||"
|
12
11
|
end
|
13
12
|
it "wraps itself in pipe chars if nil" do
|
14
|
-
sym =
|
15
|
-
expect(sym.
|
13
|
+
sym = nil.to_s.to_sym
|
14
|
+
expect(sym._nydp_inspect).to eq "||"
|
16
15
|
end
|
17
16
|
it "wraps itself in pipe chars if it has spaces" do
|
18
|
-
sym =
|
19
|
-
expect(sym.
|
17
|
+
sym = :"hello world"
|
18
|
+
expect(sym._nydp_inspect).to eq "|hello world|"
|
20
19
|
end
|
21
20
|
it "wraps itself in pipe chars if it has pipe chars" do
|
22
|
-
sym =
|
23
|
-
expect(sym.
|
21
|
+
sym = :"hello|world"
|
22
|
+
expect(sym._nydp_inspect).to eq '|hello\|world|'
|
24
23
|
end
|
25
24
|
it "wraps itself in pipe chars if it contains quote chars" do
|
26
|
-
sym =
|
27
|
-
expect(sym.
|
25
|
+
sym = :"hello 'world'"
|
26
|
+
expect(sym._nydp_inspect).to eq "|hello 'world'|"
|
28
27
|
end
|
29
28
|
it "wraps itself in pipe chars if it contains doublequote chars" do
|
30
|
-
sym =
|
31
|
-
expect(sym.
|
29
|
+
sym = :'hello "world"'
|
30
|
+
expect(sym._nydp_inspect).to eq '|hello "world"|'
|
32
31
|
end
|
33
32
|
it "wraps itself in pipe chars if it has other punctuation" do
|
34
|
-
sym =
|
35
|
-
expect(sym.
|
33
|
+
sym = :'hello,(world)'
|
34
|
+
expect(sym._nydp_inspect).to eq '|hello,(world)|'
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
|
-
it "returns a ruby symbol in #to_ruby" do
|
40
|
-
sym = Nydp::Symbol.mk :foo, ns
|
41
|
-
expect(sym.to_ruby).to eq :foo
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should not recognise an unknown symbol" do
|
45
|
-
sym = Nydp::Symbol.find :foo, ns
|
46
|
-
expect(sym).to eq nil
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should create a new symbol" do
|
50
|
-
sym = Nydp::Symbol.mk :foo, ns
|
51
|
-
expect(sym.name).to eq :foo
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should not create a new symbol when the symbol already exists" do
|
55
|
-
sym1 = Nydp::Symbol.mk :baz, ns
|
56
|
-
sym2 = Nydp::Symbol.mk :baz, ns
|
57
|
-
|
58
|
-
expect(sym1).to eq sym2
|
59
|
-
expect(sym1).to equal sym2
|
60
|
-
end
|
61
|
-
|
62
38
|
it "should consider symbols == when they share the same name" do
|
63
39
|
ns1 = { }
|
64
40
|
ns2 = { }
|
65
41
|
|
66
|
-
sym1 =
|
67
|
-
sym2 =
|
42
|
+
sym1 = :baz
|
43
|
+
sym2 = :baz
|
68
44
|
|
69
45
|
expect(sym1.hash).to eq sym2.hash
|
70
46
|
|
71
47
|
expect(sym1 == sym2).to eq true
|
72
48
|
expect(sym1.eql? sym2).to eq true
|
73
|
-
expect(sym1.equal? sym2).to eq
|
49
|
+
expect(sym1.equal? sym2).to eq true
|
74
50
|
end
|
75
51
|
|
76
52
|
it "works with builtin greater-than when true" do
|
77
53
|
f = Nydp::Builtin::GreaterThan.instance
|
78
54
|
|
79
|
-
f.
|
55
|
+
a = f.call foo, bar
|
80
56
|
|
81
|
-
expect(
|
57
|
+
expect(a).to eq bar
|
82
58
|
end
|
83
59
|
|
84
60
|
it "works with builtin greater-than when false" do
|
85
61
|
f = Nydp::Builtin::GreaterThan.instance
|
86
62
|
|
87
|
-
f.
|
63
|
+
a = f.call bar, foo
|
88
64
|
|
89
|
-
expect(
|
65
|
+
expect(a).to eq Nydp::NIL
|
90
66
|
end
|
91
67
|
|
92
68
|
it "works with builtin less-than when true" do
|
93
69
|
f = Nydp::Builtin::LessThan.instance
|
94
70
|
|
95
|
-
f.
|
71
|
+
a = f.call bar, foo
|
96
72
|
|
97
|
-
expect(
|
73
|
+
expect(a).to eq foo
|
98
74
|
end
|
99
75
|
|
100
76
|
it "works with builtin less-than when false" do
|
101
77
|
f = Nydp::Builtin::LessThan.instance
|
102
78
|
|
103
|
-
f.
|
79
|
+
a = f.call foo, bar
|
104
80
|
|
105
|
-
expect(
|
81
|
+
expect(a).to eq Nydp::NIL
|
106
82
|
end
|
107
|
-
|
108
83
|
end
|
data/spec/thread_local_spec.rb
CHANGED
@@ -1,21 +1,36 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Nydp do
|
4
|
-
def run
|
5
|
-
Nydp::Runner.new(
|
4
|
+
def run txt
|
5
|
+
Nydp::Runner.new(ns, Nydp::StringReader.new("test", txt)).run
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should isolate threadlocal values" do
|
9
|
+
|
10
|
+
# note : this test is mostly on principle, it can't guarantee
|
11
|
+
# correctness insofar as it doesn't guarantee that the threads
|
12
|
+
# run in a way such that they would interfere with each other
|
13
|
+
# if thread_locals were not used...
|
14
|
+
|
9
15
|
Nydp.setup ns
|
10
16
|
|
11
|
-
vm0 = Nydp::VM.new ns
|
12
|
-
vm1 = Nydp::VM.new ns
|
13
17
|
|
14
|
-
|
15
|
-
|
18
|
+
t0 = Thread.new {
|
19
|
+
run "(hash-set (thread-locals) 'testing (+ 1 2 3))"
|
20
|
+
sleep 0.1
|
21
|
+
run "(hash-get (thread-locals) 'testing)"
|
22
|
+
}
|
23
|
+
|
24
|
+
t1 = Thread.new {
|
25
|
+
run "(hash-set (thread-locals) 'testing (+ 6 7 8))"
|
26
|
+
run "(hash-get (thread-locals) 'testing)"
|
27
|
+
}
|
28
|
+
|
29
|
+
t0.join
|
30
|
+
t1.join
|
16
31
|
|
17
|
-
val0 =
|
18
|
-
val1 =
|
32
|
+
val0 = t0.value
|
33
|
+
val1 = t1.value
|
19
34
|
|
20
35
|
expect(val0).to eq 6
|
21
36
|
expect(val1).to eq 21
|
data/spec/time_spec.rb
CHANGED
@@ -2,8 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Nydp::Date do
|
4
4
|
|
5
|
-
let(:ns) { { } }
|
6
|
-
let(:vm) { Nydp::VM.new(ns) }
|
7
5
|
let(:timef) { Nydp::Builtin::Time.instance }
|
8
6
|
|
9
7
|
it "r2n does not convert ruby Time" do
|
@@ -15,16 +13,14 @@ describe Nydp::Date do
|
|
15
13
|
end
|
16
14
|
|
17
15
|
it "creates a new Time instance" do
|
18
|
-
timef.
|
19
|
-
nd = vm.args.pop
|
16
|
+
nd = timef.call 2015, 11, 18, 18, 30, 17
|
20
17
|
expect(nd).to be_a Time
|
21
18
|
expect(nd).to eq Time.new(2015, 11, 18, 18, 30, 17)
|
22
19
|
end
|
23
20
|
|
24
21
|
it "creates a new Time instance for #now" do
|
25
22
|
t0 = Time.now
|
26
|
-
timef.
|
27
|
-
nd = vm.args.pop
|
23
|
+
nd = timef.call
|
28
24
|
t1 = Time.now
|
29
25
|
expect(nd).to be_a Time
|
30
26
|
expect(nd).to be_between(t0, t1)
|
@@ -32,16 +28,14 @@ describe Nydp::Date do
|
|
32
28
|
|
33
29
|
it "creates a new Time instance for #now plus offset" do
|
34
30
|
t0 = Time.now
|
35
|
-
timef.
|
36
|
-
nd = vm.args.pop
|
31
|
+
nd = timef.call 3.14
|
37
32
|
t1 = Time.now
|
38
33
|
expect(nd).to be_a Time
|
39
34
|
expect(nd).to be_between((t0 + 3.14), (t1 + 3.14))
|
40
35
|
end
|
41
36
|
|
42
37
|
it "creates a new Time instance for a given Date" do
|
43
|
-
timef.
|
44
|
-
nd = vm.args.pop
|
38
|
+
nd = timef.call Date.parse "2006-06-21"
|
45
39
|
expect(nd).to be_a Time
|
46
40
|
expect(nd).to eq Time.new(2006, 6, 21)
|
47
41
|
end
|
data/spec/tokeniser_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe "tokenising" do
|
4
4
|
it "should return another stream of tokens" do
|
5
5
|
tt = []
|
6
|
-
reader = Nydp::StringReader.new "(a b c 1 2 3)"
|
6
|
+
reader = Nydp::StringReader.new "test", "(a b c 1 2 3)"
|
7
7
|
t = Nydp::Tokeniser.new reader
|
8
8
|
tt = []
|
9
9
|
tok = t.next_token
|
@@ -22,7 +22,7 @@ describe "tokenising" do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should return a stream of tokens, including whitespace before right-paren" do
|
25
|
-
reader = Nydp::StringReader.new "foo )"
|
25
|
+
reader = Nydp::StringReader.new "test", "foo )"
|
26
26
|
t = Nydp::Tokeniser.new reader
|
27
27
|
tt = []
|
28
28
|
tok = t.next_token
|
@@ -35,33 +35,33 @@ describe "tokenising" do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it "returns nothing at all" do
|
38
|
-
s = Nydp::StringReader.new ""
|
38
|
+
s = Nydp::StringReader.new "test", ""
|
39
39
|
tkz = Nydp::Tokeniser.new s
|
40
40
|
expect(tkz.next_token).to be_nil
|
41
41
|
end
|
42
42
|
|
43
43
|
it "returns a whitespace token" do
|
44
|
-
s = Nydp::StringReader.new " "
|
44
|
+
s = Nydp::StringReader.new "test", " "
|
45
45
|
tkz = Nydp::Tokeniser.new s
|
46
46
|
expect(tkz.next_token).to be_nil
|
47
47
|
end
|
48
48
|
|
49
49
|
it "returns a symbol token" do
|
50
|
-
s = Nydp::StringReader.new "hello"
|
50
|
+
s = Nydp::StringReader.new "test", "hello"
|
51
51
|
tkz = Nydp::Tokeniser.new s
|
52
52
|
expect(tkz.next_token).to eq [:symbol, "hello"]
|
53
53
|
expect(tkz.next_token).to be_nil
|
54
54
|
end
|
55
55
|
|
56
56
|
it "returns symbol then whitespace" do
|
57
|
-
s = Nydp::StringReader.new "hello "
|
57
|
+
s = Nydp::StringReader.new "test", "hello "
|
58
58
|
tkz = Nydp::Tokeniser.new s
|
59
59
|
expect(tkz.next_token).to eq [:symbol, "hello"]
|
60
60
|
expect(tkz.next_token).to be_nil
|
61
61
|
end
|
62
62
|
|
63
63
|
it "returns whitespace symbol whitespace symbol whitespace" do
|
64
|
-
s = Nydp::StringReader.new " hello world "
|
64
|
+
s = Nydp::StringReader.new "test", " hello world "
|
65
65
|
tkz = Nydp::Tokeniser.new s
|
66
66
|
expect(tkz.next_token).to eq [:symbol, "hello"]
|
67
67
|
expect(tkz.next_token).to eq [:symbol, "world"]
|
@@ -69,7 +69,7 @@ describe "tokenising" do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it "returns whitespace left_paren symbol whitespace symbol right_paren whitespace" do
|
72
|
-
s = Nydp::StringReader.new " (hello world) "
|
72
|
+
s = Nydp::StringReader.new "test", " (hello world) "
|
73
73
|
tkz = Nydp::Tokeniser.new s
|
74
74
|
expect(tkz.next_token).to eq [:left_paren, ""]
|
75
75
|
expect(tkz.next_token).to eq [:symbol, "hello"]
|
@@ -79,7 +79,7 @@ describe "tokenising" do
|
|
79
79
|
end
|
80
80
|
|
81
81
|
it "returns whitespace left_paren with prefix symbol whitespace symbol right_paren whitespace" do
|
82
|
-
s = Nydp::StringReader.new " %w(hello world) "
|
82
|
+
s = Nydp::StringReader.new "test", " %w(hello world) "
|
83
83
|
tkz = Nydp::Tokeniser.new s
|
84
84
|
expect(tkz.next_token).to eq [:left_paren, "%w"]
|
85
85
|
expect(tkz.next_token).to eq [:symbol, "hello"]
|
@@ -89,7 +89,7 @@ describe "tokenising" do
|
|
89
89
|
end
|
90
90
|
|
91
91
|
it "returns a comment" do
|
92
|
-
s = Nydp::StringReader.new "hello
|
92
|
+
s = Nydp::StringReader.new "test", "hello
|
93
93
|
; observe!
|
94
94
|
world"
|
95
95
|
tkz = Nydp::Tokeniser.new s
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nydp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Conan Dalton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: irb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rake
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - "~>"
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
33
|
+
version: '13'
|
20
34
|
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
38
|
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
40
|
+
version: '13'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,6 +96,7 @@ files:
|
|
82
96
|
- lib/lisp/core-120-settings.nydp
|
83
97
|
- lib/lisp/core-130-validations.nydp
|
84
98
|
- lib/lisp/core-900-benchmarking.nydp
|
99
|
+
- lib/lisp/tests/000-empty-args-examples.nydp
|
85
100
|
- lib/lisp/tests/accum-examples.nydp
|
86
101
|
- lib/lisp/tests/add-hook-examples.nydp
|
87
102
|
- lib/lisp/tests/aif-examples.nydp
|
@@ -147,6 +162,7 @@ files:
|
|
147
162
|
- lib/lisp/tests/relative-months-examples.nydp
|
148
163
|
- lib/lisp/tests/returning-examples.nydp
|
149
164
|
- lib/lisp/tests/rfnwith-tests.nydp
|
165
|
+
- lib/lisp/tests/rotate-2d-array-examples.nydp
|
150
166
|
- lib/lisp/tests/seqf-examples.nydp
|
151
167
|
- lib/lisp/tests/set-difference-examples.nydp
|
152
168
|
- lib/lisp/tests/set-intersection-examples.nydp
|
@@ -181,12 +197,12 @@ files:
|
|
181
197
|
- lib/nydp/builtin/inspect.rb
|
182
198
|
- lib/nydp/builtin/is_equal.rb
|
183
199
|
- lib/nydp/builtin/less_than.rb
|
200
|
+
- lib/nydp/builtin/log.rb
|
184
201
|
- lib/nydp/builtin/math_ceiling.rb
|
185
202
|
- lib/nydp/builtin/math_floor.rb
|
186
203
|
- lib/nydp/builtin/math_power.rb
|
187
204
|
- lib/nydp/builtin/math_round.rb
|
188
205
|
- lib/nydp/builtin/minus.rb
|
189
|
-
- lib/nydp/builtin/modulo.rb
|
190
206
|
- lib/nydp/builtin/parse.rb
|
191
207
|
- lib/nydp/builtin/parse_in_string.rb
|
192
208
|
- lib/nydp/builtin/plus.rb
|
@@ -195,16 +211,13 @@ files:
|
|
195
211
|
- lib/nydp/builtin/quit.rb
|
196
212
|
- lib/nydp/builtin/rand.rb
|
197
213
|
- lib/nydp/builtin/random_string.rb
|
198
|
-
- lib/nydp/builtin/
|
214
|
+
- lib/nydp/builtin/rng.rb
|
199
215
|
- lib/nydp/builtin/ruby_wrap.rb
|
200
216
|
- lib/nydp/builtin/script_run.rb
|
201
217
|
- lib/nydp/builtin/set_intersection.rb
|
202
218
|
- lib/nydp/builtin/set_union.rb
|
203
219
|
- lib/nydp/builtin/sort.rb
|
204
|
-
- lib/nydp/builtin/sqrt.rb
|
205
220
|
- lib/nydp/builtin/string_match.rb
|
206
|
-
- lib/nydp/builtin/string_pad_left.rb
|
207
|
-
- lib/nydp/builtin/string_pad_right.rb
|
208
221
|
- lib/nydp/builtin/string_replace.rb
|
209
222
|
- lib/nydp/builtin/string_split.rb
|
210
223
|
- lib/nydp/builtin/sym.rb
|
@@ -224,13 +237,13 @@ files:
|
|
224
237
|
- lib/nydp/date.rb
|
225
238
|
- lib/nydp/error.rb
|
226
239
|
- lib/nydp/function_invocation.rb
|
227
|
-
- lib/nydp/hash.rb
|
228
240
|
- lib/nydp/helper.rb
|
229
|
-
- lib/nydp/image_store.rb
|
230
241
|
- lib/nydp/interpreted_function.rb
|
231
242
|
- lib/nydp/lexical_context.rb
|
232
243
|
- lib/nydp/lexical_context_builder.rb
|
233
244
|
- lib/nydp/literal.rb
|
245
|
+
- lib/nydp/loop.rb
|
246
|
+
- lib/nydp/namespace.rb
|
234
247
|
- lib/nydp/pair.rb
|
235
248
|
- lib/nydp/parser.rb
|
236
249
|
- lib/nydp/plugin.rb
|
@@ -243,7 +256,6 @@ files:
|
|
243
256
|
- lib/nydp/tokeniser.rb
|
244
257
|
- lib/nydp/truth.rb
|
245
258
|
- lib/nydp/version.rb
|
246
|
-
- lib/nydp/vm.rb
|
247
259
|
- lib/tasks/tests.rake
|
248
260
|
- nydp.gemspec
|
249
261
|
- spec/date_spec.rb
|
@@ -283,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
283
295
|
- !ruby/object:Gem::Version
|
284
296
|
version: '0'
|
285
297
|
requirements: []
|
286
|
-
rubygems_version: 3.0.3
|
298
|
+
rubygems_version: 3.0.3.1
|
287
299
|
signing_key:
|
288
300
|
specification_version: 4
|
289
301
|
summary: A civilised yet somewhat dangerous kind of Lisp for a new generation
|
data/lib/nydp/builtin/modulo.rb
DELETED
data/lib/nydp/builtin/regexp.rb
DELETED
data/lib/nydp/builtin/sqrt.rb
DELETED
data/lib/nydp/hash.rb
DELETED
data/lib/nydp/image_store.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'digest'
|
2
|
-
|
3
|
-
module Nydp
|
4
|
-
class ImageStore
|
5
|
-
attr_accessor :store
|
6
|
-
|
7
|
-
def initialize store=nil
|
8
|
-
@store = store
|
9
|
-
FileUtils.mkdir_p(store, mode: 0775) if store
|
10
|
-
end
|
11
|
-
|
12
|
-
def digest ; Digest::MD5.hexdigest(Nydp.all_files.map { |f| File.read f }.join) ; end
|
13
|
-
def file_name id ; File.join @store, "#{id}.nydp_image" ; end
|
14
|
-
def load? fname ; File.binread(fname) if File.exists?(fname) ; end
|
15
|
-
def load id ; load?(file_name id) if @store ; end
|
16
|
-
def store id, image ; File.open(file_name(id), "wb") { |f| f.write(image) } if @store ; end
|
17
|
-
def generate id ; Marshal.dump(::Nydp.build_nydp).tap { |im| store id, im } ; end
|
18
|
-
def resurrect id ; load(id) || generate(id) ; end
|
19
|
-
def get ; Marshal.load(@image ||= resurrect(digest)) ; end
|
20
|
-
end
|
21
|
-
end
|
data/lib/nydp/vm.rb
DELETED
@@ -1,129 +0,0 @@
|
|
1
|
-
module Nydp
|
2
|
-
class VM
|
3
|
-
NIL = Nydp::NIL
|
4
|
-
include Helper
|
5
|
-
attr_accessor :instructions, :args, :contexts, :current_context, :locals, :unhandled_error, :last_error, :ns, :thisi
|
6
|
-
|
7
|
-
module Finally ; end
|
8
|
-
module HandleError ; end
|
9
|
-
|
10
|
-
def initialize ns
|
11
|
-
@instructions = []
|
12
|
-
@args = []
|
13
|
-
@contexts = []
|
14
|
-
@locals = Nydp::Hash.new
|
15
|
-
@ns = ns
|
16
|
-
end
|
17
|
-
|
18
|
-
def push_instructions ii, ctx
|
19
|
-
if @current_instructions && NIL != @current_instructions
|
20
|
-
@instructions.push @current_instructions
|
21
|
-
@contexts.push @current_context
|
22
|
-
end
|
23
|
-
|
24
|
-
@current_instructions = ii
|
25
|
-
@current_context = ctx
|
26
|
-
end
|
27
|
-
|
28
|
-
def push_ctx_instructions ii
|
29
|
-
if @current_instructions && NIL != @current_instructions
|
30
|
-
@instructions.push @current_instructions
|
31
|
-
@contexts.push @current_context
|
32
|
-
end
|
33
|
-
|
34
|
-
@current_instructions = ii
|
35
|
-
end
|
36
|
-
|
37
|
-
def thread_with_expr expr
|
38
|
-
@current_instructions = expr
|
39
|
-
thread
|
40
|
-
end
|
41
|
-
|
42
|
-
def thread
|
43
|
-
while @current_instructions
|
44
|
-
begin
|
45
|
-
if NIL == @current_instructions
|
46
|
-
@current_instructions = @instructions.pop
|
47
|
-
@current_context = @contexts.pop
|
48
|
-
else
|
49
|
-
now = @current_instructions.car
|
50
|
-
@current_instructions = @current_instructions.cdr
|
51
|
-
now.execute(self)
|
52
|
-
end
|
53
|
-
|
54
|
-
rescue StandardError => e
|
55
|
-
handle_error e
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
if @unhandled_error
|
60
|
-
e = @unhandled_error
|
61
|
-
@unhandled_error = nil
|
62
|
-
raise e
|
63
|
-
end
|
64
|
-
|
65
|
-
args.pop
|
66
|
-
end
|
67
|
-
|
68
|
-
def handle_error ex
|
69
|
-
@unhandled_error = ex
|
70
|
-
|
71
|
-
protecti = []
|
72
|
-
protectc = []
|
73
|
-
|
74
|
-
while (@instructions.length > 0) && !(@instructions.last.car.is_a? HandleError)
|
75
|
-
if @instructions.last.car.is_a? Finally
|
76
|
-
protecti << @instructions.last
|
77
|
-
protectc << @contexts.last
|
78
|
-
end
|
79
|
-
|
80
|
-
@instructions.pop
|
81
|
-
@contexts.pop
|
82
|
-
end
|
83
|
-
|
84
|
-
while protecti.length > 0
|
85
|
-
push_instructions protecti.pop, protectc.pop
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def push_arg a ; args.push a ; end
|
90
|
-
def args! ; args.empty? ? (raise "illegal operation: no args") : args ; end
|
91
|
-
def peek_arg ; args!.last ; end
|
92
|
-
|
93
|
-
def pop_args count, tail=Nydp::NIL
|
94
|
-
case count
|
95
|
-
when 0
|
96
|
-
tail
|
97
|
-
else
|
98
|
-
pop_args(count - 1, cons(args.pop, tail))
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def vm_info
|
103
|
-
msg = ""
|
104
|
-
msg << "\n"
|
105
|
-
msg << "\ninstruction stack"
|
106
|
-
msg << "\n================="
|
107
|
-
instructions.each_with_index do |ii, ix|
|
108
|
-
msg << "\ninstructions##{ix} : #{ii} #{ii.source if ii.respond_to?(:source)}"
|
109
|
-
end
|
110
|
-
msg << "\n"
|
111
|
-
msg << "\n"
|
112
|
-
msg << "\ncontext stack"
|
113
|
-
msg << "\n================="
|
114
|
-
contexts.each_with_index do |ctx, ix|
|
115
|
-
msg << "\ncontext##{ix} :\n#{ctx}"
|
116
|
-
end
|
117
|
-
msg << "\n"
|
118
|
-
msg << "\n"
|
119
|
-
msg << "\nargs stack"
|
120
|
-
msg << "\n================="
|
121
|
-
args.each_with_index do |args, ix|
|
122
|
-
msg << "\args##{ix} :\n#{args}"
|
123
|
-
end
|
124
|
-
msg << "\n"
|
125
|
-
msg << "\n"
|
126
|
-
msg
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|