nydp 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +77 -56
  4. data/lib/lisp/core-000.nydp +1 -1
  5. data/lib/lisp/core-010-precompile.nydp +49 -29
  6. data/lib/lisp/core-012-utils.nydp +12 -8
  7. data/lib/lisp/core-015-documentation.nydp +41 -15
  8. data/lib/lisp/core-017-builtin-dox.nydp +621 -100
  9. data/lib/lisp/core-020-utils.nydp +33 -6
  10. data/lib/lisp/core-025-warnings.nydp +1 -1
  11. data/lib/lisp/core-030-syntax.nydp +64 -48
  12. data/lib/lisp/core-035-flow-control.nydp +20 -28
  13. data/lib/lisp/core-037-list-utils.nydp +84 -21
  14. data/lib/lisp/core-040-utils.nydp +8 -5
  15. data/lib/lisp/core-041-string-utils.nydp +17 -11
  16. data/lib/lisp/core-043-list-utils.nydp +140 -77
  17. data/lib/lisp/core-045-dox-utils.nydp +1 -0
  18. data/lib/lisp/core-050-test-runner.nydp +8 -12
  19. data/lib/lisp/core-070-prefix-list.nydp +19 -15
  20. data/lib/lisp/core-080-pretty-print.nydp +13 -5
  21. data/lib/lisp/core-090-hook.nydp +11 -11
  22. data/lib/lisp/core-100-utils.nydp +51 -66
  23. data/lib/lisp/core-110-hash-utils.nydp +34 -7
  24. data/lib/lisp/core-120-settings.nydp +14 -9
  25. data/lib/lisp/core-130-validations.nydp +28 -13
  26. data/lib/lisp/core-900-benchmarking.nydp +420 -47
  27. data/lib/lisp/tests/000-empty-args-examples.nydp +5 -0
  28. data/lib/lisp/tests/andify-examples.nydp +1 -1
  29. data/lib/lisp/tests/auto-hash-examples.nydp +6 -1
  30. data/lib/lisp/tests/best-examples.nydp +1 -1
  31. data/lib/lisp/tests/boot-tests.nydp +1 -1
  32. data/lib/lisp/tests/date-examples.nydp +129 -102
  33. data/lib/lisp/tests/destructuring-examples.nydp +1 -1
  34. data/lib/lisp/tests/dox-tests.nydp +2 -2
  35. data/lib/lisp/tests/hash-examples.nydp +58 -33
  36. data/lib/lisp/tests/list-tests.nydp +137 -1
  37. data/lib/lisp/tests/pretty-print-tests.nydp +12 -0
  38. data/lib/lisp/tests/rotate-2d-array-examples.nydp +26 -0
  39. data/lib/lisp/tests/sort-examples.nydp +5 -5
  40. data/lib/lisp/tests/string-tests.nydp +30 -5
  41. data/lib/lisp/tests/syntax-tests.nydp +10 -2
  42. data/lib/lisp/tests/time-examples.nydp +8 -1
  43. data/lib/lisp/tests/unparse-tests.nydp +13 -7
  44. data/lib/nydp/assignment.rb +15 -28
  45. data/lib/nydp/builtin/abs.rb +4 -3
  46. data/lib/nydp/builtin/apply.rb +8 -10
  47. data/lib/nydp/builtin/cdr_set.rb +1 -1
  48. data/lib/nydp/builtin/comment.rb +1 -3
  49. data/lib/nydp/builtin/date.rb +11 -28
  50. data/lib/nydp/builtin/divide.rb +3 -10
  51. data/lib/nydp/builtin/ensuring.rb +6 -21
  52. data/lib/nydp/builtin/error.rb +2 -4
  53. data/lib/nydp/builtin/eval.rb +9 -4
  54. data/lib/nydp/builtin/greater_than.rb +7 -8
  55. data/lib/nydp/builtin/handle_error.rb +10 -34
  56. data/lib/nydp/builtin/hash.rb +24 -45
  57. data/lib/nydp/builtin/inspect.rb +1 -3
  58. data/lib/nydp/builtin/is_equal.rb +4 -7
  59. data/lib/nydp/builtin/less_than.rb +6 -7
  60. data/lib/nydp/builtin/log.rb +7 -0
  61. data/lib/nydp/builtin/math_ceiling.rb +1 -3
  62. data/lib/nydp/builtin/math_floor.rb +1 -3
  63. data/lib/nydp/builtin/math_power.rb +1 -3
  64. data/lib/nydp/builtin/math_round.rb +2 -2
  65. data/lib/nydp/builtin/minus.rb +7 -14
  66. data/lib/nydp/builtin/parse.rb +5 -5
  67. data/lib/nydp/builtin/parse_in_string.rb +5 -7
  68. data/lib/nydp/builtin/plus.rb +14 -31
  69. data/lib/nydp/builtin/pre_compile.rb +1 -3
  70. data/lib/nydp/builtin/puts.rb +4 -8
  71. data/lib/nydp/builtin/quit.rb +1 -1
  72. data/lib/nydp/builtin/rand.rb +6 -11
  73. data/lib/nydp/builtin/random_string.rb +2 -4
  74. data/lib/nydp/builtin/rng.rb +25 -0
  75. data/lib/nydp/builtin/ruby_wrap.rb +27 -14
  76. data/lib/nydp/builtin/script_run.rb +1 -3
  77. data/lib/nydp/builtin/set_intersection.rb +3 -4
  78. data/lib/nydp/builtin/set_union.rb +3 -4
  79. data/lib/nydp/builtin/sort.rb +2 -7
  80. data/lib/nydp/builtin/string_match.rb +5 -13
  81. data/lib/nydp/builtin/string_replace.rb +2 -7
  82. data/lib/nydp/builtin/string_split.rb +3 -8
  83. data/lib/nydp/builtin/sym.rb +2 -9
  84. data/lib/nydp/builtin/thread_locals.rb +2 -2
  85. data/lib/nydp/builtin/time.rb +38 -44
  86. data/lib/nydp/builtin/times.rb +6 -15
  87. data/lib/nydp/builtin/to_integer.rb +8 -14
  88. data/lib/nydp/builtin/to_string.rb +2 -13
  89. data/lib/nydp/builtin/type_of.rb +10 -16
  90. data/lib/nydp/builtin/vm_info.rb +2 -10
  91. data/lib/nydp/builtin.rb +15 -37
  92. data/lib/nydp/compiler.rb +29 -19
  93. data/lib/nydp/cond.rb +95 -88
  94. data/lib/nydp/context_symbol.rb +11 -9
  95. data/lib/nydp/core.rb +74 -73
  96. data/lib/nydp/core_ext.rb +88 -24
  97. data/lib/nydp/date.rb +22 -19
  98. data/lib/nydp/error.rb +2 -3
  99. data/lib/nydp/function_invocation.rb +76 -289
  100. data/lib/nydp/helper.rb +18 -9
  101. data/lib/nydp/interpreted_function.rb +159 -25
  102. data/lib/nydp/lexical_context.rb +9 -8
  103. data/lib/nydp/lexical_context_builder.rb +1 -1
  104. data/lib/nydp/literal.rb +3 -7
  105. data/lib/nydp/loop.rb +72 -0
  106. data/lib/nydp/namespace.rb +52 -0
  107. data/lib/nydp/pair.rb +146 -50
  108. data/lib/nydp/parser.rb +9 -11
  109. data/lib/nydp/plugin.rb +88 -19
  110. data/lib/nydp/runner.rb +141 -23
  111. data/lib/nydp/symbol.rb +16 -26
  112. data/lib/nydp/symbol_lookup.rb +3 -2
  113. data/lib/nydp/tokeniser.rb +1 -1
  114. data/lib/nydp/truth.rb +2 -37
  115. data/lib/nydp/version.rb +1 -1
  116. data/lib/nydp.rb +33 -44
  117. data/nydp.gemspec +2 -1
  118. data/spec/date_spec.rb +26 -32
  119. data/spec/embedded_spec.rb +22 -22
  120. data/spec/error_spec.rb +12 -16
  121. data/spec/foreign_hash_spec.rb +21 -36
  122. data/spec/hash_non_hash_behaviour_spec.rb +12 -29
  123. data/spec/hash_spec.rb +36 -49
  124. data/spec/literal_spec.rb +6 -6
  125. data/spec/nydp_spec.rb +14 -14
  126. data/spec/pair_spec.rb +8 -8
  127. data/spec/parser_spec.rb +41 -37
  128. data/spec/rand_spec.rb +1 -4
  129. data/spec/spec_helper.rb +3 -3
  130. data/spec/string_atom_spec.rb +15 -16
  131. data/spec/symbol_spec.rb +27 -52
  132. data/spec/thread_local_spec.rb +23 -8
  133. data/spec/time_spec.rb +4 -10
  134. data/spec/tokeniser_spec.rb +10 -10
  135. metadata +25 -13
  136. data/lib/nydp/builtin/modulo.rb +0 -11
  137. data/lib/nydp/builtin/regexp.rb +0 -7
  138. data/lib/nydp/builtin/sqrt.rb +0 -7
  139. data/lib/nydp/builtin/string_pad_left.rb +0 -7
  140. data/lib/nydp/builtin/string_pad_right.rb +0 -7
  141. data/lib/nydp/hash.rb +0 -9
  142. data/lib/nydp/image_store.rb +0 -21
  143. data/lib/nydp/vm.rb +0 -129
