nydp 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lisp/boot.nydp +40 -5
- data/lib/lisp/test-runner.nydp +1 -1
- data/lib/lisp/tests/boot-tests.nydp +29 -1
- data/lib/lisp/tests/foundation-test.nydp +34 -2
- data/lib/nydp.rb +1 -0
- data/lib/nydp/builtin/car.rb +3 -0
- data/lib/nydp/builtin/cdr.rb +3 -0
- data/lib/nydp/builtin/today.rb +7 -0
- data/lib/nydp/builtin/type_of.rb +10 -1
- data/lib/nydp/date.rb +65 -0
- data/lib/nydp/hash.rb +14 -0
- data/lib/nydp/helper.rb +5 -4
- data/lib/nydp/parser.rb +1 -0
- data/lib/nydp/string_atom.rb +1 -0
- data/lib/nydp/symbol.rb +7 -4
- data/lib/nydp/truth.rb +3 -0
- data/lib/nydp/version.rb +1 -1
- data/spec/date_spec.rb +54 -0
- data/spec/hash_spec.rb +45 -0
- data/spec/literal_spec.rb +12 -0
- data/spec/symbol_spec.rb +5 -2
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 815a0a959a0678c7fc8a7e4ad5cd50fa0a5aa0fb
|
4
|
+
data.tar.gz: 23c872b0c3126bfc18c9859e617ba645751e38ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2980ea82cc715d36febeaa27a008fef8e2eb507caad76a030ba46b52ddcb690b311c6313018c589790d9d49db3497fd0c044b2fe3ca284024dadd237fe5e5594
|
7
|
+
data.tar.gz: 3ba9d1749f05d877749af1ec35ee0a2cbdb8fa0ba818c194a8d0f3d773c674d1ea85b185a7eeea24e923781328ed4a61bcb03f38540088393d8dd9b9f9129b9c
|
data/lib/lisp/boot.nydp
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
(assign last (fn (arg) (car (last-cons arg))))
|
20
20
|
(assign caar (fn (arg) (car (car arg))))
|
21
21
|
(assign cadr (fn (arg) (car (cdr arg))))
|
22
|
+
(assign cdar (fn (arg) (cdr (car arg))))
|
22
23
|
(assign cddr (fn (arg) (cdr (cdr arg))))
|
23
24
|
(assign no (fn (arg) (cond arg nil t)))
|
24
25
|
(assign just (fn (arg) arg))
|
@@ -150,13 +151,24 @@
|
|
150
151
|
`(cond ,(car args) ,(cadr args)))
|
151
152
|
(car args))))
|
152
153
|
|
154
|
+
(def expand-colon-syntax (first rest)
|
155
|
+
(if (no rest)
|
156
|
+
`(apply ,first args)
|
157
|
+
`(,first ,(expand-colon-syntax (car rest) (cdr rest)))))
|
158
|
+
|
159
|
+
(mac colon-syntax args
|
160
|
+
(if (eq? (car args) '||)
|
161
|
+
(error "Irregular ': syntax: got ~(inspect args) : not prefix-syntax : in ~(joinstr ":" (cons pfx rest))")
|
162
|
+
`(fn args ,(expand-colon-syntax (car args) (cdr args)))))
|
163
|
+
|
153
164
|
(mac bang-syntax (pfx . rest)
|
154
165
|
(if (no (eq? pfx '||))
|
155
|
-
(error "Irregular ! syntax: got prefix ~(inspect pfx) in ~(joinstr "!" (cons pfx rest))"))
|
166
|
+
(error "Irregular '! syntax: got prefix ~(inspect pfx) in ~(joinstr "!" (cons pfx rest))"))
|
156
167
|
(if (cdr rest)
|
157
|
-
(error "Irregular ! syntax: got suffix ~(inspect (cdr rest)) in ~(joinstr "!" (cons pfx rest))")
|
158
|
-
|
159
|
-
|
168
|
+
(error "Irregular '! syntax: got suffix ~(inspect (cdr rest)) in ~(joinstr "!" (cons pfx rest))")
|
169
|
+
(if (caris 'colon-syntax (car rest))
|
170
|
+
`(colon-syntax no ,@(cdar rest))
|
171
|
+
`(colon-syntax no ,(car rest)))))
|
160
172
|
|
161
173
|
(mac and args
|
162
174
|
(if args
|
@@ -311,13 +323,20 @@
|
|
311
323
|
,result))))
|
312
324
|
(def ,name () (hash-get (thread-locals) ',name))))))
|
313
325
|
|
326
|
+
(def build-hash-get-key (name)
|
327
|
+
(if (pair? name)
|
328
|
+
(if (caris 'unquote name)
|
329
|
+
(cadr name)
|
330
|
+
name)
|
331
|
+
(list 'quote name)))
|
332
|
+
|
314
333
|
;; (build-hash-getters '(a b c))
|
315
334
|
;; => (hash-get (hash-get a 'b) 'c)
|
316
335
|
(def build-hash-getters (names acc)
|
317
336
|
(if (no acc)
|
318
337
|
(build-hash-getters (cdr names) (car names))
|
319
338
|
names
|
320
|
-
(build-hash-getters (cdr names) `(hash-get ,acc
|
339
|
+
(build-hash-getters (cdr names) `(hash-get ,acc ,(build-hash-get-key (car names))))
|
321
340
|
acc))
|
322
341
|
|
323
342
|
(def build-hash-lookup-from (root names)
|
@@ -327,6 +346,7 @@
|
|
327
346
|
(build-hash-getters names nil))
|
328
347
|
|
329
348
|
(mac dot-syntax names `(hash-lookup ,names))
|
349
|
+
(mac dollar-syntax (_ name) `(,name))
|
330
350
|
|
331
351
|
(def dot-syntax-assignment (names value-expr)
|
332
352
|
(let rnames (rev names)
|
@@ -352,6 +372,18 @@
|
|
352
372
|
,@(map (fn (m) `(hash-set ,hash ,(brace-list-hash-key (car m)) ,(cadr m))) mappings)
|
353
373
|
,hash))))
|
354
374
|
|
375
|
+
(def build-ampersand-syntax (arg)
|
376
|
+
(if (caris 'dot-syntax arg)
|
377
|
+
`(fn (obj) ,(build-hash-lookup-from 'obj (cdr arg)))
|
378
|
+
`(fn (obj) ,(build-hash-lookup-from 'obj (list arg)))))
|
379
|
+
|
380
|
+
(mac ampersand-syntax (pfx . rest)
|
381
|
+
(if (no (eq? pfx '||))
|
382
|
+
(error "Irregular '& syntax: got prefix ~(inspect pfx) in ~(joinstr "&" (cons pfx rest))"))
|
383
|
+
(if (cdr rest)
|
384
|
+
(error "Irregular '& syntax: got suffix ~(inspect (cdr rest)) in ~(joinstr "&" (cons pfx rest))")
|
385
|
+
(build-ampersand-syntax (car rest))))
|
386
|
+
|
355
387
|
(mac brace-list-mono (arg) arg)
|
356
388
|
|
357
389
|
(mac brace-list args
|
@@ -387,3 +419,6 @@
|
|
387
419
|
`(with (,v nil ,gi ,init ,gm (+ ,max 1))
|
388
420
|
(loop (assign ,v ,gi) (< ,v ,gm) (assign ,v (+ ,v 1))
|
389
421
|
,@body))))
|
422
|
+
|
423
|
+
(mac mapx (things x expr)
|
424
|
+
`(map (fn (,x) ,expr) ,things))
|
data/lib/lisp/test-runner.nydp
CHANGED
@@ -108,6 +108,11 @@
|
|
108
108
|
(test-foo "x" "y")
|
109
109
|
("a0 w0 x w0 y" "a0 w1 x w1 y" "a0 w2 x w2 y" "a0 w3 x w3 y"))
|
110
110
|
|
111
|
+
(suite "mapx"
|
112
|
+
("provides a convenient simplification for 'map"
|
113
|
+
(mapx '(1 2 3 4) n (* n 2))
|
114
|
+
(2 4 6 8)))
|
115
|
+
|
111
116
|
(suite "pre-compile"
|
112
117
|
(suite "bang-syntax"
|
113
118
|
("expansion"
|
@@ -126,6 +131,29 @@
|
|
126
131
|
(!caris 'foo '(zozo foo bar))
|
127
132
|
t))
|
128
133
|
|
134
|
+
(suite "ampersand-syntax"
|
135
|
+
("defines a hash-lookup function"
|
136
|
+
(pre-compile '&first)
|
137
|
+
(fn (obj) (hash-get obj (quote first))))
|
138
|
+
|
139
|
+
("defines a hash-lookup function with a dot-syntax arg"
|
140
|
+
(pre-compile '&teacher.address.city)
|
141
|
+
(fn (obj) (hash-get (hash-get (hash-get obj (quote teacher)) (quote address)) (quote city))) ))
|
142
|
+
|
143
|
+
(suite "colon-syntax"
|
144
|
+
("used for composition"
|
145
|
+
(pre-compile '(no:eq? a b))
|
146
|
+
((fn args (no (apply eq? args))) a b))
|
147
|
+
|
148
|
+
("used for composition"
|
149
|
+
(pre-compile '(x:y a b))
|
150
|
+
((fn args (x (apply y args))) a b)))
|
151
|
+
|
152
|
+
(suite "bang-colon syntax"
|
153
|
+
("special combination with bang"
|
154
|
+
(pre-compile '(!x:y a b))
|
155
|
+
((fn args (no (x (apply y args)))) a b)))
|
156
|
+
|
129
157
|
("expands 'let"
|
130
158
|
(do
|
131
159
|
(def x+3*z (x y)
|
@@ -184,7 +212,7 @@
|
|
184
212
|
`((a ,(+ 1 2) b)))
|
185
213
|
("returns nested quasiquotes"
|
186
214
|
`(a b `(c d ,(+ 1 2) ,,(+ 3 4)))
|
187
|
-
(a b `(c d ,(+ 1 2) ,7))))
|
215
|
+
(a b `(c d ,(+ 1 2) ,7))))
|
188
216
|
|
189
217
|
(suite "build-keyword-args"
|
190
218
|
("takes a list of lists and returns the list with the first item of each sublist quoted"
|
@@ -20,12 +20,20 @@
|
|
20
20
|
(type-of "foobar")
|
21
21
|
string)
|
22
22
|
|
23
|
+
("returns 'number for an integer"
|
24
|
+
(type-of 42)
|
25
|
+
number)
|
26
|
+
|
27
|
+
("returns 'number for a float"
|
28
|
+
(type-of 4.2)
|
29
|
+
number)
|
30
|
+
|
23
31
|
("interpolates a string"
|
24
32
|
"foobar ~(+ 1 2) you know"
|
25
33
|
"foobar 3 you know")
|
26
34
|
|
27
35
|
("returns 'string for an interpolated string"
|
28
|
-
(type-of "foobar
|
36
|
+
(type-of "foobar ~(+ 1 2)")
|
29
37
|
string)))
|
30
38
|
|
31
39
|
(suite "eq?"
|
@@ -64,13 +72,37 @@
|
|
64
72
|
(pre-compile 'a.b.c)
|
65
73
|
(hash-get (hash-get a 'b) 'c))
|
66
74
|
|
75
|
+
("hash-lookup with dollar-syntax for function call"
|
76
|
+
(pre-compile '$a.b.c)
|
77
|
+
(hash-get (hash-get (a) 'b) 'c))
|
78
|
+
|
79
|
+
("hash-lookup with embedded dollar-syntax for function call"
|
80
|
+
(pre-compile 'a.$b.c)
|
81
|
+
(hash-get (hash-get a (b)) 'c))
|
82
|
+
|
83
|
+
("hash-lookup with embedded unquote"
|
84
|
+
(pre-compile 'a.,b.c)
|
85
|
+
(hash-get (hash-get a b) 'c))
|
86
|
+
|
67
87
|
("hash assignment"
|
68
88
|
(pre-compile '(= a.b 42))
|
69
89
|
(hash-set a 'b 42))
|
70
90
|
|
71
91
|
("recursive hash assignment"
|
72
92
|
(pre-compile '(= a.b.c.d 42))
|
73
|
-
(hash-set (hash-get (hash-get a 'b) 'c) 'd 42))
|
93
|
+
(hash-set (hash-get (hash-get a 'b) 'c) 'd 42))
|
94
|
+
|
95
|
+
("recursive hash assignment with embedded unquote"
|
96
|
+
(pre-compile '(= a.b.,c.d 42))
|
97
|
+
(hash-set (hash-get (hash-get a 'b) c) 'd 42))
|
98
|
+
|
99
|
+
("recursive hash assignment with prefix dollar-syntax"
|
100
|
+
(pre-compile '(= $a.b.,c.d 42))
|
101
|
+
(hash-set (hash-get (hash-get (a) 'b) c) 'd 42))
|
102
|
+
|
103
|
+
("recursive hash assignment with embedded dollar-syntax"
|
104
|
+
(pre-compile '(= a.$b.,c.d 42))
|
105
|
+
(hash-set (hash-get (hash-get a (b)) c) 'd 42)))
|
74
106
|
|
75
107
|
(suite "isa"
|
76
108
|
("t for 'pair for list"
|
data/lib/nydp.rb
CHANGED
data/lib/nydp/builtin/car.rb
CHANGED
data/lib/nydp/builtin/cdr.rb
CHANGED
data/lib/nydp/builtin/type_of.rb
CHANGED
@@ -5,7 +5,16 @@ class Nydp::Builtin::TypeOf
|
|
5
5
|
|
6
6
|
def invoke vm, args
|
7
7
|
arg = args.car
|
8
|
-
|
8
|
+
typename = if arg.respond_to?(:nydp_type)
|
9
|
+
arg.nydp_type.to_sym
|
10
|
+
elsif arg.is_a? Numeric
|
11
|
+
:number
|
12
|
+
else
|
13
|
+
"ruby/#{arg.class.name}".to_sym
|
14
|
+
end
|
15
|
+
|
16
|
+
type = Nydp::Symbol.mk(typename, @ns)
|
17
|
+
|
9
18
|
vm.push_arg(type || Nydp.NIL)
|
10
19
|
end
|
11
20
|
end
|
data/lib/nydp/date.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'nydp/helper'
|
2
|
+
|
3
|
+
module Nydp
|
4
|
+
class Date
|
5
|
+
include Nydp::Helper
|
6
|
+
|
7
|
+
attr_accessor :ruby_date
|
8
|
+
|
9
|
+
MONTH_SIZES = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
10
|
+
def build y, m, d
|
11
|
+
s = MONTH_SIZES[m]
|
12
|
+
::Date.new(y, m, (d > s ? s : d))
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize ruby_date
|
16
|
+
@ruby_date = ruby_date
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s ; ruby_date.to_s ; end
|
20
|
+
def inspect ; ruby_date.inspect ; end
|
21
|
+
def nydp_type ; :date ; end
|
22
|
+
|
23
|
+
@@keys = Set.new %i{
|
24
|
+
year month week_day day
|
25
|
+
last_year next_year beginning_of_year end_of_year
|
26
|
+
last_month next_month beginning_of_month end_of_month
|
27
|
+
last_week next_week beginning_of_week end_of_week
|
28
|
+
yesterday tomorrow
|
29
|
+
}
|
30
|
+
|
31
|
+
def year y, m, d, w ; y ; end
|
32
|
+
def month y, m, d, w ; m ; end
|
33
|
+
def day y, m, d, w ; d ; end
|
34
|
+
def week_day y, m, d, w ; w ; end
|
35
|
+
|
36
|
+
def last_year y, m, d, w ; build(y - 1, m, d) ; end
|
37
|
+
def next_year y, m, d, w ; ruby_date.next_year ; end
|
38
|
+
def beginning_of_year y, m, d, w ; build(y, 1, 1) ; end
|
39
|
+
def end_of_year y, m, d, w ; build(y, 12, 31) ; end
|
40
|
+
|
41
|
+
def last_month y, m, d, w ; build(y, m - 1, d) ; end
|
42
|
+
def next_month y, m, d, w ; ruby_date.next_month ; end
|
43
|
+
def beginning_of_month y, m, d, w ; build(y, m, 1) ; end
|
44
|
+
def end_of_month y, m, d, w ; build(y, m, 31) ; end
|
45
|
+
|
46
|
+
def last_week y, m, d, w ; ruby_date - 7 ; end
|
47
|
+
def next_week y, m, d, w ; ruby_date + 7 ; end
|
48
|
+
def beginning_of_week y, m, d, w ; ruby_date + 1 - w ; end
|
49
|
+
def end_of_week y, m, d, w ; ruby_date + 7 - w ; end
|
50
|
+
|
51
|
+
def yesterday y, m, d, w ; ruby_date - 1 ; end
|
52
|
+
def tomorrow y, m, d, w ; ruby_date + 1 ; end
|
53
|
+
|
54
|
+
def [] key
|
55
|
+
key = key.to_s.gsub(/-/, '_').to_sym
|
56
|
+
y = ruby_date.year
|
57
|
+
m = ruby_date.month
|
58
|
+
d = ruby_date.day
|
59
|
+
w = ruby_date.wday
|
60
|
+
|
61
|
+
adjusted = self.send(key, y, m, d, w) if @@keys.include?(key)
|
62
|
+
r2n adjusted, nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/nydp/hash.rb
CHANGED
data/lib/nydp/helper.rb
CHANGED
@@ -3,9 +3,10 @@ module Nydp
|
|
3
3
|
::Symbol => ->(obj, ns) { Nydp::Symbol.mk(obj, ns) },
|
4
4
|
Array => ->(obj, ns) { Nydp::Pair.from_list obj.map { |o| Nydp.r2n o, ns } },
|
5
5
|
String => ->(obj, ns) { Nydp::StringAtom.new obj.to_s },
|
6
|
-
NilClass => ->(obj, ns) { Nydp
|
7
|
-
FalseClass => ->(obj, ns) { Nydp
|
8
|
-
TrueClass => ->(obj, ns) { Nydp
|
6
|
+
NilClass => ->(obj, ns) { Nydp.NIL },
|
7
|
+
FalseClass => ->(obj, ns) { Nydp.NIL },
|
8
|
+
TrueClass => ->(obj, ns) { Nydp.T },
|
9
|
+
::Date => ->(obj, ns) { Nydp::Date.new obj },
|
9
10
|
}
|
10
11
|
|
11
12
|
def self.n2r nydp
|
@@ -13,7 +14,7 @@ module Nydp
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.r2n ruby_obj, ns
|
16
|
-
return ruby_obj._nydp_wrapper if ruby_obj.respond_to? :_nydp_wrapper
|
17
|
+
return ruby_obj._nydp_wrapper(ns) if ruby_obj.respond_to? :_nydp_wrapper
|
17
18
|
|
18
19
|
rklass = ruby_obj.class
|
19
20
|
R2NHELPERS.each do |hklass, proc|
|
data/lib/nydp/parser.rb
CHANGED
data/lib/nydp/string_atom.rb
CHANGED
data/lib/nydp/symbol.rb
CHANGED
@@ -38,10 +38,13 @@ class Nydp::Symbol
|
|
38
38
|
ns[name.to_sym]
|
39
39
|
end
|
40
40
|
|
41
|
-
def nydp_type
|
42
|
-
def inspect
|
43
|
-
def to_s
|
44
|
-
def
|
41
|
+
def nydp_type ; :symbol ; end
|
42
|
+
def inspect ; @inspection ; end
|
43
|
+
def to_s ; name.to_s ; end
|
44
|
+
def to_sym ; name ; end
|
45
|
+
def to_ruby ; to_sym ; end
|
46
|
+
def hash ; name.hash ; end
|
47
|
+
def eql? other ; self == other ; end
|
45
48
|
|
46
49
|
def == other
|
47
50
|
other.is_a?(Nydp::Symbol) && (self.name == other.name)
|
data/lib/nydp/truth.rb
CHANGED
@@ -4,6 +4,7 @@ module Nydp
|
|
4
4
|
def inspect ; 't[nydp::Truth]' ; end
|
5
5
|
def assign *_ ; self ; end
|
6
6
|
def nydp_type ; :truth ; end
|
7
|
+
def to_ruby ; true ; end
|
7
8
|
end
|
8
9
|
|
9
10
|
class Nil
|
@@ -18,6 +19,7 @@ module Nydp
|
|
18
19
|
def assign *_ ; self ; end
|
19
20
|
def inspect ; "nil" ; end
|
20
21
|
def nydp_type ; :nil ; end
|
22
|
+
def to_ruby ; nil ; end
|
21
23
|
|
22
24
|
def execute vm
|
23
25
|
vm.push_arg self
|
@@ -34,6 +36,7 @@ module Nydp
|
|
34
36
|
class Nil
|
35
37
|
def self.new ; raise "no" ; end
|
36
38
|
end
|
39
|
+
|
37
40
|
def self.NIL; @@nil; end
|
38
41
|
def self.T; @@t; end
|
39
42
|
end
|
data/lib/nydp/version.rb
CHANGED
data/spec/date_spec.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Nydp::Date do
|
4
|
+
|
5
|
+
let(:ns) { { } }
|
6
|
+
|
7
|
+
it "converts ruby Date to Nydp::Date" do
|
8
|
+
rd = Date.parse "2015-06-08"
|
9
|
+
nd = Nydp.r2n rd, ns
|
10
|
+
|
11
|
+
expect(nd). to be_a Nydp::Date
|
12
|
+
expect(nd.to_s). to eq "2015-06-08"
|
13
|
+
expect(nd.inspect).to eq "#<Date: 2015-06-08 ((2457182j,0s,0n),+0s,2299161j)>"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns date components" do
|
17
|
+
rd = Date.parse "2015-06-08"
|
18
|
+
nd = Nydp.r2n rd, ns
|
19
|
+
|
20
|
+
expect(nd[:year]). to eq 2015
|
21
|
+
expect(nd[:month]).to eq 6
|
22
|
+
expect(nd[:day]). to eq 8
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns relative dates by year" do
|
26
|
+
rd = Date.parse "2015-06-08"
|
27
|
+
nd = Nydp.r2n rd, ns
|
28
|
+
|
29
|
+
expect(nd[:"last-year"].to_s). to eq "2014-06-08"
|
30
|
+
expect(nd[:"next-year"].to_s). to eq "2016-06-08"
|
31
|
+
expect(nd[:"beginning-of-year"].to_s). to eq "2015-01-01"
|
32
|
+
expect(nd[:"end-of-year"].to_s). to eq "2015-12-31"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns relative dates by month" do
|
36
|
+
rd = Date.parse "2015-06-08"
|
37
|
+
nd = Nydp.r2n rd, ns
|
38
|
+
|
39
|
+
expect(nd[:"last-month"].to_s). to eq "2015-05-08"
|
40
|
+
expect(nd[:"next-month"].to_s). to eq "2015-07-08"
|
41
|
+
expect(nd[:"beginning-of-month"].to_s). to eq "2015-06-01"
|
42
|
+
expect(nd[:"end-of-month"].to_s). to eq "2015-06-30"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns relative dates by week" do
|
46
|
+
rd = Date.parse "2015-03-12"
|
47
|
+
nd = Nydp.r2n rd, ns
|
48
|
+
|
49
|
+
expect(nd[:"last-week"].to_s). to eq "2015-03-05"
|
50
|
+
expect(nd[:"next-week"].to_s). to eq "2015-03-19"
|
51
|
+
expect(nd[:"beginning-of-week"].to_s). to eq "2015-03-09"
|
52
|
+
expect(nd[:"end-of-week"].to_s). to eq "2015-03-15"
|
53
|
+
end
|
54
|
+
end
|
data/spec/hash_spec.rb
CHANGED
@@ -4,6 +4,32 @@ describe Nydp::Hash do
|
|
4
4
|
|
5
5
|
let(:vm) { Nydp::VM.new }
|
6
6
|
|
7
|
+
describe "#to_ruby" do
|
8
|
+
it "converts ruby symbol key to nydp symbol key" do
|
9
|
+
hash = Nydp::Hash.new
|
10
|
+
hash[sym "boo"] = 42
|
11
|
+
|
12
|
+
rhash = hash.to_ruby
|
13
|
+
expect(rhash[:boo]).to eq 42
|
14
|
+
end
|
15
|
+
|
16
|
+
it "converts ruby string key to nydp string key" do
|
17
|
+
hash = Nydp::Hash.new
|
18
|
+
hash[Nydp::StringAtom.new "boo"] = 42
|
19
|
+
|
20
|
+
rhash = hash.to_ruby
|
21
|
+
expect(rhash["boo"]).to eq 42
|
22
|
+
end
|
23
|
+
|
24
|
+
it "uses integer keys unconverted" do
|
25
|
+
hash = Nydp::Hash.new
|
26
|
+
hash[21] = 42
|
27
|
+
|
28
|
+
rhash = hash.to_ruby
|
29
|
+
expect(rhash[21]).to eq 42
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
7
33
|
describe "nydp hashes" do
|
8
34
|
describe "new hash" do
|
9
35
|
it "returns a new Nydp hash" do
|
@@ -81,6 +107,25 @@ describe Nydp::Hash do
|
|
81
107
|
|
82
108
|
expect(vm.pop_arg).to eq Nydp::StringAtom.new("avalue")
|
83
109
|
end
|
110
|
+
|
111
|
+
it "converts ruby nil to nydp value" do
|
112
|
+
k = sym("keysym")
|
113
|
+
args = [ ahash, k ]
|
114
|
+
|
115
|
+
Nydp::Builtin::HashGet.new(ns).invoke vm, pair_list(args)
|
116
|
+
|
117
|
+
expect(vm.pop_arg).to eq Nydp.NIL
|
118
|
+
end
|
119
|
+
|
120
|
+
it "converts ruby true to nydp value" do
|
121
|
+
ahash[:keysym] = true
|
122
|
+
k = sym("keysym")
|
123
|
+
args = [ ahash, k ]
|
124
|
+
|
125
|
+
Nydp::Builtin::HashGet.new(ns).invoke vm, pair_list(args)
|
126
|
+
|
127
|
+
expect(vm.pop_arg).to eq Nydp.T
|
128
|
+
end
|
84
129
|
end
|
85
130
|
|
86
131
|
describe "hash keys" do
|
data/spec/literal_spec.rb
CHANGED
@@ -6,4 +6,16 @@ describe Nydp::Literal do
|
|
6
6
|
lit = Nydp::Literal.new sym
|
7
7
|
expect(lit.to_ruby).to eq :foo
|
8
8
|
end
|
9
|
+
|
10
|
+
describe "t" do
|
11
|
+
it "is #true in ruby" do
|
12
|
+
expect(Nydp.T.to_ruby).to eq true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "nil" do
|
17
|
+
it "is #nil in ruby" do
|
18
|
+
expect(Nydp.NIL.to_ruby).to eq nil
|
19
|
+
end
|
20
|
+
end
|
9
21
|
end
|
data/spec/symbol_spec.rb
CHANGED
@@ -31,7 +31,10 @@ describe Nydp::Symbol do
|
|
31
31
|
sym1 = Nydp::Symbol.mk :baz, ns1
|
32
32
|
sym2 = Nydp::Symbol.mk :baz, ns2
|
33
33
|
|
34
|
-
expect(sym1).to eq sym2
|
35
|
-
|
34
|
+
expect(sym1.hash).to eq sym2.hash
|
35
|
+
|
36
|
+
expect(sym1 == sym2).to eq true
|
37
|
+
expect(sym1.eql? sym2).to eq true
|
38
|
+
expect(sym1.equal? sym2).to eq false
|
36
39
|
end
|
37
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nydp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Conan Dalton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- lib/nydp/builtin/times.rb
|
129
129
|
- lib/nydp/builtin/to_string.rb
|
130
130
|
- lib/nydp/builtin/to_sym.rb
|
131
|
+
- lib/nydp/builtin/today.rb
|
131
132
|
- lib/nydp/builtin/type_of.rb
|
132
133
|
- lib/nydp/builtin/vm_info.rb
|
133
134
|
- lib/nydp/closure.rb
|
@@ -135,6 +136,7 @@ files:
|
|
135
136
|
- lib/nydp/cond.rb
|
136
137
|
- lib/nydp/context_symbol.rb
|
137
138
|
- lib/nydp/core.rb
|
139
|
+
- lib/nydp/date.rb
|
138
140
|
- lib/nydp/error.rb
|
139
141
|
- lib/nydp/function_invocation.rb
|
140
142
|
- lib/nydp/hash.rb
|
@@ -156,6 +158,7 @@ files:
|
|
156
158
|
- lib/nydp/vm.rb
|
157
159
|
- lib/tasks/tests.rake
|
158
160
|
- nydp.gemspec
|
161
|
+
- spec/date_spec.rb
|
159
162
|
- spec/embedded_spec.rb
|
160
163
|
- spec/hash_spec.rb
|
161
164
|
- spec/literal_spec.rb
|
@@ -192,6 +195,7 @@ signing_key:
|
|
192
195
|
specification_version: 4
|
193
196
|
summary: A civilised yet somewhat dangerous kind of Lisp for a new generation
|
194
197
|
test_files:
|
198
|
+
- spec/date_spec.rb
|
195
199
|
- spec/embedded_spec.rb
|
196
200
|
- spec/hash_spec.rb
|
197
201
|
- spec/literal_spec.rb
|