nydp 0.1.9.1 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46921f478f559c5d78edc626c2620ba05406f071
4
- data.tar.gz: 582c35f13517cdb8e897e6696c1873284304ec88
3
+ metadata.gz: 6eec33bbcb86a9efa22b6e3fe9be0ab2f792e54c
4
+ data.tar.gz: 61bf6dde8f734b52a82779be3b8127714cd4775c
5
5
  SHA512:
6
- metadata.gz: 9f1a7ad0dcfedb16886cdb8c932f44486745cfba9cf80ff93fd3e4e1225c762fcb38902b689fcf3a68bce1c230cb1e47d14d95ff6c7d294879793c36a881e2ef
7
- data.tar.gz: 91e528cd2bf04dae0ac591ca6ad93fe29c5c9f71f1751aa5692b6392d38161a19b4c869f49ec37e576db34589ccd3d7b5b582e8c73086a21fabe8eb4c185430d
6
+ metadata.gz: 47dd8b9bdd75f050da422385256417a2ed334c1b988dbb718c53f2be91905174af5390a37817b9938eddc09b67b056e718310932fa00375f622240607a33f06c
7
+ data.tar.gz: d947fab3747a487f5d99db30ae90186ee8b2424fb3370b8463567430afc94ff533c1ec51b7770ecf93aeed1ed919dcdbc5b28886e92487aa1547168187454252
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ test/version_tmp
17
17
  tmp
18
18
  lib/lisp/scratch
19
19
  .#*
20
+ bm.txt
@@ -17,26 +17,26 @@
17
17
  (assign times (+ elapsed times))
18
18
  (p " took: ~elapsed ms, ~(/ elapsed iterations) ms per iteration"))))
19
19
  (p "total ~(just times), average ~(/ times repeats) per run")
20
- (p "================================================\n"))
21
- nil)
20
+ (p "================================================\n")
21
+ "~desc : total ~(just times), average ~(/ times repeats) per run"))
22
22
 
23
- (let private-x 0
24
- (let inc-x (fn () (assign private-x (+ 1 private-x)))
25
- (def bm-zero-arg-call ()
26
- (for i 0 400 (inc-x)))))
27
23
 
28
- (let private-y 0
29
- (let inc-y (fn (n) (assign private-y (+ n private-y)))
30
- (def bm-one-arg-call ()
31
- (for i 0 400 (inc-y 10)))))
24
+ (def bm-0-arg-times-call () (*))
25
+ (def bm-1-arg-times-call () (* 23))
26
+ (def bm-2-arg-times-call () (* 23 24))
27
+ (def bm-3-arg-times-call () (* 23 24 25))
28
+ (def bm-4-arg-times-call () (* 23 24 25 26))
32
29
 
33
- (let private-z 0
34
- (let inc-z (fn (n m) (assign private-z (+ (* n m) private-z)))
35
- (def bm-two-arg-call ()
36
- (for i 0 400 (inc-z 2 5)))))
37
-
38
- (def rbs ()
39
- (bm "pythag" bm-pythag 10 100)
40
- (bm "zero arg call" bm-zero-arg-call 10 500)
41
- (bm "one arg call" bm-one-arg-call 10 500)
42
- (bm "two arg call" bm-two-arg-call 10 500))
30
+ (def rbs (name)
31
+ (let summary nil
32
+ ;; (push (bm "pythag" bm-pythag 10 20) summary)
33
+ ;; (push (bm "zero arg call" bm-zero-arg-call 10 100) summary)
34
+ ;; (push (bm "one arg call" bm-one-arg-call 10 100) summary)
35
+ ;; (push (bm "two arg call" bm-two-arg-call 10 100) summary)
36
+ ;; (push (bm "three arg call" bm-three-arg-call 10 100) summary)
37
+ (push (bm "0 arg times" bm-0-arg-times-call 10 10000) summary)
38
+ (push (bm "1 arg times" bm-1-arg-times-call 10 10000) summary)
39
+ (push (bm "2 arg times" bm-2-arg-times-call 10 10000) summary)
40
+ (push (bm "3 arg times" bm-3-arg-times-call 10 10000) summary)
41
+ (push (bm "4 arg times" bm-4-arg-times-call 10 10000) summary)
42
+ (each s summary (p name " " s))))
@@ -42,19 +42,33 @@
42
42
  ))
43
43
 