data/lib/nydp/builtin.rb CHANGED
@@ -1,55 +1,33 @@
1
1
  module Nydp::Builtin
2
2
  module Base
3
+ @@reraise_errors = []
3
4
  include Nydp::Helper
4
5
 
5
- def builtin_invoke vm, args ; raise "#{self.class.name} : please implement #builtin_invoke" ; end
6
- def builtin_invoke_1 vm ; builtin_invoke vm, Nydp::NIL ; end
7
- def builtin_invoke_2 vm, a ; builtin_invoke vm, cons(a) ; end
8
- def builtin_invoke_3 vm, a0, a1 ; builtin_invoke vm, cons(a0, cons(a1)) ; end
9
- def builtin_invoke_4 vm, a0, a1, a2 ; builtin_invoke vm, cons(a0, cons(a1, cons(a2))) ; end
10
-
11
- def invoke_1 vm
12
- builtin_invoke_1 vm
13
- rescue StandardError => e
14
- handle_error e
15
- end
16
-
17
- def invoke_2 vm, arg
18
- builtin_invoke_2 vm, arg
19
- rescue StandardError => e
20
- handle_error e, arg
6
+ def self.ignore_errors kla
7
+ @@reraise_errors << kla
21
8
  end
22
9
 
23
- def invoke_3 vm, arg_0, arg_1
24
- builtin_invoke_3 vm, arg_0, arg_1
25
- rescue StandardError => e
26
- handle_error e, arg_0, arg_1
27
- end
28
-
29
- def invoke_4 vm, arg_0, arg_1, arg_2
30
- builtin_invoke_4 vm, arg_0, arg_1, arg_2
31
- rescue StandardError => e
32
- handle_error e, arg_0, arg_1, arg_2
33
- end
34
-
35
- # called from 'apply (among others)
36
- def invoke vm, args
37
- builtin_invoke vm, args
38
- rescue StandardError => e
39
- handle_error e, *(args.to_a)
40
- end
10
+ ignore_errors Nydp::Error
41
11
 
