nydp 0.1.15 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lisp/core-015-documentation.nydp +11 -4
- data/lib/lisp/core-040-utils.nydp +3 -0
- data/lib/lisp/tests/builtin-tests.nydp +1 -1
- data/lib/lisp/tests/foundation-test.nydp +40 -0
- data/lib/lisp/tests/time-examples.nydp +21 -0
- data/lib/nydp.rb +10 -8
- data/lib/nydp/builtin.rb +3 -2
- data/lib/nydp/builtin/apply.rb +2 -2
- data/lib/nydp/builtin/car.rb +1 -1
- data/lib/nydp/builtin/cdr.rb +1 -1
- data/lib/nydp/builtin/cdr_set.rb +1 -1
- data/lib/nydp/builtin/comment.rb +2 -2
- data/lib/nydp/builtin/cons.rb +1 -1
- data/lib/nydp/builtin/date.rb +20 -0
- data/lib/nydp/builtin/divide.rb +2 -2
- data/lib/nydp/builtin/ensuring.rb +3 -3
- data/lib/nydp/builtin/error.rb +1 -1
- data/lib/nydp/builtin/eval.rb +2 -6
- data/lib/nydp/builtin/greater_than.rb +3 -3
- data/lib/nydp/builtin/handle_error.rb +2 -2
- data/lib/nydp/builtin/hash.rb +14 -20
- data/lib/nydp/builtin/inspect.rb +1 -1
- data/lib/nydp/builtin/is_equal.rb +10 -5
- data/lib/nydp/builtin/less_than.rb +3 -3
- data/lib/nydp/builtin/load_tests.rb +3 -7
- data/lib/nydp/builtin/millisecs.rb +1 -1
- data/lib/nydp/builtin/minus.rb +2 -2
- data/lib/nydp/builtin/modulo.rb +1 -1
- data/lib/nydp/builtin/parse.rb +3 -6
- data/lib/nydp/builtin/parse_in_string.rb +3 -6
- data/lib/nydp/builtin/plus.rb +3 -3
- data/lib/nydp/builtin/pre_compile.rb +2 -2
- data/lib/nydp/builtin/puts.rb +2 -2
- data/lib/nydp/builtin/random_string.rb +4 -4
- data/lib/nydp/builtin/sort.rb +1 -1
- data/lib/nydp/builtin/sqrt.rb +1 -1
- data/lib/nydp/builtin/string_match.rb +7 -10
- data/lib/nydp/builtin/string_replace.rb +1 -1
- data/lib/nydp/builtin/string_split.rb +1 -1
- data/lib/nydp/builtin/sym.rb +2 -6
- data/lib/nydp/builtin/thread_locals.rb +1 -1
- data/lib/nydp/builtin/time.rb +52 -0
- data/lib/nydp/builtin/times.rb +2 -2
- data/lib/nydp/builtin/to_string.rb +2 -2
- data/lib/nydp/builtin/type_of.rb +3 -7
- data/lib/nydp/builtin/vm_info.rb +1 -1
- data/lib/nydp/compiler.rb +2 -2
- data/lib/nydp/cond.rb +1 -1
- data/lib/nydp/core.rb +48 -48
- data/lib/nydp/function_invocation.rb +1 -1
- data/lib/nydp/helper.rb +5 -5
- data/lib/nydp/interpreted_function.rb +3 -3
- data/lib/nydp/lexical_context.rb +4 -4
- data/lib/nydp/lexical_context_builder.rb +2 -2
- data/lib/nydp/pair.rb +11 -11
- data/lib/nydp/runner.rb +2 -2
- data/lib/nydp/symbol.rb +2 -2
- data/lib/nydp/symbol_lookup.rb +1 -1
- data/lib/nydp/truth.rb +8 -11
- data/lib/nydp/version.rb +1 -1
- data/lib/nydp/vm.rb +4 -3
- data/spec/date_spec.rb +28 -20
- data/spec/error_spec.rb +1 -1
- data/spec/foreign_hash_spec.rb +12 -12
- data/spec/hash_non_hash_behaviour_spec.rb +8 -8
- data/spec/hash_spec.rb +14 -14
- data/spec/literal_spec.rb +2 -2
- data/spec/nydp_spec.rb +6 -6
- data/spec/pair_spec.rb +8 -8
- data/spec/parser_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/string_atom_spec.rb +9 -9
- data/spec/string_token_spec.rb +1 -1
- data/spec/symbol_spec.rb +9 -9
- data/spec/thread_local_spec.rb +2 -6
- data/spec/time_spec.rb +48 -0
- metadata +7 -3
- data/lib/nydp/builtin/today.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7639157cc6f6e6959cec1491e180b71930204ae
|
4
|
+
data.tar.gz: 80357a5ba720caa3065845a575a154087d9ff25c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a0824e45483b39ca5cd26730753025ffc57a1a976a83ec4e16f10c62c217993f30ef85d892aec26c52e08fb36dc8be9e55f460ed10a492bb2955260eb5e0636
|
7
|
+
data.tar.gz: c8530f8e2afcce52d310d2b76bf09de29dc162fd97df159e4c4fd3a7ac1c35b1deb103972d00fd7d7027ded94d98a85683cee28f849329f20975a955f85dbc62
|
@@ -37,6 +37,8 @@
|
|
37
37
|
(cond (dox? name)
|
38
38
|
(hash-get (car (dox-lookup name)) attr)))
|
39
39
|
|
40
|
+
(def dox-chapter-names () (hash-keys chapters ))
|
41
|
+
(def dox-chapter (name) (hash-get chapters name ))
|
40
42
|
(def dox-what-is? (name) (dox-get-attr name 'what ))
|
41
43
|
(def dox-src (name) (dox-get-attr name 'src ))
|
42
44
|
(def dox-examples (name) (hash-get examples name ))
|
@@ -84,7 +86,8 @@
|
|
84
86
|
'mac
|
85
87
|
',(map car (hash-get body-forms 'comment))
|
86
88
|
',args
|
87
|
-
'(mac ,name ,args ,@(hash-get body-forms nil))
|
89
|
+
'(mac ,name ,args ,@(hash-get body-forms nil))
|
90
|
+
',(map car (hash-get body-forms 'chapter)))))
|
88
91
|
|
89
92
|
(hash-set macs 'mac
|
90
93
|
(fn (name args . body)
|
@@ -94,13 +97,15 @@
|
|
94
97
|
'mac
|
95
98
|
'("define a new global macro")
|
96
99
|
'(name args . body)
|
97
|
-
'`(hash-set macs ',name (fn ,ooargs ,@body))
|
100
|
+
'`(hash-set macs ',name (fn ,ooargs ,@body))
|
101
|
+
'(nydp-core))
|
98
102
|
|
99
103
|
(dox-add-doc 'do
|
100
104
|
'mac
|
101
105
|
'("perform a series of operations")
|
102
106
|
'args
|
103
|
-
'`((fn nil ,@args))
|
107
|
+
'`((fn nil ,@args))
|
108
|
+
'(nydp-core))
|
104
109
|
|
105
110
|
(mac def-assign args `(assign ,@args))
|
106
111
|
|
@@ -111,8 +116,10 @@
|
|
111
116
|
'def
|
112
117
|
',(map car (hash-get body-forms 'comment))
|
113
118
|
',args
|
114
|
-
'(def ,name ,args ,@(hash-get body-forms nil))
|
119
|
+
'(def ,name ,args ,@(hash-get body-forms nil))
|
120
|
+
',(map car (hash-get body-forms 'chapter)))))
|
115
121
|
|
116
122
|
(mac def (name args . body)
|
117
123
|
; define a new function in the global namespace
|
124
|
+
(chapter nydp-core)
|
118
125
|
(define-def-expr name args (filter-forms (build-def-hash (hash)) body)))
|
@@ -12,7 +12,6 @@
|
|
12
12
|
("eval" (inspect eval ) "builtin/eval" )
|
13
13
|
("hash" (inspect hash ) "builtin/hash" )
|
14
14
|
("date" (inspect date ) "builtin/date" )
|
15
|
-
("today" (inspect today ) "builtin/today" )
|
16
15
|
("error" (inspect error ) "builtin/error" )
|
17
16
|
("apply" (inspect apply ) "builtin/apply" )
|
18
17
|
("error" (inspect error ) "builtin/error" )
|
@@ -32,6 +31,7 @@
|
|
32
31
|
("string-length" (inspect string-length ) "builtin/string-length" )
|
33
32
|
("string-replace" (inspect string-replace ) "builtin/string-replace" )
|
34
33
|
("string-split" (inspect string-split ) "builtin/string-split" )
|
34
|
+
("time" (inspect time ) "builtin/time" )
|
35
35
|
("thread-locals" (inspect thread-locals ) "builtin/thread-locals" )
|
36
36
|
("eq?" (inspect eq? ) "builtin/eq?" )
|
37
37
|
("hash-get" (inspect hash-get ) "builtin/hash-get" )
|
@@ -16,6 +16,46 @@
|
|
16
16
|
(eq? '|| '||)
|
17
17
|
t)
|
18
18
|
|
19
|
+
("true for two identical numbers"
|
20
|
+
(eq? 42 42)
|
21
|
+
t)
|
22
|
+
|
23
|
+
("true for three identical numbers"
|
24
|
+
(eq? 42 42 42)
|
25
|
+
t)
|
26
|
+
|
27
|
+
("true for four identical numbers"
|
28
|
+
(eq? 42 42 42 42)
|
29
|
+
t)
|
30
|
+
|
31
|
+
("true for five identical numbers"
|
32
|
+
(eq? 42 42 42 42 42)
|
33
|
+
t)
|
34
|
+
|
35
|
+
("true for six identical numbers"
|
36
|
+
(eq? 42 42 42 42 42 42)
|
37
|
+
t)
|
38
|
+
|
39
|
+
("false for one different number in six"
|
40
|
+
(eq? 42 42 42 42 42 -3)
|
41
|
+
nil)
|
42
|
+
|
43
|
+
("false for one different number in five"
|
44
|
+
(eq? 42 42 42 -3 42)
|
45
|
+
nil)
|
46
|
+
|
47
|
+
("false for one different number in four"
|
48
|
+
(eq? 42 -3 42 42)
|
49
|
+
nil)
|
50
|
+
|
51
|
+
("false for one different number in three"
|
52
|
+
(eq? -3 42 42)
|
53
|
+
nil)
|
54
|
+
|
55
|
+
("false for two different numbers"
|
56
|
+
(eq? -3 42)
|
57
|
+
nil)
|
58
|
+
|
19
59
|
("nil for two different symbols"
|
20
60
|
(eq? 'foo 'bar)
|
21
61
|
nil))
|
@@ -0,0 +1,21 @@
|
|
1
|
+
(examples-for time
|
2
|
+
("creates a single date" (to-string (time 1965 6 8)) "1965-06-08 00:00:00 +0100" )
|
3
|
+
("adds ten seconds" (to-string (time (time 2004 3 12 14 30) 10)) "2004-03-12 14:30:10 +0100" )
|
4
|
+
("'+ adds seconds" (to-string (+ (time 2004 3 12 14 30) 29)) "2004-03-12 14:30:29 +0100" )
|
5
|
+
("subtracts times" (time (time 2004 3 12 14 32) (time 2004 3 12 14 30)) 120.0 )
|
6
|
+
("'- subtracts times" (- (time 2004 3 12 14 36) (time 2004 3 12 14 26)) 600.0 )
|
7
|
+
|
8
|
+
("can act as hash key"
|
9
|
+
(with (h {} d (time 1971 11 18 14 57))
|
10
|
+
(hash-set h d "on this day")
|
11
|
+
(to-string (hash-get h (time 1971 11 18 14 57))))
|
12
|
+
"on this day")
|
13
|
+
|
14
|
+
("equals itself" (eq? (time 2004 3 12) (time 2004 3 12)) t )
|
15
|
+
("does not equal another" (eq? (time 2004 3 12) (time 2006 6 21)) nil)
|
16
|
+
("does not equal nil" (eq? (time 2004 3 12) nil ) nil)
|
17
|
+
("nil does not equal a time" (eq? nil (time 2004 3 12) ) nil)
|
18
|
+
|
19
|
+
("returns its year" (&year (date (time 1999 12 31 13 29 52))) 1999)
|
20
|
+
("returns its month" (&month (date (time 1999 12 31 13 29 52))) 12)
|
21
|
+
("returns its day" (&day (date (time 1999 12 31 13 29 52))) 31))
|
data/lib/nydp.rb
CHANGED
@@ -8,7 +8,7 @@ module Nydp
|
|
8
8
|
def self.testfiles; PLUGINS.map(&:testfiles).flatten ; end
|
9
9
|
def self.plugin_names ; PLUGINS.map(&:name) ; end
|
10
10
|
def self.loadall ns, files
|
11
|
-
vm = VM.new
|
11
|
+
vm = VM.new(ns)
|
12
12
|
files.each { |f|
|
13
13
|
reader = Nydp::StreamReader.new(File.new(f))
|
14
14
|
Nydp::Runner.new(vm, ns, reader).run
|
@@ -27,29 +27,31 @@ module Nydp
|
|
27
27
|
def self.apply_function ns, function_name, *args
|
28
28
|
function = r2n(function_name.to_sym, ns).value
|
29
29
|
args = r2n args, ns
|
30
|
-
vm = VM.new
|
30
|
+
vm = VM.new(ns)
|
31
31
|
|
32
32
|
function.invoke vm, args
|
33
33
|
vm.thread
|
34
34
|
end
|
35
35
|
|
36
|
-
def self.reader txt ; Nydp::StringReader.new txt
|
37
|
-
def self.eval_src ns, src_txt ; eval_with Nydp::Runner, ns, src_txt
|
38
|
-
def self.eval_src! ns, src_txt ; eval_with Nydp::ExplodeRunner, ns, src_txt
|
39
|
-
def self.eval_with runner, ns, src_txt ; runner.new(VM.new, ns, reader(src_txt)).run ; end
|
36
|
+
def self.reader txt ; Nydp::StringReader.new txt ; end
|
37
|
+
def self.eval_src ns, src_txt ; eval_with Nydp::Runner, ns, src_txt ; end
|
38
|
+
def self.eval_src! ns, src_txt ; eval_with Nydp::ExplodeRunner, ns, src_txt ; end
|
39
|
+
def self.eval_with runner, ns, src_txt ; runner.new(VM.new(ns), ns, reader(src_txt)).run ; end
|
40
40
|
|
41
41
|
def self.repl
|
42
42
|
puts "welcome to nydp"
|
43
43
|
puts "^D to exit"
|
44
44
|
reader = Nydp::ReadlineReader.new $stdin, "nydp > "
|
45
|
-
|
45
|
+
ns = build_nydp
|
46
|
+
Nydp::Runner.new(VM.new(ns), ns, reader, $stdout).run
|
46
47
|
end
|
47
48
|
|
48
49
|
def self.tests *options
|
49
50
|
verbose = options.include?(:verbose) ? "t" : "nil"
|
50
51
|
puts "welcome to nydp : running tests"
|
51
52
|
reader = Nydp::StringReader.new "(run-all-tests #{verbose})"
|
52
|
-
|
53
|
+
ns = build_nydp
|
54
|
+
Nydp::Runner.new(VM.new(ns), ns, reader).run
|
53
55
|
end
|
54
56
|
|
55
57
|
end
|
data/lib/nydp/builtin.rb
CHANGED
@@ -5,7 +5,8 @@ module Nydp::Builtin
|
|
5
5
|
module Base
|
6
6
|
include Nydp::Helper
|
7
7
|
|
8
|
-
def
|
8
|
+
def builtin_invoke vm, args ; raise "#{self.class.name} : please implement #builtin_invoke" ; end
|
9
|
+
def builtin_invoke_1 vm ; builtin_invoke vm, Nydp::NIL ; end
|
9
10
|
def builtin_invoke_2 vm, a ; builtin_invoke vm, cons(a) ; end
|
10
11
|
def builtin_invoke_3 vm, a0, a1 ; builtin_invoke vm, cons(a0, cons(a1)) ; end
|
11
12
|
def builtin_invoke_4 vm, a0, a1, a2 ; builtin_invoke vm, cons(a0, cons(a1, cons(a2))) ; end
|
@@ -13,7 +14,7 @@ module Nydp::Builtin
|
|
13
14
|
def invoke_1 vm
|
14
15
|
builtin_invoke_1 vm
|
15
16
|
rescue Exception => e
|
16
|
-
handle_error e, Nydp
|
17
|
+
handle_error e, Nydp::NIL
|
17
18
|
end
|
18
19
|
|
19
20
|
def invoke_2 vm, arg
|
data/lib/nydp/builtin/apply.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Nydp::Builtin::Apply
|
2
|
-
include Nydp::Helper, Nydp::Builtin::Base
|
2
|
+
include Nydp::Helper, Nydp::Builtin::Base, Singleton
|
3
3
|
|
4
4
|
def builtin_invoke vm, args
|
5
5
|
args.car.invoke vm, apply_args(args.cdr)
|
@@ -10,7 +10,7 @@ class Nydp::Builtin::Apply
|
|
10
10
|
def apply_args args
|
11
11
|
raise "Apply: expected a list : got #{args.inspect}" unless pair? args
|
12
12
|
raise "Apply: improper list : cdr is ruby nil" if args.cdr.nil?
|
13
|
-
return args.car if Nydp
|
13
|
+
return args.car if Nydp::NIL.is? args.cdr
|
14
14
|
cons args.car, apply_args(args.cdr)
|
15
15
|
end
|
16
16
|
end
|
data/lib/nydp/builtin/car.rb
CHANGED
data/lib/nydp/builtin/cdr.rb
CHANGED
data/lib/nydp/builtin/cdr_set.rb
CHANGED
data/lib/nydp/builtin/comment.rb
CHANGED
data/lib/nydp/builtin/cons.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
class Nydp::Builtin::Date
|
2
|
+
include Nydp::Helper, Nydp::Builtin::Base, Singleton
|
3
|
+
|
4
|
+
def builtin_invoke_1 vm
|
5
|
+
vm.push_arg(Nydp::Date.new Date.today)
|
6
|
+
end
|
7
|
+
|
8
|
+
# it's a Time object (or any object that responds to #to_date)
|
9
|
+
def builtin_invoke_2 vm, arg
|
10
|
+
vm.push_arg(Nydp::Date.new arg.to_date)
|
11
|
+
end
|
12
|
+
|
13
|
+
def builtin_invoke_3 vm, a0, a1
|
14
|
+
raise Nydp::Error.new "Date, got 2 args (#{a0} #{a1}), expected 0 or 1 or 3 args"
|
15
|
+
end
|
16
|
+
|
17
|
+
def builtin_invoke_4 vm, y, m, d
|
18
|
+
vm.push_arg(Nydp::Date.new Date.new(y,m,d))
|
19
|
+
end
|
20
|
+
end
|
data/lib/nydp/builtin/divide.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
class Nydp::Builtin::Divide
|
2
|
-
include Nydp::Builtin::Base
|
2
|
+
include Nydp::Builtin::Base, Singleton
|
3
3
|
|
4
4
|
def builtin_invoke vm, args
|
5
5
|
vm.push_arg divide(args.cdr, args.car)
|
6
6
|
end
|
7
7
|
|
8
8
|
def divide args, accum
|
9
|
-
if Nydp
|
9
|
+
if Nydp::NIL.is? args
|
10
10
|
accum
|
11
11
|
else
|
12
12
|
divide(args.cdr, (accum / args.car))
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "nydp/vm"
|
2
2
|
|
3
3
|
class Nydp::Builtin::Ensuring
|
4
|
-
include Nydp::Helper, Nydp::Builtin::Base
|
4
|
+
include Nydp::Helper, Nydp::Builtin::Base, Singleton
|
5
5
|
|
6
6
|
class InvokeProtection
|
7
7
|
include Nydp::VM::Finally
|
@@ -12,7 +12,7 @@ class Nydp::Builtin::Ensuring
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def execute vm
|
15
|
-
protection.invoke vm, Nydp
|
15
|
+
protection.invoke vm, Nydp::NIL
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -24,6 +24,6 @@ class Nydp::Builtin::Ensuring
|
|
24
24
|
vm.instructions.push protection_instructions
|
25
25
|
vm.contexts.push vm.current_context
|
26
26
|
|
27
|
-
fn_tricky.invoke vm, Nydp
|
27
|
+
fn_tricky.invoke vm, Nydp::NIL
|
28
28
|
end
|
29
29
|
end
|
data/lib/nydp/builtin/error.rb
CHANGED
data/lib/nydp/builtin/eval.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
class Nydp::Builtin::Eval
|
2
|
-
include Nydp::Builtin::Base
|
3
|
-
|
4
|
-
def initialize ns
|
5
|
-
@ns = ns
|
6
|
-
end
|
2
|
+
include Nydp::Builtin::Base, Singleton
|
7
3
|
|
8
4
|
def builtin_invoke vm, args
|
9
|
-
evaluator = Nydp::Evaluator.new Nydp::VM.new,
|
5
|
+
evaluator = Nydp::Evaluator.new Nydp::VM.new(vm.ns), vm.ns
|
10
6
|
vm.push_arg evaluator.evaluate args.car
|
11
7
|
end
|
12
8
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
class Nydp::Builtin::GreaterThan
|
2
|
-
include Nydp::Builtin::Base
|
2
|
+
include Nydp::Builtin::Base, Singleton
|
3
3
|
|
4
4
|
def builtin_invoke vm, args
|
5
|
-
vm.push_arg (greater_than(args.car, args.cdr) ? Nydp
|
5
|
+
vm.push_arg (greater_than(args.car, args.cdr) ? Nydp::T : Nydp::NIL)
|
6
6
|
end
|
7
7
|
|
8
8
|
def greater_than arg, args
|
9
|
-
return true if Nydp
|
9
|
+
return true if Nydp::NIL.is? args
|
10
10
|
(arg > args.car) && greater_than(args.car, args.cdr)
|
11
11
|
end
|
12
12
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "nydp/vm"
|
2
2
|
|
3
3
|
class Nydp::Builtin::HandleError
|
4
|
-
include Nydp::Helper, Nydp::Builtin::Base
|
4
|
+
include Nydp::Helper, Nydp::Builtin::Base, Singleton
|
5
5
|
|
6
6
|
class CatchError
|
7
7
|
include Nydp::Helper, Nydp::VM::HandleError
|
@@ -36,6 +36,6 @@ class Nydp::Builtin::HandleError
|
|
36
36
|
vm.instructions.push catcher_instructions
|
37
37
|
vm.contexts.push vm.current_context
|
38
38
|
|
39
|
-
fn_tricky.invoke vm, Nydp
|
39
|
+
fn_tricky.invoke vm, Nydp::NIL
|
40
40
|
end
|
41
41
|
end
|
data/lib/nydp/builtin/hash.rb
CHANGED
@@ -1,27 +1,25 @@
|
|
1
1
|
require "nydp/hash"
|
2
2
|
|
3
3
|
class Nydp::Builtin::Hash
|
4
|
-
include Nydp::Helper, Nydp::Builtin::Base
|
4
|
+
include Nydp::Helper, Nydp::Builtin::Base, Singleton
|
5
5
|
def builtin_invoke vm, args
|
6
6
|
vm.push_arg(Nydp::Hash.new)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
class Nydp::Builtin::HashGet
|
11
|
-
include Nydp::Helper, Nydp::Builtin::Base
|
12
|
-
attr_accessor :ns
|
13
|
-
def initialize ns ; @ns = ns; end
|
11
|
+
include Nydp::Helper, Nydp::Builtin::Base, Singleton
|
14
12
|
def builtin_invoke vm, args
|
15
13
|
hsh = args.car
|
16
14
|
key = args.cdr.car
|
17
15
|
case hsh
|
18
16
|
when Nydp::Hash
|
19
|
-
vm.push_arg(hsh[key] || Nydp
|
20
|
-
when NilClass, Nydp
|
21
|
-
vm.push_arg Nydp
|
17
|
+
vm.push_arg(hsh[key] || Nydp::NIL)
|
18
|
+
when NilClass, Nydp::NIL
|
19
|
+
vm.push_arg Nydp::NIL
|
22
20
|
else
|
23
21
|
v = hsh.respond_to?(:[]) ? hsh[n2r key] : ruby_call(hsh, key)
|
24
|
-
vm.push_arg(r2n v, ns)
|
22
|
+
vm.push_arg(r2n v, vm.ns)
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
@@ -38,7 +36,7 @@ class Nydp::Builtin::HashGet
|
|
38
36
|
end
|
39
37
|
|
40
38
|
class Nydp::Builtin::HashSet
|
41
|
-
include Nydp::Helper, Nydp::Builtin::Base
|
39
|
+
include Nydp::Helper, Nydp::Builtin::Base, Singleton
|
42
40
|
def builtin_invoke vm, args
|
43
41
|
hash = args.car
|
44
42
|
key = args.cdr.car
|
@@ -46,7 +44,7 @@ class Nydp::Builtin::HashSet
|
|
46
44
|
case hash
|
47
45
|
when Nydp::Hash
|
48
46
|
hash[key] = value
|
49
|
-
when NilClass, Nydp
|
47
|
+
when NilClass, Nydp::NIL
|
50
48
|
nil
|
51
49
|
else
|
52
50
|
if hash.respond_to?(:[]=)
|
@@ -60,25 +58,21 @@ class Nydp::Builtin::HashSet
|
|
60
58
|
end
|
61
59
|
|
62
60
|
class Nydp::Builtin::HashKeys
|
63
|
-
include Nydp::Helper, Nydp::Builtin::Base
|
64
|
-
attr_accessor :ns
|
65
|
-
def initialize ns ; @ns = ns; end
|
61
|
+
include Nydp::Helper, Nydp::Builtin::Base, Singleton
|
66
62
|
def builtin_invoke vm, args
|
67
63
|
hash = args.car
|
68
64
|
if hash.is_a? Nydp::Hash
|
69
65
|
vm.push_arg Nydp::Pair.from_list hash.keys
|
70
66
|
elsif hash.respond_to?(:keys)
|
71
|
-
vm.push_arg r2n(hash.keys.to_a.sort, ns)
|
67
|
+
vm.push_arg r2n(hash.keys.to_a.sort, vm.ns)
|
72
68
|
else
|
73
|
-
vm.push_arg Nydp
|
69
|
+
vm.push_arg Nydp::NIL
|
74
70
|
end
|
75
71
|
end
|
76
72
|
end
|
77
73
|
|
78
74
|
class Nydp::Builtin::HashKeyPresent
|
79
|
-
include Nydp::Helper, Nydp::Builtin::Base
|
80
|
-
attr_accessor :ns
|
81
|
-
def initialize ns ; @ns = ns; end
|
75
|
+
include Nydp::Helper, Nydp::Builtin::Base, Singleton
|
82
76
|
def builtin_invoke vm, args
|
83
77
|
hash = args.car
|
84
78
|
key = args.cdr.car
|
@@ -88,13 +82,13 @@ class Nydp::Builtin::HashKeyPresent
|
|
88
82
|
else
|
89
83
|
hash.key? n2r key
|
90
84
|
end
|
91
|
-
vm.push_arg(truth ? Nydp
|
85
|
+
vm.push_arg(truth ? Nydp::T : Nydp::NIL)
|
92
86
|
end
|
93
87
|
def name ; "hash-key?" ; end
|
94
88
|
end
|
95
89
|
|
96
90
|
class Nydp::Builtin::HashMerge
|
97
|
-
include Nydp::Helper, Nydp::Builtin::Base
|
91
|
+
include Nydp::Helper, Nydp::Builtin::Base, Singleton
|
98
92
|
|
99
93
|
def builtin_invoke vm, args
|
100
94
|
hash_0 = args.car
|