44
44
  (examples-for +
45
- ("adds integers"
46
- (+ 11 22 33)
47
- 66)
45
+ ("adds nothing" (+) 0)
46
+ ("adds 1 int" (+ 42) 42)
47
+ ("adds 2 ints" (+ 42 45) 87)
48
+ ("adds 3 ints" (+ 11 22 33) 66)
48
49
 
49
- ("adds floats"
50
- (+ 14.80 (* 91.31 1.05))
51
- 110.6755))
50
+ ("adds 1 float" (+ 4.2) 4.2)
51
+ ("adds 2 floats" (+ 4.2 4.5) 8.7)
52
+ ("adds 3 floats" (+ 1.1 2.2 3.3) 6.6))
52
53
 
53
54
  (examples-for -
54
- ("subtracts integers"
55
- (- 66 25)
56
- 41)
55
+ ("subtracts nothing" (-) 0)
56
+ ("subtracts 1 int" (- 42) -42)
57
+ ("subtracts 2 ints" (- 45 42) 3)
58
+ ("subtracts 3 ints" (- 66 22 33) 11)
57
59
 
58
- ("subtracts floats"
59
- (- 6.25 4.125)
60
- 2.125))
60
+ ("subtracts 1 float" (- 4.2) -4.2)
61
+ ("subtracts 2 floats" (- 4.2 4.7) -0.5)
62
+ ("subtracts 3 floats" (- 6.6 1.1 3.3) 2.2))
63
+
64
+ (examples-for *
65
+ ("multiplies nothing" (*) 1)
66
+ ("multiplies 1 int" (* 42) 42)
67
+ ("multiplies 2 ints" (* 5 42) 210)
68
+ ("multiplies 3 ints" (* 2 3 5) 30)
69
+ ("multiplies 3 ints" (* 2 3 5 7) 210)
70
+
71
+ ("multiplies 1 float" (* 4.2) 4.2)
72
+ ("multiplies 2 floats" (* 4.2 0.5) 2.1)
73
+ ("multiplies 3 floats" (* 4.2 -2.5) -10.5)
74
+ ("multiplies 4 floats" (* 6.6 1.1 3.3) 23.958))
data/lib/nydp/builtin.rb CHANGED
@@ -5,16 +5,33 @@ module Nydp::Builtin
5
5
  module Base
6
6
  include Nydp::Helper
7
7
 
8
+ def builtin_invoke_1 vm ; builtin_invoke vm, Nydp.NIL ; end
9
+ def builtin_invoke_2 vm, a ; builtin_invoke vm, cons(a) ; end
10
+ def builtin_invoke_3 vm, a0, a1 ; builtin_invoke vm, cons(a0, cons(a1)) ; end
11
+ def builtin_invoke_4 vm, a0, a1, a2 ; builtin_invoke vm, cons(a0, cons(a1, cons(a2))) ; end
12
+
8
13
  def invoke_1 vm
9
- invoke vm, Nydp.NIL
14
+ builtin_invoke_1 vm
15
+ rescue Exception => e
16
+ handle_error e, Nydp.NIL
10
17
  end
11
18
 
12
19
  def invoke_2 vm, arg
13
- invoke vm, cons(arg)
20
+ builtin_invoke_2 vm, arg
21
+ rescue Exception => e
22
+ handle_error e, cons(arg)
14
23
  end
15
24
 
16
25
  def invoke_3 vm, arg_0, arg_1
17
- invoke vm, cons(arg_0, cons(arg_1))
26
+ builtin_invoke_3 vm, arg_0, arg_1
27
+ rescue Exception => e
28
+ handle_error e, cons(arg_0, cons(arg_1))
29
+ end
30
+
31
+ def invoke_4 vm, arg_0, arg_1, arg_2
32
+ builtin_invoke_4 vm, arg_0, arg_1, arg_2
33
+ rescue Exception => e
34
+ handle_error e, cons(arg_0, cons(arg_1, cons(arg_2)))
18
35
  end
19
36
 
20
37
  def invoke vm, args
@@ -1,6 +1,11 @@
1
1
  class Nydp::Builtin::Minus
2
2
  include Nydp::Builtin::Base
3
3
 
4
+ def invoke_1 vm ; vm.push_arg 0 ; end
5
+ def invoke_2 vm, a ; vm.push_arg -a ; end
6
+ def invoke_3 vm, a0, a1 ; vm.push_arg(a0 - a1) ; end
7
+ def invoke_4 vm, a0, a1, a2 ; vm.push_arg(a0 - a1 - a2) ; end
8
+
4
9
  def builtin_invoke vm, args