42
12
  def handle_error e, *args
43
13
  case e
44
- when Nydp::Error
14
+ when *@@reraise_errors
45
15
  raise e
46
16
  else
47
- arg_msg = args.map { |a| " #{a.inspect}"}.join("\n")
48
- new_msg = "Called #{self.inspect}\nwith args\n#{arg_msg}"
17
+ arg_msg = args.map { |a| "#{a._nydp_inspect}"}.join("\n").split(/\n/).map { |s| " #{s}"}.join("\n")
18
+ new_msg = "Called #{self._nydp_inspect}\nwith args\n#{arg_msg}"
49
19
  raise new_msg
50
20
  end
51
21
  end
52
22
 
23
+ def call *args
24
+ builtin_call *args
25
+ rescue => e
26
+ handle_error e, *args
27
+ end
28
+
29
+ alias _nydp_call call
30
+
53
31
  def name
54
32
  cname = self.class.name.split("::").last
55
33
  cname = cname.gsub(/([a-z])([A-Z])/) { |m| "#{m[0]}-#{m[1].downcase}" }
data/lib/nydp/compiler.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'nydp/cond'
2
+ require 'nydp/loop'
2
3
  require 'nydp/function_invocation'
3
4
  require 'nydp/interpreted_function'
4
5
  require 'nydp/literal'
