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
@@ -3,32 +3,77 @@ module Nydp
|
|
3
3
|
end
|
4
4
|
|
5
5
|
module Invocation
|
6
|
-
@@sig_counts = Hash.new { |h,k| h[k] = 0}
|
7
|
-
|
8
|
-
# def self.sig name ; @@sig_counts[name] += 1 ; end
|
9
|
-
|
10
|
-
# def self.whazzup
|
11
|
-
# puts @@sig_counts.to_a.sort_by { |c| c[1] }.map { |c| "#{c[1]}\t#{c[0]}"}
|
12
|
-
# end
|
13
|
-
|
14
6
|
class Base
|
15
7
|
include Helper
|
16
8
|
def initialize expr, source, sig=nil
|
17
9
|
@expr, @source, @sig = expr, source, sig
|
18
10
|
end
|
19
11
|
|
12
|
+
def compile_to_ruby indent, srcs, opts={}
|
13
|
+
ruby = if opts[:cando]
|
14
|
+
compile_do_expr_to_ruby indent, srcs
|
15
|
+
end
|
16
|
+
|
17
|
+
ruby ||= normal_compile_to_ruby indent, srcs
|
18
|
+
end
|
19
|
+
|
20
|
+
def compile_do_expr_to_ruby indent, srcs
|
21
|
+
if @expr.car.is_a?(InterpretedFunction) && !@expr.cdr && @expr.car.can_do?
|
22
|
+
@expr.car.compile_do_expr_to_ruby indent, srcs
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def normal_compile_to_ruby indent, srcs
|
27
|
+
ra = @expr.map { |e| e.compile_to_ruby "#{indent} ", srcs}.to_a
|
28
|
+
fn_expr = @expr.first.to_s.inspect.gsub("\'", "\\\\'")
|
29
|
+
fn = ra.shift
|
30
|
+
|
31
|
+
src_expr = @expr.inspect.split(/\n/).join('\n')
|
32
|
+
|
33
|
+
if ra.empty?
|
34
|
+
"#{indent} ##> #{src_expr}
|
35
|
+
#{indent} (begin ; #{fn}.
|
36
|
+
#{indent} ##> #{src_expr}
|
37
|
+
#{indent} _nydp_call()
|
38
|
+
#{indent} rescue CantCallNil => e
|
39
|
+
#{indent} (raise 'can\\'t call nil : #{fn_expr}')
|
40
|
+
#{indent} end)"
|
41
|
+
else
|
42
|
+
"#{indent} ##> #{src_expr}
|
43
|
+
#{indent} (begin ; #{fn}.
|
44
|
+
#{indent} ##> #{src_expr}
|
45
|
+
#{indent} _nydp_call(#{ra.join(",\n")})
|
46
|
+
#{indent} rescue CantCallNil => e
|
47
|
+
#{indent} (raise 'can\\'t call nil : #{fn_expr}')
|
48
|
+
#{indent} end)"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# def compile_to_ruby indent, srcs
|
53
|
+
# ra = @expr.map { |e| e.compile_to_ruby "#{indent} ", srcs}
|
54
|
+
# fn = ra.shift
|
55
|
+
|
56
|
+
# if ra.empty?
|
57
|
+
# "#{indent}#{fn}._nydp_callable(#{@expr.first.to_s.inspect})._nydp_call()"
|
58
|
+
# else
|
59
|
+
# "#{indent}#{fn}._nydp_callable(#{@expr.first.to_s.inspect})._nydp_call(
|
60
|
+
# #{ra.join(",\n")}
|
61
|
+
# #{indent})"
|
62
|
+
# end
|
63
|
+
# end
|
64
|
+
|
20
65
|
def handle e, f, invoker, *args
|
21
66
|
case e
|
22
67
|
when Nydp::Error, InvocationFailed
|
23
68
|
raise
|
24
69
|
else
|
25
70
|
if e.is_a?(NoMethodError) && !f.respond_to?(invoker)
|
26
|
-
raise InvocationFailed.new("#{f.
|
71
|
+
raise InvocationFailed.new("#{f._nydp_inspect} is not a function: args were #{args._nydp_inspect} in #{source._nydp_inspect}")
|
27
72
|
else
|
28
|
-
msg = args.map { |a| " #{a.
|
29
|
-
msg = "failed to execute invocation #{f.
|
30
|
-
msg += "\nsource was #{source.
|
31
|
-
msg += "\nfunction name was #{source.car.
|
73
|
+
msg = args.map { |a| " #{a._nydp_inspect}"}.join("\n")
|
74
|
+
msg = "failed to execute invocation #{f._nydp_inspect}\n#{msg}"
|
75
|
+
msg += "\nsource was #{source._nydp_inspect}"
|
76
|
+
msg += "\nfunction name was #{source.car._nydp_inspect}"
|
32
77
|
raise InvocationFailed.new msg
|
33
78
|
end
|
34
79
|
end
|
@@ -39,253 +84,10 @@ module Nydp
|
|
39
84
|
@expr.map { |x| x.lexical_reach n}.max
|
40
85
|
end
|
41
86
|
|
42
|
-
def inspect ; @expr.map { |x| x.
|
87
|
+
def inspect ; "(" + @expr.map { |x| x._nydp_inspect }.join(' ') + ")" ; end
|
43
88
|
def source ; @source ; end
|
44
89
|
def to_s ; source.to_s ; end
|
45
90
|
end
|
46
|
-
|
47
|
-
class Invocation_1 < Invocation::Base
|
48
|
-
def execute vm
|
49
|
-
# Invocation.sig @sig
|
50
|
-
f = vm.args.pop
|
51
|
-
f.invoke_1 vm
|
52
|
-
rescue StandardError => e
|
53
|
-
handle e, f, :invoke_1
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class Invocation_2 < Invocation::Base
|
58
|
-
def execute vm
|
59
|
-
# Invocation.sig @sig
|
60
|
-
arg = vm.args.pop
|
61
|
-
f = vm.args.pop
|
62
|
-
f.invoke_2 vm, arg
|
63
|
-
rescue StandardError => e
|
64
|
-
handle e, f, :invoke_2, arg
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
class Invocation_3 < Invocation::Base
|
69
|
-
def execute vm
|
70
|
-
# Invocation.sig @sig
|
71
|
-
arg_1 = vm.args.pop
|
72
|
-
arg_0 = vm.args.pop
|
73
|
-
f = vm.args.pop
|
74
|
-
f.invoke_3 vm, arg_0, arg_1
|
75
|
-
rescue StandardError => e
|
76
|
-
handle e, f, :invoke_3, arg_0, arg_1
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
class Invocation_4 < Invocation::Base
|
81
|
-
def execute vm
|
82
|
-
# Invocation.sig @sig
|
83
|
-
arg_2 = vm.args.pop
|
84
|
-
arg_1 = vm.args.pop
|
85
|
-
arg_0 = vm.args.pop
|
86
|
-
f = vm.args.pop
|
87
|
-
f.invoke_4 vm, arg_0, arg_1, arg_2
|
88
|
-
rescue StandardError => e
|
89
|
-
handle e, f, :invoke_4, arg_0, arg_1, arg_2
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
class Invocation_N < Invocation::Base
|
94
|
-
def initialize arg_count, expr, source
|
95
|
-
super expr, source
|
96
|
-
@arg_count = arg_count
|
97
|
-
end
|
98
|
-
|
99
|
-
def execute vm
|
100
|
-
# Invocation.sig @sig
|
101
|
-
args = vm.pop_args @arg_count
|
102
|
-
args.car.invoke vm, args.cdr
|
103
|
-
rescue StandardError => e
|
104
|
-
handle e, args.car, :invoke, args.cdr
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
# TODO generate various Invocation_XXX classes on-demand instead of hand_coding them all up front
|
109
|
-
SIGS = Set.new
|
110
|
-
|
111
|
-
class Invocation_LEX < Invocation::Base
|
112
|
-
SIGS << self.name
|
113
|
-
def initialize expr, src
|
114
|
-
super expr, src
|
115
|
-
@sym = expr.car
|
116
|
-
end
|
117
|
-
|
118
|
-
def execute vm
|
119
|
-
# Invocation.sig self.class.name
|
120
|
-
@sym.value(vm.current_context).invoke_1 vm
|
121
|
-
rescue StandardError => e
|
122
|
-
handle e, @sym.value(vm.current_context), :invoke_1
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
class Invocation_SYM < Invocation::Base
|
127
|
-
SIGS << self.name
|
128
|
-
def initialize expr, src
|
129
|
-
super expr, src
|
130
|
-
@sym = expr.car
|
131
|
-
end
|
132
|
-
|
133
|
-
def execute vm
|
134
|
-
# Invocation.sig self.class.name
|
135
|
-
@sym.value.invoke_1 vm
|
136
|
-
rescue StandardError => e
|
137
|
-
handle e, @sym.value, :invoke_1
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
class Invocation_LEX_LEX < Invocation::Base
|
142
|
-
SIGS << self.name
|
143
|
-
def initialize expr, src
|
144
|
-
super expr, src
|
145
|
-
@lex0 = expr.car
|
146
|
-
@lex1 = expr.cdr.car
|
147
|
-
end
|
148
|
-
|
149
|
-
def execute vm
|
150
|
-
# Invocation.sig self.class.name
|
151
|
-
fn = @lex0.value(vm.current_context)
|
152
|
-
a0 = @lex1.value(vm.current_context)
|
153
|
-
fn.invoke_2 vm, a0
|
154
|
-
rescue StandardError => e
|
155
|
-
handle e, fn, :invoke_2, a0
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
class Invocation_SYM_LEX < Invocation::Base
|
160
|
-
SIGS << self.name
|
161
|
-
def initialize expr, src
|
162
|
-
super expr, src
|
163
|
-
@sym = expr.car
|
164
|
-
@lex = expr.cdr.car
|
165
|
-
end
|
166
|
-
|
167
|
-
def execute vm
|
168
|
-
# Invocation.sig self.class.name
|
169
|
-
a0 = @lex.value(vm.current_context)
|
170
|
-
@sym.value.invoke_2 vm, a0
|
171
|
-
rescue StandardError => e
|
172
|
-
handle e, @sym.value, :invoke_2, a0
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
class Invocation_SYM_LIT < Invocation::Base
|
177
|
-
SIGS << self.name
|
178
|
-
def initialize expr, src
|
179
|
-
super expr, src
|
180
|
-
@sym = expr.car
|
181
|
-
@lit = expr.cdr.car.expression
|
182
|
-
end
|
183
|
-
|
184
|
-
def execute vm
|
185
|
-
# Invocation.sig self.class.name
|
186
|
-
@sym.value.invoke_2 vm, @lit
|
187
|
-
rescue StandardError => e
|
188
|
-
handle e, @sym.value, :invoke_2, @lit
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
class Invocation_LEX_LEX_LEX < Invocation::Base
|
193
|
-
SIGS << self.name
|
194
|
-
def initialize expr, src
|
195
|
-
super expr, src
|
196
|
-
@lex_0 = expr.car
|
197
|
-
@lex_1 = expr.cdr.car
|
198
|
-
@lex_2 = expr.cdr.cdr.car
|
199
|
-
end
|
200
|
-
|
201
|
-
def execute vm
|
202
|
-
# Invocation.sig self.class.name
|
203
|
-
fn = @lex_0.value(vm.current_context)
|
204
|
-
a0 = @lex_1.value(vm.current_context)
|
205
|
-
a1 = @lex_2.value(vm.current_context)
|
206
|
-
fn.invoke_3 vm, a0, a1
|
207
|
-
rescue StandardError => e
|
208
|
-
handle e, fn, :invoke_3, a0, a1
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
class Invocation_SYM_LEX_LEX < Invocation::Base
|
213
|
-
SIGS << self.name
|
214
|
-
def initialize expr, src
|
215
|
-
super expr, src
|
216
|
-
@sym = expr.car
|
217
|
-
@lex_0 = expr.cdr.car
|
218
|
-
@lex_1 = expr.cdr.cdr.car
|
219
|
-
end
|
220
|
-
|
221
|
-
def execute vm
|
222
|
-
# Invocation.sig self.class.name
|
223
|
-
a0 = @lex_0.value(vm.current_context)
|
224
|
-
a1 = @lex_1.value(vm.current_context)
|
225
|
-
@sym.value.invoke_3 vm, a0, a1
|
226
|
-
rescue StandardError => e
|
227
|
-
handle e, @sym.value, :invoke_3, a0, a1
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
class Invocation_SYM_LEX_LEX_LEX < Invocation::Base
|
232
|
-
SIGS << self.name
|
233
|
-
def initialize expr, src
|
234
|
-
super expr, src
|
235
|
-
@sym = expr.car
|
236
|
-
@lex_0 = expr.cdr.car
|
237
|
-
@lex_1 = expr.cdr.cdr.car
|
238
|
-
@lex_2 = expr.cdr.cdr.cdr.car
|
239
|
-
end
|
240
|
-
|
241
|
-
def execute vm
|
242
|
-
# Invocation.sig self.class.name
|
243
|
-
a0 = @lex_0.value(vm.current_context)
|
244
|
-
a1 = @lex_1.value(vm.current_context)
|
245
|
-
a2 = @lex_2.value(vm.current_context)
|
246
|
-
@sym.value.invoke_4 vm, a0, a1, a2
|
247
|
-
rescue StandardError => e
|
248
|
-
handle e, @sym.value, :invoke_4, a0, a1, a2
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
class Invocation_SYM_LEX_LIT_LEX < Invocation::Base
|
253
|
-
SIGS << self.name
|
254
|
-
def initialize expr, src
|
255
|
-
super expr, src
|
256
|
-
@sym = expr.car
|
257
|
-
@lex_0 = expr.cdr.car
|
258
|
-
@lit_1 = expr.cdr.cdr.car.expression
|
259
|
-
@lex_2 = expr.cdr.cdr.cdr.car
|
260
|
-
end
|
261
|
-
|
262
|
-
def execute vm
|
263
|
-
# Invocation.sig self.class.name
|
264
|
-
a0 = @lex_0.value(vm.current_context)
|
265
|
-
a2 = @lex_2.value(vm.current_context)
|
266
|
-
@sym.value.invoke_4 vm, a0, @lit_1, a2
|
267
|
-
rescue StandardError => e
|
268
|
-
handle e, @sym.value, :invoke_4, a0, @lit_1, a2
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
class Invocation_SYM_LIT_LEX < Invocation::Base
|
273
|
-
SIGS << self.name
|
274
|
-
def initialize expr, src
|
275
|
-
super expr, src
|
276
|
-
@sym = expr.car
|
277
|
-
@lit_0 = expr.cdr.car.expression
|
278
|
-
@lex_1 = expr.cdr.cdr.car
|
279
|
-
end
|
280
|
-
|
281
|
-
def execute vm
|
282
|
-
# Invocation.sig self.class.name
|
283
|
-
a1 = @lex_1.value(vm.current_context)
|
284
|
-
@sym.value.invoke_3 vm, @lit_0, a1
|
285
|
-
rescue StandardError => e
|
286
|
-
handle e, @sym.value, :invoke_3, @lit_0, a1
|
287
|
-
end
|
288
|
-
end
|
289
91
|
end
|
290
92
|
|
291
93
|
class FunctionInvocation
|
@@ -293,35 +95,26 @@ module Nydp
|
|
293
95
|
attr_accessor :function_instruction, :argument_instructions
|
294
96
|
|
295
97
|
def lexical_reach n
|
296
|
-
function_instruction.
|
98
|
+
function_instruction.lexical_reach(n)
|
297
99
|
end
|
298
100
|
|
299
|
-
def
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
101
|
+
def compile_to_ruby indent, srcs, opts=nil
|
102
|
+
ra = argument_instructions.map { |e| e.compile_to_ruby "#{indent} ", srcs, cando: true }.to_a
|
103
|
+
if ra.length == 1
|
104
|
+
"#{indent}#{ra.shift}._nydp_call()"
|
105
|
+
else
|
106
|
+
"#{indent}#{ra.shift}._nydp_call(
|
107
|
+
#{ra.join(",\n")}
|
108
|
+
#{indent})"
|
109
|
+
end
|
110
|
+
end
|
304
111
|
|
305
|
-
|
112
|
+
@@seen = { }
|
306
113
|
|
307
|
-
|
308
|
-
|
309
|
-
return Nydp::Invocation.const_get(cname).new(compiled, expression)
|
310
|
-
end
|
114
|
+
def self.build expression, bindings, ns
|
115
|
+
compiled = Compiler.compile_each(expression, bindings, ns)
|
311
116
|
|
312
|
-
|
313
|
-
when 1
|
314
|
-
Invocation::Invocation_1.new(compiled, expression)
|
315
|
-
when 2
|
316
|
-
Invocation::Invocation_2.new(compiled, expression)
|
317
|
-
when 3
|
318
|
-
Invocation::Invocation_3.new(compiled, expression)
|
319
|
-
when 4
|
320
|
-
Invocation::Invocation_4.new(compiled, expression)
|
321
|
-
else
|
322
|
-
Invocation::Invocation_N.new(expression.size, compiled, expression)
|
323
|
-
end
|
324
|
-
new invocation, compiled, expression, cname
|
117
|
+
Invocation::Base.new(compiled, expression)
|
325
118
|
end
|
326
119
|
|
327
120
|
def initialize function_instruction, argument_instructions, source, sig=nil
|
@@ -329,13 +122,7 @@ module Nydp
|
|
329
122
|
@sig = sig
|
330
123
|
end
|
331
124
|
|
332
|
-
def
|
333
|
-
|
334
|
-
vm.push_ctx_instructions function_instruction
|
335
|
-
vm.push_ctx_instructions argument_instructions
|
336
|
-
end
|
337
|
-
|
338
|
-
def inspect ; @function_instruction.inspect ; end
|
339
|
-
def to_s ; @source.to_s ; end
|
125
|
+
def inspect ; @function_instruction._nydp_inspect ; end
|
126
|
+
def to_s ; @source.to_s ; end
|
340
127
|
end
|
341
128
|
end
|
data/lib/nydp/helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Nydp
|
2
2
|
module AutoWrap
|
3
3
|
# include this and be sure to either override #_nydp_ok? or #_nydp_whitelist
|
4
|
-
# #_nydp_whitelist should return a list of accessor (zero-arg) methods which are safe for nydp to
|
4
|
+
# #_nydp_whitelist should return a list of accessor (zero-arg) methods which are safe for nydp to call
|
5
5
|
# #_nydp_procify should return a list of methods that can be exposed to script code.
|
6
6
|
#
|
7
7
|
# class Blub
|
@@ -19,11 +19,9 @@ module Nydp
|
|
19
19
|
#
|
20
20
|
# blubme here, now
|
21
21
|
#
|
22
|
-
def _nydp_wrapper ; self ; end
|
23
22
|
def _nydp_ok? method ; _nydp_whitelist.include? method ; end
|
24
23
|
def _nydp_procify? method ; _nydp_procs.include? method ; end # override to allow returning Method instances for given method name
|
25
24
|
def _nydp_get key ; _nydp_safe_send(key.to_s.as_method_name) ; end
|
26
|
-
def to_ruby ; self ; end
|
27
25
|
def _nydp_safe_send meth, *args
|
28
26
|
return send meth, *args if _nydp_ok?(meth)
|
29
27
|
return method(meth) if _nydp_procify?(meth)
|
@@ -37,8 +35,16 @@ module Nydp
|
|
37
35
|
end
|
38
36
|
|
39
37
|
module Converter
|
40
|
-
def n2r
|
41
|
-
def r2n o
|
38
|
+
def n2r o ; o.respond_to?(:to_ruby) ? o.to_ruby : o ; end
|
39
|
+
def r2n o ; o._nydp_wrapper ; end
|
40
|
+
|
41
|
+
def rubify value
|
42
|
+
if value.is_a?(Array) ; value.map { |v| rubify v }
|
43
|
+
elsif value.is_a?(::Nydp::Pair) ; rubify(value.to_a)
|
44
|
+
elsif value.is_a?(::Hash) ; { }.tap { |h| value.each { |k, v| h[rubify k] = rubify(v) } }
|
45
|
+
else ; n2r value
|
46
|
+
end
|
47
|
+
end
|
42
48
|
end
|
43
49
|
|
44
50
|
extend Converter
|
@@ -62,14 +68,15 @@ module Nydp
|
|
62
68
|
end
|
63
69
|
|
64
70
|
def sym? expr, name
|
65
|
-
expr.is_a?(Nydp::Symbol) && (expr.is? name)
|
71
|
+
# expr.is_a?(Nydp::Symbol) && (expr.is? name)
|
72
|
+
expr.is_a?(::Symbol) && (expr == name.to_sym)
|
66
73
|
end
|
67
74
|
|
68
75
|
def pair? expr
|
69
76
|
expr.is_a?(Nydp::Pair)
|
70
77
|
end
|
71
78
|
|
72
|
-
def cons a, b=
|
79
|
+
def cons a=nil, b=nil
|
73
80
|
Nydp::Pair.new a, b
|
74
81
|
end
|
75
82
|
|
@@ -78,12 +85,14 @@ module Nydp
|
|
78
85
|
end
|
79
86
|
|
80
87
|
def sym name, ns
|
81
|
-
|
88
|
+
name.to_s.to_sym
|
82
89
|
end
|
83
90
|
|
84
91
|
def literal? expr
|
85
92
|
case expr
|
86
|
-
when String, Float, Integer, Integer,
|
93
|
+
# when String, Float, Integer, Integer, Symbol, Nydp::Truth, Nydp::Nil
|
94
|
+
# when String, Float, Integer, Integer, Symbol, Nydp::Truth, NilClass
|
95
|
+
when String, Float, Integer, Integer, Symbol, TrueClass, FalseClass, NilClass
|
87
96
|
true
|
88
97
|
else
|
89
98
|
false
|