5
10
  vm.push_arg diff(args.cdr, args.car)
6
11
  end
@@ -1,6 +1,11 @@
1
1
  class Nydp::Builtin::Plus
2
2
  include Nydp::Builtin::Base
3
3
 
4
+ def builtin_invoke_1 vm ; vm.push_arg 0 ; end
5
+ def builtin_invoke_2 vm, a ; vm.push_arg a ; end
6
+ def builtin_invoke_3 vm, a0, a1 ; vm.push_arg(a0 + a1) ; end
7
+ def builtin_invoke_4 vm, a0, a1, a2 ; vm.push_arg(a0 + a1 + a2) ; end
8
+
4
9
  def builtin_invoke vm, args
5
10
  vm.push_arg case args.car
6
11
  when Nydp::Pair
@@ -1,6 +1,11 @@
1
1
  class Nydp::Builtin::Times
2
2
  include Nydp::Builtin::Base
3
3
 
4
+ def invoke_1 vm ; vm.push_arg 1 ; end
5
+ def invoke_2 vm, a ; vm.push_arg a ; end
6
+ def invoke_3 vm, a0, a1 ; vm.push_arg(a0 * a1) ; end
7
+ def invoke_4 vm, a0, a1, a2 ; vm.push_arg(a0 * a1 * a2) ; end
8
+
4
9
  def builtin_invoke vm, args
5
10
  vm.push_arg multiply(args, 1)
6
11
  end
data/lib/nydp/closure.rb CHANGED
@@ -18,6 +18,10 @@ module Nydp
18
18
  ifn.invoke_3 vm, context, arg_0, arg_1
19
19
  end
20
20
 
21
+ def invoke_4 vm, arg_0, arg_1, arg_2
22
+ ifn.invoke_4 vm, context, arg_0, arg_1, arg_2
23
+ end
24
+
21
25
  def invoke vm, arg_values
22
26
  ifn.invoke vm, context, arg_values
23
27
  end
@@ -58,6 +58,18 @@ module Nydp
58
58
  end
59
59
  end
60
60
 
61
+ class Invocation_4 < Invocation::Base
62
+ def execute vm
63
+ arg_2 = vm.pop_arg
64
+ arg_1 = vm.pop_arg
65
+ arg_0 = vm.pop_arg
66
+ f = vm.pop_arg
67
+ f.invoke_4 vm, arg_0, arg_1, arg_2
68
+ rescue Exception => e
69
+ handle e, f, cons(arg_0, cons(arg_1, cons(arg_2)))
70
+ end
71
+ end
72
+
61
73
  class Invocation_N < Invocation::Base
62
74
  def initialize arg_count, source_expression
63
75
  super source_expression
@@ -85,6 +97,8 @@ module Nydp
85
97
  Invocation::Invocation_2.new(expression)
86
98
  when 3
87
99
  Invocation::Invocation_3.new(expression)
100
+ when 4
101
+ Invocation::Invocation_4.new(expression)
88
102
  else
89
103
  Invocation::Invocation_N.new(expression.size, expression)
90
104
  end
@@ -31,6 +31,12 @@ module Nydp
31
31
  vm.push_instructions self.body, lc
32
32
  end
33
33
 
34
+ def invoke_4 vm, parent_context, arg_0, arg_1, arg_2
35
+ lc = LexicalContext.new parent_context
36
+ set_args_3 lc, arg_0, arg_1, arg_2
37
+ vm.push_instructions self.body, lc
38
+ end
39
+
34
40
  def invoke vm, parent_context, arg_values
35
41
  lc = LexicalContext.new parent_context
36
42
  set_args lc, arg_values
@@ -45,6 +45,15 @@ class Nydp::LexicalContext
45
45
  end
46
46
  end
47
47
 
48
+ def set_args_3 names, arg_0, arg_1, arg_2
49
+ if pair? names
50
+ set names.car, arg_0
51
+ set_args_2 names.cdr, arg_1, arg_2
52
+ elsif Nydp.NIL.isnt? names
53
+ set names, cons(arg_0, cons(arg_1, cons(arg_2)))
54
+ end
55
+ end
56
+
48
57
  def set_index index, value
49
58
  values[index] = value
50
59
  end
@@ -2,17 +2,19 @@ module Nydp::LexicalContextBuilder
2
2
  extend Nydp::Helper
3
3
 
4
4
  module B_0