@@ -7,48 +8,57 @@ module Nydp
7
8
  class Compiler
8
9
  extend Helper
9
10
 
10
- def self.compile expression, bindings
11
- compile_expr expression, bindings
11
+ def self.compile expression, bindings, ns
12
+ compile_expr expression, bindings, ns
12
13
  rescue StandardError => e
13
- raise Nydp::Error.new "failed to compile expression:\n#{expression.inspect}"
14
+ raise Nydp::Error.new "failed to compile expression:\n#{expression._nydp_inspect}\n#{e.message}"
14
15
  end
15
16
 
16
- def self.compile_expr expression, bindings
17
- if expression.is_a? Nydp::Symbol
18
- SymbolLookup.build expression, bindings
17
+ def self.compile_expr expression, bindings, ns
18
+ # if expression.is_a? Nydp::Symbol
19
+ if expression.is_a? ::Symbol
20
+ SymbolLookup.build expression, bindings, ns
19
21
  elsif literal? expression
20
- Literal.build expression, bindings
22
+ Literal.build expression, bindings, ns
21
23
  elsif expression.is_a? Nydp::Pair
22
- compile_pair expression, bindings
24
+ begin
25
+ compile_pair expression, bindings, ns
26
+ rescue => e
27
+ raise "failed to compile #{expression._nydp_inspect}"
28
+ end
29
+ else
30
+ raise Nydp::Error.new "failed to compile unrecognised expression:\n#{expression._nydp_inspect}\nwhich is a #{expression.class}"
23
31
  end
24
32
  end
25
33
 
26
34
  def self.maybe_cons a, b
27
- Nydp::NIL.is?(a) ? b : cons(a, b)
35
+ (a == nil) ? b : cons(a, b)
28
36
  end
29
37
 
30
- def self.compile_each expr, bindings
31
- if Nydp::NIL.is?(expr)
38
+ def self.compile_each expr, bindings, ns
39
+ if expr == nil
32
40
  expr
33
41
  elsif pair?(expr)
34
- maybe_cons compile(expr.car, bindings), compile_each(expr.cdr, bindings)
42
+ maybe_cons compile(expr.car, bindings, ns), compile_each(expr.cdr, bindings, ns)
35
43
  else
36
- compile(expr, bindings)
44
+ compile(expr, bindings, ns)
37
45
  end
38
46
  end
39
47
 
40
- def self.compile_pair expression, bindings
48
+ def self.compile_pair expression, bindings, ns
41
49
  key = expression.car
42
50
  if sym?(key, :cond)
43
- Cond.build expression.cdr, bindings # todo: replace with function? (cond x (fn () iftrue) (fn () iffalse)) -->> performance issues, creating two closures for every cond invocation
51
+ Cond.build expression.cdr, bindings, ns # todo: replace with function? (cond x (fn () iftrue) (fn () iffalse)) -->> performance issues, creating two closures for every cond invocation
52
+ elsif sym?(key, :loop)
53
+ Loop.build expression.cdr, bindings, ns
44
54
  elsif sym?(key, :quote)
45
- Literal.build expression.cadr, bindings
55
+ Literal.build expression.cadr, bindings, ns
46
56
  elsif sym?(key, :assign)
47
- Assignment.build expression.cdr, bindings
57
+ Assignment.build expression.cdr, bindings, ns
48
58
  elsif sym?(key, :fn)
49
- InterpretedFunction.build expression.cadr, expression.cddr, bindings
59
+ InterpretedFunction.build expression.cadr, expression.cddr, bindings, ns
50
60
  else
51
- FunctionInvocation.build expression, bindings
61
+ FunctionInvocation.build expression, bindings, ns
52
62
  end
53
63
  end
54
64
  end
data/lib/nydp/cond.rb CHANGED
@@ -1,73 +1,69 @@
1
1
  module Nydp
2
- class ExecuteConditionalInstruction
3
- extend Helper
4
-
5
- def initialize when_true, when_false
6
- @when_true, @when_false = when_true, when_false
7
- end
8
-
9
- def lexical_reach n
10
- [@when_true.lexical_reach(n), @when_false.lexical_reach(n)].max
11
- end
12
-
13
- def execute vm
14
- (Nydp::NIL.is?(vm.args.pop) ? @when_false : @when_true).execute vm
15
- end
16
-
17
- def inspect
18
- "when_true:#{@when_true.inspect}:when_false:#{@when_false.inspect}"
19
- end
20
-
21
- def to_s
22
- "#{@when_true.to_s} #{@when_false.to_s}"
23
- end
24
- end
25
-
26
2
  class Cond
27
3
  extend Helper
28
4
  include Helper
29
5
  attr_reader :condition, :conditional
30
6
 
31
7
  def initialize cond, when_true, when_false
32
- @condition, @conditional = cond, cons(ExecuteConditionalInstruction.new(when_true, when_false))
8
+ @condition, @when_true, @when_false = cond, when_true, when_false
33
9
  end
34
10
 
35
11
  def lexical_reach n
36
- [@condition.lexical_reach(n), @conditional.car.lexical_reach(n)].max
12
+ [@condition.lexical_reach(n), @when_true.lexical_reach(n), @when_false.lexical_reach(n)].max
37
13
  end
38
14
 
39
15
  def execute vm
40
- vm.push_ctx_instructions conditional
41
- condition.execute vm
16
+ if (@condition.execute(vm))
17
+ @when_true.execute(vm)
18
+ else
19
+ @when_false.execute(vm)
20
+ end
21
+ end
22
+
23
+ def compile_to_ruby indent, srcs, opts=nil
24
+ if (!@when_false) || (@when_false.is_a?(Nydp::Literal) && !@when_false.expression)
25
+ "#{indent}##> #{inspect.split(/\n/).join('\n')}
26
+ #{indent}if (#{@condition.compile_to_ruby "", srcs})
27
+ #{@when_true.compile_to_ruby(indent + " ", srcs, cando: true)}
28
+ #{indent}end"
29
+ else
30
+ "#{indent}##> #{inspect.split(/\n/).join('\n')}
31
+ #{indent}if (#{@condition.compile_to_ruby "", srcs})
32
+ #{@when_true.compile_to_ruby(indent + " ", srcs, cando: true)}
33
+ #{indent}else
34
+ #{@when_false.compile_to_ruby(indent + " ", srcs, cando: true)}
35
+ #{indent}end"
36
+ end
42
37
  end
43
38
 
44
39
  def inspect
45
- "cond:#{condition.inspect}:#{conditional.inspect}"
40
+ "(cond #{condition._nydp_inspect} #{@when_true._nydp_inspect} #{@when_false._nydp_inspect})"
46
41
  end
47
42
 
48
43
  def to_s
49
- "(cond #{condition.to_s} #{conditional.to_s})"
44
+ "(cond #{condition.to_s} #{@when_true.to_s} #{@when_false.to_s})"
50
45
  end