5
- def initialize_names _ ; end
6
- def set_args_1 lc, a ; end
7
- def set_args_2 lc, a_0, a_1 ; end
8
- def set_args lc, args ; end
5
+ def initialize_names _ ; end
6
+ def set_args_1 lc, a ; end
7
+ def set_args_2 lc, a_0, a_1 ; end
8
+ def set_args_3 lc, a_0, a_1, a_2 ; end
9
+ def set_args lc, args ; end
9
10
  end
10
11
 
11
12
  module B_1
12
- def initialize_names names ; @param_name = names.car ; end
13
- def set_args_1 lc, arg ; lc.set @param_name, arg ; end
14
- def set_args_2 lc, arg_0, arg_1 ; lc.set @param_name, arg_0 ; end
15
- def set_args lc, args ; lc.set @param_name, args.car ; end
13
+ def initialize_names names ; @param_name = names.car ; end
14
+ def set_args_1 lc, arg ; lc.set @param_name, arg ; end
15
+ def set_args_2 lc, arg_0, arg_1 ; lc.set @param_name, arg_0 ; end
16
+ def set_args_3 lc, arg_0, arg_1, arg_2 ; lc.set @param_name, arg_0 ; end
17
+ def set_args lc, args ; lc.set @param_name, args.car ; end
16
18
  end
17
19
 
18
20
  module B_2
@@ -27,18 +29,48 @@ module Nydp::LexicalContextBuilder
27
29
  lc.set @param_name_0, arg_0
28
30
  lc.set @param_name_1, arg_1
29
31
  end
32
+ def set_args_3 lc, arg_0, arg_1, arg_2
33
+ lc.set @param_name_0, arg_0
34
+ lc.set @param_name_1, arg_1
35
+ end
30
36
  def set_args lc, args
31
37
  lc.set @param_name_0, args.car
32
38
  lc.set @param_name_1, args.cdr.car
33
39
  end
34
40
  end
35
41
 
42
+ module B_3
43
+ def initialize_names names
44
+ @param_name_0 = names.car
45
+ @param_name_1 = names.cdr.car
46
+ @param_name_2 = names.cdr.cdr.car
47
+ end
48
+ def set_args_1 lc, arg
49
+ lc.set @param_name_0, arg
50
+ end
51
+ def set_args_2 lc, arg_0, arg_1
52
+ lc.set @param_name_0, arg_0
53
+ lc.set @param_name_1, arg_1
54
+ end
55
+ def set_args_3 lc, arg_0, arg_1, arg_2
56
+ lc.set @param_name_0, arg_0
57
+ lc.set @param_name_1, arg_1
58
+ lc.set @param_name_2, arg_2
59
+ end
60
+ def set_args lc, args
61
+ lc.set @param_name_0, args.car
62
+ lc.set @param_name_1, args.cdr.car
63
+ lc.set @param_name_2, args.cdr.cdr.car
64
+ end
65
+ end
66
+
36
67
  module B_0_Rest
37
68
  include Nydp::Helper
38
- def initialize_names names ; @param_name = names ; end
39
- def set_args_1 lc, arg ; lc.set @param_name, cons(arg) ; end
40
- def set_args_2 lc, arg_0, arg_1 ; lc.set @param_name, cons(arg_0, cons(arg_1)) ; end
41
- def set_args lc, args ; lc.set @param_name, args ; end
69
+ def initialize_names names ; @param_name = names ; end
70
+ def set_args_1 lc, arg ; lc.set @param_name, cons(arg) ; end
71
+ def set_args_2 lc, arg_0, arg_1 ; lc.set @param_name, cons(arg_0, cons(arg_1)) ; end
72
+ def set_args_3 lc, arg_0, arg_1, arg_2 ; lc.set @param_name, cons(arg_0, cons(arg_1, cons(arg_2))) ; end
73
+ def set_args lc, args ; lc.set @param_name, args ; end
42
74
  end
43
75
 
44
76
  module B_1_Rest
@@ -54,6 +86,10 @@ module Nydp::LexicalContextBuilder
54
86
  lc.set @param_name_0, arg_0
55
87
  lc.set @param_name_1, cons(arg_1)
56
88
  end
89
+ def set_args_3 lc, arg_0, arg_1, arg_2
90
+ lc.set @param_name_0, arg_0
91
+ lc.set @param_name_1, cons(arg_1, cons(arg_2))
92
+ end
57
93
  def set_args lc, args
58
94
  lc.set @param_name_0, args.car
59
95
  lc.set @param_name_1, args.cdr