51
46
 
52
- def self.build expressions, bindings
47
+ def self.build expressions, bindings, ns
53
48
  if expressions.is_a? Nydp::Pair
54
- cond = Compiler.compile expressions.car, bindings
55
- when_true = Compiler.compile expressions.cdr.car, bindings
56
- when_false = Compiler.compile expressions.cdr.cdr.car, bindings
49
+ cond = Compiler.compile expressions.car, bindings, ns
50
+ when_true = Compiler.compile expressions.cdr.car, bindings, ns
51
+ when_false = Compiler.compile expressions.cdr.cdr.car, bindings, ns
57
52
  csig = sig(cond)
58
- # puts cond_sig
59
- # TODO : handle literal nil explicitly (if x y) -> #when_false is literal nil, we can hardcode that
60
- # todo : handle "OR" explicitly -> (if x x y) -> when #cond equals #when_true, hardcode this case
61
- case csig
62
- when "LEX"
63
- Cond_LEX.build(cond, when_true, when_false)
64
- when "SYM"
65
- Cond_SYM.new(cond, cons(when_true), cons(when_false))
66
- else
67
- new(cond, when_true, when_false)
68
- end
53
+ xsig = "#{sig(cond)}_#{sig(when_true)}_#{sig(when_false)}"
54
+
55
+ # case csig
56
+ # when "LEX"
57
+ # Cond_LEX.build(cond, when_true, when_false)
58
+ # when "SYM"
59
+ # Cond_SYM.new(cond, when_true, when_false)
60
+ # else
61
+ # new(cond, when_true, when_false)
62
+ # end
63
+
64
+ new(cond, when_true, when_false)
69
65
  else
70
- raise "can't compile Cond: #{expressions.inspect}"
66
+ raise "can't compile Cond: #{expressions._nydp_inspect}"
71
67
  end
72
68
  end
73
69
  end
@@ -84,20 +80,26 @@ module Nydp
84
80
  [@condition.lexical_reach(n), @when_true.lexical_reach(n), @when_false.lexical_reach(n)].max
85
81
  end
86
82
 
87
- def inspect ; "cond:#{@condition.inspect}:#{@when_true.inspect}:#{@when_false.inspect}" ; end
83
+ def inspect ; "cond:#{@condition._nydp_inspect}:#{@when_true._nydp_inspect}:#{@when_false._nydp_inspect}" ; end
88
84
  def to_s ; "(cond #{@condition.to_s} #{@when_true.to_s} #{@when_false.to_s})" ; end
85
+ # def compile_to_ruby indent
86
+ # "((#{@condition.compile_to_ruby "", srcs}) ? (#{@when_true.compile_to_ruby "", srcs}) : (#{@when_false.compile_to_ruby "", srcs}))"
87
+ # end
89
88
  end
90
89
 
91
90
  class Cond_LEX < CondBase
92
91
  def execute vm
93
- truth = !Nydp::NIL.is?(@condition.value vm.current_context)
94
- vm.push_ctx_instructions (truth ? @when_true : @when_false)
92
+ if @condition.value vm.current_context
93
+ @when_true.execute(vm)
94
+ else
95
+ @when_false.execute(vm)
96
+ end
95
97
  end
96
98
 
97
99
  def lexical_reach n
98
100
  cr = @condition.lexical_reach(n)
99
- ct = @when_true.car.lexical_reach(n)
100
- cf = @when_false.car.lexical_reach(n)
101
+ ct = @when_true.lexical_reach(n)
102
+ cf = @when_false.lexical_reach(n)
101
103
 
102
104
  [cr, ct, cf].max
103
105
  end
@@ -107,23 +109,27 @@ module Nydp
107
109
  fsig = sig(when_false)
108
110
  cond_sig = "#{tsig}_#{fsig}"
109
111
 
110
- # if (cond == when_true)
111
- # OR_LEX.build cond, when_false
112
-
113
112
  if (cond == when_true) && (fsig == "LIT")
114
- OR_LEX_LIT.new cond, nil, when_false
113
+ OR_LEX_LIT.new cond, nil, when_false.expression
115
114
  elsif (cond == when_true) && (fsig == "LEX")
116
115
  OR_LEX_LEX.new cond, nil, when_false
116
+ elsif (cond == when_true)
117
+ OR_LEX_XXX.new cond, nil, when_false
117
118
  else
118
119
  case cond_sig
119
120
  when "LIT_LIT"
121
+ # puts "building Cond_LEX_LIT_LIT #{[cond, when_true.expression, when_false.expression]}"
120
122
  Nydp::Cond_LEX_LIT_LIT.new(cond, when_true.expression, when_false.expression)
121
123
  when "LEX_LIT"
122
124
  Nydp::Cond_LEX_LEX_LIT.new(cond, when_true, when_false.expression)
123
125
  when "CND_LIT"
124
126
  Nydp::Cond_LEX_CND_LIT.new(cond, when_true, when_false.expression)
127
+ when "NVB_LEX"
128
+ Nydp::Cond_LEX_NVB_LEX.new(cond, when_true, when_false)
129
+ when "NVB_LIT"
130
+ Nydp::Cond_LEX_NVB_LIT.new(cond, when_true, when_false.expression)
125
131
  else
126
- Nydp::Cond_LEX.new(cond, cons(when_true), cons(when_false))
132
+ new(cond, when_true, when_false)
127
133
  end
128
134
  end
129
135
  end
@@ -131,67 +137,68 @@ module Nydp
131
137
 
132
138
  class OR_LEX_LIT < CondBase
133
139
  def execute vm
134
- value = @condition.value vm.current_context
135
- vm.push_arg(!Nydp::NIL.is?(value) ? value : @when_false)
140
+ @condition.value(vm.current_context) || @when_false
136
141
  end
137
142
  end
138
143
 
139
144
  class OR_LEX_LEX < CondBase
140
145
  def execute vm
141
- value = @condition.value vm.current_context
142
- vm.push_arg(!Nydp::NIL.is?(value) ? value : (@when_false.value vm.current_context))
146
+ @condition.value(vm.current_context) || (@when_false.value vm.current_context)
143
147
  end
144
148
  end
145
149
 
146
- # class OR_LEX < CondBase
147
- # def execute vm
148
- # value = @condition.value vm.current_context
149
- # if !Nydp::NIL.is?(value)
150
- # vm.push_arg value
151
- # else
152
- # @when_false.execute vm
153
- # end
154
- # end
155
-
156
- # def self.build cond, when_false
157
- # case sig(when_false)
158
- # when "LIT"
159
- # OR_LEX_LIT.new(cond, nil, when_false)
160
- # when "LEX"
161
- # OR_LEX_LEX.new(cond, nil, when_false)
162
- # else
163
- # OR_LEX.new(cond, nil, when_false)
164
- # end
165
- # end
166
- # end
150
+ class OR_LEX_XXX < CondBase
151
+ def execute vm
152
+ @condition.value(vm.current_context) || (@when_false.execute vm)
153
+ end
154
+ end
167
155
 
168
156
  class Cond_LEX_LIT_LIT < CondBase # (def no (arg) (cond arg nil t))
169
157
  def execute vm
170
- falsity = Nydp::NIL.is?(@condition.value vm.current_context)
171
- vm.push_arg(falsity ? @when_false : @when_true)
158
+ (@condition.value vm.current_context) ? @when_true : @when_false
172
159
  end
173
160
  end
174
161
 
175
162
  class Cond_LEX_LEX_LIT < CondBase
176
163
  def execute vm
177
- falsity = Nydp::NIL.is?(@condition.value vm.current_context)
178
- vm.push_arg(falsity ? @when_false : (@when_true.value vm.current_context))
164
+ (@condition.value vm.current_context) ? (@when_true.value vm.current_context) : @when_false
179
165
  end
180
166
  end
181
167
 
182
168
  class Cond_LEX_CND_LIT < CondBase
183
169
  def execute vm
184
- if Nydp::NIL.is?(@condition.value vm.current_context)
185
- vm.push_arg @when_false
170
+ if (@condition.value vm.current_context)
171
+ @when_true.execute vm
172
+ else
173
+ @when_false
174
+ end
175
+ end
176
+ end
177
+
178
+ class Cond_LEX_NVB_LEX < CondBase
179
+ def execute vm
180
+ if (@condition.value vm.current_context)
181
+ @when_true.execute vm
186
182
  else
183
+ @when_false.value(vm.current_context)
184
+ end
185
+ end
186
+ end
187
+
188
+ class Cond_LEX_NVB_LIT < CondBase
189
+ def execute vm
190
+ if (@condition.value vm.current_context)
187
191
  @when_true.execute vm
192
+ else
193
+ @when_false
188
194
  end
189
195
  end
190
196
  end
191
197
 
192
198
  class Cond_SYM < CondBase
193
199
  def execute vm
194
- vm.push_ctx_instructions (Nydp::NIL.is?(@condition.value) ? @when_false : @when_true)
200
+ # puts "Cond_SYM"
201
+ (@condition.value) ? @when_true.execute(vm) : @when_false.execute(vm)
195
202
  end
196
203
  end
197
204
  end
@@ -24,6 +24,7 @@ module Nydp
24
24
  "set_index(#{binding_index}, value)"
25
25
  end
26
26
 
27
+ line = __LINE__ + 2
27
28
  code = <<-KLASS
28
29
  def initialize name, lexical_depth
29
30
  @name, @lexical_depth = name, lexical_depth
@@ -33,10 +34,14 @@ module Nydp
33
34
  @lexical_depth + n
34
35
  end
35
36
 
37
+ def compile_to_ruby indent, srcs, opts=nil
38
+ "\#{indent}_arg_\#{@name.to_s._nydp_name_to_rb_name}"
39
+ end
40
+
36
41
  def value ctx
37
- ctx#{getctx}.#{at_index} || Nydp::NIL
42
+ ctx#{getctx}.#{at_index} || nil
38
43
  rescue
39
- raise "failed looking up \#{@name.inspect} (\#{@name.class.name})"
44
+ raise "failed looking up \#{@name._nydp_inspect} (\#{@name.class.name}) : lookup expression was ctx#{getctx}.#{at_index}"
40
45
  end
41
46
 
42
47
  def assign value, ctx
@@ -45,24 +50,21 @@ module Nydp
45
50
  raise "problem in \#{self.class.name}#assign, name is \#{@name}, depth is \#{depth}, index is #{binding_index}"
46
51
  end
47
52
 
48
- def execute vm
49
- vm.push_arg value vm.current_context
50
- end
51
-
52
53
  def depth ; #{depth} ; end
53
54
  def inspect ; to_s ; end
54
- def to_s ; "[#{depth}##{binding_index}#\#{@lexical_depth}]\#{@name}" ; end
55
+ # def to_s ; "[#{depth}##{binding_index}#\#{@lexical_depth}]\#{@name}" ; end
56
+ def to_s ; @name ; end
55
57
  KLASS
56
58
 
57
59
  const_set name, Class.new(Nydp::ContextSymbol) {
58
- eval code, binding, name.to_s, 0
60
+ eval code, binding, "#{name.to_s} : #{__FILE__}", line
59
61
  }
60
62
  end
61
63
 
62
64
  def self.build effective_depth, name, binding_index, lexical_depth
63
65
  const_get(:"ContextSymbol_#{effective_depth}_#{binding_index}").new(name, lexical_depth)
64
66
  rescue
65
- raise "building ContextSymbol #{[effective_depth, name, binding_index, lexical_depth].inspect}"
67
+ raise "building ContextSymbol #{[effective_depth, name, binding_index, lexical_depth]._nydp_inspect}"
66
68
  end
67
69
  end
68
70
  end