@@ -73,6 +109,11 @@ module Nydp::LexicalContextBuilder
73
109
  lc.set @param_name_0, arg_0
74
110
  lc.set @param_name_1, arg_1
75
111
  end
112
+ def set_args_3 lc, arg_0, arg_1, arg_2
113
+ lc.set @param_name_0, arg_0
114
+ lc.set @param_name_1, arg_1
115
+ lc.set @param_name_2, cons(arg_2)
116
+ end
76
117
  def set_args lc, args
77
118
  lc.set @param_name_0, args.car
78
119
  lc.set @param_name_1, args.cdr.car
@@ -80,6 +121,32 @@ module Nydp::LexicalContextBuilder
80
121
  end
81
122
  end
82
123
 
124
+ module B_3_Rest
125
+ def initialize_names names
126
+ @param_name_0 = names.car
127
+ @param_name_1 = names.cdr.car
128
+ @param_name_2 = names.cdr.cdr
129
+ end
130
+ def set_args_1 lc, arg
131
+ lc.set @param_name_0, arg
132
+ end
133
+ def set_args_2 lc, arg_0, arg_1
134
+ lc.set @param_name_0, arg_0
135
+ lc.set @param_name_1, arg_1
136
+ end
137
+ def set_args_3 lc, arg_0, arg_1, arg_2
138
+ lc.set @param_name_0, arg_0
139
+ lc.set @param_name_1, arg_1
140
+ lc.set @param_name_2, arg_2
141
+ end
142
+ def set_args lc, args
143
+ lc.set @param_name_0, args.car
144
+ lc.set @param_name_1, args.cdr.car
145
+ lc.set @param_name_2, args.cdr.cdr.car
146
+ lc.set @param_name_3, args.cdr.cdr.cdr
147
+ end
148
+ end
149
+
83
150
  module B_X
84
151
  def initialize_names names
85
152
  @param_names = names
@@ -91,6 +158,11 @@ module Nydp::LexicalContextBuilder
91
158
  lc.set @param_names.car, arg_0
92
159
  lc.set @param_names.cdr.car, arg_1
93
160
  end
161
+ def set_args_3 lc, arg_0, arg_1, arg_2
162
+ lc.set @param_names.car, arg_0
163
+ lc.set @param_names.cdr.car, arg_1
164
+ lc.set @param_names.cdr.cdr.car, arg_2
165
+ end
94
166
  def set_args lc, args
95
167
  _set_args lc, @param_names, args
96
168
  end
@@ -104,10 +176,11 @@ module Nydp::LexicalContextBuilder
104
176
 
105
177
  module B_X_Rest
106
178
  include Nydp::Helper
107
- def initialize_names names ; @param_names = names ; end
108
- def set_args_1 lc, arg ; set_args lc, cons(arg) ; end
109
- def set_args_2 lc, arg_0, arg_1 ; set_args lc, cons(arg_0, cons(arg_1)) ; end
110
- def set_args lc, args ; _set_args lc, @param_names, args ; end
179
+ def initialize_names names ; @param_names = names ; end
180
+ def set_args_1 lc, arg ; set_args lc, cons(arg) ; end
181
+ def set_args_2 lc, arg_0, arg_1 ; set_args lc, cons(arg_0, cons(arg_1)) ; end
182
+ def set_args_3 lc, arg_0, arg_1, arg_2 ; set_args lc, cons(arg_0, cons(arg_1, cons(arg_2))) ; end
183
+ def set_args lc, args ; _set_args lc, @param_names, args ; end
111
184
  def _set_args lc, names, args
112
185
  if pair? names
113
186
  lc.set names.car, args.car
@@ -121,7 +194,7 @@ module Nydp::LexicalContextBuilder
121
194
  def self.select arg_names
122
195
  if pair? arg_names
123
196
  size = pair?(arg_names) ? arg_names.size : 0
124
- class_name = "B_#{size > 2 ? "X" : size}#{arg_names.proper? ? "" : "_Rest"}"
197
+ class_name = "B_#{size > 3 ? "X" : size}#{arg_names.proper? ? "" : "_Rest"}"
125
198
  else
126
199
  class_name = "B_0_Rest"
127
200
  end
data/lib/nydp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nydp
2
- VERSION = "0.1.9.1"
2
+ VERSION = "0.1.10"
3
3
  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.1.9.1
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Conan Dalton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-20 00:00:00.000000000 Z
11
+ date: 2016-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler